Python Forum
i have hundreds of Python functions
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
i have hundreds of Python functions
#1
i have hundreds of Python functions and often use quite many of them. there are two major methods i have tried to import these functions. method 1 keeps each function in a separate file in a directory listed in the PYTHONPATH environment variable. method 2 merges all (or some) of the functions in one single file which is placed in a directory listed in the PYTHONPATH environment variable. method 1 has the disadvantage of requiring a separate import statement for each function. method 2 has the disadvantage of importing a huge file (just once per script that needs it). it has over 34000 lines.

i'm curious if Python has any alternatives that could be more efficient or have less of an impact.
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply
#2
You have presented two extremes. It is best to be in the middle. Organize your functions into multiple different files based on what they do. Then you should be importing one or two files that are smaller but still each contain multiple functions. That should be enough for whatever particular task you are doing.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply
#3
so, group them into categories where i will typically not need them all for a project and merge each category into its own module?
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply
#4
Yeah. Look at the built-in packages. They didn't put all the extra functions and classes into one package. They organized them into different packages based on their functionality.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply


Forum Jump:

User Panel Messages

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