my problem is the following
i have a ruby script looking like this
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
and i need this script to be translated to python but i am little confused ?
first i made this :
i turned the "module parent" into a python package
i made "module son_1" and "module son_2" like two files inside the package
and finally i defined the last two classed in the
__init__
file of this package (开发者_如何学编程 "module parent" )
my questions are :
is this solution correct ?
and if it is , is there a better one ?
It should look like this on the file system :
- 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
then in actual code in 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()
精彩评论