Warning
doxygenclass: Cannot find class “Py” in doxygen xml output for project “pythonnet” from directory: ../doxygen_xml
This class provides the public interface of the Python runtime.
Public Functions
Called when the engine is shut down.
Shutdown handlers are run in reverse order they were added, so that resources available when running a shutdown handler are the same as what was available when it was added.
Properties
Set totrue
to enable GIL debugging assistance.
Public Static Functions
Set the NoSiteFlag to disable loading the site module. Must be called before Initialize.https://docs.python.org/3/c-api/init.html#c.Py_NoSiteFlag.
Initialize Method.
Initialize the Python runtime. It is safe to call this method more than once, though initialization will only happen on the first call. It isnot necessary to hold the Python global interpreter lock (GIL) to call this method. initSigs can be set to 1 to do default python signal configuration. This will override the way signals are handled by the application.
A helper to perform initialization from the context of an active CPython interpreter process - this bootstraps the managed runtime when it is imported by the CLR extension module.
Shutdown and release resources held by the Python runtime. The Python runtime can no longer be used in the current process after calling the Shutdown method.
Add a function to be called when the engine is shut down.
Shutdown handlers are executed in the opposite order they were added, so that you can be sure that everything that was initialized when you added the handler is still initialized when you need to shut down.
If the same shutdown handler is added several times, it will be run several times.
Don’t add shutdown handlers while running a shutdown handler.
Remove a shutdown handler.
If the same shutdown handler is added several times, only the last one is removed.
Don’t remove shutdown handlers while running a shutdown handler.
BeginAllowThreads Method.
Release the Python global interpreter lock to allow other threads to run. This is equivalent to the Py_BEGIN_ALLOW_THREADS macro provided by the C Python API. For more information, see the “Extending and Embedding” section of the Python documentation on www.python.org.
EndAllowThreads Method.
Re-aquire the Python global interpreter lock for the current thread. This is equivalent to the Py_END_ALLOW_THREADS macro provided by the C Python API. For more information, see the “Extending and Embedding” section of the Python documentation on www.python.org.
Eval Method.
Evaluate a Python expression and returns the result. It’s a subset of Python eval function.
Exec Method.
Run a string containing Python code. It’s a subset of Python exec function.
Gets the Python thread ID.
The Python thread ID.
Interrupts the execution of a thread.
The Python thread ID.
The number of thread states modified; this is normally one, but will be zero if the thread id is not found.
Represents a generic Python object. The methods of this class are generally equivalent to the Python “abstract object API”. See PY2:https://docs.python.org/2/c-api/object.html PY3:https://docs.python.org/3/c-api/object.html for details.
Subclassed by Python.Runtime.NullOnly,Python.Runtime.PyIter,Python.Runtime.PyIterable,Python.Runtime.PyModule,Python.Runtime.PyNumber,Python.Runtime.PyType
Public Functions
AsManagedObject Method.
Return a managed object of the given type, based on the value of the Python object.
Return a managed object of the given type, based on the value of the Python object.
The Dispose method provides a way to explicitly release the Python object represented by aPyObject instance. It is a good idea to call Dispose on PyObjects that wrap resources that are limited or need strict lifetime control. Otherwise, references to Python objects will not be released until a managed garbage collection occurs.
GetPythonType Method.
Returns the Python type of the object. This method is equivalent to the Python expression: type(object).
TypeCheck Method.
Returns true if the object o is of type typeOrClass or a subtype of typeOrClass.
HasAttr Method.
Returns true if the object has an attribute with the given name.
HasAttr Method.
Returns true if the object has an attribute with the given name, where name is aPyObject wrapping a string or unicode object.
GetAttr Method.
Returns the named attribute of the Python object, or raises a PythonException if the attribute access fails.
Returns the named attribute of the Python object, or the given default object if the attribute access throws AttributeError.
This method ignores any AttrubiteError(s), even ones not raised due to missing requested attribute.
For example, if attribute getter calls other Python code, and that code happens to cause AttributeError elsewhere, it will be ignored and_default value will be returned instead.
Name of the attribute.
The object to return on AttributeError.
GetAttr Method.
Returns the named attribute of the Python object or raises a PythonException if the attribute access fails. The name argument is aPyObject wrapping a Python string or unicode object.
Returns the named attribute of the Python object, or the given default object if the attribute access throws AttributeError.
This method ignores any AttrubiteError(s), even ones not raised due to missing requested attribute.
For example, if attribute getter calls other Python code, and that code happens to cause AttributeError elsewhere, it will be ignored and_default value will be returned instead.
Name of the attribute. Must be of Python type ‘str’.
The object to return on AttributeError.
SetAttr Method.
Set an attribute of the object with the given name and value. This method throws a PythonException if the attribute set fails.
SetAttr Method.
Set an attribute of the object with the given name and value, where the name is a Python string or unicode object. This method throws a PythonException if the attribute set fails.
DelAttr Method.
Delete the named attribute of the Python object. This method throws a PythonException if the attribute set fails.
DelAttr Method.
Delete the named attribute of the Python object, where name is aPyObject wrapping a Python string or unicode object. This method throws a PythonException if the attribute set fails.
GetItem Method.
For objects that support the Python sequence or mapping protocols, return the item at the given object index. This method raises a PythonException if the indexing operation fails.
GetItem Method.
For objects that support the Python sequence or mapping protocols, return the item at the given string index. This method raises a PythonException if the indexing operation fails.
GetItem Method.
For objects that support the Python sequence or mapping protocols, return the item at the given numeric index. This method raises a PythonException if the indexing operation fails.
SetItem Method.
For objects that support the Python sequence or mapping protocols, set the item at the given object index to the given value. This method raises a PythonException if the set operation fails.
SetItem Method.
For objects that support the Python sequence or mapping protocols, set the item at the given string index to the given value. This method raises a PythonException if the set operation fails.
SetItem Method.
For objects that support the Python sequence or mapping protocols, set the item at the given numeric index to the given value. This method raises a PythonException if the set operation fails.
DelItem Method.
For objects that support the Python sequence or mapping protocols, delete the item at the given object index. This method raises a PythonException if the delete operation fails.
DelItem Method.
For objects that support the Python sequence or mapping protocols, delete the item at the given string index. This method raises a PythonException if the delete operation fails.
DelItem Method.
For objects that support the Python sequence or mapping protocols, delete the item at the given numeric index. This method raises a PythonException if the delete operation fails.
Returns the length for objects that support the Python sequence protocol.
Return a new (Python) iterator for the object. This is equivalent to the Python expression “iter(object)”.
Thrown if the object can not be iterated.
Invoke Method.
Invoke the callable object with the given arguments, passed as aPyObject[]. A PythonException is raised if the invocation fails.
Invoke Method.
Invoke the callable object with the given arguments, passed as a Python tuple. A PythonException is raised if the invocation fails.
Invoke Method.
Invoke the callable object with the given positional and keyword arguments. A PythonException is raised if the invocation fails.
Invoke Method.
Invoke the callable object with the given positional and keyword arguments. A PythonException is raised if the invocation fails.
InvokeMethod Method.
Invoke the named method of the object with the given arguments. A PythonException is raised if the invocation is unsuccessful.
InvokeMethod Method.
Invoke the named method of the object with the given arguments. A PythonException is raised if the invocation is unsuccessful.
InvokeMethod Method.
Invoke the named method of the object with the given arguments. A PythonException is raised if the invocation is unsuccessful.
InvokeMethod Method.
Invoke the named method of the object with the given arguments. A PythonException is raised if the invocation is unsuccessful.
InvokeMethod Method.
Invoke the named method of the object with the given arguments and keyword arguments. Keyword args are passed as aPyDict object. A PythonException is raised if the invocation is unsuccessful.
InvokeMethod Method.
Invoke the named method of the object with the given arguments and keyword arguments. Keyword args are passed as aPyDict object. A PythonException is raised if the invocation is unsuccessful.
IsInstance Method.
Return true if the object is an instance of the given Python type or class. This method always succeeds.
Returntrue
if the object is identical to or derived from the given Python type or class. This method always succeeds.
IsCallable Method.
Returns true if the object is a callable object. This method always succeeds.
IsIterable Method.
Returns true if the object is iterable object. This method always succeeds.
IsTrue Method.
Return true if the object is true according to Python semantics. This method always succeeds.
Return true if the object is None.
Dir Method.
Return a list of the names of the attributes of the object. This is equivalent to the Python expression “dir(object)”.
Repr Method.
Return a string representation of the object. This method is the managed equivalent of the Python expression “repr(object)”.
ToString Method.
Return the string representation of the object. This method is the managed equivalent of the Python expression “str(object)”.
Equals Method.
Return true if this object is equal to the given object. This method is based on Python equality semantics.
GetHashCode Method.
Return a hashcode based on the Python object. This returns the hash as computed by Python, equivalent to the Python expression “hash(obj)”.
GetBuffer Method. This Method only works for objects that have a buffer (like “bytes”, “bytearray” or “array.array”)
Send a request to thePyObject to fill in view as specified by flags. If thePyObject cannot provide a buffer of the exact type, it MUST raise PyExc_BufferError, set view->obj to NULL and return -1. On success, fill in view, set view->obj to a new reference to exporter and return 0. In the case of chained buffer providers that redirect requests to a single object, view->obj MAY refer to this object instead of exporter(See Buffer Object Structures). Successful calls toPyObject.GetBuffer must be paired with calls toPyBuffer.Dispose(), similar to malloc() and free(). Thus, after the consumer is done with the buffer,PyBuffer.Dispose() must be called exactly once.
Returns the enumeration of all dynamic member names.
This method exists for debugging purposes only.
A sequence that contains dynamic member names.
Properties
Gets the native handle of the underlying Python object. This value is generally for internal use by the PythonNet runtime.
String Indexer.
Provides a shorthand for the string versions of the GetItem and SetItem methods.
PyObject Indexer.
Provides a shorthand for the object versions of the GetItem and SetItem methods.
Numeric Indexer.
Provides a shorthand for the numeric versions of the GetItem and SetItem methods.
Represents a Python dictionary object. See the documentation at PY2:https://docs.python.org/2/c-api/dict.html PY3:https://docs.python.org/3/c-api/dict.html for details.
Subclassed by Python.Runtime.Py.KeywordArguments
Public Functions
Creates a new Python dictionary object.
Wraps existing dictionary object.
Thrown if the given object is not a Python dictionary object
HasKey Method.
Returns true if the string key appears in the dictionary.
Keys Method.
Returns a sequence containing the keys of the dictionary.
Values Method.
Returns a sequence containing the values of the dictionary.
Items Method.
Returns a sequence containing the items of the dictionary.
Clear Method.
Clears the dictionary.
Represents a Python tuple object. See the documentation at PY2:https://docs.python.org/2/c-api/tupleObjects.html PY3:https://docs.python.org/3/c-api/tupleObjects.html for details.
Public Functions
PyTuple Constructor.
Copy constructor - obtain aPyTuple from a genericPyObject. An ArgumentException will be thrown if the given object is not a Python tuple object.
PyTuple Constructor.
Creates a newPyTuple from an array ofPyObject instances.
See caveats about PyTuple_SetItem:https://www.coursehero.com/file/p4j2ogg/important-exceptions-to-this-rule-PyTupleSetItem-and-PyListSetItem-These/
Public Static Functions
Represents a standard Python list object. See the documentation at PY2:https://docs.python.org/2/c-api/list.html PY3:https://docs.python.org/3/c-api/list.html for details.
Public Functions
PyList Constructor.
Copy constructor - obtain aPyList from a genericPyObject. An ArgumentException will be thrown if the given object is not a Python list object.
Creates a new empty Python list object.
Creates a new Python list object from an array of objects.
Reverse Method.
Reverse the order of the list object in place.
Sort Method.
Sort the list in place.
Public Static Functions
Represents a Python integer object. See the documentation athttps://docs.python.org/3/c-api/long.html.
Public Functions
PyInt Constructor.
Copy constructor - obtain aPyInt from a genericPyObject. An ArgumentException will be thrown if the given object is not a Python int object.
PyInt Constructor.
Creates a new Python int from an int32 value.
PyInt Constructor.
Creates a new Python int from a uint32 value.
PyInt Constructor.
Creates a new Python int from an int64 value.
Creates a new Python int from a UInt64 value.
PyInt Constructor.
Creates a new Python int from an int16 value.
PyInt Constructor.
Creates a new Python int from a uint16 value.
PyInt Constructor.
Creates a new Python int from a byte value.
PyInt Constructor.
Creates a new Python int from an sbyte value.
PyInt Constructor.
Creates a new Python int from a string value.
ToInt16 Method.
Return the value of the Python int object as an int16.
Return the value of the Python int object as an Int32.
ToInt64 Method.
Return the value of the Python int object as an int64.
Public Static Functions
Represents a Python (ANSI) string object. See the documentation at PY2:https://docs.python.org/2/c-api/string.html PY3: No Equivalent for details.
2011-01-29: …Then why does the string constructor call PyUnicode_FromUnicode()???
Subclassed by Python.Runtime.ReflectedClrType
Public Functions
Wraps an existing type object.
Properties
Returnstrue
when type is fully initialized.
Public Functions
Import module as a variable of given name.
The ‘import .. as ..’ statement in Python. Import a module as a variable.
Import all variables of the module into this module.
Import all variables in the dictionary into this module.
Execute method.
Execute a Python ast and return the result as aPyObject. The ast can be either an expression or stmts.
Execute a Python ast and return the result as aPyObject, and convert the result to a Managed Object of given type. The ast can be either an expression or stmts.
Evaluate a Python expression and return the result as aPyObject.
Evaluate a Python expression.
Evaluate a Python expression and convert the result to a Managed Object of given type.
Exec Method.
Exec a Python script and save its local variables in the current local variable dict.
Set Variable Method.
Add a new variable to the variables dict if it not exist or update its value if the variable exists.
Returns true if the variable exists in the module.
Returns the value of the variable with the given name.
Thrown when variable with the given name does not exist.
TryGet Method.
Returns the value of the variable, local variable first. If the variable does not exist, return null.
Get Method.
Obtain the value of the variable of given name, and convert the result to a Managed Object of given type. If the variable does not exist, throw an Exception.
TryGet Method.
Obtain the value of the variable of given name, and convert the result to a Managed Object of given type. If the variable does not exist, return false.
Public Static Functions
Given a module or package name, import the module and return the resulting object.
Fully-qualified module or package name
Represents a standard Python iterator object. See the documentation at PY2:https://docs.python.org/2/c-api/iterator.html PY3:https://docs.python.org/3/c-api/iterator.html for details.
Public Functions
Public Functions
Returns true if the memory defined by the view is C-style (order is ‘C’) or Fortran-style (order is ‘F’) contiguous or either one (order is ‘A’). Returns false otherwise.
C-style (order is ‘C’) or Fortran-style (order is ‘F’) contiguous or either one (order is ‘A’)
Get the memory area pointed to by the indices inside the given view. indices must point to an array of view->ndim indices.
Copy contiguous len bytes from buf to view. fort can be ‘C’ or ‘F’ (for C-style or Fortran-style ordering).
Copy len bytes from view to its contiguous representation in buf. order can be ‘C’ or ‘F’ or ‘A’ (for C-style or Fortran-style ordering or either one). 0 is returned on success, -1 on error.
order can be ‘C’ or ‘F’ or ‘A’ (for C-style or Fortran-style ordering or either one).
Buffer to copy to
Writes a managed byte array into the buffer of a python object. This can be used to pass data like images from managed to python.
Reads the buffer of a python object into a managed byte array. This can be used to pass data like images from python to managed.
Release the buffer view and decrement the reference count for view->obj. This function MUST be called when the buffer is no longer being used, otherwise reference leaks may occur. It is an error to call this function on a buffer that was not obtained viaPyObject.GetBuffer.
Properties
An array of length Dimensions indicating the shape of the memory as an n-dimensional array.
An array of length Dimensions giving the number of bytes to skip to get to a new element in each dimension. Will be null except when PyBUF_STRIDES or PyBUF_INDIRECT flags in GetBuffer/>.
An array of Py_ssize_t of length ndim. If suboffsets[n] >= 0, the values stored along the nth dimension are pointers and the suboffset value dictates how many bytes to add to each pointer after de-referencing. A suboffset value that is negative indicates that no de-referencing should occur (striding in a contiguous memory block).
Public Static Functions
Return the implied itemsize from format. On error, raise an exception and return -1. New in version 3.9.
Subclassed byPython.Runtime.PyDict,Python.Runtime.PySequence
Represents a generic Python sequence. The methods of this class are equivalent to the Python “abstract sequence API”. See PY2:https://docs.python.org/2/c-api/sequence.html PY3:https://docs.python.org/3/c-api/sequence.html for details.
Subclassed byPython.Runtime.PyList,Python.Runtime.PyString,Python.Runtime.PyTuple
Public Functions
Creates new instance from an existing object.
o does not provide sequence protocol
DelSlice Method.
Deletes the slice of the sequence with the given indices.
Return the index of the given item in the sequence, or -1 if the item does not appear in the sequence.
Return the index of the given item in the sequence, or -1 if the item does not appear in the sequence.
Return the index of the given item in the sequence, or -1 if the item does not appear in the sequence.
Return true if the sequence contains the given item. This method throws a PythonException if an error occurs during the check.
Represents a generic Python number. The methods of this class are equivalent to the Python “abstract number API”. See PY3:https://docs.python.org/3/c-api/number.html for details.
TODO: add all of the PyNumber_XXX methods.
Subclassed by Python.Runtime.PyFloat,Python.Runtime.PyInt
Python::Runtime::PythonEngine
Python::Runtime::PyObject
AsManagedObject()
As<T>()
Dispose()
GetPythonType()
TypeCheck()
HasAttr()
GetAttr()
SetAttr()
DelAttr()
GetItem()
SetItem()
DelItem()
Length()
GetIterator()
Invoke()
InvokeMethod()
IsInstance()
IsSubclass()
IsCallable()
IsIterable()
IsTrue()
IsNone()
Dir()
Repr()
Equals()
GetHashCode()
GetBuffer()
GetDynamicMemberNames()
Handle
FromManagedObject()
Python::Runtime::PyDict
Python::Runtime::PyTuple
Python::Runtime::PyList
Python::Runtime::PyInt
Python::Runtime::PyString
Python::Runtime::PyType
Python::Runtime::PyModule
Python::Runtime::PyIter
Python::Runtime::PyBuffer
BufferOrderStyle
Python::Runtime::PyIterable
Python::Runtime::PySequence
Python::Runtime::PyNumber