Common functions., enum, prefix=None, to_upper=False, strict=True)[source]

Convert obj to an Enum member.

  • obj (object) – Any object to be converted to the specified enum. Can be a value of member of the specified enum.

  • enum (Type[Enum]) – The Enum object that obj should be converted to.

  • prefix (str, optional) – If obj is a str, then ensures that prefix is included at the beginning of obj before converting obj to the enum.

  • to_upper (bool, optional) – If obj is a str, then whether to change obj to be upper case before converting obj to the enum.

  • strict (bool, optional) – Whether errors should be raised. If False and obj cannot be converted to enum then obj is returned and the error is logged.


Enum – The enum member.


ValueError – If obj is not in enum and strict is True.[source]

Convert text into a primitive value.


text (str or bytes) – The text to convert.


  • The text as a None, bool, int,

  • float or complex object. Returns the

  • original text if it cannot be converted to any of these types.

  • The text 0 and 1 get converted to an integer not a boolean., fmt='%Y-%m-%d', strict=True)[source]

Convert an object to a object.

Returns: – A object., indent='  ', encoding='utf-8', fix_newlines=True)[source]

Convert an XML Element in to a string with proper indentation.

  • element (Element) – The element to convert.

  • indent (str, optional) – The value to use for the indentation.

  • encoding (str, optional) – The encoding to use.

  • fix_newlines (bool, optional) – Whether to remove newlines inside text nodes.


str – The element as a pretty string. The returned value can be directly written to a file (i.e., it includes the XML declaration).


If the Element contains unicode characters then you should use the codecs module to create the file if you are using Python 2.7:

import codecs
with'my_file.xml', mode='w', encoding='utf-8') as fp:

otherwise you can use the builtin open() function:

with open('my_file.xml', mode='w', encoding='utf-8') as fp:
    fp.write(convert_to_xml_string(element)), text=None, tail=None, **attributes)[source]

Create a new XML element.

  • tag (str) – The element’s name.

  • text (str, optional) – The text before the first sub-element. Can either be a string or None.

  • tail (str, optional) – The text after this element’s end tag, but before the next sibling element’s start tag.

  • attributes – All additional key-value pairs are included as XML attributes for the element. The value must be of type str.


Element – The new XML element.[source]

Create a new XML comment element.


text (str) – The comment.


Comment() – A special element that is an XML comment., fmt='ieee', dtype='<f')[source]

Convert an iterable of numbers into bytes.

  • iterable – An object to convert to bytes. Must be a 1-dimensional sequence of elements (not a multidimensional array).

  • fmt (str or None, optional) –

    The format to use to convert iterable. Possible values are:

    • '' (empty string or None) – convert iterable to bytes without a header.

      None: <byte><byte><byte>...

    • 'ascii' – comma-separated ASCII characters, see the <PROGRAM DATA SEPARATOR> standard that is defined in Section, IEEE 488.2-1992.

      ascii: <string>,<string>,<string>,...

    • 'ieee' – arbitrary block data for SCPI messages, see the <DEFINITE LENGTH ARBITRARY BLOCK RESPONSE DATA> standard that is defined in Section 8.7.9, IEEE 488.2-1992.

      ieee: #<length of num bytes value><num bytes><byte><byte><byte>...

    • 'hp' – the HP-IB data transfer standard, i.e., the FORM# command option. See the programming guide for an HP 8530A for more details.

      hp: #A<num bytes as uint16><byte><byte><byte>...

  • dtype – The data type to use to convert each element in iterable to. If fmt is 'ascii' then dtype must be of type str and it is used as the format_spec argument in format() to first convert each element in iterable to a string, and then it is encoded (e.g., '.2e' converts each element to scientific notation with two digits after the decimal point). If dtype includes a byte-order character, it is ignored. For all other values of fmt, the dtype can be any object that numpy.dtype supports (e.g., 'H', 'uint16' and numpy.ushort are equivalent values to convert each element to an unsigned short). If a byte-order character is specified then it is used, otherwise the native byte order of the CPU architecture is used. See Format Strings for more details.


bytes – The iterable converted to bytes., fmt='ieee', dtype='<f')[source]

Convert bytes into an array.

  • buffer (bytes, bytearray or str) – A byte buffer. Can be an already-decoded buffer of type str, but only if fmt equals 'ascii'.

  • fmt (str or None, optional) – The format that buffer is in. See to_bytes() for more details.

  • dtype – The data type of each element in buffer. Can be any object that numpy.dtype supports. See to_bytes() for more details.


numpy.ndarray – The array. set[str][source]

Get all IPv4 addresses on all network interfaces., port=80, timeout=1)[source]

Get the information about an LXI device from the device’s webserver.

  • host (str) – The IP address or hostname of the LXI device.

  • port (int, optional) – The port number of the device’s webservice.

  • timeout (float, optional) – The maximum number of seconds to wait for a reply.


dict – The information about the LXI device.