1

I have two files. The first one is python file with some config constants defined. The second one is the json file where I would like to use one of these constants. Can I use the constant defined in python file in json file? How to import it and use it?

settings.py

MAX_SIZE = 100

settings.json

parameters:[
  {
    "max_size": MAX_SIZE
  }
]

1 Answer 1

1

I don't think you can access MAX_SIZE directly from JSON without an actual language implementation in between.

What you can do is the inverse - import "settings.json" into your settings.py file and then edit the imported json.

Pseudocode (in your settings.py file):

import parameters from settings.json

MAX_SIZE = 100

//Assign constant value to json object
parameters[0].max_size = MAX_SIZE
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks. That's what I did meanwhile.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.