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

    Join Date
    Jun 2004
    Posts
    37
    Rep Power
    11

    Text/Input Question


    Hello,

    I have a text file that contains names..

    Sally
    Jenni
    Jess

    and I want to take those names and run them through a program so the out put looks like this...

    "Sally",
    "Jenni",
    "Jess",

    Any Help would be appreciated. Thanks again!
  2. #2
  3. Only the strong survives!!.
    Devshed God 1st Plane (5500 - 5999 posts)

    Join Date
    Feb 2003
    Location
    A World of wonders.
    Posts
    5,583
    Rep Power
    407
    names.txt
    Code:
    Sally
    Jenni
    Jess
    Names.py
    Code:
    for x in file('names.txt'):
            lines  = x.splitlines( )
                                                                                    
            print lines
    Output
    Code:
    ['Sally']
    ['Jenni']
    ['Jess']
    Hopefully this is what you want
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2004
    Posts
    37
    Rep Power
    11
    Not exactly, but I can work from there.

    Thanks again!
  6. #4
  7. Hello World :)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2003
    Location
    Hull, UK
    Posts
    2,537
    Rep Power
    69
    This any better?

    Code:
    #!/usr/bin/env python
    
    for line in file('names.txt'):
        print '"%s",' % line.strip()
    Mark.
    programming language development: www.netytan.com Hula

  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2004
    Posts
    37
    Rep Power
    11
    Mark, that works perfectly.

IMN logo majestic logo threadwatch logo seochat tools logo