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)
    

      

  • 相关阅读:
    Python:Lasso方法、GM预测模型、神经网络预测模型之财政收入影响因素分析及预测
    ARIMA模型构建、预测——基于Python
    家用电器用户行为分析与事件识别学习笔记
    JQData数据提取及MySQL简单操作——基于Python
    android 沉浸通知栏
    PullToRefreshScrollView 修改下拉刷新图标
    Android AlertDialog 设置setSingleChoiceItems不显示列表的原因【setMessage和setSingleChoiceItems不能同时使用】
    图片跑马灯抽奖,本地图片变换简单实现
    android知识点大总结
    Android 面试精华题目总结
  • 原文地址:https://www.cnblogs.com/lilyfindjobs/p/4525305.html
Copyright © 2011-2022 走看看