简体   繁体   English

如何使用可执行的Linux程序/脚本更改python文件中的变量?

[英]How to change variable in python file using an executable linux program/script?

I am building a datalogger for a group of PV inverters using Raspberry Pi and am using two python scripts to collect the data over two separate communication protocols. 我正在使用Raspberry Pi为一组PV逆变器构建一个数据记录器,并且正在使用两个python脚本通过两个单独的通信协议来收集数据。 I need to change two variables in each script if I move from one site to another - the first and the last inverter id for the new site. 如果我从一个站点移至另一个站点,则需要在每个脚本中更改两个变量-新站点的第一个和最后一个逆变器ID。 I want to make this change user friendly such that a new user does not have to open the python script to change the values. 我想使此更改对用户友好,以便新用户不必打开python脚本即可更改值。 So I want to have an executable program in linux environment (which may have an icon on the Pi desktop) which the user can open and it will prompt to specify first and last inverter id and transfers this change to python script. 所以我想在Linux环境中有一个可执行程序(在Pi桌面上可能有一个图标),用户可以打开该程序,并提示指定第一个和最后一个逆变器ID,并将此更改传输到python脚本。 If this is too complicated to achieve for this task, maybe a simple command for the terminal window which will prompt the same changes?? 如果这对于完成此任务而言太复杂了,也许是一个用于终端窗口的简单命令,它将提示相同的更改?

I hope the task is sufficiently explained. 我希望任务能得到充分解释。 I am not a programmer by trade and am doing this project as a hobby, so please forgive me if I am ignoring something obvious :| 我不是行业程序员,而是出于业余爱好从事此项目,所以如果我忽略了明显的事情,请原谅我:|

Just posting a successful update for this query. 刚刚为此查询发布了成功的更新。 The desktop configuration file method was the simplest and it worked. 桌面配置文件方法是最简单且有效的方法。 I wrote the following in the .desktop file 我在.desktop文件中写了以下内容

[Desktop Entry]
Version=1.0
Name= ProgramName
Comment= my comment
Exec=sudo python /usr/share/app/app.py
Icon=/usr/share/pixmaps/geany.xpm
Path=/usr/local/lib/python2.7
Terminal=true
Type=Application
Categories=Utility;Application;

I added the "python" bit to the Exec line and hence did not have to write a she-bang line in the script. 我在Exec行中添加了“ python”位,因此不必在脚本中编写she-bang行。 Also the Terminal option had to made True since I needed a prompt for the user to enter a value. 终端选项也必须设为True,因为我需要提示用户输入值。

Hope this helps somebody else. 希望这对其他人有帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM