Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 264fc2a

Browse files
Update random_names.py
Updates based on feedback from #1
1 parent cd47998 commit 264fc2a

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

‎random_names.py

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,19 @@
22
# -*- coding: utf-8 -*-
33
import random
44
import string
5+
from os.path import dirname, join
56

6-
FirstNames = './Names/FirstNames.txt'
7-
MiddleNames = './Names/MiddleNames.txt'
8-
LastNames = './Names/LastNames.txt'
9-
CountyNames = './Names/CountyNames.txt'
10-
PlaceNames = './Names/PlaceNames.txt'
11-
StateNames = './Names/StateNames.txt'
12-
CountryNames = './Names/CountryNames.txt'
13-
CompanyNames = './Names/CompanyNames.txt'
7+
script_dir = dirname(__file__)
8+
names_dir = join(script_dir, 'Names')
149

10+
FirstNames = join(names_dir, 'FirstNames.txt')
11+
MiddleNames = join(names_dir, 'MiddleNames.txt')
12+
LastNames = join(names_dir, 'LastNames.txt')
13+
CountyNames = join(names_dir, 'CountyNames.txt')
14+
PlaceNames = join(names_dir, 'PlaceNames.txt')
15+
StateNames = join(names_dir, 'StateNames.txt')
16+
CountryNames = join(names_dir, 'CountryNames.txt')
17+
CompanyNames = join(names_dir, 'CompanyNames.txt')
1518

1619

1720
def Number(start=0, end=100000):
@@ -49,6 +52,9 @@ def rawCount(filename):
4952

5053

5154
def randomLine(filename):
55+
"""
56+
Read the given text file and return a random line
57+
"""
5258
num = int(random.uniform(0, rawCount(filename)))
5359
with open(filename, 'r', encoding="UTF-8") as f:
5460
for i, line in enumerate(f, 1):

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /