首页 > 试题广场 >

以下哪个代码是正确的读取一个文件?

[单选题]
以下哪个代码是正确的读取一个文件?
  • f = open("test.txt", "read")
  • f = open("r","test.txt")
  • f = open("test.txt", "r")
  • f = open("read","test.txt")

答案:C

分析

  • Python中,打开文件语法为
    text = oepn(filePath, 操作方式,编码方式)
  • 常见操作方式
    • 'r':读
    • 'w':写
    • 'a':追加
  • 常见编码方式
    • utf-8
    • gbk    
编辑于 2019-11-29 11:03:10 回复(7)
+1,选C
发表于 2019-10-26 15:53:40 回复(1)
我按答案D去运行,代码出错了.所以应该是C.

编辑于 2019-11-07 12:28:00 回复(0)
python中打开文件的语法为:f=open(filepath,操作方式,编码方式)
常见的操作方式为:r-读、w-写、a-追加
常见的编码方式为:utf-8、gbk
发表于 2022-05-07 16:23:21 回复(0)
text = oepn(filePath, 操作方式,编码方式) r读
发表于 2022-05-07 10:44:15 回复(0)
<p>c</p>
发表于 2020-05-12 19:12:31 回复(0)
这题选C
发表于 2019-10-21 08:47:08 回复(0)
ValueError: mode string must begin with one of 'r', 'w', 'a' or 'U', not 'test.txt'
这题选C
编辑于 2019-11-07 12:27:35 回复(0)
text = oepn(filePath, 操作方式,编码方式)
发表于 2024-03-12 11:38:47 回复(0)
对Python打开文件方式还不熟Python 打开文件方式应为(filepath,操作方式,编码方式)操作方式:r 读w 写a 添加
发表于 2023-04-05 03:42:27 回复(0)
虽然我做对了,再发一次 open() 函数的形参说明;

help(open)
Help on built-in function open in module io:

open(file, mode='r', buffering=-1, encoding=None, errors=None, newline=None, closefd=True, opener=None)


发表于 2022-11-03 12:00:00 回复(1)
答案:C 分析 Python中,打开文件语法为 text = oepn(filePath, 操作方式,编码方式) 常见操作方式 'r':读 'w':写 'a':追加 常见编码方式 utf-8 gbk
发表于 2022-03-28 23:19:50 回复(0)
Open是读取 r是文件 rb是二进制文件 read是读取整个文件 readlines是读取整个文件,每一行为一个元素存在列表里,有\n readline 一行一行读取,慢,所需内存大
编辑于 2021-11-15 22:47:31 回复(0)
C
发表于 2021-10-11 14:49:22 回复(0)
r 读写
发表于 2021-08-07 21:16:37 回复(0)
f=(文件路径,读写模式,指定编码)
发表于 2021-07-26 01:49:18 回复(0)
C
发表于 2021-06-25 15:26:00 回复(0)
c
编辑于 2021-06-01 01:42:48 回复(0)
C
发表于 2021-05-14 01:33:57 回复(0)
c
发表于 2021-04-13 19:03:16 回复(0)