Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Jul 12th, 2005, 10:21 AM   #1
Flinch
Newbie
 
Join Date: Jul 2005
Posts: 1
Rep Power: 0 Flinch is on a distinguished road
Python and Pygame

Well, I am a newb when it comes to Python, but not programming in general. I am an experienced PHP programmer, but that's off-topic. Anyway, I downloaded Python v2.3 and Pygame v1.6 for Python 2.3 and installed both; Python to Program Files\Python23 and Pygame to Program Files\Python23\Lib\site-packages. Now, to my bleak understanding, to use a module in Python, you use Import. So, I do this:

import pygame

Now, when I try to do anythin with that module I get errors:

>>>pygame.init()
Traceback (most recent call last):
  File "<pyshell#6>", line 1, in -toplevel-
    pygame.init()
AttributeError: 'module' object has no attribute 'init'

I have read all of the intro articles at pygame.org on how to install and get it working, and they all say to just use import. I know it's importing pygame because when I print pygame it tells me the directory of the installed module.

>>>print pygame
<module 'pygame' from 'C:\Program Files\Python23\lib\pygame.pyc'>

I would really appreciate any help at all.
Flinch is offline   Reply With Quote
Old Jul 12th, 2005, 4:06 PM   #2
Sane
Programming Guru
 
Sane's Avatar
 
Join Date: Apr 2005
Location: Waterloo, Ontario
Posts: 1,886
Rep Power: 5 Sane will become famous soon enough
Send a message via MSN to Sane
That's odd...

HMMMmmm...

o_o;;

Pygame doesn't even work on my computer, but still even that worked for me...

x_x

Errr.... durr....

Try

import pygame
help(pygame)

See if it shows you the init function.

And then run:

import pygame
dir(pygame)

It should show as:
['ACTIVEEVENT', 'ANYFORMAT', 'ASYNCBLIT', 'AUDIO_S16', 'AUDIO_S16LSB', 'AUDIO_S16MSB', 'AUDIO_S16SYS', 'AUDIO_S8', 'AUDIO_U16', 'AUDIO_U16LSB', 'AUDIO_U16MSB', 'AUDIO_U16SYS', 'AUDIO_U8', 'Color', 'DOUBLEBUF', 'FULLSCREEN', 'GL_ACCUM_ALPHA_SIZE', 'GL_ACCUM_BLUE_SIZE', 'GL_ACCUM_GREEN_SIZE', 'GL_ACCUM_RED_SIZE', 'GL_ALPHA_SIZE', 'GL_BLUE_SIZE', 'GL_BUFFER_SIZE', 'GL_DEPTH_SIZE', 'GL_DOUBLEBUFFER', 'GL_GREEN_SIZE', 'GL_MULTISAMPLEBUFFERS', 'GL_MULTISAMPLESAMPLES', 'GL_RED_SIZE', 'GL_STENCIL_SIZE', 'GL_STEREO', 'HAT_CENTERED', 'HAT_DOWN', 'HAT_LEFT', 'HAT_LEFTDOWN', 'HAT_LEFTUP', 'HAT_RIGHT', 'HAT_RIGHTDOWN', 'HAT_RIGHTUP', 'HAT_UP', 'HWACCEL', 'HWPALETTE', 'HWSURFACE', 'JOYAXISMOTION', 'JOYBALLMOTION', 'JOYBUTTONDOWN', 'JOYBUTTONUP', 'JOYHATMOTION', 'KEYDOWN', 'KEYUP', 'KMOD_ALT', 'KMOD_CAPS', 'KMOD_CTRL', 'KMOD_LALT', 'KMOD_LCTRL', 'KMOD_LMETA', 'KMOD_LSHIFT', 'KMOD_META', 'KMOD_MODE', 'KMOD_NONE', 'KMOD_NUM', 'KMOD_RALT', 'KMOD_RCTRL', 'KMOD_RMETA', 'KMOD_RSHIFT', 'KMOD_SHIFT', 'K_0', 'K_1', 'K_2', 'K_3', 'K_4', 'K_5', 'K_6', 'K_7', 'K_8', 'K_9', 'K_AMPERSAND', 'K_ASTERISK', 'K_AT', 'K_BACKQUOTE', 'K_BACKSLASH', 'K_BACKSPACE', 'K_BREAK', 'K_CAPSLOCK', 'K_CARET', 'K_CLEAR', 'K_COLON', 'K_COMMA', 'K_DELETE', 'K_DOLLAR', 'K_DOWN', 'K_END', 'K_EQUALS', 'K_ESCAPE', 'K_EURO', 'K_EXCLAIM', 'K_F1', 'K_F10', 'K_F11', 'K_F12', 'K_F13', 'K_F14', 'K_F15', 'K_F2', 'K_F3', 'K_F4', 'K_F5', 'K_F6', 'K_F7', 'K_F8', 'K_F9', 'K_FIRST', 'K_GREATER', 'K_HASH', 'K_HELP', 'K_HOME', 'K_INSERT', 'K_KP0', 'K_KP1', 'K_KP2', 'K_KP3', 'K_KP4', 'K_KP5', 'K_KP6', 'K_KP7', 'K_KP8', 'K_KP9', 'K_KP_DIVIDE', 'K_KP_ENTER', 'K_KP_EQUALS', 'K_KP_MINUS', 'K_KP_MULTIPLY', 'K_KP_PERIOD', 'K_KP_PLUS', 'K_LALT', 'K_LAST', 'K_LCTRL', 'K_LEFT', 'K_LEFTBRACKET', 'K_LEFTPAREN', 'K_LESS', 'K_LMETA', 'K_LSHIFT', 'K_LSUPER', 'K_MENU', 'K_MINUS', 'K_MODE', 'K_NUMLOCK', 'K_PAGEDOWN', 'K_PAGEUP', 'K_PAUSE', 'K_PERIOD', 'K_PLUS', 'K_POWER', 'K_PRINT', 'K_QUESTION', 'K_QUOTE', 'K_QUOTEDBL', 'K_RALT', 'K_RCTRL', 'K_RETURN', 'K_RIGHT', 'K_RIGHTBRACKET', 'K_RIGHTPAREN', 'K_RMETA', 'K_RSHIFT', 'K_RSUPER', 'K_SCROLLOCK', 'K_SEMICOLON', 'K_SLASH', 'K_SPACE', 'K_SYSREQ', 'K_TAB', 'K_UNDERSCORE', 'K_UNKNOWN', 'K_UP', 'K_a', 'K_b', 'K_c', 'K_d', 'K_e', 'K_f', 'K_g', 'K_h', 'K_i', 'K_j', 'K_k', 'K_l', 'K_m', 'K_n', 'K_o', 'K_p', 'K_q', 'K_r', 'K_s', 'K_t', 'K_u', 'K_v', 'K_w', 'K_x', 'K_y', 'K_z', 'MOUSEBUTTONDOWN', 'MOUSEBUTTONUP', 'MOUSEMOTION', 'NOEVENT', 'NOFRAME', 'NUMEVENTS', 'OPENGL', 'OPENGLBLIT', 'PREALLOC', 'QUIT', 'RESIZABLE', 'RLEACCEL', 'RLEACCELOK', 'Rect', 'SRCALPHA', 'SRCCOLORKEY', 'SWSURFACE', 'SYSWMEVENT', 'Surface', 'SurfaceType', 'USEREVENT', 'VIDEOEXPOSE', 'VIDEORESIZE', '__builtins__', '__doc__', '__file__', '__name__', '__path__', '__rect_constructor', '__rect_reduce', '__version__', 'base', 'cdrom', 'color', 'colordict', 'constants', 'cursors', 'display', 'draw', 'error', 'event', 'font', 'get_error', 'image', 'init', 'joystick', 'key', 'locals', 'mixer', 'mouse', 'movie', 'msg', 'quit', 'rect', 'register_quit', 'segfault', 'sndarray', 'sprite', 'string', 'surface', 'surfarray', 'sysfont', 'time', 'transform', 'ver', 'vernum', 'version']
(init near the end in bold and italics and underline)

I don't believe init is actually completely necessary though, I think it just makes it more stable for certain commands.
Sane is offline   Reply With Quote
Old Jul 12th, 2005, 4:20 PM   #3
Cerulean
Professional Programmer
 
Cerulean's Avatar
 
Join Date: Apr 2005
Location: London, England
Posts: 459
Rep Power: 4 Cerulean is on a distinguished road
Ok, run this and show me the ouput:
import pygame
print dir(pygame)

<edit>ahhh, beaten to it</edit>
Cerulean is offline   Reply With Quote
Old Jul 12th, 2005, 4:23 PM   #4
Sane
Programming Guru
 
Sane's Avatar
 
Join Date: Apr 2005
Location: Waterloo, Ontario
Posts: 1,886
Rep Power: 5 Sane will become famous soon enough
Send a message via MSN to Sane
WOOOT!

...hehehehe :p

...

What am I doing here again?

>_>

*runs*
Sane is offline   Reply With Quote
Old Jul 14th, 2005, 4:23 AM   #5
Dietrich
Professional Programmer
 
Dietrich's Avatar
 
Join Date: Feb 2005
Posts: 434
Rep Power: 4 Dietrich is on a distinguished road
Smile

Looking at your result:
>>>print pygame
<module 'pygame' from 'C:\Program Files\Python23\lib\pygame.pyc'>
I think your problem is 'C:\Program Files\' Python behaves somewhat unpredictable when there is a space in a directory name. This is a Microsoft thing only perpetrated by the US version of Windows, and it really stinks!
__________________
I looked it up on the Intergnats!
Dietrich is offline   Reply With Quote
Old Jul 14th, 2005, 2:15 PM   #6
Sane
Programming Guru
 
Sane's Avatar
 
Join Date: Apr 2005
Location: Waterloo, Ontario
Posts: 1,886
Rep Power: 5 Sane will become famous soon enough
Send a message via MSN to Sane
Ahhh, clever leprachaun you are. :eek:
Sane is offline   Reply With Quote
Old Jul 15th, 2005, 9:10 PM   #7
hamstu
Newbie
 
Join Date: Jul 2005
Posts: 2
Rep Power: 0 hamstu is on a distinguished road
Guido says it best himself...
Quote:
That's why the Python installer defaults to installing in
C:\Python##\

Try reinstalling Python using the default path.
from http://mail.python.org/pipermail/idl...ry/001507.html
hamstu is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 9:40 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC