Re: [問題] Python 子程序內變數提取至主程序問題

看板Python作者 (脫俗仙子談無慾)時間5年前 (2019/03/26 07:51), 5年前編輯推噓2(206)
留言8則, 2人參與, 5年前最新討論串2/2 (看更多)
※ 引述《zero06795 (zero06795)》之銘言: : 各位大佬們請幫幫新手小白~我想了好久了 先謝謝大家了 : 請問python主程序運行到觸發副程式(open_file)後,要怎?把副程式變數值提輸出到主程 : def open_file(): : filename = tf.askopenfilename() : if filename != '': : app=xw.App(visible=False) : wb=xw.Book(filename) : sht=wb.sheets[0] : ros=sht.used_range.rows.count : cos=sht.used_range.columns.count : print(ros) : wb.close() : app.quit() : else: : tkinter.messagebox.showerror(title='error', message='no select') 根據通靈的結果 有sheets[0]我猜是excel格式 https://stackoverflow.com/questions/11310248/find-number-of- columns-in-csv-file reader = csv.reader(f,delimiter=d) for row in reader: row += [None] * (3 - len(row)) try: foo, bar, baz = row except ValueError: # Too many values to unpack: too many columns in the CSV raise CSVError("Too many columns in input file.") 類似這種長相的語法才會是正確的 -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 123.194.180.20 ※ 文章網址: https://www.ptt.cc/bbs/Python/M.1553557897.A.623.html ※ 編輯: MOONY135 (111.71.42.209), 03/26/2019 07:57:17

03/26 08:09, 5年前 , 1F
先把內容物印出來再DEBUG
03/26 08:09, 1F

03/26 08:22, 5年前 , 2F
謝謝moony 我在試試你的方法,我目前找到用global可以
03/26 08:22, 2F

03/26 08:22, 5年前 , 3F
解問題謝謝你
03/26 08:22, 3F

03/26 08:47, 5年前 , 4F
所以不是內容物錯誤 而是你想丟到其他地方嗎
03/26 08:47, 4F

03/26 08:48, 5年前 , 5F
看一下 self.吧 因為你只用print
03/26 08:48, 5F

03/26 08:49, 5年前 , 6F
就會聽起來像是print出來的東西是錯的
03/26 08:49, 6F

03/26 14:04, 5年前 , 7F
嗯嗯 我只是想丟到其他地方做為使用,謝謝mooney指導
03/26 14:04, 7F

03/26 14:04, 5年前 , 8F
我在看一下self.的用法。
03/26 14:04, 8F
文章代碼(AID): #1ScMc9OZ (Python)
文章代碼(AID): #1ScMc9OZ (Python)