首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > perl python >

global name is not defined解决思路

2012-09-12 
global name is not defined#!/usr/bin/python# -*- coding: UTF-8 -*-def quick_sort(numbers, left, rig

global name is not defined
#!/usr/bin/python
# -*- coding: UTF-8 -*-

def quick_sort(numbers, left, right, partion_func = None):
  if left < right: #只有left小于right的时候才有必要排序
  if partion_func:
  middle = partion_func(numbers, left, right)#确定基准位置
  else:
  middle = partion(numbers, left, right)
  qucik_sort(numbers, left, middle - 1)#就在这里报错的!这里的quick_sort为什么被认为没定义?是函数迭代用法吗?
  quick_sort(numbers, middle + 1, right)#

   
def partion(numbers, left, right):#确定基准位置,比它小的移到它左边,大的移到它右边
  i = left
  for j in range(left, right):
  if numbers[j] <= numbers[right]:
  numbers[i], numbers[j] = numbers[j], numbers[i]
  i = i + 1
  numbers[i], numbers[right] = numbers[right], numbers[i]
  return i

def main():
  numbers1 = [12, 1, 65, 11, 24, 22, 98, 10]
  print numbers1
  print "the sorted nums are :"
  quick_sort(numbers1, 0, len(numbers1) - 1)
  print numbers1

   
   

if __name__ == "__main__":
  main()


报错:
NameError: global name 'qucik_sort' is not defined,谁能解释下为什么会这样呀?没搞明白。另外以上是快速排序法。

[解决办法]
def quick_sort(numbers, left, right, partion_func = None):
上下对比一下
qucik_sort(numbers, left, middle - 1)

低级的拼写错误 汗
[解决办法]
def quick_sort[b][/b](numbers, left, right, partion_func = None):
if left < right: #只有left小于right的时候才有必要排序
if partion_func:
middle = partion_func(numbers, left, right)#确定基准位置
else:
middle = partion(numbers, left, right)
qucik_sort[b][/b](numbers, left, middle - 1

拼写错误

热点排行