Re: read file problem

Philip Aston <[email protected]>
Newsgroups gmane.comp.java.grinder.user
Message-ID <[email protected]>
line = lines[line_number]

You'll also need to strip the trailing new line, and your call to split
is slightly wrong. This should help:

    Jython 2.5.2 (Release_2_5_2:7206, Mar 2 2011, 23:12:06)
    [Java HotSpot(TM) 64-Bit Server VM (Oracle Corporation)] on java1.7.0_25
    Type "help", "copyright", "credits" or "license" for more information.
    >>> *infile = open('/tmp/login.txt', 'r')*
    >>> *lines = infile.readlines()*
    >>> *lines*
    ['foo,bah\n', 'lah,dah\n', 'x,y\n']
    >>> *import random*
    >>> *line_number = random.randint(0,len(lines))**
    *>>>*infile.close()*
    >>> *line = lines[line_number]*
    >>> *username, password = line.rstrip().split(',')*
    >>> *username, password*
    ('x', 'y')


- Phil


On 03/10/13 16:09, Salma Bouriat wrote:
> hello
>
> I am reading from a file and putting the content into a list, but I
> don't know how to get to a particular line, tried,but in vain.  keep
> in mind that I have a text file in the format (username, password) and
> I need to split them too, but I also don't know  how to make that
> happen. Here is my code. Thank you
>
> infile = open('login.txt', 'r')
> lines = infile.readlines()
> line_number = random.randint(0,len(lines))
> infile.close()
> data = line.split(line,',')
> username = data[0]
> password = data[1]
>
>
> -- 
> Salma BOURIAT
> Master of Science in Software Engineering
> Al Akhawayn University
>

------------------------------------------------------------------------------
October Webinars: Code for Performance
Free Intel webinars can help you accelerate application performance.
Explore tips for MPI, OpenMP, advanced profiling, and more. Get the most from 
the latest Intel processors and coprocessors. See abstracts and register >
http://pubads.g.doubleclick.net/gampad/clk?id=60134791&iu=/4140/ostg.clktrk

_______________________________________________
grinder-use mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/grinder-use
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.