Whenever I create a python script in the terminal and tell it to save it, the files get saves as "shutdown.py.save" intstead of "shutdown.py" like I want.
What am I doing wrong?
Re: Python files not saving
what editor are you using?
I had a similar problem writing Python with notepad. I was telling it to save as myprogram.py and it ended up adding its own extension and saving as myprogram.py.txt. I'm now using thonny and haven't seen the problem since
I had a similar problem writing Python with notepad. I was telling it to save as myprogram.py and it ended up adding its own extension and saving as myprogram.py.txt. I'm now using thonny and haven't seen the problem since
Re: Python files not saving
I just opened the terminal and entered this:
nano ~pi/Scripts/shutdown-with-hold.py
and then exited and saved the file. Do I need to be using an editor instead of this?
nano ~pi/Scripts/shutdown-with-hold.py
and then exited and saved the file. Do I need to be using an editor instead of this?
Re: Python files not saving
What OS are you using? Are you running a desktop?
Why not use a GUI based Python editor such as Thonny?
Why not use a GUI based Python editor such as Thonny?
Re: Python files not saving
What Operating System are you running on your RPi board?
Have you deliberately created a Scripts subdirectory in your Home directory? The nano editor will not create it if it does not exist. It is not a default location pre-installed with RasPiOS.
Code: Select all
pi@rpitest64:~ $ mkdir Scripts
pi@rpitest64:~ $ nano ~pi/Scripts/shutdown-with-hold.py
pi@rpitest64:~ $ ls -al Scripts
total 12
drwxr-xr-x 2 pi pi 4096 Feb 17 18:26 .
drwxr-xr-x 24 pi pi 4096 Feb 17 18:23 ..
-rw-r--r-- 1 pi pi 22 Feb 17 18:26 shutdown-with-hold.py
pi@rpitest64:~ $ cat Scripts/shutdown-with-hold.py
# shutdown-with-hold
pi@rpitest64:~ $
Beware of the Leopard
Re: Python files not saving
nano will add ".save" to the file name if it encounters a serious error such as running out of memory, or if it is killed with sighup.
Unreadable squiggle
Re: Python files not saving
This can easily happen if the terminal window is closed by clicking the [X] without first saving the nano file.
3B+ & 4B4G Running RPi OS Bookworm w/ Desktop
Re: Python files not saving
I am running a modified version of Raspbian OS I believe, it is from OpenAuto Pro. Its a program for a CarPi.
As to why I'm not using Thonny, I was following third part directions.
I have an external board that will set a GPIO pin to ground and tell the pi to shutdown by utilizing the script I am trying to write. If thonny can write a script then I will use that.
Re: Python files not saving
I believe I am running a modified Raspbian OS from OpenAuto Pro. This pi is for a carpi/headunit.B.Goode wrote: ↑Thu Feb 17, 2022 6:27 pm
What Operating System are you running on your RPi board?
Have you deliberately created a Scripts subdirectory in your Home directory? The nano editor will not create it if it does not exist. It is not a default location pre-installed with RasPiOS.
Code: Select all
pi@rpitest64:~ $ mkdir Scripts pi@rpitest64:~ $ nano ~pi/Scripts/shutdown-with-hold.py pi@rpitest64:~ $ ls -al Scripts total 12 drwxr-xr-x 2 pi pi 4096 Feb 17 18:26 . drwxr-xr-x 24 pi pi 4096 Feb 17 18:23 .. -rw-r--r-- 1 pi pi 22 Feb 17 18:26 shutdown-with-hold.py pi@rpitest64:~ $ cat Scripts/shutdown-with-hold.py # shutdown-with-hold pi@rpitest64:~ $
I did create a folder called scripts.
Re: Python files not saving
Are these directions shareable?I was following third part directions
Re: Python files not saving
... but that is not where you are trying to create or edit the python file.
If you are following instructions related to a customised OS from a third-party maybe your support questions should be directed to them?
(Because chances are most volunteer helpers here will not know how that OS differs from the standard Raspberry Pi Operating System released directly from Raspberry Pi.)
https://bluewavestudio.io/contact/
Beware of the Leopard
Re: Python files not saving
Yes, I will paste them below:
Python script install:
1.Create folder for script(s):
1. Open the terminal on your Raspberry and make folder Scripts:
- mkdir Scripts and press <Enter>
2.Create the script:
1. Open the terminal and enter:
- nano ~pi/Scripts/shutdown-with-hold.py and press <Enter>
- enter the code:
#!/usr/bin/env python3
from gpiozero import Button
from signal import pause
import os, sys
offGPIO = 21
holdTime = 2
# the function called to shut down the RPI
def shutdown():
os.system("sudo poweroff")
btn = Button(offGPIO, hold_time=holdTime)
btn.when_held = shutdown
pause() # handle the button presses in the background
- press Ctrl+X to close window
- press Y to save changes
or
open the terminal and go to the folder Scripts:
- cd Scripts and press <Enter>
- wget
https://raw.githubusercontent.com/picot ... 1_script/m
aster/shutdown-with-hold.py and press <Enter>
3.Test script:
1. Make shutdown-with-hold.py executable:
- chmod a+x shutdown-with-hold.py
- start script with ./shutdown-with-hold.py
- connect GPIO21 to GND for 2 seconds and check that Pi will start to the shutdown
If this is correct, go to step 4.
4.Make script run at boot time:
1. Open the terminal and enter:
- sudo su and press <Enter>
- nano /etc/rc.local and press <Enter>
- at the end of the file but before exit 0 write:
python /home/pi/Scripts/shutdown-with-hold.py &
∙ NOTE: there is one space before &
∙ press Ctrl+X to close window
∙ press Y to save changes
∙ reboot Raspberry
I am currently stuck at step 3, since my code is saved as "shutdown-with-hold.py.save" instead of "shutdown-with-hold.py".
Thank all of you for your help!
I'm in a little over my head.
Re: Python files not saving
If you look back you will see that I demonstrated those steps being carried out successfully.
Previously you said you had created a directory scripts. Which is not what the instructions say...
What did you actually do?
What is the output from -
Previously you said you had created a directory scripts. Which is not what the instructions say...
What did you actually do?
What is the output from -
Code: Select all
ls -al Scripts
Beware of the Leopard
Re: Python files not saving
The output is:B.Goode wrote: ↑Thu Feb 17, 2022 11:24 pmIf you look back you will see that I demonstrated those steps being carried out successfully.
Previously you said you had created a directory scripts. Which is not what the instructions say...
What did you actually do?
What is the output from -Code: Select all
ls -al Scripts
total 16
drwxr-xr-x 2 pi pi 4096 Jul 27 21:56 .
drwxr-xr-x 25 pi pi 4096 Jul 27 22:22 ..
-rw------- 1 pi pi 242 Jul 27 21:56 shutdown-with-hold.py.save
Re: Python files not saving
The saved file doesn't look big enough to contain the python script. (You could check by following my example, above.)
I suggest you delete it and recreate it.
If cating the file shows that it is intact you could simply make a copy with the correct name.
Something like -
I suggest you delete it and recreate it.
If cating the file shows that it is intact you could simply make a copy with the correct name.
Something like -
Code: Select all
cp ~/Scripts/shutdown-with-hold.py.save ~/Scripts/shutdown-with-hold.py
Beware of the Leopard
Re: Python files not saving
Note that all file names and directories are case sensitive. "Scripts" is different from "scripts".
Also make sure that you are actually saving the file. The ".save" extension is an indication that the editor had an issue.
Re: Python files not saving
Hi all, thanks for the replies.
I was able to fix this by using Thonny, instead of using nano in the terminal.
I was able to fix this by using Thonny, instead of using nano in the terminal.