Files application architecture

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Benjamin Watine

    Files application architecture

    Hi,

    I'm about to develop a small python application and I wonder how to
    organize files in this application.
    I'm familar to java, so I'm tempted to use the same convention : 1 file
    per class and 1 folders per package.

    I know that packages doesn't exists in python, they are modules instead.
    May I create specific module for each "group of class" ? My application
    follow the MVC paradigm, so basically, I've a package Model, a package
    View, and a package Controller.

    So, what are best practices for organizing files and folders in a small
    python project ?
    I've found PEP8 (http://www.python.org/dev/peps/pep-0008/) that gives a
    lot of good hints on coding convention, but nothing about files
    organization.

    Thanks in advance !

    Ben


  • Diez B. Roggisch

    #2
    Re: Files application architecture

    Benjamin Watine schrieb:
    Hi,
    >
    I'm about to develop a small python application and I wonder how to
    organize files in this application.
    I'm familar to java, so I'm tempted to use the same convention : 1 file
    per class and 1 folders per package.
    >
    I know that packages doesn't exists in python, they are modules instead.
    This is wrong. There are packages & modules in python.



    And please *don't* do put one class per module, as you would do in Java!
    Instead, group related classes into modules, breaking them up into
    several submodules if size or differences in usage suggest so.
    May I create specific module for each "group of class" ? My application
    follow the MVC paradigm, so basically, I've a package Model, a package
    View, and a package Controller.
    >
    So, what are best practices for organizing files and folders in a small
    python project ?
    I've found PEP8 (http://www.python.org/dev/peps/pep-0008/) that gives a
    lot of good hints on coding convention, but nothing about files
    organization.
    The MVC pattern is more important in terms of actual classes written,
    not so much regarding their distribution over a set of files. If you
    want, start with one big single module inside a application-naming
    package - or even no package at all. Split up if you need to.

    Or just go for

    <mypackage>/__init__.py
    <mypackage>/model.py
    <mypackage>/view.py
    <mypackage>/controller.py


    if you *must*.

    Diez

    Comment

    • Benjamin Watine

      #3
      Re: Files application architecture

      Bruno Desthuilliers a écrit :
      Benjamin Watine a écrit :
      >Hi,
      >>
      >I'm about to develop a small python application and I wonder how to
      >organize files in this application.
      >I'm familar to java, so I'm tempted to use the same convention
      >

      >
      >: 1 file per class and 1 folders per package.
      >
      Don't. This is a waste of time and a pain to maintain, and more over it
      doesn't make any sense since Python doesn't force you to put everything
      in classes.
      >
      >I know that packages doesn't exists in python,
      >
      Did you actually read the doc ? While Python's packages are not the same
      thing as Java's, they do exist.
      >

      >
      >they are modules instead. May I create specific module for each "group
      >of class" ?
      >
      The usual way to get cohesive modules is indeed to group closely related
      objects (classes, functions, etc) in a same module.
      >
      >My application follow the MVC paradigm, so basically, I've a package
      >Model, a package View, and a package Controller.
      >
      If your app is small, having _modules_ models, views and controllers
      should be enough.
      >
      >So, what are best practices for organizing files and folders in a
      >small python project ?
      >
      The best practice is to keep things simple, as usual.
      >
      Thank you all for your good advices and links. I'm new to python and I
      have yet a lot of things to learn !

      Now, I would like to take a look to a well coded wxPython application.
      Could anybody indicate a project that I could take as reference for
      standard python coding style ?

      Regards,

      Ben

      Comment

      Working...