Skip to content

Commit c0e8112

Browse files
committed
added string_import.py
1 parent 7ddf575 commit c0e8112

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

string_import.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# you can use builtin __import__ function
2+
3+
modname = 'string'
4+
string = __import__(modname)
5+
print(string)
6+
7+
# Python official prefferred way
8+
9+
import importlib
10+
modname = 'string'
11+
string = importlib.import_module(modname)
12+
print(string)

0 commit comments

Comments
 (0)