sciris.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:
dcp()
: shortcut tocopy.deepcopy()
pp()
: shortcut topprint.pprint()
isnumber()
: checks if something is any number typetolist()
: converts any object to a list, for easy iterationtoarray()
: tries to convert any object to an array, for easy use with numpymergedicts()
: merges any set of inputs into a dictionarymergelists()
: merges any set of inputs into a listruncommand()
: simple way of executing a shell commanddownload()
: download multiple URLs in parallel
Functions
Convert an arbitrary Unicode string to ASCII. |
|
A convenience function for checking instances. |
|
Function to compare versions, expecting both arguments to be a string of the format 1.2.3, but numeric works too. |
|
Shortcut to perform a shallow copy operation |
|
Shortcut to perform a deep copy operation |
|
Download one or more URLs in parallel and return output or save them to disk. |
|
Create a fast UID or set of UIDs. |
|
Try converting any object to a "regular" string (i.e. |
|
Alias for pip freeze. |
|
Try to get information on the calling function, but fail gracefully. |
|
Return the name of the current platform: 'linux', 'windows', 'mac', or 'other'. |
|
Retrieve git info |
|
Convert a string to its HTML representation by converting unicode characters, characters that need to be escaped, and newlines. |
|
Import modules by name. |
|
Check whether something is a Numpy array, and optionally check the dtype. |
|
Simply determine whether or not the input is iterable. |
|
Alias to |
|
Alias to |
|
Determine whether or not the input is a number. |
|
Determine whether or not the input is string-like (i.e., str or bytes). |
|
Alias to |
|
Small function to merge multiple dicts together. |
|
Merge multiple lists together. |
|
Alias to |
|
Shortcut for pretty-printing the object. |
|
Small function to ensure consistent format for things that should be arrays (note: |
|
Make sure object is always a list (note: |
|
Check whether environment requirements are met. |
|
Make it easier to run shell commands. |
|
Shortcut for the standard hashing (SHA) method |
|
Like string |
|
Convenience function to split common types of strings. |
|
Return suggested item |
|
Swap the keys and values of a dictionary. |
|
Small function to ensure consistent format for things that should be arrays (note: |
|
Make sure object is always a list (note: |
|
Shortcut for accessing the traceback |
|
Convert e.g. |
|
Given a name and a list of other names, find a replacement to the name that doesn't conflict with the other names, and pass it back. |
|
Download a single URL. |
|
Shortcut for creating a UUID; default is to create a UUID4. |
|
Download a single URL. |
Classes
Create a "lazy" module that is loaded if and only if an attribute is called. |
|
A class to differentiate between an object and a link to an object. |
|
A simple extension to a list that defines add methods to simplify appending and extension. |
|
Use pretty repr for objects, instead of just showing the type and memory pointer (the Python default for objects). |
|
Simple class to catch exceptions in a single line -- effectively an alias to contextlib.suppress. |
Exceptions
A tiny class to fix repr for KeyErrors. |
|
An exception to raise when links are broken, for exclusive use with the Link class. |