Why Does My Python Program Sometimes Print Binary Numbers Instead of Text?
Asked by
!+FairEnough
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?
Answers
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.
Reply to this answer
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.
Reply to this answer
Add your answer
Answers are reviewed before publication.
Related Discussions