Learn Python Easy Way

Wednesday, December 9, 2015

write lines to file: create file easy way

def create_file('file_name', 'text'):
    with open(INDEX_HTML,"w") as fp:
        fp.writelines(html_contents)


create_file('test.txt', 'hello world')



   
Posted by Gopal Singh at 12:22 PM
Email ThisBlogThis!Share to XShare to FacebookShare to Pinterest

No comments:

Post a Comment

Newer Post Older Post Home
Subscribe to: Post Comments (Atom)

Blog Archive

  • ►  2017 (13)
    • ►  September (4)
    • ►  August (6)
    • ►  July (3)
  • ►  2016 (62)
    • ►  August (1)
    • ►  June (8)
    • ►  May (11)
    • ►  April (18)
    • ►  March (17)
    • ►  February (5)
    • ►  January (2)
  • ▼  2015 (77)
    • ▼  December (8)
      • linked list in python
      • clear list for further use
      • serch key in python dictionary using 'in' in place...
      • exit python commandline
      • django server setup and code
      • python question-answer
      • write lines to file: create file easy way
      • color console text on windows
    • ►  November (19)
    • ►  October (28)
    • ►  September (2)
    • ►  August (17)
    • ►  July (3)
  • ►  2013 (1)
    • ►  October (1)
Simple theme. Powered by Blogger.