On Thu, Aug 18, 2011 at 11:18 PM, Milo Gertjejansen <[email protected]> wrote:
> Hello all
>
> I am working on a website and at this point it has gotten (relatively)
> large. Large enough to warrant separating main.py into several
> different files for easy management.
>
> Additionally I am sharing a site with my friend who also will be using
> the comment system we developed (based heavily off of the Skeleton
> Code on webpy.org). I mention this because I want a comments.py
> module, so I can give it to anybody along with the appropriate
> templates and they could have a comment system (nearly) out of the
> box.
>
> Basically I would like to separate my huge main.py file into many
> others.
>
> In the example code, it is done rather elegantly, but all the
> applications are relatively simple and easy to separate.
>
> I am pretty experience in python itself, but creating modules is one
> of my weak points that I find hard to understand. I do have some
> experience with MVC but again, my understanding of that is limited and
> the few times I tried to use it I implemented it incorrectly/in a
> weird way/inefficiently.
>
> My main.py file is located at http://milogert.com/static/main.py.zip
>
> If anybody can direct me to a good resource for this or just post help
> directly (I realize it is a relatively involved subject), anything at
> all would be appreciated.

I had this problem too and the way I solved it was to make a separate
mod directory and then use Python's module system
(http://docs.python.org/tutorial/modules.html) to include those
modules as I needed them. Here's a basic example of how I used the
module system (outside of web.py scope) when viewed from a unix shell:

> ls
foo.py mod/
> ls mod/
bar.py
>
> cat mod/bar.py
def f():
    print("I am bar")
>
> cat foo.py
print("I am foo")
import sys
sys.path.append("mod/")
import bar
bar.f()
>
> python foo.py
I am foo
I am bar
>

looking at your code I see SQL statements in main.py. I had this in
the beginning but when my program got larger I abstracted those out of
my main.py and into separate modules within mod and then made my
main.py's job to instantiate the desired objects for the appropriate
URL and then pass them through to web.py's templating system. This
approach worked nicely for me since I hadn't written "web.py modules"
but just separate Python modules that I could then debug on the
command line or use for other programs.

  John

-- 
You received this message because you are subscribed to the Google Groups 
"web.py" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/webpy?hl=en.

Reply via email to