foo = ‘abc‘ for i in range(len(foo)): print "%d , %s" % (i, foo[i]) print [x ** 2 for x in range(5) if not x % 2] try: f = open(‘e:\XIN_370_logic.tx‘, ‘r‘) for eachline in f: print eachline f.close() except IOError, e: print e def func1(x): return x + x x = [i for i in range(4)] print func1(x) def func2(debug=True): if debug: print ‘true,in debug mode!‘ print ‘done‘ func2(False) """ """ a = int(raw_input(‘input num1:‘)) b = int(raw_input(‘input num2:‘)) c = int(raw_input(‘input num3:‘)) alist = [a, b, c] minalist = min(alist) maxalist = max(alist) medalist = [x for x in alist if x != minalist and x!= maxalist] medalist = medalist[0] print minalist, medalist, maxalist """ import os while True: ar = raw_input("read or write file[r/w],enter . to quit>>") if ar == ‘w‘: ls = os.linesep globals(ls) while True: os.chdir(r"e:\\") filename = raw_input(‘input filename:‘) if os.path.exists(filename): print ‘file %s already exists!‘ % filename else: break all = [] print "\nenter lines(‘.‘ by is self to quit).\n" while True: entry = raw_input(‘>>>‘) if entry == ‘.‘: print ‘quit‘ break else: all.append(entry) f = open(filename, ‘w‘) print all for eachline in all: f.writelines("%s%s" % (eachline, ls)) f.close() elif ar == ‘r‘: filename = raw_input(‘input filename:‘) print try: os.chdir(r"e:\\") f = open(filename, ‘r‘) except IOError: print ‘file %s is not exists!‘ % filename else: for eachline in f: print eachline f.close() elif ar == ‘.‘: break else: print ‘input error,input again!‘ continue
时间: 2024-10-09 18:25:54