Announcement

Collapse
No announcement yet.

Write text file with given content at specified Path

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Write text file with given content at specified Path

    Please use the script to write given content on specified text file

    Code:
    ## Pass the path here, for example "C:\samplefile.txt"
    path = 'C:\samplefile.txt'
    ## Pass your content here to write there on the file
    contents = """
    Sample Content 1
    Sample Content 2
    Sample Content 3
    Sample Content 4
    Sample Content 5
    etc
    """
    try:
        with open(path, 'w') as fiOb:
            fiOb.write(contents)
            print 'Success: File has been written at - '+path
    except:
        print 'Fail: Check your path!!'
    Sample Output:
    Click image for larger version

Name:	Write File with Given texts and Path (Including text file name).PNG
Views:	1
Size:	3.0 KB
ID:	4814

    Last edited by Purushothaman; 11-04-2016, 01:45 PM.
Working...
X