|
Python.Objects | Portability | portable | Stability | provisional | Maintainer | jgoerzen@complete.org |
|
|
|
|
|
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 | | | class FromPyObject a where | | | 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 | |
|
|
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 | | | Instances | |
|
|
class FromPyObject a where |
Members of this class can be derived from a Python object. | | Methods | | | Instances | |
|
|
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 |
:: PyObject | Object to operate on | -> String | Name of attribute | -> PyObject | Set 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 |
:: PyObject | Object to call | -> [PyObject] | List of non-keyword parameters (may be empty) | -> [(String, PyObject)] | List of keyword parameters (may be empty) | -> IO PyObject | Return value | Call a Python object (function, etc).
For a higher-level wrapper, see callByName.
|
|
|
pyObject_CallHs |
:: (ToPyObject a, ToPyObject b, FromPyObject c) | | => PyObject | Object t | -> [a] | List of non-keyword parameters | -> [(String, b)] | List of keyword parameters | -> IO c | Return 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) | | => PyObject | Object 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) | | => PyObject | The main object | -> String | Name of method to call | -> [a] | Non-kw args | -> [(String, b)] | Keyword args | -> IO c | Result | Calls the named method of the given object. |
|
|
runMethodHs |
|
|
noParms :: [String] |
|
noKwParms :: [(String, String)] |
|
Produced by Haddock version 0.6 |