954,546 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Bug in my program

Hey guys, recently I started playing around with pygame. Right now im making a little orb move when you hit a key. But its stuck with the image loading!

background_image_filename = 'C:\\orb\\backroundorb.jpeg'
sprite_image_filename = 'C:\\orb\\orbsprite.jpeg'

import pygame
from pygame.locals import *
from sys import exit

pygame.init()



screen = pygame.display.set_mode((640, 480), 0, 32)

background = pygame.image.load(background_image_filename)
sprite = pygame.image.load(sprite_image_filename)


does anyone see the problem with this part of the code? It comes up with the error message

Traceback (most recent call last):
File "C:\Python25\orb", line 14, in
background = pygame.image.load(background_image_filename)
error: Couldn't open C:\orb\backroundorb.jpeg

There is a folder called orb and there are images called
backroundorb.jpeg and orbsprite.jpeg.

Can anyone help me with this?

rysin
Light Poster
41 posts since Jan 2008
Reputation Points: 10
Solved Threads: 0
 

Is your file named backroundorb.jpeg or backgroundorb.jpeg

vegaseat
DaniWeb's Hypocrite
Moderator
5,989 posts since Oct 2004
Reputation Points: 1,345
Solved Threads: 1,417
 

In my file name i mispelled background and spelled it backround. I was to lazy to fix it so its still backroundorb.jpeg

rysin
Light Poster
41 posts since Jan 2008
Reputation Points: 10
Solved Threads: 0
 

Hi rysin,

Can you open the file at all from within python? If you say

f = open("C:\\orb\\backroundorb.jpeg", "r")


does that work?

G-Do
Junior Poster
147 posts since Jun 2005
Reputation Points: 41
Solved Threads: 31
 

No it doesnt haha! What do you think is wrong with it? IM on a compaq computer... do I put that in the path name?

rysin
Light Poster
41 posts since Jan 2008
Reputation Points: 10
Solved Threads: 0
 

Hi rysin,

Maybe try importing os and run os.listdir() on the given directory. Do the following and please tell me what you get:

import os
os.listdir("C:\\orb")


Or maybe it could be some kind of weirdness in processing the backslashes? I'm not at a Windows PC, so I can't tell.

G-Do
Junior Poster
147 posts since Jun 2005
Reputation Points: 41
Solved Threads: 31
 

THis is what I got

>>>
>>>
It just skipped to a new line

rysin
Light Poster
41 posts since Jan 2008
Reputation Points: 10
Solved Threads: 0
 

YES! After many many hours(3 to be exact!) of debugging I found the problem. It was actually later in the program! Thanks to all who helped!

rysin
Light Poster
41 posts since Jan 2008
Reputation Points: 10
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You