Movatterモバイル変換


[0]ホーム

URL:


ContentsMenuExpandLight modeDark modeAuto light/dark, in light modeAuto light/dark, in dark modeSkip to content
Python.NET documentation
Python.NET documentation

Contents:

Back to top

C# Reference

Warning

doxygenclass: Cannot find class “Py” in doxygen xml output for project “pythonnet” from directory: ../doxygen_xml

classPython.Runtime.PythonEngine:IDisposable

This class provides the public interface of the Python runtime.

Public Functions

delegatevoidShutdownHandler()

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

boolDebugGIL{get;set;}=false

Set totrue to enable GIL debugging assistance.

Public Static Functions

voidSetNoSiteFlag()

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.

voidInitialize(IEnumerable<string>args,boolsetSysArgv=true,boolinitSigs=false)

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.

IntPtrInitExt()

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.

voidShutdown()

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.

voidAddShutdownHandler(ShutdownHandlerhandler)

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.

voidRemoveShutdownHandler(ShutdownHandlerhandler)

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.

unsafeIntPtrBeginAllowThreads()

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.

unsafevoidEndAllowThreads(IntPtrts)

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.

PyObjectEval(stringcode,PyDict?globals=null,PyObject?locals=null)

Eval Method.

Evaluate a Python expression and returns the result. It’s a subset of Python eval function.

voidExec(stringcode,PyDict?globals=null,PyObject?locals=null)

Exec Method.

Run a string containing Python code. It’s a subset of Python exec function.

ulongGetPythonThreadID()

Gets the Python thread ID.

Return:

The Python thread ID.

intInterrupt(ulongpythonThreadID)

Interrupts the execution of a thread.

Param pythonThreadID:

The Python thread ID.

Return:

The number of thread states modified; this is normally one, but will be zero if the thread id is not found.

PyObjectRunString(stringcode,PyDict?globals=null,PyObject?locals=null)

RunString Method. Function has been deprecated and will be removed. Use Exec/Eval/RunSimpleString instead.

classPython.Runtime.PyObject:DynamicObject,IDisposable,ISerializable,IConvertible

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

object?AsManagedObject(Typet)

AsManagedObject Method.

Return a managed object of the given type, based on the value of the Python object.

TAs<T>()

Return a managed object of the given type, based on the value of the Python object.

voidDispose()

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.

PyTypeGetPythonType()

GetPythonType Method.

Returns the Python type of the object. This method is equivalent to the Python expression: type(object).

boolTypeCheck(PyTypetypeOrClass)

TypeCheck Method.

Returns true if the object o is of type typeOrClass or a subtype of typeOrClass.

boolHasAttr(stringname)

HasAttr Method.

Returns true if the object has an attribute with the given name.

boolHasAttr(PyObjectname)

HasAttr Method.

Returns true if the object has an attribute with the given name, where name is aPyObject wrapping a string or unicode object.

PyObjectGetAttr(stringname)

GetAttr Method.

Returns the named attribute of the Python object, or raises a PythonException if the attribute access fails.

PyObjectGetAttr(stringname,PyObject_default)

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.

Param name:

Name of the attribute.

Param _default:

The object to return on AttributeError.

PyObjectGetAttr(PyObjectname)

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.

PyObjectGetAttr(PyObjectname,PyObject_default)

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.

Param name:

Name of the attribute. Must be of Python type ‘str’.

Param _default:

The object to return on AttributeError.

voidSetAttr(stringname,PyObjectvalue)

SetAttr Method.

Set an attribute of the object with the given name and value. This method throws a PythonException if the attribute set fails.

voidSetAttr(PyObjectname,PyObjectvalue)

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.

voidDelAttr(stringname)

DelAttr Method.

Delete the named attribute of the Python object. This method throws a PythonException if the attribute set fails.

voidDelAttr(PyObjectname)

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.

PyObjectGetItem(PyObjectkey)

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.

PyObjectGetItem(stringkey)

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.

PyObjectGetItem(intindex)

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.

voidSetItem(PyObjectkey,PyObjectvalue)

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.

voidSetItem(stringkey,PyObjectvalue)

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.

voidSetItem(intindex,PyObjectvalue)

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.

voidDelItem(PyObjectkey)

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.

voidDelItem(stringkey)

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.

voidDelItem(intindex)

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.

longLength()

Returns the length for objects that support the Python sequence protocol.

PyIterGetIterator()

Return a new (Python) iterator for the object. This is equivalent to the Python expression “iter(object)”.

Throws PythonException:

Thrown if the object can not be iterated.

PyObjectInvoke(paramsPyObject[]args)

Invoke Method.

Invoke the callable object with the given arguments, passed as aPyObject[]. A PythonException is raised if the invocation fails.

PyObjectInvoke(PyTupleargs)

Invoke Method.

Invoke the callable object with the given arguments, passed as a Python tuple. A PythonException is raised if the invocation fails.

PyObjectInvoke(PyObject[]args,PyDict?kw)

Invoke Method.

Invoke the callable object with the given positional and keyword arguments. A PythonException is raised if the invocation fails.

PyObjectInvoke(PyTupleargs,PyDict?kw)

Invoke Method.

Invoke the callable object with the given positional and keyword arguments. A PythonException is raised if the invocation fails.

PyObjectInvokeMethod(stringname,paramsPyObject[]args)

InvokeMethod Method.

Invoke the named method of the object with the given arguments. A PythonException is raised if the invocation is unsuccessful.

PyObjectInvokeMethod(stringname,PyTupleargs)

InvokeMethod Method.

Invoke the named method of the object with the given arguments. A PythonException is raised if the invocation is unsuccessful.

PyObjectInvokeMethod(PyObjectname,paramsPyObject[]args)

InvokeMethod Method.

Invoke the named method of the object with the given arguments. A PythonException is raised if the invocation is unsuccessful.

PyObjectInvokeMethod(PyObjectname,PyTupleargs)

InvokeMethod Method.

Invoke the named method of the object with the given arguments. A PythonException is raised if the invocation is unsuccessful.

PyObjectInvokeMethod(stringname,PyObject[]args,PyDict?kw)

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.

PyObjectInvokeMethod(stringname,PyTupleargs,PyDict?kw)

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.

boolIsInstance(PyObjecttypeOrClass)

IsInstance Method.

Return true if the object is an instance of the given Python type or class. This method always succeeds.

boolIsSubclass(PyObjecttypeOrClass)

Returntrue if the object is identical to or derived from the given Python type or class. This method always succeeds.

boolIsCallable()

IsCallable Method.

Returns true if the object is a callable object. This method always succeeds.

boolIsIterable()

IsIterable Method.

Returns true if the object is iterable object. This method always succeeds.

boolIsTrue()

IsTrue Method.

Return true if the object is true according to Python semantics. This method always succeeds.

boolIsNone()

Return true if the object is None.

PyListDir()

Dir Method.

Return a list of the names of the attributes of the object. This is equivalent to the Python expression “dir(object)”.

string?Repr()

Repr Method.

Return a string representation of the object. This method is the managed equivalent of the Python expression “repr(object)”.

override?stringToString()

ToString Method.

Return the string representation of the object. This method is the managed equivalent of the Python expression “str(object)”.

overrideboolEquals(objecto)

Equals Method.

Return true if this object is equal to the given object. This method is based on Python equality semantics.

overrideintGetHashCode()

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)”.

PyBufferGetBuffer(PyBUFflags=PyBUF.SIMPLE)

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.

overrideIEnumerable<string>GetDynamicMemberNames()

Returns the enumeration of all dynamic member names.

This method exists for debugging purposes only.

Return:

A sequence that contains dynamic member names.

Properties

IntPtrHandle{get;set;}

Gets the native handle of the underlying Python object. This value is generally for internal use by the PythonNet runtime.

PyObjectthis[stringkey]{get;set;}

String Indexer.

Provides a shorthand for the string versions of the GetItem and SetItem methods.

PyObjectthis[PyObjectkey]{get;set;}

PyObject Indexer.

Provides a shorthand for the object versions of the GetItem and SetItem methods.

PyObjectthis[intindex]{get;set;}

Numeric Indexer.

Provides a shorthand for the numeric versions of the GetItem and SetItem methods.

Public Static Functions

PyObjectFromManagedObject(objectob)

Gets raw Python proxy for this object (bypasses all conversions, exceptnull <==>None)

Given an arbitrary managed object, return a Python instance that reflects the managed object.

classPython.Runtime.PyDict:Python.Runtime.PyIterable

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

PyDict()

Creates a new Python dictionary object.

PyDict(PyObjecto)

Wraps existing dictionary object.

Throws ArgumentException:

Thrown if the given object is not a Python dictionary object

boolHasKey(PyObjectkey)

HasKey Method.

Returns true if the object key appears in the dictionary.

boolHasKey(stringkey)

HasKey Method.

Returns true if the string key appears in the dictionary.

PyIterableKeys()

Keys Method.

Returns a sequence containing the keys of the dictionary.

PyIterableValues()

Values Method.

Returns a sequence containing the values of the dictionary.

PyIterableItems()

Items Method.

Returns a sequence containing the items of the dictionary.

PyDictCopy()

Copy Method.

Returns a copy of the dictionary.

voidUpdate(PyObjectother)

Update Method.

Update the dictionary from another dictionary.

voidClear()

Clear Method.

Clears the dictionary.

Public Static Functions

boolIsDictType(PyObjectvalue)

IsDictType Method.

Returns true if the given object is a Python dictionary.

classPython.Runtime.PyTuple:Python.Runtime.PySequence

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(PyObjecto)

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()

PyTuple Constructor.

Creates a new emptyPyTuple.

PyTuple(PyObject[]items)

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

boolIsTupleType(PyObjectvalue)

Returnstrue if the given object is a Python tuple.

PyTupleAsTuple(PyObjectvalue)

Convert a Python object to a Python tuple if possible. This is equivalent to the Python expression “tuple(<paramref name=”value”/>)”.

Throws PythonException:

Raised if the object can not be converted to a tuple.

classPython.Runtime.PyList:Python.Runtime.PySequence

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(PyObjecto)

PyList Constructor.

Copy constructor - obtain aPyList from a genericPyObject. An ArgumentException will be thrown if the given object is not a Python list object.

PyList()

Creates a new empty Python list object.

PyList(PyObject[]items)

Creates a new Python list object from an array of objects.

voidAppend(PyObjectitem)

Append an item to the list object.

voidInsert(intindex,PyObjectitem)

Insert an item in the list object at the given index.

voidReverse()

Reverse Method.

Reverse the order of the list object in place.

voidSort()

Sort Method.

Sort the list in place.

Public Static Functions

boolIsListType(PyObjectvalue)

Returns true if the given object is a Python list.

PyListAsList(PyObjectvalue)

Converts a Python object to a Python list if possible, raising a PythonException if the conversion is not possible. This is equivalent to the Python expression “list(object)”.

classPython.Runtime.PyInt:Python.Runtime.PyNumber,IFormattable,IComparable<long>,IComparable<int>,IComparable<sbyte>,IComparable<short>,IComparable<ulong>,IComparable<uint>,IComparable<ushort>,IComparable<byte>,IEquatable<long>,IEquatable<int>,IEquatable<short>,IEquatable<sbyte>,IEquatable<ulong>,IEquatable<uint>,IEquatable<ushort>,IEquatable<byte>,IComparable<PyInt?>,IEquatable<PyInt?>

Represents a Python integer object. See the documentation athttps://docs.python.org/3/c-api/long.html.

Public Functions

PyInt(PyObjecto)

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(intvalue)

PyInt Constructor.

Creates a new Python int from an int32 value.

PyInt(uintvalue)

PyInt Constructor.

Creates a new Python int from a uint32 value.

PyInt(longvalue)

PyInt Constructor.

Creates a new Python int from an int64 value.

PyInt(ulongvalue)

Creates a new Python int from a UInt64 value.

PyInt(shortvalue)

PyInt Constructor.

Creates a new Python int from an int16 value.

PyInt(ushortvalue)

PyInt Constructor.

Creates a new Python int from a uint16 value.

PyInt(bytevalue)

PyInt Constructor.

Creates a new Python int from a byte value.

PyInt(sbytevalue)

PyInt Constructor.

Creates a new Python int from an sbyte value.

PyInt(stringvalue)

PyInt Constructor.

Creates a new Python int from a string value.

shortToInt16()

ToInt16 Method.

Return the value of the Python int object as an int16.

intToInt32()

Return the value of the Python int object as an Int32.

longToInt64()

ToInt64 Method.

Return the value of the Python int object as an int64.

Public Static Functions

boolIsIntType(PyObjectvalue)

IsIntType Method.

Returns true if the given object is a Python int.

PyIntAsInt(PyObjectvalue)

Convert a Python object to a Python int if possible, raising a PythonException if the conversion is not possible. This is equivalent to the Python expression “int(object)”.

classPython.Runtime.PyString:Python.Runtime.PySequence,IComparable<string>,IEquatable<string>

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()???

Public Functions

PyString(PyObjecto)

PyString Constructor.

Copy constructor - obtain aPyString from a genericPyObject. An ArgumentException will be thrown if the given object is not a Python string object.

PyString(strings)

PyString Constructor.

Creates a Python string from a managed string.

Public Static Functions

boolIsStringType(PyObjectvalue)

Returns true if the given object is a Python string.

classPython.Runtime.PyType:Python.Runtime.PyObject

Subclassed by Python.Runtime.ReflectedClrType

Public Functions

PyType(TypeSpecspec,PyTuple?bases=null)

Creates heap type object from thespec .

PyType(PyObjecto)

Wraps an existing type object.

Properties

boolIsReady{get;set;}

Returnstrue when type is fully initialized.

Public Static Functions

boolIsType(PyObjectvalue)

Checks if specified object is a Python type.

PyTypeGet(TypeclrType)

GetsPyType, which represents the specified CLR type.

classPython.Runtime.PyModule:Python.Runtime.PyObject

Public Functions

PyModuleReload()

Reloads the module, and returns the updated object.

PyDictVariables()

Returns the variables dict of the module.

PyModuleNewScope()

Create a scope, and import all from this scope.

PyObjectImport(stringname,string?asname=null)

Import module by its name.

voidImport(PyModulemodule,stringasname)

Import module as a variable of given name.

voidImport(PyObjectmodule,string?asname=null)

The ‘import .. as ..’ statement in Python. Import a module as a variable.

voidImportAll(PyModulemodule)

Import all variables of the module into this module.

voidImportAll(PyObjectmodule)

Import all variables of the module into this module.

voidImportAll(PyDictdict)

Import all variables in the dictionary into this module.

PyObjectExecute(PyObjectscript,PyDict?locals=null)

Execute method.

Execute a Python ast and return the result as aPyObject. The ast can be either an expression or stmts.

T?Execute<T>(PyObjectscript,PyDict?locals=null)

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.

PyObjectEval(stringcode,PyDict?locals=null)

Evaluate a Python expression and return the result as aPyObject.

T?Eval<T>(stringcode,PyDict?locals=null)

Evaluate a Python expression.

Evaluate a Python expression and convert the result to a Managed Object of given type.

PyModuleExec(stringcode,PyDict?locals=null)

Exec Method.

Exec a Python script and save its local variables in the current local variable dict.

PyModuleSet(stringname,object?value)

Set Variable Method.

Add a new variable to the variables dict if it not exist or update its value if the variable exists.

PyModuleRemove(stringname)

Remove Method.

Remove a variable from the variables dict.

boolContains(stringname)

Returns true if the variable exists in the module.

PyObjectGet(stringname)

Returns the value of the variable with the given name.

Throws KeyNotFoundException:

Thrown when variable with the given name does not exist.

boolTryGet(stringname,outPyObject?value)

TryGet Method.

Returns the value of the variable, local variable first. If the variable does not exist, return null.

TGet<T>(stringname)

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.

boolTryGet<T>(stringname,outT?value)

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

PyObjectImport(stringname)

Given a module or package name, import the module and return the resulting object.

Param name:

Fully-qualified module or package name

classPython.Runtime.PyIter:Python.Runtime.PyObject,IEnumerator<PyObject>

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

PyIter(PyObjectpyObject)

Creates newPyIter from an untyped reference to Python object. The object must support iterator protocol.

Public Static Functions

PyIterGetIter(PyObjectiterable)

Create a newPyIter from a given iterable.

Like doing “iter(<paramref name=”iterable”/>)” in Python.

classPython.Runtime.PyBuffer:IDisposable

Public Functions

boolIsContiguous(BufferOrderStyleorder)

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.

Param order:

C-style (order is ‘C’) or Fortran-style (order is ‘F’) contiguous or either one (order is ‘A’)

IntPtrGetPointer(long[]indices)

Get the memory area pointed to by the indices inside the given view. indices must point to an array of view->ndim indices.

voidFromContiguous(IntPtrbuf,longlen,BufferOrderStylefort)

Copy contiguous len bytes from buf to view. fort can be ‘C’ or ‘F’ (for C-style or Fortran-style ordering).

voidToContiguous(IntPtrbuf,BufferOrderStyleorder)

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.

Param order:

order can be ‘C’ or ‘F’ or ‘A’ (for C-style or Fortran-style ordering or either one).

Param buf:

Buffer to copy to

voidWrite(byte[]buffer,intsourceOffset,intcount,nintdestinationOffset)

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.

voidRead(byte[]buffer,intdestinationOffset,intcount,nintsourceOffset)

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.

voidDispose()

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

long?[]Shape{get;set;}

An array of length Dimensions indicating the shape of the memory as an n-dimensional array.

long?[]Strides{get;set;}

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/>.

long?[]SubOffsets{get;set;}

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

longSizeFromFormat(stringformat)

Return the implied itemsize from format. On error, raise an exception and return -1. New in version 3.9.

enumPython.Runtime.BufferOrderStyle

Values:

C
Fortran
EitherOne
classPython.Runtime.PyIterable:Python.Runtime.PyObject,IEnumerable<PyObject>

Subclassed byPython.Runtime.PyDict,Python.Runtime.PySequence

Public Functions

PyIterable(PyObjecto)

Creates new instance from an existing object.

This constructor does not check ifo is actually iterable.

PyIterGetEnumerator()

Return a newPyIter object for the object. This allows any iterable python object to be iterated over in C#. A PythonException will be raised if the object is not iterable.

classPython.Runtime.PySequence:Python.Runtime.PyIterable

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

PySequence(PyObjecto)

Creates new instance from an existing object.

Throws ArgumentException:

o does not provide sequence protocol

PyObjectGetSlice(inti1,inti2)

Return the slice of the sequence with the given indices.

voidSetSlice(inti1,inti2,PyObjectv)

Sets the slice of the sequence with the given indices.

voidDelSlice(inti1,inti2)

DelSlice Method.

Deletes the slice of the sequence with the given indices.

nintIndex(PyObjectitem)

Return the index of the given item in the sequence, or -1 if the item does not appear in the sequence.

intIndex32(PyObjectitem)

Return the index of the given item in the sequence, or -1 if the item does not appear in the sequence.

longIndex64(PyObjectitem)

Return the index of the given item in the sequence, or -1 if the item does not appear in the sequence.

boolContains(PyObjectitem)

Return true if the sequence contains the given item. This method throws a PythonException if an error occurs during the check.

PyObjectConcat(PyObjectother)

Return the concatenation of the sequence object with the passed in sequence object.

PyObjectRepeat(intcount)

Return the sequence object repeated N times. This is equivalent to the Python expression “object * count”.

Public Static Functions

boolIsSequenceType(PyObjectvalue)

Returnstrue if the given object implements the sequence protocol.

classPython.Runtime.PyNumber:Python.Runtime.PyObject

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

Public Static Functions

boolIsNumberType(PyObjectvalue)

IsNumberType Method.

Returns true if the given object is a Python numeric type.

On this page

[8]ページ先頭

©2009-2025 Movatter.jp