9. ipython
$
ipython
Python
2.7
(r27:82500,
Nov
7
2010,
14:17:28)
Type
"copyright",
"credits"
or
"license"
for
more
informaXon.
IPython
0.13.2
-‐-‐
An
enhanced
InteracXve
Python.
?
-‐>
IntroducXon
and
overview
of
IPython's
features.
%quickref
-‐>
Quick
reference.
help
-‐>
Python's
own
help
system.
object?
-‐>
Details
about
'object',
use
'object??'
for
extra
details.
In
[1]:
10. In
[1]:
import
random
In
[2]:
random.choice?
Type:
instancemethod
String
Form:<bound
method
Random.choice
of
<random.Random
object
at
0x10183f820>>
File:
/usr/local/Cellar/python/2.7/
lib/python2.7/random.py
Definition:
random.choice(self,
seq)
Docstring:
Choose
a
random
element
from
a
non-‐empty
sequence.
11. In
[3]:
random.choice??
Type:
instancemethod
String
Form:<bound
method
Random.choice
of
<random.Random
object
at
0x10183f820>>
File:
/usr/local/Cellar/python/2.7/
lib/python2.7/random.py
Definition:
random.choice(self,
seq)
Source:
def
choice(self,
seq):
"""Choose
a
random
element
from
a
non-‐empty
sequence."""
return
seq[int(self.random()
*
len(seq))]
#
raises...
12. ls
とか
cd
とか
In
[4]:
ls
bin/
lib/
share/
include/
man/
src/
In
[5]:
cd
src
/Users/torufurukawa/works/pyfes201307/src
13. コマンド実行
In
[6]:
!ps
PID
TTY
TIME
CMD
2739
8ys000
0:00.84
-‐zsh
6059
8ys000
0:01.13
/Users/torufurukawa/
works/pyfes201307/bin/python2.7
/Us....
14. In
[7]:
!redis-‐server
[6080]
27
Jul
12:59:29
#
Warning:
no
config
file
specified,
using
the
default
config.
In
order
to
specify
a
config
file
use
'redis-‐server
/path/to/
redis.conf'
[6080]
27
Jul
12:59:29
*
Server
started,
Redis
version
2.4.10
[6080]
27
Jul
12:59:29
*
The
server
is
now
ready
to
accept
connecXons
on
port
6379
17. from
urllib
import
urlopen
#
使ってない
def
add(a,
b
):
#
カッコのまわりに不要スペース
addressess
=
None
#
スペルミス
return
a
+
b
18. pep8
$
pep8
spam.py
spam.py:2:1:
E302
expected
2
blank
lines,
found
0
spam.py:2:13:
E202
whitespace
before
')'
19. pyflakes
$
pyflakes
spam.py
spam.py:1:
'urlopen'
imported
but
unused
spam.py:3:
local
variable
'addressess'
is
assigned
to
but
never
used
20. flake8
$
flake8
spam.py
spam.py:1:1:
F401
'urlopen'
imported
but
unused
spam.py:2:1:
E302
expected
2
blank
lines,
found
0
spam.py:2:13:
E202
whitespace
before
')'
spam.py:3:1:
F841
local
variable
'addressess'
is
assigned
to
but
never
used
30. ...
def
test2():
x
=
{'foo':
'bar',
'hoge':
'fuga'}
y
=
{'foo':
'bar',
'hoge':
'wozozo'}
>
assert
x
==
y
E
assert
{'foo':
'bar',
'hoge':
'fuga'}
==
{'foo':
'bar',...ge':
'wozozo'}
E
Hiding
1
idenXcal
items,
use
-‐v
to
show
E
Differing
items:
E
{'hoge':
'fuga'}
!=
{'hoge':
'wozozo'}