Re: [Python-Dev] pkgutil, pkg_resource and Python 3.0 name space packages

2008-01-08 Thread Paul Moore
On 08/01/2008, Christian Heimes [EMAIL PROTECTED] wrote:
 Paul Moore wrote:
  What would be used on Windows? It's likely to be of marginal use on
  Windows, but an appropriate equivalent should be defined. Possibly
  just replace ~ with %USERPROFILE%. I'd argue against anything under
  %APPDATA% as that directory is hidden.

 No, we shouldn't mess with the profile root directory on Windows. The
 data should either be installed under Application Data or under My
 Documents. You are right, the appdata directory is hidden by the
 installer could add a link to Application Data\Python\python2.x\ to the
 start menu.

Not My Documents, please! That's for documents, not configuration.
%USERPROFILE% is actually where most other applications put stuff. The
alternative would be %HOMEDRIVE%%HOMEPATH% which is what
os.path.expanduser uses.

 Apropos My Documents and other special directories on Windows. Python
 doesn't have an API to get the directories from the registry. Is
 somebody interested in having a module for the task? I've some code for
 the job on disk.

It would probably be a good idea to have it in the core, although I'm
sure it's in pywin32, and anyone coding Python on Windows will have
that. Personally, I've no code that would benefit from this, so I'd be
+0 on theoretical grounds only.

Paul.
___
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] New Developer

2008-01-08 Thread Paul Moore
On 08/01/2008, Mark Dickinson [EMAIL PROTECTED] wrote:
 Hello all,

 I've recently been granted commit privileges; so, following the usual
 protocol, here's a quick introduction.

Welcome, congratulations and thanks for your work so far!
Paul.
___
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] New Developer

2008-01-08 Thread Nick Coghlan
Mark Dickinson wrote:
 Hello all,
 
 I've recently been granted commit privileges; so, following the usual 
 protocol, here's a quick introduction.

Welcome, and as Paul said, thanks for everything you've done already.

Cheers,
Nick.

P.S. Does this mean Tim now has another person he can talk numerical 
correctness with without having to slow right down and use really small 
words? ;)

-- 
Nick Coghlan   |   [EMAIL PROTECTED]   |   Brisbane, Australia
---
 http://www.boredomandlaziness.org
___
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] test_sys failures

2008-01-08 Thread Nick Coghlan
Guido van Rossum wrote:
 No answers yet, but a clue, and anyone on OSX should now be able to
 reproduce this (with 2.5, 2.6 or 3.0) as follows:
 
   ./python ./Lib/test/test_sys.py | cat
 
 That is, the problem happens when stdout is redirected to a pipe (or a file).

Redirecting stdout also fails for both the trunk and the py3k branch for 
me on Ubuntu. If I redirected stderr as well then the tests worked again.

Given that a pipe/file and the console very likely *do* have different 
encodings, maybe the test is just wrong?

Cheers,
Nick.

-- 
Nick Coghlan   |   [EMAIL PROTECTED]   |   Brisbane, Australia
---
 http://www.boredomandlaziness.org
___
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] test_sys failures

2008-01-08 Thread Jeroen Ruigrok van der Werven
-On [20080108 12:09], Nick Coghlan ([EMAIL PROTECTED]) wrote:
Redirecting stdout also fails for both the trunk and the py3k branch for 
me on Ubuntu. If I redirected stderr as well then the tests worked again.

Given that a pipe/file and the console very likely *do* have different 
encodings, maybe the test is just wrong?

This sounds like a problem I recently blogged about (verbatim copy):

When you use Python with sys.stdout you might run into a problem where
sys.stdout.encoding suddenly becomes None. This happens due to the fact that
upon using a pipe or redirection, at least under Unix, it falls back to not
knowing anything about the target. In order to work around this you can add a
fallback to use locale.getpreferredencoding(). So if you use encode() on a
string you can do something like:

from locale import getpreferredencoding
 
text = uSomething special
 
print text.encode(sys.stdout.encoding or getpreferredencoding() or 'ascii', 
'replace')

This is how we currently use it within Babel as well for printing the locale
list.

-- 
Jeroen Ruigrok van der Werven asmodai(-at-)in-nomine.org / asmodai
イェルーン ラウフロック ヴァン デル ウェルヴェン
http://www.in-nomine.org/ | http://www.rangaku.org/
Angel to some, Daemon to others...
___
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] Backport PEP 3129: Class Decorators

2008-01-08 Thread Robin Stocker
Christian Heimes schrieb:
 PEP 3107 (function annotation), PEP 3104 (nonlocal) and PEP 3132
 (extended iterable unpacking: a, *b = 1,2,3) are IMHO other useful
 feature for 2.6. nonlocal would require a __future__ import.

I'm planning to work on PEP 3107 (function annotations) after I have 
finished backporting PEP 3102 (keyword-only arguments) (issue1745).

Could someone with access rights update the spreadsheet so there won't 
be duplicated efforts?

http://spreadsheets.google.com/pub?key=pCKY4oaXnT81FrGo3ShGHGggid=2


   Robin Stocker
___
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] Backport PEP 3129: Class Decorators

2008-01-08 Thread Christian Heimes
Robin Stocker wrote:
 I'm planning to work on PEP 3107 (function annotations) after I have
 finished backporting PEP 3102 (keyword-only arguments) (issue1745).

Thanks! I've backported class decorators: http://bugs.python.org/issue1759

Could somebody with more knowledge about grammer and ASDL check it out,
please?

Christian
___
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] pkgutil, pkg_resource and Python 3.0 name space packages

2008-01-08 Thread Christian Heimes
Paul Moore wrote:
 Not My Documents, please! That's for documents, not configuration.
 %USERPROFILE% is actually where most other applications put stuff. The
 alternative would be %HOMEDRIVE%%HOMEPATH% which is what
 os.path.expanduser uses.

On mys system only one application has put configuration data directly
into USERPROFILE. It's Python's IDLE and I don't like it. It should
store its configuration under APPDATA.

I also don't agree that Python extensions are configuration data. They
are code, maybe plugins and the files are user editable content. Ms
products like Visual Studio store files like them in My Documents.

 It would probably be a good idea to have it in the core, although I'm
 sure it's in pywin32, and anyone coding Python on Windows will have
 that. Personally, I've no code that would benefit from this, so I'd be
 +0 on theoretical grounds only.

Python's _winreg module and pywin32 expose several functions to get the
paths from the registry but I don't think it has a simple function like
get_mydocuments().

Christian
___
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] Backport PEP 3129: Class Decorators

2008-01-08 Thread Eli Courtwright
Since we're talking about class decorators, I have a question about function
and instancemethod objects.  The following code works

class Root(object):
   def index(self):
   return Hello World!
   index.exposed = True

but this code

class Root(object):
   def index(self):
   return Hello World!
index.exposed = True

gives the following exception

Traceback (most recent call last):
  File stdin, line 1, in module
AttributeError: 'instancemethod' object has no attribute 'exposed'

I can tell that instancemethods can't have attributes added to them outside
of their class definition.  Is this part of the Python language spec, or
just an implementation detail of CPython?

I bring this up here because it makes writing certain class decorators much
more annoying.  For example, if I want to write a class decorator that will
set exposed=True for every method of a class, I must resort to
shenanigans.

- Eli
___
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] Backport PEP 3129: Class Decorators

2008-01-08 Thread Eli Courtwright
Christian,

Thanks for the example; I'm sorry that I didn't read the docs carefully
enough to realize that I could extract the original function and set the
attribute on that.

- Eli

On Jan 8, 2008 11:49 AM, Christian Heimes [EMAIL PROTECTED] wrote:

 The example should shed some light on the problem:

 ...

  Root.index.im_func.exposed = False
  Root.index.exposed
 False

___
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] pkgutil, pkg_resource and Python 3.0 name space packages

2008-01-08 Thread Christian Heimes
Paul Moore wrote:
 Not My Documents, please! That's for documents, not configuration.
 %USERPROFILE% is actually where most other applications put stuff. The
 alternative would be %HOMEDRIVE%%HOMEPATH% which is what
 os.path.expanduser uses.

http://msdn2.microsoft.com/en-us/library/bb762494(VS.85).aspx

CSIDL_PROFILE (FOLDERID_Profile)
Version 5.0. The user's profile folder. A typical path is
C:\Documents and Settings\username. Applications should not create files
or folders at this level; they should put their data under the locations
referred to by CSIDL_APPDATA or CSIDL_LOCAL_APPDATA.

Christian
___
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


[Python-Dev] PEP: Lazy module imports and post import hook

2008-01-08 Thread Christian Heimes
I've attached the first public draft of my first PEP. A working patch
against the py3k branch is available at http://bugs.python.org/issue1576

Christian
PEP: 369
Title: Lazy importing and post import hooks
Version: $Revision$
Last-Modified: $Date$
Author: Christian Heimes christian(at)cheimes(dot)de
Status: Draft
Type: Standards Track
Content-Type: text/x-rst
Created: 02-Jan-2008
Python-Version: 2.6, 3.0
Post-History:


Abstract


This PEP proposes enhancements for the import machinery to add lazy
importing and post import hooks to Python.

It is intended primarily to support the wider use of abstract base
classes that is expected in Python 3.0.


Rationale
=

In current Python an import always loads a module from the disk even if
the importing module never actually uses the module named in the import
statement. It requires some extra code to conditionally import modules
or the unnecessary imports can slow down a small script.

Embedding import statements inside functions is no solution, as doing
so invokes the import machinery every time the function is called.
Hiding the import inside a function also makes the modules dependencies
less clear.

Python also has no API to hook into the import machinery and execute code
*after* a module is successfully loaded. The import hooks of PEP 302 are
about finding modules and loading modules but they were not designed to
as post import hooks.

 - An import always loads the module from the disk which may cause a 
   considerable speed impact on the execution time of a small script.

 - Conditional imports make the code harder to read and may lead to slow
   and ugly function level imports.

 - Python can't notify code when a module is loaded.
   

Use cases
=

A use case for a post import hook is mentioned in Nick Coghlan's initial
posting [1]_. about callbacks on module import. It was found during the
development of Python 3.0 and its ABCs. We wanted to register classes 
like decimal.Decimal with an ABC but the module should not be imported
on every interpreter startup. Nick came up with this example::

   @imp.when_imported('decimal')
   def register(decimal):
   Inexact.register(decimal.Decimal)

The function ``register`` is registered as callback for the module named
'decimal'. When decimal is imported the function is called with the module
object as argument.

While this particular example isn't necessary in practice, (as
decimal.Decimal will inherit from the appropriate abstract Number base
class in 2.6 and 3.0), it still illustrates the principle.


Existing implementations


There are two major implementations for lazy imports in the Python world.

PJE's peak.util.imports [3] supports lazy modules an post load hooks. My
implementation shares a lot with his and it's partly based on his ideas.

Zope 3's zope.deferredimport doesn't have post import hooks but it has
additional methods for deprecation warnings.


Post import hook implementation
===

Post import hooks are called after a module has been loaded. The hooks
are callable which take one argument, the module instance. They are 
registered by the dotted name of the module, e.g. 'os' or 'os.path'.

The callable are stored in the dict ``sys.post_import_hooks`` which
is a mapping from names (as string) to a list of callables or None.


States
--

No hook was registered
''

sys.post_import_hooks contains no entry for the module

A hook is registered and the module is not loaded yet
'

The import hook registry contains an entry 
sys.post_import_hooks[name] = [hook1]

A module is successfully loaded
'''

The import machinery checks if sys.post_import_hooks contains post import
hooks for the newly loaded module. If hooks are found then the hooks are
called in the order they were registered with the module instance as first
argument. The processing of the hooks is stopped when a method raises an
exception. At the end the entry for the module name is removed from
sys.post_import_hooks, even when an error has occured.

A module can't be loaded


The import hooks are neither called nor removed from the registry. It may be
possible to load the module later.

A hook is registered but the module is already loaded
'

The hook is fired immediately. 


C API
-

New PyImport_* API functions


PyObject* PyImport_GetPostImportHooks(void)
Returns the dict sys.post_import_hooks or NULL

PyObject* PyImport_NotifyModuleLoaded(PyObject *module)
   Notify the post import system that a module was requested. Returns the
   module or NULL if an error has occured.

PyObject* PyImport_RegisterPostImportHook(PyObject *callable, PyObject 
*mod_name)
   Register a new hook ``callable`` for the module ``mod_name``

The PyImport_PostImportNotify() 

Re: [Python-Dev] PEP: Lazy module imports and post import hook

2008-01-08 Thread Neal Becker
Christian Heimes wrote:

 I've attached the first public draft of my first PEP. A working patch
 against the py3k branch is available at http://bugs.python.org/issue1576
 
 Christian

Note also that mercurial has demandimport
http://www.selenic.com/mercurial/wiki/

___
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] PEP: Lazy module imports and post import hook

2008-01-08 Thread Andrew Bennetts
Neal Becker wrote:
 Christian Heimes wrote:
 
  I've attached the first public draft of my first PEP. A working patch
  against the py3k branch is available at http://bugs.python.org/issue1576
  
  Christian
 
 Note also that mercurial has demandimport
 http://www.selenic.com/mercurial/wiki/

And that bzr has lazy_import (inspired by mercurial's demandimport):
http://codebrowse.launchpad.net/~bzr/bzr/trunk/annotate/3170?file_id=lazy_import.py-20060910203832-f77c54gf3n232za0-1
http://bazaar-vcs.org/

-Andrew.

___
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] Extracting variables from string.Template objects

2008-01-08 Thread Aahz
On Fri, Jan 04, 2008, Isaac Morland wrote:
 On Fri, 4 Jan 2008, Aahz wrote:
 
Also, on a related issue, does it make sense to scan the template
string for invalid escape sequences in Template.__init__?  For the
applications I can imagine of string.Template, I would prefer to get
an error upon creating the Template object rather than arbitrarily
later when I try to .substitute with it.

No, create an is_valid() method at best.
 
 I'm curious as to why.  Is it to avoid changing the behaviour of existing 
 code (i.e., backwards compatibility), or do you see a design problem with 
 having the Template constructor reject invalid template strings?

Mostly the former, though I'm not sure about the performance
implications of scanning on instance creation.
-- 
Aahz ([EMAIL PROTECTED])   * http://www.pythoncraft.com/

Weinberg's Second Law: If builders built buildings the way programmers wrote 
programs, then the first woodpecker that came along would destroy civilization.
___
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] PEP: Lazy module imports and post import hook

2008-01-08 Thread Fred Drake
On Jan 8, 2008, at 7:53 PM, Neal Becker wrote:
 Note also that mercurial has demandimport
 http://www.selenic.com/mercurial/wiki/


Let's not forget zope.deferredimport:

   http://pypi.python.org/pypi/zope.deferredimport


   -Fred

-- 
Fred Drake   fdrake at acm.org




___
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] PEP: Lazy module imports and post import hook

2008-01-08 Thread glyph
On 01:09 am, [EMAIL PROTECTED] wrote:
Neal Becker wrote:
Christian Heimes wrote:

  I've attached the first public draft of my first PEP. A working 
patch
  against the py3k branch is available at 
http://bugs.python.org/issue1576
 
  Christian

Note also that mercurial has demandimport
http://www.selenic.com/mercurial/wiki/

And that bzr has lazy_import (inspired by mercurial's demandimport):

and very recently, I implemented similar functionality myself (though it 
isn't in use in Twisted yet):

http://codebrowse.launchpad.net/~glyph/+junk/pyexport/files

Something that I notice about every other implementation of this 
functionality is that they're all in Python.  But the proposed 
implementation here is written in C, and therefore more prone to 
crashing bugs.  Looking at the roundup log, I can see that several 
refcounting bugs have already been found and fixed.  Perhaps the post- 
import hooks, being a modification to the import mechanism itself, needs 
to be in C, but given that lazy imports *have* been implemented before 
without using C code (and without post import hooks), I can't see why 
they need to be in the same PEP.

Also, as is my custom, I'd like to suggest that, rather than designing 
something new, one of the third-party implementations be adopted (or at 
least its interface) since these have been demonstrated to work in real 
application code already.  Happily, I can escape the charge of bias this 
time since I don't think my own implementation should be taken seriously 
in this case :).
___
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] PEP: Lazy module imports and post import hook

2008-01-08 Thread Christian Heimes
Fred Drake wrote:
 On Jan 8, 2008, at 7:53 PM, Neal Becker wrote:
 Note also that mercurial has demandimport
 http://www.selenic.com/mercurial/wiki/
 
 
 Let's not forget zope.deferredimport:
 
http://pypi.python.org/pypi/zope.deferredimport

I've mentioned zope.deferredimport in my PEP. :)

Christian
___
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] PEP: Lazy module imports and post import hook

2008-01-08 Thread Fred Drake
I foolishly wrote:
 Let's not forget zope.deferredimport:

   http://pypi.python.org/pypi/zope.deferredimport

On Jan 8, 2008, at 11:03 PM, Christian Heimes wrote:
 I've mentioned zope.deferredimport in my PEP. :)

Indeed; that's what I get for scanning the text too quickly.  Sorry!

The URL I posted may be somewhat better for most users, though.


   -Fred

-- 
Fred Drake   fdrake at acm.org




___
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] PEP: Lazy module imports and post import hook

2008-01-08 Thread Christian Heimes
[EMAIL PROTECTED] wrote:
 and very recently, I implemented similar functionality myself (though it 
 isn't in use in Twisted yet):
 
 http://codebrowse.launchpad.net/~glyph/+junk/pyexport/files

I'm going to study your implementation tomorrow.

 Something that I notice about every other implementation of this 
 functionality is that they're all in Python.  But the proposed 
 implementation here is written in C, and therefore more prone to 
 crashing bugs.  Looking at the roundup log, I can see that several 
 refcounting bugs have already been found and fixed.  Perhaps the post- 
 import hooks, being a modification to the import mechanism itself, needs 
 to be in C, but given that lazy imports *have* been implemented before 
 without using C code (and without post import hooks), I can't see why 
 they need to be in the same PEP.

Correct, the first few patches were rough implementation sketches. I
wanted to discuss implementation details with PJE and it was the easiest
way to exchange code. A distributed VCS would have made the task easier
but that's a different story. Eventually I focused on the reference
counter and I straightened out some ref count bugs.

Deferred loading of modules can be implemented without post import hooks
and vice versa. But PJE urged me to - at least - consider lazy modules /
deferred importing in the post import hook implementation. 3rd party
tools need a way to interact with the hooks and notify the system when
their own lazy module implementation loads a real module.

I figured out I could write a PEP for both features in one PEP and
implement them in a combined patch. I could separate them and create two
PEPs.

 Also, as is my custom, I'd like to suggest that, rather than designing 
 something new, one of the third-party implementations be adopted (or at 
 least its interface) since these have been demonstrated to work in real 
 application code already.  Happily, I can escape the charge of bias this 
 time since I don't think my own implementation should be taken seriously 
 in this case :).

:)

I *did* mention that my implementation of lazy imports is based on PJE's
peak.util.import:


PJE's peak.util.imports [3] supports lazy modules an post load hooks. My
implementation shares a lot with his and it's partly based on his ideas.


Finally I like to say something about my choice to implement the lazy
loading in C. Most implementation like zope.deferredimport, Hg's
demandimport and bzr's lazy_import are using the proxy design pattern.
They are storing a wrapper object in the module and sys.modules instead
of the real module and they are loading the real module when an
attribute is accessed. Some of some (brz) are even using some strange
scope replacing. I've to study the implementation more carefully to
understand what's going on.

peak.util.imports' way is slightly different. It return the instance of
a module subclass. When the real module is loaded it redirect name
lookup of the lazy module to the real module by replacing the
__getattribute__ and __setattr__ methods of the lazy module with the
methods of the real module.

My implementation uses a similar approach. But I've the luxury that I
can modify the C implementation of the module class. It makes the
load-real-module-when-attribute-is-accessed dance much easier. I don't
have to write a proxy or deal with name spaces.

However the PEP covers only the basic infrastructure for lazy imports.
For example imp.lazy_import(a.b.c) doesn't put a and a.b in
sys.modules. It neither doesn't cover the replacement __import__ hook
provided by Hg nor the deprecation feature of zope.deferredimport. Such
infrastructure functions can be implemented in Python.

Please remember, the PEP is a draft. I'm waiting for comments and
suggestions from users and developers.

Christian

___
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


[Python-Dev] Import by filename with __import__ ?

2008-01-08 Thread Christian Heimes
Today I stumbled about an unknown and undocumented (?) feature. At least
it's not documented in our docs. __import__ can import a module by file
name:

 open(/tmp/example.py, w).write(test = 23\n)
 mod = __import__(/tmp/example)
 mod
module '/tmp/example' from '/tmp/example.py'
 mod.__name__
'/tmp/example'
 mod.__file__
'/tmp/example.py'
 mod.test
23

Is it just a coincidence? Is it a desired feature? Why isn't it documented?

Christian

___
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] PEP: Lazy module imports and post import hook

2008-01-08 Thread Phillip J. Eby
At 06:01 AM 1/9/2008 +0100, Christian Heimes wrote:
However the PEP covers only the basic infrastructure for lazy imports.
For example imp.lazy_import(a.b.c) doesn't put a and a.b in
sys.modules.

That's probably a mistake.  In the early days of peak.util.imports 
(which is now available as the Importing package on PyPI), I went 
through a lot of hairy edge conditions regarding such matters as when 
parent packages must be present, and ensuring the correct runtime 
ordering of post-import callbacks.

Although I glanced at some of your earlier patch versions and had 
comments, you should be aware that I have *not* validated it for 
these sorts of trickier timing considerations, mostly because I'm not 
100% sure what they are any more, only that I made sure 
peak.util.imports could handle them.

___
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] Import by filename with __import__ ?

2008-01-08 Thread Guido van Rossum
Sounds like a coincidence. Looks like it's using os.path.join(X, name
+ .py) where X is a member of sys.path, e.g. the initial .. This
gives good results for valid module names (which never contain
slashes) but in this example, os.path.join() ignores the first
component if the second starts with '/'.

Feel free to add a check that the module name doesn't contain '/',
'\\' or '.'. (I think that silently accepting other non-identifier
characters is fine, since it doesn't interfere with parsing either the
module name or the filename.)

On Jan 8, 2008 9:09 PM, Christian Heimes [EMAIL PROTECTED] wrote:
 Today I stumbled about an unknown and undocumented (?) feature. At least
 it's not documented in our docs. __import__ can import a module by file
 name:

  open(/tmp/example.py, w).write(test = 23\n)
  mod = __import__(/tmp/example)
  mod
 module '/tmp/example' from '/tmp/example.py'
  mod.__name__
 '/tmp/example'
  mod.__file__
 '/tmp/example.py'
  mod.test
 23

 Is it just a coincidence? Is it a desired feature? Why isn't it documented?

 Christian

 ___
 Python-Dev mailing list
 Python-Dev@python.org
 http://mail.python.org/mailman/listinfo/python-dev
 Unsubscribe: 
 http://mail.python.org/mailman/options/python-dev/guido%40python.org




-- 
--Guido van Rossum (home page: http://www.python.org/~guido/)
___
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] pkgutil, pkg_resource and Python 3.0 name space packages

2008-01-08 Thread Jeroen Ruigrok van der Werven
-On [20080108 17:07], Christian Heimes ([EMAIL PROTECTED]) wrote:
Python's _winreg module and pywin32 expose several functions to get the
paths from the registry but I don't think it has a simple function like
get_mydocuments().

Careful with the name though. Microsoft Windows Vista did away with 'My
Documents  Settings'. It is now C:\Users.

So you get:

C:\Users\name\AppData\Local\(former Local Settings\Application Data)
C:\Users\name\AppData\Roaming\  (former Application Data)
C:\Users\name\Documents (former My Documents)
C:\Users\name\Music (former My Music)
C:\Users\name\Pictures  (former My Pictures)
C:\Users\name\Videos(former My Videos)

-- 
Jeroen Ruigrok van der Werven asmodai(-at-)in-nomine.org / asmodai
イェルーン ラウフロック ヴァン デル ウェルヴェン
http://www.in-nomine.org/ | http://www.rangaku.org/
Vae victis!
___
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com