ContentsIndex
Python.Objects
Portability portable
Stability provisional
Maintainer jgoerzen@complete.org
Contents
Basic Object Types
Conversions between Haskell and Python Objects
Information about Python Objects
Conversions between Python Objects
Calling Python Objects
Description

Python type instances and object utilities.

For more similar utilities, see Python.Objects.File and Python.Objects.Dict.

Written by John Goerzen, jgoerzen@complete.org

Synopsis
data PyObject
class ToPyObject a where
toPyObject :: a -> IO PyObject
class FromPyObject a where
fromPyObject :: PyObject -> IO a
typeOf :: PyObject -> IO PyObject
strOf :: PyObject -> IO String
reprOf :: PyObject -> IO String
showPyObject :: PyObject -> IO String
dirPyObject :: PyObject -> IO [String]
getattr :: PyObject -> String -> IO PyObject
hasattr :: PyObject -> String -> IO Bool
setattr :: PyObject -> String -> PyObject -> IO ()
pyList_AsTuple :: PyObject -> IO PyObject
pyObject_Call :: PyObject -> [PyObject] -> [(String, PyObject)] -> IO PyObject
pyObject_CallHs :: (ToPyObject a, ToPyObject b, FromPyObject c) => PyObject -> [a] -> [(String, b)] -> IO c
pyObject_RunHs :: (ToPyObject a, ToPyObject b) => PyObject -> [a] -> [(String, b)] -> IO ()
callMethodHs :: (ToPyObject a, ToPyObject b, FromPyObject c) => PyObject -> String -> [a] -> [(String, b)] -> IO c
runMethodHs :: (ToPyObject a, ToPyObject b) => PyObject -> String -> [a] -> [(String, b)] -> IO ()
noParms :: [String]
noKwParms :: [(String, String)]
Basic Object Types
data PyObject
The type of Python objects.
Instances
ToPyObject [PyObject]
FromPyObject [PyObject]
ToPyObject [(PyObject, PyObject)]
ToPyObject [(PyObject, PyObject)]
FromPyObject [(PyObject, PyObject)]
FromPyObject [(PyObject, PyObject)]
ToPyObject a => ToPyObject [(a, PyObject)]
FromPyObject a => FromPyObject [(a, PyObject)]
Eq PyObject
Show PyObject
Conversions between Haskell and Python Objects
class ToPyObject a where
Members of this class can be converted from a Haskell type to a Python object.
Methods
toPyObject :: a -> IO PyObject
Instances
ToPyObject [PyObject]
ToPyObject [(PyObject, PyObject)]
ToPyObject a => ToPyObject [(a, PyObject)]
(ToPyObject a, ToPyObject b) => ToPyObject [(a, b)]
ToPyObject CStringLen
ToPyObject String
ToPyObject CLong
ToPyObject CInt
ToPyObject Integer
ToPyObject CDouble
ToPyObject a => ToPyObject [a]
class FromPyObject a where
Members of this class can be derived from a Python object.
Methods
fromPyObject :: PyObject -> IO a
Instances
FromPyObject [PyObject]
FromPyObject [(PyObject, PyObject)]
FromPyObject a => FromPyObject [(a, PyObject)]
(FromPyObject a, FromPyObject b) => FromPyObject [(a, b)]
FromPyObject String
FromPyObject CLong
FromPyObject CInt
FromPyObject Integer
FromPyObject CDouble
FromPyObject a => FromPyObject [a]
Information about Python Objects
typeOf :: PyObject -> IO PyObject
Gets the type of a Python object. Same as type(x) in Python.
strOf :: PyObject -> IO String
Gets a string representation of a Python object. Same as str(x) in Python.
reprOf :: PyObject -> IO String
Gets the Python representation of a Python object. Same as repr(x) in Python.
showPyObject :: PyObject -> IO String
Displays a Python object and its type.
dirPyObject :: PyObject -> IO [String]
Displays a list of keys contained in the Python object.
getattr :: PyObject -> String -> IO PyObject
An interface to a function similar to Python's getattr. This will look up an attribute (such as a method) of an object.
hasattr :: PyObject -> String -> IO Bool
An interface to Python's hasattr. Returns True if the named attribute exists; False otherwise.
setattr
:: PyObjectObject to operate on
-> StringName of attribute
-> PyObjectSet the attribute to this value
-> IO ()
An interface to Python's setattr, used to set attributes of an object.
Conversions between Python Objects
pyList_AsTuple :: PyObject -> IO PyObject
Calling Python Objects
pyObject_Call
:: PyObjectObject to call
-> [PyObject]List of non-keyword parameters (may be empty)
-> [(String, PyObject)]List of keyword parameters (may be empty)
-> IO PyObjectReturn value

Call a Python object (function, etc).

For a higher-level wrapper, see callByName.

pyObject_CallHs
:: (ToPyObject a, ToPyObject b, FromPyObject c)
=> PyObjectObject t
-> [a]List of non-keyword parameters
-> [(String, b)]List of keyword parameters
-> IO cReturn value

Call a Python object with all-Haskell parameters. Similar to PyObject_Call. This limits you to a single item type for the regular arguments and another single item type for the keyword arguments. Nevertheless, it could be a handy shortcut at times.

For a higher-level wrapper, see callByName.

You may find noParms and noKwParms useful if you aren't passing any parameters.

pyObject_RunHs
:: (ToPyObject a, ToPyObject b)
=> PyObjectObject t
-> [a]List of non-keyword parameters
-> [(String, b)]List of keyword parameters
-> IO ()Return value
Like PyObject_CallHs, but discards the return value.
callMethodHs
:: (ToPyObject a, ToPyObject b, FromPyObject c)
=> PyObjectThe main object
-> StringName of method to call
-> [a]Non-kw args
-> [(String, b)]Keyword args
-> IO cResult
Calls the named method of the given object.
runMethodHs
:: (ToPyObject a, ToPyObject b)
=> PyObjectThe main object
-> StringName of method to call
-> [a]Non-kw args
-> [(String, b)]Keyword args
-> IO ()Result
Like callMethodHs, but discards the return value.
noParms :: [String]
noKwParms :: [(String, String)]
Produced by Haddock version 0.6