[Tutor] PySide 1.2.2 and Python 3 - "native Qt signal is not callable"

Danny Yoo dyoo at hashcollision.org
Sun Aug 31 00:01:08 CEST 2014


> Now the problem is another one... And NOT related to PySide, it's pure
> Python. The problem is in the 'get_date()' func
> (http://pastebin.com/mPhJcXmF) - I get all the text from bankofcanada site
> but when I reach 'line.strip()' I get an error, "'int' object has no
> attribute 'strip'".

You've got a type error.  Let's analyze why.



What are the types we're dealing with?  Let's see.  In line 4 of the program:

        fh = urllib.request.urlopen("http://www.bankofcanada.ca/en/markets/csv/exchange_eng.csv").read()


urlopen() gives us a response object, according to:

    https://docs.python.org/3/library/urllib.request.html#urllib.request.urlopen


What is the return type of read()?

 https://docs.python.org/3/library/http.client.html#http.client.HTTPResponse.read

It sounds like it's returning a "bytes".  But what is a "bytes"?

    https://docs.python.org/3/library/stdtypes.html#bytes

Reading... ah, there's a section in the documentation on bytes that is relevant:

"""While bytes literals and representations are based on ASCII text,
bytes objects actually behave like immutable sequences of integers"""


Why is this fact relevant?


Because the loop here is trying to iterate over the individual elements in fh:

        for line in fh:

And from reading the documentation, those elements are the individual
byte integer values.  And so the "line" in line 6:

        for line in fh:

is not truly representing a line of text: it's representing a single
numeric byte in your input.  So that's the origin of the error.



Correct the code by using bytes.split().

    https://docs.python.org/3/library/stdtypes.html#bytes.split

So the loop really should be:

        for line in fh.split("\n"):
              ...


More information about the Tutor mailing list