Python word
³¬Èº.comµÄ²©¿Í
Pythonת»»office wordÎļþΪHTML
ÕâÀï²âÊԵĻ·¾³ÊÇ£ºwindows xp,office 2007,python 2.5.2,pywin32 build
213£¬ÔÀíÊÇÀûÓÃwin32com½Ó¿ÚÖ±½Óµ÷ÓÃoffice
API£¬ºÃ´¦ÊǼòµ¥¡¢¼æÈÝÐԺã¬Ö»ÒªofficeÄÜ´¦ÀíµÄ£¬python¶¼¿ÉÒÔ´¦Àí£¬´¦Àí³öÀ´µÄ½á¹ûºÍoffice wordÀïÃæ“Áí´æΪ”Ò»Ö¡£
#!/usr/bin/env python
#coding=utf-8
from
win32com import
client as
wc
word = wc.Dispatch
(
'Word.Application'
)
doc = word.Documents
.Open
(
'd:/labs/math.doc'
)
doc.SaveAs
(
'd:/labs/math.html'
, 8
)
doc.Close
(
)
word.Quit
(
)
¹Ø¼üµÄ¾ÍÊÇdoc.SaveAs(‘d:/labs/math.html’,
8)ÕâÒ»ÐУ¬ÍøÉϺܶàÎÄÕÂд³É£ºdoc.SaveAs(‘d:/labs/math.html’,
win32com.client.constants.wdFormatHTML)£¬Ö±½Ó±¨´í£º
AttributeError: class Constants has no attribute ‘wdFormatHTML’
µ±È»ÄãÒ²¿ÉÒÔÓÃÉÏÃæµÄ´úÂ뽫wordÎļþת»»³ÉÈÎÒâ¸ñʽÎļþ£¨Ö»Òªoffice 2007Ö§³Ö£¬±ÈÈ罫wordÎļþת»»³ÉPDFÎļþ£¬°Ñ8¸Ä³É17¼´¿É£©£¬ÏÂÃæÊÇoffice 2007Ö§³ÖµÄÈ«²¿Îļþ¸ñʽ¶ÔÓ¦±í£º
wdFormatDocument = 0
wdFormatDocument97 = 0
wdFormatDocumentDefault = 16
wdFormatDOSText = 4
wdFormatDOSTextLineBreaks = 5
wdFormatEncodedText = 7
wdFormatFilteredHTML = 10
wdFormatFlatXML = 19
wdFormatFlatXMLMacroEnabled = 20
wdFormatFlatXMLTemplate = 21
wdFormatFlatXMLTemplateMacroEnabled = 22
wdFormatHTML = 8
wdFormatPDF = 17
wdFormatRTF = 6
wdFormatTemplate = 1
wdFormatTemplate97 = 1
wdFormatText = 2
wdFormatTextLineBreaks = 3
wdFormatUnicodeText = 7
wdFormatWebArchive = 9
wdFormatXML = 11
wdFormatXMLDocument = 12
wdFormatXMLDocumentMacroEnabled = 13
wdFormatX
Ïà¹ØÎĵµ£º
¹Ø¼ü×Ö: python
Python¡¢UnicodeºÍÖÐÎÄ[ת]
pythonµÄÖÐÎÄÎÊÌâÒ»Ö±ÊÇÀ§ÈÅÐÂÊÖµÄÍ·ÌÛÎÊÌ⣬ÕâƪÎÄÕ½«¸øÄãÏêϸµØ½²½âÒ»ÏÂÕâ·½ÃæµÄ֪ʶ¡£µ±È»£¬¼¸ºõ¿ÉÒÔÈ·¶¨µÄÊÇ£¬ÔÚ½«À´µÄ°æ±¾ÖУ¬python»á³¹µ×½â¾ö´ËÎÊÌ⣬²»ÓÃÎÒÃÇÕâôÂé·³ÁË¡£
ÏÈÀ´¿´¿´pythonµÄ°æ±¾£º
>>> import sys
>> ......
>>> 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 = ......
ÕýÔò±í´ïʽÊǸöħ¹í£¬Ò²ÊǸöÌìʹ¡£ÔÚÄãûÓÐÕÆÎÕËü֮ǰ£¬ËüÊÇħ¹í£¬ÔÚÄãÕÆÎÕËüºó£¬ËüÊÇÌìʹ£¬µ«ÊÇ£¬Ê±
²»Ê±»¹ÊÇÒªÌø³öÀ´£¬¸øÄãµ÷Ƥµ·µ°Ò»·¬¡£
Ò»¸öÕýÔò±í´ïʽ¾ÍÊÇÓÉÆÕͨ×Ö·ûÒÔ¼°ÌØÊâ×Ö·û×é³ÉµÄÎÄ×Öģʽ£¬¸ÃģʽÃèÊöÔÚ²éÕÒÎÄ×ÖÖ÷Ìåʱ´ý
Æ¥ÅäµÄÒ»¸ö»ò¶à¸ö×Ö·û´®¡£ÕýÔò±í´ïʽ×÷Ϊһ¸öÄ£°å£¬½«Ä³¸ö×Ö·ûģʽÓëËùËÑË÷µÄ ......
ÔÚLearning Python 3rd ÀïµÚÈý²¿·ÖÁ·Ï°ÌâÓеÀÌ⣺
1.c ±àдfor Ñ»·£¬¶ÔÓÚ×Ö·û´®S£¬·µ»ØÒ»¸öеÄÁÐ±í£¬ÆäÖаüº¬ÁË×Ö·û´®Ã¿¸ö×Ö·ûµÄASCIIÂë¡£
ÎÒµÄ˼·ÊÇ£º
for i in S:
L = [ord(i) for i in S] #Áбí½âÎöµÄ˼·
ÎҵĴíÎó˼·£º
for i in S:
L = L.append(ord(i))
Ìáʾ¿Õ¶ ......
Python MySQLdb ²éѯ·µ»Ø×Öµä½á¹¹ smallfish
MySQLdbĬÈϲéѯ½á¹û¶¼ÊÇ·µ»Øtuple£¬Êä³öʱºò²»ÊǺܷ½±ã£¬±ØÐë°´ÕÕ0£¬1ÕâÑù¶ÁÈ¡£¬ÎÞÒâÖÐÔÚÍøÉÏÕÒµ½¼òµ¥µÄÐ޸ķ½·¨£¬¾ÍÊÇ´«µÝÒ»¸öcursors.DictCursor¾ÍÐС£
ĬÈϳÌÐò£º
import MySQLdb
db = MySQLdb.connect(host = 'localhost', user = 'root', passwd = '123456', d ......