I'm pretty comfortable with Python, but recently I'm constantly
finding mysterious issues with import. For example, looking at http://genshi.edgewall.org/browser/t...s/transform.py
the examples use the symbol 'HTML' but it's not defined locally, it's
not explicitly imported, and there's no import *. Yet doctest will
test this module and it passes with flying colors. It turns out HTML
is defined in genshi.input. How do I know that? I grepped for it.
How does it become available to this module?
Another example: I was recently working on some code that did an
import from inside a class method. That import was failing. I moved
the import to the top of the file (at module scope) and it succeeded.
I'm fairly sure that nobody was monkeying around with sys.path in that
case. Can anyone think of a likely explanation?
TIA,
--
Dave Abrahams
Boost Consulting http://www.boost-consulting.com
The Astoria Seminar == http://www.astoriaseminar.com
Jun 21 '07
11 1333
on Wed Jul 04 2007, Peter Otten <__peter__-AT-web.dewrote:
>>Explicitly passed, see
http://genshi.edgewall.org/browser/t...s/transform.py
>> IIRC I ran doctest on the file I cited, not the one you're pointing at. Is there some new magic doctest feature I should know about?
Had you looked at it
Gimme a little credit, please! Of course I looked at it.
you'd seen that the file I pointed to is the driver
script for running the doctests in the file you pointed to
Yes, I saw that, but I don't know of any magic feature that causes the
driver script to get loaded when I invoke doctest directly on the file
I pointed to.
-- unfortunately they have the same name. [...]/tests/transform.py
does indeed inject a HTML object into the globals of
[...]/filters/transform.py before it runs the tests.
Yes, I saw that, but as I said...
Anyway, maybe I just got confused and doctest-ed the driver script.
That certainly would explain everything.
>>>Another example: I was recently working on some code that did an import from inside a class method. That import was failing. I moved the import to the top of the file (at module scope) and it succeeded. I'm fairly sure that nobody was monkeying around with sys.path in that case. Can anyone think of a likely explanation?
Too vague, sorry.
# this will succeed if I do it here # import foo.bar
class X: def y(): import foo.bar # but this fails
Are threads involved? I vaguely remember a problem with Queue.Queue that
came up on this list some time ago.
I don't know, honestly. This was probably in Trac somewhere. I don't
know if it's threaded.
--
Dave Abrahams
Boost Consulting http://www.boost-consulting.com
The Astoria Seminar == http://www.astoriaseminar.com
David Abrahams wrote:
>
on Wed Jul 04 2007, Peter Otten <__peter__-AT-web.dewrote:
>>>Explicitly passed, see
http://genshi.edgewall.org/browser/t...s/transform.py
>>> IIRC I ran doctest on the file I cited, not the one you're pointing at. Is there some new magic doctest feature I should know about?
Had you looked at it
Gimme a little credit, please! Of course I looked at it.
Sorry.
>you'd seen that the file I pointed to is the driver script for running the doctests in the file you pointed to
Yes, I saw that, but I don't know of any magic feature that causes the
driver script to get loaded when I invoke doctest directly on the file
I pointed to.
Nor do I.
>-- unfortunately they have the same name. [...]/tests/transform.py does indeed inject a HTML object into the globals of [...]/filters/transform.py before it runs the tests.
Yes, I saw that, but as I said...
Anyway, maybe I just got confused and doctest-ed the driver script.
That certainly would explain everything.
Compelling assumption because it does away with the mystery...
Peter This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Stian Søiland |
last post by:
all examples performed with:
Python 2.3+ (#2, Aug 10 2003, 11:09:33)
on linux2
(2, 3, 0, 'final', 1)
This is a recursive import:
|
by: Vio |
last post by:
Hi,
I've been trying to embed (statically) wxPy alongside an embedded py
interpreter on a linux/gtk box.
At one point, for some reason misc.o linking reported "multiple
definitions of wxGetFreeMemory()". Since wxGetFreeMemory() seemed
effectively unused in gtk, I just commented it out in misc_wrap.cpp
(didn't want to patch SWIG to regenerate the wrapper code, so hacked the
generated cpp source), and replaced...
|
by: Steve Holden |
last post by:
This is even stranger: it makes it if I import the module a second time:
import dbimp as dbimp
import sys
if __name__ == "__main__":
dbimp.install()
#k = sys.modules.keys()
#k.sort()
#for kk in k:
|
by: David Poundall |
last post by:
importedfiles = {}
for f in FileList
f2 = f.split('.') # strip the .py, .pyc
__import__(f2)
s2 = f2+'.main()' # main is the top file in each import
c = compile(s2, '', 'eval')
importedfiles = eval(c)
'importedfiles' should hold an object reference to the main() function
within each imported file.
|
by: Prem Mallappa |
last post by:
hi everybody,
i was searching for the book Obfuscated C and other mysteries by Don Libes
does any one has a softcopy or any pointers
thanks in advance
prem
PS: amazon doen't have shipping option to India. and the book is not in
print, other online bookshops its double its original price..
| |
by: dbuchanan |
last post by:
Help me understand the behavior of this code.
If I run code 1 (below) the datagrid stays populated.
=== incidental code ===
Private dataSet1 As CLIP.dsTables
private Sub FillDataSet()
Dim DAL As New CLIP.DataAccess
|
by: Jon |
last post by:
It appears that (windows) python searches in the current working
directory before looking in the local site-packages directory, or that
'.' comes first in sys.path? The problem arises when I made the mistake
of running a test program from the same directory where I built and
installed my package. Python uses the package from the current
directory, which misses the pyd files, instead of the site-packages
package which has them installed.
...
|
by: rsoh.woodhouse |
last post by:
Hi,
I'm trying to work out some strange (to me) behaviour that I see when
running a python script in two different ways (I've inherited some
code that needs to be maintained and integrated with another lump of
code). The sample script is:
# Sample script, simply create a new thread and run a
# regular expression match in it.
import re
|
by: . |
last post by:
9/11 Mysteries
http://video.google.com/videoplay?docid=-8172271955308136871
http://www.911weknow.com
Ignore those who would go to great effort and expend much of heir time
in poo-pooing this post. See for yourself what really happened in the
3 demolished buildings in the weeks before 9/11. Since 9-11 the
American public has shown a "remarkable indifference to being
deceived" (George Soros). But this is changing. As Hugo Chavez put it:
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |