Working with JSON in Python

To work with JSON in Python, we need to import the json module:

 import json

To parse JSON to Python Object

We can use json.loads() method as follow:

import json

# some JSON:
x =  '{ "name":"", "age":30, "city":"New York"}'

# parse x:
y = json.loads(x)

# the result is a Python dictionary:

To dumps Python object to JSON

We can use json.dumps() method as follow:

import json

# a Python object (dict):
x = {
  "name": "",
  "age": 30,
  "city": "New York"

# convert into JSON:
y = json.dumps(x)

# the result is a JSON string:

Happy coding!

Issue modifying Jupyter Home Directory

Issue modifying Jupyter Home Directory

At one point I set my Jupyter home directory to ~/Dropbox  Unfortunately, because of the way Dropbox changed their folder name that location is now a symbolic link on my machine that points to a hidden directory.  This causes the following error in Jupyter
Refusing to serve hidden directory '/Users/alex/Dropbox', via 404 Error
That's fine ... I'd like to now change my Jupyter home directory, but the issue I'm having is that I can't figure out where it's currently set.
I've checked my ~/.jupyter/ but that seems to be unmodified from the default.  
The output of $jupyter --paths is : 

Interestingly, the following directories don't exist. 

Setting c.NotebookApp.notebook_dir = '/Users/alex/' in /Users/alex/.jupyter/ seems to have no effect.
$jupyter notebook
[I 18:26:34.756 NotebookApp] [nb_conda_kernels] enabled, 4 kernels found
[I 18:26:35.257 NotebookApp] The port 8888 is already in use, trying another port.
[I 18:26:35.258 NotebookApp] The port 8889 is already in use, trying another port.
[I 18:26:35.259 NotebookApp] The port 8890 is already in use, trying another port.
[I 18:26:35.260 NotebookApp] The port 8891 is already in use, trying another port.
[I 18:26:36.299 NotebookApp] [nb_anacondacloud] enabled
[I 18:26:36.304 NotebookApp] [nb_conda] enabled
[I 18:26:36.382 NotebookApp] ✓ nbpresent HTML export ENABLED
[W 18:26:36.382 NotebookApp] ✗ nbpresent PDF export DISABLED: No module named 'nbbrowserpdf'
[I 18:26:36.388 NotebookApp] Serving notebooks from local directory: /Users/alex
[I 18:26:36.388 NotebookApp] 0 active kernels
[I 18:26:36.388 NotebookApp] The Jupyter Notebook is running at:
[I 18:26:36.388 NotebookApp] http://localhost:8892/?token=289948463daed06187325be63202f620b812dddc14f2918a
[I 18:26:36.388 NotebookApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).
[C 18:26:36.389 NotebookApp] 

    Copy/paste this URL into your browser when you connect for the first time,
    to login with a token:
[I 18:26:36.717 NotebookApp] Accepting one-time-token-authenticated connection from ::1
[I 18:26:37.252 NotebookApp] Refusing to serve hidden directory '/Users/alex/Dropbox', via 404 Error
[W 18:26:37.252 NotebookApp] 404 GET /api/contents?type=directory&_=1526088397023 (::1): directory does not exist: 'Dropbox'
[W 18:26:37.252 NotebookApp] directory does not exist: 'Dropbox'
[W 18:26:37.253 NotebookApp] 404 GET /api/contents?type=directory&_=1526088397023 (::1) 15.70ms referer=http://localhost:8892/tree

Where could the Jupyter home directory be set from?


Answer 1:

It is the intended behavior of jupyter notebook to throw a 404 when starting it from a hidden folder.

Generally, jupyter notebook will start in the folder where you invoke the jupyter notebook command. So cd into the directory where you want it to run from, and issue jupyter notebook there.

If that doesn’t work, you can try forcing the directory with a command line argument like jupyter notebook --notebook-dir=NEWDIR.

Otherwise, there is a global config and a local (per user) one you refer above. If the local is the default, then you probably changed the global config earlier. If you change your local config in ~/.jupyter/ to the new value that should override the global config.

To clean up the global config, look for it in /etc/jupyter or /usr/local/etc/jupyter/ on Unix or %PROGRAMDATA%\jupyter\ in Windows.

You can list the current config paths used with the command jupyter --paths. More info in the manual.