Python backspace (\b) creating checkmark characters [duplicate] - python

This question already has an answer here:
python IDLE shell appears not to handle some escapes correctly
(1 answer)
Closed 3 years ago.
I'm a Raspberry Pi using Thonny Python's IDE to code, and whenever I try to use a backspace in the form of '\b', it outputs as a check mark:
Like this one
I've already looked at some articles on here and only a few mention a GUI bug within Tkinter, but since I'm not using that I'm not sure what's going on. I've also tested it with a simple print('a\b') command in the IDLE, but it still comes out with the check mark following the a.
For reference, I'm using code from this answer: https://stackoverflow.com/a/39504463/11357553
It's specifically this part that produces the oddity:
sys.stdout.write('\b')
sys.stdout.flush()
I'm simply looking to complete the provided function by deleting the most recent character printed to the spinning cursor. I'm rather new and have been able to solve most of my problems, but this one leaves me stuck.

IDLE does not implement a terminal. It does not process either control characters or escape sequences. Run your program in an actual terminal emulator and not via IDLE.
IDLE uses tkinter to implement its GUI. It uses two TK text areas to form the editor and console parts of its windows.

Related

How to run Octave code without the Octave IDE (similarly to Python)? [duplicate]

This question already has answers here:
Octave: How to prevent plot window from closing itself?
(2 answers)
Closed 2 years ago.
Context: When I use Python + matplotlib, I can compose the code in any text editor (like Sublime Text), do CTRL+B, and then the text output appears in the "Build results" panel of the text editor, and, optionally, graph/plots are rendered in a new GUI window.
Under the hood, the text editor calls python myscript.py when we do "Build", and that's it.
It's simple and working flawlessly, easily.
Now I'm trying to do the same with GNU Octave: write a test.m code (such as this one). Then run it from my favorite text editor (and not the Octave IDE), or from command-line. I tried:
octave test.m: the plot is displayed during 100 ms and then disappears! not OK
octave --persist test.m: the plot stays displayed, this is ok ... but this part is not good: it opens an IDE (which I don't want since I want to continue using my usual text editor!), see the background window:
How to have GNU Octave behave like expected: the text output in stdout (either in terminal or in the "Build Results" panel of your text editor) and the plot output in a new window? Important: without spawning an IDE window.
I find strange that this behaviour is not the default behaviour. Shouldn't it be?
Edit: solved with:
octave-cli test.m
and
k = plot(...)
waitfor(k)
to have a similar effect I run the command line interface octave-cli or octave --no-gui in a terminal and vim in a different one.
Not exactly what you are looking for, but matplotlib is a python module while octave is a separate program from your editor.
See example of the two terminals and the graphs, all on separate windows.

\b (backspace) not functioning correctly in Python IDLE, instead printing box character

I am writing a program for a simple loading animation, like the one you see while Window Command is processing something. Unfortunately, this does not seem to function in Python IDLE.
I discovered that the root of the problem was Python's \b function, which is supposed to backspace the character written before it. For some reason, this instead prints a character. When opened in CMD, it works just as its supposed to.
Any ideas of what could be wrong?
Example of backspace not working in IDLE:
One answer is that IDLE doesn't support \b, so it puts the box with a question mark. there is no way to fix this, other than asking Python to add support for it.
IDLE is functioning correctly; it just isn't working the way you expect it to. If your program requires \b to move the cursor to the left to allow other text to overwrite the previous character, then you need to use a terminal that supports such behavior.

Only allowing one instance of a pyqt4 application [duplicate]

This question already has answers here:
PyQt - how to detect and close UI if it's already running?
(3 answers)
Closed 7 years ago.
I have created a pyqt4 app and I want to make it so only one instance (of QApplication) is allowed to run.
The program reads and writes audio files, and if more than 1 instance is running, Windows (linux is fine) throws errors that 2 programs are trying to access the same files. I see a lot of java and C apps that will display a simple dialog if the program is already running, I just want to know how to do this in pyqt4.
A little help?
This kind of programming pattern is called a "singleton" instance or a "singleton application".
Usually it is done with a global mutex or by locking a file early in the life of the program.
And when you program launches, if the file handle is already locked, then you exit.
Qt Solutions has it here: http://doc.qt.digia.com/solutions/4/qtsingleapplication/qtsingleapplication.html
https://qt.gitorious.org/qt-solutions/qt-solutions/source/841982ceec9d30a7ab7324979a0fd5c9c36fd121:qtsingleapplication
It would probably take a bit of work to get those global mutexes/locks to work in pyqt, since pyqt doesn't have the qt-solutions part in it yet as far as I could tell.
Here is an alternative that uses a cross platform python script:
Python: single instance of program
Hope that helps.
Thanks. I Used https://gitorious.org/qsingleapplication/qsingleapplication/source/ca13324b0f5bdfcaf4e379a78108f0bd85fed98a:qSingleApplication.py#L66 And Called QSingleApplication On My MainWindow And Works Fine

Lost in pudb command line area

I'm starting to use pudb for Python debugging. It comes up fine, and I can step through, and it stops at breakpoints I put into code with pudb.set_trace(). So far so good. The main problem I'm having is this:
If I hit ^X to get to the command-line pane, I can type executable lines or variable names, like running interactive Python, but the slightest typo (or experiment in search of other commands, or request for help()) lands me in a state I can't recover from. Even Control-c (as claimed at https://docs.python.org/2/tutorial/appendix.html#tut-interac) just shows up as "^C" and does nothing.
For example, if I type "help()", it prints some Python (not pudb) help, redisplays "help()" in yellow, and then I'm dead in the water. Backspace won't affect the "help()" that's displayed, and ^H just gets displayed as caret + H -- until I hit return, when it seems to be appended to "help()" as literal backspaces, since I can make part of all of "help()" disappear. I can type anything after "help()", but I always get:
SyntaxError: unexpected EOF while parsing
followed by a redisplay of what I had typed. How do I "clear" this state and get back to the normal command line, short of quitting my terminal program?
Using Terminal on Mac OS X 10.9.5, though I can also try Linux.
Your description points not to a problem with pudb but rather to a problem with behaviour of Backspace on the Terminal you're using.
Please try changing this behaviour so it's sending the proper Backspace. This could be helpful: http://fredericiana.com/2006/10/16/fixing-backspace-and-delete-for-ssh-in-os-xs-terminalapp/
Then, you should be able to enter pudb's full screen Python interpreter by '!' and leave it by Control-D.
A "small" Python command line inside pudb's interface can be accessed by Control-X and you can leave it by Control-X. In this one you have three other shortcuts which also let you manipulate the command line: Control-V - insert new line and Control-N/Control-P to browse command line history. If any of these is not working it's rather an issue with the way the Terminal treats these shortcuts and not in the way pudb does.

Python Print output at same place or position working on IDLE [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
How to create a spinning command line cursor using python?
python 3 IDLE progressbar/loadingbar
I want to print the output as below:
Percentage: 10%
and only the percentage keeps changing to 20, 30, 40 so on in the same position. Overwriting 10%. I saw many of the posts on stackoverflow. But none of them work right in Python 3.
I tried using \r, \c and even \b but does not work from within print() or sys.stdout()
I am trying this using IDLE and running the program from Python Shell by pressing F5. The environment is Windows.
Please help. Thanks
IDLE does not provide a true TTY/terminal. Sorry.
Test your program by running it from the windows command line:
C:\PythonXX\python.exe path\to\script.py

Categories