nick help... about import

Posted by Pkerr on Fri 04 Oct 2013 01:05 AM — 7 posts, 31,495 views.

#0
my english is poor. please understand....

tt.py

def test():
  world.Note('Hello Mushclient')

>> import tt
>> tt.test()

脚本错误
游戏: pkuxkx
执行 1 行 0 列
立即执行
Traceback (most recent call last):
File "<Script Block 4>", line 1, in <module>
tt.test()
File "D:\MUSHclient\tt.py", line 2, in test
world.Note('Hello Mushclient')
NameError: global name 'world' is not defined

出错行:
tt.test()

>> execfile('tt.py')
>> tt.test()

Hello Mushclient


please tell me about import wrong .....thank you

Amended on Fri 04 Oct 2013 01:07 AM by Pkerr
Australia Forum Administrator #1
I am not a Python expert. Maybe someone else can help you?
#2
Nick Gammon said:

I am not a Python expert. Maybe someone else can help you?



ok..
thank you
USA Global Moderator #3
Quote:
world.Note('Hello Mushclient')

The function name is case sensitive. It is supposed to be world.note, not world.Note.
Australia Forum Administrator #4
However "Note" is the correct capitalization.
USA Global Moderator #5
That's not what the note doc says for python. *shrug*
#6
I find a solution...

#filename test.py

Quote:

world = object

def test():
world.Note('Hello Mushclient.')


Input in the game:

>> import test
>> test.world = world #pass namespace 'world'
>> test.test()
Quote:
Hello Mushclient.



My english is poor..... sorry

Thank every body