Python module application (linecache)

Source: Internet
Author: User

Linecache

Linecache is a library of functions that specifically support reading large files and support row-type reading. Linecache pre-reads the file into the cache, and later, if you access the file, it is no longer read from the hard disk. Good reading efficiency for large files

Help on module Linecache:name linecache-Cache Lines fromfiles. FILE/usr/local/lib/python2.7/linecache.pymodule DOCS http:docs.python.org/library/Linecachedescription This isIntended to read lines fromModules imported--henceifa filename is  notFound, it'll look down the module search path fora file by that name. FUNCTIONS checkcache (filename=None)        Discard cache entries that is out of date. ( this is  notchecked upon each call!)        ClearCache () Clear the cache entirely. Getline (filename, Lineno, module_globals=None) DATA__all__= ['Getline','ClearCache','Checkcache']
Help (Linecache)

Common methods:

Linecache.getlines (filename,)  # receives a file object, returns a list, and each element in the list is a row in the file. Same as ReadLines () Linecache.getline (Filename,lineno)  # receives a file object and a number of rows, returning the row contents for the specified number of rows
>>> Linecache.getlines ('/etc/passwd')['root:x:0:0:root:/root:/bin/bash\n','bin:x:1:1:bin:/bin:/sbin/nologin\n','daemon:x:2:2:daemon:/sbin:/sbin/nologin\n','adm:x:3:4:adm:/var/adm:/sbin/nologin\n','lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin\n','sync:x:5:0:sync:/sbin:/bin/sync\n','shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown\n','halt:x:7:0:halt:/sbin:/sbin/halt\n','mail:x:8:12:mail:/var/spool/mail:/sbin/nologin\n','uucp:x:10:14:uucp:/var/spool/uucp:/sbin/nologin\n','operator:x:11:0:operator:/root:/sbin/nologin\n','games:x:12:100:games:/usr/games:/sbin/nologin\n','gopher:x:13:30:gopher:/var/gopher:/sbin/nologin\n','ftp:x:14:50:ftp user:/var/ftp:/sbin/nologin\n','nobody:x:99:99:nobody:/:/sbin/nologin\n','Dbus:x:81:81:system Message bus:/:/sbin/nologin\n','vcsa:x:69:69:virtual Console Memory owner:/dev:/sbin/nologin\n','abrt:x:173:173::/etc/abrt:/sbin/nologin\n','Haldaemon:x:68:68:hal daemon:/:/sbin/nologin\n','ntp:x:38:38::/etc/ntp:/sbin/nologin\n','saslauth:x:499:76: "SASLAUTHD user":/var/empty/saslauth:/sbin/nologin\n','postfix:x:89:89::/var/spool/postfix:/sbin/nologin\n','sshd:x:74:74:privilege-separated ssh:/var/empty/sshd:/sbin/nologin\n','tcpdump:x:72:72::/:/sbin/nologin\n','ansibletest:x:500:500::/home/ansibletest:/bin/bash\n','Mysql:x:27:27:mysql server:/var/lib/mysql:/bin/bash\n','Zabbix:x:498:499:zabbix monitoring system:/var/lib/zabbix:/sbin/nologin\n','apache:x:48:48:apache:/var/www:/sbin/nologin\n','Elasticsearch:x:497:498:elasticsearch user:/home/elasticsearch:/sbin/nologin\n','Redis:x:496:497:redis server:/var/lib/redis:/sbin/nologin\n','pythons:x:501:501::/home/pythons:/bin/bash\n']
Linecache.getlines ()
>>> linecache.getline ('/etc/passwd', ten)'uucp:x:10:14: uucp:/var/spool/uucp:/sbin/nologin\n'>>> linecache.getline ('/etc/passwd  ', 5)'lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin\n'
Linecache.getline ()

Python module application (linecache)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.