@cvp Thank you so much for your effort. Unfortunately this code isn't working for the format I want to get for my CSV file (as I described above). But please don't worry. I will continue with my search for a solution for this. Thanks again.
Welcome!
This is the community forum for my apps Pythonista and Editorial.
For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.
Latest posts made by jokiehints
-
RE: Error on writing to csv file
-
RE: Error on writing to csv file
@cvp OK thanks, I understand. Ik hope somewone else can give me the tips I need.
-
RE: Error on writing to csv file
@cvp Thanks for your reply. Can I ask you another question? I hope I'm not asking too much. If this is the case, please forgive me asking.
It regards the code below:
import csv kolom = 'geb_dag' value = 19 with open('data.csv', 'a', newline='') as csvfile: fieldnames = ['column', 'value'] writer = csv.DictWriter(csvfile, fieldnames=fieldnames) writer.writeheader() writer.writerow({'column': kolom, 'value': value})``` This code gives an addition tot my data.csv file like: column,value geb_dag,19 I want to use this code several times to add more values to 'data.csv' like column,value geb_dag,19 geb_mnd, 10 geb_jr, 1981 vnaam, 2 anaam, 5 But every time I give the variables 'kolom' (which stands for columnname) and 'value' (which stand for values I want to add) other strings or integers I get: column,value geb_dag,19 column,value geb_mnd, 10 column,value geb_jr, 1981 column,value vnaam, 2 column,value anaam, 5 At first: I want to get rid of the "column, value" row every time I use the code. Second: Even beter I want the CSV go to a horizontal presentation like: geb_dag, geb_mnd, geb_jr, vnaam, a_naam, 19, 10, 1981, 2, 5 But what ever I do, it fails. Do you know an easy way to make this happen working with csv? I have a code that is working. But this is written using pandas and that doesn't work in pythonista. For that reason I want to use CSV, so I can use my python code on my mobile. Thank you so much With kind regards.
-
RE: Error on writing to csv file
@cvp Thank you! this is indeed the solution! Since I have pythonista I have worked within de directory phytonista. But.... not with this one! That's the reason why I couln't understand why the script didn't run. Now I do. Stupid me.
-
Error on writing to csv file
I get a error call running this script:
import csv with open('data.csv', 'w', newline='') as csvfile: fieldnames = ['first_name', 'last_name'] writer = csv.DictWriter(csvfile, fieldnames=fieldnames) writer.writeheader() writer.writerow({'first_name': 'Baked', 'last_name': 'Beans'})
There is a permission error [Errno 1] Operation not permitted: 'data.csv'.
Can someone please explain to me what I'm doing wrong?
Thank you so much for your assistence!Kind regards
-
RE: File handling CSV files and TXT files within Phytonista
@cvp: Yes!! Thank you very much. That's is the solution. This works wonderfull. All my python work is now useble within Pythonista!
-
RE: File handling CSV files and TXT files within Phytonista
@JonB: Thank you for your response. I thought of this before, but my first question is how do I get these files on my ipad in the right place.
Second: In your answer you specified "This Ipad Folder" Is that the actual name or did you meant another folder?
I'm sorry if my english is not good. But I hope you understand my questions. -
RE: File handling CSV files and TXT files within Phytonista
@cvp**:** Many thanks for your concern. I'm very gratefull!
Both files are in Icloud and in the same folder.
When I run the code on my laptop there is no probleem. I get the results I want. But when I run the code in Pythonista, I get the error code and the traceback.
I'm using python 3.7.2. Maybe that's the problem?
Other question: Schould the csv file normally be accessible to read en write when using Pythonista?
Is that the same with TXT files? I have several scripts were I exchange data to other files.
I hope that this is also possible when using Pythonista. I hope you can discover the problem. -
RE: File handling CSV files and TXT files within Phytonista
The code is as follows:
import csv
filename = 'nummer.csv'
with open(filename, newline = '') as file_object:
csvreader = csv.reader(file_object, delimiter = ';', dialect='excel',)
csv_headings = next(csvreader)
first_line = next(csvreader)
vnaam = int(first_line[0])
anaam = int(first_line[1])
dnaam_1 = int(first_line[2])
dnaam_2 = int(first_line[3])
dnaam_3 = int(first_line[4])
geb_dag = int(first_line[5])
geb_mnd = int(first_line[6])
geb_jr = int(first_line[7]) -
RE: File handling CSV files and TXT files within Phytonista
The same code runs without problems on my laptop. Should I make changes in my code?