Re: [Tutor] Main program confusion

2007-02-19 Thread Dave Kuhlman
On Mon, Feb 19, 2007 at 10:15:08AM -0600, Hazlett, Les wrote:

 
 if __name__ == '__main__':
 import sys,os
 import run
 run.main(['', os.path.basename(sys.argv[0])] + sys.argv[1:])
  
[snip]
 if__name__=='__main__' only runs when this program file is executed.
 
 But, I can't find any reference to a module run and I don't see how the
 run.main([ line casues 
 
 the runTest( function to run.

Step 1 -- Find the run module.  If the import of run succeeds,
you can find out where the module run is installed on your system
by adding a print statement:

import run
print run module:, run

That will show you where Python is finding the run module.  

And, if the import statement is failing, then you are likely to
need to install something in order to execute that sample code.

Once you have found the run module, ...

Step 2 -- Read the source in the run module.  In particular, you
are looking for a function named main.

Dave

-- 
Dave Kuhlman
http://www.rexx.com/~dkuhlman
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Main program confusion

2007-02-19 Thread Luke Paireepinart
Hazlett, Les wrote:

 Hello,

 I am trying to understand some sample code that includes the following 
 for a main program:

 def runTest(frame, nb, log):

 win = TestPanel(nb, log)

 return win

 if __name__ == '__main__':

 import sys,os

 import run

 run.main(['', os.path.basename(sys.argv[0])] + sys.argv[1:])

 I understand that win is an object of the class TestPanel. The class 
 code for TestPanel preceded

 the code which I copied above. The object win clearly is instantiated. 
 I understand how the

 if__name__==’__main__’ only runs when this program file is executed.

 But, I can’t find any reference to a module run and I don’t see how 
 the “run.main([“ line casues

 the “runTest(“ function to run.

I've never heard of this module. Where did this code come from?
Have you tried the code? Either run is some builtin I haven't heard of, 
or the code is in some library/turorial that defines a custom module.
-Luke

 What am I missing?

 Thanks for any help.

 Les Hazlett

 
 The information contained in this communication may be CONFIDENTIAL 
 and is intended only for the use of the recipient(s) named above. If 
 you are not the intended recipient, you are hereby notified that any 
 dissemination, distribution, or copying of this communication, or any 
 of its contents, is strictly prohibited. If you have received this 
 communication in error, please notify the sender and delete/destroy 
 the original message and any copy of it from your computer or paper 
 files.
 

 ___
 Tutor maillist  -  Tutor@python.org
 http://mail.python.org/mailman/listinfo/tutor
   

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Main program confusion

2007-02-19 Thread [EMAIL PROTECTED]

It's wxpython demo's code.
It's necessary to have the run.py in the same path, to make it run, and usually 
also some other files.

--
Tom, http://www.vscripts.net


I've never heard of this module. Where did this code come from?

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Main program confusion

2007-02-19 Thread Kent Johnson
Hazlett, Les wrote:
 Dave,
 
 Thanks for the guidance.  I followed your advice and learned the following:
 
  import run
 
  print run module:, run
 
 run module: module 'run' from 'C:\Python25\Lib\idlelib\run.pyc'

I don't think that is the correct run.py.

 Luke,
 
 I found this mystery main program in the extensive demos in \wsPython2.8 
 Docs and Demos\demo\.  It is
 
 used throughout the demo code – in every demo sample I have looked at. 

There is a run.py in the demo folder, that is the one you get when you 
run the demos.

Kent

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Main program confusion

2007-02-19 Thread Luke Paireepinart
Hazlett, Les wrote:

 Thanks Kent,

 Yes, there is a run.py in the demo folder. I is the one that runs and 
 not the one in the Python25 lib.

 So, I tried to see if I could find it if I previously imported 
 everything that the code imports. It didn’t – see below:

 IDLE 1.2

  import wx

  import sys,os

  import run

  print run module, run

 run module module 'run' from 'C:\Python25\Lib\idlelib\run.pyc'

 

 This has been a good lesson in my learning process. Thanks everyone.

It's not finding it because you're running your code in the directory 
that IDLE is located in!
If you start a Python interpreter in the Demo directory, you will be 
able to find the file you need.
Python searches the current working directory for modules first before 
it does anything else.
Coincidentally, Idle has a module named 'run' and since the 
interpreter's current working directory is IDLE's directory,
it imports that one.
Try using the commands
import os
os.chdir(Path/To/Demo/Directory)

and import the module.
You should get the correct one, then.

HTH,
-Luke
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor