Visual Studio Code Watch hexadecimal notation

Asked 2 years ago, Updated 2 years ago, 62 views

When debugging Visual Studio Code in Python, set the contents of the variable to hexadecimal. I checked if it was possible, but if you specify <variable name>,h in the watch expression,
I saw that it would be hexadecimal, but I couldn't.
Is Python impossible?

python vscode

2022-09-30 20:13

1 Answers

The value displayed in the watch expression is the same as the value displayed when running on the source or debug console.
<variable name>,h may have been referenced by the C++ notation, but Python simply interprets it as the variable h and outputs it.

You can watch hexadecimal numbers in the same description as when displaying hexadecimal numbers in the source or debug console.
hex(<variable name>) to make the number hex.

In your environment, I was able to confirm the hexadecimal notation of the string by using the following description in a watch style.

  • ord(hoge)
  • "{:x}".format(ord(hoge))
    :X uppercase
  • binascii.hexlify(u.encode("utf-8")
    import binascii

As for the watch expression, it does not use print statements, so syntax that can be used in print like hoge, fuga, sep="&" is an error.
Screenshot Debugging


2022-09-30 20:13

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.