Skip to content
This repository has been archived by the owner on Nov 7, 2019. It is now read-only.

Sharing some experience #2

Open
felipevolpone opened this issue Jul 4, 2016 · 0 comments
Open

Sharing some experience #2

felipevolpone opened this issue Jul 4, 2016 · 0 comments

Comments

@felipevolpone
Copy link

Hi @rochacbruno, nice work exporting this code to a new library, it's really usefull :)

I've done done this kind of import in some projects, but using this approach:

import importlib
foopath = 'src.apis.foo.Foo'

module_name = '.'.join(foopath.split('.')[:-1]) # to get src.apis.foo
foo_module = importlib.import_module(module_name)
clazz_name = foopath.split('.')[-1] # to get Foo
Foo = getattr(module_name, clazz_name)
print Foo()

It's almost the same thing, but using importlib instead of import directly. Actually, importlib uses the import function as well. Anyway, just creating this issue to share some alternatives to the same goal.

Thank you!

@rochacbruno rochacbruno pinned this issue Nov 7, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant