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自动绘图&文本添加行号所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)