예제 #1
0
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
예제 #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)
예제 #4
0
#! /usr/bin/env/python
# -*- coding:utf-8 -*-

import linecache
from linecache_data import make_tempfile, cleanup, lorem

filename = make_tempfile()

#The cache always returns a string,
#and uses an empty string to indicate a line which does not exist

not_there = linecache.getline(filename, 500)
print 'NOT THERE:%r includes %d characters' % (not_there, len(not_there))
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)