这是我的原代码,从网上搜到要用locale,用locale.getlocale()得到的手机上是('en_US','UTF-8')电脑上是(None,None)
但是两边都不支持用locale. setlocale()修改
感觉这个东西莫名其妙
第1个nowfile=open(nowname,'wb')正常生成了5.txt,但是while里面的nowfile=open(nowname,'wb')明明传入了一样的参数,但是却报了错
#!/usr/bin/python3
import time
import socket
import locale
locale.getlocale()
HOST = '192.168.1.25'
PORT = 47513
nowname='/storage/emulated/0/A_/通讯/5.txt'
print(nowname)
nowfile=open(nowname,'wb')
nowfile.close()
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((HOST, PORT))
print('Access!')
odd=b""
while True:
data = s.recv(1024)
if data==b'':
continue
dh=data[:5]
data=data[5:]
if dh[0]==102: #f
if dh[1]==104: #h
nowname='/storage/emulated/0/A_/通讯/'+data[:int.from_bytes(dh[1:3],'big')].decode('utf-8')
print(nowname)
print(dh)
print(data)
nowfile=open(nowname,'wb')
if dh[1]==100: #d
nowfile.write(data[:int.from_bytes(dh[1:3],'big')])
if dh[1]==101: #e
nowfile.close()
if dh[0]==108: #l
print (">> ",data.decode('utf-8'))