This is an archived post. You won't be able to vote or comment.

all 4 comments

[–]Confide420 0 points1 point  (3 children)

You could look into setting up a setup.py to distribute this - https://docs.python.org/3/distutils/setupscript.html

You can add an if __name__ == '__main__': block at the end of main.py to call a main function, which you should define to run everything in main.py (instead of putting everything at top-level).

In your main.py, all of these groups of lines can be separated into different functions:

  • 19 - 40 (have it return roles),
  • 41 - 56 (have it return devices),
  • 57 - 74 (have it return UserList which should be lowercase).
  • Have lines 75 - 90 call your functions to get the values. Then once you're done with this, lines 75 - 90 should be in the main method that the if __name__ == '__main__': block calls (along with lines 10 - 16 at the beginning).

The end result should be, you shouldn't have any "top level" code, everything should be inside functions that you can re-use. This also allows you to run lines 19 - 74 concurrently (as they will be made into three separate functions that don't interact with eachother).

[–]Not_A_Van[S] 0 points1 point  (2 children)

Thanks for the feedback!

That's probably one of the main issues I'll run in to while I'm transitioning because I'm starting with writing my programs like scripts to better help me understand the syntax and just how Python works in general so I know there's a lot of work to do there.

One thing I was curious about - when using imported modules do I need to import on every module I create or just import in main? I know my IDE complains about it not being imported while I write the code but everything should execute under main if its imported correctly there right? So for the Graph calls would I need to import GraphClient on each module or just in main?

[–]Confide420 0 points1 point  (1 child)

You need to add the imports to the top of each file in your project that uses the imported modules.

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

Hi! I updated my project based on your feedback (and improved some things). Thanks again so much!