我想檢查導入的名稱。
代碼:python string to symbolic name
import fst # empty file fst.py
for s in dir(fst):
print(s) # got string with symbolic names
輸出:
__builtins__
__cached__
__doc__
__file__
__name__
__package__
現在我要檢查每個定義的名稱的值:
代碼:
print(__builtins__)
print(__cached__)
print(__doc__)
print(__file__)
print(__name__)
print(__package__)
問:我如何 「提取物」字符串的符號名稱?
應該代碼:
import fst #empty file fst.py
for s in dir(fst):
print(s, StrToSym(s)) # this call should be equal to str("__name__", __name__)