namegen_example.py
1.63 KB
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
60
61
62
63
64
65
66
"""
Copyright 2010 Joao Henriques <jotaf (no spam) at hotmail dot com>.
This file is part of name-gen.
name-gen is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
name-gen is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with name-gen. If not, see
<http://www.gnu.org/licenses/>.
"""
"""
name-gen: Free python name generator module that analyzes sample text and produces
similar words.
Example usage and simple demonstration.
"""
import os
from namegen import NameGen
#get all available language files
files = os.listdir('./Languages')
exit = False
while not exit:
print 'Select a language file: (any other input to quit)\n'
#present all available files as options
for (id, file) in enumerate(files):
print id, ': ', file
#interpret option number, if anything goes wrong quit
try:
filename = files[int(raw_input())]
except ValueError or IndexError:
break
#load generator data from language file
generator = NameGen('Languages/' + filename)
#generate a few words
for i in range(20):
print generator.gen_word()
#pause (wait for some input)
print '\nPress Enter to continue.'
try:
raw_input()
except EOFError:
pass