Pregunta

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?

¿Fue útil?

Solución

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.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top