[Tutor] Assigning each line of text to a separate variable
Dave Angel
davea at ieee.org
Fri Jul 31 02:46:42 CEST 2009
Marv Boyes wrote:
> <div class="moz-text-flowed" style="font-family: -moz-fixed">I'm very
> sorry; I should have been more explicit in what it is I'm working with.
>
> The response from the server consists of a pair of hashes and a list
> of URLs for doing different things with the file the hashes represent.
> So the full response is like this:
>
> file_hash
> delete_hash
> http://server.com/file_hash.ext
> http://server.com/file_hashA.ext
> http://server.com/file_hashB.ext
> http://server.com/file_hashC.ext
> http://server.com/delete/deletehash
>
> I'm hoping to assign each line of that response to a separate variable
> so I can format the output on a case-by-case basis, e.g.:
>
> direct_link = <third URL in response>
> print "Direct link to file: %s' % direct_link
>
> -or-
>
> delete_file = <seventh URL in response>
> print "Delete the file: %s' % delete_file
>
> I've got seven lines worth of server response, their order is
> significant, and I need to be able to present each value in an
> arbitrary way. I won't necessarily be presenting these values to the
> user in the same order they come in the server response. Some of the
> values I'll need to use elsewhere in the script to do other things,
> but it won't be necessary to present those values to the user.
>
> I'm not sure I'm even making sense to myself.
>
> <snip>
Assuming the server response is in a single string, which consists of 7
strings separated by newlines.
response = server_getdata(....)
responseList = response.splitlines()
file_hash, delete_hash, direct_link, other_link, other_link3,
other_link4, delete_file = responseList
DaveA
More information about the Tutor
mailing list