Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Importing Help
#1
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
Reply
#2
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)?
Reply
#3
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
Reply
#4
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.
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020