PythonObject

@dynamicCallable
@dynamicMemberLookup
public struct PythonObject
extension PythonObject : CustomStringConvertible
extension PythonObject : CustomPlaygroundDisplayConvertible
extension PythonObject : CustomReflectable
extension PythonObject : PythonConvertible, ConvertibleFromPython
extension PythonObject : SignedNumeric
extension PythonObject : Strideable
extension PythonObject : Equatable, Comparable
extension PythonObject : Hashable
extension PythonObject : MutableCollection
extension PythonObject : Sequence
extension PythonObject : ExpressibleByBooleanLiteral, ExpressibleByIntegerLiteral,
ExpressibleByFloatLiteral, ExpressibleByStringLiteral
extension PythonObject : ExpressibleByArrayLiteral, ExpressibleByDictionaryLiteral

PythonObject represents an object in Python and supports dynamic member lookup. Any member access like object.foo will dynamically request the Python runtime for a member with the specified name in this object.

PythonObject is passed to and returned from all Python function calls and member references. It supports standard Python arithmetic and comparison operators.

Internally, PythonObject is implemented as a reference-counted pointer to a Python C API PyObject.

  • A textual description of this PythonObject, produced by Python.str.

    Declaration

    public var description: String { get }
  • Declaration

    public var playgroundDescription: Any { get }
  • Declaration

    public var customMirror: Mirror { get }
  • Creates a new instance from a PythonConvertible value.

    Declaration

    init<T>(_ object: T) where T : PythonConvertible
  • Declaration

    public init(_ object: PythonObject)
  • Declaration

    public var pythonObject: PythonObject { get }
  • Returns a callable version of this PythonObject. When called, the result throws a Swift error if the underlying Python function throws a Python exception.

    Declaration

    var throwing: ThrowingPythonObject { get }
  • Returns a PythonObject wrapper capable of member accesses.

    Declaration

    var checking: CheckingPythonObject { get }
  • Declaration

    subscript(dynamicMember memberName: String) -> PythonObject { get nonmutating set }
  • Access the element corresponding to the specified PythonConvertible values representing a key.

    Note

    This is equivalent to object[key] in Python.

    Declaration

    subscript(key: PythonConvertible...) -> PythonObject { get nonmutating set }
  • Converts to a 2-tuple.

    Declaration

    var tuple2: (PythonObject, PythonObject) { get }
  • Converts to a 3-tuple.

    Declaration

    var tuple3: (PythonObject, PythonObject, PythonObject) { get }
  • Converts to a 4-tuple.

    Declaration

    var tuple4: (PythonObject, PythonObject, PythonObject, PythonObject) { get }
  • Call self with the specified positional arguments.

    Precondition

    self must be a Python callable.

    Declaration

    @discardableResult
    func dynamicallyCall(
        withArguments args: [PythonConvertible] = []) -> PythonObject

    Parameters

    args

    Positional arguments for the Python callable.

  • Call self with the specified arguments.

    Precondition

    self must be a Python callable.

    Declaration

    @discardableResult
    func dynamicallyCall(
        withKeywordArguments args:
        KeyValuePairs<String, PythonConvertible> = [:]) -> PythonObject

    Parameters

    args

    Positional or keyword arguments for the Python callable.

  • Declaration

    init(tupleOf elements: PythonConvertible...)
  • Declaration

    init<T : Collection>(tupleContentsOf elements: T)
        where T.Element == PythonConvertible
  • Declaration

    init<T : Collection>(tupleContentsOf elements: T)
        where T.Element : PythonConvertible
  • Declaration

    static func + (lhs: PythonObject, rhs: PythonObject) -> PythonObject
  • Declaration

    static func - (lhs: PythonObject, rhs: PythonObject) -> PythonObject
  • Declaration

    static func * (lhs: PythonObject, rhs: PythonObject) -> PythonObject
  • Declaration

    static func / (lhs: PythonObject, rhs: PythonObject) -> PythonObject
  • Declaration

    static func += (lhs: inout PythonObject, rhs: PythonObject)
  • Declaration

    static func -= (lhs: inout PythonObject, rhs: PythonObject)
  • Declaration

    static func *= (lhs: inout PythonObject, rhs: PythonObject)
  • Declaration

    static func /= (lhs: inout PythonObject, rhs: PythonObject)
  • Declaration

    static func & (lhs: PythonObject, rhs: PythonObject) -> PythonObject
  • Declaration

    static func | (lhs: PythonObject, rhs: PythonObject) -> PythonObject
  • Declaration

    static func ^ (lhs: PythonObject, rhs: PythonObject) -> PythonObject
  • Declaration

    static func &= (lhs: inout PythonObject, rhs: PythonObject)
  • Declaration

    static func |= (lhs: inout PythonObject, rhs: PythonObject)
  • Declaration

    static func ^= (lhs: inout PythonObject, rhs: PythonObject)
  • Declaration

    prefix static func ~ (operand: `Self`) -> PythonObject
  • Declaration

    public init<T>(exactly value: T) where T : BinaryInteger
  • Declaration

    public typealias Magnitude = PythonObject
  • Declaration

    public var magnitude: PythonObject { get }
  • Declaration

    public prefix static func - (operand: `Self`) -> PythonObject
  • Declaration

    public typealias Stride = PythonObject
  • Declaration

    public func distance(to other: PythonObject) -> Stride
  • Declaration

    public func advanced(by stride: Stride) -> PythonObject
  • Declaration

    public static func == (lhs: PythonObject, rhs: PythonObject) -> Bool
  • Declaration

    public static func != (lhs: PythonObject, rhs: PythonObject) -> Bool
  • Declaration

    public static func < (lhs: PythonObject, rhs: PythonObject) -> Bool
  • Declaration

    public static func <= (lhs: PythonObject, rhs: PythonObject) -> Bool
  • Declaration

    public static func > (lhs: PythonObject, rhs: PythonObject) -> Bool
  • Declaration

    public static func >= (lhs: PythonObject, rhs: PythonObject) -> Bool
  • Declaration

    static func == (lhs: PythonObject, rhs: PythonObject) -> PythonObject
  • Declaration

    static func != (lhs: PythonObject, rhs: PythonObject) -> PythonObject
  • Declaration

    static func < (lhs: PythonObject, rhs: PythonObject) -> PythonObject
  • Declaration

    static func <= (lhs: PythonObject, rhs: PythonObject) -> PythonObject
  • Declaration

    static func > (lhs: PythonObject, rhs: PythonObject) -> PythonObject
  • Declaration

    static func >= (lhs: PythonObject, rhs: PythonObject) -> PythonObject
  • Declaration

    public func hash(into hasher: inout Hasher)
  • Declaration

    public typealias Index = PythonObject
  • Declaration

    public typealias Element = PythonObject
  • Declaration

    public var startIndex: Index { get }
  • Declaration

    public var endIndex: Index { get }
  • Declaration

    public func index(after i: Index) -> Index
  • Declaration

    public subscript(index: PythonObject) -> PythonObject { get set }
  • Declaration

    public struct Iterator : IteratorProtocol
  • Declaration

    public func makeIterator() -> Iterator
  • Declaration

    public init(booleanLiteral value: Bool)
  • Declaration

    public init(integerLiteral value: Int)
  • Declaration

    public init(floatLiteral value: Double)
  • Declaration

    public init(stringLiteral value: String)
  • Declaration

    public init(arrayLiteral elements: PythonObject...)
  • Key

    Declaration

    public typealias Key = PythonObject
  • Declaration

    public typealias Value = PythonObject
  • Declaration

    public init(dictionaryLiteral elements: (PythonObject, PythonObject)...)