colorramps = re.split("#ramp\[([0-9a-fA-F]{6})\](.+?)#rampend\[([0-9a-fA-F]{6})\]", message)
colorramps.reverse()
if len(colorramps) > 1:
starttext = colorramps.pop()
starttext = starttext.replace("$message", getSaveString(text))
starttext = starttext.replace("$playername", getSaveString(username), 1)
complete = [starttext]
while len(colorramps):
startcolor = getColor(colorramps.pop())
colors = filter(None, re.split("#over\[([0-9a-fA-F]{6})\]", colorramps.pop()))
middletxt = colors.pop()
endcolor = getColor(colorramps.pop())
middletxt = middletxt.replace("$message", getSaveString(text))
middletxt = middletxt.replace("$playername", getSaveString(username), 1)
middletxt = middletxt.decode("utf")
if len(colors) > 0:
colors = map(getColor, colors)
colors.append(endcolor)
middletxt = rangeOverColors(middletxt, startcolor, colors)
else:
middletxt = getRangeString(middletxt, startcolor, endcolor)
middletxt = middletxt.encode("utf")
complete.append(middletxt)
endtext = colorramps.pop()
endtext = endtext.replace("$message", getSaveString(text))
endtext = endtext.replace("$playername", getSaveString(username), 1)
complete.append(endtext)
message = "".join(complete)
else:
message = message.replace("$message", getSaveString(text))
message = message.replace("$playername", getSaveString(username), 1)
return message
大家好! 我在replaceColorRamps中进入第128行 middletxt = colors.pop()
AttributeError:' filter'对象没有属性' pop'
我将此代码用于python 2.5,现在将其移植到3.4 ..
有人可以帮助我
答案 0 :(得分:10)
你是否在Python 3中运行它?
在Python 2.7 filter()
中返回了list
,其中.pop()
具有filter()
功能
在Python 3.x filter
中返回一个.pop()
可迭代对象,而不是。
在您可以从Python 3中的filter
colors = list(colors)
之前,您需要将其转换为列表。所以添加例如。
colors = filter(...)
在# Remove leading spaces
DT[, ITEM := gsub("^\\s*([^\\s].*)$", "\\1", ITEM, perl = TRUE)]
# Remove trailing spaces
DT[, ITEM := gsub("^(.*[^\\s])\\s*$", "\\1", ITEM, perl = TRUE)]
# Substitute center spaces and slash with underscore
DT[, ITEM := gsub("\\s+|/", "_", ITEM, perl = TRUE)]
# UPPER Case
DT[, ITEM := toupper(ITEM)]
# Text cleanup
DT["CARS" == ITEM, ITEM := "CAR"]
DT["TYRE" == ITEM, ITEM := "TIRE"]
DT["BRAKE_PADS" == ITEM, ITEM := "BREAKS"]
DT["CHAINS" == ITEM, ITEM := "CHAIN"]
DT["BICYCLE" == ITEM, ITEM := "BIKE"]
# Numeric substitutions
DT[,
METRIC_1_CLASS :=
ifelse(
"A" == METRIC_1_CLASS
, 100
, ifelse(
"B" == METRIC_1_CLASS
, 1000
, ifelse(
"C" == METRIC_1_CLASS
, 10000
, NA
)))]
行之后。在Python 2.7中,这将没有任何效果,因此您的代码将继续在那里工作。请参阅this question for more information 和these docs。