TypeError:int()参数必须是字符串、类似字节的对象或数字,而不是“Calendar”

2024-10-01 17:28:40 发布

您现在位置:Python中文网/ 问答频道 /正文

我有代码,允许用户点击日历,它将输出日期。我想将日期链接到sql查询,但出现错误:

File "C:\Users\dansi\AppData\Local\Programs\Python\Python36-32\gui test 3.py", line 293, in datefunction
agro = int(agro)
TypeError: int() argument must be a string, a bytes-like object or a number, not 'Calendar'

问题代码:

^{pr2}$

假设用户在3月3日点击,它就会输出

'2017-03-03 00-00-00'

怎样才能克服这个错误呢?在


Tags: 代码用户sql链接local错误guiusers
1条回答
网友
1楼 · 发布于 2024-10-01 17:28:40

问题是datefunction有一个参数agro。但是由于它是一个实例函数,self被绑定到agro。您可以用以下方法解决:

def datefunction(self,agro):
    print(agro)
    agro = int(agro)
    agro = datetime.datetime(agro)
    timeslot = cursor.execute('''SELECT * FROM dates WHERE Date = (?)''',(agro,))
    list1 = list(cursor.fetchall())
    print(list1)

def _show_selection(self, text, bbox):
    """Configure canvas for a new selection."""
    agro = self.selection
    print(self.selection, self.datefunction(agro))
    print(agro)

编辑

如果只需要日期,可以将代码修改为:

^{pr2}$

相关问题 更多 >

    热门问题