def pickle_data_recover(): try: with open('testdata/man_data.out', "rb") as man_file, open('testdata/other_data.out', "rb") as other_file: new_man = pickle.load(man_file) except IOError as err: print('File established failed : ' + str(err)) except pickle.PickleError as p_err: print('Pickle error : '+str(p_err)) nester.print_list(new_man)
def create_file_real(): try: #'with' includes data open/close/IOError handle of a file with open('testdata/man_data.out', "w") as man_file: #print(man, file=man_file) nester.print_list(man, man_file)#due to format with open('testdata/other_data.out', "w") as other_file: nester.print_list(other,False,0, other_file) except IOError as err: print('File established failed : ' + str(err)) '''
import pickle import nester try: with open('data.pickle','wb') as data_file: cities=["jim","loli","jax",["lax","pek","ctu",["3ua","3ub","3uc"],"ckg"],["sha","xmn","ljg"],"tmd"] pickle.dump(cities,data_file) with open('data.pickle','rb') as data_file: a_list = pickle.load(data_file) nester.print_list(a_list,True,0) except IOError as err: print 'error occured when open file: ' + str(err) except pickle.PickleError as p_err: print 'error occured when load file: ' + str(p_err)
ProcedureControl movies = ["The Holy Grail", 1975, "Terry Jones & Terry Gilliam", 91, ["Graham Chapman", ["Michael Palin", "John Cleese", "Terry Gilliam", "Eric Idle", "Terry Jones"]]] #Define Function SelfDefineFunction.my_function() print('//================Do self-function with recursive') SelfDefineFunction.print_list(movies) print('//================Public-available module') nester.print_list(movies,0) #File process #File open, read and close / try and exception catch and finally #'with'(context management protocol)/pickle print('//================File process') fileprocess.do_file_process() #Data process #sort(In-place / Copied), split, set, List Comprehension print('//================Data process') dataprocess.do_data_process() #Custom Data Object #dictionary, Object class, Inherit class print('//================Custom Object')
#import nester from nester import print_list movices = ['Frozen', 'Thor', ["HP1", "HP2", "HP3", "HP4"]] #nester.print_list(movices,1) print_list(movices, True)
import nester m=['l',['l2',['l3']]] nester.print_list(m)
import nester this_list = ['a', 'b', ['c', ['d', 'e'], 'f']] nester.print_list(this_list) nester.print_list(this_list, True) nester.print_list(this_list, True, 2)
import nester cities=["jim","loli","jax",["lax","pek","ctu","ckg"],["sha","xmn","ljg"],"tmd"] nester.print_list(cities,True,0)