Tuesday, 5 February 2019

Python Script to create File and append 10 dummy lines on every function call

def createFolder():
   try:
        if not os.path.exists(directory):
            os.makedirs(directory)
            return 'FolderCreated'
            return 'FolderNotCreated'

     f = open("/home/raghu/Desktop/raghu1234.txt","a+")

     for i in range(10):
        f.write("This is the line %d\r\n" % (i+1))

     f.close()

# FunctionCall
createFolder()

No comments:

Post a Comment