How to import a file by its full path using C api?

Discussion in 'Python' started by lallous, Nov 25, 2009.

  1. lallous

    lallous Guest

    Hello

    PyObject* PyImport_ImportModule( const char *name)

    How to specify a full file path instead and a module name?

    Like PyImport_SomeFunction(const char *path_to_script, const char *name)

    Thanks,
    Elias
    lallous, Nov 25, 2009
    #1
    1. Advertising

  2. lallous

    lallous Guest

    Looks like one way to do that is to use something like:

    s.sprintf(
    "import imp\n"
    "imp.load_source('%s', r'%s')", modname, script_path);
    PyRun_SimpleString(s.c_str());

    Unless someone has a better suggestion.

    Regards,
    Elias
    "lallous" <> wrote in message news:heir4g$ohv$...
    > Hello
    >
    > PyObject* PyImport_ImportModule( const char *name)
    >
    > How to specify a full file path instead and a module name?
    >
    > Like PyImport_SomeFunction(const char *path_to_script, const char *name)
    >
    > Thanks,
    > Elias
    lallous, Nov 25, 2009
    #2
    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. Samuel R. Neff
    Replies:
    2
    Views:
    578
    bradley
    Jun 10, 2005
  2. dude
    Replies:
    5
    Views:
    1,680
    Jussi Piitulainen
    Mar 17, 2011
  3. thunk
    Replies:
    1
    Views:
    292
    thunk
    Mar 30, 2010
  4. thunk
    Replies:
    0
    Views:
    453
    thunk
    Apr 1, 2010
  5. thunk
    Replies:
    14
    Views:
    599
    thunk
    Apr 3, 2010
Loading...

Share This Page