Exercise one: Hit all the even numbers between 1-100Def even_print (): For I in range (1,101): If I% 2 = = 0: print (i) even_print ()Exercise two: Design a function, create 10 files on the desktop, and name them as numbersDef text_creation (): path = ' c:/users/administrator/desktop ' for name in range (1,11): With open (path + str ( Name) + ' txt ', ' W ') as text: text.write (str (name)) text.c
Admin Background Management FrameworkEmulate the admin component and develop the stark component1. startup fileExecute the stark.py file under each appRewrite a def ready () function Autodiscover_modules automatically scans all apps under settings for Stark filesdef Ready ():# automatically scan all apps under settings for Stark files Autodiscover_modules ('Stark', Register_to=site)2. Source code1. Registration function #Write a registration function classclassStarkmodel (object):#Container
In web development, the back-end code is actually quite easy to write.
For example, we write a rest API for creating a blog:
@api @post ('/api/blogs ') def api_create_blog (): i = ctx.request.input (name= ", summary=", content= ") name = I.name.strip () summary = I.summary.strip () content = I.content.strip () If not name: raise Apivalueerror (' name ', ' name cannot be empty. ') If not summary: raise Apivalueerror (' summary ', ' summary cannot is empty. ') If not content: rai
Create process and pythoncreate process for python System ProgrammingI. forking process
The process generated by fork has the following features:
Is a process clone.
The created process exists independently of the parent process.
The thread is copied and executed when fork () is called.
Returns 0 in the Child thread.
Returns the pid of the subthread in the parent thread.
The PID of the sub-t
SublimeText is a very powerful Text editor. The following describes how to create SublimeText3 as a PythonDjango development tool: 1. install Sublime Text 3.
Although Sublime 3 is still in beta stage, it is very stable and the speed is improved compared with Sublime 2. sublime 3 can be downloaded and installed on the official website. although Sublime is free software, if you have sufficient financial capabilities, you can consider purchasing it to s
This article will share with you the Python code used to create a crawler to collect novels. it is very simple and practical. although it is still a bit flawed, you can change it together and make common progress in the development tool python3.4.
Operating system: win8
Main function: specify the novel web page to crawl the novel Directory, save it to the local location by chapter, and save the crawled web
I wrote the test code for the fork process under Python (to illustrate this problem is not necessarily appropriate ):
Def fork (a): def now (): import datetime return datetime. datetime. now (). strftime ("% S. % f ") import OS import time print now (), a if OS. fork () = 0: print 'sub-process [% s]: % s' % (now (), OS. getpid () while 1: a-= 10 print 'sub-process a value [% s]: % s' % (now (), a) if a
TIPS:
OS. fork () has two returned values: the r
* #consistent with parentnode.append (Element) Effect $NewNode = elementtree.subelement (node,'Activetype')Panax Notoginseng #Setting Properties -newnode.attrib['ID'] ='9' thenewnode.attrib[' Level'] =' -' +newnode.attrib['begin'] ='201401010000' Anewnode.attrib['End'] ='201401010000' the #Chinese need special decoding +newnode.attrib['Tip'] ='Test'. Decode ('Utf-8') - #symbol at the end of a node $Newnode.tail ='\ n' $ #node.append (N
Import NumPy as NPNp.arange (Dtype = float) #numpy中的arange与普通的range作用一样, range (start, stop, step)#arange可以通过dtype来指定创建的数组类型, arrays differ from tuples and lists, and the entire array must be of the same type.Np.linspace (Start, stop, number) #其中number指定了start到stop之间的个数 (contains both end point values)Of course, you can also generate random numbers to initialize an array.Np.random.rand (2, 4) #产生一个2行4列的array, Rand uses a uniform distribution between 0 and 1.NP.RANDOM.RANDN (2, 4) #产生一个2行4列的array
Create a crawler collection novel using Python,
Development Tool: python3.4Operating System: win8Main function: Specify the novel web page to crawl the novel directory, save it to the local location by chapter, and save the crawled web page to the local configuration file.Crawled Website: http://www.cishuge.com/Novel name: Liling night travelCode Source: Self-signed
Import urllib. requestimport http. cookie
#!/usr/bin/env pythonImport OS#导入功能模块url = "/tmp/"#变量定义def check ():#函数定义 whileTrue:#一直循环 prompt the user to enter the correct file name to createOs.system ("cd/tmp")d_com=raw_input ("please input filename")#将用户输入的值赋给变量做判断if os.path.exists (url+d_com) = = True:#调用功能模块判断文件是否存在print "error!! File had existed "#输出判断结果Continue#存在时重新输入文件名Else:While True:#当要创建的文件不存在M = open (url+d_com, ' a ')# Prompt the user to enter content into the created fileA = raw_input ("Piease input what ' s want Add") m.writ
In order to facilitate later work, today in ADT installed Pydev (http://pydev.org/updates), but after the installation, the new project was not found in pydev,perference.Immediately after trying to install a slightly lower version still does not work, meditation began to think about what was done to make Pydev unavailable.Finally I found out that the original requirements for the project, the JDK must be under the 1.7 version.Think of this reason speed installation JDK1.7, of course, environment
I have just learned to use Photoshop to make Python word effect, feel good, close-up down to share with you. Let's look at the effect chart first.
1, create a new file, set as shown.
2, we select the Text tool in the toolbar, and its font set to stencil std, font size is 110, color is black, and then enter text. Get the font as shown.
3, the deletion of the text, and c
ABC modules /ABC moduleIn defining an abstract method, Python provides an ABC module to detect whether an abstract method was redefined during the initialization phase.1 fromAbcImportAbcmeta, Abstractmethod2 3 #Generate a abstract base obj-myabc4 classMYABC (metaclass=Abcmeta):5 #__metaclass__ = Abcmeta6 @abstractmethod7 defRun (self):8 Pass9 Ten classFoo (MYABC): One defRun (self): A Print('Run') - -f =Foo () theF.run ()
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.