python for a real programer
DESCRIPTION
pythonoccTRANSCRIPT
-
1. HappyToWritetheBook2. Basic-Preparation3. Basic-Ediotr4. start-5. Python6. ipython7. Play-8. setup.py
TableofContents
-
BETAVersionofthebook.
OO
-
DeveloperArchitectOperationPackageManagerReleaseManagerQualityAssuranceTestDevelopment
ubutntuvim,terminalvim,
tim@ubuntu:~$vim
Theprogram'vim'canbefoundinthefollowingpackages:*vim*vim-gnome*vim-tiny*vim-athena*vim-gtk*vim-noxTry:sudoapt-getinstall
google,
vimubuntuvim,ubuntu
sudoapt-getinstallvim
terminalvim
ubutntuapt-get,apt-cache
-
apt-cachesearch
canonicalubuntuubuntu
pythonshell
timdeMacBook-Pro:python-for-a-real-programertim$pythonPython2.7.6(default,Sep92014,15:04:36)[GCC4.2.1CompatibleAppleLLVM6.0(clang-600.0.39)]ondarwinType"help","copyright","credits"or"license"formoreinformation.>>>a=u''>>>au'\u4e2d\u6587'>>>
u'\u4e2d\u6587'unicode
pythonuniout,pythonshell
apt-cacheuniout
unioutuniout
sudopipinstalluniout
pippython
sudoapt-getinstallpython-pip
ubuntuapt-get
-
Python
Pythonpip.
uniout.
,
timdeMacBook-Pro:python-for-a-real-programertim$sudopipinstallunioutDownloading/unpackingunioutDownloadinguniout-0.3.7.tar.gzRunningsetup.pyegg_infoforpackageuniout
warning:nopreviously-includedfilesmatching'*.pyc'foundanywhereindistributionInstallingcollectedpackages:unioutRunningsetup.pyinstallforuniout
warning:nopreviously-includedfilesmatching'*.pyc'foundanywhereindistributionSuccessfullyinstalledunioutCleaningup...
successfully
sudoPermissiondenied.
error:/Library/Python/2.7/site-packages/_uniout.py:Permissiondenied
----------------------------------------Cleaningup...
-
Command/usr/bin/python-c"importsetuptools;__file__='/private/var/folders/7r/0m7j9n750xn_hfh73nly7sk00000gn/T/pip_build_tim/uniout/setup.py';exec(compile(open(__file__).read().replace('\r\n','\n'),__file__,'exec'))"Storingcompletelogin/Users/tim/Library/Logs/pip.log
root.local/lib/python2.7/site-packages/
pipinstall--useruniout
uniout,Pythonshell.
>>>exit()
pythonshell
Python2.7.6(default,Sep92014,15:04:36)[GCC4.2.1CompatibleAppleLLVM6.0(clang-600.0.39)]ondarwinType"help","copyright","credits"or"license"formoreinformation.>>>importuniout>>>a=u''>>>au''
apt-get,apt-cache,PythonPython
pythonvirtualenv.
sudopipinstallvirtualenv
ubuntupythonubuntupipubuntu
virtualenv
virtualenvvenv
virtualenv:
VirtualEnvironment
-
sourcevenv/bin/activate
virtualenv,terminalvirtualenvbashshell
deactivate
virtualenv
virtualenvvirtualenv
/tmp/virtualenvvirtualenvpycuber
virtualenvpythonshell,pycuber
-
Python
:VIM,SublimeText3IDE:Eclipse+Pydev,PyCharm
IDE
)
IDEIDE
vim
:
vimtest.py
vimviminsertmodenormalMode.
normalmode,,
i,insertmode.
#-*-coding:utf-8-*-importrandompossible=[u'',u'',u'']printrandom.choice(possible)
normalemode(esc)ZZ()
bashshell:
pythontest.py
vimvimpython
IDE
VIMQuickTips
-
vim~/.vimrc
.vimrcinsertmode,normalmodelZZ
:settabstop=4:setshiftwidth=4:setexpandtab
test.py
vim
vimpycharmPyCharmvimplugin,
Project,first.pyfirst.py
pycharmkeyenter,pycharm
a=list()a.append(10)a.append(3)a.append(9)printaa.sort()printa
Run
10,3,9
pycharm
list()listx()a.appendb.appednappendpigg=10
pycharm
PyCharm
-
Python2.7
Pythonisaneasytolearn,powerfulprogramminglanguage.Ithasefficienthigh-leveldatastructuresandasimplebuteffectiveapproachtoobject-orientedprogramming.Pythonselegantsyntaxanddynamictyping,togetherwithitsinterpretednature,makeitanideallanguageforscriptingandrapidapplicationdevelopmentinmanyareasonmostplatforms.
ObjectOriented
PythonDon'tRepeatYourself),
numbers=list()numbers.append(10)numbers.append(3)numbers.append(9)printnumbers#[10,3,9]numbers.sort()printnumbers#[3,9,10]
list()listnumbers
numbersmethodlistappendmethod.listlistsortmethod.numbers.
classdef
class
classButton:'nothinghereisonlycomment'
button=Button()
Python:ScriptLanguage
start-
-
(class)Button,button=Button()button
classButton:defclick(self):print"Iamclicked"
a=Button()a.click()#Iamclicked
classButton:defclick(self):print"{0}isclicked".format(self.name)
powerup_button=Button()powerup_button.name='powerup'powerup_button.click()#powerupisclicked
powerdown_button=Button()powerdown_button.name='powerdown'powerdown_button.click()#powerdownisclicked
,
classButton:def__init__(self,name):self.name=name
defclick(self):print"{0}isclicked".format(self.name)
mute=Button('mute')mute.click()#muteisclicked
Button('mute')instance,__init__,instance,'mute'
-
PowerPointppt
class
classButton(object):def__init__(self,name):self.name=name
defclick(self):print"{0}isclicked".format(self.name)
classTV(object):def__init__(self):self.mute=Button('mute')self.power=Button('power')
tv=TV()tv.mute.click()#muteisclickedtv.power.click()#powerisclicked
DjangoGirl
Reference
-
ipython,
bpythondreampypythonconsolePythonShell,
pipinstallipython
commandlineipython
Python2.7.6(default,Sep92014,15:04:36)Type"copyright","credits"or"license"formoreinformation.
IPython2.3.1--AnenhancedInteractivePython.?->IntroductionandoverviewofIPython'sfeatures.%quickref->Quickreference.help->Python'sownhelpsystem.object?->Detailsabout'object',use'object??'forextradetails.
In[1]:
a=10a
10a10
1+1a*2a**3
?
a**0.5
a="tim"a.upper()
Python
list
-
a=['1','2','3']a
"tim"[1,2,3]list:
a=['1','2','3']b=list('123')a==b
tutorial,DjangoGirlsTaipei
deffib(order):ifordern
Combination,nr
Recursion
-
defanonymous(x):returnx**2+1
defintegrate(fun,start,end):step=0.1intercept=startarea=0whileintercept