filmov
tv
How namespaces work in Python

Показать описание
Explains briefly how to use a namespace
# try from the python prompt
# import this
code
#!/usr/bin/env python
# basic function
# scope of variable
# how import module
# namespace
# the ...
def addme(val1,val2):
z = val1 + val2
# this ok - local scope
# z is only available in the function
# print("In the function",z)
return z
# run only if from the command line
if __name__ == "__main__":
x = int(input("Enter a value for x "))
y = int(input("Enter a value for y "))
total=addme(x,y)
print(total)
else:
... # ... is how a non-op works in python
#Done.
---------------------------------------------------------------
#!/usr/bin/env python
# basic function
# how import module
# namespaces
# import this
# you have two options here ...
from func_demo import addme
# or
#import func_demo
a = int(input("Enter a value for a "))
b = int(input("Enter a value for b "))
total=addme(a,b)
print(total)#!/usr/bin/env python3
# basic function
# how import module
# namespaces
# import this
from func_demo import addme
#import func_demo
a = int(input("Enter a value for a "))
b = int(input("Enter a value for b "))
total=addme(a,b)
print(total)
#Done.
# try from the python prompt
# import this
code
#!/usr/bin/env python
# basic function
# scope of variable
# how import module
# namespace
# the ...
def addme(val1,val2):
z = val1 + val2
# this ok - local scope
# z is only available in the function
# print("In the function",z)
return z
# run only if from the command line
if __name__ == "__main__":
x = int(input("Enter a value for x "))
y = int(input("Enter a value for y "))
total=addme(x,y)
print(total)
else:
... # ... is how a non-op works in python
#Done.
---------------------------------------------------------------
#!/usr/bin/env python
# basic function
# how import module
# namespaces
# import this
# you have two options here ...
from func_demo import addme
# or
#import func_demo
a = int(input("Enter a value for a "))
b = int(input("Enter a value for b "))
total=addme(a,b)
print(total)#!/usr/bin/env python3
# basic function
# how import module
# namespaces
# import this
from func_demo import addme
#import func_demo
a = int(input("Enter a value for a "))
b = int(input("Enter a value for b "))
total=addme(a,b)
print(total)
#Done.