sc_utils#
Miscellaneous utilities for type checking, printing, dates and times, etc.
Note: there are a lot! The design philosophy has been that it’s easier to ignore a function that you don’t need than write one from scratch that you do need.
- Highlights:
sc.dcp()
: shortcut tocopy.deepcopy()
sc.pp()
: shortcut topprint.pprint()
sc.isnumber()
: checks if something is any number typesc.tolist()
: converts any object to a list, for easy iterationsc.toarray()
: tries to convert any object to an array, for easy use with numpysc.mergedicts()
: merges any set of inputs into a dictionarysc.mergelists()
: merges any set of inputs into a listsc.runcommand()
: simple way of executing a shell commandsc.download()
: download multiple URLs in parallel
Classes
A simple extension to a list that defines add methods to simplify appending and extension. |
|
A class to differentiate between an object and a link to an object. |
|
Create a "lazy" module that is loaded if and only if an attribute is called. |
|
Simple class to catch exceptions in a single line |
Functions
Create a fast UID or set of UIDs. |
|
Shortcut for creating a UUID; default is to create a UUID4. |
|
Shortcut to perform a deep copy operation |
|
Shortcut to perform a shallow copy operation |
|
Shortcut for pretty-printing the object. |
|
Shortcut for the standard hashing (SHA) method |
|
Shortcut for accessing the traceback |
|
Get the current username |
|
Return the name of the current "main" platform (e.g. 'mac'). |
|
Alias to |
|
Alias to |
|
Alias to |
|
Check if a command is running inside a Jupyter notebook. |
|
Convert an arbitrary Unicode string to ASCII. |
|
Download a single URL. |
|
Download a single URL. |
|
Download one or more URLs in parallel and return output or save them to disk. |
|
Convert a string to its HTML representation by converting unicode characters, characters that need to be escaped, and newlines. |
|
Try converting any object to a "regular" string (i.e. |
|
Remove all non-"standard" characters from a string |
|
Determine whether or not the input is iterable, with optional types to exclude. |
|
A convenience function for checking instances. |
|
Determine whether or not the input is a number. |
|
Determine whether or not the input is string-like (i.e., str or bytes). |
|
Check whether something is a Numpy array, and optionally check the dtype. |
|
Quickly check if something is a function. |
|
Small function to ensure consistent format for things that should be arrays (note: |
|
Make sure object is always a list (note: |
|
Small function to ensure consistent format for things that should be arrays (note: |
|
Make sure object is always a list (note: |
|
Convert e.g. a list of key-value tuples into a list of keys and a list of values. |
|
Swap the keys and values of a dictionary. |
|
Small function to merge multiple dicts together. |
|
Merge multiple lists together. |
|
For a list of inputs, return the first one that meets the condition |
|
Like string |
|
Alias to |
|
Convenience function to split common types of strings. |
|
Make it easier to run shell commands. |
|
Given a name and a list of other names, add a counter to the name so that it doesn't conflict with the other names. |
|
Return suggested item |
|
Import modules by name. |
|
Import a module by path. |
Exceptions
A tiny class to fix repr for KeyErrors. |
|
An exception to raise when links are broken, for exclusive use with the Link class. |