0

Can we create/remove files with Python ?

Can we?

4th May 2021, 5:07 AM
fayou
fayou - avatar
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
4th May 2021, 5:26 AM
Alpha Diallo
Alpha Diallo - avatar
+ 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.
4th May 2021, 5:19 AM
Seb TheS
Seb TheS - avatar
+ 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.
4th May 2021, 5:19 AM
Alpha Diallo
Alpha Diallo - avatar
0
Thanks but how, what is the command to create files?
4th May 2021, 5:20 AM
fayou
fayou - avatar
0
Thanks you
4th May 2021, 5:27 AM
fayou
fayou - avatar