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

0
3
Asked By MellowCedar42 On

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?

2 Answers

Answered By SilverKite8 On

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.

Answered By QuietMaple17 On

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.

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.