In python,I want to use \b to backspace but it shows 0x08,how to fix this problem - python-3.x

print("a\bc", end="", flush=True)
#I hope the out put is c rather than a0x08c
the result

I tried out your code it works perfectly fine for me, it printed https://i.stack.imgur.com/bA97f.png
I'm guessing something wrong with the editor or python itself, but not really sure.
you can once try the code in IDLE, Jupyter Notebook / Lab, or Terminal.

Related

Python file does not work when executed by double click on Windows

Hi there is an issue I cannot work my head around.
Basically the script works very fine when I execute it via Powershell/cmd python ./myscript.py but not when I double click on it.
I checked with a much simpler script to check if the issue was with my Windows/Python3 configuration.
import os
if __name__ == "__main__":
print('hello')
os.system("PAUSE")
And this one works either by double click or by python ./myscript.py
I guess the issue is with my script but no error is returned and it works just as expected when launched in PS so I do not get it.
Would you guys have some debugging insights?
Similar to this old question: Python Script not working on double click

Code work in PyCharm but doesn't work when lauching through python console

I have been working on a project and in the end it's suppose to print an output in a notepad file and it works perfectly in pycharm but as soon as I launch my file with python it crash every time I execute the code
I am 100% sure that the problem lies between the line I copied and pasted and I know that if start the project in pycharm with the python console setting active it work too so it may be some right problem? that's the conclusion I came with althought I'm not sure and I don't have any idea how to fix it even with my research. Ho and I,ve checked too and my python is up-to-date
number_of_product = [0,0,0,0]
Total = 0
with open("Bill.txt", "w+") as Bill:
Bill.write("{0} ChocoMilk\n".format(number_of_product[0]))
Bill.write("{0} Katkit\n".format(number_of_product[1]))
Bill.write("{0} N&N's\n".format(number_of_product[2]))
Bill.write("{0} SourJoes\n".format(number_of_product[3]))
Bill.write("Total : {0}$".format(Total))
The result should be 5 line of text written in a notepad file.
I found the problem: I was opening the Pycharm file by clicking "Open with" python3.7 and Windows wasn't giving me all the right I needed.
You need to change the basic application that runs the program from Pycharm to Python itself.

Create a program that asks the user for a string and then prints the string in upper case

EDIT: I tried the code lines in the link to other questions that were similar, however the programs did not execute correctly
I am a full-on noob trying to complete some free online resources for self improvement and learning. I am using University of Waterloo's 'Python from scratch' and CS circles course I have tried to answer this question and cannot seem to:
Write a program that asks the user for a string and then prints the string in upper case.
I have tried:
print (str(input()).upper)
AS WELL AS
text = input()
print (text.upper)
AND
print(input().upper())
all programs run, but dont have correct output so I dont know what I am missing here. It's likely obvious and I may feel foolish
I would love to learn and move on, thanks for any assistance!
this is 'Python from scratch' 2.11 problem 'g' (7th problem in set)
You were very close, the following works:
input.upper()
so, print(input.upper())
should work for you.
text=input()
print(text.upper())
print(input().upper())
This should have worked for you in Python 3.x

Cycling through webbrowser tabs with autokey

I am trying to make a macro that will cycle through and update browser tabs when hitting 'F10'.
Currently it only updates the page I'm currently on, it doesn't cycle through them, I tried googling for it but all the answers were for 'AutoHotKey'. So I looked at the documentation for 'AutoKey' and tried to convert a 'AutoHotKey' script to 'AutoKey' (python) but it doesn't work and I have no idea why.
Here's the script
keyboard.send_keys("< f5>")
keyboard.press_key("< ctrl>")
keyboard.send_keys("< tab>")
keyboard.release_key("< ctrl>")
replacing lines 2 -> 4 with just a "keyboard.press_key("< ctrl>" + "< tab>") doesn't work (I'm not quite sure if it's ("< ctrl> + < tab>") instead, but none works, sadly)
(Please bare in mind that the spaces in front of the "keycodes" are so that Stackoverflow will show them)
Thank you all in advance!!!
I asked in the Google group of AutoKey and they came up with this:
keyboard.send_keys("<f5><ctrl>+<tab>")
And that's all you need, it works flawlessly.
I would later change the 'f5' to 'enter' instead and it never skips any browser tab, it's awesome!
Thank you all for your time!
It strangely worked only the other way around for me, but I think that might still suite your task:
keyboard.press_key("<ctrl>")
keyboard.press_key("<tab>")
time.sleep(0.3)
keyboard.release_key("<ctrl>")
keyboard.release_key("<tab>")
keyboard.send_key("<f5>")
I hope this helps.

Novice with Python

I have just downloaded Python 3.3.2 to use on windows7 and run the msi file to install. After installation I have tried using the prog only to find that every time I run my initial print 'hello world' it keeps reporting a syntax error.
I have tried both single and double quotes but each time reports a syntax. It will add say 8 + 9 and return the answer but no joy with using a print statement.
I have tried both the shell and a new window but without success.
Any advice please much appreciated.
If you are using Python 3.x, you have to do print('hello world').
In Python 2.x, print was a statement, like if, for, etc. Now it is a function, thus the ().
You're probably using instructions for a python-2 program, where print was a statement, rather than a function. In python >= 3, you have to do print(something), rather than just print something.

Resources