Today made a use of Python to extract the contents of the log, and exported Excel small script, the code is not good, novice do not spray, the following to summarize.The requirements are as follows:1. Read the number of file lines and make an Excel table2. Read the 7th field in the file, summing up the sum to find the
At work, you often need to extract the specific URL address of the APK file, which is the idea of using a Python script for automatic processing.
The Python basics you need to use are as follows:
Os.walk ()
function declaration: Os.walk (Top,topdown=true,onerror=none)
(1) The parameter top represents the path of the to
Through the TCP/IP protocol learning, I wrote a can achieve the Pcap file in the IPV4 TCP stream extraction, as well as extract the specified TCP stream, in order to learn, did not adopt the third party package parsing pcap, but the analysis of the bytes stream, the core idea is: If you want to extract TCP Content, in the lower-level IPV4 protocol to determine wh
""" #Gets the current page article URLLb_url = Response.xpath ('//a[@class = "archive-title"]/@href'). Extract ()#get the article List URL forIinchLb_url:#print (parse.urljoin (response.url,i)) #urllib库里的parse模块的urljoin () method, is an automatic URL stitching, if the URL address of the second parameter is relative to the path will be automatically spliced with the first parameter yield Request (url=parse.urljoin (response.u
From a simple perspective, the zip format will be a good choice, and Python's support for the ZIP format is simple and easy to use.
1) Simple Application
If you only want to use python for compression and decompression, you don't need to repeat the document. Here we provide a simple usage for you to understand at a glance.
Import zipfile
F = zipfile.zipfile('filename.zip ', 'w', zipfile. zip_deflated)
F.write('file1.txt ')
F.write('file2.doc ')
F.
Python's Tarfile module makes it easy to read tar archive files, and Cow B is able to handle compressed archive files using gzip and bz2 tar.gz and tar.bz2.
Corresponding to the Tarfile is the ZipFile module, ZipFile is the processing of zip compression. Note: Os.system (cmd) allows the Python script to execute commands, of course including: Tar-czf *.tar.gz *,tar-xzf *.tar.gz,unzip and so on, when I think this can solve the problem, but I feel very a
Reading floating-point data from a text file is one of the most common tasks, and Python does not have scanf such input functions, but we can use regular expressions to extract floating-point numbers from a read string
Copy Code code as follows:
Import re
fp = open (' C:/1.txt ', ' R ')
s = Fp.readline ()
Print (s)
Alist = Re.findall (' [
in the Python help document is that Iteralbe refers to an object that can return one of its members at one time.Iteralbe mainly includes 3 categories:The first class is all sequence types, such as list (lists), STR (strings), tuple (tuples).The second class is a number of dict types, such as a dictionary, file, and so on.The third class is the object of any class you define that contains the __iter__ () or
I have already posted a piece of code about Baidu Post bar grabbing. today, let's take a look at the community version of the code and refer to the idea of grabbing the Encyclopedia of the community, for more information, see Baidu Post Bar's crawler production. it works basically the same as Baibai's crawler production. The key data is deducted from the source code and stored in a local txt file.
Project content:
Web crawler of Baidu Post Bar writte
Author: vamei Source: http://www.cnblogs.com/vamei welcome reprint, please also keep this statement. Thank you!
1. Introduction to paths and files
See Linux File System
Http://www.cnblogs.com/vamei/archive/2012/09/09/2676792.html
2. OS. Path package
The OS. Path package mainly processes path strings, such as '/home/vamei/doc/file.txt', to extract useful information.
Import OS. pathpath = '/home/vamei/doc/
() #将字符串写入文件F.writelines () #将列表内所有字符串写入文件F.close () #手动关闭F.flush () #把输出缓冲区刷到硬盘中F.seek (N) #将文件指针移到N处, in bytesFor line in open (' Data '):Print (line) #文件迭代器将文件一行行读出Open (' F.txt ', ' R '). Read () #read all @ ance into string
Three: Storing and parsing Python objects in a file
X, y, z = 41,42,43s = ' spam ' D = {' A ': 1, ' B ': 2} #字典对象L = [' A ', ' B ', ' C '] #列表f = open (' F.txt ', ' W ') f.write (s
-line identifiersAlist = F.readlines () #读取整个文件到字符串列表F.write () #将字符串写入文件F.writelines () #将列表内所有字符串写入文件F.close () #手动关闭F.flush () #把输出缓冲区刷到硬盘中F.seek (N) #将文件指针移到N处, in bytesFor line in open (' Data '): Print (line) #文件迭代器将文件一行行读出Open (' F.txt ', ' R '). Read () #read all @ ance into stringThree: Storing and parsing Python objects in a fileX, y, z = 41,42,43s = ' spam 'D = {' A ':
Python applets, file operations and other
Below are several small programs written by myself for file operations, including file operations and the use of lists (collections and dictionaries. For example, read a row of data from a file, store it in the list, and then perform
These files were previously extracted using a colleague's batch file; Not quite handy, just recently learning some python, all on their own to write a Python extract files applet;
1. Principle
The principle of extracting files is very simple, that is, to a specified directory, to find the last modified time than a gi
Use a Python script to extract a sequence of specified ID names#!/usr/bin/python3#-*-coding:utf-8-*-# Extract the sequence of the specified IDs import Sysargs =SYS.ARGVFR=open (args[1],'R') FW=open ('./out.fasta','W') Dict={} forLineinchfr:ifLine.startswith ('>'): Name=line.split () [0] Dict[name]="' Else: Dict[name]+=line.replace ('\ n',"') Fr.close () forIdi
1. Search file name beginning with the specified string (e.g. search DLL, results containing DLL a,dll ABC, etc.)My directory has DLLs A.txt and dll.txt filesWhere a folder has these two filesI want to find the four files by Python by choosing the keyword DLL.Import OSResult=[]def search (path= ".", Name= ""): For item in Os.listdir (path): Item_path = Os.path.join (path, item) If Os.path.i
. ReadLine()) prints The single row of the current cursorprint (FFF. ReadLines ()) prints everything after the cursor ( multiline ) F. close () close Open file f.tell () file cursor position
(medium: 3, UK: 1) F. seek (3) artificially cursor is positioned to 3 F. flush () contents from memory written to disk F.truncate([size]) intercepts the
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.