Can you separate python projects logically into separate files/classes like in C#/Java?
I'm looking to develop a project in python and all o开发者_Python百科f the python I have done is minor scripting with no regard to classes or structure. I haven't seen much about this, so is this how larger python projects are done?
Also, do things like "namespaces" and "projects" exist in this realm? As well as object oriented principles such as inheriting from other classes?
Yes, you can, and you should! :)
Here is a nice introduction to Python Modules (including packages).
Correction: you probably should not put each single class into a separate file (like Java mandates and many C++ places do). The language is pretty lax about it as you can see in the linked tutorial, keep an open eye on other projects, use common sense, and do whatever makes sense to you (or whatever is being done in your team/project - unless it is very wrong).
You can put code (classes, function defs, etc) into python modules (individual source files), which are then imported with import
. Typically like functionality (like in the Python standard library) is contained within a single module.
You can do that, but usually they are arranged a bit different.
You can take a look to the source code of one python application.
Here's one: "JaikuEngine" which powers the website http://www.jaiku.com/
Yes.
You can put python classes into separate files, use namespaces for scoping, then place this into Modules which can be loaded from other scripts.
精彩评论