[Dev] Upcoming Chandler date/time related changes
Donn Denman
donn at osafoundation.org
Wed May 25 22:06:56 PDT 2005
On May 24, 2005, at 4:43 PM, Andi Vajda wrote:
>
>> I think there are subtle differences. I would have to check, but I
>> believe one difference is that with import doing reload() would work
>> as
>> expected, but not so with from. In other words, doing:
>>
>> from datetime import datetime
>> # then sometime later call
>> reload(datetime)
>>
>> would be slightly different than:
>>
>> import datetime.datetime as datetime
>> # then sometime later call
>> reload(datetime)
>>
>> We haven't been rigorous with enforcing the convention though. And I
>> don't know if we are actually using reload(), or if we are even
>> planning
>> on using it, or if it would actually be a bad idea to even try use it.
>
> I don't ever use reload, I've never been able to make it work reliably.
> Is anybody using reload ?
We hope to use reload in the "Test/Reload Parcels" menu to provide more
interactive Chandler development sessions sometime soon. Changing a
line of Python code currently requires us to quit and relaunch
Chandler. Many bugs could be fixed without the quit/launch cycle
simply by editing the file and reloading the new code into the current
running Chandler. Getting this to work will require us to change all
references to modules that we'd like to be reload-able so they use
"import" instead of "from".
Are there other good reasons to use "import" rather than "from"? Yes;
Alex Martelli recommends using "import"! See the paragraph in the
middle of page 120 of the Python in a Nutshell book for specifics. My
understanding, based on reading his sections on "from" and "import" is
this: Using "import" brings the module into the system, where it can be
shared by multiple client modules, so the loading is only done once
(until you reload). Using "from" brings selected attributes into your
module's global data space, so you have to load your own copy of those
attributes. This may indeed give you faster lookup, as Andi said
previously, but at the cost of always loading your own copy. So
there's a tradeoff, hence we don't have a hard and fast rule about not
using "from". Just don't ever use "from module import *" form in
Chandler source code because that can cause all kinds of problems.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: text/enriched
Size: 2233 bytes
Desc: not available
Url : http://lists.osafoundation.org/pipermail/dev/attachments/20050525/07e7925f/attachment.bin
More information about the Dev
mailing list