我的问题是以下
我有一个看起来像这样的红宝石脚本
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”作为包中的两个文件
最后我定义了这个包的__init__
文件中的最后两个(“模块父”)
我的问题是:
此解决方案是否正确?
如果是,那还有更好的吗?
答案 0 :(得分:0)
它应该在文件系统上看起来像这样:
- 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
然后在test.py的实际代码中:
from parent import son_1, son_2, one, two
c = one('something')
b = son_1.something()
#or
import parent
import parent.son_1
import parent.son_2
c = parent.one('something')
b = parent.son_1.something()