Operations on files and folders in Python involve the OS module and shutil module.
Create a file:1) OS. mknod ("test.txt") to create an empty file2) Open ("test.txt", W) open a file directly. If the file does not exist, create a file.
Create
You can see this writing: #-*-coding: UTF-8-*-this is used to illustrate your Python source
ProgramThe encoding used for the file. By default, your program needs to be written in ASCII code, but if you write Chinese in it, the python interpreter
Problem:There are two special situations in the Function Definition of Python: The *, * form.For example, Def myfun1 (username, * keys) Or Def myfun2 (username, ** keys.
Explanation:* This parameter is used to pass any parameter without a name.
Python was a fan of me about three months ago. However, three months ago, my manager gave me a task to delete (replace) All comments containing specific lines in the source code files of all projects. The source code of the entire project is 1 GB.
Before February, the iPhone official website provided insufficient supply, so I wrote a reminder script to regularly refresh the page. If the conditions are met, I sent an email reminder,
The first time I did something with python, I was deeply
Document directory
4.7.1 Default Value
4.7.2 keyword Parameters
4.7.3 arbitrary parameter list
4.7.4 extract the parameter list
4.7.5 Lambda format
4.1 If statement
Perhaps the most familiar statement type is the if statement. For
Document directory
5.1.1 list used as stack
5.1.2 The list is used as a queue
5.1.3 list Comprehension
5.1.4 nested list
This chapter will describe in more detail what you have learned and add new content.5.1 more information
There are more
Document directory
9.2.1 example of scope and namespace
9.3.1 class definition syntax
9.3.2 Class Object
9.3.3 Instance Object
9.3.4 method object
9.5.1 multi-Inheritance
Compared with other programming languages, the class mechanism of
In the past two days, I learned how to use an API of Microsoft. I wrote the interface code in Python and used the HTTP method for testing. The last response of the HTTP API is an XML file, seeing that the APIs of the XML elementtree interface in
Module
I. Introduction
The module is basically a file that contains all the functions and variables you define. To reuse a module in other programs, the module File name must be.pyIs the extension.
For example:
#! /Usr/bin/python # filename:
Object-oriented nature of Python
Class and object are two main aspects of object-oriented programming. Class to create a new type, and the object classInstance. This is similarintType variable, which stores the integer variable isintClass instance
Exceptions in Python
An exception occurs when some exceptions occur in your program.
I. Handling exceptions
We can usetry..exceptStatement to handle exceptions. We place the common statements in the try-block and the error handling statement in
Basic operation expression of Python
(1) Judgment statement
I will not introduce the rules of if statements. I will only introduce the usage and features of IF Statements in Python.
#! /Usr/bin/python # filename: If. PY Number = 23 guess = int
A.Dict. fromkeys (s)
S is a list or tuples...
Use the element in s as the dictionary key. The default value is none. You can also specify an initial value. The code example is as follows:
myDict = dict.fromkeys('hello', True)for k in myDict.keys():
1.2 interactive Interpreter
1.4 numbers and expressions
Integer, floating point, long integer
Division, hexadecimal, octal, etc.
The literal values of Python include: integer, long integer, floating point, compound (plural), string, and Unicode.
1. Use * in Python to represent variable parameters, similar to the C language... however, one or more parameters must be included before variable parameters in C language.
Def funcd (a, B, * C): print a print B print "length of C is: % d" % Len (c)
I found that python has an easy-to-use check module-inspect. Looking at the source file, I found that it provides a lot of useful methods:""Here are some of the useful functions provided by this module:
Ismodule (), isclass (), ismethod (),
I checked a lot on the Internet and used struct for packaging and package settlement. please google the content, but it is not the result I want, I just want to directly convert a string into byte []. I don't need to define every location so
Baseexception all Exception base classes + -- systemexit Python interpreter request exit + -- keyboardinterrupt User Interrupt execution (usually press Ctrl + C) + -- generatorexit generator (generator) when an exception occurs, the exit is notified.
The problem of Chinese encoding is that Chinese programmers often have a big problem. This is also true in Python. How can we understand and solve the problem of Python encoding?
We need to know that python uses unicode encoding internally, while
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