sys.stdin is an iterator not a list so addressing an element in the way you are 
doing it won't work, you would need to wrap sys.stdin in a list() to cause it 
to read all the lines, and then address the element, for example

        print ( list(sys.stdin)[1] )

would be the way to go, note that arrays are 0 based so this would get you the 
second line.

If you just want the first line:
        
        line = sys.stdin.readline()

You could use .split() to split the line, or check re.match() if you want to 
use a regex as opposed to a string:

        field1, field2 = line.split('\t')

would split on a tab.

F. 


On Apr 28, 2013, at 7:04 PM, LuKreme <[email protected]> wrote:

> 
> On 28 Apr 2013, at 15:44 , François Schiettecatte <[email protected]> 
> wrote:
> 
>> #!/usr/bin/python
>> import sys
>> 
>> for line in  sys.stdin:
>>      replacement_line = "***" + line.strip()
>>      print  replacement_line
> 
> huh, that's interesting. I tried what I thought was the simplest possible 
> script:
>       
> #!/usr/bin/python
> import sys
> 
> print (sys.stdin[1])
> 
> and it not only didn't do anything, it gave an "error 32"
> 
> Yours works, but I need to look up how to split the line into two fields so I 
> can operate on the first one.
> 
> -- 
> Personal isn't the same as important
> 
> -- 
> -- 
> You received this message because you are subscribed to the 
> "BBEdit Talk" discussion group on Google Groups.
> To post to this group, send email to [email protected]
> To unsubscribe from this group, send email to
> [email protected]
> For more options, visit this group at
> <http://groups.google.com/group/bbedit?hl=en>
> If you have a feature request or would like to report a problem, 
> please email "[email protected]" rather than posting to the group.
> Follow @bbedit on Twitter: <http://www.twitter.com/bbedit>
> 
> --- 
> You received this message because you are subscribed to the Google Groups 
> "BBEdit Talk" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to [email protected].
> For more options, visit https://groups.google.com/groups/opt_out.
> 
> 

-- 
-- 
You received this message because you are subscribed to the 
"BBEdit Talk" discussion group on Google Groups.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
<http://groups.google.com/group/bbedit?hl=en>
If you have a feature request or would like to report a problem, 
please email "[email protected]" rather than posting to the group.
Follow @bbedit on Twitter: <http://www.twitter.com/bbedit>

--- 
You received this message because you are subscribed to the Google Groups 
"BBEdit Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to