-
-
Save repodevs/143ca3c995f9e91e388399b6384ef704 to your computer and use it in GitHub Desktop.
python-decouple casting octal number 0o in python3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# by default this is will be converted to string | |
# if you want cast to octal number you need custom cast function | |
FILE_UPLOAD_PERMISSIONS=0o644 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from decouple import config | |
# Custom casting function | |
str_to_octal = lambda v: int(v, base=8) | |
FILE_UPLOAD_PERMISSIONS = config('FILE_UPLOAD_PERMISSIONS', default='0o600', cast=str_to_octal) | |
print(FILE_UPLOAD_PERMISSIONS) | |
# output will be `420` instead of `0o644` | |
# ref: https://stackoverflow.com/a/18806794/5460735 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment