Given a very large string. I would like to process parts of the string in a loop like this:
large_string = "foobar..."
while large_string:
process(large_string.pop(200))
What is a nice and efficient way of doing this?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You can wrap the string in a
StringIOorBytesIOand pretend it’s a file. That should be pretty fast.