SyntaxError: keyword can't be an expression

I am getting this error
SyntaxError: keyword can't be an expression

  • at TaskAssignment, line 15
  • called from AssignTaskForm, line 7
  • called from Admin_tasks, line 8
  • called from Admin_Dashboard, line 41

for the follwing code:

class Task_assign:
def init(self, Assignee, title, description, due_date):
self.assignee = assignee
self.title = title
self.description = description
self.due_date = due_date
def assign(self):
user_row = app_tables.users.get(username=self.assignee)
new_task = app_tables.tasks.add_row(
‘Task Name’ = self.title,
‘Description’ = self.description,
‘Due Date’ = self.due_date,
‘Status’ = ‘Not Started’,
‘Assignee’ = self.assignee
)
anvil.server.call_s(
‘send_task_email’,
Assignee = self.assignee,
Task Name = self.title,
Due Date = self.due_date
)

Can anyone tell me how do i overcome this error.
I believe the error is happening in the add_row() or call_s() function when I’m passing keyword arguments, but I’m not sure what I’m doing wrong.

Can someone help me understand what’s causing the error and how to fix it?

Thanks in advance!

You have keyword arguments with spaces in them. That isn’t legal Python. Variables and parameter names may not have spaces.

3 Likes

OH…Thankyou so much…I will find another way.

You could either make the variable names have underscores (i.e. Task_name, or more pythonicly, taks_name) or pass a dictionary as a single arguments

anvil.server.call_s(
    'send_task_email',
    email_values={
        "Assignee": self.assignee,
        "Task Name": self.title,
        "Due Date": self.due_date,
    }
)
1 Like