[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] Directory Problem?



Luke Paireepinart wrote:


C:\Code \06 Fall \Other \Seagame C \Conch (conch.py is in here) My program, the one I'm running \Shining Sea \Conch (another copy is in here)

So apparently, even though I'm running a program in "Seagame C", which says "import Conch", Python is loading a completely different copy of Conch from another directory! What gives?

Put the conch.py you want to use in the same directory as your program if you want to be able to just import it.
Otherwise, you'll have to tell python where it is.
Apparently Python knows about the other conch somehow, but it doesn't recursively search subdirectories for modules (afaik)

In Seagame C\Conch, I have a file "__init__.py" consisting of: "from conch import *", with "conch.py" being in that directory.


Normally, calling "import Conch" will load the Conch from the same subdirectory as the program calling that. In fact, opening up my main.py program in Seagame C and then trying to load a deliberately glitched version of Conch does what I want it to:

import Conch
Traceback (most recent call last):
  File "<pyshell#0>", line 1, in ?
    import Conch
  File "C:\Code\06 Fall\Shining Sea\Conch\__init__.py", line 1, in ?
    from conch import *
  File "C:\Code\06 Fall\Other\Seagame C\Conch\conch.py", line 18, in ?
    print "42"+42
TypeError: cannot concatenate 'str' and 'int' objects

So in this case, it's loading from Seagame C\Conch, as intended. But not... Wait...


Just now I tried it again, and now:
Traceback (most recent call last):
  File "C:\Code\06 Fall\Other\Seagame C\main.py", line 360, in ?
    Conch.j.LoadSound("18403_inferno_xplosm.wav","cannon")
  File "C:\Code\06 Fall\Other\Seagame C\Conch\conch.py", line 150, in LoadSound
    new_sound = pygame.mixer.Sound( os.path.join(SOUND_DIRECTORY,filename) )
error: Unknown WAVE data format: 0x4x

So now it's loading the correct copy! Weird.

Kris