1

I created yesterday a Jupyter notebook file in Python 3 and saved it. I do not know what bad manipulation I did but today, when I want to reopen this file, I realize that it is in plain text format! Is there a way to revert to a python encoded format?

The file doesn't have extension ipynb (It has no extension) ; it looks like this (few first lines):

 "cells": [
  {
   "cell_type": "code",
   "execution_count": 377,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "C:\\Users\\thaly\\anaconda3\\lib\\site-packages\\pandas\\core\\indexing.py:965: SettingWithCopyWarning: \n",
      "A value is trying to be set on a copy of a slice from a DataFrame.\n",
      "Try using .loc[row_indexer,col_indexer] = value instead\n",
      "\n",
      "See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
      "  self.obj[item] = s\n"
     ]
    }
   ],
   "source": [
    "import pandas as pd\n",
    "\n",````

2
  • has the extension changed? Commented Apr 19, 2020 at 9:09
  • Could you be more specific. Show us an sample of the file, is it a JSON which is also plain/text format but the native format of Jupyter notebook? Also notebook are auto saved. Did you run the Jupyter instance on the same home folder? What is your expected output a python file or jupyter notebook? Commented Apr 19, 2020 at 9:09

4 Answers 4

4

The file you have saved is a Jupyter notebook (internally it is a JSON file).

To convert this notebook, you can:

  • Just add an extension .ipynb to it,
  • run Jupyter and open the notebook with it.
  • Then you will be able to export the content of the notebook in several format such as Python file.
Sign up to request clarification or add additional context in comments.

1 Comment

Many thanks! I just added the extension ipynb as you suggested, and it's now perfect. I don't understand what happened but i'm really relieved!
1
  1. simple open you txt or any file on jupyter notebook
  2. go to the rename option and edit the the name of file with .ipynb (Example file.txt to file.ipynb)
  3. save it and open again.

Comments

0

Maybe you're trying to open the html file without actually starting the notebook and using a text editor instead? You need to start the notebook, for instance, from IPython.

Comments

0

Just select the python kernel and it should format the code as python

I ran into an issue where I created a .ipynb file in vscode, but when I add new code cells, they show up as 'plain text' "code" cells instead of python. I was googling for 5 minutes before I just did that and I was good to go.

I think this might be what Denis was referring to by 'starting' the notebook.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.