-2
Good afternoon, everyone.
I am in a dilemma when making the FROM statement. import to import the modules, as follows below:
- For this utility, I do not want and cannot pass the FROM.. import declaration at the beginning of the script, I need to call directly in the function. Here is a problem, because it is a function somewhat generic, it was to be at least. It is a function that depending on the option the user chooses will need a different module, so my idea is to pass the modules by variable and use these variables in the FROM declaration.. import as follows below:
both the module directory name and the class name is test, for example.
var_concorrente = teste
from + var_concorrente import var_concorrente
the problem is that this way does not work.
Could someone help me?
I don’t want to make a very big script and it will be if you’re not good, if you can’t find a solution to this.
Let me try to improve my question.
The normal from would be like this:
from source.netspeed.netspeed import Netspeed
source is the name of the directory containing all the modules.
The first netspeed is the client directory
The second netspeed is the name of the module
Netspeed is the name of the class inside the netspeed module
I have to go through all this for parameter, like this:
client = "netspeed" from_estructure = "source."+ client+"."+ client
declare from using these variables:
from from_estructure import client.capitalize()
Grateful to all.
Can you give a concrete example of what you want to do? For example, showing at least two different modules that would be imported by the function, show what is the idea of this function and what would be the calls to each module?
– Woss
Let me try to improve my question. The normal from would look like this: from source.netspeed.netspeed import Netspeed The source is the name of the directory that contains all the modules. The first netspeed is the client directory The second netspeed is the module name Netspeed is the class name inside the netspeed module I have to pass all this by parameter, like this: client = "netspeed" from_estructure = "source."+ client+"."+ client declare from using these variables: from from_estructure import client.capitalize()
– Cleber Nandi
The name of the module at all times is the same as the client directory name? And the class name, will always be
Netspeed
, client independent?– Woss
The module name will always be the client name with low box, and the Class will always be the module name with first letter high box.
– Cleber Nandi
Do all classes that can be imported have the same contract? That is, it will be guaranteed that the methods and attributes you use in the function exist in all possible classes?
– Woss
No. Several functions not equal, but each client has a specific function, so I’ve separated them into modules. Otherwise I’d use them all in the same module, I guess.
– Cleber Nandi
So after importing the class how will you know which methods you can use from it? This is looking like a XY problem, in which you try to implement something you think is the solution, but it is not.
– Woss
Why this will be called via the menu created for this. I have a menu to, for example, print a sum, so when the client chooses this menu, it will be this information passed by the parameter.
– Cleber Nandi