5

I'm looking to develop a project in python and all of 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?

Mark
  • 6,123
  • 13
  • 41
  • 52
  • 2
    See the following closely related recently asked question: http://stackoverflow.com/questions/2098088/should-i-create-each-class-in-its-own-py-file – Greg Hewgill Jan 21 '10 at 01:25

4 Answers4

3

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).

Bandi-T
  • 3,231
  • 1
  • 20
  • 15
2

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.

  • do things like projects and inheritance exist in the same realm? i should probably edit my question to include this :) – Mark Jan 21 '10 at 01:23
  • I'm not sure what you mean by "projects", so I'm guessing no. Python is an Object Oriented language. Python is more OO than Java, for that matter. I'd suggest reading the Python Tutorial (from python.org), and it should take you through plenty of the things you're asking about. – Jesse Kempf Jan 21 '10 at 03:36
1

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/

OscarRyz
  • 196,001
  • 113
  • 385
  • 569
0

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.

Reed Copsey
  • 554,122
  • 78
  • 1,158
  • 1,373