Skip to content

Instantly share code, notes, and snippets.

@repodevs
Created December 5, 2020 16:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save repodevs/143ca3c995f9e91e388399b6384ef704 to your computer and use it in GitHub Desktop.
Save repodevs/143ca3c995f9e91e388399b6384ef704 to your computer and use it in GitHub Desktop.
python-decouple casting octal number 0o in python3
# 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
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