open函数r模式如何换行
Python3读取文件(r模式):f=open('haoma.txt','r')
a=f.read()#解码
print(a)
f.close()#关闭文件
r模式的文件指针默认在开头,怎样调整呢? https://docs.python.org/3/library/io.html#io.IOBase.seek seek函数
sh-5.1$ cat main.c
#include <stdio.h>
int main(void) {
printf("hello world!\n");
return 0;
}
sh-5.1$ python
Python 3.10.9 (main, Dec 19 2022, 17:35:49) on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> f = open('main.c', 'r')
>>> f.
f.buffer f.errors f.mode f.readline( f.tell() f.writelines(
f.close() f.fileno() f.name f.readlines( f.truncate(
f.closed f.flush() f.newlines f.reconfigure( f.writable()
f.detach() f.isatty() f.read( f.seek( f.write(
f.encoding f.line_bufferingf.readable() f.seekable() f.write_through
>>> f.seek(30)
30
>>> f.readline()
'oid) {\n'
>>> f.seek(10)
10
>>> f.readline()
'stdio.h>\n'
>>>
甲鱼宝典:https://fishc.com.cn/thread-210581-1-1.html
页:
[1]