[Newbie Q on String & List Manipulation]

Joe Mason joe at notcharles.ca
Fri Apr 16 02:45:45 EDT 2004


In article <567a7c35.0404150247.7809bef5 at posting.google.com>, Matthew wrote:
>     ok, seems quite ok, however, not sure why it doesn't work on
>     my silly Gmail script (pls refer to my script belows):
> 
>         for item in thecookies:
>             mycookies += item
> 
>         print mycookies
> 
>     i have exactly 4 items in the "thecookies" list, however, when
>     printing out "mycookies", it just show the last item (in fact,
>     seems the 4 items have been overlapped each others).

I had to comment out the SID and GV tests, because they kept failing,
but then I got:

['=en_CA; Expires=Sat, 16-Apr-05 06:35:14 GMT; Path=/\r',
'Session=en_CA\r']
Session=en_CAes=Sat, 16-Apr-05 06:35:14 GMT; Path=/

Note the "\r" at the end of each cookie.  That's carriage return, which
moves the cursor back to the beginning of the line.  mycookies actually
contains all the data you want, but the print statement interprets the
control character so they overwrite each other.

Tip for future debugging: you don't need to do "sys.exit" at the end.
It will automatically exit for you.  And if you don't do that, you can
run your script with "python -i" and get an interactive prompt when the
script is finished, so you can examine the variables directly instead of
going through print:

  >>> mycookies
  '=en_CA; Expires=Sat, 16-Apr-05 06:44:23 GMT; Path=/\rSession=en_CA\r'

Joe



More information about the Python-list mailing list