3.15 haas506开发教程-example-文本操作
1.文本读取/写入
'''
1表示 可以,0表示不行
_____________________________________________
模式 r r+ w w+ a a+
读 1 1 0 1 0 1
写 0 1 1 1 1 1
创建 0 0 1 1 1 1
覆盖 0 0 1 1 0 0
指针在头 1 1 1 1 0 0
指针在尾 0 0 0 0 1 1
_____________________________________________
'''
import uos
def main():
uos.mountsd()
print("files in sd card are:",uos.listdir('/sdcard0'))
read_from_txt()
print('-'*30)
write_to_txt()
def read_from_txt():
print('read_from_txt test')
f=open('/sdcard0/filename1.txt','r')
content1=f.readline()
print('content :',content1)
f.close()
def write_to_txt():
print('write_to_txt test')
f=open('/sdcard0/filename2.txt','w')
lens=f.write("type anything you want")
print("lens of content:",lens)
f.close()
print('-'*30)
p=open('/sdcard0/filename2.txt','r')
c=p.read(100)
print('content in filename2.txt is:',c)
p.close()
if __name__ == '__main__':
main()
files in sd card are: ['record1.pcm', 'System Volume Information', 'haas506.mp3', 'helloworld.mp3', 'filename1.txt', 'filename2.txt']
read_from_txt test
content : welcome come to use haas 506
------------------------------
write_to_txt test
lens of content: 22
------------------------------
content in filename2.txt is: type anything you want
|