Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > python newb has problem with import statements

Reply
Thread Tools

python newb has problem with import statements

 
 
danielmcbrearty@gmail.com
Guest
Posts: n/a
 
      03-19-2006
Hi

Old hand at perl, giving python a try. Trying to get pymedia running on
my winxp box.

Have installed activestate python 2.4 and pymedia using precompiled
installers.

Problem is it SEEMS that the __init__.py is not getting run when I
import a module.

So, I have pymedia installed and it imports fine:

>>> import pymedia
>>> dir(pymedia)

['__builtins__', '__doc__', '__file__', '__name__']
>>>


the init file looks like this:

(docs and comments skipped)

print "in pymedia" # added by me to see
__all__= [ 'muxer', 'audio', 'video', 'removable' ]
import muxer, audio, video, removable

but I can't import submodules of pymedia:

>>> import pymedia.sound

Traceback (most recent call last):
File "<interactive input>", line 1, in ?
ImportError: No module named sound
>>>


if I do this

>>> from pymedia import *
>>> import pymedia.sound

Traceback (most recent call last):
File "<interactive input>", line 1, in ?
ImportError: No module named sound
>>>


the weird thing is teh IDE (pythonwin) knows about the sub modules - it
shows them in the auto-suggest thingy when I type "pymedia."

so what's going on? do I have an install problem? (I did try removing
and reinstalling, no avail) am I just misunderstanding how this should
work?

all helpful stuff much appreciated

Daniel

 
Reply With Quote
 
 
 
 
Peter Otten
Guest
Posts: n/a
 
      03-19-2006
http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:

> the init file looks like this:
>
> (docs and comments skipped)
>
> print "in pymedia" # added by me to see
> __all__= [ 'muxer', 'audio', 'video', 'removable' ]
> import muxer, audio, video, removable
>
> but I can't import submodules of pymedia:


The file with the contents given above is clearly not the one that is
imported here,

> >>> import pymedia
> >>> dir(pymedia)

> ['__builtins__', '__doc__', '__file__', '__name__']


as __all__, muxer, audio etc. are missing.

Maybe you have created a test script 'pymedia.py' in the working directory?
You can check what file you are dealing with by entering

>>> pymedia.__file__


If that is 'whatever/site-packages/pymedia/__init__.pyc' I'm guessing wrong.
Otherwise removing that file (probably 'pymedia.pyc') and the corresponding
source (pymedia.py) should fix your problem.

Peter
 
Reply With Quote
 
 
 
 
danielmcbrearty@gmail.com
Guest
Posts: n/a
 
      03-19-2006
that was indeed the problem. Thanks!

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Prepare Statements VS Statements Vince Java 12 01-21-2008 01:18 PM
component statements within architecture statements Neil Zanella VHDL 8 10-20-2006 09:05 AM
{newb} Each statements STEPHEN BECKER I V Ruby 14 09-28-2004 11:36 AM
if statements with or w/o else statements Harry George Python 6 02-23-2004 06:48 PM
Newb, using Python in win32 app, how to import c++ modules created with swig from an .exe Jon Moldover Python 0 10-28-2003 11:34 PM



Advertisments