hoamon's sandbox
hoamon
hoamon's sandbox is about »
tag cloud
- aix
- ajax
- amazon web service
- amd64
- android
- apache
- apple
- athletes
- bank
- baseball
- bike
- bitbucket
- blog
- bond
- book
- boto
- brooks
- bullshit
- capital gains tax
- car accident
- cds
- chrome
- civil engineering
- cloud computing
- cmclass
- computer
- construction management
- construction site management
- django
- drbl
- e-sun bank
- ec2
- eclipse
- ecryptfs
- education
- election
- english
- environment
- fedora
- feeling
- finance
- firefox
- firegpg
- flash ram
- foclass
- football
- fortran
- freetds
- future
- genetic algorithm
- glassfish
- gnuplot
- google adsense
- google app engine
- google gears
- gpg
- graphviz
- gtalk
- hg
- history
- htc
- html5
- http
- https
- ibm
- iconv
- ie
- iis
- iloveit
- imagemagick
- infomation
- investment
- ipatbles
- ipp2p
- iptables
- ironman
- java
- javascript
- job
- jog
- joke
- jpg
- jquery
- jython
- kde
- knapsack problem
- latex
- learning
- least square method
- levenberg-marquardt method
- libsvm
- linux
- list
- lp
- mac
- marathon
- math
- matlab
- mencoder
- mercurial
- microsoft
- mod_fcgi
- mod_python
- modelviz
- moinmoin
- monte carlo
- movie
- mplayer
- msn
- mssql
- mysql
- netbeans
- netfilter
- newton's method
- nfl
- nginx
- odiogo
- offline system
- open source
- openid
- openoffice
- openssl
- option
- oracle
- p2p
- paypal
- pdf2jpg
- pdftojpg
- perl
- personal
- pgp
- php
- policy
- politic
- postgresql
- power
- program
- python
- python25
- r51
- rds
- realty
- reit
- restructured text
- ruby
- ruby on rails
- s3
- science
- screen
- securities
- seediq bale
- self-management
- shell script
- sis
- skype
- solaris
- something
- ssh
- ssl
- subversion
- sun
- swap
- sybase
- tax
- testcase
- the guass-newton method
- the steepest descent method
- thinkpad
- tomcat6
- tortoisehg
- totero
- trac
- travel
- triathlete
- turbogears
- ubuntu
- un*x
- unix
- vedio
- version control
- vim
- virtual machine
- virtualbox
- vst
- web
- windows
- x86_64
- yahoo
- zfs
- zipcode
- zotera
- zotero
» python2.5真的與2.4有差
在 Ubuntu 上開發程式的環境是 2.5 ,但網頁伺服器是用 Fedora Core 5 ,所以它的版本還在 2.4 ,已經跑過無數個程式了,一直都是相容的,直到今天。
在 2.5 中,抓日期物件如下:
dateobj = datetime.datetime.strptime('2007-1-1', '%Y-%m-%d').date()
但在 2.4 中,卻不能這樣用,因為 datetime.datetime 並沒有 strptime 函式。那麼 strptime 函式在那裡呢!在 time 下。所以要改成如下的寫法:
dateobj = datetime.date(*time.strptime('2007-1-1', '%Y-%m-%d')[:3])
這樣在 2.4 及 2.5 下才能同時正確執行。
不過,我認為 2.5 改得好,因為我一直認為 time 物件是用來抓時間用的,而 datetime 是用作時間日期格式轉換用的, strptime 放在 datetime.datetime 下比較適合。







