2
我将一块Ruby移植到Python。除了以下内容,我移植了大部分代码。我无法弄清楚它的功能。将Ruby移植到Python
变量休息将是表示电话号码的字符串。它只有真正的
country_handler = splitter_mapping[i][presumed_cc]
我发现令人困惑。我意识到我可以在python中使用kwargs,但我不太确定。
任何想法?
module Phony
class CountryCodes
attr_reader :splitter_mapping
def split_cc rest
presumed_cc = ''
1.upto(3) do |i|
presumed_cc << rest.slice!(0..0)
country_handler = splitter_mapping[i][presumed_cc]
return [country_handler, presumed_cc, rest] if country_handler
end
# This line is never reached as CCs are in prefix code.
end
什么是'splitter_mapping'? – delnan
它看起来像你从一个字符串开始,它试图找到该字符串(长度为1到3)的前缀,它存在于分割器映射中(它看起来是一个国家代码哈希值到某种值的排列,排列按国家代码的长度)。不知道为什么 –
对不起,遗漏了splitter_mapping定义的源文件可以在这里找到 - https://github.com/floere/phony/blob/master/lib/phony/country_codes.rb – David