Skip to content
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

Potential issue with path concatenation on OSX #29

Open
sarmento opened this issue Aug 31, 2024 · 0 comments
Open

Potential issue with path concatenation on OSX #29

sarmento opened this issue Aug 31, 2024 · 0 comments

Comments

@sarmento
Copy link

I have just installed xbTools, and I am facing an issue that may be related with Windows vs osX path definitions.
My script is:

from xbTools.xbeachpost import XBeachModelAnalysis

results = XBeachModelAnalysis('Test', '/Users/lsarmento/xbeach/xbtools_test')
print(results.metadata)

The result from:

python xbtools.py 

is:

Traceback (most recent call last):
  File "xbtools.py", line 7, in <module>
    results = XBeachModelAnalysis('Test', '/Users/lsarmento/xbeach/xbtools_test')
  File "/usr/local/anaconda3/lib/python3.8/site-packages/xbTools/xbeachpost.py", line 39, in __init__
    self.get_metadata()
  File "/usr/local/anaconda3/lib/python3.8/site-packages/xbTools/xbeachpost.py", line 60, in get_metadata
    with open(self.model_path+'\\XBlog.txt') as file:
FileNotFoundError: [Errno 2] No such file or directory: '/Users/lsarmento/xbeach/xbtools_test\\XBlog.txt'

Looking at the source code of the class, it seems it may be related with this line:

        with open(self.model_path+'\\XBlog.txt') as file:

which I believe is not capable of handling non-windows paths.
Potential fix: use os.path.join instead of string concatenation:

with open(os.path.join(self.model_path,'XBlog.txt')) as file:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant