william

wcmckee python notebook

In [ ]:
print  'hello worl'
In [22]:
print 5 + 5
10
In [23]:
x = 'Hi Tony!'
In [24]:
print x
Hi Tony!
In [25]:
from random import randint as ri
In [26]:
ri(0,20)
Out[26]:
7
In [29]:
newlist = ['hello', 'test', 'number']
In [30]:
newtuple = ('hello', 'google')
In [38]:
cat = {'teewfewhtwertjygfgfdgesting': 'omg', 'blah': 5}
In [45]:
print cat.setdefault('testing')
omg
In [56]:
def upstr(mystring):
    upstrn = mystring.upper
    return upstrn()
In [57]:
upstr('testing one two three')
Out[57]:
'TESTING ONE TWO THREE'
In [58]:
def cent(p1, p2, p3 = 'fred'):
    return cent
In [63]:
cent('hello', 'test')
<function cent at 0x20fc7d0>
In [65]:
h = 'test'
In [70]:
for h in range(5):
    print h
    print 'test'
0
test
1
test
2
test
3
test
4
test
In [ ]:
import random

wcmckee. Notes on Python

In [46]:
import sys
In [47]:
import os
import subprocess
import os.path

We got IPython Notebook running on all the machines at the cafe. It connects to the raspberry pi. There is a git repo that I have connected to github - hamipy. On Wednesday I plan to get everyone that wants to use the notebook. Teaching git would be worth it also. I showed git to many people at unity classes but it would be even better to show to the python class. I will be interested in seeings the numbers for this week - So the plan for this week:

  • git -ipython notebook
  • ??

During the first class we had about 12 people show up. It was a mixture of beginners and advance. Majority of the beginners were from Hamilton PC computer club. I had several members of WLUG attend - including the vice president. With so many people showing up I was very overwelmed. I didn't have the notebooks setup but i encourged people to use the ipython. Some peope choose to write in a text document and run. Sadly the internet at the cafe had reset eariler in the day - this caused problems with the connection.

Tonight I had my 2nd python class. We had about 8 people this time. Less than last week - but i felt the place was still very crowded - and hot. I had asked Bruce about perhaps setting up outside with laptops. Most people have laptops so we could setup desks and laptops outside. It just gets too hot inside. For people that don't have a laptop - they have two linux laptops - hp. They run Puppy Linux but the OS that they use doesn't really matter since we will just be using the pi notebook or ssh. I could also setup my laptops with this also. I brought along two of my laptops but they were not used. Next week ill bring them again, just in case. It would be good to do some 1 on 1 (or small groups) with some of the kids. They ask Bruce for the laptops but he tends to say no. I'm sure he would say yes if they agreed to sit down with me and work through some python exercises

next week i plan on having a more structued class. We need a break for 15 - 20 mins. At the start of the class I plan on doing a demo. Maybe show people about creating .py files and running them. Many people are just working down ipython notebook and running the same print hello. Show more of the basics of ipython - different text, SAVE,

setup cron job to push at midnight. add to save a pop up that asks for commit message

ask what git repo you want to edit and open it

go to website - opens login - see a list of git repos that you have access to. Click and opens up repo.

everyones station could have ipython notebook running on half. Otherwise have two terminals open. First ina text doc - other ipython. The terminals will have screen on them with me controlling it (or bruce) Will get people outside with their laptops and they can just connect to the notebook over network. This means they wont need to worry about the OS on their system. I am not going to help anyone with Windows problems, they can do everything on the pi

It's good I have started using markdown more. I should keep this going as i don't write like i use to but i don't like to write blog posts. I really just want to archieve my blogs and work on something fresh. I think treating the ipython notebook as a blog could suit me well. Lets see how it goes.

Run bash in ipython (danger danger!)

control raspberry pi lights from python

week 3 thoughts

last night i had my third python class. sadly only three people showed up (not including Bruce). I decided to setup on the lawn outside the computer room. This worked well as it was a nice evening and it was too hot inside. Being outside meant we attracted some local teenagers over that we were able to show some Python to. Toara was one who made a notebook and wrote a little code. When starting people off I get them to use IPython Notebook and create a new Notebook, renaming it too thier name. Since I am awful with names I can just reference the notebook. Tony also did excellent work with dict and creating functions. John sadly did some work but didn't save. He is still understanding strings I believe but can't comment due to not saving. Ian and John worked away together and I hanged out with Bruce. We walked accross to the skatepark and then went back inside the cafe. The normal afterschool kids filled the cafe and were playing Urban Terror. I've loaded the computers with some Humble Bundle games to play. They don't run well and freeze often. FTL works fine but Airforte doesn't. It would be great to get some better machines and we could put Steam on the machines. Anyway, lets see who shows for next weeks Python class

This week i am tired and feeling sick. We have one new person which is awesome. Lowrance is working with him and showing him a few things. I met him when I was at Mr Greens home during the weekend. For the past several weeks people have worked outside. This is nice because inside gets too hot. It's quite windy tonight so packed up outside and came in. Ian had a go with flask tonight. it is so simple to get something running. I really need to do more stuff with it - and write python code for it. In the past when I have used Flask I have

In [137]:
%%bash
cp -b /var/www/install6 /home/pi/learnpython
In [138]:
def chandir(dirmove):
    changed = os.chdir(dirmove)
    return changed
    print os.curdir
In [139]:
chandir('/home/pi/learnpython')
In [*]:
%%bash
git add .
git commit -m ('notes for week 3 added')
In [141]:
%%bash
git push origin
fatal: could not read Username for 'https://github.com': No such device or address

This is likely wrong

In [142]:
ls
adon.ipynb        hooks/         main.py         site
Alex .ipynb       ian.ipynb      main.py.save    StephM.ipynb
branches/         info/          main.py.save.1  test/
Bruce.ipynb       install6       main.py.save.2  TK Hello World.ipynb
config            install6~      objects/        Untitled5.ipynb
d                 John T.ipynb   PeterW.ipynb    william.ipynb
Dele.ipynb        lance.ipynb    pybac.py        wp-post.py.save
description       learnpy.ipynb  Readme.ipynb
HEAD              learnpy.py     README.md
helloworld.ipynb  LICENSE        refs/
In [143]:
sys.getsizeof('pi')
Out[143]:
39
In [144]:
sys.getfilesystemencoding()
Out[144]:
'UTF-8'

how about it does a git add commit after each save and a push at midnight

In [1]:
import subprocess
In [2]:
subprocess.call('ls')
Out[2]:
0
In [3]:
def cmdchk(ls):
    check = subprocess.check_output(ls)
    return check
In [7]:
docmd = cmdchk('ls')
In [8]:
listdoc = []
In [9]:
for d in docmd:
    print d
    listdoc.append(d)
    
A
l
e
x
 
.
i
p
y
n
b


B
r
u
c
e
.
i
p
y
n
b


B
r
u
c
e
.
p
y


D
e
l
e
.
i
p
y
n
b


E
x
c
e
l
_
W
o
r
k
b
o
o
k
.
x
l
s


E
x
c
e
l
_
w
o
r
k
b
o
o
k
.
x
l
s


H
E
A
D


J
o
h
n
 
T
.
i
p
y
n
b


L
I
C
E
N
S
E


P
e
t
e
r
W
.
i
p
y
n
b


R
E
A
D
M
E
.
m
d


R
e
a
d
m
e
.
i
p
y
n
b


S
t
e
p
h
M
.
i
p
y
n
b


T
K
 
H
e
l
l
o
 
W
o
r
l
d
.
i
p
y
n
b


T
o
n
y
.
i
p
y
n
b


U
n
t
i
t
l
e
d
0
.
i
p
y
n
b


U
n
t
i
t
l
e
d
1
.
i
p
y
n
b


U
n
t
i
t
l
e
d
2
.
i
p
y
n
b


U
n
t
i
t
l
e
d
3
.
i
p
y
n
b


U
n
t
i
t
l
e
d
4
.
i
p
y
n
b


U
n
t
i
t
l
e
d
5
.
i
p
y
n
b


U
n
t
i
t
l
e
d
6
.
i
p
y
n
b


a
d
d
r
e
s
s
.
x
l
s


a
d
o
n
.
i
p
y
n
b


b
r
u
c
e
.
i
p
y
n
b


c
o
n
f
i
g


d


d
a
t
a


d
e
s
c
r
i
p
t
i
o
n


e
x
c
e
l
d
o
c
.
x
l
s


e
x
f
c
e
l
d
o
c
.
x
l
s


f
r
a
n
k
i
e
.
i
p
y
n
b


h
e
l
l
o
w
o
r
l
d
.
i
p
y
n
b


h
o
o
k
s


i
a
n
.
i
p
y
n
b


i
n
f
o


i
n
s
t
a
l
l
6


i
n
s
t
a
l
l
6
~


l
a
n
c
e
.
i
p
y
n
b


l
e
a
r
n
p
y
.
i
p
y
n
b


l
e
a
r
n
p
y
.
p
y


m
a
i
n
.
p
y


m
a
i
n
.
p
y
.
s
a
v
e


m
a
i
n
.
p
y
.
s
a
v
e
.
1


m
a
i
n
.
p
y
.
s
a
v
e
.
2


p
y
b
a
c
.
p
y


p
y
e
x
c
e
l
.
i
p
y
n
b


p
y
e
x
c
e
l
.
p
y


s
i
t
e


t
e
s
t


t
e
s
t
.
i
p
y
n
b


t
o
a
r
a
.
i
p
y
n
b


w
i
l
l
i
a
m
.
i
p
y
n
b


w
i
l
l
i
a
m
.
p
y


w
p
-
p
o
s
t
.
p
y
.
s
a
v
e


In [10]:
print listdoc
['A', 'l', 'e', 'x', ' ', '.', 'i', 'p', 'y', 'n', 'b', '\n', 'B', 'r', 'u', 'c', 'e', '.', 'i', 'p', 'y', 'n', 'b', '\n', 'B', 'r', 'u', 'c', 'e', '.', 'p', 'y', '\n', 'D', 'e', 'l', 'e', '.', 'i', 'p', 'y', 'n', 'b', '\n', 'E', 'x', 'c', 'e', 'l', '_', 'W', 'o', 'r', 'k', 'b', 'o', 'o', 'k', '.', 'x', 'l', 's', '\n', 'E', 'x', 'c', 'e', 'l', '_', 'w', 'o', 'r', 'k', 'b', 'o', 'o', 'k', '.', 'x', 'l', 's', '\n', 'H', 'E', 'A', 'D', '\n', 'J', 'o', 'h', 'n', ' ', 'T', '.', 'i', 'p', 'y', 'n', 'b', '\n', 'L', 'I', 'C', 'E', 'N', 'S', 'E', '\n', 'P', 'e', 't', 'e', 'r', 'W', '.', 'i', 'p', 'y', 'n', 'b', '\n', 'R', 'E', 'A', 'D', 'M', 'E', '.', 'm', 'd', '\n', 'R', 'e', 'a', 'd', 'm', 'e', '.', 'i', 'p', 'y', 'n', 'b', '\n', 'S', 't', 'e', 'p', 'h', 'M', '.', 'i', 'p', 'y', 'n', 'b', '\n', 'T', 'K', ' ', 'H', 'e', 'l', 'l', 'o', ' ', 'W', 'o', 'r', 'l', 'd', '.', 'i', 'p', 'y', 'n', 'b', '\n', 'T', 'o', 'n', 'y', '.', 'i', 'p', 'y', 'n', 'b', '\n', 'U', 'n', 't', 'i', 't', 'l', 'e', 'd', '0', '.', 'i', 'p', 'y', 'n', 'b', '\n', 'U', 'n', 't', 'i', 't', 'l', 'e', 'd', '1', '.', 'i', 'p', 'y', 'n', 'b', '\n', 'U', 'n', 't', 'i', 't', 'l', 'e', 'd', '2', '.', 'i', 'p', 'y', 'n', 'b', '\n', 'U', 'n', 't', 'i', 't', 'l', 'e', 'd', '3', '.', 'i', 'p', 'y', 'n', 'b', '\n', 'U', 'n', 't', 'i', 't', 'l', 'e', 'd', '4', '.', 'i', 'p', 'y', 'n', 'b', '\n', 'U', 'n', 't', 'i', 't', 'l', 'e', 'd', '5', '.', 'i', 'p', 'y', 'n', 'b', '\n', 'U', 'n', 't', 'i', 't', 'l', 'e', 'd', '6', '.', 'i', 'p', 'y', 'n', 'b', '\n', 'a', 'd', 'd', 'r', 'e', 's', 's', '.', 'x', 'l', 's', '\n', 'a', 'd', 'o', 'n', '.', 'i', 'p', 'y', 'n', 'b', '\n', 'b', 'r', 'u', 'c', 'e', '.', 'i', 'p', 'y', 'n', 'b', '\n', 'c', 'o', 'n', 'f', 'i', 'g', '\n', 'd', '\n', 'd', 'a', 't', 'a', '\n', 'd', 'e', 's', 'c', 'r', 'i', 'p', 't', 'i', 'o', 'n', '\n', 'e', 'x', 'c', 'e', 'l', 'd', 'o', 'c', '.', 'x', 'l', 's', '\n', 'e', 'x', 'f', 'c', 'e', 'l', 'd', 'o', 'c', '.', 'x', 'l', 's', '\n', 'f', 'r', 'a', 'n', 'k', 'i', 'e', '.', 'i', 'p', 'y', 'n', 'b', '\n', 'h', 'e', 'l', 'l', 'o', 'w', 'o', 'r', 'l', 'd', '.', 'i', 'p', 'y', 'n', 'b', '\n', 'h', 'o', 'o', 'k', 's', '\n', 'i', 'a', 'n', '.', 'i', 'p', 'y', 'n', 'b', '\n', 'i', 'n', 'f', 'o', '\n', 'i', 'n', 's', 't', 'a', 'l', 'l', '6', '\n', 'i', 'n', 's', 't', 'a', 'l', 'l', '6', '~', '\n', 'l', 'a', 'n', 'c', 'e', '.', 'i', 'p', 'y', 'n', 'b', '\n', 'l', 'e', 'a', 'r', 'n', 'p', 'y', '.', 'i', 'p', 'y', 'n', 'b', '\n', 'l', 'e', 'a', 'r', 'n', 'p', 'y', '.', 'p', 'y', '\n', 'm', 'a', 'i', 'n', '.', 'p', 'y', '\n', 'm', 'a', 'i', 'n', '.', 'p', 'y', '.', 's', 'a', 'v', 'e', '\n', 'm', 'a', 'i', 'n', '.', 'p', 'y', '.', 's', 'a', 'v', 'e', '.', '1', '\n', 'm', 'a', 'i', 'n', '.', 'p', 'y', '.', 's', 'a', 'v', 'e', '.', '2', '\n', 'p', 'y', 'b', 'a', 'c', '.', 'p', 'y', '\n', 'p', 'y', 'e', 'x', 'c', 'e', 'l', '.', 'i', 'p', 'y', 'n', 'b', '\n', 'p', 'y', 'e', 'x', 'c', 'e', 'l', '.', 'p', 'y', '\n', 's', 'i', 't', 'e', '\n', 't', 'e', 's', 't', '\n', 't', 'e', 's', 't', '.', 'i', 'p', 'y', 'n', 'b', '\n', 't', 'o', 'a', 'r', 'a', '.', 'i', 'p', 'y', 'n', 'b', '\n', 'w', 'i', 'l', 'l', 'i', 'a', 'm', '.', 'i', 'p', 'y', 'n', 'b', '\n', 'w', 'i', 'l', 'l', 'i', 'a', 'm', '.', 'p', 'y', '\n', 'w', 'p', '-', 'p', 'o', 's', 't', '.', 'p', 'y', '.', 's', 'a', 'v', 'e', '\n']
In [11]:
listdoc.reverse()
In [12]:
listdoc.count('y')
Out[12]:
43
In [13]:
revnow = listdoc.count('y')
In [14]:
print revnow
43
In [15]:
print listdoc
['\n', 'e', 'v', 'a', 's', '.', 'y', 'p', '.', 't', 's', 'o', 'p', '-', 'p', 'w', '\n', 'y', 'p', '.', 'm', 'a', 'i', 'l', 'l', 'i', 'w', '\n', 'b', 'n', 'y', 'p', 'i', '.', 'm', 'a', 'i', 'l', 'l', 'i', 'w', '\n', 'b', 'n', 'y', 'p', 'i', '.', 'a', 'r', 'a', 'o', 't', '\n', 'b', 'n', 'y', 'p', 'i', '.', 't', 's', 'e', 't', '\n', 't', 's', 'e', 't', '\n', 'e', 't', 'i', 's', '\n', 'y', 'p', '.', 'l', 'e', 'c', 'x', 'e', 'y', 'p', '\n', 'b', 'n', 'y', 'p', 'i', '.', 'l', 'e', 'c', 'x', 'e', 'y', 'p', '\n', 'y', 'p', '.', 'c', 'a', 'b', 'y', 'p', '\n', '2', '.', 'e', 'v', 'a', 's', '.', 'y', 'p', '.', 'n', 'i', 'a', 'm', '\n', '1', '.', 'e', 'v', 'a', 's', '.', 'y', 'p', '.', 'n', 'i', 'a', 'm', '\n', 'e', 'v', 'a', 's', '.', 'y', 'p', '.', 'n', 'i', 'a', 'm', '\n', 'y', 'p', '.', 'n', 'i', 'a', 'm', '\n', 'y', 'p', '.', 'y', 'p', 'n', 'r', 'a', 'e', 'l', '\n', 'b', 'n', 'y', 'p', 'i', '.', 'y', 'p', 'n', 'r', 'a', 'e', 'l', '\n', 'b', 'n', 'y', 'p', 'i', '.', 'e', 'c', 'n', 'a', 'l', '\n', '~', '6', 'l', 'l', 'a', 't', 's', 'n', 'i', '\n', '6', 'l', 'l', 'a', 't', 's', 'n', 'i', '\n', 'o', 'f', 'n', 'i', '\n', 'b', 'n', 'y', 'p', 'i', '.', 'n', 'a', 'i', '\n', 's', 'k', 'o', 'o', 'h', '\n', 'b', 'n', 'y', 'p', 'i', '.', 'd', 'l', 'r', 'o', 'w', 'o', 'l', 'l', 'e', 'h', '\n', 'b', 'n', 'y', 'p', 'i', '.', 'e', 'i', 'k', 'n', 'a', 'r', 'f', '\n', 's', 'l', 'x', '.', 'c', 'o', 'd', 'l', 'e', 'c', 'f', 'x', 'e', '\n', 's', 'l', 'x', '.', 'c', 'o', 'd', 'l', 'e', 'c', 'x', 'e', '\n', 'n', 'o', 'i', 't', 'p', 'i', 'r', 'c', 's', 'e', 'd', '\n', 'a', 't', 'a', 'd', '\n', 'd', '\n', 'g', 'i', 'f', 'n', 'o', 'c', '\n', 'b', 'n', 'y', 'p', 'i', '.', 'e', 'c', 'u', 'r', 'b', '\n', 'b', 'n', 'y', 'p', 'i', '.', 'n', 'o', 'd', 'a', '\n', 's', 'l', 'x', '.', 's', 's', 'e', 'r', 'd', 'd', 'a', '\n', 'b', 'n', 'y', 'p', 'i', '.', '6', 'd', 'e', 'l', 't', 'i', 't', 'n', 'U', '\n', 'b', 'n', 'y', 'p', 'i', '.', '5', 'd', 'e', 'l', 't', 'i', 't', 'n', 'U', '\n', 'b', 'n', 'y', 'p', 'i', '.', '4', 'd', 'e', 'l', 't', 'i', 't', 'n', 'U', '\n', 'b', 'n', 'y', 'p', 'i', '.', '3', 'd', 'e', 'l', 't', 'i', 't', 'n', 'U', '\n', 'b', 'n', 'y', 'p', 'i', '.', '2', 'd', 'e', 'l', 't', 'i', 't', 'n', 'U', '\n', 'b', 'n', 'y', 'p', 'i', '.', '1', 'd', 'e', 'l', 't', 'i', 't', 'n', 'U', '\n', 'b', 'n', 'y', 'p', 'i', '.', '0', 'd', 'e', 'l', 't', 'i', 't', 'n', 'U', '\n', 'b', 'n', 'y', 'p', 'i', '.', 'y', 'n', 'o', 'T', '\n', 'b', 'n', 'y', 'p', 'i', '.', 'd', 'l', 'r', 'o', 'W', ' ', 'o', 'l', 'l', 'e', 'H', ' ', 'K', 'T', '\n', 'b', 'n', 'y', 'p', 'i', '.', 'M', 'h', 'p', 'e', 't', 'S', '\n', 'b', 'n', 'y', 'p', 'i', '.', 'e', 'm', 'd', 'a', 'e', 'R', '\n', 'd', 'm', '.', 'E', 'M', 'D', 'A', 'E', 'R', '\n', 'b', 'n', 'y', 'p', 'i', '.', 'W', 'r', 'e', 't', 'e', 'P', '\n', 'E', 'S', 'N', 'E', 'C', 'I', 'L', '\n', 'b', 'n', 'y', 'p', 'i', '.', 'T', ' ', 'n', 'h', 'o', 'J', '\n', 'D', 'A', 'E', 'H', '\n', 's', 'l', 'x', '.', 'k', 'o', 'o', 'b', 'k', 'r', 'o', 'w', '_', 'l', 'e', 'c', 'x', 'E', '\n', 's', 'l', 'x', '.', 'k', 'o', 'o', 'b', 'k', 'r', 'o', 'W', '_', 'l', 'e', 'c', 'x', 'E', '\n', 'b', 'n', 'y', 'p', 'i', '.', 'e', 'l', 'e', 'D', '\n', 'y', 'p', '.', 'e', 'c', 'u', 'r', 'B', '\n', 'b', 'n', 'y', 'p', 'i', '.', 'e', 'c', 'u', 'r', 'B', '\n', 'b', 'n', 'y', 'p', 'i', '.', ' ', 'x', 'e', 'l', 'A']
In [16]:
subprocess.check_output('ping', 'artcontrol.me')
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-16-70ff00c02a78> in <module>()
----> 1 subprocess.check_output('ping', 'artcontrol.me')

/usr/lib/python2.7/subprocess.pyc in check_output(*popenargs, **kwargs)
    535     if 'stdout' in kwargs:
    536         raise ValueError('stdout argument not allowed, it will be overridden.')
--> 537     process = Popen(stdout=PIPE, *popenargs, **kwargs)
    538     output, unused_err = process.communicate()
    539     retcode = process.poll()

/usr/lib/python2.7/subprocess.pyc in __init__(self, args, bufsize, executable, stdin, stdout, stderr, preexec_fn, close_fds, shell, cwd, env, universal_newlines, startupinfo, creationflags)
    627         self._child_created = False
    628         if not isinstance(bufsize, (int, long)):
--> 629             raise TypeError("bufsize must be an integer")
    630 
    631         if mswindows:

TypeError: bufsize must be an integer
In [17]:
subprocess.sys.copyright
Out[17]:
'Copyright (c) 2001-2012 Python Software Foundation.\nAll Rights Reserved.\n\nCopyright (c) 2000 BeOpen.com.\nAll Rights Reserved.\n\nCopyright (c) 1995-2001 Corporation for National Research Initiatives.\nAll Rights Reserved.\n\nCopyright (c) 1991-1995 Stichting Mathematisch Centrum, Amsterdam.\nAll Rights Reserved.'
In [179]:
 
In [180]:
os.fork()
Out[180]:
31239
In [181]:
myenv = os.environ
In [182]:
print myenv.items
<bound method _Environ.items of {'LANG': 'en_NZ.UTF-8', 'TERM': 'xterm-color', 'SHELL': '/bin/bash', 'XDG_SESSION_COOKIE': '8fcd93f95efb16bcf8c8407952d098f2-1392766423.446500-2010730714', 'LANGUAGE': 'en_NZ:en', 'SHLVL': '1', 'PAGER': 'cat', 'OLDPWD': '/home/pi', 'CLICOLOR': '1', 'PWD': '/home/pi/learnpython', 'LOGNAME': 'pi', 'USER': 'pi', 'MAIL': '/var/mail/pi', 'PATH': '/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games', 'HOME': '/home/pi', '_': '/usr/bin/ipython', 'GIT_PAGER': 'cat'}>
In [30]:
import random
In [37]:
samp = random.sample(listdoc, 9)
In [38]:
print samp
['e', 'i', 'x', 'D', 'l', 'W', 'y', 't', 'i']
In [39]:
samp.index('c')
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-39-6418fde61f07> in <module>()
----> 1 samp.index('c')

ValueError: 'c' is not in list
In [40]:
import string
In [41]:
string.join(samp)
Out[41]:
'e i x D l W y t i'
In [45]:
strsamp = string.joinfields(samp)
In [47]:
string.lower(strsamp)
Out[47]:
'e i x d l w y t i'
In [53]:
string.zfill(strsamp, 0)
Out[53]:
'e i x D l W y t i'
In [54]:
string.split(strsamp, ' ')
Out[54]:
['e', 'i', 'x', 'D', 'l', 'W', 'y', 't', 'i']
In [56]:
string.strip(strsamp, 'i ')
Out[56]:
'e i x D l W y t'
In [57]:
import time
In [59]:
time.localtime()
Out[59]:
time.struct_time(tm_year=2014, tm_mon=3, tm_mday=2, tm_hour=8, tm_min=37, tm_sec=13, tm_wday=6, tm_yday=61, tm_isdst=0)
In [60]:
time.time()
Out[60]:
1393749454.653164
In [63]:
time.gmtime()
Out[63]:
time.struct_time(tm_year=2014, tm_mon=3, tm_mday=2, tm_hour=8, tm_min=37, tm_sec=57, tm_wday=6, tm_yday=61, tm_isdst=0)
In [64]:
time.asctime()
Out[64]:
'Sun Mar  2 08:37:59 2014'
In [65]:
time.gmtime()
Out[65]:
time.struct_time(tm_year=2014, tm_mon=3, tm_mday=2, tm_hour=8, tm_min=38, tm_sec=7, tm_wday=6, tm_yday=61, tm_isdst=0)
In [68]:
time.timezone
Out[68]:
0
In [71]:
curtime = time.ctime()
In [72]:
print curtime
Sun Mar  2 08:57:57 2014
In [74]:
strcurtime = string.split(curtime, ' ')
In [80]:
strcurtime
Out[80]:
['2014', '08:57:57', '2', '', 'Mar', 'Sun']
In [91]:
listcurtime = list(strcurtime)
In [92]:
listcurtime.append('test')
In [93]:
print listcurtime
['2014', '08:57:57', '2', '', 'Mar', 'Sun', 'test']
In [95]:
str(listcurtime)
Out[95]:
"['2014', '08:57:57', '2', '', 'Mar', 'Sun', 'test']"
In [118]:
incurtime = (listcurtime.index('Mar'))
In [119]:
listcurtime[incurtime]
Out[119]:
'Mar'
In [74]:
listsamp = listcurtime + samp
---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-74-42fab39d7507> in <module>()
----> 1 listsamp = listcurtime + samp

NameError: name 'listcurtime' is not defined
In [75]:
newlistsame = list(listsamp)
---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-75-b14aaa250d74> in <module>()
----> 1 newlistsame = list(listsamp)

NameError: name 'listsamp' is not defined
In [76]:
newlists
---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-76-e9492d890428> in <module>()
----> 1 newlists

NameError: name 'newlists' is not defined
In [77]:
x = 'chanceis'
In [78]:
print x
chanceis
In [79]:
print x * 10
chanceischanceischanceischanceischanceischanceischanceischanceischanceischanceis
In [81]:
y = 'william'
In [82]:
print y
william
In [84]:
print x + ' ' + y
chanceis william
In [85]:
d = ' is cool!'
In [86]:
print x + d
chanceis is cool!
In [87]:
print y + d
william is cool!
In [89]:
for n in range(5):
    print y + d
william is cool!
william is cool!
william is cool!
william is cool!
william is cool!
In [*]:
x = 'william'
print 5 *  12
In [1]:
thislist = ['first', 'second', 'third']
In [2]:
thisdict = {'one': 'blah', 'twoz': 'haha'}  
In [3]:
print thislist
['first', 'second', 'third']
In [4]:
print thisdict
{'twoz': 'haha', 'one': 'blah'}
In [ ]:
print 

Comments

Comments powered by Disqus