Karteikarten
python beyond introspection
Karten in diesem Stapel (26)
- 1i = 7 type(i) ==>?
- 2int ==>
- 3repr(int)""
- 4i=7 type(I) is int ==>true
- 5i = 7 x = type(i)(78) x=?78
- 6i = 78 type(type(i))
- 7i=78 i.__class__ ==> ?
- 8i=78 i.__class__.__class__ => ?
- 9i=78 i.__class__.__class__.__class__ = ?
- 10issubclass(type,object) ?True
- 11type(object) ?
- 12isinstance(i, int) ?True
- 13i = 78 how do you get a list of attribute names for the instance i ?dir(i)
- 14how do you get the value of a single attribute(you choose) of i=78 ?(to get all attributes dir(i))
getattr(i, 'denominator')
==>returns 1 - 15a = 78 , how do you get denominator value directly?a.denominator
- 16i= 78 how can you tell if the attribute conjucate (returned from dir(i) ) is callable?callable(getattr(i,'conjugate'))
==>True - 17how can you test if an object as a particular attribute?i=78
hasattr(i, 'bit_length') - 18how can you get the dictionary representing the global namespace?globals()
- 19how do you put a variable into the global namespace directly using the global dictionary?globals()['tau'] = 6.28
- 20how do you get the dictionary of local variables?locals()
- 21what standard python module provides great detail for object introspection ?inspect module
- 22given a class sorted_set, how do you get the its classes , using the inspect module?inspect.getmembers(sorted_set, inspect.isclass)
- 23if chain is an imported module inside sorted set, will inspect.getmembers(sorted_set, inspect.isclass) reports 'chain' as a class ?Yes
- 24if chain is an imported module (inside sorted_set module) , can you import it directly?Yes
from sorted_set import chain - 25using the inspect module, how can you get the parameters of the __init__() function inside a SortedSet class?init_sig = inspect.signature(sorted_set, SortedSet.__init__)
init_sig.parameters - 26how can you query for default paramaters of Sorted_Set __init__() function (by using inspect module)init_sig = inspect.signature(sorted_set, SortedSet.__init__)
init_sig.parameters
repr(init_sig.parameters['items'].default)
Informationen
- Beschreibung
- python (beyond basics python flashcards) Karteikarten am python beyond introspection, erstellt von Andrew Sperazza am 13/01/2017.
- Erstellt von
- Andrew Sperazza
- Aufrufe
- 1
- Tags
- Bewertung