[Python-bugs-list] [ python-Bugs-735293 ] Command line timeit.py sets sys.path badly
SourceForge.net
noreply@sourceforge.net
Mon, 19 May 2003 16:52:53 -0700
Bugs item #735293, was opened at 2003-05-09 10:36
Message generated for change (Comment added) made by rhettinger
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=735293&group_id=5470
Category: Python Library
Group: Python 2.3
Status: Open
Resolution: Accepted
Priority: 5
Submitted By: Paul Moore (pmoore)
>Assigned to: Raymond Hettinger (rhettinger)
Summary: Command line timeit.py sets sys.path badly
Initial Comment:
Running timeit.py from the command line results in the
directory containing timeit.py (ie, the standard Python
library) being added to sys.path, and the current
directory *not* being.
To test, create a file mymod.py in the current directory,
containing
def test():
"Stupid test function"
L = []
for i in range(100):
L.append(i)
Now, execute
\Apps\Python\Lib\timeit.py -s "import
mymod" "mymod.test()"
Result is
Traceback (most recent call last):
File "\Apps\Python\Lib\timeit.py", line 245, in main
x = t.timeit(number)
File "\Apps\Python\Lib\timeit.py", line 159, in timeit
return self.inner(it, self.timer)
File "<timeit-src>", line 3, in inner
import mymod
ImportError: No module named mymod
It's possible to work around this, either by setting
PYTHONPATH in the environment to ".", or by
adding "import sys; sys.path.insert(0, '.')" to the code in
the -s option. But neither is a particularly attractive
solution.
----------------------------------------------------------------------
>Comment By: Raymond Hettinger (rhettinger)
Date: 2003-05-19 18:52
Message:
Logged In: YES
user_id=80475
I've got it from here.
----------------------------------------------------------------------
Comment By: Guido van Rossum (gvanrossum)
Date: 2003-05-19 16:01
Message:
Logged In: YES
user_id=6380
I won't be offended if someone else checks this in and
closes this issue. :)
----------------------------------------------------------------------
Comment By: Paul Moore (pmoore)
Date: 2003-05-19 11:00
Message:
Logged In: YES
user_id=113328
This patch does what I'd expect.
----------------------------------------------------------------------
Comment By: Guido van Rossum (gvanrossum)
Date: 2003-05-16 14:03
Message:
Logged In: YES
user_id=6380
Good point. Can you provide a patch?
----------------------------------------------------------------------
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=735293&group_id=5470