Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 8374

Beginners • Re: RPi3 Python and Motion Sensor Project

$
0
0
In addition to previous response: a slightly smaller solution is to use random.choice(seq)
https://docs.python.org/3/library/rando ... -sequences

Code:

import randomplaylist = ["mistsoftime", "purplehaze", "snowblind", "trooper", "wheelsofsteel"]print( random.choice(playlist))
The integration into existing code could look like this. Uses the modern f-string or "Formatted String Literals"

Code:

# define playlist array earlier !subprocess.call( f"aplay -D plughw:0,0 {random.choice(playlist)}.wav", shell=True)
And perhaps switch to subprocess.run ; should be used later than python 3.5.

Statistics: Posted by ghp — Fri Aug 08, 2025 2:13 pm



Viewing all articles
Browse latest Browse all 8374

Trending Articles