How to organise code in Python?

A forum for general discussion of the Python programming language.

How to organise code in Python?

Postby elija » Fri May 17, 2013 10:30 am

I'm brand new to the world of Python and I must say up front that it kind of reminds me of the BASIC language from the old 16 bit days. Not in the syntax, but in how it feels. This is a good thing, I have never enjoyed coding so much as I did in HiSoft BASIC!

In recent years and in all OO languages, code has tended to be organised with a single class in a file of the same name with related classes in the same folder. Each folder equates to a name space. During various Google searches for unrelated questions, I have seen quite a few Python programmers say that this is an "un-pythonesque" way of organising your code.

None of them have said why or, more importantly, what is a pythonesque way of organising classes. Is it something completely different? :mrgreen:
Posts: 4
Joined: Fri May 17, 2013 10:15 am

Re: How to organise code in Python?

Postby setrofim » Fri May 17, 2013 1:54 pm

Basically, you would just be creating more work for yourself. You don't really gain anything by creating a multude of files, each with only a few lines in it. The habit of sticking each class into its own file (and multi-level namespacing into different directories) is one of the reasons why it's a nightmare to write Java without an IDE. In Python a single .py file doubles up as a module and comes with it's own namespace. If you put each class into its own file, your code would be full of "from my_class import MyClass" kind of lines. Also, see this discussion.
Posts: 288
Joined: Mon Mar 04, 2013 7:52 pm

Return to General Discussions

Who is online

Users browsing this forum: No registered users and 4 guests