我使用的是树莓Pi4模型B,在它里面有一些小东西。我正在尝试编写一个python脚本,用于在启动时运行网页。在终端中输入sudo nano 并在最后一行添加@ can浏览器--启动-全屏--启动--最大化的,我可以在引导时看到网页。但问题是,我需要用python程序来完成这个任务。已经尝试了很多脚本,但它不起作用。每次抛出错误时,它都会说:“没有这样的文件或目录: sudo /etc/xdg/lxsession/LXDE-pi/autostart".我正在附上下面的脚本。请帮助我解决这个问题,我是新来的树莓派。
不添加sudo纳米
conf_file =/etc/xdg/lxsession/LXDE/autostart
def update_url():
conf_file= '/etc/xdg/lxsession/LXDE-pi/autostart'
try:
with open(conf_file, 'w')as file:
file.write('@chromium-browser --start-fullscreen --start-maximized https://teams.microsoft.com/')
except Exception as ex:
print("Cant write dirctory:",ex)
return 0
finally:
pass输出:
permission denied: /etc/xdg/lxsession/LXDE-pi/autostart
添加sudo纳米
conf_file = sudo /etc/xdg/lxsession/LXDE/autostart
def update_url():
conf_file= 'sudo nano /etc/xdg/lxsession/LXDE-pi/autostart'
try:
with open(conf_file, 'w')as file:
file.write('@chromium-browser --start-fullscreen --start-maximized https://teams.microsoft.com/')
except Exception as ex:
print("Cant write dirctory:",ex)
return 0
finally:
pass输出:
No such file or directory: sudo nano /etc/xdg/lxsession/LXDE-pi/autostart
发布于 2022-03-20 16:07:49
我有一种预感,Python认为"sudo“是一个目录。也许试着让它在终点站运行。读这个:Using sudo with Python script
https://stackoverflow.com/questions/71548168
复制相似问题