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

RTSTRUCT save as #5

Closed
awtkns opened this issue Jan 21, 2021 · 1 comment
Closed

RTSTRUCT save as #5

awtkns opened this issue Jan 21, 2021 · 1 comment

Comments

@awtkns
Copy link
Contributor

awtkns commented Jan 21, 2021

Two small things here:

  • We are opening but never closing the file.
  • Why are we using open? Why not Path.exsists() && Path.is_file()

def save(self, file_path):
try:
open(file_path, 'w')
# Opening worked, we should have a valid file_path
print("Writing file to", file_path)
self.ds.save_as(file_path)
except OSError:
raise Exception(f"Cannot write to file path '{file_path}'")

@asim-shrestha
Copy link
Contributor

motivation behind it is to ensure we have a valid file name / file is writable / can overwrite existing files. I'm not sure if we can do this with those methods (initially the path will probably be empty so .exists() would be false. Issue arises since .exists() also just returns false with invalid file names)

As for closing, python should handle closing it eventually but I added a close to be sure

@awtkns awtkns closed this as completed Jan 25, 2021
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

2 participants