one, python in the file, folder operations often used in the OS module and Shutil module common methods.
1. Get the current working directory, that is, the directory path of the current Python script work: OS.GETCWD ()
2. Return all files and
In the Webhostingtalk forum, some foreign businessmen will be virtual machine as a standalone server to sell, last July, when a Chinese fellow was deceived, and in WHT posted denounced, evidence, even the service providers themselves also admitted
Python itself has many very useful modules that can be used immediately as soon as the installation is complete.
Our built-in sys module, for example, writes a Hello module:
#!/usr/bin/env python#-*-coding:utf-8-*-' a test module ' __author__ = '
Considering the increasing number of servers in my hand, sometimes it is necessary to deploy the same file on a large scale, for example, because it is convenient to use the Systemtap tool to locate the problem, it needs to install kernel-debuginfo
Classes and Objects
Classes and functions are all objects in Python. When a class definition is complete, Python creates a "class object" and assigns it to a variable of the same name. Class is a type of object (is it a bit of a mouthful?) )。
The
type ()
The biggest difference between dynamic and static languages is the definition of functions and classes, not defined at compile time, but dynamically created at run time.
Let's say we want to define a Hello class and write a hello.py module:
Analysis
The number is often a group of 3 numbers followed by a comma, so the rule is: ***,***,***
Regular type
The code is as follows:
[A-z]+,[a-z]?
The code is as follows:
Import re
Sen = "ABC,123,456,789,MNP"p = re.compile ("\d+,\d+?")
For COM
The code is as follows:
#coding: Utf-8Import Urllib.requestImport Xml.dom.minidomImport Sqlite3Import threadingImport timeClass Logger (object):def log (self,*msg):For I in msg:Print (i)Log = Logger ()Log.log (' under test ')Class Downloader
Python 2.6 introduces the Itertools module, which makes the implementation of the permutation combination very simple:
The code is as follows:
Import Itertools
Orderly arrangement: e.g., 4 number of 2 selected permutations:
The code is as
Like most programmers, I often need to identify the parts and structures that exist in a text document, including: Log files, configuration files, delimited data, and a more free-form (but semi-structured) report format. All of these documents have
This example describes how Python uses 7z to unzip the APK package. Share to everyone for your reference. Specific as follows:
This code is extracted from the shell by invoking the 7z APK package
def run_shell (Command, Mayfreeze=false): Def check_
The following is a function defined first:
The code is as follows:
def foo ():Print (' function ')Foo ()
In the above code, a function named Foo is defined, and the function has no arguments. The function of the last line of code is to call this
This example describes how Python obtains an intermediate string based on the starting and ending strings. Share to everyone for your reference. The specific analysis is as follows:
This is given a string that specifies the beginning and end of
This article discusses Python's from
Import * and from
Import *, how they execute and why using this syntax (perhaps) is a bad idea.
import all from one module
from import * means means "I want to have access to
Recently, as more and more data scientists began to use Python, I could not help but think that although they benefited from the libraries of Pandas, Scikit-learn and NumPy, they might have missed some of the older but also helpful python libraries.
This example describes how Python randomly assigns user-agent to each request when it uses Scrapy to collect data. Share to everyone for your reference. The specific analysis is as follows:
This method allows each request to change different
1, single pixel (draw point)
There are three main ways to draw points using Pygame:Method One: Draw a square with a length of 1 pixels wide
The code is as follows:
Import Pygame,sysPygame.init ()Screen=pygame.display.set_caption (' Hello world!
The example in this article describes how Python implements downloading pictures from a feed. Share to everyone for your reference. Specific as follows:
This code is implemented based on Python 3.4, and Python2. X is a lot different than that.This
about Gnumeric
Gnumeric is a powerful and easy-to-use spreadsheet software under the Linux platform that is very consistent in style with other common spreadsheet software such as Excel. Gnumeric the current stable version is 1.2.13, the support
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