Python Forum

Full Version: python import module or namespace from namepsace variable ?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
this is very important to me, i want import a module or package (namespace) from another namespace variable.

example

import mydir # imports namepace

module_foo = get_module_from_name_space("foo", namespace = mydir) # imports foo module from mydir. that means from mydir import foo expression but I must import foo in that way, with this function.

print(module_foo == mydir.foo) # prints True
thanks.

is there a function like get_module_from_name_space ?
you should be able to do this with importlib
You'll have to read the docs, I have used it, but it's been a while
If you look at my github account: https://github.com/Larz60p/PyHarry
module HarryHelp.py i use it there
you may also be able to use pkgutil
@Larz60+,

sorry, i couldn't find the function I am looking for in your HarryHelp.py file

can you post this function to here ?
Try here: importlib, there are even some examples.
@sparkz_alot

I tried too many times with importlib module
given https://python-forum.io/Thread-python-Ho...-namespace I think it's a matter of proper organising the package (i.e. __init__.py, etc.) and understanding the import mechanism rather than using some complicated import scheme.
i even think the two threads should be merged
the python import system soooooooooooooooo bad,
Maybe this will help?

importlib keep on changing - and remain being scantily (understatement of the century Wall ) documented
@volcano63

can you write a function like function (get_module_from_name_psace) in my first reply
(May-23-2017, 01:28 PM)harun2525 Wrote: [ -> ]the python import system soooooooooooooooo bad,

is it really bad or simply you don't understand it?

given the folder structure in the other thread a __init__.py and __all__ property in it would allow you to do star import. Not that is a good practice :-)
Pages: 1 2