In Perl I often read data in from the filehandle __DATA__
at the end of the script:
while (<DATA>) {
chomp;
say;
}
__DATA__
line1
line2
I find this quicker for testing code etc than reading in a file, as it means I can edit its contents on the fly.
From the doc:
The
__DATA__
token tells the perl compiler that the perl code for compilation is finished.Everything after the
__DATA__
token is available for reading via the filehandleFOOBAR::DATA
, whereFOOBAR
is the name of the current package when the__DATA__
token is reached.
Is there an equivalent in Python? If not, can anybody suggest the most Python-ish way of achieving a similar thing?