Python Forum

Full Version: module to store functions/variables and how to call them?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Can I create a module to store all my functions?
for instance could i have a module that contains every function I need for my program, and if so how do I call on them?

Can I create a module that hosts only variables? If so how do I call on them?

Appreciate the help and apologize for noob questions.
variables.py
VARIABLE1 = 'Variable1'
my_funtions.py
def function1(something):
    print(something)
another.py
import variables
import my_funtions

my_funtions.function1(variables.VARIABLE1)
Output:
Variable1
A program reads code line for line and execute according to its structure. Variables are defined and store specific values and information given to them according to the writers need or wants and they are called and used accordingly.
If you are trying to save time in writing the code using modules containing variables in one and functions in another makes no viable sense and even if it were possible, and I do not believe it is, it would be more work in writing the code instead of writing it with conventional means.

But of course I could be wrong in what you are trying to do and this reply may not apply.
(Jun-03-2020, 06:15 PM)DT2000 Wrote: [ -> ]A program reads code line for line and execute according to its structure. Variables are defined and store specific values and information given to them according to the writers need or wants and they are called and used accordingly.
If you are trying to save time in writing the code using modules containing variables in one and functions in another makes no viable sense and even if it were possible, and I do not believe it is, it would be more work in writing the code instead of writing it with conventional means.

But of course I could be wrong in what you are trying to do and this reply may not apply.

in other languages I've used I find it makes my code more organized and easier for me to maintain, just a preference I guess.

(Jun-03-2020, 06:10 PM)Yoriz Wrote: [ -> ]variables.py
VARIABLE1 = 'Variable1'
my_funtions.py
def function1(something):
    print(something)
another.py
import variables
import my_funtions

my_funtions.function1(variables.VARIABLE1)
Output:
Variable1

ty!