Why isnt my variable set when I call the other function? [duplicate]
2024/11/18 21:33:19
TypeError: '<' not supported between instances of 'NoneType' and 'int'
I have looked for an answer in Stack Overflow and found that I should be taking an int(input(prompt)), but that's what I am doing
def main(): while True:vPopSize = validinput("Population Size: ")if vPopSize < 4:print("Value too small, should be > 3")continueelse:breakdef validinput(prompt):while True:try:vPopSize = int(input(prompt))except ValueError:print("Invalid Entry - try again")continueelse:break
Answer
This problem also comes up when migrating to Python 3.
In Python 2 comparing an integer to None will "work," such that None is considered less than any integer, even negative ones:
>>> None > 1
False
>>> None < 1
True
In Python 3 such comparisons raise a TypeError:
>>> None > 1
Traceback (most recent call last):File "<stdin>", line 1, in <module>
TypeError: '>' not supported between instances of 'NoneType' and 'int'>>> None < 1
Traceback (most recent call last):File "<stdin>", line 1, in <module>
TypeError: '<' not supported between instances of 'NoneType' and 'int'
I want to replace negative values in a pandas DataFrame column with zero.Is there a more concise way to construct this expression?df[value][df[value] < 0] = 0
views.pydef generate_xml(request, number):caller_id = x-x-x-xresp = twilio.twiml.Response()with resp.dial(callerId=caller_id) as r:if number and re.search([\d\(\)\- \+]+$, number):r.number(number)else:…
Closed. This question is opinion-based. It is not currently accepting answers.Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.Clo…
I am building a C++ extension for use in Python. I am seeing this warning being generated during the compilation process - when a type:python setup.py build_ext -iWhat is causing it, and how do I fix i…
I was playing around with flask when I came across an odd problem with the \n character. it dosent seem to have an effect in my browser, I tried putting in there but it didnt work, any ideas?from fla…
Im trying to understand how Django is setting keys for my views. Im wondering if theres a way to just get all the saved keys from Memcached. something like a cache.all() or something. Ive been trying t…
I have those arrays:a = np.array([[1,2],[3,4],[5,6],[7,8]])b = np.array([1,2,3,4])and I want them to multiply like so:[[1*1, 2*1],
[3*2, 4*2],
[5*3, 6*3],
[7*4, 8*4]]... basically out[i] = a[i] * b[i],…
I am trying to set up some post_save receivers similar to the following:
@receiver(post_save, sender=Game, dispatch_uid=game_updated)
def game_updated(sender, **kwargs):DO SOME STUFF HEREMyPick.objects…
I have a list of say 100k floats and I want to convert it into a bytes buffer.buf = bytes()
for val in floatList:buf += struct.pack(f, val)
return bufThis is quite slow. How can I make it faster using …
When a new developer joins the team, or Jenkins runs a complete build, I need to create a fresh virtualenv. I often find that setting up a virtualenv with Pip and a large number (more than 10) of requi…