Skip to content

Tag: python

Python if statement with string as condition

There’s some code in virtualenv that’s tripping me up. It’s this: path.decode(“utf-8”) if “__DECODE_PATH__” else path from activate_this.py line 28. How can if “__DECODE_PATH__” ever be false? It’s possible it’s a bug, but since it’s in v…

call a method only if the previous one returned a value

I am looking for a specific string in text, and want to get it only if found. I can write it as followד and it works: But I remember another nicer way to write it with question mark before the “group”, and put value “1” as default value in case of re.search return an empty result. Answ…

python how to write an update sql query?

I am trying to write an update query but I could not manage the string. My connections is ok. My query is like this: This is giving me error: undefined column name ‘hello’. I want to update message column as hello but it is getting it as a column name. In sql, when I write it as UPDATE users SET