传统弱校HFUT的蒟蒻,真相只有一个

Python 学习笔记四

接着三继续写http://www.cnblogs.com/dzzy/p/5295019.html

文件和函数操作:

from sys import argv
script,input_file=argv
def print_all(f):
    print f.read()
def rewind(f):
    f.seek(0)
def print_a_line(line_count,f):
    print line_count,f.readline()

current_file=open(input_file)
print_all(current_file)
print "Let's rewind"
rewind(current_file)
current_line=1
print_a_line(current_line,current_file)
current_line+1
print_a_line(current_line,current_file)
current_line+1
print_a_line(current_line,current_file)

 

class调用 注意init下划线是前后两个

class song(object):
    def __init__(self,lyrics):
        self.lyrics=lyrics
    def sing_me(self):
        for line in self.lyrics:
            print line
            
happy=song(["shit","sb","23333"])
happy.sing_me()

 

posted @ 2016-03-29 15:20  未名亚柳  阅读(162)  评论(0编辑  收藏  举报