• 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)
    

      

  • 相关阅读:
    css实现多行文本溢出显示省略号(…)全攻略
    Git使用教程
    requireJS对文件合并与压缩(二)
    requireJS(版本是2.1.15)学习教程(一)
    谷歌浏览器javascript调试教程
    IPMITool driver
    ironic的自动化脚本
    serial console
    如何将自己写的代码上传到github上
    硬件检查
  • 原文地址:https://www.cnblogs.com/lilyfindjobs/p/4525305.html
Copyright © 2020-2023  润新知