Skip to content

Runtime filepath defining instead of fixed filepath for text files. #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
rowds opened this issue Aug 12, 2024 · 1 comment
Closed
Assignees
Labels
enhancement New feature or request

Comments

@rowds
Copy link

rowds commented Aug 12, 2024

Importing this as is from a python project's modules' directory that is 'project_dir/sample/' will raise a filepath error. It is very simple to fix this issue but will greatly increase the usabilty of the code. Instead of defining fixed file paths for text files like this:

FirstNames    = './Names/FirstNames.txt'
MiddleNames   = './Names/MiddleNames.txt'
LastNames     = './Names/LastNames.txt'
CountyNames   = './Names/CountyNames.txt'
PlaceNames    = './Names/PlaceNames.txt'
StateNames    = './Names/StateNames.txt'
CountryNames  = './Names/CountryNames.txt'
CompanyNames  = './Names/CompanyNames.txt'

Define the filepaths in runtime instead so that it can run as a importable module or a standalone script or whatever, like this:

#directory from where the module is running currently.
script_dir    = os.path.dirname(__file__)
names_dir     = os.path.join(module_dir, 'Names')

FirstNames    = os.path.join(names_dir, 'FirstNames.txt')
MiddleNames   = os.path.join(names_dir, 'MiddleNames.txt')
LastNames     = os.path.join(names_dir, 'LastNames.txt')
CountyNames   = os.path.join(names_dir, 'CountyNames.txt')
PlaceNames    = os.path.join(names_dir, 'PlaceNames.txt')
StateNames    = os.path.join(names_dir, 'StateNames.txt')
CountryNames  = os.path.join(names_dir, 'CountryNames.txt')
CompanyNames  = os.path.join(names_dir, 'CompanyNames.txt')

P.S. the Names folder still needs to be in the same directory as the script.

@navchandar navchandar self-assigned this Aug 13, 2024
@navchandar navchandar added the enhancement New feature or request label Aug 13, 2024
navchandar added a commit that referenced this issue Aug 13, 2024
Updates based on feedback from #1
@navchandar
Copy link
Owner

Fixed and released. Please check v4.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants