Python_files_operationsFiles, file objectsOpen (name [, mode [, BufSize]]) Eg:file = "Data.txt" f = open (file, ' r ') F = open (file, ' W ')
' R ': Read
' W ': Write
' A ': Append
' RB ': Write binary, where files in Unix can
In this chapter, I just add my own comments to all the output.#!/usr/bin/env python#-*-coding:utf-8-*-defcheese_and_crakers (Cheese_count, boxes_of_crackers):" "The function that defines the cheese_and_crakers reads out two variables and outputs
From http://www.iplaypython.com/module/gzip.htmlI. Compressing files using the Gzip module>>> Import gzip #导入gzip模块, play Snake tips: Note the name is all lowercase>>> g = gzip. Gzipfile (filename= "", mode= "WB", Compresslevel=9, Fileobj=open ('
After reading chapter 18, I found that the first exercise, using *args to read all of the input parameters as a tuple, but in his practice only gave two variables to assign value, when the user is not clear about the definition of this function, it
Before:Contact Python time: 2014-09-27Main Learning Reference: "Basic python Tutorial", Web video tutorialLearning Achievement: Learn the basics of Python, understand the concept of Python programming, but lack a holistic understanding of Python's
At present, Python development is not the same as Java, mainly Python work is still more in-depth system layer and framework layer to do design development, such as Django,sqlalchemy,fail2ban,mail mail system, twisted and so on. This part of the
This code is to learn the basic syntax of Python, refer to an online video write code, the function is to intercept search engine 360 keywords.Code:1 #!/usr/bin/python2 #Encoding:utf-83 4 ImportUrllib5 ImportUrllib26 ImportRe7 Import Time8
New version of Python installation directory/usr/local/python3#./configure--prefix=/usr/local/python3# Make && make install# Mv/usr/bin/python/usr/bin/python_old #把旧版本的python移至python_old下# ln-s/usr/local/python3/bin/python/usr/bin/python #创建新版本链接#
Capitalize ()
Change the first character of a string to uppercase
Casefold ()
Change all characters of the entire string to lowercase
Center (width)
Centers the string and fills the new string with a space
Time module is primarily processed in Python1.time.localtime ()TM YearTM Mon Month 1-12TM Mday Date 1-31TM Hour Hours 0-23TM min Min 0-61TM sec Sec. 0-61TM Wday 0-6 weeksTM yday number of days in the year 1-366TM Isdst is daylight saving time,
Split function: Splitting a string into a sequenceStr.split ("delimiter")It is generally possible to use list = [n for n in Str.split] so that a new sequence can be obtainedStrip function: Remove the space characters on both sides, if the strip with
To create a dictionary type:Zidian = {} or Zidian = Dict ()[]: Use the index inside square bracketsLen (Zidian): Number of test key-value pairsIn: Whether the key is in the dictionary, returns a Boolean valueDictionary method:Items (): A list of
the data format used by the Pickle module is Python-specific and is not backwards compatible with different versions and cannot be recognized by other languages. To interact with other languages, you can use the built-in JSON package using the
In Python 3 Unicode strings is the ' regular Strings ' (str) and byte strings are separate objects.The low-level I/O can be do only with data (byte strings) and not text (sequence of characters). For Python 2.x str is also the ' binary data ' type.
# Surprisingly there is only three numbers so can be written as the sum of fourth powers of their digits:# 1634 = 14 + 64 + 34 + 44# 8208 = 84 + 24 + 04 + 84# 9474 = 94 + 44 + 74 + 44# as 1 = not a sum it's not included.# The sum of these numbers is
Sqlite3
Create a Connection object to represent a db with the following code: Import= sqlite3.connect ('example.db')# If you want to create a DB in RAM, You can use a specific name: Memory: when there are multiple connection accessing the DB
Django admin site (2) ModelAdmin methods, djangomodeladminModelAdmin methods
Save_model (request, obj, form, change)
This method is used when the admin interface saves the model instance. Request is an HttpRequest instance, obj is a model instance,
Django admin site (iii) InlineModelAdmin, djangoadminInlineModelAdmin
Class InlineModelAdminClass TabularInlineClass StackedInline
For example, there are two models:
from django.db import modelsclass Author(models.Model): name =
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