Strange Behavior

Peter Otten __peter__ at web.de
Mon Jun 2 13:59:23 EDT 2014


robertw89 at googlemail.com wrote:

> Hello folks,
> 
> I am not sure if it is only on my system the case that the code in
> http://pastebin.com/WETvqMJN misbehaves in the stated way.
> Can anybody reproduce it?
> 
> I thought it could be that the tabs/spaces do influence it, but it doesn't
> care.
> 
> Thank you very much for your time.
> 
> Robert

I get what you expect:

$ cat bug.py
class EnumSectionContentType(object):
    DATABYTE = 2
    DATADOUBLEWORD = 3
    DATAWORD = 4
#LABEL = 0

def _getStringOfElements(elements):
    objectFileString = ""

    elements = [{'type': 2, 'data': {'elements': ['83H', '0FAH', '9AH', '27H', '81H', '49H', '0CEH', '11H']}}]

    for iterationElement in elements:
        objectFileString += "INSIDE1 "
        
        if iterationElement["type"] == EnumSectionContentType.LABEL:
            objectFileString +=  iterationElement["data"]["labelname"] + ":" + "\n"
        elif iterationElement["type"] == EnumSectionContentType.DATABYTE:
            objectFileString += "INSIDE" + "\n"

            if   iterationElement["type"] == EnumSectionContentType.DATADOUBLEWORD:
                objectFileString += objectFileString + "dd "
            elif iterationElement["type"] == EnumSectionContentType.DATABYTE:
                objectFileString += objectFileString + "db "

    return objectFileString

print(_getStringOfElements(None))
$ python3.4 bug.py
Traceback (most recent call last):
  File "bug.py", line 27, in <module>
    print(_getStringOfElements(None))
  File "bug.py", line 15, in _getStringOfElements
    if iterationElement["type"] == EnumSectionContentType.LABEL:
AttributeError: type object 'EnumSectionContentType' has no attribute 'LABEL'

Are you absolutely sure you are invoking the right bug.py?
(I think on windows you can use type instead of cat to see 
the file contents).




More information about the Python-list mailing list