Deleting lines in python
<p>I was just wondering how to delete lines in python.</p>

<p>Firstly I have opened up the csv file (using the with statements and whatnot), however the first couple of lines are unneccessary. They go along the lines of this:</p>

<p>**version 2.0 keyboard strokes</p>

<p>version 1.5 mouse wheel</p>

<p>...       ..**</p>

<p>[data starts here which i will manipulate]</p>

<p>Any functions I could use to perheps prompt the user with the number of rows theyd like to delete for future spreadsheets?</p>

<pre><code>    from __future__ import print_funciton
    import fileinput
    import csv

    with open('filename.csv', delimiter=",")

           readcsv = csv.reader(csvfile, delimiter=",")
           skip_rows = int(input('How many rows to skip? '))

           for i in range(skip_rows):
                 _ = next(readcsv)
           for row in readcsv:
                 print(row,end='')
</code></pre>

<p>Alternatively, I tried this, but it doesnt seem to get rid of the rows that have blank spaces (blank rows included in the number of rows I'd like to delete). Meanwhile, the code above appears to get rid of those blank spaces, but there is line termination.</p>

<pre><code>    next(filecsv) for i in range(10)
</code></pre>

<p>There are quite a few ways to grab input from a command line tool (which is what I am inferring you wrote).  Here are a couple:</p>

<p><em>Option 1:</em>  created in a file called out.py
use sys.argv</p>

<pre><code>import sys
arg1 = sys.argv[1]
print("passed in value: %s" % arg1)
</code></pre>

<p>Then run it by passing in an argument (note index 1, script is index 0)</p>

<pre><code>python out.py cell1
passed in value: cell1
</code></pre>

<p><em>Option 2:</em></p>

<p>A potentially better way is to use a commandline tool framework like click:  <a href="http://click.pocoo.org/5/" rel="nofollow">http://click.pocoo.org/5/</a>.  This has almost everything you could ever want to do, and they handle much of the hard logic for you.</p>

python csv