Re: Strings show as brackets with a 'u'.
Rick gave you some good advice, perhaps worth re-reading. What you need are investigative skills, and not just bits of data. Totally agree. beginning to see what's going on. I'm not specifically accessing the list element with n (vs. n[0]). Printing n uses repr which gives the unicode tag. Something akin to this...thanks for showing what i need to read up on... -- http://mail.python.org/mailman/listinfo/python-list
Re: Strings show as brackets with a 'u'.
On Jul 25, 3:00 am, Ulrich Eckhardt ulrich.eckha...@dominolaser.com wrote: Chris Angelico wrote: [snip] You just gave the OP a fish, he provided a valuable advise on fishing itself. I always believed the best way to teach someone is not to give them a direct answer. No. Instead i like to offer clues so that the person can utilize his own problem solving skills to find the answer. Because the most important skill a person can have in the programming field is the ability to solve complex problems by breaking them down into their smallest units; tackling each unit; and finally assembling the puzzle in a cohesive and intelligent manner. Anyway the OP may want to check out my recent thread regarding Python's Built-in Functions. http://groups.google.com/group/comp.lang.python/browse_thread/thread/f419d4e11f27882e?hl=en# -- rr http://sites.google.com/site/thefutureofpython/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Strings show as brackets with a 'u'.
Thank you. So what is happening? Is it that I'm in an environment that is not unicode and python is telling me the string (ie. n[0]) is unicode? (I'll do a hatchet-job on this subject if I ask anymore about unicode). Thanks to posters for their patience! -- http://mail.python.org/mailman/listinfo/python-list
Re: Strings show as brackets with a 'u'.
On 7/26/2011 9:18 PM, goldtech wrote: Thank you. So what is happening? Is it that I'm in an environment that is not unicode and python is telling me the string (ie. n[0]) is unicode? Yes, n is a list and n[0] is a unicode string and you are using some 2.x, which is ascii/byte string based. Python 3 is unicode based. If you do not *need* to use 2.x and are just learning Python, I personally recommend starting with Python 3. Others agree with me, still other do not. I would add 'especially if you want to use unicode'. Rick gave you some good advice, perhaps worth re-reading. What you need are investigative skills, and not just bits of data. -- Terry Jan Reedy -- http://mail.python.org/mailman/listinfo/python-list
Re: Strings show as brackets with a 'u'.
On Wed, 27 Jul 2011 11:18 am goldtech wrote: Thank you. So what is happening? Is it that I'm in an environment that is not unicode and python is telling me the string (ie. n[0]) is unicode? (I'll do a hatchet-job on this subject if I ask anymore about unicode). Thanks to posters for their patience! It's hard to say with no context remaining. I take it you're printing n[0] and getting unexpected results? To start with, try calling this: type(n[0]) That will tell you if the object is a byte-string, or unicode. I don't think there is any way to tell the console's encoding directly from Python, although you can look at sys.stdout.encoding which will tell you what Python thinks it is. I think that from Windows you can run chcp.exe to see the console encoding, although I can't confirm that. From Linux, there's probably a bazillion different ways, none of which guaranteed to be either correct or consistent with the others. But I'm not bitter. You can try with the default locale encoding, or the LANG environment variable: locale charmap echo $LANG but that only tells you what your shell thinks the encoding should be, not what your terminal is actually using. Your console app (xterm, konsole, Gnome terminal, whatever...) probably has a way to query what encoding it is using, but I'll be buggered if I can find out what that is. In konsole I can look at the Settings Encodings menu, but it claims to be using default. How very useful. -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: Strings show as brackets with a 'u'.
Chris Angelico wrote: On Sun, Jul 24, 2011 at 10:33 AM, goldtech goldt...@worldpost.com wrote: I'm using using Idle on winXP, activestate 2.7. Is there a way to suppress this and just show 174 in the shell ? A script reading data and assigns 174 to n via some regex. Links on this appreciated - I've tried to understand unicode before, will keep trying...thanks. There's two things there. Firstly, your regex is returning a list, not a string; and secondly, you are seeing repr(n) instead of just its content. Try: print(n[0]) This should print just the value. (Pro tip: rantingrick is a troll. You can safely ignore him.) If he's a troll, he's one of the better trolls here IMHO because he gave the best advise in this thread. You just gave the OP a fish, he provided a valuable advise on fishing itself. Uli -- Domino Laser GmbH Geschäftsführer: Thorsten Föcking, Amtsgericht Hamburg HR B62 932 -- http://mail.python.org/mailman/listinfo/python-list
Re: Strings show as brackets with a 'u'.
On Jul 23, 7:33 pm, goldtech goldt...@worldpost.com wrote: n [u'174'] Probably newbie question but not sure how suppress the brackets and the 'u' ? I assume pyhon is telling me it's a unicode string in the n variable. Try type(n) and see what happens. Then report back. :) -- http://mail.python.org/mailman/listinfo/python-list
Re: Strings show as brackets with a 'u'.
It's probably a list containing a single unicode string. You can pull the first element from the list with n[0]. To print a unicode string in 2.x without the u stuff: print u'174'.encode('ISO-8859-1') On Sat, Jul 23, 2011 at 5:33 PM, goldtech goldt...@worldpost.com wrote: Hi, n [u'174'] Probably newbie question but not sure how suppress the brackets and the 'u' ? I assume pyhon is telling me it's a unicode string in the n variable. I'm using using Idle on winXP, activestate 2.7. Is there a way to suppress this and just show 174 in the shell ? A script reading data and assigns 174 to n via some regex. Links on this appreciated - I've tried to understand unicode before, will keep trying...thanks. -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
Re: Strings show as brackets with a 'u'.
On Sun, Jul 24, 2011 at 10:33 AM, goldtech goldt...@worldpost.com wrote: I'm using using Idle on winXP, activestate 2.7. Is there a way to suppress this and just show 174 in the shell ? A script reading data and assigns 174 to n via some regex. Links on this appreciated - I've tried to understand unicode before, will keep trying...thanks. There's two things there. Firstly, your regex is returning a list, not a string; and secondly, you are seeing repr(n) instead of just its content. Try: print(n[0]) This should print just the value. (Pro tip: rantingrick is a troll. You can safely ignore him.) Chris Angelico -- http://mail.python.org/mailman/listinfo/python-list
Re: Strings show as brackets with a 'u'.
On 24/07/11 02:52, Dan Stromberg wrote: It's probably a list containing a single unicode string. You can pull the first element from the list with n[0]. To print a unicode string in 2.x without the u stuff: print u'174'.encode('ISO-8859-1') just print u'174' will do. Encoding the string by hand is only useful if Python doesn't know the terminal's encoding, but you do. On Sat, Jul 23, 2011 at 5:33 PM, goldtech goldt...@worldpost.com mailto:goldt...@worldpost.com wrote: Hi, n [u'174'] Probably newbie question but not sure how suppress the brackets and the 'u' ? I assume pyhon is telling me it's a unicode string in the n variable. I'm using using Idle on winXP, activestate 2.7. Is there a way to suppress this and just show 174 in the shell ? A script reading data and assigns 174 to n via some regex. Links on this appreciated - I've tried to understand unicode before, will keep trying...thanks. -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list