python¶ÁȡĿ¼ÏÂÎļþ²¢Éú³ÉÈÕÖ¾
ºÜ³¤µÄÒ»¶Î´úÂ룬µ«ºÜÇå³þ¡£¹þ¹þ¡£
import os
from time import strftime
stamp=strftime("%Y-%m-%d %H:%M:%S")
logfile = 'F:\\test\\m-php-framework\\tmp\logs\\error_report.log'
path = 'F:\\test\\'
files = os.listdir(path)
bytes = 0
numfiles = 0
for f in files:
if f.startswith('t'):
info = os.stat(path + f)
numfiles +=1
bytes+=info[6]
if numfiles > 1:
title = 'tiles'
else:
title = 'file'
string = stamp + " -- " + str(numfiles) + " session" +title+","+ str(bytes)+" bytes\n"
file = open(logfile,"a")
file.writelines(string)
file.close()
Ïà¹ØÎĵµ£º
½ñÌìÓöµ½ÁËÂé·³£º
ÓÃEclipse±àÒëpythonÏòsqliteÊý¾Ý¿â²åÈëÊý¾Ý×ÜÊÇÌáʾ±àÂëµÄÎÊÌ⣬ÎÒÉèÖÃÁËEclipseµÄworkspaceÓÃutf-8±àÂ뻹ÊDz»ÐÐ
µ«ÊÇÓÃEclipseдµÄ³ÌÐò±£´æÔÙÓÃIDLE´ò¿ªÈ´ÄܱàÒë£¬Ææ¹ÖÁË
ÎÒ¿¼Âǵ½¿ÉÄÜÊÇÅäÖõÄÔÒò£¬ÕÒÕÒ±éÁËËùÓеÄÅäÖ㬶¼Ã»ÓÐÎÊÌ⣬°üÀ¨¹¤³ÌÎļþ
×îºóÎÒÓÃxvi32´ò¿ ......
Ó¢ÎİæDive in python¿ÉÒÔÔÚÏÂÃæÕÒµ½ÖÐÎÄ·Òëhttp://linuxtoy.org/docs/dip/toc/index.html
Ä£¿éµÄ__name__£¬µ±Ä£¿é±»importʱ£¬ÆäΪģ¿éµÄÃû×Ö£¬µ±Ä£¿é×÷ΪmainÖ´ÐеÄʱºò£¬ÆäΪ__main__
´ÊµäµÄkeyÊÇ´óСдÃô¸ÐµÄ¡£
ListÒ²Ö§³ÖÖØÔØ+²Ù×÷£¬ÓÃÓÚ½«Á½¸ölistÁ¬½ÓÆðÀ´£¬²¢·µ»ØÒ»¸öList£¬Òò´ËËüûÓÐextendedÖ´ÐиßЧ¡£listÒ²+ ......
>>> from socket import socket, SOCK_DGRAM, AF_INET
>>> s = socket(AF_INET, SOCK_DGRAM)
>>> s.connect(('google.com', 0))
>>> s.getsockname()
('192.168.1.113', 43711)
Linux:
import socket
import fcntl
import struct
def get_ip_address(ifname):
s = ......
%a ÐÇÆÚ¼¸µÄ¼òд
%A ÐÇÆÚ¼¸µÄÈ«³Æ
%b Ô·ֵļòд
%B Ô·ݵÄÈ«³Æ
%c ±ê×¼µÄÈÕÆÚµÄʱ¼ä´®
%C
Äê·ÝµÄºóÁ½Î»Êý×Ö
%d Ê®½øÖƱíʾµÄÿÔµĵڼ¸Ìì
%D ÔÂ/Ìì/Äê
%e ÔÚÁ½×Ö·ûÓòÖУ¬Ê®½øÖƱíʾµÄÿÔµĵڼ¸Ìì
%F
Äê-ÔÂ-ÈÕ
%g Äê·ÝµÄºóÁ½Î»Êý×Ö£¬Ê¹ÓûùÓÚÖܵÄÄê
%G Äê·Ö£¬Ê¹ÓûùÓÚÖܵÄÄê
%h ¼òдµÄÔ·ÝÃû ......
>>> 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_n ......