Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > pygame - importing GL - very bad...

Reply
Thread Tools

pygame - importing GL - very bad...

 
 
someone
Guest
Posts: n/a
 
      01-01-2013
See this code (understand why I commented out first line):

# from OpenGL.GL import *
from OpenGL.GL import glEnable, GL_DEPTH_TEST, \
glShadeModel, GL_SMOOTH, glClearColor, \
GL_CULL_FACE, GL_BLEND, glBlendFunc, \
GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, \
glClear, GL_COLOR_BUFFER_BIT, GL_DEPTH_BUFFER_BIT, \
glLoadIdentity, glTranslate, glRotate, \
glMultMatrixf, glPushMatrix, glCallList, \
glPopMatrix, glDisable, GL_LIGHTING

The reason why I commented out the first line is that I use "pylint" and
it reports: "[W] Redefining built-in 'format'" for this line.

From: http://www.logilab.org/card/pylintfeatures tell:
W0621: Redefining name %r from outer scope (line %s) Used when a
variable's name hide a name defined in the outer scope.

I don't like to redefine already defined names so therefore I had to
outcomment first line and then keep on adding stuff until I could run my
program... But this SUCKS! I can see that pygame hasn't been updated for
a long while - not many users use it? I'm not very happy about this...

Any good / clever solution to this problem, so I avoid this nasty crappy
work-around?

Any ideas / suggestions ?
Thanks.


 
Reply With Quote
 
 
 
 
Chris Angelico
Guest
Posts: n/a
 
      01-01-2013
On Tue, Jan 1, 2013 at 10:00 PM, someone <(E-Mail Removed)> wrote:
> See this code (understand why I commented out first line):
>
> # from OpenGL.GL import *
> from OpenGL.GL import glEnable, GL_DEPTH_TEST, \
> glShadeModel, GL_SMOOTH, glClearColor, \
> GL_CULL_FACE, GL_BLEND, glBlendFunc, \
> GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, \
> glClear, GL_COLOR_BUFFER_BIT, GL_DEPTH_BUFFER_BIT, \
> glLoadIdentity, glTranslate, glRotate, \
> glMultMatrixf, glPushMatrix, glCallList, \
> glPopMatrix, glDisable, GL_LIGHTING
>
> Any good / clever solution to this problem, so I avoid this nasty crappy
> work-around?


You could simply

import OpenGL.GL as GL

and then use all those names as GL.glPopMatrix, GL.GL_LIGHTING, etc. I
don't know if that's better or worse.

ChrisA
 
Reply With Quote
 
 
 
 
Steven D'Aprano
Guest
Posts: n/a
 
      01-01-2013
On Tue, 01 Jan 2013 12:00:32 +0100, someone wrote:

> See this code (understand why I commented out first line):
>
> # from OpenGL.GL import *

[...]
> The reason why I commented out the first line is that I use "pylint" and
> it reports: "[W] Redefining built-in 'format'" for this line.
>
> From: http://www.logilab.org/card/pylintfeatures tell: W0621: Redefining
> name %r from outer scope (line %s) Used when a variable's name hide a
> name defined in the outer scope.
>
> I don't like to redefine already defined names so therefore I had to
> outcomment first line and then keep on adding stuff until I could run my
> program... But this SUCKS! I can see that pygame hasn't been updated for
> a long while - not many users use it? I'm not very happy about this...


from pygame import *
del format


pylint may still complain, but you can ignore it. By deleting the name
"format", that will unshadow the builtin format.


--
Steven
 
Reply With Quote
 
Peter Otten
Guest
Posts: n/a
 
      01-01-2013
someone wrote:

> See this code (understand why I commented out first line):
>
> # from OpenGL.GL import *
> from OpenGL.GL import glEnable, GL_DEPTH_TEST, \
> glShadeModel, GL_SMOOTH, glClearColor, \
> GL_CULL_FACE, GL_BLEND, glBlendFunc, \
> GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, \
> glClear, GL_COLOR_BUFFER_BIT, GL_DEPTH_BUFFER_BIT, \
> glLoadIdentity, glTranslate, glRotate, \
> glMultMatrixf, glPushMatrix, glCallList, \
> glPopMatrix, glDisable, GL_LIGHTING
>
> The reason why I commented out the first line is that I use "pylint" and
> it reports: "[W] Redefining built-in 'format'" for this line.
>
> From: http://www.logilab.org/card/pylintfeatures tell:
> W0621: Redefining name %r from outer scope (line %s) Used when a
> variable's name hide a name defined in the outer scope.
>
> I don't like to redefine already defined names so therefore I had to
> outcomment first line and then keep on adding stuff until I could run my
> program... But this SUCKS! I can see that pygame hasn't been updated for
> a long while - not many users use it? I'm not very happy about this...
>
> Any good / clever solution to this problem, so I avoid this nasty crappy
> work-around?
>
> Any ideas / suggestions ?
> Thanks.


It turns out pylint is lying. The situation is equivalent to

$ cat module.py
for format in [42]:
pass
del format

$ cat main.py
original_format = format
from module import *
assert format is original_format
$ python main.py

The assert doesn't trigger, so format is not redefined. But pylint complains
anyway:

$ pylint main.py -rn
No config file found, using default configuration
************* Module main
W: 2: Redefining built-in 'format'
C: 1: Missing docstring
C: 1: Invalid name "original_format" (should match (([A-Z_][A-Z0-9_]*)|
(__.*__))$)
W: 2: Wildcard import module

If you can ignore the warning about the wildcard import you should be able
to ignore the "redefining built-in" warning, too. Personally I would avoid
putting magic comments like

from module import * # pylint: disable=W0622

$ pylint main.py -rn
No config file found, using default configuration
************* Module main
I: 2: Locally disabling W0622
C: 1: Missing docstring
C: 1: Invalid name "original_format" (should match (([A-Z_][A-Z0-9_]*)|
(__.*__))$)
W: 2: Wildcard import module

into the code.

 
Reply With Quote
 
alex23
Guest
Posts: n/a
 
      01-01-2013
On Jan 1, 9:00*pm, someone <(E-Mail Removed)> wrote:
> I can see that pygame hasn't been updated for
> a long while - not many users use it?


It helps if you look in the right place:

pygame "Last Updated 2012-12-29": https://bitbucket.org/pygame/pygame/src
pygame2: http://code.google.com/p/pgreloaded/
 
Reply With Quote
 
someone
Guest
Posts: n/a
 
      01-01-2013
On 01/01/2013 12:13 PM, Chris Angelico wrote:
> On Tue, Jan 1, 2013 at 10:00 PM, someone <(E-Mail Removed)> wrote:
>> See this code (understand why I commented out first line):
>>
>> # from OpenGL.GL import *
>> from OpenGL.GL import glEnable, GL_DEPTH_TEST, \
>> glShadeModel, GL_SMOOTH, glClearColor, \
>> GL_CULL_FACE, GL_BLEND, glBlendFunc, \
>> GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, \
>> glClear, GL_COLOR_BUFFER_BIT, GL_DEPTH_BUFFER_BIT, \
>> glLoadIdentity, glTranslate, glRotate, \
>> glMultMatrixf, glPushMatrix, glCallList, \
>> glPopMatrix, glDisable, GL_LIGHTING
>>
>> Any good / clever solution to this problem, so I avoid this nasty crappy
>> work-around?

>
> You could simply
>
> import OpenGL.GL as GL
>
> and then use all those names as GL.glPopMatrix, GL.GL_LIGHTING, etc. I
> don't know if that's better or worse.


You're right - but I forgot to write that even though this maybe
should/is recommended many places then I've seen a lot of opengl code on
the internet and IMHO NOBODY does that and it'll be a lot slower to type
that in front of all the opengl commands...

So this solution is not something I like too... But I can see some other
people came up with good solutions, which I didn't knew about..

Thank you.

 
Reply With Quote
 
someone
Guest
Posts: n/a
 
      01-01-2013
On 01/01/2013 12:49 PM, Steven D'Aprano wrote:
> On Tue, 01 Jan 2013 12:00:32 +0100, someone wrote:
>
>> See this code (understand why I commented out first line):
>>
>> # from OpenGL.GL import *

> [...]
>> The reason why I commented out the first line is that I use "pylint" and
>> it reports: "[W] Redefining built-in 'format'" for this line.
>>
>> From: http://www.logilab.org/card/pylintfeatures tell: W0621: Redefining
>> name %r from outer scope (line %s) Used when a variable's name hide a
>> name defined in the outer scope.
>>
>> I don't like to redefine already defined names so therefore I had to
>> outcomment first line and then keep on adding stuff until I could run my
>> program... But this SUCKS! I can see that pygame hasn't been updated for
>> a long while - not many users use it? I'm not very happy about this...

>
> from pygame import *
> del format


Are you sure about this? Because I'm not (OTOH I'm maybe not as
experienced in python as some of you)... Ipython log:

--------
In [6]: test=format(43)

In [7]: type(test)
Out[7]: str

In [8]: from pygame import *

In [9]: test=format(43)

In [10]: type(test)
Out[10]: str

In [11]: del format
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
<ipython-input-11-028e6ffb84a8> in <module>()
----> 1 del format

NameError: name 'format' is not defined
--------

What does this mean? Why does it say 'format" cannot be deleted after I
did the wildcard import ?

> pylint may still complain, but you can ignore it. By deleting the name
> "format", that will unshadow the builtin format.


Are you sure?

 
Reply With Quote
 
someone
Guest
Posts: n/a
 
      01-01-2013
On 01/01/2013 01:56 PM, Peter Otten wrote:
> someone wrote:


> It turns out pylint is lying. The situation is equivalent to
>
> $ cat module.py
> for format in [42]:
> pass
> del format
>
> $ cat main.py
> original_format = format
> from module import *
> assert format is original_format
> $ python main.py
>
> The assert doesn't trigger, so format is not redefined. But pylint

complains
> anyway:
>
> $ pylint main.py -rn
> No config file found, using default configuration
> ************* Module main
> W: 2: Redefining built-in 'format'
> C: 1: Missing docstring
> C: 1: Invalid name "original_format" (should match (([A-Z_][A-Z0-9_]*)|
> (__.*__))$)
> W: 2: Wildcard import module
>
> If you can ignore the warning about the wildcard import you should be

able

In the case of opengl import, I'll ignore the wildcard import warning.
But in other cases I'll likely look a bit into it and see if I can avoid
it or at least change it to something like: "import OpenGL.GL as GL" etc.

> to ignore the "redefining built-in" warning, too. Personally I would

avoid
> putting magic comments like
>
> from module import * # pylint: disable=W0622


Oh, I just learned something new now... How come I cannot type "#pylint:
enable=W0622" in the line just below the import ?

Not so intuitively/logically for me...

> $ pylint main.py -rn
> No config file found, using default configuration
> ************* Module main
> I: 2: Locally disabling W0622
> C: 1: Missing docstring
> C: 1: Invalid name "original_format" (should match (([A-Z_][A-Z0-9_]*)|
> (__.*__))$)
> W: 2: Wildcard import module
>
> into the code.


Thank you very much...

Another thing is that I don't understand this warning:

Invalid name "original_format" (should match (([A-Z_][A-Z0-9_]*)|
> (__.*__))$)


I get it everywhere... I don't understand how it wants me to label my
variables... Maybe I should disable this warning to get rid of it...



 
Reply With Quote
 
someone
Guest
Posts: n/a
 
      01-01-2013
On 01/01/2013 11:39 PM, alex23 wrote:
> On Jan 1, 9:00 pm, someone <(E-Mail Removed)> wrote:
>> I can see that pygame hasn't been updated for
>> a long while - not many users use it?

>
> It helps if you look in the right place:
>
> pygame "Last Updated 2012-12-29": https://bitbucket.org/pygame/pygame/src
> pygame2: http://code.google.com/p/pgreloaded/


Maybe... But if you look for stable releases here:

http://www.pygame.org/download.shtml

You'll find the top option: 1.9.1 Packages (August 6th 2009)


And then previous releases is just below 1.9.1:

pygame-1.9.0release.tar.gz ~ 1.4M - August 1, 2009
pygame-1.8.1release.tar.gz ~ 1.4M - July 30, 2008
pygame-1.8.0release.tar.gz ~ 1.4M - March 29, 2008
pygame-1.7.1release.tar.gz ~ 1.3M - August 16, 2005
1.7.0 ~ no source release was made.
pygame-1.6.2.tar.bz2 ~ 1140 kb -
pygame-1.6.tar.gz ~ 832 kb - October 23, 2003
pygame-1.5.tar.gz ~ 736 kb - May 30, 2002
pygame-1.4.tar.gz ~ 808 kb - Jan 30, 2002
pygame-1.3.tar.gz ~ 731 kb - Dec 19, 2001
pygame-1.2.tar.gz ~ 708 kb - Sep 4, 2001
pygame-1.1.tar.gz ~ 644 kb - Jun 23, 2001
pygame-1.0.tar.gz ~ 564 kb - Apr 5, 2001
pygame-0.9.tar.gz ~ 452 kb - Feb 13, 2001
pygame-0.5.tar.gz ~ 436 kb - Jan 6 14, 2001
pygame-0.4.tar.gz ~ 420 kb - Dec 14, 2000
pygame-0.3b.tar.gz ~ 367 kb - Nov 20, 2000
pygame-0.2b.tar.gz ~ 408 kb - Nov 3, 2000
pygame-0.1a.tar.gz ~ 300 kb - Oct 28, 2000


Back to year 2000...

Maybe they should get a grip on themselves and distribute a new stable
releases in year 2013 - then it would at least SEEM to look as the
project is not dead. But in any case, I'm happy with it - haven't
experienced any big issues with pygame yet, so don't take this as I
don't value what they do. Maybe they've made a great version back in
2009 and it's so good that there wasn't any need for a newer stable
version before 2013.

But it gives the impression that nothing happens, when so many years
pass on...

Anyway, thanks a lot to all...

(And sorry I accidentally replied privately to some of you - in
thunderbird I should hit the "followup"-button but maybe they've removed
it and instead I keep on hitting "reply" - very confusing that the first
button in thunderbird is reply instead of followup, which is what I
always prefer to use (so other people can see the answers).

Thanks you for pointing out that (at least) something did happen on
2012-12-29, when it looks a bit dead on the official homepage.


 
Reply With Quote
 
Nobody
Guest
Posts: n/a
 
      01-02-2013
On Wed, 02 Jan 2013 00:49:36 +0100, someone wrote:

> In [11]: del format
> ---------------------------------------------------------------------------
> NameError Traceback (most recent call last)
> <ipython-input-11-028e6ffb84a8> in <module>()
> ----> 1 del format
>
> NameError: name 'format' is not defined
> --------
>
> What does this mean? Why does it say 'format" cannot be deleted after I
> did the wildcard import ?


You can't delete built-in names.

It has nothing to do with the wildcard import. The PyOpenGL modules delete
"format" from the module's variables as soon as they are finished with
it, so the set of names created by the wildcard import doesn't include
"format".

 
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
[pygame-bug] Pygame.cdrom bug rantingrick Python 1 01-30-2011 04:40 AM
[pygame] Very simple program fails. Why? Brent W. Hughes Python 2 04-27-2005 10:24 PM
very very very long integer shanx__=|;- C Programming 19 10-19-2004 03:55 PM
Quick Book file access very very very slow Thomas Reed Computer Support 7 04-09-2004 08:09 PM
very Very VERY dumb Question About The new Set( ) 's Raymond Arthur St. Marie II of III Python 4 07-27-2003 12:09 AM



Advertisments