python中常用日期操作总结
http://hbszyandong.javaeye.com/blog/377199
# -*- coding: utf-
8
-*-
from datetime import
datetime
from datetime import
date
from time import
strftime
from time import
strptime
from datetime import
timedelta
def getCurDate():
""
"Return value of the date"
""
return
date(datetime.now().year,datetime.now().month,datetime.now().day)
def getCurTime():
""
"Return value of the datetime"
""
return
datetime.now()
def converDateTimeToStr(cdate,format='%Y-%m-%d %H:%M:%S'
):
""
"
Convert datetime to String
cdata parameter must be the datetime or date of
Return value of the date string format(%Y-%m-%d)
""
"
sdate = None
try
:
sdate = cdate.strftime(format)
except:
raise ValueError
return
sdate
def converDateToDateTime(fdate):
""
"
&
相关文档:
PEP 0263
Defining Python Source Code Encodings
Python will default to ASCII as standard encoding if no other
encoding hints are given.
To define a source code encoding, a magic comment must
be placed into the source files either as first or second
line in the file, suc ......
2009-11-16
Collin Winter是Python社区一位颇具影响力的开发者,他曾是CPython项目的核心开发者之一、也曾是Unladen Swallow(见文末注释)的核心开发者,参与了很多Python项目的开发。近来传闻Google将在其新项目中限制Python的使用,为此有开发者(以K表示)在Google 论坛中公开询问了Collin Winter,Collin Winte ......
由subprocess创建一个进程,然后进行监视
每一秒钟查看一次,如果正在运行,打印pid和running,如果已停止,,继续执行任务并打印Termined
shell和stdout均设置为False
也许这对做病毒的守护进程很好
#!/usr/bin/env python
import subprocess , sys , time
p=subprocess.Popen(['ping','127.0.0.1','-n','10'], she ......
Documentation for C's fopen():
---
r Open text file for reading. The stream is positioned at the beginning
of the file.
r+ Open for reading and writing. The stream is positioned at the
beginning of the file.
w Truncate file to zero length or create text file for writing. The
stream is posi ......
关于Python程序的运行,其实一个Python程序就相当于一个应用程序,它不需要经过编译,只需要用户电脑上面安装Python环境即可。要运行一个py程序,直接双击这个py文件即可。一般情况下,没有提示用户输入或控制屏幕显示,打开一个py文件时会突然闪一下马上就退出,这是由于程序运行已经完成了。若需要显示,则要添加一 ......