Create a file and write content to it
Import OS # Coding = 'utf-8' # Get OS linefeed ls = OS. linesep # Get the file name while true: fname = raw_input ('input file name: ') If OS. path. exists (fname): Print "error: '% s' already exists! "% Fname
From http://obmem.info /? P = 476
Python has been used for more than three months, and the most common examples are crawler scripts: scripts that capture the local verification of the proxy, I wrote the script for automatic logon and Automatic
I made a compromise. Although the effect is not good, I can always catch things.
# Coding: utf-8import timeimport threadingimport queuerlock = threading. rlock () Class mthread (threading. thread): def _ init _ (self, oputque, * ARGs, ** kd_args):
Confusion between guid and UUIDC # is too deep, so when looking for a way to generate a unique value, it is natural to search for "Python guid ". Poor results. I thought Python didn't generate a method similar to the guid in C. Calm down and look
This is the content introduced in the python Learning Group. It is a good way to learn and practice more.
Step 1: Prepare the simplest function and add additional functions.
#-*-Coding: GBK-*-''' Example 1: The simplest function, indicating
# Coding = 'utf-8' class user (): def _ init _ (self, name, sex): Self. name = Name self. sex = sex print 'here is the constructor 'def setname (self, name): Self. name = Name def getname (Self): return self. nameuser = user ("Python", 'male') user.
Create
>>> List = ["A", "B", "C", "D", "E"] >>> list ['A', 'B ', 'C', 'D', 'E']
Obtains an element or substring.
>>> List = ["A", "B", "C", "D ", "E"] # obtain the first element >>> list [0] 'A' # obtain the last element >>> list [-1] 'E' # If
In python, the priority order for accessing an attribute is as follows:
Class attributes
Data Descriptor
Instance attributes
Non-data Descriptor
The complete definition of the _ getattr _ () method is as follows:
Def _
Class Method string. Upper (STR) needs to introduce the string module, the instance method Str. Upper () does not need to introduce the string Module
Unparalleled list resolution
# Coding = UTF-8 # list parsing print [I * 2 for I in [8,-2, 5]
>>> Logfile = open ('/tmp/mylog.txt', 'A ')
>>> Print> logfile, 'fatail error: invalid arguments'
>>> Logfile. Close ()
>>>
User = raw_input ("Please input your name :")
Numbers:
Int
Long
Bool(True, false)
Float
Complex(6.23
Python get Baidu get search results
# -*-Coding: cp936 -*- Import Urllib2, urllib, sys, Io """ Use get to query on Baidu search engine. This example shows how to generate a get string and request it. """ URL = " Http://www.baidu.com "
generally, the number of function parameters should not be too large. If the number of function parameters is too large, the function will not be easy to understand and use. In C, if there are too many function parameters, function parameters will
This is a small Socket Application I wrote before, and I also used a little bit of multithreading.This Socket Client is a small application I wrote to facilitate the company's recharge system debugging. It communicates with the recharge system to
Many people in Python are familiar with python, and I am a late adopter. Although it is a slow step, learning will never be too late. In fact, as a shell, whether it is Perl, Ruby, powershell, and so on, the syntax is very similar. I have never
Python operations on JSON
To be honest, I don't do front-end development. I really don't have any special feelings for JSON. I recently encountered a problem using python to operate JSON. I am also prepared to have a simple understanding of the
When printing strings in Python, you can call ljust (left-aligned), right-aligned (right-aligned), and center (center-aligned) to output neat and beautiful strings, which is very easy to use, this includes filling with the second parameter (space by
In python, the sub-string in a string is extracted in a certain format. It is very efficient to use struck. Unpack.1. Set the fomat format as follows:# Take the first 5 characters, skip 4 characters, and then 3 Characters
Format = '5s 4x 3s'
2. Use
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