Problem with diferences in executinion
Chris Liechti
cliechti at gmx.net
Mon Jul 22 18:58:16 EDT 2002
samschul at pacbell.net (Samuel Schulenburg) wrote in
news:d7fcf8b4.0207221430.37c26071 at posting.google.com:
> If I execute the following code snipit from Python it executes the way
> I expected it. If I build a standalone exe with McMillan's installer
> the function call to startscsi() function in MaxPTI's __init__() is
> not in scope.
>
> Maxscsi.py is a file that initializes and loads MaxSCSI.dll which
> contains startscsi(). This DLL and Maxscsi.py have been used in other
> McMillan installer programs without any problems. This is the first
> time I have tried to use a class to instanuate the DLL. The whole idea
> behind this program is the desire to embed Python in an exe with some
> added methods to allow non programmers to write an external script
> file and execute it with the exe with the following call:
>
> "MaxPTI MyTest"
>
> Any Help would be appreciated
> Sam Schulenburg
>
> ======================= MaxPTI.py/MaxPTI.exe contains ===============
>
> from Maxscsi import * # import scsi library
> from sys import *
don't do import *. it's fine for some packages spcially designed for such
use. generally it's a source of problem if a module defines names that
conflict with an other module's names.
don't do it with sys and _never_ with os.
> class MaxPTI:
>
> def __init__(self,Headless=0):
> startscsi(1,Headless) # Start scsi initializtion setting
> # Genericflag = 1,and Headless
> initscsi("MaxPTI","physicaldrive",1) # Locate drives
> setshowcdb(0)
> setlogerror(1)
> setpauseonerror(0)
> .....
> .....
> def Function1()
> ....
> ....
>
> def Function2()
> ....
> ....
>
> if __name__ == '__main__':
> a = MaxPTI(1)
> exec("from %s import MyScript"%(argv[1]))
you could do this with "__import__('filename')", "exec" smells bad...
> print 'Start Script'
> MyScript(a)
so you require a function MyScript.MyScript... i would use
"execfile(sys.argv[1])" is executed in the current namespace, so your class
is available right away. no need to have a special named function neither.
> =================== End MaxPTI.py ==============
>
> ================== MyTest.py ===================
> def MyScript(a):
> print a.DeviceTable
> for i in range(a.DeviceTableLength):
> print a.DeviceTable[i]
> print a.DeviceTable[2][a.pSERIALNUM]
> print a.DeviceTable[2][a.pVENDOR]
>
you don't provide detailed information about the failure you experience.
please paste a traceback in such cases. often that says more than a tousand
words ;-)
chris
--
Chris <cliechti at gmx.net>
More information about the Python-list
mailing list