0

Google App Engine 用の Python を使い始めたばかりです。私はファイル notifications.py を持っています。ここでは、users.py で指定された User エンティティを作成します。これどうやってするの?を試しましimport usersたが、エラーが発生します:NameError: global name 'User' is not defined

4

3 に答える 3

2

ああ、私もこの問題を抱えていました!あなたがした後:

import users

取得Userするには、入力する必要がありますusers.User

または、次のようにインポートすることもできます。

from users import User

次にそれをそのまま参照しUserますが、このようにすると、必要なユーザーからのすべてのビットを次の形式でリストする必要があります。

from users import User, Somthingelse, Somthing

あなたが非常に怠け者で、プレフィックスを入力したくない、または必要なものをすべてリストしたくない場合は、次のように入力してください。

from users import *
于 2012-04-15T03:47:27.970 に答える
1

それ以外の

import users

行う

from users import User
于 2012-04-15T03:15:10.497 に答える
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

http://docs.python.org/tutorial/modules.html

于 2012-04-15T03:08:23.807 に答える