Well, I finally ran into a Python Unicode problem, sort of

BartC bc at freeuk.com
Mon Jul 4 10:36:34 EDT 2016


On 04/07/2016 13:47, Ned Batchelder wrote:
> On Monday, July 4, 2016 at 6:05:20 AM UTC-4, BartC wrote:
>> On 04/07/2016 03:30, Steven D'Aprano wrote:

>>> You're still having problems with the whole Python-as-a-dynamic-language
>>> thing, aren't you? :-)

>> Most Pythons seem to pre-compile code before executing the result. That
>> pre-compilation requires that operators and precedences are known in
>> advance and the resulting instructions are then hard-coded before execution.
>
> This is the key but subtle point that all the discussion of parser mechanics
> are missing: Python today needs no information from imported modules in
> order to compile a file.  When the compiler encounters "import xyzzy" in
> a file, it doesn't have to do anything to find or read xyzzy.py at compile
> time.

Yeah, there's that small detail. Anything affecting how source is to be 
parsed needs to known in advance.

> If operators can be invented, they will only be useful if they can be
> created in modules which you then import and use.  But that would mean that
> imported files would have to be found and read during compilation, not
> during execution as they are now.
>
> This is a huge change.

I've used a kind of 'weak' import scheme elsewhere, corresponding to C's 
'#include'.

Then the textual contents of that 'imported' module are read by the 
compiler, and treated as though they occurred in this module. No new 
namespace is created.

I think that could work in Python provided whatever is defined can 
tolerate having copies redefined in each module that includes the same 
file. Anything that is defined once and is never assigned to nor 
modified for example.

-- 
Bartc



More information about the Python-list mailing list