python行长度有限制吗_换行超过行长度的所有行

我正在写一个程序,它限制每一行的长度。在

这就是我到目前为止所得到的,我几乎完成了,但我仍然需要删减每一行,但我不明白。在def main():

filename = input("Please enter the name of the file to be used: ")

openFile = open(filename, 'r+')

file = openFile.read()

lLength = int(input("enter a number between 10 & 20: "))

while (lLength < 10) or (lLength > 20) :

print("Invalid input, please try again...")

lLength = int(input("enter a number between 10 & 20: "))

wr = textwrap.TextWrapper()

wraped = wr.wrap(file)

print("Here is your output formated to a max of", lLength, "characters per line: ")

wr.width = lLength

wr.expand_tabs = True

for lines in wraped:

print(lines)

编辑:

^{pr2}$

输出应该是什么的一个例子如下。

如果指定的文件包含此文本:hgytuinghdt #here the length is 11

ughtnjuiknshfyth #here the length is 16

nmjhkaiolgytuhngjuin #here the length is 20

l长度被指定为15,则应打印出:hgytuinghdt

ughtnjuiknshfyt

h

nmjhkaiolgytuhng

juin

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值