The __str__
and __repr__
method do not work.
#2212
-
I am implementing a struct named #[pymethods]
impl IndexList {
// Arrange the following methods in alphabetical order.
#[new]
pub fn new(vec: Vec<usize>) -> Self {
IndexList { _values: vec }
}
fn __repr__(&self) -> String {
format!("IndexList({})", self.__str__())
}
fn __str__(&self) -> String {
let v = &self._values;
let n = v.len();
if n < 100 {
format!("{:?}", self._values)
} else {
format!(
"[{}, {}, {}, ..., {}, {}, {}]",
v[0],
v[1],
v[2],
v[n - 3],
v[n - 2],
v[n - 1]
)
}
} After compiled by >>> import ulist as ul
>>> arr = ul.from_seq([True, False, True, True], dtype='bool')
>>> idx = arr.to_index()
>>> idx
<builtins.IndexList object at 0x7fa285193f00>
>>> str(idx)
'<builtins.IndexList object at 0x7fa285193f00>'
>>> idx.__str__()
'[0, 2, 3]'
>>> idx.__repr__()
'IndexList([0, 2, 3])'
>>> So it seem that the |
Beta Was this translation helpful? Give feedback.
Answered by
davidhewitt
Mar 6, 2022
Replies: 1 comment 1 reply
-
What PyO3 version are you using? This would only work in 0.15 or newer. |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
tushushu
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
What PyO3 version are you using? This would only work in 0.15 or newer.