我想创建python脚本,可以使用Python Language Services或使用任何其他方式修改该脚本本身的代码。
例如它保持它的全成执行自我修改python脚本
import re
COUNT = 0
def updateCount():
# code to update second line e.g. COUNT = 0
pass
if __name__ == '__main__':
print('This script has run {} times'.format(COUNT))
updateCount()
的计数的轨道上的这个脚本代码成功执行的脚本应该得到改变
import re
COUNT = 1
def updateCount():
# code to update second line e.g. COUNT = 0
pass
if __name__ == '__main__':
print('This script has run {} times'.format(COUNT))
updateCount()
简单的方式来到我的脑海里是写模式打开__file__
和做requried修改使用reguler expessions等,但没有工作,我得到了异常io.UnsupportedOperation: not readable
。即使这种方法可行,那也是非常危险的,因为它会破坏我的整个脚本。所以我正在寻找使用Python语言服务的解决方案。
您可以打开并编辑'__file__'。 – kichik
请注意,您可能会遇到权限问题(如果脚本是由没有写入权限的用户运行的话)。 – Leon
不起作用'io.UnsupportedOperation:不可读' –