Short answer:
if filename == "default" :
Long answer:
is
checks for object identity. To check for equality, use ==
. Check the Python documentation on comparisons. In your case:
Note that comparing two string constants with is
will actually return true.
def f():
a = "foo"
b = "foo"
print(a is b) # True, because a and b refer to the same constant
x = "f" + "oo"
print(a is x) # True, because the addition is optimized away
y = "f"
z = y + "oo" #
print(a is z) # False, because z is actually a different object
You can see what happens under the hood by disassembling the CPython byte code:
>>> import dis
>>> dis.dis(f)
2 0 LOAD_CONST 1 ('foo')
3 STORE_FAST 0 (a)
3 6 LOAD_CONST 1 ('foo')
9 STORE_FAST 1 (b)
4 ...
5 28 LOAD_CONST 4 ('foo')
31 STORE_FAST 2 (x)
6 ...
7 50 LOAD_CONST 2 ('f')
53 STORE_FAST 3 (y)
8 56 LOAD_FAST 3 (y)
59 LOAD_CONST 3 ('oo')
62 BINARY_ADD
63 STORE_FAST 4 (z)
9 ...