1

I need to write some input data files for a python program, and I need the full thing:

comments, spacing, variable = value, etc.

Is there any library (line argparser for command line arguments) for python or should I write my own?

Thanks!

1
  • 1
    You could use pure Python modules as "data files". They support comments, spacing, variable assignment and more. Commented Jun 13, 2012 at 14:09

2 Answers 2

6

Take a look at the ConfigParser module (renamed to configparser in Python 3).

Alternatively, you could simply write the input data using Python syntax, and import the result into your main program.

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

Comments

0

Does the syntax have to look like that? Could you just use a character delimited file (like csv or tab-delimited) with each predefined field in a separate column? Python has well defined modules to handle csv data.

If you specifically want input files that present blocks of code, then aix's suggestion of importing would also work.

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.