When to put my modules

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Bob van der Poel

    When to put my modules


    I'm working on a moderately sized application and I'm planning on having
    a fair number of modules. The only question in my mind is: where do I
    put the modules ... and how do I let python know about them?

    I could put them with the rest of the python lib, but I'm not really
    presumtious to do that.

    I can keep them all in the current directory, but that forces the user
    to chd to a certain location all the time.

    Best, I think, is to put them in a program specific location. My program
    needs some other data files, etc. so I'm thinking that I can just put
    the python stuff in /usr/local/lib/MYPROGRAM/modules.

    Okay, but what about when I'm just working on them? In this case I'd
    like them to be in my current working dir.

    Is there a magic line I need to add to the top of the main module to set
    the path up?

    Apologies if this is covered in a document...but I can't see to find
    anything. Maybe this is a faq?

    --
    Bob van der Poel ** Wynndel, British Columbia, CANADA **
    EMAIL: bvdpoel@kootena y.com
    WWW: http://www.kootenay.com/~bvdpoel
  • Yermat

    #2
    Re: When to put my modules

    Hi,

    "Bob van der Poel" <bvdpoel@kooten ay.com> a écrit dans le message de
    news:3ff0e744_1 @dns.sd54.bc.ca[color=blue]
    > I'm working on a moderately sized application and I'm planning on
    > having a fair number of modules. The only question in my mind is:
    > where do I put the modules ... and how do I let python know about
    > them?[/color]

    see http://www.python.org/doc/current/tut/node8.html especially the 6.1.1
    [color=blue]
    > I could put them with the rest of the python lib, but I'm not really
    > presumtious to do that.[/color]

    Not that good...
    [color=blue]
    > I can keep them all in the current directory, but that forces the user
    > to chd to a certain location all the time.
    >
    > Best, I think, is to put them in a program specific location. My
    > program needs some other data files, etc. so I'm thinking that I can
    > just put the python stuff in /usr/local/lib/MYPROGRAM/modules.[/color]

    Not that good too. You may want to re-use your module later in another
    program...
    [color=blue]
    > Okay, but what about when I'm just working on them? In this case I'd
    > like them to be in my current working dir.
    >
    > Is there a magic line I need to add to the top of the main module to
    > set the path up?
    >
    > Apologies if this is covered in a document...but I can't see to find
    > anything. Maybe this is a faq?[/color]

    What I'm doing is something like this :
    All my module are in a directory such as /home/loic/MyPython/.
    I set the PYTHONPATH to that directory.
    I've got for example a module rtf in /home/loic/MyPython/rtf/, another one
    Heredis in /home/loic/MyPython/Heredis and my program is in
    /home/loic/MyPython/Heredis2Gedcom for example.
    In that way, I don't mix my module with standard one. Every program can
    access all non program specific module.

    For other tips, look at sys.path too.

    Hope it help !
    Yermat


    Comment

    • Bob van der Poel

      #3
      Re: When to put my modules



      Yermat wrote:[color=blue]
      > Hi,
      >
      > "Bob van der Poel" <bvdpoel@kooten ay.com> a écrit dans le message de
      > news:3ff0e744_1 @dns.sd54.bc.ca
      >[color=green]
      >>I'm working on a moderately sized application and I'm planning on
      >>having a fair number of modules. The only question in my mind is:
      >>where do I put the modules ... and how do I let python know about
      >>them?[/color]
      >
      >
      > see http://www.python.org/doc/current/tut/node8.html especially the 6.1.1
      >[/color]

      Okay...so I just need to add paths to the sys.path variable. Seems
      simple enough. Thanks.
      [color=blue][color=green]
      >>I could put them with the rest of the python lib, but I'm not really
      >>presumtious to do that.[/color]
      >
      >
      > Not that good...
      >
      >[color=green]
      >>I can keep them all in the current directory, but that forces the user
      >>to chd to a certain location all the time.
      >>
      >>Best, I think, is to put them in a program specific location. My
      >>program needs some other data files, etc. so I'm thinking that I can
      >>just put the python stuff in /usr/local/lib/MYPROGRAM/modules.[/color]
      >
      >
      > Not that good too. You may want to re-use your module later in another
      > program...
      >[/color]

      Well, probably not. The modules I'm talking about here are pretty
      specific to my program.
      [color=blue][color=green]
      >>Okay, but what about when I'm just working on them? In this case I'd
      >>like them to be in my current working dir.
      >>
      >>Is there a magic line I need to add to the top of the main module to
      >>set the path up?
      >>
      >>Apologies if this is covered in a document...but I can't see to find
      >>anything. Maybe this is a faq?[/color]
      >
      >
      > What I'm doing is something like this :
      > All my module are in a directory such as /home/loic/MyPython/.
      > I set the PYTHONPATH to that directory.
      > I've got for example a module rtf in /home/loic/MyPython/rtf/, another one
      > Heredis in /home/loic/MyPython/Heredis and my program is in
      > /home/loic/MyPython/Heredis2Gedcom for example.
      > In that way, I don't mix my module with standard one. Every program can
      > access all non program specific module.
      >
      > For other tips, look at sys.path too.
      >
      > Hope it help !
      > Yermat[/color]

      Yes, it does help. Just to clearify, the program I'm working on will be
      distributed to other users. So, putting the modules in a
      my-personal-python-stuff directory isn't really an option. They most
      likely need to go in the main python tree (which, again, I don't like),
      or in a program specific directory. Setting PYTHONPATH is an option, but
      I don't like to force a user to set an env variable just to run my
      program. Yes, I could turn my prog into a shell script which sets the
      variable, and then runs the *real* program, but I always find that
      method to be a bit convoluted.
      [color=blue]
      >[/color]

      --
      Bob van der Poel ** Wynndel, British Columbia, CANADA **
      EMAIL: bvdpoel@kootena y.com
      WWW: http://www.kootenay.com/~bvdpoel

      Comment

      • Terry Reedy

        #4
        Re: When to put my modules

        [color=blue]
        > Okay...so I just need to add paths to the sys.path variable. Seems
        > simple enough. Thanks.[/color]

        If your modules are specific to an application, adding the application
        module-dir to the front of sys.path is probably best. If your modules
        constitute a library that other Python programmers might want to access
        (such as pygame or numerical), then the package should go in
        lib/site-packages.

        TJR


        Comment

        • Bob van der Poel

          #5
          Re: When to put my modules



          Terry Reedy wrote:[color=blue][color=green]
          >>Okay...so I just need to add paths to the sys.path variable. Seems
          >>simple enough. Thanks.[/color]
          >
          >
          > If your modules are specific to an application, adding the application
          > module-dir to the front of sys.path is probably best. If your modules
          > constitute a library that other Python programmers might want to access
          > (such as pygame or numerical), then the package should go in
          > lib/site-packages.[/color]

          Yes, thanks. And I'll find out soon enuf when I try this, but I suppose
          that having a bunch of alternates in the path is not a problem.

          --
          Bob van der Poel ** Wynndel, British Columbia, CANADA **
          EMAIL: bvdpoel@kootena y.com
          WWW: http://www.kootenay.com/~bvdpoel

          Comment

          Working...