Answer the question
In order to leave comments, you need to log in
Can you help a teapot on Linux with python?
Hello dear programmers!
I have already read similar questions and answers to them, but alas, I don’t know python from the word at all, so don’t hit hard))
I have Ubuntu 21 installed on my computer. I have a working script in python2.7, it is launched by the command line from the folder . It reads from the text file kolonial.txt, which is located in the same folder with it, and creates a second text file kolonial2.txt with the results in the same folder. It is located on the sdb1 disk.
I want it to read a text file from the kooper folder on the sda1 drive and write the results to the deals folder in kolonial2.txt on the sdb2 drive.
This is what it looks like now
#!/usr/bin/env python
# encoding: utf-8
import sys
import getopt
import random
#sys.stdout = open('output.txt','wt')
MARKS = open('kolonial.txt', 'r').readlines()
outputtxt = open('kolonial2.txt', 'w')
class Usage(Exception):
def __init__(self, msg):
self.msg = msg
How to set the path, drives and folders with files???? I remind you, I have Ubuntu))
I beg you to write a piece of code that you can copy and paste instead of
MARKS = open('kolonial.txt', 'r').readlines()
outputtxt = open('kolonial2.txt', 'w' )
Tried
open('/mnt/dev/sda1/home/kooper/kolonial.txt', 'r')
open('/mnt/dev/sdb2/deals/kolonial2.txt', 'w')
Wrote IOError:
Answer the question
In order to leave comments, you need to log in
Your Open call can accept both relative paths (when it looks in the working directory) and full paths, feel free to specify the full path in both cases and everything will work, just look that the user has rights to this directory and file ...
For example :
open('kolonial.txt', 'r') replace with open('/mnt/kooper/kolonial.txt', 'r')
and open('kolonial2.txt', 'w') with open('/ mnt/deals/colonial2.txt', 'w')
Everything was solved quite simply)) By replacing the lines with
open('/home/kooper/kolonial.txt', 'r')
open('/home/deals/kolonial2.txt', 'w')
Then I mounted Dropbox as a network folder cooper, and GoogleDrive as a network folder deals.
As a result, my work files are dumped on Dropbox, I run the script, it processes them and creates a report to the authorities directly on GoogleDrive.
Many thanks to Valentin Sudakov Valentin Sudakov and AUser0 AUser0
Now it takes me about 5 minutes to create a report instead of 3-4 hours))
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question