diff options
| author | Matthias Geier <Matthias.Geier@gmail.com> | 2016-08-05 09:40:51 +0200 |
|---|---|---|
| committer | Matthias Geier <Matthias.Geier@gmail.com> | 2016-08-05 09:40:51 +0200 |
| commit | 5408733e7f7b3ed1f350bbae8d74e758a00f0be7 (patch) | |
| tree | bdac9db11b3e428a521342666ede37c087f2fc38 /examples/play_file.py | |
| parent | 104d912af4bd54bc34521c43ab53332e933425a0 (diff) | |
Accept device substrings in all examples
Diffstat (limited to 'examples/play_file.py')
| -rwxr-xr-x | examples/play_file.py | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/examples/play_file.py b/examples/play_file.py index 402d814..29a594c 100755 --- a/examples/play_file.py +++ b/examples/play_file.py @@ -7,9 +7,18 @@ PySoundFile (https://github.com/bastibe/PySoundFile/) has to be installed! import argparse import logging + +def int_or_str(text): + """Helper function for argument parsing.""" + try: + return int(text) + except ValueError: + return text + parser = argparse.ArgumentParser(description=__doc__) parser.add_argument("filename", help="audio file to be played back") -parser.add_argument("-d", "--device", type=int, help="device ID") +parser.add_argument('-d', '--device', type=int_or_str, + help='output device (numeric ID or substring)') args = parser.parse_args() try: |
