Howard
Howard

Reputation: 19825

Proper layout for a large python script

Currently I have a python script (proofreader.py) that help me to read a text file, process from several proofreading method, and output the corrected test to a file.

But the script is quite lengthy, e.g. > 1000 Line of codes, so I want to better organize it and better reuse in the future.

Current structure: proofreader.py

def main(argv)
..

def read_text_file():

def proofreading_method_1():

def proofreading_method_2():

def proofreading_method_3():
..
def common_string_function_1():

def common_string_function_2():

def common_string_function_3():
..
def write_text_file():

Can anyone suggest a proper layout for this project (Proofreader)?

According to: http://jcalderone.livejournal.com/39794.html, I came up with with the following:

Proofreader/
|-- bin/
|   |-- proofreader (The python script with the .py extension)
|
|-- proofreader/
|   |-- test/
|   |   |-- __init__.py
|   |   |-- test_main.py
|   |   
|   |-- __init__.py
|   |-- main.py
|   |-- proofreading.py (class for proofreading methods)
|   |-- stringutil.py (class for frequently used string methods)
|
|-- setup.py
|-- README

Any problem with the above suggestion?

Upvotes: 1

Views: 852

Answers (2)

Christo Buschek
Christo Buschek

Reputation: 306

Consider to use the automatic script creation of distribute (see: http://packages.python.org/distribute/setuptools.html?highlight=entry_points#automatic-script-creation ) instead of keeping a seperate .py file in 'bin'. I usualy keep the tests outside my module. Split up your proofreader.py into several files containing different classes if possible. Thats actually the most important thing to keep an overview.

Upvotes: 1

jcollado
jcollado

Reputation: 40414

I usually use a similar layout.

The only significant difference I'd say is that test module would be under Proofreader instead of under Proofreader/proofreader. The main reason to keep tests separate from the code is that you usually just want to make them available to other developers, but not to the users that just want to install your software.

Upvotes: 1

Related Questions