Questions tagged [python-import]

Need help with understanding how to bring in modules in Python?

What is the process for importing a list of classes from a module?

How can I import only a specific, predefined list of classes from a Python module? Let's say I have modules a.py and b.py in the same directory with the following code: #a.py class Foo(object): '''definition of class Foo goes here''' class Bar(object ...

Exploring pytest integration: mastering the art of importing modules

My current setup involves using py.test to test my python code within the following project structure: -myproject file.py file2.py -test/ input.txt input2.dat test_part.py -regress/ file2_old.py __ini ...

When utilizing os.listdir() in Python, the output is displaying an empty list

Here is the code snippet I'm having trouble with: names = os.listdir(SAVE_PATH + "/temp") After debugging, it seems that the variable names is an empty list []. The SAVE_PATH variable, which is imported from another file, appears to be working ...

The problem with importing a pre-defined Selenium function in the browser

Initial Set-up Working with selenium, I found myself constantly redefining functions. To streamline the process, I decided to create a separate file for these functions and import them as needed in my work files. A Basic Example Initially, when all fun ...

Bringing in a function from a library in Python 2.7

I need assistance with importing the foo function from the mod.py file. In an attempt to resolve this, I have created a new empty file called init.py within the directory C/Users/me/Desktop/NF. I also tried using __init__.py My understanding was that hav ...

Error encountered: Attempting relative import without a known parent package in Python package

The project is structured as shown in the picture: I am attempting to import from "mod.py" into "index.py" from .. import mod However, I encounter the error message: "ImportError: attempted relative import with no known parent package" when trying this op ...

What is the process for starting a Dash App that is contained within a package that has already been installed?

In the process of developing a package, I have structured it with a module containing functions (fed3live.py) and another with a Dash App (fed3_app.py). Here is how the package is organized: fed3live/ ├─__init__.py ├─fed3live/ │ └─fed3live.py ...

Tips on preventing built-in functions from appearing when using the dir function on my modules

Is there a way to prevent built-ins from appearing when using the dir function on a module I have created? For example, I do not want built-in libraries like os, sys, random, struct, time, hashlib, etc. to be displayed. >>> import endesive.pdf. ...

Executing PHP code that imports a Python library

My attempt to execute a Python script from a PHP file is encountering issues when it comes to loading a local library. Surprisingly, the PHP successfully calls the Python script without the local libraries, and manually launching the Python script works fl ...

Troubleshooting Matplotlib and Pyplot Import Problem in Python with Tkinter

Having an issue here where the 'pyplot' element of 'matplotlib' cannot be called. In the given code snippet, I had to include "TkAgg" for the matplotlib element to function properly, as it is a common problem. import matplotlib matplotlib.use("TkAgg") Bu ...

Simple ways to bring a function from a parent directory into your Python script

I am facing an issue with importing a function in my Python project. Despite searching through numerous similar questions on SO, I have been unable to find a suitable solution for my specific problem. The existing answers either lack specificity, are over ...