Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #78254
| Path | csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!news.stack.nl!newsfeed.xs4all.nl!newsfeed2a.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <miguelglafuente@gmail.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.066 |
| X-Spam-Evidence | '*H*': 0.87; '*S*': 0.00; 'string': 0.09; 'broke': 0.09; 'gente': 0.09; 'subject:skip:c 10': 0.09; 'cc:addr:python- list': 0.11; '(it': 0.16; 'devil': 0.16; 'non-ascii': 0.16; 'rewriting': 0.16; 'skip:[ 30': 0.16; 'cc:addr:python.org': 0.22; 'cc:2**0': 0.24; 'this:': 0.26; 'header:In-Reply-To:1': 0.27; 'subject:list': 0.30; 'message-id:@mail.gmail.com': 0.30; 'url:mailman': 0.30; 'code': 0.31; 'fine,': 0.31; 'larry': 0.31; 'url:python': 0.33; 'maybe': 0.34; 'could': 0.34; 'subject:with': 0.35; 'except': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'there': 0.35; 'are,': 0.36; 'consistent': 0.36; 'subject:data': 0.36; 'url:listinfo': 0.36; 'url:org': 0.36; 'list': 0.37; 'skip:[ 10': 0.38; 'changed': 0.39; '8bit%:6': 0.40; 'url:mail': 0.40; 'how': 0.40; 'skip:\xc2 10': 0.60; 'details.': 0.61; 'world.': 0.61; 'today': 0.64; 'more': 0.64; 'different': 0.65; 'to:addr:gmail.com': 0.65; 'este': 0.70; 'subject:Best': 0.91; 'education,': 0.96 |
| DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type; bh=f4JDDmvp8OR8eIddyZ6BgK6o5wwkkc/Cj/mEDV2KnIY=; b=GC+a10zfaSL6yY9TgGChk0qLW7hyixFuvzFl1dw3k7hoXKvnvetZ+AE8It+XCATmDa r3yj6roB1+g5r72YSXkeonI21872LbwJRM7PEQZvJH+CL7pyW0k/oTgdc8BulbA4jgs2 dK3JQkzwsifkMTRUcHnOu1QhTCeWdxlkiBryz4lAo+CcD59H0B2xM7B6aQ8woHpUiHhs ag2ES+QAASTaRBV78brvnUdfyeBUR4M+Jol6ubCyUqwsssMonP+/hylF8vfSYPX+4xX5 pmvddvpPGWkfJKXYXJJv/66vm1cMVStWEe59DORlEos+q0GBNU0jYM/KD0ySuMNZGXkM 6shw== |
| X-Received | by 10.152.9.37 with SMTP id w5mr2454752laa.28.1411509982761; Tue, 23 Sep 2014 15:06:22 -0700 (PDT) |
| MIME-Version | 1.0 |
| In-Reply-To | <CACwCsY6rL5gQb2Utp1zrDur=1ecD9BjDgSRBn12DnP9U2yTgMA@mail.gmail.com> |
| References | <CACwCsY6rL5gQb2Utp1zrDur=1ecD9BjDgSRBn12DnP9U2yTgMA@mail.gmail.com> |
| From | Rock Neurotiko <miguelglafuente@gmail.com> |
| Date | Wed, 24 Sep 2014 00:05:52 +0200 |
| Subject | Re: Best way to deal with different data types in a list comprehension |
| To | Larry Martell <larry.martell@gmail.com> |
| Content-Type | multipart/alternative; boundary=089e014946f41e97ff0503c2c703 |
| Cc | "python-list@python.org" <python-list@python.org> |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.15 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.14291.1411509984.18130.python-list@python.org> (permalink) |
| Lines | 117 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1411509984 news.xs4all.nl 2843 [2001:888:2000:d::a6]:50488 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:78254 |
Show key headers only | View raw
[Multipart message — attachments visible in raw view] - view raw
Maybe there are a different way, but you can do this:
' '.join([self.get_abbrev()] +
[str(f['value').encode('utf-8') if type(f['value']) is str else
str(f['value']
for f in self.filters
if f.has_key('value')]).strip()
2014-09-24 0:01 GMT+02:00 Larry Martell <larry.martell@gmail.com>:
> I have some code that I inherited:
>
> ' '.join([self.get_abbrev()] +
> [str(f['value')
> for f in self.filters
> if f.has_key('value')]).strip()
>
>
> This broke today when it encountered some non-ascii data.
>
> I changed the str(f['value']) line to f['value'].encode('utf-8'),
> which works fine, except when f['value'] is not a string (it could be
> anything).
>
> Without rewriting this without the list comprehension, how can I write
> this to deal with both strings and non-strings?
> --
> https://mail.python.org/mailman/listinfo/python-list
>
--
Miguel García Lafuente - Rock Neurotiko
Do it, the devil is in the details.
The quieter you are, the more you are able to hear.
Happy Coding. Code with Passion, Decode with Patience.
If we make consistent effort, based on proper education, we can change the
world.
El contenido de este e-mail es privado, no se permite la revelacion del
contenido de este e-mail a gente ajena a él.
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: Best way to deal with different data types in a list comprehension Rock Neurotiko <miguelglafuente@gmail.com> - 2014-09-24 00:05 +0200
csiph-web