ElectronicZoologyfield notes from the garage
← Back to PAM8403 guide
terminal nano wav_to_header.py # paste your code here Ctrl+O to save Enter to confirm filename Ctrl+X to exit
Linux basics

Saving a Script File

How to save a block of code as a runnable file

A script is just a plain text file. There is nothing special about it - the code you copy from this guide goes into a file, you give it a name ending in .py, and Python can then run it.

Option 1 - nano (terminal, no install needed)

Open a terminal and type:

nano wav_to_header.py

This opens a blank file in the terminal editor. Paste the script code in, then:

  • Press Ctrl+O to save
  • Press Enter to confirm the filename
  • Press Ctrl+X to exit

Option 2 - any text editor (VS Code, Kate, gedit, etc.)

Open your text editor, create a new file, paste the code in, and save it as wav_to_header.py. Make sure it saves as plain text - not a Word document or rich text file.

Save it somewhere easy to find - your home folder (/home/yourname/) or a project folder works well.

Then run it

Open a terminal, navigate to where you saved the file, and run it with Python:

python3 wav_to_header.py /tmp/myclip_8bit.wav myclip.h myclip

If the terminal says No such file or directory, you are not in the right folder. Use cd to navigate there first - for example cd ~/Documents if that is where you saved it.

Key details

  • A script is just a plain text file with code inside
  • The filename extension (.py) tells Linux what it is
  • Any text editor works - nano, gedit, VS Code, Kate
  • Save it somewhere you can find it - your home folder is fine