Is there a significant difference in assigning values one-by-one and with tuples in Python? -


Whether there is a big difference in the time, memory usage, or two statements in some:

  (Script_name, option1, option2) = (sys.argv [0], sys.argv [1], sys.argv [2])  

and

< Pre> script_name = sys.argv [0] option1 = sys.argv [1] option2 = sys.argv [2]

(no value optparse is used)

No significant differences Thanks to Bettecode Payfool Optimization, in the first one Not even a temporary Tupal construction Is. Even if there is, dirt is cheap in making and deleting tuples.

Personally, I write it as

  script_name, option1, option2, * _ = sys. Argv # or script_name, option1, option2 = sys.argv [: 3]  

I think it raises a different, perhaps more deceptive error message, if there are very few command line logic , But an good error message requires a clear check in advance, I have no problem.


Comments

Popular posts from this blog

Member with no value in F# -

java - Joda Time Interval Not returning what I expect -

c# - Showing a SelectedItem's Property -