python-import

How to call an imported module knowing its name as a string?

How to call an imported module knowing its name as a string? Question: I am writing an application that should test the solution of many students. I have structure like this app/ students/ A/ lab1/ solution.py lab2 solution.py B/ lab1/ solution.py C/ test.py I want to import the solution file in the testing module and …

Total answers: 1

Does pip provide a TOML parser for python 3.9?

Does pip provide a TOML parser for python 3.9? Question: I want to parse TOML files in python 3.9, and I am wondering if I can do so without installing another package. Since pip knows how to work with pyproject.toml files, and I already have pip installed, does pip provide a parser that I can …

Total answers: 3

How to configure a PYTHONPATH env variable in the Dockerfile?

How to configure a PYTHONPATH env variable in the Dockerfile? Question: I am modifying the Machine Learning Inference to perform inference using my trained model and to this it is need to import a set of modules. So the project tree is now: . ├── Dockerfile ├── __init__.py ├── app.py ├── requirements.txt ** └── maskrcnn …

Total answers: 3

Using different classes (one imported and one defined) with the same name in a module

Using different classes (one imported and one defined) with the same name in a module Question: from .models import User, AuctionListing, Comment, Bids, Category, Watchlist, Activities, Winners and class Comment(forms.Form): comment = forms.CharField(label="", widget=forms.Textarea(attrs={ ‘placeholder’: ‘Comment’, ‘class’: ‘listing_textarera’ })) Class name is Comment. I have imported from .models and individual definition as above. Here is …

Total answers: 1

Custom module not found python

Custom module not found python Question: I’m building a simple telegram bot and i need to create many .py files to order the project but when I try to run the code, the terminal displays this error message: from consts.Key import Values ModuleNotFoundError: No module named ‘consts’ The project folder is structured like this: | …

Total answers: 1

I need to import function from another file

I need to import function from another file Question: I know how to import functions from normal files… but my file name is ‘selection sort’ it contains a space in between is there a way to import function from these without renaming it I tried import selection sort and import selection_sort… both didn’t work I …

Total answers: 2

How do I correctly import models in Python if I'm having such directories?

How do I correctly import models in Python if I'm having such directories? Question: I’m using Django-REST framework with a telegram-bot in here. I need to import models from Django inside my telegram-bot file. I’m getting module not found error and probably thinking something wrong. Telegram-bot file is commands.py and the django models is models.py. …

Total answers: 2

When using importlib to load a module, can I put it in a package without an __init__.py file?

When using importlib to load a module, can I put it in a package without an __init__.py file? Question: My Python application loads plugins from a user-specified path (which is not part of sys.path), according to the importlib documentation: import importlib.util import sys def load_module(module_name, file_path): spec = importlib.util.spec_from_file_location(module_name, file_path) module = importlib.util.module_from_spec(spec) sys.modules[module_name] = …

Total answers: 1

python import yaml – but which one?

python import yaml – but which one? Question: Ok, so you clone a repo, there’s an import import yaml ok, so you do pip install yaml and you get: ERROR: No matching distribution found for yaml Ok, so you look for a package with yaml in it, and there’s like a gazillion of them… usually …

Total answers: 5