Tables :
- word : id_word, word
- problem : id_problem, problem
- solution : id_solution, solution
- problem_solution : id_problem, id_solution (a problem can have multiple solutions).
- word_problem : id_word, id_problem (a word can be found in multiple problems).
Logic :
ask user for problem.
split problem on space (" ") to get words.
for every word, ask your db for related problems.
show your user distinct related problems (ordering by the most occuring problem)
user selects a problem
fetch solutions for the problem and show them.
import csv
input_d = list()
while(True):
make = input('Enter make')
# fill in the rest
input_d.append(dict(make=make, #fill in the rest))
# figure out how to break this loop
with open('path/to/save/csv/file', 'w') as fh:
headers = input_d.keys()
writer = csv.DictWriter(fh, headers)
writer.writeheader()
writer.writerows(input_d)
所以你有关键词,问题和解决方案。在
通常,一个问题可以,而且会有多种解决方案。在
所以基本上,如果你使用的是csv,这意味着你将有一个列'solution'和几倍相同的解决方案。 这在维护方面不是很好(假设你在解决方案中犯了一个打字错误,你如何在所有地方都改变它?)在
将csv导入关系数据库(例如MySQL和MySQL Workbench)非常容易。 使用SQL可以让您使用很棒的函数,比使用csv要快得多,而且总的来说允许您以后使用ORM来实现类似于在数据库中插入django之类的功能。在
csv库将帮助您完成此操作。这是链接
https://docs.python.org/2/library/csv.html
我喜欢用听写器和听写器。在
相关问题 更多 >
编程相关推荐