I have written a function as follows, with optional argument ‘b’.
url depends on the existence of b.
def something(a, b=None)
if len(b) >= 1:
url = 'http://www.xyz.com/%sand%s' % (a, b)
else:
url = 'http://www.xyz.com/%s' (a)
This raises an error when b=None, saying “object of type ‘none-type’ has no length”
Any ideas how to get around this?
You can simply use
if b:– this will require the value to be both notNoneand not an empty string/list/whatever.