Linked Questions

0 votes
2 answers
1k views

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
0 votes
2 answers
1k views

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 ...
Or Smith's user avatar
  • 3,626
0 votes
1 answer
762 views

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 ...
Soviero's user avatar
  • 1,912
2 votes
0 answers
2k views

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>", ...
user1424739's user avatar
  • 14.2k
-1 votes
1 answer
621 views

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

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

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

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

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 ...
C. Kelly's user avatar
  • 162
0 votes
1 answer
291 views

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"
monster's user avatar
  • 59
0 votes
0 answers
404 views

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 ...
Paul Brink's user avatar
0 votes
1 answer
274 views

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

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

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

15 30 50 per page
1
2 3 4