Python brings a lightweight relational database SQLite. This database uses the SQL language. SQLite as a back-end database, you can build a Web site with Python or create tools that have data storage requirements. SQLite also has a wide range of applications in other areas, such as HTML5 and mobile terminals. The sqlite3 in the Python
has been returned to the teacher, so many distribution ╮(╯▽╰)╭★random.random () returns a random floating-point number in [0.0, 1.0].★random.uniform (A, B) returns the random floating-point number in [A, b]Random.triangular (low=0.0, high=1.0, Mode=none)Random.betavariate (alpha, beta) Beta distributionRandom.expovariate (LAMBD) Index distributionRandom.gammavariate (alpha, beta) gamma distributionRandom.gauss (Mu, sigma) Gaussian distributionRandom.lognormvariate (Mu, sigma) Log normal distrib
Python standard library notes (4)-collections module, pythoncollections
This module provides several very useful Python container types1. Container
Name
Function Description
OrderedDict
Dict that maintains the key Insertion Sequence
Namedtuple
Generate a tuple subclass that can a
Python Study Notes 17: Mathematical Correlation of the standard library (math package, random package)
The previous sections are really tired. Now let's take a look at simple and easy-to-understand content.
A math package mainly deals with mathematical operations.
Constant math. e # natural constant e
Math. pi # pi
Calculation function math. ceil (x) # rounded
understand these distributions):Random.gauss (MU,SIGMA) # randomly generates random numbers that conform to the Gaussian distribution. The Mu,sigma is a Gaussian distribution of two parameters.Random.expovariate (LAMBD) # randomly generates random numbers that conform to the exponential distribution. LAMBD is an exponential distribution of the number of parameters.There are also logarithmic distributions, which are normally distributed. Pareto distribution. Weibull distributionIf we have a grou
Os.path.dirname (PATH)
Returns the directory of path. is actually the first element of Os.path.split (path)
Os.path.basename (PATH)
Returns the last file name of path. A / \ null value is returned if the path is or ends. The second element of Os.path.split (path)
Os.path.exists (PATH)
Returns true if path exists, false if path does not exist
Os.path.isabs (PATH)
Returns true if path is an absolute path
Os.
ObjectYou can use the Pickle.dumps () method to convert an object summer to a string picklestring (that is, a text stream).We can then store the string in the file (the input and output of the text file) using the normal text storage method.Import Pickleclass Bird (object): have_feather = True way_of_reproduction = ' egg ' summer = Bird () FileName = ' Save.pkl ' with open (FileName, ' W ') as f: # Open file with write-mode picklestring = Pickle.dump (Summer, F) # serialize and save O
conforms to the Gaussian distribution, and the Mu,sigma is two parameters of the Gaussian distribution.Random.expovariate (LAMBD) # randomly generates a random number that conforms to the exponential distribution, LAMBD is the parameter of the exponential distribution.There are also logarithmic distributions, normal distribution, Pareto distributions, Weibull distributions.Suppose we have a group of people in a dance competition, in order to be fair, we have to randomly arrange their appearance
(f) # Read file and build objectThe function and use of the Cpickle package of the two Cpickle package almost exactly the same as the pickle package, where the difference is actually very seldom used;The difference is that Cpickle is based on the C language, which is 1000 times times faster than the pickle package.For the example above, it is assumed that using the Cpickle package, we can change the import statement to:Import Cpickle as PickleThere is no need to make any changes.Python Learning
(self.to_send))return bool (self.to_send)def readable (self):Self.logger.debug (' True ')Return True# Each time the loop is processed, if writable () makes a positive response, it calls handle_write(),echoclients divides a message into parts based on a given size limit to show how a fairly large multipart message is transferred by looping through multiple iterations, each time handle_write ()is called, will write the next part of the message until the message is fully utilized.def handle_writ
/proc directory. This method does not need to start a shell, only need to read the files in the/proc directory to obtain the process information.#!/usr/bin/env pythonimport osimport sysfor dirname in Os.listdir ('/proc '): if DirName = = ' Curproc ': Continue Try:with open ('/proc/{}/cmdline '. Format (dirname), mode= ' RB ') as FD: Content = Fd.read (). Decode (). Split (' \x00 ') except exception:continue for I in Sys.argv[1:]: If I in Content[0]: print (' {0: phoemur ~/
interface to obtain the process information.#!/usr/bin/env python ImportOSImportSYS forDirNameinchOs.listdir ('/proc'): ifDirName = ='Curproc': Continue Try: With open ('/proc/{}/cmdline'. Format (dirname), mode='RB') as Fd:content= Fd.read (). Decode (). Split ('\x00') exceptException:Continue forIinchSys.argv[1:]: ifIinchContent[0]:Print('{0:'. Format (DirName,' '. Join (content))Method 4:Gets the current script's proce
= locals_dict[keywords] For K in keywords_dict: setattr (self, k, keywords_dict[k]) class Foo (object): def __init__ (self, Name, **KWARGV): attr_from_locals (Locals ()) F = Foo (' Bar ', color= ' yellow ', num=1) print f.__dict__The result is:{' Color ': ' Yellow ', ' num ': 1, ' name ': ' Bar '}The object has been initialized correctly.GetMembers (object[, predicate])Returns a list of (name, value) that contains all the members of the object. The content retu
The ==popen2 module = = ' Popen2 ' module allows you to execute external commands and access its ' stdin ' and ' stdout ' (possibly also ' stderr ') by stream. In Python 1.5.2 and previous versions, the module exists only on Unix platforms. After 2.0, the function is also implemented under Windows. [Example 3-9 #eg-3-9] shows how to use the module to sort strings. ====example 3-9. Use the Popen2 module to sort strings for module to sort strings====[eg
. It can also allow you to write comments to the RE, which are ignored by the engine; the comment is identified by the "#" sign, but the symbol cannot be followed by a string or backslash. FunctionMatch () matches from scratch, no return nullSearch () in the string to return to the firstPattern =' This'text='Does This text match this pattern?'Match=Re.match (pattern, text) search=Re.search (pattern, text) s=Search.start () e=search.end ()Print(Match)Print(Search.re.pattern)Print(search.string)Pr
' Befort: 'Print getoutput (r ' copy ')Shutil.rmtree (R ' copy ', R ' Copy/abcde ')print ' After: 'Print getoutput (r ' copy ')#默认地, errors are generated as exceptions, but if the second argument is true, you can ignore the exceptions and provide a special error-handling function in the third parameter#要把一个文件或者目录从一个位置移动到另一个位置可以使用move.With open (' aa.txt ', ' wt ') as F:F.write (' AA ')print ' Beform: ', Glob.glob (' CC ')Shutil.move (' Aa.txt ', ' Aa.bim ')print ' Atfer: ', Glob.glob (' CC ')#其
)
Open URL in a new window of the browser handled by this controller, if possible, otherwise, open URL in The only browser window. Alias open_new ().
Controller.
Open_new_tab
(
url
)
Open URL in a new page ("tab") of the browser handled by this controller, if possible, otherwise equivalent to open_new ().
Footnotes
[1]
Executables named here without a full path would
Python standard library: built-in functions int (x = 0), pythonint
This function converts a floating point or numeric string to an integer. If no parameter is input, 0 is returned by default. If the parameter is a number, call the x. _ init _ () object to return the corresponding value. If the parameter is a floating point, the fractional part is removed and an
Python standard library: built-in function exec (object [, globals [, locals]), pythonglobals
This function is used to execute a statement or function. The parameter object is the name of a string statement or compiled statement. The globals parameter is a global namespace used to specify the global namespace that can be accessed during statement execution. The
Python standard library: built-in function id (object), pythonobject
This function is the identifier of the returned object. The identifier type is an integer. In the same time, all object identifiers are unique, objects with different lifecycles may have the same identifier. For example, after object A is created, object A is deleted and object B is created. Ob
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.