Movatterモバイル変換
[0]ホーム
import and the WSH
Steve Holdensholden at holdenweb.com
Mon Apr 30 13:24:31 EDT 2001
<cory at c-riddell.com> wrote in messagenews:mailman.988638404.26067.python-list at python.org...> I have a file called msg.pys that contains one function:> def Message(msg):> WScript.Echo(msg)>> I have a second file foo.pys that has two lines:> from msg import Message> Message("hello")>> When I run foo.pys (under wscript.exe), it doesn't work. It pops up> a box saying "NameError: global name 'WScript' is not defined". If I> put the Message() function inside of my test.pys file, everything> works fine.>> Sorry for such a simple question, but this has had me stumped for too> long.>In fact the error *I* get is "no module name 'msg'", because the interpreterisn't looking for .pys files when it processes the import statement. When Irename it to msg.py I get the error you report.Running the test.pys file under wscript.exe, the Windows scripting engine,appears to provide an implicit import of the Wscript namespace that holdsall the Microsoft scripting objects.Because msg.py[s] is imported, the Wscript name is not defined as global tothe module automatically. I haven't found an easy way to get it in there,either, but I'm sure someone will know how.regards Steve
More information about the Python-listmailing list
[8]ページ先頭