Python Forum
module to store functions/variables and how to call them?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
module to store functions/variables and how to call them?
#1
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.
Reply
#2
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
Reply
#3
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.
"Often stumped... But never defeated."
Reply
#4
(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!
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  importing variables from module 8376459 1 274 Feb-18-2024, 02:24 PM
Last Post: deanhystad
  How to store columns of a .csv in variables (when the .csv has no headers) ? hobbyist 6 1,257 Aug-18-2023, 02:06 PM
Last Post: deanhystad
  using variables with functions imported from different files. Scordomaniac 3 1,271 May-24-2022, 10:53 AM
Last Post: deanhystad
  Storing whole functions in variables dedesssse 3 2,090 Jul-29-2021, 09:17 PM
Last Post: deanhystad
  Getting parent variables in nested functions wallgraffiti 1 2,139 Jan-30-2021, 03:53 PM
Last Post: buran
  How to call multiple functions sequentially Mayo 2 9,336 Jan-06-2021, 07:37 PM
Last Post: Mayo
  how do i store then call a mp3 from sqlite3 .db file gr3yali3n 3 5,724 Dec-11-2020, 10:28 AM
Last Post: snippsat
  local/global variables in functions abccba 6 3,429 Apr-08-2020, 06:01 PM
Last Post: jefsummers
  How to access variables from dirsync module steve_shambles 3 3,857 Apr-02-2020, 08:18 AM
Last Post: steve_shambles
  Python 2.7 passing variables from functions zetto33 1 1,778 Mar-19-2020, 07:27 PM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020