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-02-2013
On 01/02/2013 04:01 AM, Nobody wrote:
> 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.


Ah, ok - and cannot overwrite it too, I guess... A shame that pylint
didn't knew about this.

> 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".


Ok, sounds to me like I can safely ignore this pylint warning in any
case... Thanks!


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

> 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)...


In the general case of deleting global names that shadow builtin names,
yes I am.

In the specific case of importing * from pygame, no. I trusted you that
pygame exports format. Unfortunately, it seems that you were fooled by an
invalid warning from pylint, so we were both mistaken.


> 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 ?


It means that there is no "format" in the current scope, which implies
that pygame no longer has a "format" which can be imported.

You don't need an import to shadow built-ins. See for example:

py> format
<built-in function format>
py> format = "NOBODY expects the Spanish Inquisition!"
py> format # this shadows the built-in "format"
'NOBODY expects the Spanish Inquisition!'
py> del format # get rid of the Spanish Inquisition
py> format
<built-in function format>
py> del format
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'format' is not defined


When a name is not discovered in the current scope, the builtin scope is
checked before Python gives up and reports a NameError. But del only
works on the current scope, to stop you from accidentally deleting the
wrong object.


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

>
> Are you sure?


Since it turns out that pylint was actually wrong to complain, no format
was actually imported, then yes you can safely ignore it



--
Steven
 
Reply With Quote
 
 
 
 
alex23
Guest
Posts: n/a
 
      01-02-2013
On Jan 2, 1:01*pm, Nobody <(E-Mail Removed)> wrote:
> You can't delete built-in names.


Actually, you can. If you ever need to shoot yourself in the foot in
this particular way, you can always do:

del __builtins__.format

Not saying you _should_, just that you _can_
 
Reply With Quote
 
Peter Otten
Guest
Posts: n/a
 
      01-02-2013
someone wrote:

> On 01/01/2013 01:56 PM, Peter Otten wrote:


>> 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 ?


With what intended effect?

> 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...


pylint wants global names to be uppercase (what PEP 8 recommends for
constants) or "special" (two leading and two trailing underscores):

THATS_OK = 42
__thats_ok_too__ = object()
but_thats_not = "spam"


 
Reply With Quote
 
someone
Guest
Posts: n/a
 
      01-02-2013
On 01/02/2013 10:52 AM, alex23 wrote:
> On Jan 2, 1:01 pm, Nobody <(E-Mail Removed)> wrote:
>> You can't delete built-in names.

>
> Actually, you can. If you ever need to shoot yourself in the foot in
> this particular way, you can always do:
>
> del __builtins__.format
>
> Not saying you _should_, just that you _can_


Ok, good to know (not saying I would ever try it)


 
Reply With Quote
 
someone
Guest
Posts: n/a
 
      01-02-2013
On 01/02/2013 08:39 AM, Steven D'Aprano wrote:
> On Wed, 02 Jan 2013 00:49:36 +0100, someone wrote:


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

>
> It means that there is no "format" in the current scope, which implies
> that pygame no longer has a "format" which can be imported.
>
> You don't need an import to shadow built-ins. See for example:
>
> py> format
> <built-in function format>
> py> format = "NOBODY expects the Spanish Inquisition!"
> py> format # this shadows the built-in "format"
> 'NOBODY expects the Spanish Inquisition!'
> py> del format # get rid of the Spanish Inquisition
> py> format
> <built-in function format>
> py> del format
> Traceback (most recent call last):
> File "<stdin>", line 1, in <module>
> NameError: name 'format' is not defined


Ok, thank you very much - that was/is very illustrative...

> When a name is not discovered in the current scope, the builtin scope is
> checked before Python gives up and reports a NameError. But del only
> works on the current scope, to stop you from accidentally deleting the
> wrong object.


Ok, I'll remember that in the future, thank you.

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

>>
>> Are you sure?

>
> Since it turns out that pylint was actually wrong to complain, no format
> was actually imported, then yes you can safely ignore it


Ok, I can see from your example that you're right. Nice to know the real
explanation, thank you very much.

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

>
>>> 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 ?

>
> With what intended effect?


If I have a section with A LOT OF warnings and I don't want those in
that section to show up ? Isn't that valid enough?

>> 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...

>
> pylint wants global names to be uppercase (what PEP 8 recommends for
> constants) or "special" (two leading and two trailing underscores):
>
> THATS_OK = 42
> __thats_ok_too__ = object()
> but_thats_not = "spam"


OMG... I don't want to type those underscores everywhere... Anyway,
thank you very much for explaining the meaning of what it wants...



 
Reply With Quote
 
Dave Angel
Guest
Posts: n/a
 
      01-02-2013
On 01/02/2013 09:09 AM, someone wrote:
> On 01/02/2013 01:07 PM, Peter Otten wrote:
>> someone wrote:
>>
>>> On 01/01/2013 01:56 PM, Peter Otten wrote:

>>
>>>> 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 ?

>>
>> With what intended effect?

>
> If I have a section with A LOT OF warnings and I don't want those in
> that section to show up ? Isn't that valid enough?
>
>>> 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...

>>
>> pylint wants global names to be uppercase (what PEP 8 recommends for
>> constants) or "special" (two leading and two trailing underscores):
>>
>> THATS_OK = 42
>> __thats_ok_too__ = object()
>> but_thats_not = "spam"

>
> OMG... I don't want to type those underscores everywhere... Anyway,
> thank you very much for explaining the meaning of what it wants...
>
>
>


Global const values should be ALL_CAPS, so it's obvious that nobody
intends to modify them. It's the non-const global attributes that
expect to be underscored.

You shouldn't have to use those underscores very often. After all,
there is seldom a need for a non-const global value, right? Don't think
of it as a pylint problem, but as a hint from pylint that perhaps you
should use fewer globals.



--

DaveA

 
Reply With Quote
 
Chris Angelico
Guest
Posts: n/a
 
      01-02-2013
On Wed, Jan 2, 2013 at 11:07 PM, Peter Otten <(E-Mail Removed)> wrote:
> someone wrote:
>> 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...

>
> pylint wants global names to be uppercase (what PEP 8 recommends for
> constants) or "special" (two leading and two trailing underscores):
>
> THATS_OK = 42
> __thats_ok_too__ = object()
> but_thats_not = "spam"


Okay, I have to ask... why? Does it have an exception for names of classes?

I don't like linters that enforce too much style. Catch things that
might be mis-coded (like C's classic "if (x = 1)"), but don't complain
about my names. They're MY business.

ChrisA
 
Reply With Quote
 
Ian Kelly
Guest
Posts: n/a
 
      01-02-2013
On Wed, Jan 2, 2013 at 7:32 AM, Chris Angelico <(E-Mail Removed)> wrote:
> Okay, I have to ask... why? Does it have an exception for names of classes?


Yes, and for module-level functions.

> I don't like linters that enforce too much style. Catch things that
> might be mis-coded (like C's classic "if (x = 1)"), but don't complain
> about my names. They're MY business.


pylint is configurable though, so you can disable any warnings you
don't care about. My pylint macro has a fairly large number of -d
options in it.
 
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