from file1 import *  

will import all objects and methods in file1

Answer from ennuikiller on Stack Overflow
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ how-to-import-variables-from-another-file-in-python
How to import variables from another file in Python? - GeeksforGeeks
July 23, 2025 - We can use any Python source file as a module by executing an import statement in some other Python source file. When the interpreter encounters an import statement, it imports the module if the module is present in the search path.
Discussions

How would I import variables from one python file to another when they are in two different folders but in the same directory?
When you run a Python script, you can't import anything that's not either a site package or underneath the enclosing folder. You can't go "up and over" and import. More on reddit.com
๐ŸŒ r/learnpython
5
1
December 14, 2023
python - Importing files from different folder - Stack Overflow
I have this folder structure: application โ”œโ”€โ”€ app โ”‚ โ””โ”€โ”€ folder โ”‚ โ””โ”€โ”€ file.py โ””โ”€โ”€ app2 โ””โ”€โ”€ some_folder โ””โ”€โ”€ some_file.py How can I import a function from file.py, from within som... More on stackoverflow.com
๐ŸŒ stackoverflow.com
How to import variable from another file if another file write the code inside def main():
The whole purpose of a function is to enclose local variables and not expose them to the outside. If you want a function to have some value from main, you pass that value as an argument when you call that function. def main(): v = 1 otherfunc(v) def otherfunc(v): #now otherfunc has access to v's value print(v) More on reddit.com
๐ŸŒ r/learnpython
11
0
March 26, 2022
python - How to import variable from another function and another directory? - Stack Overflow
0 How can I call a function that is stored as a variable from a python file that is also stored as a variable? 0 How to import a variable from a function in a different directory More on stackoverflow.com
๐ŸŒ stackoverflow.com
๐ŸŒ
Medium
medium.com โ€บ @gl7526 โ€บ importing-variables-from-another-file-5afcdaa6c8df
Importing Variables From Another File | by George | Medium
November 17, 2020 - Instead, weโ€™re going to run through ... way to do so is to have a regular Python file that you want to import variables from, and the file you want to import the variable to, in the same directory....
๐ŸŒ
Dive into Python
diveintopython.org โ€บ home โ€บ learn python programming โ€บ variables in python โ€บ how to import variables from files
Examples of Import Variables and Exporting Strings to Files in Python
May 3, 2024 - By assigning an alias during import (as alias_variable), you can provide a clearer name within the current file context, improving code understanding. Python supports importing modules from different directories using absolute or relative paths.
๐ŸŒ
CodeBurst
codeburst.io โ€บ importing-variables-from-other-files-in-python-96a200f410da
Importing variables from other files in Python | by aneesh joshi | codeburst
June 30, 2017 - As a โ€œformerโ€ โ€” C programmer, I am often shocked by some of the things that Python can do. In this post, I will discuss one of these things. Letโ€™s consider two files A.py and B.py in the same folder. ... When the line from A import a is executed, the python interpreter executes the referenced script (A.py) automatically.
๐ŸŒ
EyeHunts
tutorial.eyehunts.com โ€บ home โ€บ python import variable from another file | example code
Python import variable from another file | Example code
August 1, 2022 - First import the file from the current program, then you can import the variable or access the variable in Python. There are three approaches to importing variables from another file.
Find elsewhere
๐ŸŒ
Sololearn
sololearn.com โ€บ en โ€บ Discuss โ€บ 2988478 โ€บ python-importing-a-variable-from-another-file-without-its-functions
https://www.sololearn.com/en/Discuss/2988478/pytho...
sl_scroll_/de/Discuss/2689918/i-made-a-bmi-calculator-in-python-and-youa-are-supposed-to-write-the-height-in-meter-i-want-whenever-you-write-the-height-in-cePending
๐ŸŒ
YouTube
youtube.com โ€บ watch
PYTHON : Importing variables from another file? - YouTube
PYTHON : Importing variables from another file? [ Gift : Animated Search Engine : https://www.hows.tech/p/recommended.html ] PYTHON : Importing variables fr...
Published: December 5, 2021
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python-import-module-from-different-directory
Python โ€“ Import module from different directory - GeeksforGeeks
June 20, 2024 - # importing sys from module1 import odd_even, add import sys # adding Folder_2 to the system path sys.path.insert(0, '/home/amninder/Desktop/Folder_2') # importing the add and odd_even # function # calling odd_even function odd_even(5) # calling add function print("Addition of two number is :", add(2, 2)) ... Similarly, if you don't want to use the sys module to set the path of the new directory. You can assign a directory path to the PYTHONPATH variable and still get your program working.
๐ŸŒ
CodeRivers
coderivers.org โ€บ blog โ€บ python-import-variable-defined-in-another-file
Python: Importing Variables Defined in Another File - CodeRivers
February 22, 2026 - When we import a module, Python creates a module object in memory and executes the code in that module file. Any variables defined in the module become attributes of the module object. The simplest way to import variables from another file is to import the entire module.
๐ŸŒ
YouTube
youtube.com โ€บ watch
Importing variables from another file? - YouTube
Become part of the top 3% of the developers by applying to Toptal https://topt.al/25cXVn--Music by Eric Matyashttps://www.soundimage.orgTrack title: Lost Civ...
Published: March 12, 2023
๐ŸŒ
Python Forum
python-forum.io โ€บ thread-23800.html
Importing variables from another file
January 17, 2020 - I've been googling this problem for a while now and nothing seems to work. Here's my problem: I have variables in 4 different files. I want these variables to be read by my main file. I started programming today, so I thought a simple text based c...
๐ŸŒ
Towards Data Science
towardsdatascience.com โ€บ home โ€บ data science โ€บ common mistakes when dealing with multiple python files
Common Mistakes When Dealing with Multiple Python Files | Towards Data Science
May 10, 2021 - But sometimes we really want to have a GLOBAL variable that can be accessed, modified by every Python file in the directory. The canonical way to achieve this is to create another file with your GLOBAL variables.
๐ŸŒ
Reddit
reddit.com โ€บ r/learnpython โ€บ importing a variable from another python file imports everything?
r/learnpython on Reddit: Importing a variable from another python file imports everything?
February 17, 2022 -

Hi guys, I am currently working on some assignments from Python Crash course book for self study, however, I am trying to import a specific list from a few files and this leads to the running of all previous code, what am I doing wrong?

Here are the links to the series of python files in chronological order:

  1. https://pastebin.com/zqpp3Auv

  2. https://pastebin.com/9PxNzBM7

  3. https://pastebin.com/rjeapb8J

Here is the resulting output of the third python file: https://pastebin.com/zT6Nvu5V

What am I doing wrong?