[Tutor] Read file line by line

2005-01-25 Thread Gilbert Tsang
Hey you Python coders out there: Being a Python newbie, I have this question while trying to write a script to process lines from a text file line-by-line: #!/usr/bin/python fd = open( "test.txt" ) content = fd.readline() while (content != "" ): content.replace( "\n", "" ) # process cont

[Tutor] Control flow

2005-01-28 Thread Gilbert Tsang
Hi there, I have this logic that I cannot wrap my mind it: def go_jogging(): # go out and jog return if ( bad_weather =='y' ): # ask user only if weather is bad. b = input ( "Weather is really bad, still go out to jog?[y/n]" ) if b == 'y': go_jogging() else: # program

Re: [Tutor] Control flow

2005-01-31 Thread Gilbert Tsang
Thanks for the enthusiasm on how input/raw_input() works - my original intention was to ask a question on control flow so I didn't spend that much time testing out this piece of input code besides typing. But I did learn a lot. Thanks! Gilbert Jacob S. wrote: I noticed that too, Liam. b = input

[Tutor] question on string

2005-08-01 Thread Gilbert Tsang
Hi there, I would like to construct some string objects using the cprintf-style format: command_string = "diff -u %s %s > %s.patch" % ( src, dst, file ) Of course it is illegal in python but I couldn't figure out a way to construct strings with that kind of formatting and substitution. I have

Re: [Tutor] question on string

2005-08-01 Thread Gilbert Tsang
ZIYAD A. M. AL-BATLY wrote: On Mon, 2005-08-01 at 10:42 -0700, Gilbert Tsang wrote: Hi there, I would like to construct some string objects using the cprintf-style format: command_string = "diff -u %s %s > %s.patch" % ( src, dst, file ) Of course it is illegal in pytho