break in a module

Chris Angelico rosuav at gmail.com
Sat Jun 18 01:06:47 EDT 2011


On Sat, Jun 18, 2011 at 2:49 PM, Steven D'Aprano
<steve+comp.lang.python at pearwood.info> wrote:
> Not quite. In my config language, "ignored" means ignored. There was no
> way of accessing the rest of the file, short of guessing the file name,
> opening it and reading it as text.
>
> In Perl, the __END__ and __DATA__ keywords mark the end of the Perl
> program, and leave the rest of the document visible to the caller via a
> special file handle:

Sure, but if you don't use that handle, it comes to the same thing.
It's like a function's return value when you just want its side
effects, or using re.match and ignoring all but whether it evaluates
as True or False. In REXX, you can access any part of the source file
using the sourceline() function - sometimes I've done things like
this:

/*
Usage: scriptname [arg] [arg] [arg]
arg: specifies the number of times to yell Argh
arg: specifies the type of black beast to kill you
arg: chooses an Abstract Resource Group

Use this only in cases of blargh.
*/
.
.
.
.
usage:
do i=2 to sourceline() until sourceline(i)="*/"; say sourceline(i); end

Does this mean that the comment isn't ignored? Nope. It's ignored, but
it can be retrieved through in-language means.

Anyhow, it's not uncommon to abuse language features to do different
things. I've heard that it's faster in MS-DOS Batch to put comments
with a leading colon (making them labels for goto) than to use the REM
(remark) command...

ChrisA



More information about the Python-list mailing list