Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to "verify" your details, making threats, or asking for money, are
spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the
password reset link.
Entire forum
➜ MUSHclient
➜ Python
➜ More questions about python
More questions about python
|
It is now over 60 days since the last post. This thread is closed.
Refresh page
Posted by
| Hairui
China (24 posts) Bio
|
Date
| Sat 03 Jul 2004 06:25 AM (UTC) Amended on Sun 04 Jul 2004 07:51 PM (UTC) by Hairui
|
Message
| I wrote a AddAliases.py file which like this:
def AddSkAlias():
world.AddAlias("skillsAlias","sk","skills",eEnbled,"")
if __name__!="__main__":
world.note("Moudle AddAliases Imported")
Add I tried to import it in main script file like this:
import sys
sys.path.append("c:\fy4") # add the path of AddAliases.py
import AddAliases
AddSkAlias()
But the MUSHClient cried :
Quote:
Traceback (most recent call last):
File "<Script Block >", line 404, in ?
AddSkAlias()
NameError: name 'AddSkAlias' is not defined
Line in error:
AddSkAlias()
Can somebody help me to correct it?Thanks. | Top |
|
Posted by
| Ked
Russia (524 posts) Bio
|
Date
| Reply #1 on Sat 03 Jul 2004 09:24 AM (UTC) Amended on Sat 03 Jul 2004 09:26 AM (UTC) by Ked
|
Message
| You are importing AddAliases, so you need to call the functions contained in it through it's object:
import AddAliases
AddAliases.AddSkAlias()
If you want to make the AddSkAlias() function directly accessible in the importing module then you'll have to do one of the following imports:
import AddAliases.AddSkAlias as AddSkAlias
from AddAliases import AddSkAlias
from AddAliases import *
However, the best way to do it would be the second - from module import function. The first might work also, but the third should be avoided at all costs, especially if you are importing a large module.
| Top |
|
Posted by
| Hairui
China (24 posts) Bio
|
Date
| Reply #2 on Sat 03 Jul 2004 12:41 PM (UTC) Amended on Sat 03 Jul 2004 01:27 PM (UTC) by Hairui
|
Message
| I changed the script like this:
import AddAliases
AddAliases.AddSkAlias()
but i met with the error:
Quote:
Traceback (most recent call last):
File "<Script Block >", line 404, in ?
AddAliases.AddSkAlias()
AttributeError: 'module' object has no attribute 'AddSkAlias'
Line in error:
AddAliases.AddSkAlias()
And then i rechanged the scirpt to:
from Addaliases import AddSkAlias
This time the mushclient cried:
Quote:
Traceback (most recent call last):
File "<Script Block >", line 403, in ?
from Addaliases import AddSkAlias
ImportError: No module named Addaliases
Line in error:
from Addaliases import AddSkAlias
I am so puzzled now.:( | Top |
|
Posted by
| Ked
Russia (524 posts) Bio
|
Date
| Reply #3 on Sat 03 Jul 2004 12:46 PM (UTC) Amended on Sat 03 Jul 2004 12:48 PM (UTC) by Ked
|
Message
| The second attempt obviously failed because you mispelled the module name: Addaliases instead of AddAliases. But why the first one did is beyond me. Maybe the problem is with the function itself - invalid indentation for example? Post the AddAliases module using the [code][/code] here to preserve the formatting. | Top |
|
Posted by
| Hairui
China (24 posts) Bio
|
Date
| Reply #4 on Sat 03 Jul 2004 01:37 PM (UTC) |
Message
| I corrected the second one to:
from AddAliases import AddSkAlias
and the result is:
Quote: Traceback (most recent call last):
File "<Script Block >", line 403, in ?
from AddAliases import AddSkAlias
ImportError: cannot import name AddSkAlias
Line in error:
from AddAliases import AddSkAlias
It seemed this time i met with anthoer kind of error
| Top |
|
Posted by
| Ked
Russia (524 posts) Bio
|
Date
| Reply #5 on Sun 04 Jul 2004 02:38 AM (UTC) |
Message
| The problem has to be with AddAliases module, but I can't say what it is without seeing it first. Something that happens to me sometimes is that I copy a module to Python/Lib to have easier access to it while testing, and then forget about it there and make a different copy of the module somewhere else. The import then fails because Python finds the old module in the /Lib directory before the new one wherever I put it. | Top |
|
Posted by
| Ked
Russia (524 posts) Bio
|
Date
| Reply #6 on Sun 04 Jul 2004 09:56 AM (UTC) |
Message
| Actually, I think I can try to guess what the problem is. That AddSkAlias function in the AddAliases option uses a Mushclient callback. The problem is probably that when the module is being imported, the interpreter looks for an object 'world' in that module's space and fails to find it (since 'world' is only added to the module immediately loaded by Mushclient and doesn't exist in modules loaded by those modules), so the function is skipped. Try rewritting that function like this:
def AddSkAlias(world):
world.AddAlias("skillsAlias", "sk", "skills", "Enabled", "")
That will make 'world' an argument to the function, so the interpreter won't complain. When calling the function you'll need to do:
AddAliases.AddSkAlias(world)
instead of:
| Top |
|
Posted by
| Hairui
China (24 posts) Bio
|
Date
| Reply #7 on Sun 04 Jul 2004 08:54 PM (UTC) Amended on Mon 05 Jul 2004 04:45 AM (UTC) by Hairui
|
Message
| I changed the moudle code to:
def AddSkAlias(world):
world.AddAlias("skillsAlias", "sk", "skills", eEnabled, "")
the main script is :
import sys
sys.path.append("c:\fy4")
import AddAliases
AddAliases.AddSkAlias(world)
And this time the error is :
Quote: Traceback (most recent call last):
File "<Script Block >", line 426, in ?
AddAliases.AddSkAlias(world)
File "C:\FY4\AddAliases.py", line 2, in AddSkAlias
world.AddAlias("skillsAlias", "sk", "skills", eEnabled, "")
File "<COMObject world>", line 2, in AddAlias
COM Error: (0x80020005)
Line in error:
It seemed the object world is a COMObject.But what is a COMObject? | Top |
|
Posted by
| Ked
Russia (524 posts) Bio
|
Date
| Reply #8 on Mon 05 Jul 2004 04:27 AM (UTC) |
Message
| Hmmm, looking at your AddSkAlias function I am seeing the eEnabled flag used there. Are you sure that this flag is available for use in that module? Try substituting it with 1 to see if it works that way. That's the only explanation I can think of really, since it works for me just fine with world.Note(). | Top |
|
Posted by
| Hairui
China (24 posts) Bio
|
Date
| Reply #9 on Mon 05 Jul 2004 04:46 AM (UTC) |
Message
| I have tried to replace the eEnabled with 1
But the result is the same | Top |
|
Posted by
| Hairui
China (24 posts) Bio
|
Date
| Reply #10 on Mon 05 Jul 2004 05:29 AM (UTC) |
Message
| I have found the ultimate reason why I had met with so many errors and been puzzled for these few days.
When I pressed the button of "Reload Script", the MushClient or its python script engine just reloaded the main script in script setting without reloading the script which are imported in the main script.Each time I edited the script to be imported and pressed the "Reload Scirpt", nothing changed to MUSHClient.
Thanks for your help,Ked | Top |
|
Posted by
| Auren
(5 posts) Bio
|
Date
| Reply #11 on Sat 15 Oct 2005 09:45 PM (UTC) |
Message
| Hate to be a thread necromancer, but...
This is my problem as well. I make changes in the imported file, and MUSHclient doesn't re-import it, only the main script. How do I get around that, or force a re-import? As it stands, I have to shutdown MUSH and restart it order for my changes in the imported class to show.
-Auren | Top |
|
Posted by
| Auren
(5 posts) Bio
|
Date
| Reply #12 on Sat 15 Oct 2005 09:53 PM (UTC) |
Message
| Ignore this, I found the thread in the Bug Reports section. These posts never happened *Jedi hand wave*.
-Auren | Top |
|
The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).
To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.
31,943 views.
It is now over 60 days since the last post. This thread is closed.
Refresh page
top