• Register
0 votes
1.2k 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.9k points

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.

36.1k points

Related questions

0 votes
1 answer 158 views
158 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 alecxe 7.5k points
0 votes
1 answer 27 views
27 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 Raphael Pacheco 2.3k points
0 votes
2 answers 790 views
790 views
Problem : I am new to Py 3.5. This code was working properly in Python 2.7: with open(fname, 'rb') as f: lines = [x.strip() for x in f.readlines()] for line in lines: tmp = line.strip().lower() if 'some-pattern' in tmp: continue # ... code After upgrading to 3.5, I'm getting the: TypeError: a bytes-like object is required, not 'str'
asked Oct 22, 2019 peterlaw 6.9k points
0 votes
1 answer 775 views
775 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
1 vote
1 answer 20 views
20 views
Problem : I want to learn the python programming and also want to work on projects. One of my projects is to code the voting system so that it can select the best player among 23 players of a match by using the lists. I am currently using the Python3. Please ... any of the strings in my above code all my variables are of the type integers. Please guide me in fixing above python related error.
asked May 14 Martin K 6.6k points