There is a demand online, formatting, from a pile of s1, s100-s199 to find continuous servers and formatting display, such:Magic: S106-109, s123, s125Royal sword: s106-109, s123, s125Copy codeThe Code is as follows:#! /Usr/bin/env python#-*-Coding:
Copy codeThe Code is as follows:#! /Usr/bin/env python#-*-Coding: UTF-8 -*-
# Import the random and string modulesImport random, string
Def GenPassword (length ):# Number of random numbersNumOfNum = random. randint (1, length-1)NumOfLetter =
Previously, we read data from the file, processed the data, and printed it using the print statement. However, we often need to save the processed data to a file. So here we will introduce how to save the processed data to a file, because we only
Import time print time. strftime ('% H-% M-% s ')Time and date formatting symbols in python:
% Y two-digit year (00-99)
% Y indicates the four-digit year (000-9999)
% M month (01-12)
One day in % d month (0-31)
% H hour in 24-hour format (0-23)
Python shell >>> open('abc.txt ', 'R') Traceback (most recent call last): File "", line 1, in IOError: [Errno 2] No such file or directory: 'abc.txt 'open a file named abc.txt that does not exist. If the system cannot find the file named abc.txt,
Sometimes it is inevitable to directly call Shell commands to complete some simple operations, such as mount a file system. So how can we use Python to call Linux Shell commands? The following describes several common methods:1. OS Module
1.1. exec
A bug in Libmimetypes. py in python27, which belongs to the def enum_types (mimedb) function:
Error message:
File D: Python27libmimetypes. py, line 249, in enum_types ctype = ctype. encode (default_encoding) # omit in 3.x! UnicodeDecodeError:
Because voice recognition requires the use of voxforge speech files, but there are too many voxforge files, manual download is definitely not acceptable. You can use the batch Download Software for download. Out of curiosity, I plan to use python to
This chapter describes how to create your own objects:
7.2 create your own class
First, you can use a simple class.
_metaclass_=type>>> class Person:def setName(self,name):self.name=namedef getName(self):return self.namedef greet(self):print ("hello
In the previous article, we used python for file reading and simple data processing, but we encountered a problem during processing, it means that an error is caused by the absence of a colon in a row. In the end, we add the if statement to the
The performance of the table jumping is similar to that of the Red/black tree AVL, but the structure is quite simple.
You can easily perform table jumping by simply operating the linked list.
Refer to the following article and use python to
Copy codeThe Code is as follows:# Compare two strings. If they are different, return the first different position# If the same result is returned, 0 is returned.Def cmpstr (str1, str2 ):Col = 0For c1, c2 in zip (str1, str2 ):If c1 = c2:Col + =
The struct module of Python is used to create and extract packaged binary data from strings.Pack (fmt, v1, v2,...) encapsulates data into strings (actually byte streams similar to the c struct) in the given format (fmt ). Unpack (fmt, string) parses
Map Functions
Python actually provides a built-in tool, map function. The main function of this function is to apply the passed-in function to each element of a sequence object, and return a list containing the results of all function
This article is translated from How to become a proficient Python programmer.
This article is a summary of some articles I have collected. Because many talented people have already written a lot of good articles about how to become a good Python
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