raw_input just continues anyway?

Steve Holden steve at holdenweb.com
Tue Apr 3 14:49:07 EDT 2007


oliver at obeattie.com wrote:
> How could I resolve this?
> 
Try to keep each answer so it makes sense on its own, please. I presume 
you are responding to this:

> In <1175611910.685578.246780 at w1g2000hsg.googlegroups.com>,
> oliver at obeattie.com wrote:
> 
>> > if __name__ == "__main__":
>> > 	bucket_name = raw_input('Name of the bucket you wish the files to be
>> > placed into? ')
>> > 	update_s3()
>> > 
>> > 
>> > Basically I pipe some files into the script - so would this cause a
>> > linebreak?
> 
> Yes of course.  `raw_input()` is reading from `stdin` so the very first
> line you pipe in will be assigned to `bucket_name`.
> 
from Marc 'BlackJack' Rintsch?

Essentially you seem to want to use standard input for two separate 
purposes: one to provide the name of a bucket (which it appears you 
would like to specify interactively) and the other to provide a list of 
filenames that your script has to process.

I would suggest in that case providing the bucket name as a command-line 
argument. That way standard input can be limited to communicating 
filenames, and your pipeline doesn't need to contain two separate types 
of information. Your code would then become (without error checking):

if __name__ == '__main__':
     import sys
     bucket_name = sys.argv[1]
     update_s3()

I assume from this code, by the way, that update_s3() makes use of the 
bucket name as a global variable. While this will work it isn't best 
practice. You might want to consider passing bucket_name as an argument 
to update_s3() (and you won't need to change the code of update_s3() if 
you call the argument bucket_name too).

Hope this serves to help rather than confuse.

regards
  Steve
-- 
Steve Holden       +44 150 684 7255  +1 800 494 3119
Holden Web LLC/Ltd          http://www.holdenweb.com
Skype: holdenweb     http://del.icio.us/steve.holden
Recent Ramblings       http://holdenweb.blogspot.com




More information about the Python-list mailing list