How to remove variable from last iteration of while loop in python -
im not expert @ python , ive got following while loop. padding iterations buffer. however, results in unwanted padding in last iteration of while loop. there way can remove this?
# send data packets. bytes_sent = 0 while (bytes_sent < len(padded_buf)): bytes_to_send = len(padded_buf) - bytes_sent assert bytes_to_send % 4 == 0 bytes_this_block = min(_max_block_size, bytes_to_send) s.send(padded_buf[bytes_sent:(bytes_sent + bytes_this_block)]) bytes_sent += bytes_this_block # clean , return. s.close() return bytes_sent
cheers helps.
i'm not sure you're trying remove… whatever is, can easily.
if want remove after fact, can. of variables define inside while
loop still available after done, value last iteration. can this:
padded_buf = padded_buf[:-bytes_this_block]
but really, better not add in first place. put if
statement in middle of while , break
if you've reached end.
Comments
Post a Comment