user3502263
user3502263

Reputation: 11

TypeError: unsupported operand type(s) python web2py

The code below is giving me the following error: TypeError: unsupported operand type(s) for +: 'int' and 'Row'

import datetime
#product withholding in days
days = (0)

pdays = db(db.product.withholding_period>0).select().first()

wdate = db(db.stock_task.completed_date>0).select().first()

fdate = wdate + datetime.timedelta(days+pdays)

Can anyone explain what causes this error and how it can be solved?

Upvotes: 1

Views: 153

Answers (2)

br3w5
br3w5

Reputation: 4583

You cannot add a database Row to an int. You need to extract the pdays and wdate from the correct column in the row. Swap the column names below with the correct ones for your table:

import datetime

product withholding in days

days = (0)

# get the pdays
pdays_row = db(db.product.withholding_period>0).select().first()
pdays = pdays_row.withholding_period

# get the wdate
wdate_row = db(db.stock_task.completed_date>0).select().first()
wdate = wdate_row.completed_ date

fdate = wdate + datetime.timedelta(days + pdays)

Upvotes: 0

Nir Levy
Nir Levy

Reputation: 12953

The error is because you are trying to add up days (which is int) and pdays (which is Row). the + operator does not work with these two type of arguments

Upvotes: 1

Related Questions