Maintainer | John Goerzen, |
---|---|
Safe Haskell | None |
Maintainer : jgoerzen@complete.org Stability : provisional Portability: portable
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
- 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
The type of Python objects.
Eq PyObject | |
Show PyObject | |
FromPyObject a => FromPyObject [(a, PyObject)] | |
FromPyObject [(PyObject, PyObject)] | ALs from Dicts |
FromPyObject [PyObject] | Tuples and Lists to [PyObject] lists |
ToPyObject a => ToPyObject [(a, PyObject)] | This is a common variant used for arg lists |
ToPyObject [(PyObject, PyObject)] | Dicts from ALs |
ToPyObject [PyObject] | Lists from a PyObject |
Conversions between Haskell and Python Objects
class ToPyObject a whereSource
Members of this class can be converted from a Haskell type to a Python object.
toPyObject :: a -> IO PyObjectSource
ToPyObject Integer | |
ToPyObject String | |
ToPyObject CStringLen | |
ToPyObject CInt | |
ToPyObject CLong | |
ToPyObject CDouble | |
(ToPyObject a, ToPyObject b) => ToPyObject [(a, b)] | Dicts from Haskell objects |
ToPyObject a => ToPyObject [(a, PyObject)] | This is a common variant used for arg lists |
ToPyObject [(PyObject, PyObject)] | Dicts from ALs |
ToPyObject a => ToPyObject [a] | Lists from anything else |
ToPyObject [PyObject] | Lists from a PyObject |
class FromPyObject a whereSource
Members of this class can be derived from a Python object.
fromPyObject :: PyObject -> IO aSource
FromPyObject Integer | |
FromPyObject String | |
FromPyObject CInt | |
FromPyObject CLong | |
FromPyObject CDouble | |
(FromPyObject a, FromPyObject b) => FromPyObject [(a, b)] | Dicts to Haskell objects |
FromPyObject a => FromPyObject [(a, PyObject)] | |
FromPyObject [(PyObject, PyObject)] | ALs from Dicts |
FromPyObject a => FromPyObject [a] | |
FromPyObject [PyObject] | Tuples and Lists to [PyObject] lists |
Information about Python Objects
strOf :: PyObject -> IO StringSource
Gets a string representation of a Python object. Same as str(x) in Python.
reprOf :: PyObject -> IO StringSource
Gets the Python representation of a Python object. Same as repr(x) in Python.
showPyObject :: PyObject -> IO StringSource
Displays a Python object and its type.
dirPyObject :: PyObject -> IO [String]Source
Displays a list of keys contained in the Python object.
getattr :: PyObject -> String -> IO PyObjectSource
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 BoolSource
An interface to Python's hasattr. Returns True if the named attribute exists; False otherwise.
:: 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
Calling Python Objects
:: 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 |
Converts a Python list to a tuple.
Call a Python object (function, etc).
For a higher-level wrapper, see callByName
.
:: (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.
:: (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.
:: (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.
:: (ToPyObject a, ToPyObject b) | |
=> PyObject | The main object |
-> String | Name of method to call |
-> [a] | Non-kw args |
-> [(String, b)] | Keyword args |
-> IO () | Result |
Like callMethodHs
, but discards the return value.