Ada*_*ter 2 python python-idle
我有一个需要使用的脚本,__file__所以我了解到IDLE没有设置它.我的脚本有没有办法可以检测到IDLE的存在?
if '__file__' not in globals():
# __file__ is not set
Run Code Online (Sandbox Code Playgroud)
如果你想做一些特殊的事情,如果__file__没有设置.要么,
try:
__file__
except NameError:
# __file__ is not set
raise
Run Code Online (Sandbox Code Playgroud)
如果你想做某事,那么无论如何都要提出错误,或者
global __file__
__file__ = globals().get('__file__', 'your_default_here')
Run Code Online (Sandbox Code Playgroud)
如果你想要一个默认值.
| 归档时间: |
|
| 查看次数: |
696 次 |
| 最近记录: |