私は自分のモジュールを書く方法を理解しようとしていますが、簡単なモジュールを作成しようとしていますが、__init__ファイルの使い方は分かりません。自分のモジュールでファイルをインポート/コールする方法は?
だから今、私は "のhelloWorld" というパッケージがあり、その構造は次のようになります。
helloWorld
__init__.py
helloWorldFile.py
helloBonjourFile.py
、これらは、各ファイルの内容は以下のとおりです。
__init__.py:
from helloWorldFile import helloWorldClass
helloWorldFile.py:
import helloBonjourFile
class helloWorldClass():
def __init__(self):
self.keyword = 'Hello Beautiful World'
def hello(self):
print self.keyword
helloBonjourFile.run()
helloBounjourFile.py:
import helloWorld
reload(helloWorld)
helloWorld.helloWorldClass().hello()
:
def run():
print 'Bonjour Mon Ami!'
だから、アイデアは、私はそれが "helloWorldFile" から "helloBonjourFile" であるものは何でも実行したいので、私はPythonシェルでこれを実行してみてください、です
それは「こんにちは美しい世界」の部分の罰金を出力しますが、その後、私はエラーを取得しておいてください。
AttributeError: 'module' object has no attribute 'run'
私は私が間違ってこれについてつもりはかなり確信して、どのようにD o「helloWorld」と「helloBonjour」の両方の内容を正しく実行しますか?私は考え出し
私はまた、可能な場合は、「helloBonjour」に引数を渡す方法を把握したいと思います...