我正在导出一个用Python编写的脚本,该脚本向投影仪的IP地址发送命令以关闭投影仪。代码的功能正常,投影仪将关闭。投影仪列表存储在与脚本不同的文件中的字典中,以允许其他脚本对其进行编辑和访问。你知道吗
一旦我使用Pyinstaller v3.3.1 for Python 3.5.1将脚本导出到exe,.exe文件不再从包含字典的.py文件更新,而是在内存中存储了一个版本,我无法更新。你知道吗
如何使可执行文件仍然从字典中读取并在每次运行时更新?你知道吗
谢谢你, 乔希
代码: dictonaryfile.py文件(为安全起见减少了,但显示了格式)。你知道吗
projectors = {
'1': '192.168.0.1'
}
执行关机的脚本
from pypjlink import Projector
from file3 import projectors
for item in projectors:
try:
myProjector = Projector.from_address(projectors[item])
myProjector.authenticate('PASSWORD REMOVED FOR SECURITY')
state = myProjector.get_power()
try:
if state == 'on':
myProjector.set_power('off')
print('Successfully powered off: ', item)
except:
print('The projector in ', item, ', raised an error, shutdown
may not have occurred')
continue
except:
print(item, 'did not respond to state request, it is likely powered
off at the wall.')
continue
正如您所注意到的,一旦创建了exe,就无法更新它。解决这类问题的方法是询问代码中
dictonaryfile.py
的位置-对于这样的应用程序,最好使用配置文件(.ini),python有Configparser来读取配置文件。您可以将配置文件创建为-
并用
Configparser
-相关问题 更多 >
编程相关推荐