Something Like os.environ['HTTP_REFERER']

Victor Subervi victorsubervi at gmail.com
Sun Dec 20 14:01:51 EST 2009


On Sun, Dec 20, 2009 at 1:20 PM, Stephen Hansen <apt.shansen at gmail.com>wrote:

> On Sun, Dec 20, 2009 at 3:05 AM, Victor Subervi <victorsubervi at gmail.com>wrote:
>
>> Of course, I can pass the page name as a parameter, but that's not
>> elegant.
>>
>
> That is precisely what it is in fact-- elegant; it is non-elegant to have
> magical behavior where what 'imports' something somehow changes or
> determines how that something behaves.
>
> It may be possible to go into dark places to discover what code first
> imported a module, but its not possible to discover what code does
> subsequent imports-- and in either case, this is /not/ something that has
> any sort of elegance to it. Its deeply hackish.
>
> If you want a piece of code to have a variable number of differing
> behaviors, that's something you can handle in many elegant ways. That's
> something inheritance is good for, with a core default behavior represented
> in one class and more specialized behavior represented in sub-classes. But
> either way, you have to tell it which class to create at the moment, which
> entails passing in a parameter explicitly activating one or the other. This
> is a good thing. Don't try to get around it.
>

Inelegant. This will be elegant:

ourFile = string.split(__file__, "/")
p = ourFile[len(ourFile) - 1]
p = p[: - 3]
site = ourFile[4][:-10]
if site != '':
  site = site[:-1]

from this import that(site)

Now it's automated.
V
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20091220/d3943fb9/attachment.html>


More information about the Python-list mailing list