Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 4 years ago.
Improve this question
Any ideas why this line isn't working? I want a variable to be assigned the integer of the text in a label. If the label does not have any text assigned, I want the variable to equal 0.
I'm getting a "can't assign to conditional expression" error before it even tries to run.
var = int(label.cget("text")) if label.cget("text") != "" else var = 0
More pythonic:
var = int(label.cget("text") or 0)
Related
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 1 year ago.
Improve this question
I am currently trying to create team selection code for my python video game.
Unfortunately, it keeps highliting the ":" of my if statement and saying that it is invalid syntax, even if i change the if statement for another. I tried everything, but after all, it IS an if statement, and i can't do much.
Heres my minimal recreation of the problem. The structure is important as there is netwroking code there;
team1=[]
team2=[]
if (len(team1)+len(team2)):
if team1==team2:
rand = (random.choice([team1, team2])
if rand == "team1":
team1.append(username)
else:
team2.append(username)
else:
if team1>=team2:
team1.append(username)
else:
team2.append(username)
else:
team1.append(username)
The problem is the stray '(' you have before random.choice([team1, team2]). Delete it so it becomes:
rand = random.choice([team1, team2])
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 3 years ago.
Improve this question
In my code below, the times variable prints data in calendar and business time. Some of the data have numbers and others print the value 'None'. I would like to only print data that does not have the value 'None'. When I run my code I still get all of the data printed.
for ticket1 in ticket_list1:
for ticket2 in ticket_list2:
times = ticket2['reply_time_in_minutes']
ticket_id = ticket2['ticket_id']
assignee = ticket1['assignee_id']
priority = ticket1['priority']
if ticket1['assignee_id'] != ticket1['requester_id']:
if times['calendar'] != 'None':
print("%s %20s %20s %20s" % (times, ticket_id,
assignee, priority))
Remove the quotes around none. None is actually a value - of <type 'NoneType'>. So it cannot be compared to a string.
if times['calendar'] != None:
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
How would I interchange the contents of variables A and B?
temp = A
B = A
A = temp
The following code doesn't work. I'm not sure how to fix it. I must not understand python syntax or variables correctly.
Python provides particularly elegant syntax for swapping variables:
A, B = B, A
Erm...
temp = A
A = B
B = temp
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
Issue occurred right after I added the and x= "J1234": I don't know what's going on.
original = ""
if len(original) > 0 and x = "J123":
raw_input("Enter a word:")
original = raw_input('word')
print "original"
else:
print "empty"
x.isalpha()
So, you're getting a SyntaxError. To fix this, change:
x = "J123":
to...
x == "J123":
In Python the former is for setting values and the latter is for checking them. Therefore when you use this the wrong way round the syntax is incorrect.
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 9 years ago.
Improve this question
I am new to this and am receiving an error that says print (line 5) is an invalid syntax
from random import randint
r=randint
while True:
s=int(input('How many sides would you like on your die')
print (r(1,s))
The problem is not actually on line 5, but on line 4. You have two ( brackets but only one ). In search of the final ) the Python interpreter checks the following line, and only at that point does it raise the error.
s=int(input('How many sides would you like on your die')
^
There is a closing parenthesis missing.