[問題] 關於Valutaion的問題

看板Python作者 (frank.k)時間4年前 (2020/12/10 19:12), 4年前編輯推噓3(303)
留言6則, 3人參與, 4年前最新討論串1/1
Python新手想請教各位前輩一個問題 https://i.imgur.com/uI38WGX.jpg
我想要文字合併的方式來print出原Z5_xpath所代表的/html/body/div[3]/div/div[2]/di 但合併後的a是Z5_xpath無法print出/html/body/div[3]/div/div[2]/div/div/div/div 想請問要如何修改呢?感謝 -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 27.52.35.68 (臺灣) ※ 文章網址: https://www.ptt.cc/bbs/Python/M.1607598769.A.E9C.html ※ 編輯: fenfenk (27.52.35.68 臺灣), 12/10/2020 19:14:18

12/10 21:16, 4年前 , 1F
你這樣是印字串 不是變數 可以參考eval但慎用
12/10 21:16, 1F
感恩 ※ 編輯: fenfenk (42.76.176.23 臺灣), 12/10/2020 23:48:48

12/11 11:56, 4年前 , 2F
aﴽ揑ocals()[course_code+'_xpath']
12/11 11:56, 2F

12/11 11:56, 4年前 , 3F
aﴽ揑ocals()[course_code+'_xpath']
12/11 11:56, 3F

12/11 11:56, 4年前 , 4F
這樣
12/11 11:56, 4F

12/11 11:56, 4年前 , 5F
a=locals()[course_code+'_xpath']
12/11 11:56, 5F

12/11 17:30, 4年前 , 6F
print(eval(a))
12/11 17:30, 6F
文章代碼(AID): #1VqWAnwS (Python)
文章代碼(AID): #1VqWAnwS (Python)