Class instantiation fails when passed in a file but work via line by line interpreter

John Krukoff jkrukoff at ltgc.com
Tue Nov 18 20:02:35 CET 2008


On Tue, 2008-11-18 at 10:45 -0800, Jeff Tchang wrote:
> Odd issue I am having with class instantiation on Python 2.5.2 (Windows).
> 
> I have a custom module with a few classes in it. The module is named SAML.py.
> There is a copy of it in C:\Python25\Lib\site-packages\SAML.py.
> 
> Basically when I try to run a python file that tries to create an
> instance of the class Subject I get this error:
> AttributeError: type object 'SAML' has no attribute 'Subject'
> 
> In SAML.py I have the class...
> 
> class Subject(object):
>   ...
>   ...
>   etc
> 
> However, when I run the same line by line by starting up python it works.
> 
> >> import SAML
> >> subject = SAML.Subject("JohnDoe at example.com","EMailAddress")
> >>> print subject
> <SAML.Subject object at 0x00C94770>
> >>>
> I've double checked I am loading the correct module by the usage of the -v flag.
> What else should I be checking?
> 
> -Jeff
> --
> http://mail.python.org/mailman/listinfo/python-list

Random related question. If you're writing a SAML implementation have
you found an XML Signature implementation that works reliably from
python? I've had a hell of a time finding something that doesn't
segfault and is interoperable with .NET.

As far as your problem goes, I would guess that somewhere you've got a
class named SAML that's shadowing your module. See the difference in the
error messages:

Python 2.5.2 (r252, Oct 31 2008, 10:47:40) 
[GCC 4.1.2 (Gentoo 4.1.2 p1.1)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import os
>>> type( os )
<type 'module'>
>>> os.doesnotexist
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'doesnotexist'
>>> class os( object ):
...  pass
... 
>>> os.doesnotexist
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: type object 'os' has no attribute 'doesnotexist'

-- 
John Krukoff <jkrukoff at ltgc.com>
Land Title Guarantee Company




More information about the Python-list mailing list