Python basics
eharetea

Some basic operations in Python.

Python primer.

Date Created:Friday December 29th, 2006 03:41 AM
Date Modified:Wednesday July 30th, 2008 05:36 PM

python -c 'print "hello world"'


IMPORT FUNCTION

Step 1:
make 2 line file.py:

first = 'dan'
last = 'lynch'

Step 2:
using import, you can call the file module

import file
print file.first
//returns dan
print file.last
//returns lynch
file.last
//returns ('lynch')
or

from file import first, last
print first
//returns dan
print last
//returns lynch
print first, last
//returns dan lynch
first, last
//returns ('dan','lynch')


RELOAD FUNCTION
>>> import dfile
>>> reload(dfile)
<module 'dfile' from 'dfile.pyc'>



DIR FUNCTION
make 3 line dfile.py:

first = 'dan'
middle = 'patrick'
last = 'lynch'


>>>import dfile
>>>dir(dfile)
['__builtins__', '__doc__', '__file__', '__name__', 'first', 'last', 'middle']


//creates a list of all frequencies on a piano
L = range(0,88)
dict={}
for x in L:
        p=1.05946306**x
        dict[x+1]=27.5*p

print dict



Downloads:
Download: python.txt 921 B

Please login or Click Here to register for downloads
Creative Commons License
Python basics by Dan Lynch
is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 United States License
Based on a work at www.3daet.com
Permissions beyond the scope of this license may be available at http://www.3daet.com