Getting stdin using TextWrangler or BBEdit,
but not MacPython (was: [Pythonmac-SIG] One IDE can find sys._buf,
the other can't. What's going on?)
Bob Ippolito
bob at redivi.com
Thu Mar 3 23:16:07 CET 2005
On Mar 3, 2005, at 16:57, Louis Pecora wrote:
> Bob Ippolito wrote:
>
>> As far as this code goes, you might be able to just get away with it
>> if you do:
>>
>> # check for MacPython IDE
>> if hasattr(sys.stdout, '_buf'):
>> sys.stdout._buf = ...
>
> You're right this is a test that would shut off the _buf part of the
> code if I were not using MacPython.
>>
>> It really depends on what the rest of your code looks like. If it
>> does sys.stdout.readline() for example, it's still going to be
>> broken, because you can't normally read from stdout. The rawinput()
>> function might do what you want everywhere else, though.
>
> I can't seem to get rawinput or raw_input() to work. Ignoring my
> previous code. I just want something that can take standard input so,
> for instance, when I prompt with
>
> print "Input 2 ints and a float"
>
> The program will wait until I type, say
>
> 2 5 5.476 (return)
>
> Then hand back the three numbers either as a string, a list, or
> individual int and float types so I can process them with my program.
> Sort of like
> int i1, i2;
> float f1;
>
> scanf(" %d %d %e", i1, i2, f1);
> would do in C using stdin. Or even a gets() which I could then
> process to pull out the two ints and a float.
> I'm just looking for simple input of numbers and strings. I'd like to
> do this from BBEdit rather than MacPython. Anyone out there done this
> with TextWrangler?
I don't know a damn thing about TextWrangler, but this works with any
Python that has a working stdin:
while True:
text = raw_input("Input 2 ints and a float: ")
try:
i1, i2, f1 = [t(v) for (t, v) in zip((int, int, float),
text.split())]
except ValueError, e:
print 'Invalid Entry: %s' % (e,)
continue
break
-bob
More information about the Pythonmac-SIG
mailing list