blob: a9cff8f78130000ec275eed918e95c7b64f3e315 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
#!/usr/bin/python
import ConfigParser
# Global definition
CONF_FILE='elephant.conf'
CAT_SECTION='Categories'
WORDS_SECTION='Words'
# Class
# Return the word list from config file and numbers of word
class word_list:
def __init__(self):
# Number of words
self.number_of_words = len(self.get_word_list())
# Get all categories from config file
def get_categories(self):
parser = ConfigParser.SafeConfigParser()
parser.read(CONF_FILE)
full_list = parser.items(CAT_SECTION)
category_list = [row[1] for row in full_list]
return category_list
# Get all words from a specifir category
#def get_words_in_category(self, category):
# parser = ConfigParser.SafeConfigParser()
# parser.read(CONF_FILE)
#
# word_list = parser.options(category)
#
# return word_list
# Get all words form config file
def get_word_list(self):
parser = ConfigParser.SafeConfigParser()
parser.read(CONF_FILE)
full_list = parser.items(WORDS_SECTION)
word_list = [row[0] for row in full_list]
return word_list
# Get path of choosen image
def get_word_image_path(self, word):
parser = ConfigParser.SafeConfigParser()
parser.read(CONF_FILE)
image_path = parser.get(WORDS_SECTION, word)
return image_path
|