×

Discussion Board

Results 1 to 2 of 2
  1. #1
    Regular Contributor
    Join Date
    Nov 2006
    Location
    Pune, india
    Posts
    186

    Question write and writelines???

    hi

    what should be the difference in output of write and writelines command for writting data in a file???

    thnks

  2. #2
    Super Contributor
    Join Date
    Oct 2007
    Location
    Deva, Romania
    Posts
    3,471

    Re: write and writelines???

    I really don't think there's difference in output, just that using write() you can write a string, using writelines() you can write a list of strings.

    For example:
    Code:
    f=file("C:\\a.txt", "w")
    f.write("some text")
    f.close()
    
    #This will write the string "some text" in the file
    #Trying to write a sequence of strings like this will result in an error
    Code:
    strings=["word1","some other word","bla"]
    
    f=file("C:\\a.txt", "w")
    f.write(strings)
    f.close()

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×