Importing Help - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: Importing Help (/thread-34688.html) |
Importing Help - mkgrtn - Aug-20-2021 Hello I am a newbie in python programming and I would appreciate any help. TYIA I have a program called ptemp which is composed of the following import requests import pandas and another 20 imports. I wqould like to know if I can call ptemp from another program to use all the imports by just coding one line right now i have to manually do ctrl-a ctrl-c in ptemp and do a ctrl-v in the new program. thank you RE: Importing Help - bowlofred - Aug-21-2021 That depends on what you mean by "call ptemp". Does ptemp define some functions/classes that you want to use? If so, yes you might be able to just import that one file and then call the functions or methods that it defines. But if you want to just use ptemp as a way to avoid creating a lot of imports and still reference those modules, no that wouldn't be common. Right now I can't tell exactly what you want to do. Can you give a more concrete example (show code)? RE: Importing Help - mkgrtn - Aug-21-2021 Thank you bowlofred But if you want to just use ptemp as a way to avoid creating a lot of imports and still reference those modules, no that wouldn't be common That what I was asking for a way to avoiding creating a lot of imports Thank you once again RE: Importing Help - bowlofred - Aug-21-2021 To call your methods and use the classes, they have to be in a namespace. The import not only loads the code it sets up the namespace for them to appear in. You could expose all the modules from within your module, but you'd have to call them them from that module's namespace. That would save you from doing the import, but it would be a lot of other work to maintain. I wouldn't recommend trying to do that. |