def linecache_out_of_range():
    fn = linecache_data.make_tempfile()
    # the cache always return a string,
    # and uses an empty string
    # to indicate a line that does not exist.
    not_there = linecache.getline(fn, 500)
    print('NOT THERE: {!r} includes {} characters'.format(
        not_there, len(not_there)))

    linecache_data.cleanup(fn)
    pass
def linecache_getline():
    filename = linecache_data.make_tempfile()
    # pick out the sanme line from source and cache
    # ! (Notice that linecache counts from 1). Differs from normal lists indexing the array from 0
    print('SOURCE:')
    print('{!r}'.format(linecache_data.lorem.split('\n')[4]))
    print()
    print('CACHE:')
    print('{!r}'.format(linecache.getline(filename, 5)))
    linecache_data.cleanup(filename)

    pass
Exemple #3
0
#! /usr/bin/env/python
# -*- coding:utf-8 -*-

import linecache
from linecache_data import make_tempfile,cleanup,lorem

filename = make_tempfile()

#Blank lines include the newline
print 'BLANK :%r' % linecache.getline(filename,8)
cleanup(filename)
def linecache_empty_line():
    fn = linecache_data.make_tempfile()
    # Blank lines include the newline
    print('BLANK    : {!r}'.format(linecache.getline(fn, 8)))
    linecache_data.cleanup(fn)
# linecache_getline.py

import linecache
from linecache_data import lorem, make_tempfile, cleanup

filename = make_tempfile()

print('SOURCE:')
print('{!r}'.format(lorem.split('\n')[4]))
print()
print('CACHE:')
print('{!r}'.format(linecache.getline(filename, 5)))

cleanup(filename)