Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #107058

RE: How to print a part of a string?

Path csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail
From Dan Strohl <D.Strohl@F5.com>
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 <mailman.26.1460730463.6324.python-list@python.org> (permalink)
References <edfe7d06-e8b1-4cef-92c3-2d1a217ebdac@googlegroups.com> <edbd324de7cb45eab05432ccbe2aa0c3@seaexchmbx03.olympus.F5Net.com>
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 <prvs=906233d47=D.Strohl@f5.com>
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 <edfe7d06-e8b1-4cef-92c3-2d1a217ebdac@googlegroups.com>
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 <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>
X-Mailman-Original-Message-ID <edbd324de7cb45eab05432ccbe2aa0c3@seaexchmbx03.olympus.F5Net.com>
X-Mailman-Original-References <edfe7d06-e8b1-4cef-92c3-2d1a217ebdac@googlegroups.com>
Xref csiph.com comp.lang.python:107058

Show key headers only | View raw


As with lots of things in python, there are lots of ways of approaching this, here are some hints for you to think about (in no particular order):

- REGEX 
- replace()
- string[:y]
- split()

And of course, you could consider creating a table with every possible string that could start with "ABC", and it's matching non-"ABC" string, then lookup the string in the table and get your match, it's a bit brute forcey, but it would work (eventually) <grin>

Good luck in your homework!

Dan




> -----Original Message-----
> From: Python-list [mailto:python-list-bounces+d.strohl=f5.com@python.org]
> 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?
> 
> 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

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

How to print a part of a string? durgadevi1 <srirajarajeswaridevikrupa@gmail.com> - 2016-04-15 05:13 -0700
  Re: How to print a part of a string? Joel Goldstick <joel.goldstick@gmail.com> - 2016-04-15 08:28 -0400
  RE: How to print a part of a string? Dan Strohl <D.Strohl@F5.com> - 2016-04-15 14:27 +0000
  Re: How to print a part of a string? durgadevi1 <srirajarajeswaridevikrupa@gmail.com> - 2016-04-16 00:25 -0700
  RE: How to print a part of a string? Joaquin Alzola <Joaquin.Alzola@lebara.com> - 2016-04-15 12:40 +0000

csiph-web