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)

  

转载于:https://www.cnblogs.com/lilyfindjobs/p/4525305.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值