我剛剛開始使用Python for Google App Engine。我有一個文件notifications.py,在這裏,我將創建User.py中指定的用戶實體。我怎樣才能做到這一點?我試過import users
,但我得到一個錯誤:NameError: global name 'User' is not defined
引用Python中的另一個類
0
A
回答
2
哦,我只是有這個問題太!在此之後:
import users
得到User
你必須鍵入users.User
另外,您可以導入它喜歡:
from users import User
然後引用它只是User
,但如果你做這種方式您必須按照以下格式列出您想要的用戶的所有位:
from users import User, Somthingelse, Somthing
如果你感覺超級懶惰,你不想在鍵入任何前綴或列出所有你想要的東西,只需鍵入
from users import *
0
# module.py
foo = "bar"
# main.py
import module
print foo # This will cause error because foo is not located in the current namespace
print module.foo # this will print "bar"
from module import foo # But you can import contents of module "module" in the current namespace
1
而不是
import users
做
from users import User
相關問題
- 1. Python - 類在引用前引用另一個類
- 2. Python使用另一個類中的一個類的對象
- 3. Java:如何引用類中的一個類,但引用另一個元素?
- 4. C# - 引用類型引用另一個引用類型
- 5. 在另一個aspx.cs類中引用一個aspx.cs類?
- 6. 在另一個類中引用一個類按鈕動作
- 7. 接口引用另一個接口,但引用C#中的另一個類的類
- 8. 如何引用Python中另一個類的方法中的函數「返回」?
- 9. 引用另一個類的文檔類中的變量
- 10. 引用另一個類中的類的錯誤
- 11. 如何正確引用另一個類?
- 12. 如何在另一個類中引用一個字符串?
- 13. 如何引用Ruby中同一類的另一個對象?
- 14. mixin的引用如何傳遞給python中的另一個mixin?
- 15. 引用一個靜態的NSString * const的另一個類
- 16. 如何從Actionscript 3.0中的另一個類實例引用一個類實例?
- 17. 在Python中從一個類訪問變量到另一個類
- 18. 如何在java中引用另一個類中的變量?
- 19. 在繼承屬性中引用另一個類中的對象
- 20. 引用變量與python中的另一個變量
- 21. 在另一個類中引用類實例
- 22. Python 2.7:如何在另一個類中使用一個類的對象?
- 23. 如何保存對另一個類中的對象的引用?
- 24. 使用Web2py/Python在SQLite中引用另一個表格
- 25. Python中,從另一個類調用類函數
- 26. 使用類在另一個類中設置參數 - Python
- 27. 引用另一個func中的func(swift)
- 28. 引用XML中的另一個元素
- 29. 如何引用另一個類中的Sprite對象屬性?
- 30. 在rails中引用屬於另一個模型類的字段
http://docs.python.org/tutorial/modules html的 – 2012-04-15 02:58:22