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
Add option append (-a) to %save #2131
Conversation
Add newline after every write to make sure successive appends work.
@@ -61,6 +61,9 @@ def save(self, parameter_s=''): | |||
-f: force overwrite. If file exists, %save will prompt for overwrite | |||
unless -f is given. | |||
|
|||
-a: append to file. Open file in append mode and end every write | |||
on a newline. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a reason why we shouldn't end on a newline always anyway?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i don't think there's ever a reason not to end a file with a newline, doda/ipython@4a6d842 would implement that and simplify the code as a result
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that makes sense - let's bring that commit into this PR.
This only writes the |
Check whether the file didn't exist beforehand or if we're not appending (in which case the file gets written anew anyways.
i've added 2 commits, the magic comment now always gets written if the file didn't exist beforehand, no matter |
@@ -61,6 +61,8 @@ def save(self, parameter_s=''): | |||
-f: force overwrite. If file exists, %save will prompt for overwrite | |||
unless -f is given. | |||
|
|||
-a: open file in append mode. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this description could be a bit clearer - how about "append to the file instead of overwriting it."
Other than the docstring (and maybe a test), I think this looks fine. |
grepping through the source didn't lead me to any tests for |
Great, thanks. I'm running the tests now. |
For some reason it's refusing to post the results automatically, but it's somehow causing a failure in the history tests:
That's in Python 3.2, but it looks like it's failing in all versions of Python. |
Oh, I think it's just because |
here you go! |
Test results for commit d5e7d79 merged into master
Not available for testing: python2.6 |
The timeout error is probably unrelated. This all looks OK now, but I'll give it a day or so in case anyone else wants to look over it. |
sure thanks for the quick replies! |
Add option append (-a) to %save
Merged. Thanks for the contribution! |
Add option append (-a) to %save
inspired by: http://www.reddit.com/r/Python/comments/wc0wp/ipython_how_to_save_code_entered_in_the_shell_to/
:)
I'm not sure if simply writing a
\n
if it isn't there is the best way to handle the case of multiplesave -a
after one another, but i'd think it's than to try and changefind_user_code
.