Posts: 4,646
Threads: 1,493
Joined: Sep 2016
which is "better"?
if opt[0].lower()=='-n':
...
or:
if opt[0] in ('-n','-N'):
...
?
Tradition is peer pressure from dead people
What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Posts: 4,646
Threads: 1,493
Joined: Sep 2016
how do you know my use case fits argparse? or is it that you know that all your future use caes will?
Tradition is peer pressure from dead people
What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Posts: 544
Threads: 15
Joined: Oct 2016
Dec-06-2017, 05:28 AM
(This post was last modified: Dec-06-2017, 05:31 AM by Windspar.)
you always could look at bytecode to see which one you like
import dis
def lower(a):
a.lower() == 'a'
def isin(a):
a in ['a', 'A']
dis.dis(lower)
print()
dis.dis(isin)
output
Quote: 4 0 LOAD_FAST 0 (a)
2 LOAD_ATTR 0 (lower)
4 CALL_FUNCTION 0
6 LOAD_CONST 1 ('a')
8 COMPARE_OP 2 (==)
10 POP_TOP
12 LOAD_CONST 0 (None)
14 RETURN_VALUE
7 0 LOAD_FAST 0 (a)
2 LOAD_CONST 3 (('a', 'A'))
4 COMPARE_OP 6 (in)
6 POP_TOP
8 LOAD_CONST 0 (None)
10 RETURN_VALUE
99 percent of computer problems exists between chair and keyboard.