小编Tim*_*Tim的帖子

在Python中有条件地导入模块

在我的程序中,我想根据用户所使用的操作系统是Windows还是Linux来导入simplejson或json.我将操作系统名称作为用户的输入.现在,执行以下操作是否正确?

osys = raw_input("Press w for windows,l for linux")
if (osys == "w"):
    import json as simplejson
else:
    import simplejson  
Run Code Online (Sandbox Code Playgroud)

python

124
推荐指数
3
解决办法
6万
查看次数

标签 统计

python ×1