dream789 发表于 2017-5-6 07:29:28

python是个什么东西---python---生成和读取X进制文件

  



# -*- coding: utf-8 -*-
#'./data.pgd'
def content2File(fileFullName, content):
writer = open(fileFullName, 'wb')
writer.write(content.encode('hex').encode('base64').encode('bz2'))
writer.close()

def file2Content(fileFullName):
reader = open(fileFullName, 'rb')
uncompressedData = ''
while True:            
s = reader.read(1024)
if not s: break
uncompressedData += s
return uncompressedData.decode('bz2').decode('base64').decode('hex')

#def splitWithRegex(content,regex):
#return content.split(regex)
#lines = 'あ,あ,あ,あ,あ,あ,あ,あ,あ,あ\nい,い,い,い,い,い,い,い,い,い\nう,う,う,う,う,う,う,う,う,う'
#content2File('./data.pgd', lines)
#print file2Content('./data.pgd')
#content = file2Content('./data.pgd')
#print content
#for line in content.split('\n'):#splitWithRegex(content,'\n'):
#for elem in content.split(','):#splitWithRegex(line,','):
#print elem
 
页: [1]
查看完整版本: python是个什么东西---python---生成和读取X进制文件