J
Jens Lippmann
Hi all!
I'm new to Python and just tried to assign values to a portion
of a string, but I don't get it.
My code is:
bits = '\3ff' * bmi.bmiHeader.biSizeImage
ofs = 0x1E2C0
for i in range(0, height):
bits[i*linesizei+1)*linesize] = self.shbits[ofsfs+width/2]
which leads to
...
TypeError: object doesn't support slice assignment
'bits' is a binary string resp. an array of byte so to say.
Note also that the right slice is shorter than the left one.
So, my questions are:
- How do I get it right?
- If slicing seems to be the favorite way to address substrings, why
is it impossible to use it on a left side of an assignment?
kind regards
Jens Lippmann
I'm new to Python and just tried to assign values to a portion
of a string, but I don't get it.
My code is:
bits = '\3ff' * bmi.bmiHeader.biSizeImage
ofs = 0x1E2C0
for i in range(0, height):
bits[i*linesizei+1)*linesize] = self.shbits[ofsfs+width/2]
which leads to
...
TypeError: object doesn't support slice assignment
'bits' is a binary string resp. an array of byte so to say.
Note also that the right slice is shorter than the left one.
So, my questions are:
- How do I get it right?
- If slicing seems to be the favorite way to address substrings, why
is it impossible to use it on a left side of an assignment?
kind regards
Jens Lippmann