Hacker News new | past | comments | ask | show | jobs | submit login
How do I edit a jupyter notebook ipynb file with python?
1 point by bashit on Dec 3, 2018 | hide | past | favorite | 2 comments
I wrote a simple note taking application that automates a few things for me when writing notes in markdown style. I can share the gitlab link if need be but perhaps a small description of my problem might be enough...

My python application which is very dumb and simple (does what I want) accomplishes a few simple tasks like...

* Inserting a markdown style timestamp for each new entry which links to a table of contents section name

* Logging complex commands from your bash_history at the end of the day

* Automatically archiving notes in a file using a markdown style table of contents

* Automatically syncing your notes (using git) with a remote repo on a hosting service like GitHub.

This all works fine if I'm taking notes using a simple .md (markdown) file. However, if I want automate this in the same way with a jupyter notebook ipynb file it becomes extremely more complicated. The ipynb file looks like it's in a json'ish format where some of it looks enrypted and apparently i need to have a notebook server running to open it??

Much of my text that isn't code in my personal jupyter notebook is formatted in markdown. I have a markdown style table of contents very similar to how I mentioned above. Therefore, it would really be nice if I could open a ipynb file like i do with python, sort it, write a line of text to it. How do I accomplish this?

Currently, I do something like the following when I want to insert some text into a .md (markdown) file. Which is simple...

with open(somefile, 'r') as f:

lines = f.readlines()

lines.insert(lineNumberToInsertAt, someText)

with open(somefile, 'w') as f:

f.writelines(lines)

I can't just open a ipynb file like this and write to it so how can I accomplish this?

Also I'm new to this site and noticed that there are some links that say "Ask HN: Some question". How do I appropriately post questions versus clogging up the main page which is more for articles?




Install PyCharm then pip (or pip3) install jupyter.


thanks suff ~ I'm having a hard time wording this question but I know how to install jupyter notebook and edit it using the jupyter notebook application. That is easy. My question was how to automate the tasks of..

Open the notebook file Grabbing the current time and inserting it into the file at line (x). Saving and closing the file.

I want to automate those three tasks using the python language.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: