Reputation: 2233
I am using following command in my Python code to list devices available in /dev
directory:
devices = ["/dev/" + x for x in os.popen("ls /dev/ | egrep -i 'ttyUSB|ttyS'").read().strip().split('\n')]
How can I modify it to find only ttyS0
and ttyS1
? Currently it returns all ttyS s :
ttyS0,ttyS1, ttyS11, ttyS12, ...
Upvotes: 1
Views: 77
Reputation: 20014
Change the pattern to the following:
devices = ["/dev/" + x for x in os.popen("ls /dev/ | egrep -i 'ttyUSB|ttyS[01]$'").read().strip().split('\n')]
Upvotes: 1