Difference between 'import' and 'from ... import'

Patrick K. O'Brien pobrien at orbtech.com
Mon Dec 3 14:48:01 EST 2001


I got the following:

C:\Code\Gadfly> python
Python 2.1.1 (#20, Jul 20 2001, 01:19:29) [MSC 32 bit (Intel)] on win32
Type "copyright", "credits" or "license" for more information.
>>> import gadfly
kjParser.py:16: DeprecationWarning: the regex module is deprecated; please
use t
he re module
  import regex
C:\PYTHON21\lib\regsub.py:15: DeprecationWarning: the regsub module is
deprecate
d; please use re.sub()
  DeprecationWarning)
>>> gadfly
<module 'gadfly' from 'gadfly.pyc'>
>>> dir(gadfly)
['GF_Cursor', '__builtins__', '__doc__', '__file__', '__name__', 'error',
'gadfl
y', 'sql', 'sqlbind', 'sqlgen', 'verbosity']
>>>

In other words, it worked. All I did was download, unzip, "python
gfinstall.py", and then what you see above. What didn't work for me was what
you said worked for you:

C:\Code>python
Python 2.1.1 (#20, Jul 20 2001, 01:19:29) [MSC 32 bit (Intel)] on win32
Type "copyright", "credits" or "license" for more information.
>>> from Gadfly import gadfly
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
ImportError: No module named Gadfly
>>>

Indeed, on my machine the Gadfly directory does not have an __init__.py
file, so Gadfly is *not* a package. Does this help at all?

--
Patrick K. O'Brien
Orbtech.com - Your Source For Python Development Services


"Andy Todd" <andy47 at halfcooked.com> wrote in message
news:Xns916C95F7E80D6andytoddspamfreeyaho at 203.109.250.24...
> I'm having a problem with imports and would appreciate any hints, tips or
> pointers to documentation or faqs.
>
> I've got a package installed in a directory on my PYTHONPATH and I cannot
> seem to import a module from that package directly. The directory is
> c:\python21\Gadfly and the module is gadfly.py. If I try;
>
> >>> from Gadfly import gadfly
>
> everything works and I can specify a connection and access my database.
> But, if I try;
>
> >>> import gadfly
>
> I get an error message;
>
> Traceback (most recent call last):
>
>   File "<interactive input>", line 1, in ?
>
> SystemError: NULL result without error in call_object
>
> I've tried googling for this error message but it seems to be a generic
> error which is masking my real problem.
>
> This has got me a little stumped because the other modules in this package
> will import (e.g. sqlgen, sqlwhere) so I presume there is something in
> gadfly.py that the interpreter doesn't like.
>
> The gadfly documentation only talks about 'from gadfly import gadfly' and
> I'm just wondering if there is something specific in the module which
> prohibits a direct import.
>
> I'm running Python 2.1.1 on Windows98 with the latest version of gadfly
> from http://www.chordate.com/gadfly.html
>
> Thanks in advance,
> Andy
> --
> Content free posts a speciality
>





More information about the Python-list mailing list