been classified as a high school computer learning course, for today's college students, more free time, learning Python programming language in bridging the relevant skills, but also to master a new skill, for future work more helpful.V. Java developersCompared to Java,python in the past two years more popular, many Java developers aimed at this market, transformation to do
In the model training, especially in the training set to do cross-validation, usually want to save the model, and then put on a separate test set test, the following is the Python training model to save and reuse.Scikit-learn already has the model persisted operation, the import joblib canfromimport joblibModel Save>>>
list is the current directory, then the order of the modules is searched by the Sys.path list, and the current directory is found, and one does not continue to be searched.Tab Completion Code#!/usr/bin/env Python # python startup file import sysimport readlineimport rlcompleterimport atexitimport os# tab complet Ion Readline.parse_and_bind (' Tab:complete ') # history file Histfile = Os.path.join (os.envir
The manager asked me to convert the bin file from Word2vec training to a TXT file, and I don't know what the TXT file is for. In fact, Word2vec training corpus can choose the training department out of the bin file or txt file, but the process is too long to train the bin file, I am afraid to directly train the TXT file is also slow, so I still try to do this thi
, Output) = Commands.getstatusoutput (' Cat/proc/cpuinfo ')>>> Print Outputprocessor:0Vendor_id:authenticamdCPU family:21... ...>>> Print Status0Note 1: The return value returned by using this method under Unix-like systems (status) is not equal to the return value after execution of the script or command, because the reason for calling Os.wait () is to understand the implementation of the system wait (). You need the correct return value (status), just move the return value to the right 8-bit o
user group Name list Os.getlogin () get user login name os.getenv get environment variable OS.PUTENV SET environment variable os.umask settings umask Os.system (cmd) Use system calls to run the cmd command Built-in modules (can be used directly without import) commonly used built-in functions:Help (obj) online, obj is any typeCallable (obj) to see if an obj can be called like a functionRepr (obj) obtains a representation string of obj that can be used to reconstruct a copy of the object us
The time is divided into 4 weeks, all self-taught, only provide an outline. Applies to web orientation:1, Week1: read "Concise python tutorial", adapt to the Python development environment2, Week2: Write a crawler, need to know more about RE, urllib2, Sqlite3, Threading,queue and several other modules. Need to use on multi-threaded crawl, regular expression analysis, concurrent resource control, re-open the
effect of improving code reusability. >>> y1 = lineconfig (1, 1) # defines the line y = x + 1 >>> p1 = y1 (2) # Calculates the y-coordinate, gets x=2 when Y1 value GT;G t;> print (p1) 3 >>> lstpoint = [Y1 (x) for x in range (3)] # Calculate y-coordinate list >>> print (lstpoint) [1 , 2, 3];>> y2 = lineconfig (4, 5) # defines the line y = 4x + 5 >>> p2 = y2 (x=2) # Calculates the y-coordinate, gets x=2 when Y2 value >> > Print (p2) "Def Line (x): return a*x + B return linedef Newcounter (i=0)
dictionary three stylesList can be deleted and changed to search index slicesTuples do not support modification but can index slicesA dictionary is a key value stored only by key to find values5, the processing of documentsThe way the file is opened R means read-only w indicates write (if the original file has content will be emptied) a means append (append content after the original file)Read the fileF=open (' file.txt ', ' R ')Print F.read ()#read () indicates that a one-time read-in memory h
Re moduleRe.math Match from scratchRe.searchStructure: Re.math (R ' ^c ', a) non-conforming return noneOriginal character:. Any character[] or [a-z,a-z,b]\d Digital \d Non-digital\s Space \s non-whitespace\w Letter \w Non-letter ([a-za-z0-9])^ Beginning $ endGrouping (A|B)Number of Matches* {0,~}+{1,~}? {0,1}{M}/{m,n}Return Object properties: Group (), groups (), span (), string ()Script#!/usr/bin/python#-*-coding:utf-8-*- from __future__ Importprint_
1. The higher order function receives the function as the parameter, returns the function.2. Function closure3. Receive a function as a parameter, wrap it, and return a wrapper function#!/usr/env/python#-*-coding:utf-8-*- from __future__ Importprint_functiondefF1 (x):returnX*2defNew_fn (f):deffn (x):Print("Pager"+f.__name__+'()') returnf (x)returnFNA= NEW_FN (F1) (2)Print(a)Print("##################") b= F1 (2)Print(b) @new_fndefF1 (x):returnX*
parameter list according to function F. For example:>>> L = [1,2,3,4,5]>>> map (lambda x:x*x, L)[1,4,9,16,25]The reduce (f, list) function is similar to map, whose argument f function receives two parameters, and all elements in the returned list are the result of the cumulative calculation of all elements in the parameter list according to function f, such as additive/multiplicative:>>> L = [1,2,3,4,5]>>> reduce (lambda x,y:x+y, l)15>>> reduce ( Lambda x,y:x*y, l)120Then using these two functi
Python 1 day training 102 ---- create a simple blog (below), python102 ----
Continue to change the blog and continue to change the blog in the previous article.
My mother tongue is not swollen in English. I have a lot of English on my blog!
The change is simple.
You can make a quick change to see if the Django management tool is translated into the language you want. Only in settings. add 'django. middle
Python one-day training 104 ---- Django URLconf exercise, pythondjangoWhen the url is http: // 127.0.0.1: 8000/sum/n/(n is a number), the returned page displays the sum of 1-n.Source code views. py file
# Coding: utf-8from django. shortcuts import renderfrom django. http import HttpResponse, Http404 # Create your views here. def num_plus (request, plus): try: plus = int (plus) handle T ValueError: raise Ht
Python one-day training 05 ---- furious clicks, python05 ----
Function
Automatically obtain the CSDN article list and add clicks for each article.
Source code
Import urllib. requestimport reimport timeimport randomfrom bs4 import BeautifulSoupp = re. compile ('/a359680405/article/details /........ ') # Your own blog homepage url = "http://blog.csdn.net/a359680405" # using build_opener () is to let the
Python one-day training 103 ---- Django template exercises, pythondjango
Requirements
Request. META is a Python dictionary that contains all the Header information of this HTTP request, such as the user IP address and user Agent. You can obtain this dictionary through request. META. items. You must output the META information to the webpage.
Output result
Sour
entire page and organizephotos = beautifulsoup (HTML). Find_all (class_= "Imgwrapper") #用BeautifulSoup解析html, then use the function of BS, Find all items of class imgwrapper exist in a listFor photo in photos:img_url = photo.img["src"] #这里是获得上面每一条里面的img (with this method) the string stored in "src" (that is, the real address of the picture)# Print photo, Img_urlimg_filename = "img/" + img_url.split ("/") [-1] #使用切片工具切出每一个文件名img = requests.get (img_url, stream=true) #保存了if Requests.get (img_url)
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.