Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
22
Task/Introspection/Python/introspection-1.py
Normal file
22
Task/Introspection/Python/introspection-1.py
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
# Checking for system version
|
||||
import sys
|
||||
major, minor, bugfix = sys.version_info[:3]
|
||||
if major < 2:
|
||||
sys.exit('Python 2 is required')
|
||||
|
||||
|
||||
def defined(name): # LBYL (Look Before You Leap)
|
||||
return name in globals() or name in locals() or name in vars(__builtins__)
|
||||
|
||||
def defined2(name): # EAFP (Easier to Ask Forgiveness than Permission)
|
||||
try:
|
||||
eval(name)
|
||||
return True
|
||||
except NameError:
|
||||
return False
|
||||
|
||||
if defined('bloop') and defined('abs') and callable(abs):
|
||||
print abs(bloop)
|
||||
|
||||
if defined2('bloop') and defined2('abs') and callable(abs):
|
||||
print abs(bloop)
|
||||
4
Task/Introspection/Python/introspection-2.py
Normal file
4
Task/Introspection/Python/introspection-2.py
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
try:
|
||||
print abs(bloop)
|
||||
except (NameError, TypeError):
|
||||
print "Something's missing"
|
||||
6
Task/Introspection/Python/introspection-3.py
Normal file
6
Task/Introspection/Python/introspection-3.py
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
def sum_of_global_int_vars():
|
||||
variables = vars(__builtins__).copy()
|
||||
variables.update(globals())
|
||||
print sum(v for v in variables.itervalues() if type(v) == int)
|
||||
|
||||
sum_of_global_int_vars()
|
||||
Loading…
Add table
Add a link
Reference in a new issue