The environment module describes an object for accessing and setting variables related to the user’s music21 environment. Such variables include the location of external applications such as MusicXML readers (e.g. Finale), whether music21 is allowed to download files directly (via the virtual corpus), and other settings. Additional documentation for and examples of using this module are found in Setting up and Configuring Environment.
The Environment object stores user preferences as dictionary-like object.
Create an instance of this object. A modName argument can be provided for use in printDebug() calls.
>>> a = Environment()
>>> post = a['writeFormat']
Environment attributes
- modNameParent¶
- A string representation of the module that contains this Environment instance.
- ref¶
- The Python dictionary used to store all internal settings.
Environment methods
- read(fp=None)¶
- Load an XML preference file if and only if the file is available and has been written in the past. This means that no preference file will ever be written unless manually done so. If no preference file exists, the method returns None.
- write(fp=None)¶
- Write an XML preference file. This must be manually called to store any changes made to the object and access preferences later. If fp is None, the default storage location will be used.
- getSettingsPath()¶
- Return the path to the platform specific settings file.
- getDefaultRootTempDir()¶
- Use the Python tempfile.gettempdir() to get the system specified temporary directory, and try to add a new ‘music21’ directory, and then return this directory. This method is only called if the no scratch directory preference has been set. If not able to create a ‘music21’ directory, the standard default is returned.
- getRootTempDir()¶
- Return a directory for writing temporary files. This does not create a new directory for each use, but either uses the user-set preference or gets the system-provided directory (with a music21 subdirectory, if possible).
- getTempFile(suffix=)¶
- Return a file path to a temporary file with the specified suffix
- keys()¶
- No documentation.
- launch(fmt, fp, options=)¶
- Opens a file with an either default or user-specified applications.
- loadDefaults()¶
- Load defaults. All keys are derived from these defaults.
- printDebug(msg, statusLevel=1)¶
- Format one or more data elements into string, and print it to stderr. The first arg can be a list of string; lists are concatenated with common.formatStr().
- restoreDefaults()¶
Restore only defaults for all parameters. Useful for testing.
>>> from music21 import * >>> a = music21.environment.Environment() >>> a['debug'] = 1 >>> a.restoreDefaults() >>> a['debug'] 0
- warn(msg)¶
- To print a warning to the user, send a list of strings to this method.