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

    Import doc ..-- Link for reference . The __init__.py files are required to make Python treat the directories as containing packages, this is done to prevent directories with a common name, such as string, from unintentionally hiding valid modules that occur later on the module search path.

  2. 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.

  3. 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 ...

  4. importing external ".txt" file in python - Stack Overflow

    I am trying to import a text with a list about 10 words. import words.txt That doesn't work... Anyway, Can I import the file without this showing up? Traceback (most recent call last): File "D:/python/p1.py", line 9, in <module> import words.txt ImportError: No module named 'words' Any sort of help is appreciated.

  5. Importing files in Python? - Stack Overflow

    Mar 28, 2013 · By default, Python won't import modules from the current working directory. There's 2 (maybe more) solutions for this: PYTHONPATH=. python my_file.py which tells python to look for modules to import in ., or: sys.path.append(os.path.dirname(__file__)) which modifies the import path on runtime, adding the directory of the 'current' file.

  6. python - Reading JSON from a file - Stack Overflow

    If you are reading the data from the Internet instead, the same techniques can generally be used with the response you get from your HTTP API (it will be a file-like object); however, it is heavily recommended to use the third-party Requests library instead, …

  7. How to import a .pyd file as a python module? - Stack Overflow

    May 11, 2018 · .pyd is basically a Windows .dll file..pyd files are dll’s, but there are a few differences. If you have a DLL named foo.pyd, then it must have a function PyInit_foo(). You can then write Python import foo, and Python will search for foo.pyd (as well as foo.py, foo.pyc) and if it finds it, will attempt to call PyInit_foo() to initialize

  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. python - How can I import a module dynamically given the full …

    def import_module_from_file(full_path_to_module): """ Import a module given the full path/filename of the .py file Python 3.4 """ module = None try: # Get module name and path from full path module_dir, module_file = os.path.split(full_path_to_module) module_name, module_ext = os.path.splitext(module_file) # Get module "spec" from filename spec ...

  10. How do I load a file into the python console? - Stack Overflow

    So if you are running this directly from the python command prompt then any variables, functions, etc. that you defined in your script would be available in your python session. – amicitas Commented Jun 16, 2021 at 13:15

Refresh