Why Does My Python Program Sometimes Print Binary Numbers Instead of Text?

0
5
Asked By MellowPine47 On

I'm new to Python and am learning it before starting university. I've noticed that sometimes my print() statement outputs numbers instead of the expected word, while other runs behave normally. The numbers appear to be binary representations of the text "open". I've already reinstalled Python and restarted my computer, and I'm running the program in VS Code. What could cause the file or output to change between runs, and how can I troubleshoot it?

2 Answers

Answered By QuietHarbor62 On

Try printing or displaying the source file immediately before executing it, then compare that with the file open in VS Code. For example, from a terminal you could run `cat /Users/Shared/Test/test.py; /usr/local/bin/python3 /Users/Shared/Test/test.py`. That can reveal whether the file is being modified, whether VS Code is running a different copy, or whether a different Python interpreter is being used.

Answered By CuriousMaple8 On

Did you change or save the code between runs? Since the output spells "open" when interpreted as binary character codes, it may be worth checking that you're running the file you think you are and that it hasn't been overwritten or changed unexpectedly.

Related Questions

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.