这是我的挑战。我有一个radioConfig.py文件,其中包含当用户更改位置或扫描时间时需要更改的变量值。这将用于学生,所以我正在编程一个GUI,pysimplegui,以更改这些变量的值
这是我到目前为止所做的,但它不起作用。它将替换变量名,而不是值
我正在使用Rpi和python3。我学的是电子学,我的编程技能是C语言。我不确定这是否是解决我的挑战的最佳方法,也不知道有哪些python选项可能有用。任何帮助都将是惊人的
#File: GuiTest.py before code is executed
freqCenter = 21000000
freqBandwidth = 8000000
upconvFreqHz = 125000000
fftWindow = "BlacHarr"
notes = "Test"
rtlSampleRateHz = 2000000
#-----------------------------------------------------------------------
#Program which will be a gui asking user for input values
freqCenterGUI = 20800280
with open('GuiTest.py', 'r') as file :
filedata = file.read()
filedata = filedata.replace('freqCenter', str(freqCenterGUI).strip('()'))
with open('GuiTest.py', 'w') as file:
file.write(filedata)
#File: GuiTest.py after code is executed
20800280 = 21000000
freqBandwidth = 8000000
upconvFreqHz = 125000000
notes = "Test"
rtlSampleRateHz = 2000000
#-----------------------------------------------------------------------
我会说:使用一个配置文件
修改脚本真的不是一个好的实践
在您的cfg.ini中:
然后使用configparser:
编辑:
或者,正如@juanpa.arrivillaga所建议的,使用json也是一个很好的解决方案
品味问题…:)
又快又脏:
文件1:
文件2
相关问题 更多 >
编程相关推荐