def test_flatten(): assert flatten({ 'a': 1, 'data': { 'a': 2, 'data': { 'a': 3, } } }) == { 'a': 1, 'data.a': 2, 'data.data.a': 3, }
def encode(self, record): flat = flatten(record) values = [] for k in self.fields: if k in flat: v = flat[k] else: v = "" v = self.escape(str(v)) values.append(v) data = self.delim.join(values) return data
def test_roundtrip(): data = { 'a.b.c': 3, } assert data == flatten(unflatten(data))
def test_flatten_array_3(self): flattendedArray = flatten([[[1,2,3]] , [['a','b','c']]]) self.assertEqual(flattendedArray, [[1,2,3], ['a','b','c']])
def index(): if request.method == 'POST': Word.query.delete() Definition.query.delete() Examples.query.delete() Synonimes.query.delete() Antonyms.query.delete() task_content = request.form['content'] with open('text.txt', "a") as myfile: myfile.write(task_content + "\n") task_content = result.main(task_content) if task_content[0][0] != request.form['content']: t = [] for i in task_content: t.append(i[0]) return render_template('problem.html', tasks=t) try: if task_content[0][1] == 0.0: return render_template('problem.html', tasks=[]) except: pass new_task = Word(word='\n\n'.join( str(elem) for elem in list(flat.flatten(task_content[0])))) try: db.session.add(new_task) db.session.commit() except: pass try: new_task = Definition(definition='\n\n'.join( str(elem) for elem in list(flat.flatten(task_content[1])))) try: db.session.add(new_task) db.session.commit() except: pass except: print("xcfvgbhunij") pass try: new_task = Examples(examples='\n\n'.join( str(elem) for elem in list(flat.flatten(task_content[2])))) try: db.session.add(new_task) db.session.commit() except: pass except: pass try: new_task = Synonimes(synonimes='\n\n'.join( str(elem) for elem in list(flat.flatten(task_content[3])))) try: db.session.add(new_task) db.session.commit() except: pass except: pass try: new_task = Antonyms(antonyms='\n\n'.join( str(elem) for elem in list(flat.flatten(task_content[4])))) try: db.session.add(new_task) db.session.commit() except: pass except: pass return redirect('/') else: try: print(session['my_var']) except: Word.query.delete() Definition.query.delete() Examples.query.delete() Synonimes.query.delete() Antonyms.query.delete() session['my_var'] = 1 tasks = Word.query.all() + Definition.query.all() + Examples.query.all( ) + Synonimes.query.all() + Antonyms.query.all() return render_template('index.html', tasks=tasks)