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

Added basic implementation for string and path manipulation in python #686

Merged
merged 4 commits into from
May 28, 2024

Conversation

k-dominik
Copy link
Collaborator

@k-dominik k-dominik commented May 27, 2024

This is more or less a 1:1 translation of the macro code to python.

  • For log messages: I included an example of using an f-string. While this is an advanced concept It adds so much to the readability of these strings, and also avoids the explicit type conversion.
  • For the paths I went for pathlib.Path. In principle one could do the same with strings and something like os.path.join() to get platform-independent joining of paths (one could also use os.sep with string concatenation to be even closer to the macro example. While this would work it encourages bad practices. pathlib.Path objects add so much useful functionality (e.g. path.name to get the filename, path.parent to get the parent directory, .stem, .suffix... so much that I missed when doing a ij macro).

fixes #683

Copy link
Collaborator

@tischi tischi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot, I added a couple of suggestions.

k-dominik and others added 2 commits May 28, 2024 09:33
* group code sections with `# %%` (will be separate cells in notebooks)
* more meaningful comments

Co-authored-by: Christian Tischer <[email protected]>
@k-dominik k-dominik force-pushed the add-py-strings-paths branch from 846564c to 82e50b8 Compare May 28, 2024 07:38
k-dominik added 2 commits May 28, 2024 10:19
Updated with composing of new file names based on the python ex.

Also removed use of File.separator as getDirectory already returns a
trailing separator (at least on mac).
@k-dominik
Copy link
Collaborator Author

Hello @tischi,

I updated the directory exercise with your proposed changes, both in python and ijm. For the ijm I also removed the used of File.separator since the directory we're working with there, already has one. If you find it important didactically to introduce it we'd have to come up with a different way of getting a directory to work with.

@k-dominik k-dominik marked this pull request as ready for review May 28, 2024 08:41
@tischi
Copy link
Collaborator

tischi commented May 28, 2024

Very cool!

💟

@tischi tischi merged commit 3ab4583 into master May 28, 2024
5 checks passed
@k-dominik k-dominik deleted the add-py-strings-paths branch May 28, 2024 09:48
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

Successfully merging this pull request may close these issues.

Implement python activities for "Working with Strings"
2 participants