Alright, I know how to print variables and strings. But how can I print something like "My string" card.price (it is my variable). I mean, here is my code: print "I have "

(and here I would like to print my variable card.price).

Login

0 votes

You can do it by your way but you are missing the order that is the only issue:

[unicode(x.strip()) if x is not None else '' for x in row]

**Syntax:-**

[f(x) if condition else g(x) for x in sequence]

In list comprehension with if condition we can do like as follows:-

[f(x) for x in sequence if condition]

Another way of doing this is:-

def change(f):

if f is None:

return unicode(f.strip())

else:

return ''

row = [change(x) for x in row]

You can also use the following way to solve the problem:-

row = map(change, row)