I have no troubles reading a .txt file from S3 with the following line
lines = sc.textFile("s3n://gvdata/ETL_Data/example.txt")
but when I want to open a file, write something into it and save it to my bucket in S3
filename = "s3n://gvdata/myLog-%s.txt"%datetime.now().strftime('%d-%m-%y')
f = open(filename,'w')
f.write("blabla %s \n" %datetime.now().strftime('%d-%m-%y_%H:%M:%S'))
f.close()
I get "No such file or directory".
Anyone knows how to change it?
Thanks in advance!
Related
I am trying to write a program in Pycharm that can take the name of 2 txt files as an input and then use that input to execute some set of instructions. I understand I can put the name of a txt file in the parameters of the configuration, but how can I do that without knowing what the file name will be beforehand? The code snippet is very vague so far but I can't really do test runs without passing the 2 txt files.
import sys
sets = sys.argv[1]
operations = sys.argv[2]
print(len(sys.argv))
print(sets)
print(operations)
Even when I've tried hard-coding names of txt-files as parameters in the configuration I only get back the names of the files so I know I have more problems than one 😬.
"I understand I can put the name of a txt file in the parameters of
the configuration, but how can I do that without knowing what the file
name will be beforehand."
In order to work with parameters unknown at the time you write your code, a filename for example in your case, you can pass those variables when you execute your python file in the terminal as arguments.
"Even when I've tried hard-coding names of txt-files as parameters in
the configuration I only get back the names of the files"
If you want to work with the text inside the files you need to open the files first, you can't just print them like print("file1.txt")
Code example:
import sys
file1 = sys.argv[1]
file2 = sys.argv[2]
print(f"Open and read file: {file1}")
with open(file1, "r") as f:
print(f.read())
print(f"Open and read file: {file2}")
with open(file2, "r") as f:
print(f.read())
Executing code (run in terminal):
python test.py test1.txt test2.txt
Output:
Open and read file: test1.txt
Hello World
This is file test1
Open and read file: test2.txt
Hello Stackoverflow
This is test2
I am trying to run an in.file in lammps, but I keep getting an error saying it cannot open the .txt file. The last command that it stops at is: 'molecule ID file.txt file2.txt file3.txt'
The file it cannot open is file.txt, yet it is all spelled the same. Please help! Thank you!
I tried renaming the files but that did not work
Below is the code I am working currently:
cd '/Users/K3iTH/Desktop/Ubuntu (Shared)/Trial/'
filename = 'slice_quarter0';
k = 1
inputfile = sprintf('%s.%d.csv','filename',k-1);
data = csvread(inputfile,1,0);
I am trying to load the .csv file exported in Ubuntu. The code is run until inputfile. When I try to run data = csvread(inputfile,1,0);, it stated file not found.
Any mistake I did?
If the file slice_quarter0.csv exists, and is located in your working directory then you should modify your sprintf call to
inputfile = sprintf('%s%d.csv',filename,k-1);
Otherwise, csvread will try to open a file named filename.0.csv, which will cause the error you have since it presumably does not exist.
I have a question for the reading of multiple files .txt in the same times and same script. I have a principal folder Matlab in which there are 7 subfolders Folder1 to Folder 7 in which of them there is un document file.txt.
I would like to read each of 'file.txt' in a script that I run in the curent folder Matlab. is there a fast way to do this? Or am I forced to do load file.txt for each folder.
You can use dir to list all your Folder. Then you can create the path of your file for each folder and load this file.
folder = dir('Folder*'); %list all the folder whose name start with 'Folder'
for ii = 1:length(folder)
s{ii} = fullfile(folder(ii).name,'text.txt'); %create the path for each file
load(s{ii});
end
In a for loop you can create the folder name:
for i = 1:n
name = ['folder',int2str(i)]
% then you can open and read the file
fileID = fopen([name,'\file.txt'])
data = fread(fileID)
% Don't forget to close the file
fclose(fileID)
end
missing link ~ I have a working batch file that takes .txt input. The data is in MS WORD and we have to manually 'save as .txt' each of hundreds of files before running the batch file. Commercial converters run from $50 to $500 . . . ANY help appreciated!