Working with Code Snippets#
Code Snippets enable you to securely upload reusable blocks of code to Anaconda Cloud. You can then share your snippets with other users, access your snippets in Excel, and insert your snippets across notebooks.
Anaconda maintains a Jupyter notebook that includes example code snippets you can modify and add to your own projects:
Creating Code Snippets#
Create a Code Snippet using the following steps:
Enter your code in an empty notebook cell.
Click Create a New Code Snippet in the cell toolbar.
Enter a name for your code snippet.
Select a project to house your snippet.
Note
If you don’t have any projects, a new project with the code snippet name as the title will be created.
Click Create Code Snippet.
A new .py
file with the code snippet’s name appears in the project and is ready to be used across your notebooks. Save the project by pushing your project to Anaconda Cloud to share your snippets across devices and software.
Inserting snippets in a notebook#
When you’re ready to use a saved snippet, insert it in a notebook using the following steps:
Open Anaconda Toolbox.
Under Code Snippets, select Manage Code Snippets. Alternatively, under Anaconda Cloud, select My Projects.
You can now insert your snippet in one of two ways:
Select a cell in the notebook where you’d like to insert the code.
Click Insert code snippet in notebook beside the code snippet.
The code snippet appears in a new cell below the selected cell. If no cell was selected, the code snippet appears in the last cell of the notebook.
Click actions beside the code snippet, then click Copy to Clipboard.
Select a cell in the notebook where you’d like to insert the code.
Paste the code into the cell.
Editing a snippet#
To edit a snippet, you must make changes to the snippet directly in the Anaconda Toolbox extension.
Open Anaconda Toolbox.
Under Code Snippets, select Manage Code Snippets. Alternatively, under Anaconda Cloud, select My Projects.
Double-click the snippet’s
.py
file to open the file.Adjust your snippet.
To save your file changes, go to File, then select Save Python File.
You can now use your updated snippet across your notebooks. However, you’ll need to push the associated project to make the changes available in Anaconda Cloud.