title: Splitting string in while loop and appending to list
body: <p>I'm working on a script to automate sending SMS messages through a website. I am using <em>Mechanize</em> and <em>BeautifulSoup 4</em> for doing this. </p>
  
  <p>The program works by calling it from the command line and passing the number and message as arguments; for this I am using <em>Optparse</em>. </p>
  
  <p>The message is passed to the program via the command line, but the website only accepts 444 characters per SMS message. So I am trying to do the following:</p>
  
  <ul>
  <li>determine the length of the message string (including whitespace) and IF greater than 444 then...</li>
  <li>iterate through a while loop which takes the temporary message string and appends the first 444 characters of the total message string from index 0 to a list object until the length of the temporary message string is no longer greater than 444</li>
  <li>and then by using the number of items in the list object I will iterate through a For Loop block which loops through the handling of sending the messages where each iteration corresponds to the index of a 444 character string (split of the total message) and I'll put that 444 character message slice in the appropriate HTML form field with Mechanize as the message to be sent (hopefully that is understandable!)</li>
  </ul>
  
  <p>The code I have written so far is as follows:</p>
  
  <pre><code>message = "abcdefghijklmnopqrstuvwxyz..." # imagine it is &gt; 444 characters
  messageList = []
  if len(message) &gt; 444:
      tmpMsgString = message
      counter = 0
      msgLength = len(message)
  
      while msgLength &gt; 444:
          messageList.append(tmpMsgString[counter:counter+445]) # 2nd index needs to point to last character's position in the string, not "counter+445" because this would cause an error when there isn't enough characters in string?
          tmpMsgString = tmpMsgString[counter+445:msgLength])
          msgLength = msgLength-444
          counter = counter + 444
  else:
      messageList.append(message)
  </code></pre>
  
  <p>I can manage the portion of the code to accept the arguments from the command line and I can also manage with looping through a for loop block and using each item within the list as the message to be sent, however I have little Python experience and I need an experienced pair of eyes to help me along with this part of the code! All help appreciated.</p>