[twill] twill hacking the sys.path

Titus Brown titus at caltech.edu
Wed May 17 11:46:16 PDT 2006


-> I had Python errors trying to run a Python script using twill API. I
-> eventually found out that twill inserts its modules at the top of
-> sys.path, so that "import utils" did not import my module but twill's.
-> 
-> The best suggestion would be of course to drop this hack, but in the
-> meantime, I suggest you do not insert your modules at index 0 but 1, in
-> order to leave the current path at the top.

Hi, Herve,

I freely acknowledge it to be a hack ;).  There's no reason for
'thisdir' to be added, and the use of such common names as 'errors' and
'utils' renders it even dumber -- thanks for pointing this out.
I've removed that & I don't think the removal will cause any problems.

The 'extensions' and 'other_packages' path mangling is there for a
reason, and I don't know of a better way to deal with it.  'extensions'
*could* be omitted from the path if I modified 'extend_with' to take
a default import path, for example, but I'm not sure what would happen
if I did that & I'm loathe to find out for this next release!
'other_packages' needs to be ahead of system-installed versions of
mechanize and pyparsing; until setuptools is on all systems, I don't
know how to do this in a better way.

Incidentally, a better way of dealing with this in your code might be to
adjust the import order -- twill's path mangling occurs on the first
'import twill', and if you're using the twill API then you should have
control over when that first happens.

Apologies for the problems, and thanks for pointing this out!

cheers,
--titus

p.s. Fix in the latest dev code:

	http://darcs.idyll.org/~t/projects/twill-latest.tar.gz



More information about the twill mailing list