Answers for "python function to create file and read file"

1

python function to create file and read file

import os
def file_oprator(filename,type_of_prosess_on_file="w+",text=None):
    """This is a function from which you can create files and read files it takes three inportant inputs one name of file which opration to do on file and text if you are using the create and write function"""
    try:
        
        do = open(filename,type_of_prosess_on_file)
        if type_of_prosess_on_file == "w+" or type_of_prosess_on_file == "w" and os.path.isfile(filename):
            do.write(text)
            return text
        else:
            return do.read()
    except:
        return "an unexpected error occurred"
    do.close()
print(file_oprator("creating file with python function","w+","look i have created a file with a python function\nit was as simple as eating a cake\npython is very inportant for the feature"))
Posted by: Guest on October-05-2021
0

make a file in python

import os
 
newpath = r'C:\Program Files\arbitrary' 
if not os.path.exists(newpath):
    os.makedirs(newpath)
Posted by: Guest on August-08-2021
1

python create file

f= open("guru99.txt","w+")
Posted by: Guest on August-31-2020

Code answers related to "python function to create file and read file"

Python Answers by Framework

Browse Popular Code Answers by Language