TypeError:'>' ' int'的实例之间不受支持和' str'

时间:2017-03-08 13:42:44

标签: python python-3.x

我正在编写代码以获取日期(日期和年份)的输入以及他们想要重复任务的次数(它的用途)。 我想使用for循环作为边界。 代码:

def addtimeslot():
    times = int(times_repeated.get())
    print(times_repeated.get())
    variable_end.get()
    day = variable_day.get()
    month = variable_month.get()
    year = variable_year.get()
    fulldateadd = datetime.date(year, month, day)
    name1 = str(name.get())
    minute = int('00')
    second = int('00')
    hour1 = variable_st.get()
    starttimehour = str(datetime.time(hour1,minute,second))
    hour2 = variable_end.get()
    endtimehour = str(datetime.time(hour2,minute,second))
    for i in range(0 , times):
        fulldateadd = datetime.date(year, month, day)
        cursor.execute( '''INSERT INTO dates (Date, Name, Start, End) VALUES( ?,?,?,? );''', (fulldateadd , name1, starttimehour, endtimehour))
        day = int(day) + 7
        if day > '31':
            month = int(month) + 1

我收到此错误:

TypeError: '>' not supported between instances of 'int' and 'str' 

1 个答案:

答案 0 :(得分:3)

由于问题不应在评论中得到解答,我将提供@AChampion的解决评论:

您已day int day = int(day) + 7 day > 31:,因此测试应为31,即与'31'的比较字符串var serverBaseUrl = 'http://localhost:4000'; app.factory('socket', function (socketFactory) { try { var myIoSocket = io.connect(serverBaseUrl, { 'reconnection delay': 1000, 'reconnection limit': 1000, 'force new connection': true }); var socket = socketFactory({ ioSocket: myIoSocket }); return socket; } catch (e) { console.log('System : Socket server is out of service. We will look into this and bring it back up.'); return null; } });