Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail From: Joel Goldstick Newsgroups: comp.lang.python Subject: Re: How to print a part of a string? Date: Fri, 15 Apr 2016 08:28:38 -0400 Lines: 44 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-Trace: news.uni-berlin.de 7mlvxTSm5fGj0v9VHRxfng7y0nnDb0q+AuJBcRZACKfg== Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.007 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'string.': 0.04; 'cc:addr :python-list': 0.09; 'subject:How': 0.09; 'subject:string': 0.09; 'received:209.85.218': 0.10; 'url:blog': 0.10; 'do,': 0.15; '2016': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'textfile': 0.16; 'wrote:': 0.16; '>>>': 0.20; 'all,': 0.20; 'cc:2**0': 0.20; 'cc:addr:python.org': 0.20; 'am,': 0.23; 'this:': 0.23; 'second': 0.24; 'header:In-Reply-To:1': 0.24; 'example': 0.26; 'fri,': 0.27; 'message-id:@mail.gmail.com': 0.27; "i'm": 0.30; 'print': 0.30; 'that.': 0.30; 'url:mailman': 0.30; 'code': 0.30; '15,': 0.30; 'certain': 0.31; 'another': 0.32; 'url:python': 0.33; 'open': 0.33; 'url:listinfo': 0.34; 'file': 0.34; 'received:google.com': 0.35; 'problem.': 0.35; 'url:org': 0.36; 'lines': 0.36; 'received:209.85': 0.36; 'subject:?': 0.36; 'subject:: ': 0.37; 'received:209': 0.38; 'means': 0.39; 'sure': 0.39; 'url:mail': 0.40; 'url:info': 0.71; 'homework': 0.84; 'to:none': 0.91; 'abc': 0.91; 'joel': 0.91 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:cc; bh=Vvr+IYjzMtPyCfVKTA6qXgMNSmaB7xSo7RIxKzjDEk8=; b=mkWk3fPyvH08a1vo2UHo1fX8k5viI0Zp8ciyIyy8RLfCCgsp9hCLSOSZoKZUqYOfEd QgdAodWX91ablSRntefu4h07jiEwBYgcmqGK7NNiFREsv9lnnP0aik2z7+l81MhPRSz7 d7IT2Tat7wvEbjDzGwnDIXcTY3kCDbzthv4NPd0bfV/AXMFQNUVTUZ/V+QUPMzaqynBZ b22eKcEM5nOKWVJrfmD+od08ov69uNDrp+JeKr3Plq1TDCjqo3BKqvIL1i2x+ehEfK4y ymzgQcm01b3o5FC1guOmZyDLiol60kMNyr59hHkjQTkDa58VnLiur0qdUYMJusNT46z1 4Z2A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:date :message-id:subject:from:cc; bh=Vvr+IYjzMtPyCfVKTA6qXgMNSmaB7xSo7RIxKzjDEk8=; b=W0fkJ4ZmhYyNBxldd5CJuRaL6ciEJl2Rb0elNfDXJmEqdeNKQMO33oaPdGeTniFoPx juxlqIKy+u+isgwVGCvzpixoxGTbXorlBTfuWIiSIvwVfzKNllfFOJrHX9+A10HH/9S5 a70ZuUCTbeDBR9FqeIoBxGFM6UN8K+z3VGEP+rEOHnNrGaxQYX5+X7uRtOkyidFR+5AH KpdC+/YCAa7YTzfUSII4V46HHAnfzerLV+kSP6j8Bwq78VsVuqjykklxa7vON0Vf4NHQ iE5Fyme97MIhN9+D3X3qioATIFEvoTlhG/m1wjgG1SqecYFrAAKxp961F4+brxXpSuqp JJvg== X-Gm-Message-State: AOPr4FWyGZ5+Bi3mnpnGCjpaB2KnEkXXKXrjKoMUc89T6m2OB61N+8u9l5cXQ/GzVUJOJyAcuyrf+1fAubfZUA== X-Received: by 10.157.13.53 with SMTP id 50mr11062825oti.35.1460723318940; Fri, 15 Apr 2016 05:28:38 -0700 (PDT) In-Reply-To: X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Mailman-Original-Message-ID: X-Mailman-Original-References: Xref: csiph.com comp.lang.python:107053 On Fri, Apr 15, 2016 at 8:13 AM, durgadevi1 wrote: > Hello all, > > I have another homework problem. > > I have a textfile. It contains lines of string. > > I am required to only print out a certain part of the string. > > For example the textfile contain: > > ABC XXXXX NNNNN > BCD QQQQQ EEEEE > ABC WWWWW AAAAA > > > I need to print all the parts that come after only ABC. > > That means I need to print only XXXXX from the first line and WWWWW from the second line. > > I'm not sure of what code to use to achieve that. > -- > https://mail.python.org/mailman/listinfo/python-list do you know how to open the file and do a for loop to get each line in the string? If you do, do you know about this: >>> s = "ABC XXXXX NNNNN" >>> s_split = s.split() >>> s_split ['ABC', 'XXXXX', 'NNNNN'] >>> s_split[0] 'ABC' >>> -- Joel Goldstick http://joelgoldstick.com/blog http://cc-baseballstats.info/stats/birthdays