How create (not create and write) a file in python? | Sololearn: Learn to code for FREE!

+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.

4/14/2021 4:41:10 PM

Operand

10 Answers

New Answer

+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.

+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!

+1

Lothar https://code.sololearn.com/cf8ufFzGu3ze/?ref=app I need the site code to download

+1

Line 22 after downloaded no Space: download/ + arg...

0

What do you mean in advanced? Function open(test.xml,"w") create file test.xml for write then you need close this file.

0

Václav Dostál but the error remained

0

Hmm, it is harder... And what about implement https://realpython.com/python-requests/

0

Does it help to correct the spelling in line 22 from '/dowloads/' to '/downloads/'?

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.

0

There Is from ... import exception And May by it shows error. But try as Brian wrote /downloads/.