问题
f = open('./demo.txt', mode='r', encoding='UTF-8')
# 读取文件, 一般都赋值给一个变量
data = f.readlines(5)
print(data)
f.close()
这读取出来的也不是5行啊. 这肉眼看着是第一行呀? 请求各位大佬以及老师.
作者回复: 是的,这里读取的是字节数量,已经勘误过,但是视频没办法修改了。
繁星不灭
2023-02-05来自广东
1.习题练习
string = """Python 3.11 is up to 10-60% faster than Python 3.10.
On average, we measured a 1.25x speedup on the standard
benchmark suite. See Faster CPython for details. """
with open("a.txt", "w") as file:
file.write(string)
with open("a.txt", "r") as file:
string_a = file.read()
with open("b.txt", "w") as file2:
file2.write(string_a)
2
江江儿嘛哩哄
2023-01-03来自浙江
string = """Python 3.11 is up to 10-60% faster than Python 3.10.
On average, we measured a 1.25x speedup on the standard benchmark suite.
See Faster CPython for details. """
f = open("a.txt", mode="w", encoding="UTF-8")
f.write(string)
f.close()
f = open("a.txt", mode="r", encoding="UTF-8")
b = open("b.txt", mode="w", encoding="UTF-8")
b.write(f.read())
b.close()
f.close()
1
rOMEo罗密欧
2022-12-26来自广东
f_a = open("./a.txt")
f_b = open("./b.txt", mode="w")
for data in f_a:
f_b.write(data)
f_a.close()
f_b.close()
1
William
2023-09-13来自吉林
def fun_45_2():
f1= open('./a.txt', mode='r', encoding='utf-8')
data = f1.readlines()
f2 = open('./b.txt', mode='w+', encoding='utf-8')
for it in data:
f2.write(it)
f1.close()
f2.close()
不再是入门水平pytho...
2023-09-01来自上海
第一题:
string = """Python 3.11 is up to 10-60% faster than Python 3.10. On average, we measured a 1.25x speedup on the standard benchmark suite. See Faster CPython for details. """
with open('a.txt','w') as file:
file.write(string)
第二题:
with open('a.txt','r') as source_file:
content = source_file.read()
with open('b.txt','w') as target_file:
target_file.write(content)
Geek_219b52
2023-08-03来自浙江
import os
file1 = open("D:\\零基础学python\\演示代码\\a.txt",mode = "w",encoding='utf-8')
str = 'string = """Python 3.11 is up to 10-60% faster than Python 3.10. On average, we measured a 1.25x speedup on the standard benchmark suite. See Faster CPython for details. """'
file1.write(str)
file1.close()
file1 = open("D:\\零基础学python\\演示代码\\a.txt",mode = "r",encoding='utf-8')
file2 = open("D:\\零基础学python\\演示代码\\b.txt",mode = "w",encoding='utf-8')
file2.write(file1.read())
file1.close()
file2.close()
Geek_Mike
2023-07-06来自云南
str1 = 'Python 3.11 is up to 10-60% faster than Python 3.10. On average, we measured a 1.25x speedup on the standard benchmark suite. See Faster CPython for details.'
with open('/Users/mike/Desktop/zero-basics-python/0/a.txt', 'w+', encoding='UTF-8') as a:
a.write(str1)
with open('/Users/mike/Desktop/zero-basics-python/0/a.txt', 'r', encoding='UTF-8') as a:
data_a = a.read()
with open('/Users/mike/Desktop/zero-basics-python/0/b.txt', 'w+', encoding='UTF-8') as b:
b.write(data_a)
print(data_a)
with open('/Users/mike/Desktop/zero-basics-python/0/b.txt', 'r', encoding='UTF-8') as b:
data_b = b.read()
print(data_b)
展开
Geek_943787
2023-05-17来自浙江
string = """Python 3.11 is up to 10-60% faster than Python 3.10. On average, we measured a 1.25x speedup on the standard benchmark suite. See Faster CPython for details. """
f = open('a.txt',mode='w',encoding='UTF-8')
f.write(string)
f.close()
f = open('a.txt',encoding='UTF-8')
f1 = open('b.txt',mode='w',encoding='UTF-8')
for data in f:
f1.write(data)
f.close()
f1.close()