代码从2.4转换为2.7

时间:2014-07-03 06:47:38

标签: python panda3d

我有2.4的东西,我希望将其转换为2.7,但问题是,我每次都会在这个字符串中崩溃:

MovieCasts = tuple(lambda [outmost-iterable]: for x in [outmost-iterable]:
SyntaxError: invalid syntax

有对应关系
tuple(lambda [outmost-iterable]: for x in [outmost-iterable]:

for 2.7?

以下是代码本身的一部分:

MovieCasts = tuple(lambda [outmost-iterable]: for x in [outmost-iterable]):
AvatarType()(range(6)))

3 个答案:

答案 0 :(得分:3)

1)括号(最后没有关闭。

MovieCasts = tuple(lambda [outmost-iterable]: for x in [outmost-iterable]:
                  ^                                                       ^

2)变量不应包含连字符(outmost-iterable)。

3)迭代for循环时没有进行任何操作。

for x in [outmost-iterable]

应该是

x for x in [outmost-iterable]

4)不确定你是否真的想使用[ ]。这样做只需要迭代一个元素。

a = [1,2,3]
b = [x for x in [a]] # b = [[1,2,3]]
c = [x for x in a]   # c = [1,2,3]

答案 1 :(得分:0)

你必须关闭元组(。请更正文字。

您可以将数据转换为元组。

MovieCasts = tuple(lambda outmost_iterable: x for x in range(10))

答案 2 :(得分:0)

def tup(a): return tuple(i for i in a)

def tup(a): return tuple(a)
print tup(range(10))
#output (0, 1, 2, 3, 4, 5, 6, 7, 8, 9)

代码

tuple([outmost-iterable])

我认为不需要使用lambda