#!/usr/bin/python#encode.pyimportsysimportos.pathimportosimportglobimportbinasciidefcur_file_dir():path=sys.path[0]ifos.path.isdir(path):returnpathelifos.path.isfile(path...
#!/usr/bin/python
#encode.py
import sys
import os.path
import os
import glob
import binascii
def cur_file_dir():
path = sys.path[0]
if os.path.isdir(path):
return path
elif os.path.isfile(path):
return os.path.dirname(path)
def encode(fileName):
file = open(fileName, 'rb+')
try:
all_the_text = file.read()
for byte in all_the_text:
temp = binascii.b2a_hex(byte)
#coding
byte = binascii.a2b_hex(temp)
file.seek(0, 0)
file.write("sandglass")
file.write(all_the_text)
file.flush()
finally:
file.close()
return None
def codePic(path):
print path
for root, dirs, files in os.walk( path ):
for file in files:
if len(file and ".png") or len(file and ".jpg"):
fullpath = os.path.join(root, file)
print fullpath
encode(fullpath)
return None
codePic(cur_file_dir())
os.system("pause")
查找文件和读写文件都实现了,但是完全搞不懂python里面的二进制和字符串之间该怎么转换和运算
#coding中是想将读出来的字符转成二进制后再做位运算,再转回字符
求大神帮忙看看该怎么实现
展开