Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail From: Dan Strohl Newsgroups: comp.lang.python Subject: RE: How to print a part of a string? Date: Fri, 15 Apr 2016 14:27:38 +0000 Lines: 51 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable X-Trace: news.uni-berlin.de ZWpKGQ9eve6y/NBcGaAhxAT7VrGWRbnwJ+zPlQ/8fN0Q== Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.009 X-Spam-Evidence: '*H*': 0.98; '*S*': 0.00; 'python,': 0.02; 'string.': 0.04; 'friday,': 0.07; 'subject:How': 0.09; 'lookup': 0.09; 'subject:string': 0.09; 'message-----': 0.15; '2016': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'skip:[ 50': 0.16; 'textfile': 0.16; 'string': 0.17; 'string,': 0.18; '(in': 0.18; 'all,': 0.20; 'to:name:python-list@python.org': 0.20; 'to:2**1': 0.21; 'bit': 0.23; 'matching': 0.23; 'second': 0.24; 'header:In- Reply-To:1': 0.24; 'example': 0.26; 'dan': 0.29; 'received:192.168.10': 0.29; "i'm": 0.30; 'print': 0.30; 'that.': 0.30; 'url:mailman': 0.30; 'creating': 0.30; 'code': 0.30; '15,': 0.30; 'certain': 0.31; 'another': 0.32; 'table': 0.32; 'url:python': 0.33; 'skip:- 10': 0.34; 'url:listinfo': 0.34; 'sent:': 0.35; 'could': 0.35; 'subject:': 0.35; 'problem.': 0.35; 'but': 0.36; 'there': 0.36; 'url:org': 0.36; 'lines': 0.36; 'possible': 0.36; 'email addr:python.org': 0.36; 'to:addr:python- list': 0.36; 'subject:?': 0.36; 'subject:: ': 0.37; 'charset:us- ascii': 0.37; 'things': 0.38; 'means': 0.39; 'sure': 0.39; 'from:': 0.39; 'received:192': 0.39; 'url:mail': 0.40; 'to:addr:python.org': 0.40; 'some': 0.40; 'your': 0.60; 'hints': 0.66; 'python-list': 0.66; 'here': 0.66; 'email name:python-list': 0.67; 'homework': 0.84; 'received:192.168.15': 0.84; 'abc': 0.91; 'luck': 0.95 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=f5.com; i=@f5.com; q=dns/txt; s=seattle; t=1460730461; x=1492266461; h=from:to:subject:date:message-id:references:in-reply-to: content-transfer-encoding:mime-version; bh=wj6Yf1UkLij8qLiQDWp6XAgzgf9++N1y/3co9UWz/7I=; b=MoLboFYzlD7z4wyqyLr/SmcEJk3dtJCQ7uQ0T13+2uo7vpohRGuI4neA mRbX8A0RO3WjHiK8g29i2ZPmYBdHmtQcgPHvaT32m9KSD3mORLm5JCXRU 4XUNVscOGPI2DRkJaz6hEhzsRxHJrTE/Otlmy1LlzjEU6MRKOwe3GukOu 4=; X-IronPort-AV: E=Sophos;i="5.24,487,1454976000"; d="scan'208";a="213151910" Thread-Topic: How to print a part of a string? Thread-Index: AQHRlxEOk5A6teZlIEWF4N/Aq6wToJ+LFbTw In-Reply-To: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-exchange-transport-fromentityheader: Hosted x-originating-ip: [192.168.15.239] 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:107058 As with lots of things in python, there are lots of ways of approaching thi= s, here are some hints for you to think about (in no particular order): - REGEX=20 - replace() - string[:y] - split() And of course, you could consider creating a table with every possible stri= ng that could start with "ABC", and it's matching non-"ABC" string, then lo= okup the string in the table and get your match, it's a bit brute forcey, b= ut it would work (eventually) Good luck in your homework! Dan > -----Original Message----- > From: Python-list [mailto:python-list-bounces+d.strohl=3Df5.com@python.or= g] > On Behalf Of durgadevi1 > Sent: Friday, April 15, 2016 5:13 AM > To: python-list@python.org > Subject: How to print a part of a string? >=20 > Hello all, >=20 > I have another homework problem. >=20 > I have a textfile. It contains lines of string. >=20 > I am required to only print out a certain part of the string. >=20 > For example the textfile contain: >=20 > ABC XXXXX NNNNN > BCD QQQQQ EEEEE > ABC WWWWW AAAAA >=20 >=20 > I need to print all the parts that come after only ABC. >=20 > That means I need to print only XXXXX from the first line and WWWWW from > the second line. >=20 > I'm not sure of what code to use to achieve that. > -- > https://mail.python.org/mailman/listinfo/python-list