You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am pretty sure there is something "special" about the way "string" are manadged in Python.
Something about "invariant" or I don't know what.
So when formatting string, even in a print there might be more or less optimal way to do it and avoid a lot of memory allocation (if it's in the stack, I guess it is fine, if it is in the heap, maybe this will make a lot of fragmentation over time).
I totally don't know the proper and best way of doing things... let's say for a program that just want to print, or display values.
There is the str() function that can convert a value into a string, and then you can concatenate.
There is the print("Value: ", value, ".") way, without formatting.
There is that notation that I have seen used: line = "Temperature %0.1f C" % (bme680.temperature + temperature_offset)
I am pretty sure one is better than the other, no big saving, except if you do a lot of string processing...
But I would love to know the recommended way (I think that kattni already asked that kind of question in meeting and got an answer from danh or tannewt ... I wish I had a good enough memory to remember what is the best and why... and maybe the question was about what is more "pythonic" rather than what is more memory efficient).
So there could be things to say about "print" and "string" but this would need to be ask to more expert people. :-)
The text was updated successfully, but these errors were encountered:
I am pretty sure there is something "special" about the way "string" are manadged in Python.
Something about "invariant" or I don't know what.
So when formatting string, even in a
print
there might be more or less optimal way to do it and avoid a lot of memory allocation (if it's in the stack, I guess it is fine, if it is in the heap, maybe this will make a lot of fragmentation over time).I totally don't know the proper and best way of doing things... let's say for a program that just want to print, or display values.
There is the
str()
function that can convert a value into a string, and then you can concatenate.There is the print("Value: ", value, ".") way, without formatting.
There is that notation that I have seen used:
line = "Temperature %0.1f C" % (bme680.temperature + temperature_offset)
I am pretty sure one is better than the other, no big saving, except if you do a lot of string processing...
But I would love to know the recommended way (I think that kattni already asked that kind of question in meeting and got an answer from danh or tannewt ... I wish I had a good enough memory to remember what is the best and why... and maybe the question was about what is more "pythonic" rather than what is more memory efficient).
So there could be things to say about "print" and "string" but this would need to be ask to more expert people. :-)
The text was updated successfully, but these errors were encountered: