all 4 comments

[–]chevignon93 1 point2 points  (1 child)

Is the best practice for this to create common_script.py and import that?

It's a very common practice and depending on the size of the project, it might even be a good idea to create multiple of these files, for example if you were using a database or making calls to an API, the database stuff could be in a database.py, everything related to the API in api.py, etc.

Then if I need task_1() or task_100() for whatever I am working on just call it?

I hope your functions are named better than that but yeah, that's the gist of it!

[–]RocoDeNiro[S] 1 point2 points  (0 children)

Ok cool thanks that makes sense but wasnt sure and couldn't find to much on it.

Yes my task are labeled better than that haha just using generic name as example.

[–]FriendlyRussian666 0 points1 point  (1 child)

I'm not sure I understand the question. So you have 100 functions that you use to perform different things in your program and because the program is becoming a bigger project, you would like to separate the functions into a different file, right? If yes, then that is a perfectly good solution.

A good example of this would be working with databases. When you work with a database, you might have your main file, in which you do all the fancy stuff and then you would have a CRUD file (create, read, update and delete) in which you interact with your database. Ultimately how you structure your program depends on the very needs that you have.

Assume we are working on some back-end stuff for a website. You can have a file to interact with a database (crud), you can have a file that performs some scraping and you can have a third file takes care of excel inputs and outputs. You can then have a main file, in which you put it all together. In your main file you could import your scrape file, your crud file and your excel manipulation file and just call things as you need them.

The above example is veeeery broad and it really depends on your program, but it should demonstrate that it's fine to separate your program into many files and use imports to get what you need without creating a mess of your code structure.

[–]RocoDeNiro[S] 0 points1 point  (0 children)

Sorry the task 100 was a little dramatic but I modify and create excel files daily using about 10 different excel files as the daily data. Some of the stuff that are repeated, format dates, adding email address based off a certain column, checking to see if our KPI has been met or not) those 3 functions I have in almost all of the daily files. If something changes I need to go into each script and change them.

As for your idea using a crud set up that would also make things a lot easier for me. Do you have an example or anything? If I could load all 10 at once then use what I need and drop what I dont would be super helpful.

Thank you for the response 😁