Python Forum
using module variable - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/Forum-Python-Coding)
+--- Forum: General Coding Help (https://python-forum.io/Forum-General-Coding-Help)
+--- Thread: using module variable (/Thread-using-module-variable)



using module variable - jacklee26 - Nov-12-2019

Hi All,
i'm trying to learn how to write a module, and meet some problem.
Is there any method we can used a variable inside a module, when we are outside the module.

I have two code, one is the module code(input_mod.py), another one is the main code(main_mod.py).
My question is how can i used the name (which is in the module) this variable in main_mod.py.

i used this print(mod.module.name()), doesn't work.




input_mod.py
def module():
    name = input ("Please enter your name:")
    print ("hell0", name)
    return 

main_mod.py
import input_mod
input_mod.module()



RE: using module variable - ThomasL - Nov-12-2019

Just return the name
def module():
    name = input ("Please enter your name:")
    print ("hell0", name)
    return name
	
import input_mod
name = input_mod.module()



RE: using module variable - jacklee26 - Nov-12-2019

thanks ThomasL

what if i have more than one variable, can we also return more than one variable.
example
def module():
    name = input ("Please enter your name:")
    class1 = input ("Please enter your class:")
    print ("hell0", name)

    return name, class1


import input_mod
aa=input_mod.module()
print (aa)

how can i print name and class like this way==> print ("name:", name, "","class", class1)
is there any method we can do like this


RE: using module variable - ThomasL - Nov-12-2019

import input_mod
name, class1 = input_mod.module()
print("Name:", name, "","Class:", class1)



RE: using module variable - jacklee26 - Nov-13-2019

thanks alot thomasL