import

Discussion in 'Python' started by jolly, Jul 6, 2007.

  1. jolly

    jolly Guest

    Hey guys,

    I'm rather new to python and i'm have trouble(as usual)

    I want to know if it is possible to change where 'import' looks....
    this will save me clogging up my python directory

    Thanks
     
    jolly, Jul 6, 2007
    #1
    1. Advertising

  2. jolly

    Amit Khemka Guest

    On 7/6/07, jolly <> wrote:
    > Hey guys,
    >
    > I'm rather new to python and i'm have trouble(as usual)


    Hope it becomes un-usual with Python !

    >
    > I want to know if it is possible to change where 'import' looks....
    > this will save me clogging up my python directory


    Yes. You can tell python where all to look for importing modules.

    import sys
    sys.path.append("/this/is/my/modules/path")


    > Thanks


    Welcome !

    cheers,

    --
    ----
    Amit Khemka
    website: www.onyomo.com
    wap-site: www.owap.in
    Home Page: www.cse.iitd.ernet.in/~csd00377

    Endless the world's turn, endless the sun's Spinning, Endless the quest;
    I turn again, back to my own beginning, And here, find rest.
     
    Amit Khemka, Jul 6, 2007
    #2
    1. Advertising

  3. jolly

    Gary Herron Guest

    jolly wrote:
    > Hey guys,
    >
    > I'm rather new to python and i'm have trouble(as usual)
    >
    > I want to know if it is possible to change where 'import' looks....
    > this will save me clogging up my python directory
    >
    > Thanks
    >

    Easily done. The value of sys.path is a list of directories that import
    looks through to satisfy an import. Just import sys and append a new
    directory to sys.path.

    import sys
    sys.path.append('/your/directory/of/importable/modules')
    // Then import code from your directory.
     
    Gary Herron, Jul 6, 2007
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Paul Opal
    Replies:
    12
    Views:
    972
    Paul Opal
    Oct 11, 2004
  2. JPractitioner
    Replies:
    13
    Views:
    20,189
    Roedy Green
    Feb 24, 2006
  3. Vitali Gontsharuk
    Replies:
    2
    Views:
    578
    Vitali Gontsharuk
    Aug 25, 2005
  4. Artur M. Piwko

    import/from import question

    Artur M. Piwko, Jun 29, 2003, in forum: Python
    Replies:
    1
    Views:
    859
    Peter Hansen
    Jul 2, 2003
  5. Dennis
    Replies:
    2
    Views:
    511
    Dennis
    Aug 18, 2003
Loading...

Share This Page