music21.common.classTools¶
Functions¶
-
music21.common.classTools.
classToClassStr
(classObj)¶ Convert a class object to a class string.
>>> common.classToClassStr(note.Note) 'Note' >>> common.classToClassStr(chord.Chord) 'Chord'
Return type: str
-
music21.common.classTools.
isIterable
(usrData)¶ Returns True if is the object can be iter’d over and is NOT a string
>>> common.isIterable([5, 10]) True >>> common.isIterable('sharp') False >>> common.isIterable((None, None)) True >>> common.isIterable(stream.Stream()) True
Return type: bool
-
music21.common.classTools.
isListLike
(usrData)¶ Returns True if is a List or Tuple
Formerly allowed for set here, but that does not allow for subscripting (set([1, 2, 3])[0] is undefined).
Differs from isinstance(collections.abc.Sequence()) in that we do not want Streams included even if __contains__, __reversed__, and count are added.
>>> common.isListLike([]) True >>> common.isListLike('sharp') False >>> common.isListLike((None, None)) True >>> common.isListLike(set(['a','b','c','c'])) False >>> common.isListLike(stream.Stream()) False
Return type: bool
-
music21.common.classTools.
isNum
(usrData)¶ check if usrData is a number (float, int, long, Decimal), return boolean
unlike isinstance(usrData, Number) does not return True for True, False.
Does not use isinstance(usrData, Number) which is 6 times slower than calling this function (except in the case of Fraction, when it’s 6 times faster, but that’s rarer)
Runs by adding 0 to the “number” – so anything that implements add to a scalar works
>>> common.isNum(3.0) True >>> common.isNum(3) True >>> common.isNum('three') False >>> common.isNum([2, 3, 4]) False
True and False are NOT numbers:
>>> common.isNum(True) False >>> common.isNum(False) False >>> common.isNum(None) False
Return type: bool
-
music21.common.classTools.
isStr
(usrData)¶ DEPRECATED: September 2015 – use isinstance(usrData, six.string_types) Remove April 2016
Will remove within six months of it not being used in music21.
Check of usrData is some form of string, including unicode.
>>> common.isStr(3) False >>> common.isStr('sharp') True >>> common.isStr(u'flat') True
Return type: bool