¹ØÓÚPythonÖÐʱ¼äÓë×Ö·û´®Ö±½ÓµÄת»»
>>> import time
>>> import datetime
>>>
now = time.localtime()
>>> now
(2006, 4, 30, 18, 7, 35,
6, 120, 0)
>>> type(now)
<type 'time.struct_time'>
>>>
str_now = time.strftime("%m/%d/%Y %X", now )
>>>
str_now
'04/30/2006 18:07:35'
>>> new_now =
time.strptime( str_now, "%m/%d/%Y %X" )
>>> new_now
(2006,
4, 30, 18, 7, 35, 6, 120, -1)
ÕâÀstrftime ½« struct_time µÄʱ¼ä°´Ö¸¶¨µÄ¸ñʽת»¯³É ×Ö·û´®
strptime ½« ×Ö·û´®°´Ö¸¶¨µÄ¸ñʽת»¯³É
struct_time µÄʱ¼ä
struct_time µÄʱ¼äûÓÐÏֳɵıȽϵĺ¯Êý£¬¿ÉÒÔ½« struct_time ת»¯³É datetime.datetime
>>> d_now = datetime.datetime( *now[:6] )
>>>
type(d_now)
<type 'datetime.datetime'>
>>> d_now
datetime.datetime(2006,
4, 30, 18, 7, 35)
Ïà¹ØÎĵµ£º
С°×ÊǸö΢ÈíÃÔ£¬ËûµÄżÏñÊDZȶû´óÊ壬ÔÒòµ±È»ÊǵØÇòÈ˶¼ÖªµÀÀ²¡£´ó¶þµÄʱºò£¬ËûµÄ“ê¡Ñ§¼Æ»®”ÔøÒ»¶ÈµÃ³Ñ£¬ÔÒòÊÇËû¹Ò¿ÆÌ«¶à¡£µ±È»£¬´óÈýÐÂѧÆÚ¿ªÊ¼µÄʱºò£¬Ãæ¶Ô¹«ÖÚÖÊÒÉ£¬Ð¡°×Õ¾ÔÚÒÎ×ÓÉÏ£¬Ïñ¼«ÁË¡¶´óÄÚÃÜ̽ÁãÁã·¢¡·ÀïµÄÎ÷ÃÅ´µÑ©£º“ÊÀ½çÊ׸»±È²»Ò»¶¨Óжà³öÉ«£¬ÕâÖ»²»¹ýÊÇÄãÃÇÕâЩÐǶ·ÊÐÃñÒ»ÏáÇéÔ¸µÄÏë·¨° ......
1. ÊÖ¶¯ÖÆ×÷pythonµÄexe¿ÉÖ´ÐгÌÐò
תÔØ---------------
PythonûÓÐÄÚ½¨Ò»¸ö±à ......
µ±Ö´ÐÐimport
moduleʱ£¬½âÊÍÆ÷»á¸ù¾ÝÏÂÃæµÄËÑË÷·¾¶£¬ËÑË÷module1.pyÎļþ¡£
1) µ±Ç°¹¤×÷Ŀ¼
2) PYTHONPATHÖеÄĿ¼
3) Python°²×°Ä¿Â¼
(/usr/local/lib/python)
ÊÂʵÉÏ£¬Ä£¿éËÑË÷ÊÇÔÚ±£´æÔÚsys.pathÕâ¸öÈ«¾Ö±äÁ¿ÖеÄĿ¼ÁбíÖнøÐÐËÑË÷¡£
sys.path»áÔÚ½âÊÍÆ÷¿ªÊ¼Ö´ÐÐʱ±»³õʼ»¯³É°üº¬£º
1)µ±Ç°¹¤×÷Ŀ¼
2) PYT ......
µ±ÎÒÃÇÕâÑù½¨Á¢Îļþʱ
f =
file('x1.txt', 'w')
f.write(u'ÖÐÎÄ')
f.colse()
Ö±
½Ó½á¹ûÓ¦¸ÃÊÇÀàËÆ
f.write(u'ÖÐÎÄ')
UnicodeEncodeError: 'ascii'
codec can't encode characters in position 0-16: ordinal not in
range(128)
ÒªÖ±½Óд utf-8 ÎļþÔõô°ìÄØ?
import codecs
f = codecs. ......
python¶Ô¶à¹úÓïÑԵĴ¦ÀíÊÇÖ§³ÖµÄºÜºÃµÄ£¬Ëü¿ÉÒÔ´¦ÀíÏÖÔÚÈÎÒâ±àÂëµÄ×Ö·û£¬ÕâÀïÉîÈëµÄÑо¿Ò»ÏÂpython¶Ô¶àÖÖ²»Í¬ÓïÑԵĴ¦Àí¡£
ÓÐÒ»µãÐèÒªÇå³þµÄÊÇ£¬µ±pythonÒª×ö±àÂëת»»µÄʱºò£¬»á½èÖúÓÚÄÚ²¿µÄ±àÂ룬ת»»¹ý³ÌÊÇÕâÑùµÄ£º
ÔÓбàÂë -> ÄÚ²¿±àÂë ->
Ä¿ ......