Wrote a python script to monitor the Nginx process _python

Copy Code code as follows: #!/usr/bin/env python Import OS, sys, time While True: Time.sleep (3) Try ret = Os.popen (' ps-c nginx-o pid,cmd '). ReadLines () If Len (ret) Print "Nginx process killed, restarting service in 3 seconds."

Python directory and filename operation example _python

1. Operation directory and filename #!/usr/bin/env python #-*-coding:utf-8-*- import os,re import shutil import Time Search with Listdir def search_ofd_old (My_pattern, diretory): try: names = Os.listdir (diretory)

A picture of a Spider-man code written in Python _python

Copy Code code as follows: #coding =utf-8 Import OS Import Sys Import re Import Urllib Url_reg = Re.compile (R ' (http://[^///]+) ', Re. I) Img_reg = Re.compile (R ' ]*?src= ([/' "]) ([^/1]*?) /1 ', Re. I) def download (dir, url):

Python writes a simple HTML page merge script _python

Recently wrote a bootstrap page ... Because the function needs to decide a page to solve all the problems, and then use jquery to dynamically display features .... However, the page would be quite large, with a stack of hidden modal windows and

Implementation and usage of cross-platform Python asynchronous callback mechanism _python

1 Copy the following code to a file named asyncore.py Copy Code code as follows: Import socket Import Select Import Sys def ds_asyncore (addr,callback,timeout=5):S=socket.socket (Socket.af_inet,socket.

Python Connection Pooling Implementation sample program _python

Copy Code code as follows: Import socket Import Queue Import threading def worker ():While True:i = Q.get ()CONN=I[0]ADDR=I[1]While 1:SMS=CONN.RECV (1024)If sms!= "":Print "Message from" ("+str (addr[0]) +": "+str (addr[1]) +"):

Implementation code for Python insert sort algorithm _python

1. Algorithm:Has a set of keywords {k 1, K 2, ..., k n}; Sorting begins with the view that K 1 is an ordered sequence, so that K 2 is inserted into an ordered sequence with a table length of 1, which is ordered by the table length 2, and then K 3 is

Python uses Reportlab to draw illustrations (including Chinese characters) _python

Preparatory work Development environment: Python2.6,reportlab Prepare Chinese font files: SIMSUN.TTC Code: Copy Code code as follows: #!/usr/bin/env python2.6 #coding: Utf-8 Import Traceback From reportlab.graphics.shapes

Example of simple use of mechanize libraries in Python _python

Copy Code code as follows: #!/usr/bin/env/python #coding =utf-8 Import Mechanize Import Cookielib # Cookie JarCJ = Cookielib. Lwpcookiejar () # Browserbr = Mechanize. Browser ()Br.set_cookiejar (CJ) # Browser

Python's Print usage example _python

In Python 2.6, print is not a function, but a keyword that is used in the following ways: Copy Code code as follows: Print 1, 2 print ' A ', ' B ' The results are as follows: A space is printed between the comma-separated items, which

Sharing _python using the Python Statistical file rows sample

Copy Code code as follows: Import time def block (file,size=65536):While True:NB = file.read (size)If not NB:BreakYield NB def getlinecount (filename):with open (filename, "R", encoding= "Utf-8") as F:return sum (line.count ("\ n") for

Detailed explanation of __init__ and __new___python in Python

First, what is the __init__ method?Students who have written object-oriented code in Python may already be familiar with __init__ methods, and __init__ methods are often used when initializing a class instance. For example: Copy Code code as

Common Python data type conversion function Summary _python

1, Chr (i)The CHR () function returns the string corresponding to the ASCII code. Copy Code code as follows: >>> Print Chr (65) A >>> Print Chr (66) >>> print Chr (+CHR) (66) Ab 2, complex (Real[,imaginary])The complex (

Troubleshoot problems in which the Windows service written by Python does not start _python

Reported the "service does not respond or control the request" error, instead of Pyinstaller generation is not; Check the data after the modification setup.py as follows, the service name, the title of the foot Please replace: Copy Code code

Python implementation guess number game (no repeat number) sample sharing _python

Copy Code code as follows: Import time, Random Class Guessnum:def __init__ (self):Self._num = ' 'Self.input_num = []Self.count = 1 #猜对所用次数self.sec = 0 #猜对所用时间Self._generate_num ()def _generate_num (self): #产生不重复的四个数字Seq_zton = List (range (1

Use Python to remove the Nginx cache file sample (Python file operation) _python

Input parameters such as: www.jb51.net/to delete www.jb51.net first page cache, www.jb51.net/test.php means to delete/test.php cache Copy Code code as follows: #coding =utf8 Import Sys,os Import Hashlib If Len (SYS.ARGV) Print ("You did

Python implements IP query sample _python

The following code implements the IP query functionProcessing program Copy Code code as follows: Import Os,time def getip (filepath):ip2city={}File=open (filepath, ' R ')Lines=file.readlines ()File.close ()For line in

Python basic tutorial Meta Group operations using the detailed _python

Brief introduction Tuple 1. Tuples are collections of data surrounded by parentheses "()", separated by "," by different members. Access through subscript 2. Immutable sequence, can be considered as immutable list, and the list is different: the

Python crawls the page picture and puts it in the specified folder _python

Python crawls a picture of a Web site and places it in a specified folder Copy Code code as follows: #-*-Coding=utf-8-*- Import Urllib2 Import Urllib Import socket Import OS Import re Def docment (): Print U ' put a file in a

Python data structure Type: string, list, tuple, dictionary, collection

One, the stringName ='Alex'#Capitalize first letterPrint(Name.capitalize ()) name='ALex Li 中文版 hahae'#First Letter LowercasePrint(Name.casefold ())#Center The specified length with = To be paddedPrint(Name.center (10,'='))#Develop scope

Total Pages: 4013 1 .... 3869 3870 3871 3872 3873 .... 4013 Go to: GO

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.