def rmlinenumber(linenumber, infile, dryrun=False):
    """
    Sed-like line deletion function based on given line number..
    Usage: pysed.rmlinenumber(<Unwanted Line Number>, <Text File>)
    Example: pysed.rmlinenumber(10, '/path/to/file.txt')
    Example 'DRYRUN': pysed.rmlinenumber(10, '/path/to/file.txt', dryrun=True)
    #This will dump the output to STDOUT instead of changing the input file.

    """

    linelist = []
    linecounter = 0
    if isinstance(linenumber, int):
        exit("""'linenumber' argument must be an integer.""")
    with open(infile) as reader:
        for item in reader:
            linecounter = linecounter + 1
            if linecounter != linenumber:
                linelist.append(item)
    if dryrun is False:
        with open(infile, "w") as writer:
            writer.truncate()
            for line in linelist:
                writer.writelines(line)
    elif dryrun is True:
        for line in linelist:
            print(line, end='')
    else:
        exit("""Unknown option specified to 'dryrun' argument,
              Usage: dryrun=<True|False>.""")
def rmlinenumber ( linenumber , infile , dryrun = False ) : linelist = [ ] linecounter = 0 if isinstance ( linenumber , int ) : exit ( """'linenumber' argument must be an integer.""" ) with open ( infile ) as reader : for item in reader : linecounter = linecounter + 1 if linecounter != linenumber : linelist . append ( item ) if dryrun is False : with open ( infile , "w" ) as writer : writer . truncate ( ) for line in linelist : writer . writelines ( line ) elif dryrun is True : for line in linelist : print ( line , end = '' ) else : exit ( """Unknown option specified to 'dryrun' argument,
              Usage: dryrun=<True|False>.""" )
Sed-like line deletion function based on given line number..
    Usage: pysed.rmlinenumber(<Unwanted Line Number>, <Text File>)
    Example: pysed.rmlinenumber(10, '/path/to/file.txt')
    Example 'DRYRUN': pysed.rmlinenumber(10, '/path/to/file.txt', dryrun=True)
    #This will dump the output to STDOUT instead of changing the input file.