Using builtin "type" function in a Python FS product
Is there changes in this usual Python builtin ? import types # somewhere in a method... if type(x) == types.UnicodeType: Raises... Error Type: UnboundLocalError Error Value: local variable 'type' referenced before assignment What did I miss ? Thanks by advance. --Gilles
if you're talking about using it in a Python Script, you want to use same_type - type is supposedly a security risk for some reason... http://www.zopelabs.com/cookbook/995873707 Gilles Lenfant wrote:
Is there changes in this usual Python builtin ?
import types
# somewhere in a method...
if type(x) == types.UnicodeType:
Raises...
Error Type: UnboundLocalError Error Value: local variable 'type' referenced before assignment
What did I miss ?
Thanks by advance.
--Gilles
_______________________________________________ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
----- Original Message ----- From: "Chris Beaven" <chris@d-designz.co.nz> To: "Gilles Lenfant" <gilles@pilotsystems.net> Cc: <zope@zope.org> Sent: Wednesday, October 15, 2003 5:57 AM Subject: Re: [Zope] Using builtin "type" function in a Python FS product
if you're talking about using it in a Python Script, you want to use same_type - type is supposedly a security risk for some reason... http://www.zopelabs.com/cookbook/995873707
Thanks Chris, But as mentioned in the title this sample is in a Python Product (in file system). Neither "type(x)" or "same_type(x, y)" work !!?? --Gilles
Please provide a testcase! -aj --On Mittwoch, 15. Oktober 2003 12:45 Uhr +0200 Gilles Lenfant <gilles@pilotsystems.net> wrote:
----- Original Message ----- From: "Chris Beaven" <chris@d-designz.co.nz> To: "Gilles Lenfant" <gilles@pilotsystems.net> Cc: <zope@zope.org> Sent: Wednesday, October 15, 2003 5:57 AM Subject: Re: [Zope] Using builtin "type" function in a Python FS product
if you're talking about using it in a Python Script, you want to use same_type - type is supposedly a security risk for some reason... http://www.zopelabs.com/cookbook/995873707
Thanks Chris,
But as mentioned in the title this sample is in a Python Product (in file system).
Neither "type(x)" or "same_type(x, y)" work !!??
--Gilles
_______________________________________________ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
Gilles Lenfant wrote:
Is there changes in this usual Python builtin ?
import types
# somewhere in a method...
if type(x) == types.UnicodeType:
Raises...
Error Type: UnboundLocalError Error Value: local variable 'type' referenced before assignment
What did I miss ?
It seems to work elsewhere. OFS/Image.py, for instance, and lots of other places. How does it work without the surrounding code? --jcc
On Tue, Oct 14, 2003 at 09:14:31PM +0200, Gilles Lenfant wrote: | Is there changes in this usual Python builtin ? No. | if type(x) == types.UnicodeType: | Error Type: UnboundLocalError | Error Value: local variable 'type' referenced before assignment | | What did I miss ?
def demonstrate_programmer_error() : ... type("a string") ... type = "some other object" ... demonstrate_programmer_error() Traceback (most recent call last): File "<stdin>", line 1, in ? File "<stdin>", line 2, in demonstrate_programmer_error UnboundLocalError: local variable 'type' referenced before assignment
Don't assign to 'type' in your method. Use a different name for the local variable. -D -- Folly delights a man who lacks judgement, but a man of understanding keeps a straight course. Proverbs 15:21 http://dman13.dyndns.org/~dman/
----- Original Message ----- From: "Derrick 'dman' Hudson" <dman@dman13.dyndns.org> To: <zope@zope.org> Sent: Thursday, October 16, 2003 12:56 AM Subject: [Zope] Re: Using builtin "type" function in a Python FS product
_______________________________________________ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
Yeees ! Many thanks ! I was patching a method of IssueTracker to check Unicode data. The author of the original stuff uses a "type" variable later. I renamed that variable and all works again ! Me dummy stupid sometimes :o) --Gilles
participants (5)
-
Andreas Jung -
Chris Beaven -
Derrick 'dman' Hudson -
Gilles Lenfant -
J Cameron Cooper