zoukankan      html  css  js  c++  java
  • python学习--文件操作实例一

    #!/usr/bin/env python3
    # -*- coding: utf-8 -*-
    
    #根据数据文件在窗口中动态路径绘制
    from turtle import *
    import turtle
    
    def main():
        #设置窗口信息
        turtle.title("数据驱动的动态路径绘制")
        turtle.setup(800, 600, 0, 0)
        #设置画笔
        pen = turtle.Turtle()
        pen.color("red")
        pen.width(3)
        pen.shape("turtle") #笔头:小乌龟
    #    pen.shape("square") #笔头:小方块
    #    pen.shape("circle") #笔头:小圆形
        pen.speed(2)
        #读取文件
        result=[]
        file = open("data.txt","r")
        for line in file:
            #把文件的每一行以逗号为分隔符,把每一个元素转换成浮点数,增加到result列表中
            #string.split(str="",num=string.count(str))
            #以str为分隔符切片string,如果num有指定值,则仅分隔num个字符串
            #map() 会根据提供的函数对指定序列做映射。
            #第一个参数 function 以参数序列中的每一个元素调用 function 函数,返回包含每次 function 函数返回值的新列表。
            #map(function,iterable,...)
            result.append(list(map(float, line.split(','))))
        print(result)
        #动态绘制
        for i in range(len(result)):
            #设置画笔的颜色
            #pen.color
            pen.color((result[i][3],result[i][4],result[i][5]))
            pen.fd(result[i][0])
            if result[i][1]:
                pen.rt(result[i][2])
            else:
                pen.lt(result[i][2])
        pen.goto(0,0)
        done()
    
    if __name__ == '__main__':
        main()
  • 相关阅读:
    System.Windows.Forms.Timer与System.Timers.Timer的区别(zz)
    30个最常用css选择器解析(zz)
    Highcharts选项配置详细说明文档(zz)
    CSS For Bar Graphs(maybe old)
    学习CSS3BUTTON(二)
    学习CSS3BUTTON(一)
    CSS CURSOR属性
    CSS3的文字阴影—text-shadow
    display:inline-block; 到底是个啥玩意?
    mysql 子查询
  • 原文地址:https://www.cnblogs.com/hayden1106/p/7832911.html
Copyright © 2011-2022 走看看