1

I have a Python app that contains an object structure that the user can manipulate. What I want to do is allow the user to create a file declaring how the object structure should be created.

For example, I would like the user to be able to create the following file:

foo.bar.baz = true
x.y.z = 12

and for my app to then create that object tree automatically. What's the best way to do something like this?

1
  • 1
    What is the expected result of foo.bar.baz = true? A tree of directories foo/bar/baz? And what is the meaning of true or 12 here? Commented Mar 16, 2010 at 18:08

1 Answer 1

1

Typically problems like this one are solved with XML. However in your case you can do something even easier.

Assuming the dots represent hierarchy delimiters, you could read in the left hand side of the = sign (input.split('=')[0]), and then perform a split('.') on the dots. Next, create a nested dictionary structure to match this. i.e. object[foo][bar][baz] returns True and object[x][y][z] returns 12

If you don't feel like coding this by hand, try out one of the many Configuration File parsers for python

Sign up to request clarification or add additional context in comments.

Comments

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.