/', ' Aj.avi ')#get file name extensionOs.path.splitext ('/users/edc/pictures/aj.avi')#('/users/edc/pictures/aj ', '. avi ')#file RenameOs.rename ('xxx.xx','BBB')#Deleting FilesOs.remove ('XXX')#you can use Shutil to help us with our files.#List all directories in the current directory[x forXinchOs.listdir ('.')ifOs.path.isDir (x)]#list. py Files[x forXinchOs.listdir ('.')ifOs.path.isDir (x) andOs.path.splitext (x) [1] = ='. PY']#serialization from memory to hard disk or transfer process for ser
1 #meta-ancestor elements cannot be modified, cannot be added and deleted2 #Ganso is also orderly.3Tu = (12,'SF', 27,67,34,7,9,4,3,5,7)4 Print(TU)5 #Ganso can be converted to str,list with each other6 #Ganso can be sliced to iterate over an object7 #the first-level element of Ganso cannot be modified, but it is only a level element8T = ('a','b', ['A','B'])9T[2][0] ='X'TenT[2][1] ='Y' One Print(t) NO 3, Life
. readlines () 3 ccc = [] 4 for I in aa: 5 if I = 'ccc \ N': 6 continue 7 else: 8 ccc. append (I) 9 foo. close () 10 11 foe = open ('text', 'W + ') 12 for iss in ccc: 13 foe. write (iss) 14 foo. close ()Delete(6) attributes of the file objectThe following lists all attributes related to the file object:Example:Fo = open ("foo.txt", "r +") print "file name:", fo. nameprint "Disabled:", fo. closedprint "Acces
Smooth python and cookbook learning notes (5), pythoncookbook1. Random selection
Use the random module to generate random numbers in python.
1. Randomly select elements from the sequence and use random. choice ()
>>> import random>>> values = [1, 2, 3, 4, 5, 6]>>> random.cho
There are two main ways in which Python operates MySQL:Native module: pymsql where Pymsql is the module that operates MySQL in Python, using the same method as MySQLdb.ORM Framework: Sqlachemy
Mysql pymysql Basic Steps
1. PYMYSQL basic structure syntax is as follows:Import pymysql# Create Connection conn = Pymysql.connect (host= ' 10.10.28.5 ', port=3306,user= ' Chen ', passwd= ' Chen1203 ... '
key parameter-we use the name (the keyword) instead of the location to assign the argument to the function.There are two advantages:One, since we don't have to worry about the order of the parameters, it's easier to use the function.Second, assuming that the other parameters have default values, we can only assign values to the parameters we want.# -*-coding:utf-8-*- # def func (A, b=5, c=10): print'ais' and bis"andCis", Cfunc (
;
In the above Code, the as keyword is used to explicitly specify the object type. This is also a difference between boo and Python-you can specify the object type to enhance security. In addition, there are 1.1 rules. Don't forget: Boo is not a real dynamic language, so the object type is fixed in its lifecycle.
4. Check the runtime type of the object (runtime type of an object)Unlike python, because Boo
Python third-party library OPENPYXL (5)Bubble chartA bubble chart is similar to a scatter plot, but a third dimension is used to determine the size of the bubble, and the chart can include multiple items fromOpenpyxlImportWorkbook fromOpenpyxl.chartImportSeries, Reference, BUBBLECHARTWB=Workbook () WS=wb.activerows= [ (" Number of products","Sales in USD","Market Share"), (14, 12200, 15), (20, 6000
it all.Well, the question of quotation marks is here first.
4. Sequence characteristics of stringsAll say that the string is also a sequence, then you can use a sequence of methods to deal with it.All sequence types can perform certain operations. These actions include: index (Indexing), Shard (sliceing), add (adding), multiply (multiplying), and check whether an element belongs to a member of a sequence (membership). In addition, Python has bu
compared to an integer and must first be str converted to an integer. Python provides a int() function to do this thing:s = input(‘birth: ‘)birth = int(s)if birth 2000: print(‘00前‘)else: print(‘00后‘)Run again to get the right results. But what if I enter abc it? And you get an error message:call last): File "1, in module>ValueError: invalid literal for int() with base 10: ‘abc‘The original int() function found a string is not a valid number whe
The path to Python's growth first (1) __ String The first step of Python's Growing Up (2)-a list and a tuplePython's Path to Growth first (3) _ DictionaryPython's Path to Growth first (4) _if,for,while conditional statement Python growth path The first (5) file basic Operation Python growing up the second (1) _ Data ty
GeneratorIn Python, a mechanism that loops one side of the computation, called the generator: Generator.Such as:1 for Xin range2 >>> gobject0x1022ef630>Here g is a generator.IteratorsWe already know that for there are several types of data that can be directly acting on a loop:A class is a collection of data types, such as,,, list tuple , and dict set str so on;One is generator to include the generator and yield the generator function with the band.T
nothing else but records the type of the class and the specific object.The multi-inheritance class of 3.Python ensures that functions of each parent class are called one at a time by means of MRO, and that each parent class function is called only once (if each class uses Super).An example of a use of the Super function:Inherit the Dict class and make an ordered dictionary type based on the Dict class.Clas
is finished, the call will throw stopiteration error. Alternatively, you can iterate over the output with for...in.The second is to replace the return of the created function with yield.def fib (max): = 0, 0, 1 while n Max: yield b = b, A + b = n + 1Generator executes at the time of each invocation next() , encounters a yield statement return, and resumes execution from the last yield statement returned.>>>defOdd (): ...Print 'Step 1'... yield1... Print 'S
causes another exception), the entire try statement will be executed after the control is complete.* If the exception occurs in the try code block and there is no matching limit t clause, the exception will be passed up to the program before entering try, or to the top layer of the process (use python to terminate the program and print the default error message)* If no exception occurs in the statements executed under the first line of try,
Python commands. Start the interpreter and wait for the main prompt >>>. (It doesn't take long.) ) 3.1.1. Digital
An interpreter can be used as a simple calculator: You can enter an expression into it and it will return its result. The expression syntax is very simple: the operator +,-, * and/is used in the same way as other languages (for example, Pascal or C); Parentheses (()) can be used for grouping. For example: >>>
>>> 2 + 2
4
>>> 50-
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.