Linked Questions
48 questions linked to/from Importing module from string variable using "__import__" gives different results than a normal import statement
0
votes
2
answers
1k
views
Possible to call function from variable module? [duplicate]
file1.py
def foo(x):
print(x)
file2.py
def foo(x):
print(x)
main.py
import file1
import file2
#User inputs either file1 or file2
variable = input()
#--
#TODO: A way to call the correct ...
user avatar
user12035491
0
votes
2
answers
1k
views
run python file from another file with dynamic path [duplicate]
I try to run command in my python file, which located in dynamic file. I try to use the import statement, which as I understand is the better solution for this case.
Here is the code:
from ...
0
votes
1
answer
762
views
Pythonic way to import module whose name is only known at runtime? [duplicate]
Given the following folder structure:
executioner/:
- executioner.py
- library/:
- __init__.py
- global_functions.py
- oakalleyit.py
If I wanted to access a function inside of either ...
2
votes
0
answers
2k
views
How to eval import in python? [duplicate]
I get the following error. Is there a way to eval import?
>>> eval('import os')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<string>", ...
-1
votes
1
answer
621
views
Import a class with a string [duplicate]
Given dot-notation of a python class, how would I import it if it's given as a string?
For example:
>>> from ingest.models import ItemInstance
>>> ItemInstance
<class 'ingest....
1
vote
1
answer
772
views
Get all functions from directory in Python [duplicate]
I have an API that has functions (e.g. function1, function2, etc) where each function is placed in a file (file1, file2, etc) and all files are in a directory, dir. The structure is as so:
dir
-> ...
0
votes
2
answers
633
views
How can I import a module named [userinput] in Python 3.6? [duplicate]
I'm trying to take the user's input, and see if there's a module named whatever they input. If there is, I then want that module to be imported, and to call a function within it of the same name. I ...
0
votes
1
answer
610
views
How to get function value from txt file with exec Python [duplicate]
I want to execute python code from txt file and store it.
In txt file I have this code:
def func(a):
return a
In python:
def random_file_input(file_name):
ran_number = random.randint(0, 100)
...
-3
votes
1
answer
510
views
Is it possible to import modules and call functions based on user input? [duplicate]
Is it possible to call modules and functions with user input in Python?
For example:
a = input("Module: ")
import a
b = input("Function: ")
a.b()
0
votes
0
answers
502
views
NLTK function from string variable isn't callable [duplicate]
I have a list of related function names which I want to iterate thru, calling the function held in the variable. But no matter how I try it, I get: "TypeError: 'TweetTokenizer' object is not ...
0
votes
1
answer
291
views
how to import module in python using string [duplicate]
I have a string which contains the name of a library that I want to import. How can I import that library dynamically?
For example:
library = "mylibrary"
0
votes
0
answers
404
views
Module not importing with eval inside of function [duplicate]
Lets say I have some function that gets called during runtime. In this function I want to import a module given a name as argument.
This is the basic idea. Essentially I have a directory full of ...
0
votes
1
answer
274
views
How to dynamically import a module in Python [duplicate]
I'm trying to import files based on their name, for example:
project /
__init__.py
log.py
conf /
__init__.py
logger_settings.py
other_settings.py
In my conf/...
Vor's user avatar
- 35.6k
-1
votes
1
answer
106
views
Can I use a function to either import or install a module [duplicate]
I am running Windows 7, Python 2.7, Anaconda 4.0.0:
Here is what I want to do. I want to take this code and put it in a function.
try:
import easygui
except ImportError:
from os import system
...
1
vote
1
answer
57
views
Import File from File Directory (Python) [duplicate]
Currently, I have the directory to a file
"../Model.py"
This model has a class called Test.
Using the string of the directory, I want to import and use the class Test.
How do I do so?
(The String ...