GoConqr has a new look! Let us know what you think.

Flashcards

python beyond introspection

Andrew Sperazza python English 26 cards

Cards in this deck (26)

  1. 1i = 7 type(i) ==>?
  2. 2int ==>
  3. 3repr(int)""
  4. 4i=7 type(I) is int ==>true
  5. 5i = 7 x = type(i)(78) x=?78
  6. 6i = 78 type(type(i))
  7. 7i=78 i.__class__ ==> ?
  8. 8i=78 i.__class__.__class__ => ?
  9. 9i=78 i.__class__.__class__.__class__ = ?
  10. 10issubclass(type,object) ?True
  11. 11type(object) ?
  12. 12isinstance(i, int) ?True
  13. 13i = 78 how do you get a list of attribute names for the instance i ?dir(i)
  14. 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
  15. 15a = 78 , how do you get denominator value directly?a.denominator
  16. 16i= 78 how can you tell if the attribute conjucate (returned from dir(i) ) is callable?callable(getattr(i,'conjugate'))
    ==>True
  17. 17how can you test if an object as a particular attribute?i=78
    hasattr(i, 'bit_length')
  18. 18how can you get the dictionary representing the global namespace?globals()
  19. 19how do you put a variable into the global namespace directly using the global dictionary?globals()['tau'] = 6.28
  20. 20how do you get the dictionary of local variables?locals()
  21. 21what standard python module provides great detail for object introspection ?inspect module
  22. 22given a class sorted_set, how do you get the its classes , using the inspect module?inspect.getmembers(sorted_set, inspect.isclass)
  23. 23if chain is an imported module inside sorted set, will inspect.getmembers(sorted_set, inspect.isclass) reports 'chain' as a class ?Yes
  24. 24if chain is an imported module (inside sorted_set module) , can you import it directly?Yes
    from sorted_set import chain
  25. 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
  26. 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)

Information

Description
python (beyond basics python flashcards) Flashcards on python beyond introspection, created by Andrew Sperazza on 13/01/2017.
Created by
Andrew Sperazza
Views
1
Rating

Feedback

What is it about?

What do you think of the new look?

How do you like it?