[Tutor] unexpected list entry

surya k suryak at live.com
Fri Dec 2 17:48:33 CET 2011


--------------------------------------------------
From: "Dave Angel" <d at davea.name>
Sent: Friday, December 02, 2011 9:36 PM
To: "surya k" <suryak at live.com>
Cc: "Python Tutor" <tutor at python.org>
Subject: Re: [Tutor] unexpected list entry

> (You top-posted.  Put your remarks AFTER whatever you quote from earlier 
> messages)
>
> On 12/02/2011 10:47 AM, surya k wrote:
>> Thanks for the information about unicode.
>>
>> Actually, I am using python 2.7 in Windows XP.
>> IDE: PyScripter.
>>
>> So, I run the same code in IDLE (Python 2.7).. Its working. It isn't
>> showing the list in unicode format!
>
> Nothing to do with list.  Reread my remarks.  The string is apparently 
> unicode, presumably from the raw_input() call.  The IDE must be changing 
> the type of stdin to make it unicode.
>
> Did you try     print repr(name1)   ?  I'll bet that's also a unicode 
> string.
>
> And you tried it in another IDE, IDLE.  But the key question is how it 
> behaves in raw Windows, from a command prompt.  The user of your code is 
> unlikely to set up your particular IDE to run something you've written.
>
> As for an IDE, the only free one I use is emacs.  I've heard good things 
> about pywin  (or something like that), a free IDE that comes with the free 
> ActiveState python.  The Active State python also includes some extensions 
> specifically for Windows, and to make it easier to use Windows dll's and 
> com objects.  I used to use the ActiveState stuff when I used Windows.
>
> The following material is out of order, but I left it in anyway, for some 
> context.
>>
>> I've used PyScripter many times before and worked on lists.. but I never
>> faced any problem like this
>>
>> --------------------------------------------------
>> From: "Dave Angel" <d at davea.name>
>> Sent: Friday, December 02, 2011 7:43 PM
>> To: "surya k" <suryak at live.com>
>> Cc: "Python Tutor" <tutor at python.org>
>> Subject: Re: [Tutor] unexpected list entry
>>
>>> On 12/02/2011 08:49 AM, surya k wrote:
>>>> Hi,
>>>>
>>>> Just take a look at this small code.. I am just taking a string as
>>>> input and assigning it as a list.
>>>> But I am finding an unexpected entry in the list.. Why this is
>>>> happening?
>>>>
>>>> I am using PyScripter IDE.
>>>>
>>>>
>>>> code :
>>>>
>>>>
>>>> #!/usr/bin/env python
>>>>
>>>> def main():
>>>> pass
>>>>
>>>> if __name__ == '__main__':
>>>> main()
>>>>
>>>> print "Flames: "
>>>> name1 = raw_input('enter name 1')
>>>>
>>>> ListName1 = list(name1)
>>>> print name1
>>>> print ListName1
>>>>
>>>>
>>>> Output:
>>>>
>>>> Flames:
>>>> foo
>>>> [u'f', u'o', u'o']
>>>>
>>>>
>>>> Observe the last line.. it isn't showing [ 'f', 'o', 'o']
>>>> Why is that "u" coming in the middle from no where ??
>>>>
>>> The u"" notation just says it's a unicode string. No more confusing
>>> than the [] meaning it's a list. Neither is the content of the object,
>>> just showing you textually what the type is. You should also print
>>> repr(name1) to see if it is likewise a unicode string. I presume it's
>>> already unicode when returned by raw_input().
>>>
>>> My puzzle is how you got unicode strings, if you've shown your entire
>>> program. In Python3, all strings are unicode, so it wouldn't bother to
>>> say so. Besides, your code has a syntax error in it, if it's supposed
>>> to be Python 3.x
>>>
>>> You probably need to identify your particular version of Python, and
>>> the platform (OS) you're running it on.
>>>
>>> But it could be affected by your IDE (Pyscripter), or by a site.py or
>>> other implicitly loaded module.
>>> You can check for the former by running the script from a command shell.
>>>
>>> --
>>>
>>> DaveA
>>>
>>>
>>
>
>
> -- 
>
> DaveA
>

Dave, I am now puzzled.. I
 don't understand but the list is now not showing unicode. I just restarted 
the IDE and rewrote the code again!

however, I tried print repr(name1), it didn't show me any unicode notation.



 



More information about the Tutor mailing list