zoukankan      html  css  js  c++  java
  • python os turtle

    import os
    
    def rename_file():
        file_name_list=os.listdir(r"/Users/Lily/Documents/ASU1/CodePractise/prank")
        print(file_name_list)
        saved_path=os.getcwd()
        print("current working directory is"+saved_path)
        os.chdir(r"/Users/Lily/Documents/ASU1/CodePractise/prank")
        for file_name in file_name_list:
            os.rename(file_name, file_name.translate(None, "0123456789"))
        os.chdir(saved_path)
    
    rename_file()
    

      os: Miscellaneous operating system interfaces

    os.listdir(path):

    Return a list containing the names of the entries in the directory given by path. The list is in arbitrary order. It does not include the special entries '.' and '..' even if they are present in the directory.

    Availability: Unix, Windows.

    inheritance

    os.getcwd(): Return a string representing the current working directory.

    os.chdir(path):Change the current working directory to path.

    python string translate():

    str.translate(table[, deletechars]);

    Parameters

    • table -- You can use the maketrans() helper function in the string module to create a translation table.

    • deletechars -- The list of characters to be removed from the source string.

    Turtle 

    import turtle
    window=turtle.Screen()
    window.bgcolor("red")
    def draw_art():
        brad=turtle.Turtle()
        brad.shape("turtle")
        brad.color("yellow")
        brad.speed(4)
        brad.penup()
        brad.goto(0,50)
        #love(brad)
        #for i in range(1,37):
        #   draw_triangle(brad)
        #   brad.right(10)
    
    
    draw_art()
    
    #draw_triangle()
    window.exitonclick()
    

     turtle.penup() make turtle stop drawing

    检测文档是否有profanity

    __author__ = 'Lily'
    
    import urllib
    
    def read_txt():
        quote=open("curseTest.txt")
        content_of_file=quote.read()
        print(content_of_file)
        quote.close()
        check_profanity(content_of_file)
    
    def check_profanity(text):
        connection=urllib.urlopen("http://www.wdyl.com/profanity?q="+text)
        output=connection.read()
        #print(output)
        connection.close()
        if "true" in output:
            print("profanity alert")
        elif "false" in output:
            print("no profanity")
        else:
            print("something wrong")
    
    read_txt()
    

     open()

    urllib.urlopen()使用于2.7版本

    connection.read()

    inheritance

    class parent():
        def __init__(self,last_name, eye_color):
            self.last_name=last_name
            self.eye_color=eye_color
    
    class child(parent):
        def __init__(self,last_name,eye_color,number_of_toys):
            parent.__init__(self,last_name,eye_color)
            self.number_of_toys=number_of_toys
    
    lily=child(zhang,black,5)
    print(lily.number_of_toys)
    

      

  • 相关阅读:
    【转】在.NET使用JSON作为数据交换格式
    类似QQ管家页面jquery图片轮换实例
    jquery+ajax 文件上传功能(无ifram嵌套)
    sql另辟蹊,持续更新
    【转】JavaScript 中 function 的动态执行
    八款js框架比较
    【转】怎样写出可维护的面向对象javascript
    【转】程序员该如何定位?
    WF4.0实战系列索引
    Microsoft Help Viewer help查看器所需的内容文件缺失或者损坏 解决办法
  • 原文地址:https://www.cnblogs.com/lilyfindjobs/p/4525305.html
Copyright © 2011-2022 走看看