[問題] def的問題

看板Python作者 (逢甲阿法)時間12年前 (2013/06/17 17:22), 編輯推噓0(004)
留言4則, 3人參與, 最新討論串1/2 (看更多)
大家好 ~ 有個問題希望大家可以幫我解答一下~@@ def move(): def move_limit(): xmin=1 xmax=2 ymin=1 ymax=2 self.bnd(xmin,xmax,ymin,ymax) def bnd(self,*arg): spatial_limit=(sqrt((arg[1]-arg[0])^2+(arg[3]-arg[2])^2))*(1/3) tolerance=spatial_limit/8 return spatial_limit,tolerance print spatial_limit print tolerance 上面是我的程式碼 可是當我執行之後 他會報錯 NameError: global name 'spatial_limit' is not defined 請問這樣子要怎麼處理呢~@@?? -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 140.112.63.202

06/17 17:30, , 1F
spatial_limit沒有定義,bnd()裡面的spatial_limit外面
06/17 17:30, 1F

06/17 17:30, , 2F
是看不到的喔
06/17 17:30, 2F

06/17 17:32, , 3F
不好意思 那我要怎麼樣才能在外面找到這個呢~@@??
06/17 17:32, 3F

06/17 17:56, , 4F
你定義了函數,沒有執行它阿...
06/17 17:56, 4F
文章代碼(AID): #1HljL30q (Python)
討論串 (同標題文章)
文章代碼(AID): #1HljL30q (Python)