0
Can we create/remove files with Python ?
Can we?
5 Antworten
+ 1
let's say I want to a file named hello.txt and write hello world
here I go about that
fp = open('hello.txt', 'w') # create file
fp.write('hello world') # write inside it
fp.close() # then close it
+ 1
Yes.
You can use the open function to create files. When you open a file in write mode, you will create new file.
For removing files you can use os module, which contains many useful methods for file handling.
os.remove can be used to remove files.
+ 1
Yeah it's totally possible.
to create a file you can use the open function
i.e: open (filename):
# statements
filename will be the path to where you file will be created.
For removing files and directories you can checkout the os module or the pathlib module.
0
Thanks but how, what is the command to create files?
0
Thanks you