#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2005
    Posts
    34
    Rep Power
    0

    file object to string


    how can i get a text file contents into a string?

    i worked out how to get each line in a list, but would like all the lines to be in a string


    thankyou.
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2004
    Posts
    40
    Rep Power
    11
    Code:
    content = open('yourfile.txt').read()

    Comments on this post

    • CyBerHigh agrees
    • netytan agrees : You can also use file('path', 'r').read()
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Nov 2004
    Location
    There where the rabbits jump
    Posts
    556
    Rep Power
    12
    yup .read() does the job but also when newlines come or tabs and stuff it will do \n,\t,...

IMN logo majestic logo threadwatch logo seochat tools logo