In [45]:
print 'Hello Alex'


Hello Alex

In [46]:
1024*98


Out[46]:
100352

In [47]:
x='Hello '

In [48]:
print x


Hello 

In [49]:
x*4


Out[49]:
'Hello Hello Hello Hello '

In [50]:
listone=[]

In [51]:
newlist


---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-51-2bc650902906> in <module>()
----> 1 newlist

NameError: name 'newlist' is not defined

In [52]:
listone.appendx


---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-52-acdbab5e5fa7> in <module>()
----> 1 listone.appendx

AttributeError: 'list' object has no attribute 'appendx'

In [53]:
listone.append(x)

In [54]:
print x


Hello 

In [55]:
listone.insert[Alex Grace Paul]


  File "<ipython-input-55-b2a7a46cc0e3>", line 1
    listone.insert[Alex Grace Paul]
                            ^
SyntaxError: invalid syntax

In [56]:
listone.append('Alex','Grace','Paul')


---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-56-ed035ab5f032> in <module>()
----> 1 listone.append('Alex','Grace','Paul')

TypeError: append() takes exactly one argument (3 given)

In [57]:
listone=['Alex', 'Grace', 'Paul']

In [58]:
print listone


['Alex', 'Grace', 'Paul']

In [59]:
print x listone


  File "<ipython-input-59-1eb76e041c88>", line 1
    print x listone
                  ^
SyntaxError: invalid syntax

In [60]:
print x+listone


---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-60-73fa20809877> in <module>()
----> 1 print x+listone

TypeError: cannot concatenate 'str' and 'list' objects

In [61]:
print x


Hello 

In [62]:
print x + listone


---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-62-637ec6dc6b9a> in <module>()
----> 1 print x + listone

TypeError: cannot concatenate 'str' and 'list' objects

In [63]:
beg=['Hello']

In [64]:
print beg


['Hello']

In [65]:
print beg+listone


['Hello', 'Alex', 'Grace', 'Paul']

In [66]:
for i in listone:
    print i


Alex
Grace
Paul

In [67]:
print beg+i


---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-67-280620e32a4f> in <module>()
----> 1 print beg+i

TypeError: can only concatenate list (not "str") to list

In [68]:
print beg + i


---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-68-135e104aca67> in <module>()
----> 1 print beg + i

TypeError: can only concatenate list (not "str") to list

In [69]:
print Hello i


  File "<ipython-input-69-ec46c0daac30>", line 1
    print Hello i
                ^
SyntaxError: invalid syntax

In [70]:
print x+i


Hello Paul

In [71]:
print x + i


Hello Paul

In [72]:
for i in listone:
    print x+i


Hello Alex
Hello Grace
Hello Paul

In [73]:
for i in listone:
    print x+i


Hello Alex
Hello Grace
Hello Paul

In [74]:
def message(y):
    return x+i+y

In [75]:
message('As we are all learning we should all be having fun.')


Out[75]:
'Hello PaulAs we are all learning we should all be having fun.'

In [76]:
def message1(y):
    for i in listone:
        return x+i+y

In [77]:
message1('Are we all having fun?')


Out[77]:
'Hello AlexAre we all having fun?'

In [78]:
print message1


<function message1 at 0x23c8aa0>

In [79]:
return message1


  File "<ipython-input-79-860d9229f461>", line 1
SyntaxError: 'return' outside function

In [80]:
h=' Are we all having fun?'

In [81]:
print h


 Are we all having fun?

In [82]:
def letter(y):
    return x+i+h

In [83]:
for i in listone:
    print x+i+h


Hello Alex Are we all having fun?
Hello Grace Are we all having fun?
Hello Paul Are we all having fun?

In [84]:
name=grace


---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-84-65333c0a6693> in <module>()
----> 1 name=grace

NameError: name 'grace' is not defined

In [85]:
name='grace'

In [86]:
print name


grace

In [87]:
print name.title()


Grace

In [88]:
listtwo=['paul','grace','alex','stephanie']

In [89]:
print listtwo


['paul', 'grace', 'alex', 'stephanie']

In [90]:
for i in listtwo:
    print i


paul
grace
alex
stephanie

In [91]:
for i in listtwo:
    print i.title()


Paul
Grace
Alex
Stephanie

In [92]:
quote="Ken Thompson once said, 'One of my most productive days was throwing away 1000 lines of code'"

In [93]:
print quote


Ken Thompson once said, 'One of my most productive days was throwing away 1000 lines of code'

note from william: Check this out for dealing with excel files in python - http://www.python-excel.org/ If you can bring along an example excel file that you would like to take into Python

I mentioned dictionaries. Here's an example:


In [172]:
newdict = {'william': 25, 'joe': 50}
print newdict

In [173]:
newdict.keys()

In [174]:
newdict.items()[0]

Hope that helps and have fun. I'll look into the python excel modules and add some example code. The following is an example of reading data from a xls doc. It's all lists - im sure you can do some super cool stuff with this data. Python makes it easy to sort and develop this further.


In [175]:
import xlrd

In [176]:
workbook = xlrd.open_workbook('address.xls')

In [177]:
print workbook.sheet_names()

In [178]:
worksheet = workbook.sheet_by_name('Sheet1')
num_rows = worksheet.nrows - 1
curr_row = -1
while curr_row < num_rows:
	curr_row += 1
	row = worksheet.row(curr_row)
	print row

In [179]:
worksheet = workbook.sheet_by_name('Sheet1')
num_rows = worksheet.nrows - 1
num_cells = worksheet.ncols - 1
curr_row = -1
while curr_row < num_rows:
	curr_row += 1
	row = worksheet.row(curr_row)
	print 'Row:', curr_row
	curr_cell = -1
	while curr_cell < num_cells:
		curr_cell += 1
		# Cell Types: 0=Empty, 1=Text, 2=Number, 3=Date, 4=Boolean, 5=Error, 6=Blank
		cell_type = worksheet.cell_type(curr_row, curr_cell)
		cell_value = worksheet.cell_value(curr_row, curr_cell)
		print '	', cell_type, ':', cell_value

In [180]:
import xlwt 
workbook = xlwt.Workbook(encoding = 'ascii') 
worksheet = workbook.add_sheet('My Worksheet') 
worksheet.write(0, 0, label = 'omg im writing python code to excel. perfect.') 
worksheet.write(1, 0, label = 'who needs excel when you have python?') 
worksheet.write(2, 0, label = listone)

In [181]:
for n in range(2, 10):
    for x in range(1, n):
        if n % x == 0:
            print n, 'equals', x, '*', n/x
            break

In [182]:
workbook.save('Excel_Workbook.xls')

In [183]:
numb = 6

In [184]:
for wr in range(5):
    worksheet.write(numb, 0, label = 'testing one two thee')
    numb = numb + 1

In [185]:
writebook = xlrd.open_workbook('Excel_Workbook.xls')

In [186]:
print writebook.sheet_names()

In [187]:
shelist = []

In [188]:
firstsheet = writebook.sheet_names()[0]

In [189]:
writesheet = writebook.sheet_by_name(firstsheet)
num_rows = writesheet.nrows - 1
curr_row = -1
while curr_row < num_rows:
	curr_row += 1
	row = writesheet.row(curr_row)
	print row

shelist.append(row)

In [190]:
print shelist

In [191]:
print row[0]

In [192]:
import random

In [193]:
ran = random.randint(5,25)
dran = ran * 2

In [194]:
shetdict = {row[0]: ran, 'blah': dran}
print shetdict

In [ ]: