python-3.xcharacter-encodingdbm

Which encoding does dbm use to save data to bytes(python(And how to convert it back to a string?))?


I mean that which type of encoding does dbm use in coding string to bytes? And how to convert it back to a string?


Solution

  • I guess that you mean encoding. So, a **dbm** database can only store strings, both as keys and values. In fact, it only stores bytes, and by default uses your default encoding if you give it Unicode strings.

    You can test your system default encoding through:

    For UNIX-based:

    echo $LC_CTYPE
    

    or

    echo $LANG
    

    For Windows using PowerShell:

    [System.Text.Encoding]::Default