求教一个python代码

juvryp 2015-01-06 12:52:06
代码如下:
def print_lol(the_list,level):
for each_item in the_list:
if isinstance(each_item,list):
print_lol(each_item,level+1)
else:
for tab_stop in range(level):
ptint("\t",end='')
print(each_item)


并把此代码构建发布后,调用:
import nester

movies = ['the holy grail',1975,'terry jones & terry gilliam',91,
['graham chapman',['michael palin','john cleese',
'terry gilliam','eric idle','terry jones']]]

nester.print_lol(movies,1) //调用

确报错:Traceback (most recent call last):
File "movie.py", line 5, in <module>
nester.print_lol(movies,1)
TypeError: print_lol() takes 1 positional argument but 2 were given

我明明在函数定义了两个参数,为什么这里说我只定义了一个?







...全文
1067 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
you5522393 2016-04-01
  • 打赏
  • 举报
回复
定义方法上面加一个@staticmethod 试一下呢
simbapc 2016-03-24
  • 打赏
  • 举报
回复
你的ptint都写错了,是print,另外
print("\t", end='')
这个没问题,因为在print函数中(python3.4)中有这个参数。
DarkChampion 2015-01-06
  • 打赏
  • 举报
回复
你把完整代码贴出来看看, 我看了下没问题,除了这句
ptint("\t",end='')
print_lol不是类的成员函数吧,如果是的话,定义需要加上self
李察德-泰森 2015-01-06
  • 打赏
  • 举报
回复
TypeError: print_lol() takes 1 positional argument but 2 were given nester.print_lol 需要一个参数,但是你给了两个

37,721

社区成员

发帖
与我相关
我的任务
社区描述
JavaScript,VBScript,AngleScript,ActionScript,Shell,Perl,Ruby,Lua,Tcl,Scala,MaxScript 等脚本语言交流。
社区管理员
  • 脚本语言(Perl/Python)社区
  • IT.BOB
加入社区
  • 近7日
  • 近30日
  • 至今

试试用AI创作助手写篇文章吧