+ 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
4 Answers
+ 6
@Gordie thanks for replying but how can I choose the file extension
+ 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 )