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


Groups > comp.lang.python > #103535

Re: How to remove the line numbers from the file in python

Path csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail
From Peter Otten <__peter__@web.de>
Newsgroups comp.lang.python
Subject Re: How to remove the line numbers from the file in python
Date Fri, 26 Feb 2016 12:31:05 +0100
Organization None
Lines 33
Message-ID <mailman.146.1456486281.20994.python-list@python.org> (permalink)
References <CACT3xuXG=VA4-XwTZ3Jibtyr6QbO+yeagp4thCYYoJiF0t=Wag@mail.gmail.com>
Mime-Version 1.0
Content-Type text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding 7Bit
X-Trace news.uni-berlin.de WaMThoZl71Q54R3j0erFzgWhn5srljC+Sd52f5AFjCXg==
Return-Path <python-python-list@m.gmane.org>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.000
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'exit': 0.07; 'subject:file': 0.07; 'subject:How': 0.09; '"w")': 0.09; '%s\\n"': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'separating': 0.09; 'python': 0.10; 'def': 0.13; 'subject:python': 0.14; 'headers': 0.15; '"test': 0.16; 'received:80.91.229.3': 0.16; 'received:dip0.t-ipconnect.de': 0.16; 'received:io': 0.16; 'received:plane.gmane.org': 0.16; 'received:psf.io': 0.16; 'received:t-ipconnect.de': 0.16; 'status",': 0.16; 'subject:remove': 0.16; 'wrote:': 0.16; 'skip:l 30': 0.18; 'skip:" 30': 0.20; 'needed.': 0.23; 'import': 0.24; 'header:User-Agent:1': 0.26; 'header:X-Complaints-To:1': 0.26; 'skip:# 10': 0.27; 'subject:numbers': 0.29; 'print': 0.30; 'file': 0.34; 'text': 0.35; 'easiest': 0.35; 'replace': 0.35; 'lines': 0.36; 'to:addr :python-list': 0.36; 'subject:: ': 0.37; 'received:org': 0.37; 'files': 0.38; 'subject:from': 0.39; 'subject:the': 0.39; 'to:addr:python.org': 0.40; 'received:de': 0.40; 'leading': 0.61; 'body': 0.61; 'mail"': 0.84
X-Injected-Via-Gmane http://gmane.org/
X-Gmane-NNTP-Posting-Host p57bd9ac6.dip0.t-ipconnect.de
User-Agent KNode/4.13.3
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.21rc2
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>
Xref csiph.com comp.lang.python:103535

Show key headers only | View raw


Ganesh Pal wrote:

> what would be the easiest way to remove the lines in the leading
> numbers 1.e 1 ,2,.... 19  from this file  using python ?
> 
> 
>   1 import os
>   2 Suite = "Test Mail"
>   3
>   4 def sendMail(x):
>   5     text = x
>   6     sendmail_location = "/home/prasad/onefs/share/sendmail" #
> sendmail location
>   7     p = os.popen("%s -t" % sendmail_location, "w")
>   8     p.write("From: %s\n" % "ganesh.pal@gmail.com")
>   9     p.write("To: %s\n" % "ganesh.pal@gmail.com")
> 10     #p.write("To: %s\n" % "umamaheshwar.b@gmail.com")
> 11     p.write("Subject: Suite : %s \n" % (Suite))
> 12     p.write("\n") # blank line separating headers from body
> 13     p.write("%s" %text)
> 14     status = p.close()
> 15
> 16     if status != 0:
> 17         print "Sendmail exit status", status
> 18
> 19 sendMail("Test Mail")

sys.stdout.writelines(
    line.lstrip().lstrip("0123456789")[1:] or "\n" 
    for line in sys.stdin)

Replace stdin/out with files as needed.

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


Thread

Re: How to remove the line numbers from the file in python Peter Otten <__peter__@web.de> - 2016-02-26 12:31 +0100

csiph-web