我们从Python开源项目中,提取了以下14个代码示例,用于说明如何使用pywintypes.Unicode()。
def toRaw(self): nm = pywintypes.Unicode(u'VS_VERSION_INFO') rawffi = self.ffi.toRaw() vallen = len(rawffi) typ = 0 sublen = 6 + 2*len(nm) + 2 pad = '' if sublen % 4: pad = '\000\000' sublen = sublen + len(pad) + vallen pad2 = '' if sublen % 4: pad2 = '\000\000' tmp = "".join([kid.toRaw() for kid in self.kids ]) sublen = sublen + len(pad2) + len(tmp) return (struct.pack('hhh', sublen, vallen, typ) + getRaw(nm) + '\000\000' + pad + rawffi + pad2 + tmp)
def toRaw(self): if type(self.name) is STRINGTYPE: self.name = pywintypes.Unicode(self.name) vallen = 0 typ = 1 sublen = 6 + 2*len(self.name) + 2 tmp = [] for kid in self.kids: raw = kid.toRaw() if len(raw) % 4: raw = raw + '\000\000' tmp.append(raw) tmp = ''.join(tmp) sublen += len(tmp) if tmp[-2:] == '\000\000': sublen -= 2 return (struct.pack('hhh', sublen, vallen, typ) + getRaw(self.name) + '\000\000' + tmp)
def toRaw(self): if type(self.name) is STRINGTYPE: self.name = pywintypes.Unicode(self.name) vallen = 0 typ = 1 sublen = 6 + 2*len(self.name) + 2 pad = '' if sublen % 4: pad = '\000\000' tmp = ''.join([kid.toRaw() for kid in self.kids]) sublen = sublen + len(pad) + len(tmp) if tmp[-2:] == '\000\000': sublen = sublen - 2 return (struct.pack('hhh', sublen, vallen, typ) + getRaw(self.name) + '\000\000' + pad + tmp)
def toRaw(self): self.vallen = 0 self.wType = 1 self.name = pywintypes.Unicode('VarFileInfo') sublen = 6 + 2*len(self.name) + 2 pad = '' if sublen % 4: pad = '\000\000' tmp = ''.join([kid.toRaw() for kid in self.kids]) self.sublen = sublen + len(pad) + len(tmp) return (struct.pack('hhh', self.sublen, self.vallen, self.wType) + getRaw(self.name) + '\000\000' + pad + tmp)
def toRaw(self): self.wValueLength = len(self.kids) * 2 self.wType = 0 if type(self.name) is STRINGTYPE: self.name = pywintypes.Unicode(self.name) sublen = 6 + 2*len(self.name) + 2 pad = '' if sublen % 4: pad = '\000\000' self.sublen = sublen + len(pad) + self.wValueLength tmp = ''.join([struct.pack('h', kid) for kid in self.kids]) return (struct.pack('hhh', self.sublen, self.wValueLength, self.wType) + getRaw(self.name) + '\000\000' + pad + tmp)
def TextExcel(xl): xl.Visible = 0 if xl.Visible: raise error("Visible property is true.") xl.Visible = 1 if not xl.Visible: raise error("Visible property not true.") if int(xl.Version[0])>=8: xl.Workbooks.Add() else: xl.Workbooks().Add() xl.Range("A1:C1").Value = (1,2,3) xl.Range("A2:C2").Value = ('x','y','z') xl.Range("A3:C3").Value = ('3','2','1') for i in xrange(20): xl.Cells(i+1,i+1).Value = "Hi %d" % i if xl.Range("A1").Value != "Hi 0": raise error("Single cell range failed") if xl.Range("A1:B1").Value != ((Unicode("Hi 0"),2),): raise error("flat-horizontal cell range failed") if xl.Range("A1:A2").Value != ((Unicode("Hi 0"),),(Unicode("x"),)): raise error("flat-vertical cell range failed") if xl.Range("A1:C3").Value != ((Unicode("Hi 0"),2,3),(Unicode("x"),Unicode("Hi 1"),Unicode("z")),(3,2,Unicode("Hi 2"))): raise error("square cell range failed") xl.Range("A1:C3").Value =((3,2,1),("x","y","z"),(1,2,3)) if xl.Range("A1:C3").Value != ((3,2,1),(Unicode("x"),Unicode("y"),Unicode("z")),(1,2,3)): raise error("Range was not what I set it to!") # test dates out with Excel xl.Cells(5,1).Value = "Excel time" xl.Cells(5,2).Formula = "=Now()" import time xl.Cells(6,1).Value = "Python time" xl.Cells(6,2).Value = pythoncom.MakeTime(time.time()) xl.Cells(6,2).NumberFormat = "d/mm/yy h:mm" xl.Columns("A:B").EntireColumn.AutoFit() xl.Workbooks(1).Close(0) xl.Quit()
def TextExcel(xl): xl.Visible = 0 if xl.Visible: raise error("Visible property is true.") xl.Visible = 1 if not xl.Visible: raise error("Visible property not true.") if int(xl.Version[0])>=8: xl.Workbooks.Add() else: xl.Workbooks().Add() xl.Range("A1:C1").Value = (1,2,3) xl.Range("A2:C2").Value = ('x','y','z') xl.Range("A3:C3").Value = ('3','2','1') for i in range(20): xl.Cells(i+1,i+1).Value = "Hi %d" % i if xl.Range("A1").Value != "Hi 0": raise error("Single cell range failed") if xl.Range("A1:B1").Value != ((Unicode("Hi 0"),2),): raise error("flat-horizontal cell range failed") if xl.Range("A1:A2").Value != ((Unicode("Hi 0"),),(Unicode("x"),)): raise error("flat-vertical cell range failed") if xl.Range("A1:C3").Value != ((Unicode("Hi 0"),2,3),(Unicode("x"),Unicode("Hi 1"),Unicode("z")),(3,2,Unicode("Hi 2"))): raise error("square cell range failed") xl.Range("A1:C3").Value =((3,2,1),("x","y","z"),(1,2,3)) if xl.Range("A1:C3").Value != ((3,2,1),(Unicode("x"),Unicode("y"),Unicode("z")),(1,2,3)): raise error("Range was not what I set it to!") # test dates out with Excel xl.Cells(5,1).Value = "Excel time" xl.Cells(5,2).Formula = "=Now()" import time xl.Cells(6,1).Value = "Python time" xl.Cells(6,2).Value = pythoncom.MakeTime(time.time()) xl.Cells(6,2).NumberFormat = "d/mm/yy h:mm" xl.Columns("A:B").EntireColumn.AutoFit() xl.Workbooks(1).Close(0) xl.Quit()
def TextExcel(xl): xl.Visible = 0 if xl.Visible: raise error, "Visible property is true." xl.Visible = 1 if not xl.Visible: raise error, "Visible property not true." if int(xl.Version[0])>=8: xl.Workbooks.Add() else: xl.Workbooks().Add() xl.Range("A1:C1").Value = (1,2,3) xl.Range("A2:C2").Value = ('x','y','z') xl.Range("A3:C3").Value = ('3','2','1') for i in xrange(20): xl.Cells(i+1,i+1).Value = "Hi %d" % i if xl.Range("A1").Value <> "Hi 0": raise error, "Single cell range failed" if xl.Range("A1:B1").Value <> ((Unicode("Hi 0"),2),): raise error, "flat-horizontal cell range failed" if xl.Range("A1:A2").Value <> ((Unicode("Hi 0"),),(Unicode("x"),)): raise error, "flat-vertical cell range failed" if xl.Range("A1:C3").Value <> ((Unicode("Hi 0"),2,3),(Unicode("x"),Unicode("Hi 1"),Unicode("z")),(3,2,Unicode("Hi 2"))): raise error, "square cell range failed" xl.Range("A1:C3").Value =((3,2,1),("x","y","z"),(1,2,3)) if xl.Range("A1:C3").Value <> ((3,2,1),(Unicode("x"),Unicode("y"),Unicode("z")),(1,2,3)): raise error, "Range was not what I set it to!" # test dates out with Excel xl.Cells(5,1).Value = "Excel time" xl.Cells(5,2).Formula = "=Now()" import time xl.Cells(6,1).Value = "Python time" xl.Cells(6,2).Value = pythoncom.MakeTime(time.time()) xl.Cells(6,2).NumberFormat = "d/mm/yy h:mm" xl.Columns("A:B").EntireColumn.AutoFit() xl.Workbooks(1).Close(0) xl.Quit()