About 307,000 results
Open links in new tab
  1. How do I import other Python files? - Stack Overflow

    Jun 3, 2024 · You do not have many complex methods to import a python file from one folder to another. Just create a __init__.py file to declare this folder is a python package and then go to your host file where you want to import just type . from …

  2. python - How do I call a function from another .py file ... - Stack ...

    First, import function from file.py: from file import function Later, call the function using: function(a, b) Note that file is one of Python's core modules, so I suggest you change the filename of file.py to something else. Note that if you're trying to import functions from a.py to a file called b.py, you will need to make sure that a.py and ...

  3. python - Importing files from different folder - Stack Overflow

    from application.app.folder.file import func_name to: from .application.app.folder.file import func_name Adding the dot instructs Python to look for the application folder within the current folder, instead of in the Python install folder.

  4. How to import another python script (.py) into main python file

    Jun 12, 2017 · Unable to import one python file into another. Related. 2. Importing a script into another script. 87.

  5. python - Importing variables from another file? - Stack Overflow

    Jan 11, 2017 · Import file1 inside file2:. To import all variables from file1 without flooding file2's namespace, use: import file1 #now use file1.x1, file2.x2, ... to access those variables

  6. How to include external Python code to use in other files?

    Apr 3, 2009 · As mikey has said, this will work if you want to have variables in the included file in scope in the caller of 'include', just insert it as normal python. It works like an include statement in PHP. Works in Python 3.8.5.

  7. How to import a Python class that is in a directory above?

    Jun 28, 2009 · # subfile.py OR some_other_python_file_somewhere_else.py import random # This is a standard package that can be imported anywhere. import top_level_file # Now, top_level_file.py works similarly. print(top_level_file.x) This is different than what I was looking for: I hoped python had a one-line way to import from a file above.

  8. Importing from a relative path in Python - Stack Overflow

    Python has a concept of packages, which is basically a folder containing one or more modules, and zero-or-more packages. When we launch python, there are two ways of doing it: Asking python to execute a specific module (python3 path/to/file.py). Asking python to execute a package. The issue is that import.py makes reference to importing .math

  9. How to import .py file from another directory? [duplicate]

    Apr 9, 2014 · @Torxed Found the way using link provided by you. Which was I needed to use import from app folder name like: from my_app.model import py_file. I tried something similar like from addons.my_app.model import py_file. When that didn't work, I thought I needed to do something else and skipped the part importing just from app directory. –

  10. How to import functions from other projects in Python?

    Ideally both projects will be an installable python package, replete with __init__.py and setup.py. They could then be installed with python setup.py install or similar. If that is not possible, don't use execfile()! Manipulate the PYTHONPATH to add Foo so that import Project1.file1 works. For example, from Project2/fileX.py:

Refresh