1. Background notes for instances
Suppose that a personal information system requires the recording of the home, place of residence, and the city of the individual in the system. The database is designed as follows:
models.py content is as follows:
Open File
The open function returns a file object with the basic syntax:
File_object = open (file_name, access_mode= ' R ' [, Buffering=-1])File_name is a string containing the name of the file to be opened, which can be a relative path or an
Learning the essence of culture around a language can make you a better programmer. If you have not read Python Zen (Zen of Python), open the command prompt for Python and enter import this, and you can find a corresponding example here for each
1.dict () Creating a dictionary
The code is as follows:
>>> fdict = Dict ([' X ', 1], [' Y ', 2])>>> fdict{' Y ': 2, ' X ': 1}
2.fromkeys () to create a "default" dictionary in which the elements in the dictionary have the same value
The code is as
This example describes how Python uses hyperlinks in beautifulsoup pages. Share to everyone for your reference. Specific as follows:
Python through hyperlinks in beautifulsoup pages, this Python code outputs all the URL links on www.bitsCN.com
Use:
The code is as follows:
foldercleanup.py-d 10-k c:\test\keepfile.txt C:\Test
Indicates that the C:\Test directory retains only the last 10 days of subfolders and subfolders specified in Keepfile.txt.
Code:
The code is as follows:
Import
Understanding New Concepts
The idea of iterators was introduced in Python V2.2. Well, this is not quite right; the "hint" of this thought has already appeared in the older function xrange () and the file method. Xreadlines (). By introducing the
In my opinion, the Python community is divided into three genres, namely Python 2.x organization, 3.x organization and PyPy organization. This classification can basically be rooted in the compatibility and speed of class libraries. This article
The example in this article describes how Python gets all the hyperlinks on a specified Web page. Share to everyone for your reference. Specific as follows:
This Python code crawls the Web page through URLLIB2 and then parses all the URL addresses
Python's explanatory language also has a dedicated threading model, and Python virtual machines use the Gil (Global interpreter lock, globe interpreter Lock) to mutually exclusive threads access to shared resources, but are temporarily unable to
RSS is an abbreviation that can be represented by a variety of extensions: "RDF Site Summary (RDF sites Summary)", "Really Simple Syndication (really Easy Syndication)", "Enrich Site Summary (Rich sites Summary)", may also be represented by other
I want to learn the algorithm, seldom go to the real quiet heart to study, a few days before the weekend to learn the shortest path of data, with Python wrote a shortest path algorithm. The algorithm is based on weighted graph to find the shortest
In this paper, we describe the object-oriented idea of Python. Share to everyone for your reference. The specific analysis is as follows:
The basic idea of object-oriented is encapsulation, inheritance, polymorphism.
The first is
Recently, I want to add the user OS version information in my Youmoney (http://code.google.com/p/youmoney/). For example, Windows users may want to return Windows XP, or Windows 2003, Apple users should return to Mac OS X 10.5.8. There are many ways
Built-in method description
__init__ (self,...) initializes the object, which is called when a new object is created
__del__ (self) Releases the object, which is called before the object is deleted
__new__ (CLS,*ARGS,**KWD) Instance generation
1. Algorithm: (set to find the array period of array[low, high])
(1) Determine the intermediate position of the period K(2) Compare the lookup value T with Array[k]. If it is equal, the lookup returns to this location successfully; otherwise,
The English literal of the socket is "hole" or "socket". As the BSD UNIX process communication mechanism, take the latter one meaning. Often also referred to as a "socket," which describes the IP address and port, is a handle to a communication
This example describes how Python detects whether a remote UDP port is open. Share to everyone for your reference. The implementation method is as follows:
The code is as follows:
Import socketImport threadingImport timeImport structImport
I. Examples and results
1) Examples of the structure and specific files:
The code is as follows:
Pypackage│pycommonm.py│__init__.py│├─p1package│p1m.py│p1mc.py│__init__.py│└─p2p2.pyp2m.py
2) pycommonm.py
The code is as follows:
Def PYCOMMONMF ():
Using Python 2.7, beginners, the code is relatively simple.
numprinter.py
The code is as follows:
#!/usr/bin/env python#-*-Coding:utf-8-*-'''@Author: Quico Tomy@Function: Input a phone number and print by line@Demo time:2015-3-16'''Numstr =
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