Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #46922
| Path | csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!xlned.com!feeder3.xlned.com!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <fabiosantosart@gmail.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.001 |
| X-Spam-Evidence | '*H*': 1.00; '*S*': 0.00; 'beginner': 0.05; 'string.': 0.05; 'expressions': 0.07; 'string': 0.09; 'parsing': 0.09; 'way:': 0.09; 'subject:question': 0.10; 'cc:addr:python- list': 0.11; 'python': 0.11; 'character.': 0.16; 'missing?': 0.16; 'subject:beginner': 0.16; 'surprises': 0.16; 'tested)': 0.16; 'wrote:': 0.18; '(not': 0.18; 'do.': 0.18; 'variable': 0.18; 'trying': 0.19; 'everyone,': 0.19; "skip:' 30": 0.19; 'split': 0.19; 'cc:addr:python.org': 0.22; 'headers': 0.24; 'replace': 0.24; 'subject:problem': 0.24; 'header': 0.24; 'file.': 0.24; 'cc:2**0': 0.24; 'cc:no real name:2**0': 0.24; 'script': 0.25; '>': 0.26; 'header:In-Reply-To:1': 0.27; 'message- id:@mail.gmail.com': 0.30; 'skip:( 20': 0.30; 'names.': 0.31; 'regular': 0.32; 'text': 0.33; 'something': 0.35; 'received:google.com': 0.35; 'thanks': 0.36; 'skip:& 20': 0.39; 'numbers': 0.61; 'advanced': 0.63; 'skip:n 10': 0.64; 'more': 0.64; 'needs,': 0.65; 'attention': 0.75; 'happening?': 0.84; '2013': 0.98 |
| DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=JWK8MKH5HpO9q4Tmr187x80Pwu+ZT2XY6CHnf1mHvYI=; b=0yY4ehhSIoRFyr5rOVaRSThmESFMekX+bAr3KM1Ny1ZZ57i3DxdgfwsbsLaZqBPXiK ZoJ2gSVjXRvYLm0itVcpiREWbXoJEvXp9zqyGFt6EK1NUgZYw/M2VgRY1YX5X7pNyQe3 w0X2akzz2n4pVjZxhgL2rf+tZ37c6lAuU1lD6BFath2rJY7kyYlLYcyxwESzTPpDl+wb cIKP2YXBu2bqXxu6DOB4i30xlBJddpJpfR3W8lxyGebVDQkbZayF3EZO2oS4jd2kjCfJ H0pegjvsIF4lHHNLYKRmtSVw1J7NWr1by0jxRZPpBvo3SKYKZ/7U5nQeZzn1V/1xHYDG xewg== |
| MIME-Version | 1.0 |
| X-Received | by 10.224.174.6 with SMTP id r6mr23826621qaz.87.1370360504318; Tue, 04 Jun 2013 08:41:44 -0700 (PDT) |
| In-Reply-To | <1fb7c07f-d974-43d0-815b-2739f7a4b965@googlegroups.com> |
| References | <1829efca-935d-4049-ba61-7138015a2806@googlegroups.com> <1fb7c07f-d974-43d0-815b-2739f7a4b965@googlegroups.com> |
| Date | Tue, 4 Jun 2013 16:41:43 +0100 |
| Subject | Re: lstrip problem - beginner question |
| From | Fábio Santos <fabiosantosart@gmail.com> |
| To | mstagliamonte <madmaxthc@yahoo.it> |
| Content-Type | multipart/alternative; boundary=485b397dd20513001604de55eb6e |
| Cc | 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 | <http://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 | <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.2657.1370360513.3114.python-list@python.org> (permalink) |
| Lines | 155 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1370360513 news.xs4all.nl 15960 [2001:888:2000:d::a6]:58402 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:46922 |
Show key headers only | View raw
[Multipart message — attachments visible in raw view] - view raw
On 4 Jun 2013 16:34, "mstagliamonte" <madmaxthc@yahoo.it> wrote:
>
> On Tuesday, June 4, 2013 11:21:53 AM UTC-4, mstagliamonte wrote:
> > Hi everyone,
> >
> >
> >
> > I am a beginner in python and trying to find my way through... :)
> >
> >
> >
> > I am writing a script to get numbers from the headers of a text file.
> >
> >
> >
> > If the header is something like:
> >
> > h01 = ('>scaffold_1')
> >
> > I just use:
> >
> > h01.lstrip('>scaffold_')
> >
> > and this returns me '1'
> >
> >
> >
> > But, if the header is:
> >
> > h02: ('>contig-100_0')
> >
> > if I use:
> >
> > h02.lstrip('>contig-100_')
> >
> > this returns me with: ''
> >
> > ...basically nothing. What surprises me is that if I do in this other
way:
> >
> > h02b = h02.lstrip('>contig-100')
> >
> > I get h02b = ('_1')
> >
> > and subsequently:
> >
> > h02b.lstrip('_')
> >
> > returns me with: '1' which is what I wanted!
> >
> >
> >
> > Why is this happening? What am I missing?
> >
> >
> >
> > Thanks for your help and attention
> >
> > Max
>
> edit: h02: ('>contig-100_1')
You don't have to use ('..') to declare a string. Just 'your string' will
do.
You can use str.split to split your string by a character.
(Not tested)
string_on_left, numbers = '>contig-100_01'.split('-')
left_number, right_number = numbers.split('_')
left_number, right_number = int(left_number), int(right_number)
Of course, you will want to replace the variable names.
If you have more advanced parsing needs, you will want to look at regular
expressions or blobs.
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
lstrip problem - beginner question mstagliamonte <madmaxthc@yahoo.it> - 2013-06-04 08:21 -0700
Re: lstrip problem - beginner question mstagliamonte <madmaxthc@yahoo.it> - 2013-06-04 08:24 -0700
Re: lstrip problem - beginner question mstagliamonte <madmaxthc@yahoo.it> - 2013-06-04 08:25 -0700
Re: lstrip problem - beginner question Fábio Santos <fabiosantosart@gmail.com> - 2013-06-04 16:41 +0100
Re: lstrip problem - beginner question mstagliamonte <madmaxthc@yahoo.it> - 2013-06-04 08:49 -0700
Re: lstrip problem - beginner question Mark Lawrence <breamoreboy@yahoo.co.uk> - 2013-06-04 17:01 +0100
Re: lstrip problem - beginner question Dave Angel <davea@davea.name> - 2013-06-04 17:48 -0400
Re: lstrip problem - beginner question mstagliamonte <madmaxthc@yahoo.it> - 2013-06-04 08:28 -0700
Re: lstrip problem - beginner question mstagliamonte <madmaxthc@yahoo.it> - 2013-06-04 08:29 -0700
Re: lstrip problem - beginner question MRAB <python@mrabarnett.plus.com> - 2013-06-04 16:48 +0100
Re: lstrip problem - beginner question mstagliamonte <madmaxthc@yahoo.it> - 2013-06-04 08:53 -0700
Re: lstrip problem - beginner question Peter Otten <__peter__@web.de> - 2013-06-04 17:52 +0200
Re: lstrip problem - beginner question John Gordon <gordon@panix.com> - 2013-06-04 15:55 +0000
Re: lstrip problem - beginner question mstagliamonte <madmaxthc@yahoo.it> - 2013-06-04 09:06 -0700
Re: lstrip problem - beginner question Larry Hudson <orgnut@yahoo.com> - 2013-06-04 21:53 -0700
csiph-web