from nester import nester movies = ["The holy grail", 1975, "Terry Jones & Terry Gilliam", 91, ["Graham Chapman", ["Michael Palin", "John Clease", "Terry Gilliam", "Terry Jones"]]] nester.print_lol(movies)
from nester.nester import print_lol movies = [ "the holy grail", 1975, "terry jones & terry gilliam", 91, [ "graham chapman", [ "michael palin", "john cleese", "terry gilliam", "eric idle", "terry jones" ] ] ] print_lol(movies) print_lol(movies, True) print_lol(movies, True, 5)
from nester import nester #import module names = ['govardhan', 'manikanta', 'kartheek'] nester.print_lol(names) #invoke the (module) function
# with open('mydata.pickle','wb') as mysavedata: # pickle.dump([1, 2, 'three'], mysavedata) # ''' # 使用load,從文件恢復數據,將恢復的數據賦予一個變數 # ''' # with open('mydata.pickle','rb') as myrestoredata: # a_list = pickle.load(myrestoredata) # print(a_list) import sys, os import pickle abs_path = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) sys.path.append(abs_path) from nester import nester new_man = [] new_other = [] try: with open('man_data.txt','rb') as man_file: new_man = pickle.load(man_file) with open('other_data.txt','rb') as other_file: new_other = pickle.load(other_file) except IOError as err: print('File error: '+str(err)) except pickle.PickleError as perr: print('picking error: '+str(perr)) nester.print_lol(new_man) print('------------------------------------------------') nester.print_lol(new_other)
# print("file error" + str(err)) # try: # with open("man_data.txt",'w') as man_data , open("other_data.txt",'w') as other_data: # nester.print_lol(man,fh=man_data) # nester.print_lol(other,fh=other_data) # except IOError as err: # print("file error" + str(err)) # Using Pickle for persistance data try: with open("man_data.txt",'wb') as man_data , open("other_data.txt",'wb') as other_data: pickle.dump(man,man_data) pickle.dump(other,other_data) except pickle.PickleError as perr: print("file error" + str(perr)) try: with open('man_data.txt','rb') as man_file: man_file = pickle.load(man_file) except IOError as err: print("file error "+ str(err)) except pickle.PickleError as perr : pickle("pickle error "+ str(perr)) nester.print_lol(man_file)