python MODULES
<p>Jan 27, 2013 04:25 PM
 
>>> import sys    # imports al the system modules
 
>>> sys.path   #  shows the paths to the system modules as a list of paths.
note:  all on the default path:  C:\Python27
 
['', 'C:\Python27\Lib\idlelib', 'C:\Python27\python27.zip', 'C:\Python27\DLLs', 'C:\Python27\lib', 'C:\Python27\lib\plat-win', 'C:\Python27\lib\lib-tk', 'C:\Python27', 'C:\Python27\lib\site-packages']
 
>>> <b>import mat</b>h  # import is a reserved word  (a command)e the math fx are.
0.5403023058681397
>>> from math import cos
>>> cos(1)
0.5403023058681397
 
>>><b> from math import cos</b>
>>> from math import sin
>>> sin(1)2 + cos(1)2
0.9999999999999999
 
Keep directory Python27 open and on monitor 4;  when you run a module, you may see
a file like  Hello.pyc   (a compiled version of the file)... you can safely delete it.
 
Note: <b>do not name modules with the same name as functions</b>... 
it will cause ENDLESS CONFUSION;
 
here's a script in the module Hello.py  
 
a='Sean'
 
def Hellospec():
   print 'Hello', a, ":now go away blablablabbity"
*
 
to open the module you can do  
import Hello... then, to invoke a function, you must do
 
>>> from Hello import Hellospec  OR
you could invoke Hellospec  by 
 
>>><b> Hello.Hellospec()</b>  OR just do
 
>>><b> from Hello import * </b>   # there<b> * is a wildcard</b>, meaning  import all the functions from Hello.
 
>>> # the way Sean works is to create a module for each project... module1.py
and to test it, then hit f5 from within module 1  (ie from the script window)
 
>>> # the other way is to work within the interpreter, and to import...
>>>  import Module1   ...# no parens  or
>>>  reload (Module1)  ... # reload does take parens...
 
 
 
 
 
 
 </p>