It is estimated that this will happen at entry time. I used the idle editor of python25 in Windows to run the script. I found that some Chinese characters in the result of running the script are garbled, but some of them are normal. Think twice
Create a file and write content to it
Import OS # Coding = 'utf-8' # Get OS linefeed ls = OS. linesep # Get the file name while true: fname = raw_input ('input file name: ') If OS. path. exists (fname): Print "error: '% s' already exists! "% Fname
The goodreader of iPad does not support JS files very well. Although it can be read, it cannot exit and the main interface of goodreader cannot be returned. Therefore, I need to convert JS files into plain text in batches. For this purpose, I have
# Coding = 'utf-8' class user (): def _ init _ (self, name, sex): Self. name = Name self. sex = sex print 'here is the constructor 'def setname (self, name): Self. name = Name def getname (Self): return self. nameuser = user ("Python", 'male') user.
These methods are located in the random module.
Random. Random (), same as the Javascript math. Random (), returns a floating point number between [0.0, 1 ).
Random. Uniform (a, B), return the floating point between [a, B]
Print random.
Use the function to get user input
(A) Create a script and use the built-in function to obtain a string from the user input, and then display the string that the user just entered.
(B) Add a similarCodeBut this time it is a value, convert it to
Under Win32, double-click PythonProgramThe DOS window is opened, but the window is closed after execution. The output result is not displayed. To see the results, you can use the following methods:
Open the DOS window and execute the python
In python, the priority order for accessing an attribute is as follows:
Class attributes
Data Descriptor
Instance attributes
Non-data Descriptor
The complete definition of the _ getattr _ () method is as follows:
Def _
Sorted is a python built-in function that can be used to sort lists and dictionaries.
The following are two examples:
1. Sort the list
>>> Elist = [1, 5, 3, 7] >>> sorted (elist) [1, 3, 5, 7]
2. Sort dictionaries
>>> Edict = {"OK": 1, "no":
Obtain the precision of different circumference rates
Import mathfor precision in range (10): Print round (math. Pi, precision)
Int, round, math. Floor differences
The int () function removes the fractional part and returns an integer.
>>> Logfile = open ('/tmp/mylog.txt', 'A ')
>>> Print> logfile, 'fatail error: invalid arguments'
>>> Logfile. Close ()
>>>
User = raw_input ("Please input your name :")
Numbers:
Int
Long
Bool(True, false)
Float
Complex(6.23
Python get Baidu get search results
# -*-Coding: cp936 -*- Import Urllib2, urllib, sys, Io """ Use get to query on Baidu search engine. This example shows how to generate a get string and request it. """ URL = " Http://www.baidu.com "
Start servers and clients
Cd ~ /Thrift-0.8.0/Thrift-R --Gen py tutorial. Thrift # generateCodeCD py./Pythonserver. py # Start the server CD~ /Thrift-0.8.0/Py./Pythonclient. py # Start the client in another shell window
As a result, an error
In normalCodeWe often need to deal with time. In python, time processing-related modules include time, datetime, and calendar. This articleArticle, Mainly describes the time module.
Before you begin, you must first describe these points:
When printing strings in Python, you can call ljust (left-aligned), right-aligned (right-aligned), and center (center-aligned) to output neat and beautiful strings, which is very easy to use, this includes filling with the second parameter (space by
Strip in python is used to remove the first character of a string. Similarly, lstrip is used to remove the character on the left, and rstrip is used to remove the character on the right. All three functions can be passed in a parameter, specifying
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