jython学习笔记3
1.os.environ["HOME"] 为什么这句话在我的STS中打印不出东西,还报错
Method | Description |
close() | Close file |
fileno() | Returns integer file descriptor |
flush() | Used to flush or clear the output buffers and write content to the file |
isatty() | If the file is an interactive terminal, returns 1 |
next() | This allows the file to be iterated over. Returns the next line in the file. If no line is found, raises StopIteration |
read(x) | Reads x bytes |
readline(x) | Reads single line up to x characters, or entire line if x is omitted |
readlines(size) | Reads all lines in file into a list. If size > 0, reads that number of characters |
seek() | Moves cursor to a new position in the file |
tell() | Returns the current position of the cursor |
truncate(size) | Truncates file’s size. Size defaults to current position unless specified |
write(string) | Writes a string to the file object |
writelines(seq) | Writes all strings contained in a sequence with no separator |
Attribute | Description |
closed | Returns a boolean to indicate if the file is closed |
encoding | Returns a string indicating encoding on file |
mode | Returns the I/O mode for a file(i.e., ‘r’, ‘w’, ‘r+,’rb’, etc.) |
name | Returns the name of the file |
newlines | Returns the newline representation in the file. This keeps track of the types of newlines encountered while reading the file. Allows for universal newline support. |
在定义类时,Car(object),指定义的是object的一个子类。类的属性可以不用实例化而直接用。self的变量只能用在单一的object中,而类的属性则属于该类的所有实例,也就是说,改变类的可改变变量(例如LIST)会影响到该类的所有实例,改变类的某一个实例中该类的不可改变属性,例如integer,本实例中的该类属性的值改变,其他实例中该类的属性的值不变。
2.jython使用left first depth first
3.这段代码感觉看不懂
from __future__ import with_statement
from contextlib import closing
from pickle import dumps, loads
def write_object(fout, obj):
data = dumps(obj)
fout.write("%020d" % len(data))
fout.write(data)
def read_object(fin):
length = int(fin.read(20))
obj = loads(fin.read(length))
return obj
class Simple(object):
def __init__(self, value):
self.value = value
def __unicode__(self):
return "Simple[%s]" % self.value
with closing(open('simplefile','wb')) as fout:
for i in range(10):
obj = Simple(i)
write_object(fout, obj)
print "Loading objects from disk!"
print '=' * 20
with closing(open('simplefile','rb')) as fin:
for i in range(10):
print read_object(fin)
4.chapter6看得有点不太懂。先跳过,等回过头再看一遍
Table 7-1. Exceptions
Exception | Description |
BaseException | This is the root exception for all others |
GeneratorExit | Raised by close() method of generators for terminating iteration |
KeyboardInterrupt | Raised by the interrupt key |
SystemExit | Program exit |
Exception | Root for all non-exiting exceptions |
StopIteration | Raised to stop an iteration action |
StandardError | Base class for all built-in exceptions |
ArithmeticError | Base for all arithmetic exceptions |
FloatingPointError | Raised when a floating-point operation fails |
OverflowError | Arithmetic operations that are too large |
ZeroDivisionError | Division or modulo operation with zero as divisor |
AssertionError | Raised when an assert statement fails |
AttributeError | Attribute reference or assignment failure |
EnvironmentError | An error occurred outside of Python |
IOError | Error in Input/Output operation |
OSError | An error occurred in the os module |
EOFError | input() or raw_input() tried to read past the end of a file |
ImportError | Import failed to find module or name |
LookupError | Base class for IndexError and KeyError |
IndexError | A sequence index goes out of range |
KeyError | Referenced a non-existent mapping (dict) key |
MemoryError | Memory exhausted |
NameError | Failure to find a local or global name |
UnboundLocalError | Unassigned local variable is referenced |
ReferenceError | Attempt to access a garbage-collected object |
RuntimeError | Obsolete catch-all error |
NotImplementedError | Raised when a feature is not implemented |
SyntaxError | Parser encountered a syntax error |
IndentationError | Parser encountered an indentation issue |
TabError | Incorrect mixture of tabs and spaces |
SystemError | Non-fatal interpreter error |
TypeError | Inappropriate type was passed to an operator or function |
ValueError | Argument error not covered by TypeError or a more precise error |
Warning | Base for all warnings |
Table 7-2. Python Warning Categories
Warning | Description |
Warning | Root warning class |
UserWarning | A user-defined warning |
DeprecationWarning | Warns about use of a deprecated feature |
SyntaxWarning | Syntax issues |
RuntimeWarning | Runtime issues |
FutureWarning | Warns that a particular feature will be changing in a future release |
Importing the warnings module into your code gives you access to a number of built-in warning functions that can be used. If you’d like to filter a warning and change its behavior then you can do so by creating a filter. Table 7-3 lists functions that come with the warnings module.
Table 7-3. Warning Functions
Function | Description |
warn(message[, category[, stacklevel]]) | Issues a warning. Parameters include a message string, the optional category of warning, and the optional stack level that tells which stack frame the warning should originate from, usually either the calling function or the source of the function itself. |
warn_explicit(message, category, filename, lineno[, module[, registry]]) | This offers a more detailed warning message and makes category a mandatory parameter. filename, lineno, and module tell where the warning is located. registry represents all of the current warning filters that are active. |
showwarning(message, category, filename, lineno[, file]) | Gives you the ability to write the warning to a file. |
formatwarning(message, category, filename, lineno) | Creates a formatted string representing the warning. |
simplefilter(action[, category[, lineno[, append]]]) | Inserts simple entry into the ordered list of warnings filters. Regular expressions are not needed for simplefilter as the filter always matches any message in any module as long as the category and line number match. filterwarnings() described below uses a regular expression to match against warnings. |
resetwarnings() | Resets all of the warning filters. |
filterwarnings(action[, message[, category[, module[, lineno[, append]]]]]) | This adds an entry into a warning filter list. Warning filters allow you to modify the behavior of a warning. The action in the warning filter can be one from those listed in Table 7-4, message is a regular expression, category is the type of a warning to be issued, module can be a regular expression, lineno is a line number to match against all lines, append specifies whether the filter should be appended to the list of all filters. |
Table 7-4. Python Filter Actions
Filter Actions | |
‘always’ | Always print warning message |
‘default’ | Print warning once for each location where warning occurs |
‘error’ | Converts a warning into an exception |
‘ignore’ | Ignores the warning |
‘module’ | Print warning once for each module in which warning occurs |
‘once’ | Print warning only one time |
5. by using Step Into (F5) to go into the code of the next function call, Step Over (F6) to run the current line and stop again, Step Return (F7) to execute the remaining code of the current function, and Resume Execution (F8) to let the program continue running until the next breakpoint is reached (or the program finishes).
6.把jdk的lib包加入到classpath中,这样py文件就可以引用java包
jython学习笔记3的更多相关文章
- jython学习笔记2
1.%是求余,//是整除的商,**是乘方 abs(var) Absolute value pow(x, y) Can be used in place of ** operator pow(x,y,m ...
- Python学习笔记—Python基础1 介绍、发展史、安装、基本语法
第一周学习笔记: 一.Python介绍 1.Python的创始人为吉多·范罗苏姆.1989年的圣诞节期间,吉多·范罗苏姆为了在阿姆斯特丹打发时间,决心开发一个新的脚本解释程序,作为ABC语言 ...
- Python学习笔记(一)基础
学习资料 跟着廖雪峰的Python教程学习Python,大家可以去官方网站查看学习教程.使用的Python版本为3.0.x,解释器为CPython.本系列博客为学习笔记,记录跟随廖老师所学知识,同时会 ...
- 【Java】「深入理解Java虚拟机」学习笔记(1) - Java语言发展趋势
0.前言 从这篇随笔开始记录Java虚拟机的内容,以前只是对Java的应用,聚焦的是业务,了解的只是语言层面,现在想深入学习一下. 对JVM的学习肯定不是看一遍书就能掌握的,在今后的学习和实践中如果有 ...
- js学习笔记:webpack基础入门(一)
之前听说过webpack,今天想正式的接触一下,先跟着webpack的官方用户指南走: 在这里有: 如何安装webpack 如何使用webpack 如何使用loader 如何使用webpack的开发者 ...
- PHP-自定义模板-学习笔记
1. 开始 这几天,看了李炎恢老师的<PHP第二季度视频>中的“章节7:创建TPL自定义模板”,做一个学习笔记,通过绘制架构图.UML类图和思维导图,来对加深理解. 2. 整体架构图 ...
- PHP-会员登录与注册例子解析-学习笔记
1.开始 最近开始学习李炎恢老师的<PHP第二季度视频>中的“章节5:使用OOP注册会员”,做一个学习笔记,通过绘制基本页面流程和UML类图,来对加深理解. 2.基本页面流程 3.通过UM ...
- 2014年暑假c#学习笔记目录
2014年暑假c#学习笔记 一.C#编程基础 1. c#编程基础之枚举 2. c#编程基础之函数可变参数 3. c#编程基础之字符串基础 4. c#编程基础之字符串函数 5.c#编程基础之ref.ou ...
- JAVA GUI编程学习笔记目录
2014年暑假JAVA GUI编程学习笔记目录 1.JAVA之GUI编程概述 2.JAVA之GUI编程布局 3.JAVA之GUI编程Frame窗口 4.JAVA之GUI编程事件监听机制 5.JAVA之 ...
随机推荐
- 感知开源的力量-APICloud Studio开源技术分享会
2014.9.15 中国领先的“云端一体”移动应用云服务提供商APICloud正式发布2015.9.15,APICloud上线一周年,迎来第一个生日这一天,APICloud 举办APICloud St ...
- vc2010 win32 控制台应用程序中文乱码
vc2010 win32 控制台应用程序中文乱码 在 vc2010 上用 win32 控制台程序写些测试代码调用 windows api ,处理错误信息时,发现用 wprintf 输出的错误信息出现了 ...
- UCenter uc_user_synlogin同步登陆返回值为空(NULL)的解决办法 及 ucenter原理
第一种方法最近刚刚接触UCenter,很多问题不是很理解,只是在摸索着.尝试着做,就在刚才有解决了一个问题,虽然不知道解决问题的具体原理,但是还是实现了同步登陆.首先我是在本地测试的,也就是local ...
- iOS 在一个应用程序中调另一个应用程序
在A应用程序中调用B应用程序 1. 首先在B应用程序中生成URL 1)点击targets文件 2)点击Info 3)生成URL ①在Info.plist文件中点击+(新添加一项) ②在Info.pli ...
- 查看iOS视图层级并修改UIsearchBar的cancel按钮不失去作用
(lldb) po [self.searchBar recursiveDescription] <UISearchBar: ; ); text = 'p'; opaque = NO; gestu ...
- JSON 基础知识总结
JSON:JavaScript 对象表示法(JavaScript Object Notation)JSON 语法规则 数据在名称/值对中 数据由逗号分隔 花括号保存对象 方括号保存数组 JSON有6种 ...
- [转] 被遗忘的Logrotate
FROM : http://huoding.com/2013/04/21/246 我发现很多人的服务器上都运行着一些诸如每天切分Nginx日志之类的CRON脚本,大家似乎遗忘了Logrotate,争相 ...
- 误卸载python2.4导致yum不能用后的修复
去 http://mirrors.ustc.edu.cn/centos/或者镜像下载如下包,版本不一定非常一致 python-2.4.3-56.el5.x86_64.rpmpython-devel-2 ...
- 关键字 self
self 总是指向调用方法的对象. self总是代表当前类的对象.当它出现在某个方法体中时,它所代表的对象是不确定的,但它的类型是确定的,它所代表的是当前类的实例对象: 当这个方法被调用时,它所代表的 ...
- WPF 面试题及答案(二)
一 · WPF中什么是样式? 首先明白WPF中样式属于资源中重要的一种. 同时样式也是属性值的集合,能被应用到一个合适的元素中,或者说能将一组属性应用到多个元素. WPF中样式可以设置任何依赖属性. ...