Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #10179 > unrolled thread
| Started by | goldtech <goldtech@worldpost.com> |
|---|---|
| First post | 2011-07-23 17:33 -0700 |
| Last post | 2011-07-27 14:20 +1000 |
| Articles | 10 — 7 participants |
Back to article view | Back to comp.lang.python
Strings show as brackets with a 'u'. goldtech <goldtech@worldpost.com> - 2011-07-23 17:33 -0700
Re: Strings show as brackets with a 'u'. rantingrick <rantingrick@gmail.com> - 2011-07-23 17:48 -0700
Re: Strings show as brackets with a 'u'. Chris Angelico <rosuav@gmail.com> - 2011-07-24 10:52 +1000
Re: Strings show as brackets with a 'u'. Ulrich Eckhardt <ulrich.eckhardt@dominolaser.com> - 2011-07-25 10:00 +0200
Re: Strings show as brackets with a 'u'. rantingrick <rantingrick@gmail.com> - 2011-07-26 17:33 -0700
Re: Strings show as brackets with a 'u'. Thomas Jollans <t@jollybox.de> - 2011-07-24 03:06 +0200
Re: Strings show as brackets with a 'u'. goldtech <goldtech@worldpost.com> - 2011-07-26 18:18 -0700
Re: Strings show as brackets with a 'u'. Terry Reedy <tjreedy@udel.edu> - 2011-07-26 23:04 -0400
Re: Strings show as brackets with a 'u'. goldtech <goldtech@worldpost.com> - 2011-07-27 16:37 -0700
Re: Strings show as brackets with a 'u'. Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-07-27 14:20 +1000
| From | goldtech <goldtech@worldpost.com> |
|---|---|
| Date | 2011-07-23 17:33 -0700 |
| Subject | Strings show as brackets with a 'u'. |
| Message-ID | <d3c602cf-8a80-4035-9478-22d9b00022c2@r5g2000prf.googlegroups.com> |
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.
[toc] | [next] | [standalone]
| From | rantingrick <rantingrick@gmail.com> |
|---|---|
| Date | 2011-07-23 17:48 -0700 |
| Message-ID | <12ad76b9-1d9d-4d49-9e4b-a0d2672d3ff4@10g2000yqn.googlegroups.com> |
| In reply to | #10179 |
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. :)
[toc] | [prev] | [next] | [standalone]
| From | Chris Angelico <rosuav@gmail.com> |
|---|---|
| Date | 2011-07-24 10:52 +1000 |
| Message-ID | <mailman.1407.1311468776.1164.python-list@python.org> |
| In reply to | #10179 |
On Sun, Jul 24, 2011 at 10:33 AM, goldtech <goldtech@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
[toc] | [prev] | [next] | [standalone]
| From | Ulrich Eckhardt <ulrich.eckhardt@dominolaser.com> |
|---|---|
| Date | 2011-07-25 10:00 +0200 |
| Message-ID | <u1kvf8-k2u.ln1@satorlaser.homedns.org> |
| In reply to | #10181 |
Chris Angelico wrote: > On Sun, Jul 24, 2011 at 10:33 AM, goldtech <goldtech@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
[toc] | [prev] | [next] | [standalone]
| From | rantingrick <rantingrick@gmail.com> |
|---|---|
| Date | 2011-07-26 17:33 -0700 |
| Message-ID | <5fadc4d3-ceb5-43b5-a728-870726a51c3f@l18g2000yql.googlegroups.com> |
| In reply to | #10247 |
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/
[toc] | [prev] | [next] | [standalone]
| From | Thomas Jollans <t@jollybox.de> |
|---|---|
| Date | 2011-07-24 03:06 +0200 |
| Message-ID | <mailman.1408.1311469574.1164.python-list@python.org> |
| In reply to | #10179 |
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 <goldtech@worldpost.com
> <mailto:goldtech@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
>
>
[toc] | [prev] | [next] | [standalone]
| From | goldtech <goldtech@worldpost.com> |
|---|---|
| Date | 2011-07-26 18:18 -0700 |
| Message-ID | <9843961d-cc18-45f8-b33a-e2ca716df283@d8g2000prf.googlegroups.com> |
| In reply to | #10182 |
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!
[toc] | [prev] | [next] | [standalone]
| From | Terry Reedy <tjreedy@udel.edu> |
|---|---|
| Date | 2011-07-26 23:04 -0400 |
| Message-ID | <mailman.1525.1311735911.1164.python-list@python.org> |
| In reply to | #10362 |
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
[toc] | [prev] | [next] | [standalone]
| From | goldtech <goldtech@worldpost.com> |
|---|---|
| Date | 2011-07-27 16:37 -0700 |
| Message-ID | <ac69959e-a5ac-4953-8fc4-51bf3da19987@r5g2000prf.googlegroups.com> |
| In reply to | #10368 |
> 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...
[toc] | [prev] | [next] | [standalone]
| From | Steven D'Aprano <steve+comp.lang.python@pearwood.info> |
|---|---|
| Date | 2011-07-27 14:20 +1000 |
| Message-ID | <4e2f9218$0$29966$c3e8da3$5496439d@news.astraweb.com> |
| In reply to | #10362 |
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
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web