Python socket programming

Server #! /Usr/bin/env python Import socket Import time Host ='' Port = 99999 S = socket. socket (socket. AF_INET, socket. SOCK_STREAM) S. bind (host, port )) S. listen (2) While 1: Conn, addr = s. accept () #--------------- Print 'got connection

Python ping Module

:Download Paste v0.2 code backup #!/usr/bin/env python""" A pure python ping implementation using raw socket. Note that ICMP messages can only be sent from processes running as root. Derived from ping.c distributed in Linux's netkit. That

Configure python in linux

In fact, it is very easy to configure python in linux. 1. Check whether python has been installed on your linux server. Enter the following command line: Python-V If the version information is displayed, it indicates that python has been installed

How to solve the problem of displaying lower version information after installing python with a higher version?

[Root @ localhost Python-2.7.5] # pythonPython 2.4.3 (#1, Jun 11 2009, 14:09:58) [GCC 4.1.2 20080704 (Red Hat 4.1.2-44)] on linux2Type "help ", "copyright", "credits" or "license" for more information. >>> Just make a soft connection. [Root @

Python BeautifulSoup usage

Let's look at the example:Copy codeThe Code is as follows:#! /Usr/bin/python#-*-Coding: UTF-8 -*-From bs4 import BeautifulSoupHtml_doc = """ The Dormouse's story The Dormouse's story Once upon a time there were three little sisters; and their

Python connection pool implementation example Program

Copy codeThe Code is as follows:Import socketImport QueueImport 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]) + "):"

Python Timestamp and time string mutual conversion instance code

Copy codeThe Code is as follows:# Set a as a stringImport timeA = "10:00:00" # In the intermediate process, strings must be converted to time arrays.Time. strptime (a, '% Y-% m-% d % H: % M: % s ')> Time. struct_time (tm_year = 2011, tm_mon = 9, tm_

A simple python program instance (Address Book)

Core code: Copy codeThe Code is as follows:#! /Usr/bin/python# Filename: friendbook. pyImport cPickle as pImport sysImport timeImport OS AB = {'xdex ': 'cwds @ fnedf.com ','Last': 'fev @ fe.com ','Fukc ': 'fexok @ ver.com ','Stifu': 'stif @ qq.com'}

Python shared reference (multiple variable references) Sample Code

Copy codeThe Code is as follows:A = 3B = First (figure 1). You can see it at a Glance: Variable name and object. After running the value assignment statement B = a, both variables a and B point to the memory space of object 3.If a = 'python' is

Python uses PyV8 to execute javascript code example sharing

Install the corresponding library. I use PyV8. Note that the function written in it must be enclosed (). Copy codeThe Code is as follows:Import PyV8 Class Test (): Def js (self ): Ctxt = PyV8.JSContext () Ctxt. enter () Func = ctxt. eval ('''

Python thread learning example

Copy codeThe Code is as follows:# Encoding: UTF-8Import threadImport time# A function used for execution in a threadDef func ():For I in range (5 ):Print 'func'Time. sleep (1)# End the current thread# This method is equivalent to thread. exit_thread

Implementation of python ternary Operators

This is a question that comes to mind when I look at lambda expressions today. We all know that the ternary operators (? :) Is a very useful statement, About the ternary operators in C Expression 1? Expression 2: expression 3 So how should we

How to Use xmlrpc in python

RPC is short for Remote Procedure Call. It is a Remote method Call technique that calls a process (method) on a local machine, this process is also known as "Distributed Computing". It is a technology invented to improve the interoperability between

Python calculates the maximum priority queue instance

Copy codeThe Code is as follows:#-*-Coding: UTF-8 -*- Class Heap (object ): @ ClassmethodDef parent (cls, I ):"Parent subscripts """Return int (I-1)> 1 ); @ ClassmethodDef left (cls, I ):"Left son subscript """Return (I @ ClassmethodDef right (cls,

Python obtains hundreds of image codes.

Copy codeThe Code is as follows:From sgmllib import SGMLParserImport urllib2 Class sgm (SGMLParser ):Def reset (self ):SGMLParser. reset (self)Self. srcs = []Self. ISTRUE = True Def start_div (self, artts ):For k, v in artts:If v = "author ":Self.

Python file copying code implementation

The main functions are implemented in the copyFiles () function as follows: Copy codeThe Code is as follows:Def copyFiles (src, dst ):SrcFiles = OS. listdir (src)DstFiles = dict (map (lambda x: [x, ''], OS. listdir (dst )))FilesCopiedNum = 0# Copy

Python simulated logon to Baidu Post Bar (Baidu Post Bar logon) instance

  Copy codeThe Code is as follows: #-*-Coding: UTF-8 -*- # Python3.3.3 Import sys, time, re, urllib. parse, urllib. request, http. cookiejar, random, math, OS. path, hashlib, json, binascii, threading "" Cookie """Cookie = http. cookiejar.

Python Regular Expression matching query progress of Hong Kong and Macao passes

Copy codeThe Code is as follows:Import socketImport re '''Guangdong Provincial Authority Entry-Exit Government Affairs Service Network Passport, pass handling progress query.The analysis URL is formatted as

Why are there so many Python? (1)

Python is outstanding However, this is a very ambiguous sentence. What does "Python" mean? Is it an abstract interface of Python? Is CPython a general implementation of Python? Do not confuse CPython with Cython )? Or does it mean anything else?

Python: the first and last language you need

I did not care about the comparison between Python and Java. However, I was amazed at the author's point of view. Since I started using Python, I have never been able to express the wonderful experience it brings to me in words. Compare other

Total Pages: 4013 1 .... 3402 3403 3404 3405 3406 .... 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.