I am writing a game in Python that has many classes and methods, and I want to know if it is advantageous to store the classes in the main python .py file or store each category of classes in separate files, then import them. This would help with organization, but are there any other pros/cons?

有帮助吗?

解决方案

It's my understanding that the result of import is essentially making the compiler jump to that file and parse it in place of the import line. Basically making it like the entire file was pasted into the file doing the importing, at the line where the import happens.

So essentially, it's helpful with organization and sanity. Once a project starts to get large enough, it would be impractical to maintain all the code in a single file.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top