2017-07-20 4 views
-1

私はPythonでcsvに行を書き込もうとしています。私のコードはこのようになります。しかし、これらの変数はローカルなので書き込まれませんか?どうすればいいのですか?ありがとうございました!エラーが表示されず、csvに行が書き込まれません。 そして、私はそれをmacのpycharmで動かすと動作しますが、私はそれをWindows上のexeにした後、行を書きません。グローバル変数をローカルで使用するにはどうすればよいですか?

types=[] 
row=[] 
col=[] 
image_number=[] 
def click(event): 
    global rectangle 
    global image_list1 
    types.append(v.get()) 
    row.append(event.x) 
    col.append(event.y) 
    filename = image_list1[0] 
    image_number.append(filename) 
    x1, y1 = (event.x -3), (event.y- 3) 
    x2, y2 = (event.x + 3), (event.y + 3) 
    rectangle=w.create_rectangle(x1, y1, x2, y2,fill=color[v.get()-1],outline="") 
if image_length: 
    root.tk() 
    w.bind("<Button-1>", click) 
    root=mainloop() 
    d.writerows(zip(image_number, types, row, col)) 

答えて

1

これはreturn文は何のためにあるのかです:

types=[] 
row=[] 
col=[] 
image_number=[] 
def click(event): 
    global rectangle 
    global image_enum 
    global image_list1 
    types.append(v.get()) 
    row.append(event.x) 
    col.append(event.y) 
    filename = image_list1[0] 
    image_number.append(filename) 
    return (image_number, types, row, col) 
if image_length: 
    image_number, types, row, col = click(event) 
    d.writerows(zip(image_number, types, row, col)) 

それとも、空想になりたい場合は:もちろん

if image_length: 
    d.writerows(zip(*click(event))) 

、あなたが最初に定義されたイベントを必要とします!

+0

あなたは 'd.writerows(zip(* click(event)))' – Zizouz212

+0

を書くことができます: – perigon

+0

あなたは2秒で私を打ち負かしています...: – Zizouz212

関連する問題