Fix Python – Simpler way to create dictionary of separate variables?

I would like to be able to get the name of a variable as a string but I don’t know if Python has that much introspection capabilities. Something like:
>>> print(my_var.__name__)

I want to do that because I have a bunch of variables I’d like to turn into a dictionary like :
bar = True
foo = False
>>> my_dict = dict(bar=bar, foo=foo)
>>> p….

Fix Python – Python __str__ versus __unicode__

Is there a python convention for when you should implement __str__() versus __unicode__(). I’ve seen classes override __unicode__() more frequently than __str__() but it doesn’t appear to be consistent. Are there specific rules when it is better to implement one versus the other? Is it necessary/good practice to implement both?

Fix Python – Find column whose name contains a specific string

I have a dataframe with column names, and I want to find the one that contains a certain string, but does not exactly match it. I’m searching for ‘spike’ in column names like ‘spike-2’, ‘hey spike’, ‘spiked-in’ (the ‘spike’ part is always continuous).
I want the column name to be returned as a string or a variable, so I access the column later wi….

Fix Python – Check if a word is in a string in Python

I’m working with Python, and I’m trying to find out if you can tell if a word is in a string.
I have found some information about identifying if the word is in the string – using .find, but is there a way to do an if statement. I would like to have something like the following:
if string.find(word):


Fix Python – Removing a list of characters in string

I want to remove characters in a string in python:
string.replace(‘,’, ”).replace(“!”, ”).replace(“:”, ”).replace(“;”, ”)…

But I have many characters I have to remove. I thought about a list
list = [‘,’, ‘!’, ‘.’, ‘;’…]

But how can I use the list to replace the characters in the string?