How do I find out a name of class that created an instance of an object in Python if the function I am doing this from is the base class of which the class of the instance has been derived?

solution 1:

type(x).__name__ will give you the name of the class, which I think is what you want.

>>> import itertools
>>> x = itertools.count(0)
>>> type(x).__name__

solution 2:


 In Python, how do I get a function name as a string, without calling the function?

def my_function():

print get_function_name_as_string(my_function) # my_function is not in quotes
should output "my_function".

 geopoint = {'latitude':41.123,'longitude':71.091}

print('{latitude} {longitude}'.format(**geopoint))

this should be good for you. 


d = dict(foo='x', bar='y', baz='z')
'foo is {foo}, bar is {bar} and baz is {baz}'.format_map(d)
or more complex case:
>>> p1 = {'latitude':41.123,'longitude':71.091}
>>> p2 = {'latitude':56.456,'longitude':23.456}
>>> '{0[latitude]} {0[longitude]} - {1[latitude]} {1[longitude]}'.format(p1, p2)
'41.123 71.091 - 56.456 23.456'

Popular Posts