[Python-Dev] __file__

Michael Foord fuzzyman at voidspace.org.uk
Sat Feb 27 00:37:26 CET 2010


On 26/02/2010 23:35, Glenn Linderman wrote:
> On approximately 2/26/2010 2:55 PM, came the following characters from 
> the keyboard of Brett Cannon:
>>
>> Maybe Greg's and my response to the mention of dropping this feature
>> is too strong -- after all we're both dinosaurs. And maybe the
>> developers who want the feature can write their own loader.
>>
>>
>> We could also provide if necessary.
>
> So if the implementation stores .pyc by default in a version-specific 
> place, then it seems there are only two things needed to make a python 
> byte-code only distribution...
>
> 1) rename all the .pyc to .py
> 2) packaging
>
> When a .pyc is renamed to .py, Python (3.1 at least) recognizes and 
> uses it... I assume by design, rather than accident, but I don't know 
> the history.
>
> I didn't experiment to discover what __file__ and __cached__ get set 
> to in this case (especially since I don't have a version with the 
> latter :) ).
>
> I speculate that packaging a distribution in this manner would be 
> slightly different that how it is currently done, but I also suspect 
> that it would avoid the same half of the stat calls, to aid performance.
>
If this is possible with the new scheme, so long as the Python version 
and magic number match, then it is slightly kooky but meets the use case.

All the best,

Michael

-- 
http://www.ironpythoninaction.com/
http://www.voidspace.org.uk/blog

READ CAREFULLY. By accepting and reading this email you agree, on behalf of your employer, to release me from all obligations and waivers arising from any and all NON-NEGOTIATED agreements, licenses, terms-of-service, shrinkwrap, clickwrap, browsewrap, confidentiality, non-disclosure, non-compete and acceptable use policies (”BOGUS AGREEMENTS”) that I have entered into with your employer, its partners, licensors, agents and assigns, in perpetuity, without prejudice to my ongoing rights and privileges. You further represent that you have the authority to release me from any BOGUS AGREEMENTS on behalf of your employer.




More information about the Python-Dev mailing list