Is it possible to store data in a Python file in a way similar toRuby's __END__ section?

  • Thread starter Christopher Roach
  • Start date
C

Christopher Roach

I have a script that I am working on to process a bunch of data. A
good portion of the Tk-based GUI is driven by a large set of YAML data
and I'd love to store that data inside of the script so that I can
send just a single file to my colleague. Ruby has a mechanism for
doing this whereby I can load the data by doing a YAML.load(DATA)
which loads everything in the file after the __END__ keyword (for a
better explanation of this see http://bit.ly/V9w8m). I was wondering
if anyone knew of a way to do something similar in Python?

I guess it's probably a good idea to point out that I am not trying to
start a flame war or compare Ruby to Python in any way, shape, or
form. I'm simply wondering if there is something in Python that is
roughly equivalent to a feature that I find useful in Ruby. If so,
I'll use it, if not, it won't make me change my mind about using
Python for my implementation, I'm quite happy with my choice, with or
without this feature.

Thanks in advance for any help you all can offer.

Christopher
 
M

Martin v. Loewis

Christopher said:
I have a script that I am working on to process a bunch of data. A
good portion of the Tk-based GUI is driven by a large set of YAML data
and I'd love to store that data inside of the script so that I can
send just a single file to my colleague. Ruby has a mechanism for
doing this whereby I can load the data by doing a YAML.load(DATA)
which loads everything in the file after the __END__ keyword (for a
better explanation of this see http://bit.ly/V9w8m). I was wondering
if anyone knew of a way to do something similar in Python?

The common approach is to write

DATA="""\
yaml data here
"""

If you want to process the data in the same file, you can't really put
them at the end of the file - in fact, putting them at the beginning is
more common.

Regards,
Martin
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,535
Members
45,007
Latest member
obedient dusk

Latest Threads

Top