将Ruby移植到Python

问题描述 投票:2回答:1

我正在将Ruby移植到Python。除以下内容外,我已移植了大部分代码。我真的无法弄清楚它的作用。

变量rest将是代表电话号码的字符串。它只有[>]

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

我正在将Ruby移植到Python。除以下内容外,我已移植了大部分代码。我真的不知道它做什么。变量rest将是代表电话的字符串...

python ruby porting
1个回答
1
投票

嗯,从代码和Frederick Cheung的评论中,我认为翻译会像这样:

© www.soinside.com 2019 - 2024. All rights reserved.