<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On 16 June 2018 at 15:49, Rin Arakaki <span dir="ltr"><<a href="mailto:koyukukan@gmail.com" target="_blank">koyukukan@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi,<br>
I'm wondering if it's possible and consistent that loosen 'as' assignment, for example:<br>
<br>
>>> import psycopg2 as pg<br>
>>> import psycopg2.extensions as pg.ex<br>
<br>
You can't now assign to an attribute in as statement but are there some reasons?<br>
To be honest, I'll be satisfied if the statement above become valid, but also interested in general design decisions about 'as' functionality, I mean, it can be applicable to all expression that can be left side of '=' such as 'list[n]' one, and also other statement than 'import' such as 'with'.<br></blockquote><div><br></div><div class="gmail_extra"><div class="gmail_quote">This is essentially
monkeypatching the psycopg2 module to alias the "extensions" submodule
as the "ex" submodule. You can already do that today as:</div><span class="gmail-im"><div class="gmail_quote"><br></div><div class="gmail_quote"> >>> import psycopg2 as pg</div><div class="gmail_quote"> >>> import psycopg2.extensions</div></span><div class="gmail_quote"> >>> pg.ex = pg.extensions</div><div class="gmail_quote"><br></div><div class="gmail_quote">Monkeypatching
other modules at runtime is a questionable enough practice that we're
unlikely to add syntax that actively encourages it.<br></div></div><div class="gmail_extra"><br></div>Cheers,</div><div class="gmail_quote">Nick.<br></div></div><div class="gmail_extra"></div><div class="gmail_extra"><br>-- <br><div class="gmail_signature" data-smartmail="gmail_signature">Nick Coghlan | <a href="mailto:ncoghlan@gmail.com" target="_blank">ncoghlan@gmail.com</a> | Brisbane, Australia</div>
</div></div>