Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/318.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
将ruby脚本转换为python_Python - Fatal编程技术网

将ruby脚本转换为python

将ruby脚本转换为python,python,Python,我的问题如下 我有一个像这样的ruby脚本 module parent module son_1 ... some code here end module son_2 ... some code here end class one ... some code here end class two ... some code here end end 我需

我的问题如下

我有一个像这样的ruby脚本

module parent

    module son_1
        ... some code here
    end

    module son_2
        ... some code here
    end

    class one
        ... some code here
    end

    class two
        ... some code here
    end

end
我需要把这个脚本翻译成python,但是 我有点困惑

首先我做了这个:

  • 我将“模块父级”转换为python包

  • 我在包中制作了“module son_1”和“module son_2”两个文件

  • 最后,我在这个包的
    \uuuuu init\uuuu
    文件(“模块父级”)中定义了最后两个类

我的问题是:

  • 这个解决方案正确吗

  • 如果是,还有更好的吗


在文件系统上应该是这样的:

- parent/
  ------- __init__.py << empty file or can have classes if you need, that way python will treat parent as a package
  ------- son_1.py
  ------- son_2.py
- test.py

在文件系统上应该是这样的:

- parent/
  ------- __init__.py << empty file or can have classes if you need, that way python will treat parent as a package
  ------- son_1.py
  ------- son_2.py
- test.py

啊!!是的,谢谢你的快速回答啊!!是的,谢谢你的快速回答