py.turtle自动绘图&文本添加行号

py.turtle自动绘图&文本添加行号,第1张

概述py.turtle自动绘图&文本添加行号py.turtle自动绘图文本添加行号py.turtle自动绘图data.txt300,1,144,1,0,0300,1,144,0,1,0300,0,144,0,0,1300,0,144,1,1,0300,0,108,0,1,1184,0,72,1,0,1184,0,72,0,0,0184,0,72,0,0,0184,0,72,0,0,0184,0,72,1,0,1184,1,72,0,0,0184,1,72,0,0,0184,

py.turtle自动绘图&文本添加行号 py.turtle自动绘图文本添加行号

py.turtle自动绘图

data.txt

300,1,144,0,0300,1300,108,1184,72,0184,720,0
# Coding=utf-8import turtle as tt.setup(800, 800, 0, 0)t.pensize(5)t.speed(8)lines = []newlines = []with open("data.txt", "r") as f:    lines = f.readlines()    for line in lines:        line = line.replace("\n", "").split(",")        newlines.append(line)for i in range(len(newlines)):    t.pencolor(int(newlines[i][3]), int(newlines[i][4]), int(newlines[i][5]))    t.fd(int(newlines[i][0]))    if newlines[i][1]:        t.lt(int(newlines[i][2]))    else:        t.rt(int(newlines[i][2]))t.penup()t.fd(100)t.hIDeturtle()t.pendown()t.write("帅9091", Font=("Arial", 16, "normal"))t.done()

文本添加行号
#Coding=gbk# 给文件添加行号lines = []with open("帅-9091.txt", "r",enCoding='gbk') as f:    lines = f.readlines()    lines = enumerate(lines)  # 给列表上序号,变为元祖    lines = List(lines)  # 将enumerate对象转化为列表# 将加入行号的内容输出到new文件中with open("帅-9091new.txt", "w",enCoding='utf-8') as f:    for i in range(len(lines)):        line = lines[i][1].replace("\n", "")  # 获取第i行数据        line = "第"+str(i+1)+"行:  " + line+"\n"        f.writelines(line)

很久前的小代码!

总结

以上是内存溢出为你收集整理的py.turtle自动绘图&文本添加行号全部内容,希望文章能够帮你解决py.turtle自动绘图&文本添加行号所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/langs/1189236.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-03
下一篇 2022-06-03

发表评论

登录后才能评论

评论列表(0条)

保存