Did I find the right examples for you? yes no      Crawl my project      Python Jobs

All Samples(1)  |  Call(0)  |  Derive(0)  |  Import(1)
returns a stripped line from a file
either iterates previous lines or seeks to the offset

:param line: linenumber
:param offset: offset in file

        def get_line_from_file(file_name, line=None, offset=None):
    """
    returns a stripped line from a file
    either iterates previous lines or seeks to the offset

    :param line: linenumber
    :param offset: offset in file
    """
    fp = open(file_name)
    if line is not None:
        for i, fline in enumerate(fp):
            if i+1 == line:
                return fline.strip()
    elif offset is not None:
        fp.seek(offset)
        return fp.readline().strip()
    else:
        raise ValueError('At least one of line or offset must be set')
        


src/p/i/pida-0.6.2/tests/utils/test_path.py   pida(Download)
import os.path
from unittest import TestCase
from pida.utils.path import get_line_from_file, get_relative_path
 
class TestPath(TestCase):