How namespaces work in Python

Published: 02 November 2020
on channel: d p
27
0

Explains briefly how to use a namespace
try from the python prompt
import this

code
#!/usr/bin/env python
func_demo.py
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
func_demo_in.py
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)
#total=func_demo.addme(a,b)
print(total)#!/usr/bin/env python3
func_demo_in.py
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.


Watch video How namespaces work in Python online without registration, duration hours minute second in high quality. This video was added by user d p 02 November 2020, don't forget to share it with your friends and acquaintances, it has been viewed on our site 27 once and liked it 0 people.