<div class="gmail_quote">On Sun, Dec 20, 2009 at 1:20 PM, Stephen Hansen <span dir="ltr"><<a href="mailto:apt.shansen@gmail.com">apt.shansen@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div class="im">On Sun, Dec 20, 2009 at 3:05 AM, Victor Subervi <span dir="ltr"><<a href="mailto:victorsubervi@gmail.com" target="_blank">victorsubervi@gmail.com</a>></span> wrote:<br></div><div class="gmail_quote">
<div class="im"><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div class="gmail_quote"><div>Of course, I can pass the page name as a parameter, but that's not elegant.</div></div></blockquote><div><br></div></div><div>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. </div>
<div><br></div><div>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.</div>
<div><br></div><div>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.</div>
</div></blockquote><div><br>Inelegant. This will be elegant:<br><br>ourFile = string.split(__file__, "/")<br>p = ourFile[len(ourFile) - 1]<br>p = p[: - 3]<br>site = ourFile[4][:-10]<br>if site != '':<br>
site = site[:-1]<br><br>from this import that(site)<br><br>Now it's automated.<br>V<br></div></div>