• Register
0 votes
2.5k views

Problem :

I am facing the issue in passing a function as a parameter to another function as follows

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

6 5 3
6,930 points

Please log in or register to answer this question.

1 Answer

0 votes

Solution :

The error is telling you that you can not convert an entire list into an integer. The better way to do it is to get an index from the list and convert that into an integer as follows:

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

If you want to convert a whole list into an integer then you need to convert the list into a string first as follows:

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

And if your list elements are not strings then you need to convert them to strings before using str.join as follows:

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

Please make sure that you are not returning a nested list.

9 7 4
38,600 points

Related questions

0 votes
1 answer 309 views
309 views
Problem : When I try to run following command: python manage.py updatestats I get the error as below: “TypeError: int() argument must be a string, a bytes-like object or a number, not 'list'” I am unable to figure out ... ) File "/Users/alecxe/project/Dev/project_files/project/main/management/commands/updatestats.py", line 34, in handle unique_visits=display_unique_visits(hostname),)
asked Jan 2, 2020 alecxe 7.5k points
0 votes
1 answer 47 views
0 votes
1 answer 25 views
25 views
Program: I having trouble passing a function as a parameter to another function. This is my code: ga.py: def display_pageviews(hostname): pageviews_results = get_pageviews_query(service, hostname).execute() if pageviews_results.get('rows', []): pv = pageviews_results.get('rows') ... ='7daysAgo', end_date='today', metrics='ga:pageviews', sort='-ga:pageviews', filters='ga:hostname==%s' % hostname,)
asked Jan 11 Mashhoodch 13k points
0 votes
1 answer 8 views
8 views
Problem: after upgrading to 3.5, I'm getting the: TypeError: a bytes-like object is required, not 'str'
asked Mar 16 ummesalma 25.2k points
0 votes
1 answer 154 views
154 views
Problem: I have freshly migrated my project from the old python2 to the new python3 and it has hundreds of the ForeignKey relations. I have very basic knowledge related to python. Using a solution to go line by line and add on_delete argument is not the possible. What ... it does not look like catching it somehow. Looking for a Python expert who can try to fix my above Python error very quickly.
asked Jul 15, 2020 Raphael Pacheco 4.9k points
0 votes
1 answer 9 views
9 views
Problem: Please help me … how can I solve it? valueerror: err must be [ scalar | n, nx1 or 2xn array-like ]
asked Mar 31 Ifra 24.4k points
0 votes
1 answer 14 views
14 views
Problem: I am facing following error: post data should be bytes, an iterable of bytes, or a file object. it cannot be of type str.
asked Mar 14 Wafa Abu Yousef 6.1k points
0 votes
1 answer 1.8K views
1.8K views
Problem : I am trying to convert my working Python 2.7 code into Python 3 code but I am facing following error post data should be bytes, an iterable of bytes, or a file object. it cannot be of type str.
asked Nov 16, 2019 peterlaw 6.9k points
0 votes
1 answer 22 views
22 views
Problem: Any ideas on what I need to do to fix this? Thanks! Doesn't declare an explicit app_label and isn't in an application in installed_apps..
asked Mar 6 Wafa Abu Yousef 6.1k points
0 votes
1 answer 2.9K views
2.9K views
Problem : I am at my minds end. After a lot of hours of troubleshooting, probably more than 20, I thought I was finally in business, but then I got following error : Model class django.contrib.contenttypes.models.ContentType doesn't ... class MyDeletenoteConfig(AppConfig): name = 'MyDeleteNote' and from django.apps import AppConfig class MyLibrarysyncConfig(AppConfig): name = 'MyLibrarySync'
asked Dec 16, 2019 alecxe 7.5k points