Re: [問題] Python 子程序內變數提取至主程序問題
※ 引述《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
03/26 08:09, 1F
推
03/26 08:22,
5年前
, 2F
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
03/26 08:48, 5F
→
03/26 08:49,
5年前
, 6F
03/26 08:49, 6F
推
03/26 14:04,
5年前
, 7F
03/26 14:04, 7F
→
03/26 14:04,
5年前
, 8F
03/26 14:04, 8F
討論串 (同標題文章)
本文引述了以下文章的的內容:
完整討論串 (本文為第 2 之 2 篇):