Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/kotlin/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在python中使用int(a[I])将数组转换为整数_Python_Arrays_Integer - Fatal编程技术网

如何在python中使用int(a[I])将数组转换为整数

如何在python中使用int(a[I])将数组转换为整数,python,arrays,integer,Python,Arrays,Integer,我在Python3.4中有以下代码: from tkinter import * from time import sleep import pickle, os global sec sec = [0] sec[0] = 0 file2 = open('sec.dat', 'wb') pickle.dump(sec[0], file2) file2.close() global end end = False window = Tk() window.configure(bg='gree

我在Python3.4中有以下代码:

from tkinter import *
from time import sleep
import pickle, os

global sec
sec = [0]
sec[0] = 0
file2 = open('sec.dat', 'wb')
pickle.dump(sec[0], file2)
file2.close()

global end
end = False

window = Tk()
window.configure(bg='green')
c = Canvas(window, width=200, height=200, bg='green')
c.pack()
data = [0]
data[0] = True

file = open('pickle.dat', 'wb')
pickle.dump(sec, file)
file.close()

sec[0] = 0

def pause():
    btnpause.configure(state=DISABLED)
    btnunpause.configure(state=NORMAL)
    pause = True

    file3 = open('pause.dat','wb')
    pickle.dump(pause,file3)
    file3.close()


def stop():
    data[0] = False
    file = open('pickle.dat', 'wb')
    pickle.dump(data,file)
    file.close()


def unpause():
    pass


def start(event):
    btn.configure(state = NORMAL)
    btnpause.configure(state = NORMAL)
    WIDTH = 200
    HEIGHT = 200

    file2 = open('sec.dat','rb')
    sec = pickle.load(file2)
    file2.close()

    while True:
        key = event.keysym
        sleep(1)
        sec[0] += 1
        min1 = sec * 60
        print(min1)
        print(counter)
        time_text = c.create_rectangle(WIDTH, HEIGHT, -WIDTH, -HEIGHT, fill='green')
        time_text = c.create_text(WIDTH/2, HEIGHT/2, text=str(sec), fill='white', font=('Droid Serif', 16))
        window.update()
        file = open('pickle.dat', 'rb')
        data = pickle.load(file)
        file.close()

        if data[0] == False:
             break

c.bind_all('<Key>', start)
btn = Button(window, text='stop', command=stop, bg='lightblue')
btnpause = Button(window, text='pause', command=pause, bg='lightblue')
btnunpause = Button(window,text='unpause', command=unpause, bg='lightblue')
btnpause.pack()
btn.pack()
btnunpause.pack()
btnunpause.configure(state=DISABLED)
btn.configure(state=DISABLED)
btnpause.configure(state=DISABLED)

我试图将数组设置为int,但它出现了错误。

试图将数组设置为int。如果我正确理解了您的问题,您需要的是:

lst = ["1", "2", "3"]
print map(int, lst)
这给了你

[1, 2, 3]

在第8行中,转储的是整数,而不是数组。该整数在第42行中作为
sec
被解吸

简单地写下:

sec += 1

一切都应该正常。

就像一句评论,“sec[0]=0”根本不会修改
sec
,因为
sec=[0]
做的事情完全一样。你不需要第二行。这使它变短了:)但它并没有解决问题!不过非常感谢!我认为您需要删除所有与此问题无关的代码,这样会更容易提供帮助。尝试只包含错误发生时出现的行,以及在这些行中初始化变量的所有行。我曾想过这样做,但我认为如果每个人都知道发生了什么,代码将得到更多响应。谢谢,但它只计算1,然后停止这是因为您总是重新加载
sec
sec += 1