[Home] [Downloads] [Search] [Help/forum]

Gammon Forum

See www.mushclient.com/spam for dealing with forum spam. Please read the MUSHclient FAQ!

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  Python
. . -> [Subject]  More questions about python
Home  |  Users  |  Search  |  FAQ
Username:
Register forum user name
Password:
Forgotten password?

More questions about python

It is now over 60 days since the last post. This thread is closed.     [Refresh] Refresh page


Posted by Hairui   China  (24 posts)  [Biography] 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.
[Go to top] top

Posted by Ked   Russia  (524 posts)  [Biography] 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.

[Go to top] top

Posted by Hairui   China  (24 posts)  [Biography] 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.:(
[Go to top] top

Posted by Ked   Russia  (524 posts)  [Biography] 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.
[Go to top] top

Posted by Hairui   China  (24 posts)  [Biography] 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
[Go to top] top

Posted by Ked   Russia  (524 posts)  [Biography] 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.
[Go to top] top

Posted by Ked   Russia  (524 posts)  [Biography] 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:

AddAliases.AddSkAlias()
[Go to top] top

Posted by Hairui   China  (24 posts)  [Biography] 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?
[Go to top] top

Posted by Ked   Russia  (524 posts)  [Biography] 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().
[Go to top] top

Posted by Hairui   China  (24 posts)  [Biography] 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
[Go to top] top

Posted by Hairui   China  (24 posts)  [Biography] 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
[Go to top] top

Posted by Auren   (5 posts)  [Biography] 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
[Go to top] top

Posted by Auren   (5 posts)  [Biography] 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
[Go to top] 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.


7,794 views.

It is now over 60 days since the last post. This thread is closed.     [Refresh] Refresh page

Go to topic:           Search the forum


[Go to top] top

Quick links: MUSHclient. MUSHclient help. Forum shortcuts. Posting templates. Lua modules. Lua documentation.

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.

[Home]


Written by Nick Gammon - 5K   profile for Nick Gammon on Stack Exchange, a network of free, community-driven Q&A sites   Marriage equality

Comments to: Gammon Software support
[RH click to get RSS URL] Forum RSS feed ( https://gammon.com.au/rss/forum.xml )

[Best viewed with any browser - 2K]    [Hosted at FutureQuest]