Why print (\ a) does not work in IDLE

NOTE I slightly modified q so that it no longer duplicates. Unfortunately.

I have these laborious bioinformatics scripts that I run. I would like them to beep when they were done.

I'm on OS X.

In a similar thread, I found that print '\a' might work, but in Idle it just prints []

Why it does not work in IDLE

+4
source share
2 answers

The reason that it does not give a sound signal is because \a (or ^G ) is the terminal bell code; it is up to stdout software to turn it into sound. Terminal.app will play the sound (unless you set it to "visual call", but turn it off completely), but Idle will not. And of course, if you run without tty, you won’t get anything.

If you don't mind using PyObjC (which is pre-installed with Apple Pythons installed in all recent versions of OS X):

 import Cocoa Cocoa.NSBeep() 

Of course, this sounds like an OS X system signal, not a terminal call. Also, maybe this is a different sound, which means that if you turn off the call in the terminal, your script will still sound. (If you really want to use Terminal Terminal, you can always use script Terminal through, for example, ScriptingBridge. But I don’t think you care.)

+4
source

This tiny Python snippet using afplay does what I need: ten loud calls at the end of the program:

 from os import system for i in range(0,10): system('afplay /System/Library/Sounds/Glass.aiff') 

I assume the overhead of the import system is small, but it works for me

+1
source

Source: https://habr.com/ru/post/1445119/


All Articles