+ 6

Please help i learned how to make some math functions but i want to learn how to make file functions 😟

in python we have the math functions ( working with some variables and some numbers 😑 ) but can I make a function for a file like a program that rewrites a chosen file I tried but I don't how I will make this function understand that let's sayâ˜ș def my_function(x,y): if x > y print("x") else: print("y") so can I make a function with a file like def file_rewrite(filename.txt): open("filename.txt","w") file.write("hi") file.close() print(file_rewrite(hello.txt)) open("hello.txt","r") note:hello.txt exists

29th Sep 2017, 9:40 AM
warlord
warlord - avatar
4 Answers
+ 6
@Gordie thanks for replying but how can I choose the file extension
29th Sep 2017, 2:38 PM
warlord
warlord - avatar
+ 6
@Gordie does that mean the file extension is not important cause it's the same file name and the important thing is the opening method ( mode )
29th Sep 2017, 5:08 PM
warlord
warlord - avatar