Perl allows me to use the __DATA__ token in a script to mark the start of a data block. I can read the data using the DATA filehandle. What\'s the Pythonic wa
Use the StringIO module to create an in-source file-like object:
from StringIO import StringIO
textdata = """\
Now is the winter of our discontent,
Made glorious summer by this sun of York.
"""
# in place of __DATA__ = open('richard3.txt')
__DATA__ = StringIO(textdata)
for d in __DATA__:
print d
__DATA__.seek(0)
print __DATA__.readline()
Prints:
Now is the winter of our discontent,
Made glorious summer by this sun of York.
Now is the winter of our discontent,
(I just called this __DATA__ to align with your original question. In practice, this would not be good Python naming style - something like datafile would be more appropriate.)