Why Does My Python Program Sometimes Print Binary Numbers Instead of Text?
Asked by
lane_8final
I'm new to Python and am learning before starting university. In one of my programs, calling print() occasionally produces numbers instead of the expected word. The output appears to be binary values that correspond to the text "open," but the problem doesn't happen consistently. Other runs work normally. I've already reinstalled Python and restarted my computer, and I'm running the program in VS Code. What could cause the source 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 seems to represent the word "open" as binary character values, compare the exact file contents each time and make sure you're running the file you think you are. It may be getting modified or you're accidentally executing a different copy.
Reply to this answer
Try displaying the file immediately before running it, then execute that same file explicitly. For example, on macOS or Linux you could use `cat /Users/Shared/Test/test.py; /usr/local/bin/python3 /Users/Shared/Test/test.py`. That lets you verify the source being run and can reveal whether VS Code is using an unexpected path or an older, changed version of the file.
Reply to this answer
Add your answer
Answers are reviewed before publication.
Related Discussions