[Tutor] Fwd: Sys.argv read parameters
Danilo Chilene
bicofino at gmail.com
Thu Apr 18 20:23:18 CEST 2013
On Thu, Apr 18, 2013 at 2:52 PM, Alan Gauld <alan.gauld at btinternet.com>wrote:
> On 18/04/13 18:14, Danilo Chilene wrote:
>
> for command in commands:
>> if arg in commands:
>> print commands[command]
>> else:
>> print 'Invalid command'
>>
>
> I don't understand what you are doing here? Its almost a random selection
> mechanism? You print the command for every item in commands if arg is in
> commands and Invalid Command for every command if its not?
> Whatever its trying to do its massively inefficient.
>
> I thought you'd have wanted something like
>
> for command in commands:
> if arg == command:
>
> print commands[command]
> else:
> print 'Invalid command'
>
> Which is roughly equivalent to:
>
> print commands.get(arg, 'Invalid command')
>
> but much less efficient!
Hi Alan,
Yes, I was doing it the wrong way.
>
>
>
> --
> Alan G
> Author of the Learn to Program web site
> http://www.alan-g.me.uk/
>
> ______________________________**_________________
> Tutor maillist - Tutor at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/**mailman/listinfo/tutor<http://mail.python.org/mailman/listinfo/tutor>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20130418/43b1082d/attachment.html>
More information about the Tutor
mailing list