about python modules

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

    about python modules

    hi friends i am new to python programming.
    i am using Python 2.5 and IDLE as editor.
    i have developed some functions in python those will be calling
    frequently in my main method .
    now i want to know how to import my functions folder to python in
    sucha way that the functions in functions folder should work like
    python library modules .

    i have python in folder C:\python25\..
    and functions folder D:\programs\Fun ctions\

    pls help me friends how to do that.
  • Roy Smith

    #2
    Re: about python modules

    In article
    <2fc55c56-7408-4f44-b6e2-64f85f341ac9@i3 6g2000prf.googl egroups.com>,
    srinivas <srinivas.puvva la@gmail.comwro te:
    hi friends i am new to python programming.
    i am using Python 2.5 and IDLE as editor.
    i have developed some functions in python those will be calling
    frequently in my main method .
    now i want to know how to import my functions folder to python in
    sucha way that the functions in functions folder should work like
    python library modules .
    >
    i have python in folder C:\python25\..
    and functions folder D:\programs\Fun ctions\
    >
    pls help me friends how to do that.
    You need to either:

    1) Put your modules in some directory that's already on your python path.
    To find out what your path is, do:

    import sys
    print sys.path

    It should include a directory which ends in "site-packages". Just drop
    your modules into that directory.

    2) Add the directory where you modules are to your python path. The
    easiest way to do this is to set PYTHONPATH in your environment.

    Comment

    • bockman@virgilio.it

      #3
      Re: about python modules

      On 21 Mag, 14:31, srinivas <srinivas.puvv. ..@gmail.comwro te:
      hi friends i am new to python programming.
      i am using Python 2.5 and IDLE as editor.
      i have developed some functions in python those will be calling
      frequently in my main method .
      now i want to know how to import my functions folder to python in
      sucha way that the functions in functions folder should work like
      python library modules .
      >
      i have  python in folder C:\python25\..
      and functions folder D:\programs\Fun ctions\
      >
      pls help me friends how to do that.
      You have two choices:

      1. In this way you can import single modules (files) in tour folder

      import sys
      sys.path.append (r'D:\programs\ Functions\')
      import my_module_1
      import my_module_2

      and then use whatever you have in the modules:

      my_module_1.my_ function()
      print my_module_1.my_ variable


      2.
      If you add an empty python module called __init__.py inside the folder
      D:\programs\Fun ctions\,
      then python will handle the folder as a package (i.e. a group of
      modules) and you can import
      them in this way:

      sys.path.append (r'D:\programs\ ')
      import Functions # I'm not sure this is needed ...
      from Functions import my_module_1, my_module_2

      And then use whatever is in your modules as in case 1.

      If you put any code in __init__.py, this code will be executed when
      the import Functions
      statement is executed. This can be handy in some cases, e.g. if you
      have subfolders of
      Function folder and want to extend sys.path to include all them.

      For more details, read the section 6 of Python tutorial.

      HTH

      Ciao
      ------
      FB

      Comment

      • inhahe

        #4
        Re: about python modules

        i always just put most of my python files in the c:\python25 directory.
        including ones i want to import as modules, since they import from there.
        otherwise you can put the file in c:\python25\lib \site-packages

        "srinivas" <srinivas.puvva la@gmail.comwro te in message
        news:2fc55c56-7408-4f44-b6e2-64f85f341ac9@i3 6g2000prf.googl egroups.com...
        hi friends i am new to python programming.
        i am using Python 2.5 and IDLE as editor.
        i have developed some functions in python those will be calling
        frequently in my main method .
        now i want to know how to import my functions folder to python in
        sucha way that the functions in functions folder should work like
        python library modules .
        >
        i have python in folder C:\python25\..
        and functions folder D:\programs\Fun ctions\
        >
        pls help me friends how to do that.

        Comment

        • Scott David Daniels

          #5
          Re: about python modules

          srinivas wrote:
          ... i want to know how to import my functions folder to python in
          sucha way that the functions in functions folder should work like
          python library modules .
          >
          i have python in folder C:\python25\..
          and functions folder D:\programs\Fun ctions\
          >
          pls help me friends how to do that.
          An unmentioned possibility:
          Create a file named "whatever.p th" (where the "whatever" is your
          choice). The contents of this file should be a line containing the
          path to your directory (in your case a single line containing
          "D:\programs\Fu nctions" (w/o the quotes).
          Put this file in your site-packages file (for windows in your case,
          that is C:\Python25\Lib \site-packages


          --Scott David Daniels
          Scott.Daniels@A cm.Org

          Comment

          Working...