What is the difference between and

前端 未结 2 810
盖世英雄少女心
盖世英雄少女心 2020-12-17 15:44

I am new to python. I\'m confused by the . I got a str by using:

response = urllib.request.urlopen(req).read().decode()
         


        
2条回答
  •  死守一世寂寞
    2020-12-17 16:31

    There is no difference. Python changed the text representation of type objects between python 2 (Types are written like this: .) and python 3 (Types are written like this: .). In both python 2 and 3, the type of the type object is, um, type:

    python 2

    >>> type(type('a'))
    
    

    python 3

    >>> type(type('a'))
    
    

    And that's the reason for the change... the string representation makes it clear that the type is a class.

    As for the rest of your problem,

    for ID in response:
    

    response is a string and enumerating it gives the characters in the string. Depending on the type of response you may want to use and HTML, JSON or other parser to turn it into python objects.

提交回复
热议问题