Профиль пользователя 晓天心田上,梦园中ФотографииБлогСписки Сервис Справка

晓天 林

Профессия
Интересы
吃得苦中苦,方为人上人
В этой сфере списки музыки отсутствуют.

心田上,梦园中

USA  
Фотография 1 из 60
июля 17

新加坡之行印象

1) 香港机场的巧克力是白菜价,Cadbury很大很大的一板只要12港元。
2) 新加坡环境真的不错,绿化很好!
3) 新加坡有数不清的印度人,潮水一般。不过严格的讲可能里边有不少都是新加坡籍的,我们有次打车一个印度人模样的出租车司机说他爷爷的爷爷就来新加坡了。。
4) 新加坡地铁站的扶梯速度要比国内快好多,足见他们的生活节奏也挺快。而且换乘很方便,
5) 到处都是罚款的警告,什么在地铁上吃东西罚款500新元,乱贴广告罚款1000新元...印象最深的是公交车上贴个大牌子,禁止带榴莲上公交,违者罚款1000新元 -_-
6) 到的时候王斌夫妇去接的我们,晚上去IMM吃斯里兰卡大闸蟹,席间互换八挂消息,感觉超级好~~他们两口子小日子过的也很甜蜜,很滋润的 ^_^
7) 遗憾的是姚岱小朋友回国了,没有见到白雪公主和七个小矮人的现实翻版,那可是一个帅哥和七个空姐!Secret telling
8) 三天内在大街上一个交警都没有看到.....
9) 新加坡的汽油卖的比美国都贵,一升要10+人民币,养个车简直烧钱......
10) 传说新加坡小强比较多,这次去看真没看到,倒是在我们住的condo看到只壁虎,忽然想起原来在mysore的时候宿舍门口整天有青蛙蹦来蹦去。唉,相比之下中国生态环境真的有点%^&*
11)房子真***贵,他们房价和平均工资的比例似乎比上海高好多,看来上海房价还有很大的上升空间!
12)夜间打了个车被加收了50%的服务费 Broken heart
13)CATHAY航班上的冰淇淋是哈根达斯的!!
июня 23

Python study notes 6

1 Regular Expressions
a) Regular expressions are a powerful and standardized way of searching, replacing, and parsing text with complex patterns of characters.
b) In python, all functionality related to regular expressions is contained in the re module.
c) The $ means "end of string", the caret ^ means "beginning of the string"
d) \b means "a word boundary must occur right here", in python, the '\' character in a string must itself be escaped.
e) To work around the backslash plague, you can use what is called a raw string, by prefixing the string with the letter r. This tells Python that nothing in this string should be escaped.
f) M? optionally match a single M character.
g) Pattern in parenthese defines a set of exclusive patterns, separated by vertical bars. (CM|CD|D?C?) etc.
 
2 Using the {n,m} Syntax
a) ^M{0,3} means match the start of the string, then anywhere from zero to three M characters, M{3} means exactly three times.
b) There's no way to programmatically determine that two regular expressions are equivalent.
 
3 Verbose Regular Expressions
a) a Verbose Regular Expression is different from a compact regular expression in two ways: Whitespace is ignored. Comments are ignored.
b) A comment in a verbose regular expression starts with a # character and goes until the end of the line
c) When using verbose regular expression, you need to pass an extra argument when working with them: re.VERBOSE.
d) \d means any numeric digit(0 through 9)
e) putting pattern in parenthese means remember them as a group that I can ask for later.
f) to access the groups that the regular expression parser remembered along the way, use groups() method on the object that the search function returns. It will return a tuple of however many gourps were defined in the regular expression.
g) \D means any character except a numeric digit, and + means 1 or more
h) * means zore or more characters.
июня 20

Python study notes 5

1 Handling exceptions
a) Python uses try...except to handle exceptions and raise to generate them.
b) A try...except block can have an else clause, like an if statement. If no exception is raised during the try block, the else clause is executed afterwards.
 
2 Working with File Objects
a) Python has a built-in function, open, for opening a file on disk. open returns a file object, which has methods and attributes for getting information about and manipulating the opened file.
b) The open method can take up to three parameters: a filename, a mode, and a buffering parameter. Only the first one, the filename, is required.
c) The mode attribute of a file object tells you in which mode the file was opened.
d) The name attribute of a file object tells you the name of the file that the file object has open.
e) The tell method of a file object tells you your current position in the open file.
f) The seek method of a file object moves to another position in the open file. The second parameter specifies what the first one means.
g) The read method reads a specified number of bytes from the open file and returns a string with the data that was read. The optional parameter specifies the maximum number of bytes to read.
h) The closed attribute of a file object indicates whether the object has a file open or not. To close a file, call the close method of the file object.
i) try...finally block: code in the finally block will always be executed, even if something in the try block raises an exception.
j) There are two modes for writing to files: "Append" mode will add data to the end of the file, "Write" mode will overwrite the file. "Append" works even if the file didn't exist, it will create the file if necessary.
 
3 Iterating with for loops
a) syntax of iterating a list: for s in li:  syntax of doing a normal counter: for i in range(n):
b) range produces a list of intergers
c) os.environ is a dictionary of the enviroment variables defined on your system.
 
4 Using sys.modules
a) you can always get a reference to a module through the global dictionary sys.modules
b) The sys module contains system-level information, such as the version of Python you're running, and system-level options
c) sys.modules is a dictionary containing all the modules that have ever been imported since Python was started. The key is the module name, the value is the module object
d) Given the name(as a string) of any previously-imported module, you can get a reference to the module itself through the sys.modules dictionary
e) Every Python class has a built-in class attribute __module__, which is the name of the module in which the class is defined.
 
5 Working with Directories
a) os.path is a reference to a module -- which module depends on your platform
b) expanduser will expand a pathname that uses ~ to represent the current user's home directory
c) The split function splits a full pathname and returns a tuple containing the path and filename
d) splitext splits a filename and returns a tuple containing the filename and the file extension
e) The listdir function takes a pathname and returns a list of the contents of the directory
f) os.path.isfile takes a pathname and returns 1 if the path represents a file, and 0 otherwise.
g) use os.path.join can ensure a full pathname
h) isdir function returns 1 if the path represents a directory, and 0 otherwise.
i) whenever possible, you should use the functions in os and os.path for file, directory, and path manipulations. These modules are wrappers for platform-specific modules
j) The glob module takes a wildcard and returns the full path of all files and directories matching the wildcard.
k) nested functions can be called only from the function in which it is defined.
 
июня 19

看了5章dive into python最深刻的感想

Python is a damn well flexible, simple and efficient language!
 
据说youtube是用python写的,有没有人能证实一下Sarcastic

Python study notes 4

1 Importing modules using from module import
a) syntax: from object import object, the attribute and methods of the imported module types are imported directly into the local namespace.
b) from module import * in Python like import module.* in java
c) If you access attributes and methods from a module very often, or if you want to selectively import some attributes or methods but not others, use from module import
 
2 Defining classes
a) Python is fully object-oriented: you can define your own classes, inherit from your own or built-in classes, and instantiate the classes you've defined.
b) syntax: class Name:
c) pass is a Python reserved word that just means "moving along, nothing to see here". The pass statement in Python is like an empty set of braces({}) in Java or C
d) In python, the ancestor of a class is simply listed in parenthese immediately after the class name. syntax: class FileInfo(UserDict):
e) Python supports multiple inheritance. In the parentheses following the class name, you can list as many ancestor classes as you like, separated by commas.
f) __init__ is called immediately after an instance of the class is created. It would be tempting but incorrect to call this the constructor of the class.
g) The first argument of every class method, including __init__, is always a reference to the current instance of the class. By convention, this argument is always named self. In the __init__ method, self refers to the newly created object; in other class methods, it refers to the instance whose method was called. You do not specfic this argument when calling the methodl; Python will add it for you automatically.
h) you must explicitly call ancestor's __init__ method if needed.
i) __init__ method never returns a value.
j) __init__ method are optional, but when you define one, you must remember to explicitly call the ancestor's __init__ mehtod(if it defines one)
 
3 Instantiating classes
a) Instantiating classes in Python is straightforward. To instantiate a class, simply call the class as if it were a function, passing the arguments that the __init__ method defines. The returned value will be the newly created object.
b) In general, there's no need to explicitly free instances, because they are freed automatically when the variables assigned to them go out of scope.
c) Python keeps a list of references to every instance created.
d) Python supports data attributes. Data attributes are pieces of data held by a specific instance of a class
e) Python has no form of function overloading
f) Python supports data attributes, they are pieces of data help by a specific instance of a class
 
4 Special class methods
a) __setitem__, __getitem__ Called to implement assignment to self[key]. Same note as for __getitem__
b) When accessing data attributes within a class, you need to qualify the attribute name: self.attribute.
c) When calling other methods within a class, you need to qualify the method name: self.method
d) When a subclass has no __init__ method of its own, Python walks up the ancestor and finds the __init__ method
e) __repr__ is a special method that is called when you call repr(instance). The repr function is a built-in function that returns a string representation of an object.
f) __cmp__ is called when you compare object, Python will call your __cmp__ when you use == to compare objects
g) __len__ is called when you call len(instance). The len function is a built-in function that returns the length of an object
h) __delitem__ is called when you call del instance[key]
i) To compare the physical memory location, use object1 is object2, to compare value, use ==
j) The __call__ method lets a class act like a function, allowing you to call a class instance directly.
 
5 Class attributes
a) class attributes are available both through direct reference to the class and through any instance of the class
b) In python, only class attributes can be defined immediately after the class definition, data attributes are defined in the __init__ method
c) There are no constants in Python, everything can be changed if you try hard enough
 
6 Private functions
a) If the name of a Python function, class method, or attribute starts with (but doesn't end with) two underscores, it's private. Everything else is public
b) Python has no concept of protected class methods.
c) In Python, all special methods (like __setitem__) and built-in attribute (like __doc__) follow a standard naming convention: they both start with and end with two underscores.
 
июня 18

Python study notes 3

1 Using optional and named arguments
a) Python allow function arguments to have default values, if the function is called without the arguemnt, the argument gets its default value
b) Pattern: def info(object, spacing=10, collapse=1):,  object is required, spaceing and collapse are optional
c) In Python, arguments can be specified by name, in any order
 
2 Using type, str, dir and other built-in fuctions
a) The type function returns the datatype of any arbitrary object.
b) type takes anything: integers, strings, modules, functions....
c) The str function coerces data into a string. Every datatype can be coerced into a string
d) dir returns a list of the attributes and methods of any object: modules, functions, strings, lists, dictionaries...
e) the callable function takes any object and returns True if the object can be called, or False otherwise. Callable objects include functions, class methods, even classes.
f) type, str, dir and all the rest of Python's built-in functions are grouped into a special module called __builtin__, python will automatically import it.
 
3 Getting object references with getattr
a) you can get a reference to a function without knowing its name until run-time, by using the getattr function
b) Pattern: getattr(object,"name")
c) getattr isn't just for built-in datatypes. It also works on modules.
d) A common usage pattern of getattr is as a dispatcher
e) getattr has a third argument, it is a default value that is returned if the attribute or method specified by the second argument wasn't found
 
4 Filtering Lists
a) Mapping lists is combined with a filtering mechanism, where some elements in the list are mapped while others are skipped entirely
b) pattern: [mapping-expression for element in source-list if filter-expression]
c) count is a list method that returns the number of times a value occurs in a list
 
5 The peculiar nature of and and or
a) and and or perform boolean logic as you would expect, but they do not return boolean values; instead, they return one of the actual values they are comparing.
b) When using and, values are evaluated in a boolean context from left to right. 0, ' ', [], {}, and None are false in a boolean context, everything else is true
c) If all values are true in a boolean context, and returns the last value
d) If any value is false in a boolean context, and returns the first false value
e) If any value is true, or returns that value immediately.
f) If all values are false, or returns the last value.
g) or evaluates values only until it finds one that is true in a boolean context, and then it ignores the rest.
 
6 Using lambda function
a) Python supports defining one-line mini functions on the fly.
b) Pattern: lambda x: x*2 no parentheses around the parameter and no return keyword
c) split without any arguments split on whitespace.
d) ljust(n) pads the string with spaces to the given length. If the given length is smaller than the length of string, ljust will simply return the string unchanged.