Strings and Unicode

- madsurfer2000 at hotmail.com
Sun Jul 20 12:28:36 EDT 2003


I wrote:
> I have a function that takes a string as an input parameter. This
> function then urlencodes the string and sends it to a server with
> telnetlib.Telnet
> 
> The problem is that the string gets converted into what seems to be
> Unicode. How can I check to see if the input-string is Unicode and
> convert it to a different character set (in this case ISO-Latin1).

I see that my question may have been asked in the wrong way, so here's
more details:

I'm using Python 2.2.2. under Windows XP. The function I was talking
about actually takes two strings, and I send both parameters to the
urlencode function. The urlencode-function I use is imported from
urllib.

My function:

def addPOSTParam(self,name,value):
    param = urlencode({name: value})
    self.POSTParameters.append(param)

Example:

client.addPOSTParam("param","abc æ")

POSTParameters then looks like:
['param=abc+%C3%A6']

Here, the 'æ' character is converted into what seems to be Unicode

I would have expected the following:
['param=abc+%E6']

type(value) gives:
<type 'str'>

I probably should have tested type() before, because it seems to be a
standard string.

Hope this explains my problem better. As you probably have guessed I'm
trying to send information to a web-server, but since this is mostly a
project for learning, I don't want to use the included HTTP classes.




More information about the Python-list mailing list