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
_______________________________________________
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor