TypeError: int() argument must be a string, a bytes-like object or a number, not 'list'

后端 未结 1 839
天涯浪人
天涯浪人 2021-02-06 22:41

I having trouble passing a function as a parameter to another function. This is my code:

ga.py:

def display_pageviews(hostname):
    pag         


        
相关标签:
1条回答
  • 2021-02-06 23:30

    What the error is telling, is that you can't convert an entire list into an integer. You could get an index from the list and convert that into an integer:

    x = ["0", "1", "2"] 
    y = int(x[0]) #accessing the zeroth element
    

    If you're trying to convert a whole list into an integer, you are going to have to convert the list into a string first:

    x = ["0", "1", "2"]
    y = ''.join(x) # converting list into string
    z = int(y)
    

    If your list elements are not strings, you'll have to convert them to strings before using str.join:

    x = [0, 1, 2]
    y = ''.join(map(str, x))
    z = int(y)
    

    Also, as stated above, make sure that you're not returning a nested list.

    0 讨论(0)
提交回复
热议问题