+ 1

How create (not create and write) a file in python?

In my version of python, mustn't to create a file using "open(test.xml, "w")", there will be an exception. If the file was created in advance, then there will be no exception.

14th Apr 2021, 4:41 PM
Operand
Operand - avatar
10 ответов
+ 1
If your operating system is POSIX-compliant then you can issue a shell command to create it by using "touch": import os os.system("touch test.xml") If the file does not exist, then it will create the file. Else it will update the access and modification date and time stamps of the existing file. See the man page for options to change its behavior.
15th Apr 2021, 6:39 AM
Brian
Brian - avatar
+ 6
Operand , very difficult to guess what are you doing in your code. it would be helpful, if you could show us your code. please put it in playground and link it here. thanks!
14th Apr 2021, 7:02 PM
Lothar
Lothar - avatar
+ 1
15th Apr 2021, 7:38 PM
Operand
Operand - avatar
+ 1
Line 22 after downloaded no Space: download/ + arg...
15th Apr 2021, 7:47 PM
Václav Dostál
Václav Dostál - avatar
0
What do you mean in advanced? Function open(test.xml,"w") create file test.xml for write then you need close this file.
14th Apr 2021, 5:50 PM
Václav Dostál
Václav Dostál - avatar
0
Václav Dostál but the error remained
15th Apr 2021, 7:51 PM
Operand
Operand - avatar
0
Hmm, it is harder... And what about implement https://realpython.com/JUMP_LINK__&&__python__&&__JUMP_LINK-requests/
15th Apr 2021, 7:56 PM
Václav Dostál
Václav Dostál - avatar
0
Does it help to correct the spelling in line 22 from '/dowloads/' to '/downloads/'?
15th Apr 2021, 8:00 PM
Brian
Brian - avatar
0
Václav Dostál What will it change? The problem is in creating the file, because the exception clearly states that this directory does not exist.
15th Apr 2021, 8:03 PM
Operand
Operand - avatar
0
There Is from ... import exception And May by it shows error. But try as Brian wrote /downloads/.
16th Apr 2021, 4:59 AM
Václav Dostál
Václav Dostál - avatar