Re: getting words from readline

2005-09-11 Thread Do Re Mi chel La Si Do
Hi !

Look :   .split()

@-salutations

Michel Claveau 


-- 
http://mail.python.org/mailman/listinfo/python-list


Re: getting words from readline

2005-09-11 Thread Steve Holden
Adam wrote:
 How is best to extract word strings from a 
 line = infile.readline()  
 
 I wish to quickly check the first word of 
 each line of a text file. 
 
 Indeed, How do I break a lineinput() line 
 into component words (separate by spaces etc) ?
 
 Should I be looking at; 
 Re Parser Slice StringIO ? 
 
 
 Any help appreciated. 
 
Python 2.4.1 (#1, May 27 2005, 18:02:40)
[GCC 3.3.3 (cygwin special)] on cygwin
Type help, copyright, credits or license for more information.
   s = This is a line of text
   s.split()
['This', 'is', 'a', 'line', 'of', 'text']
   l = s.split()
   l[0]
'This'
  

As you can see above, you probably don't need any complicated modules 
for this fairly simple requirement. If you are wanting to match the 
words against each other, or against some pre-exisitng list, you might 
want to reduce the input to lower-case first.

regards
  Steve
-- 
Steve Holden   +44 150 684 7255  +1 800 494 3119
Holden Web LLC http://www.holdenweb.com/

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: getting words from readline

2005-09-11 Thread Adam

Ouch.  That is simple with .split 

I must have got confused amongst 
slice re etc. searching searching. 

Thanks folks.  Painless. 

 
-- 
http://mail.python.org/mailman/listinfo/python-list


getting words from readline

2005-09-10 Thread Adam

How is best to extract word strings from a 
line = infile.readline()  

I wish to quickly check the first word of 
each line of a text file. 

Indeed, How do I break a lineinput() line 
into component words (separate by spaces etc) ?

Should I be looking at; 
Re Parser Slice StringIO ? 


Any help appreciated. 




-- 
http://mail.python.org/mailman/listinfo/python-list