直苦于python蹩脚的IDE,最近寻觅到一个非常优秀的python交互式解释器ipython, 再此总结下实际中常用到的方法:
特别说明下:本人为windows环境,所有命令都是相对windows的
自动补全
使用tab可以直接对已打出的对象或变量进行补全
魔术关键字
魔术关键字以%开头,如果automagic打开了,则不用输入%,否则需要,使用automagic可以切换状态
可以使用%magic参看所有魔术方法
env 显示环境变量
ed或edit 编辑一个文件并执行
ed -x filename 编辑文件不执行
edit 3:10 编辑3:10行的指令并执行
hist 显示历史纪录,可以用-n增加行号
hist 3:10 显示3-10行的历史纪录
bg function 把function函数放到后台执行
pwd 当前目录
pycat filename 语法高亮显示一个文件
macro name 1:10 把1:10行的代码设为name宏
save filename 1:10 把1:10行代码保存到文件中
time statement 计算一段代码执行时间
timeit statement 自动选择重复和循环次数计算一段代码执行时间
run filename 执行一个文件,如果希望防止执行的,需要增加if name==“main“:
autoindent 如果启用,粘贴的时候会自动缩进代码
reset 重置所有变量
Bash命令
cls 清除屏幕
colors
IPython -- An enhanced Interactive Python - Quick Reference Card================================================================obj?, obj?? : Get help, or more help for object (also works as ?obj, ??obj).
?foo.*abc* : List names in 'foo' containing 'abc' in them.
%magic : Information about IPython's 'magic' % functions.
Magic functions are prefixed by % or %%, and typically take their arguments
without parentheses, quotes or even commas for convenience. Line magics take a
single % and cell magics are prefixed with two %%.
Example magic function calls:
%alias d ls -F : 'd' is now an alias for 'ls -F'
alias d ls -F : Works if 'alias' not a python name
alist=%alias : Get list of aliases to 'alist'
cd /usr/share : Obvious. cd -<tab> to choose from visited dirs.
%cd?? : See help AND source for magic %cd
%timeit x=10 : time the 'x=10' statement with high precision.
%%timeit x=2**100
x**100 : time 'x*100' with a setup of 'x=2**100'; setup code is not
counted. This is an example of a cell magic.
System commands:
!cp a.txt b/ : System command escape, calls os.system()
cp a.txt b/ : after %rehashx, most system commands work without !
cp ${f}.txt $bar : Variable expansion in magics and system commands
files=!ls /usr : Capture sytem command output
files.s, files.l, files.n: "a b c", ['a','b','c'], 'a\nb\nc'
History:
_i, _ii, _iii : Previous, next previous, next next previous input
_i4, _ih[2:5] : Input history line 4, lines 2-4
exec _i81 : Execute input history line #81 again
%rep 81 : Edit input history line #81
_, __, ___ : previous, next previous, next next previous output
_dh : Directory history
_oh : Output history
%hist : Command history. '%hist -g foo' search history for 'foo'
Autocall:
f 1,2 : f(1,2) # Off by default, enable with %autocall magic.
/f 1,2 : f(1,2) (forced autoparen)
,f 1 2 : f("1","2")
;f 1 2 : f("1 2")
Remember: TAB completion works in many contexts, not just file names
or python names.
The following magic functions are currently available:
%alias:
Define an alias for a system command.
%alias_magic:
%alias_magic [-l] [-c] name target
%autocall:
Make functions callable without having to type parentheses.
#
%automagic:
Make magic functions callable without having to type the initial %.
#使用%automagic on(off)打开(关闭)automagic,打开后使用魔术方法不需要加%
%autosave:
Set the autosave interval in the notebook (in seconds).
%bookmark:
Manage IPython's bookmark system.
%cd:
#切换目录
Change the current working directory.
%clear:
#清除终端
Clear the terminal.
%cls:
Clear the terminal.
%colors:
Switch color scheme for prompts, info system and exception handlers.
Currently implemented schemes: NoColor, Linux, LightBG.
Color scheme names are not case-sensitive.
%config:
configure IPython
%connect_info:
Print information for connecting other clients to this kernel
%debug:
%debug [--breakpoint FILE:LINE] [statement [statement ...]]
%dhist:
Print your history of visited directories.
%dirs:
#返回当前目录
Return the current directory stack.
%doctest_mode:
Toggle doctest mode on and off.
%ed:
#打开文本编辑器
Alias for `%edit`.
%edit:
Bring up an editor and execute the resulting code.
%env:
#罗列环境变量
List environment variables.
%gui:
Enable or disable IPython GUI event loop integration.
%guiref:
Show a basic reference about the GUI Console.
%hist:
Alias for `%history`.
%history:
%history [-n] [-o] [-p] [-t] [-f FILENAME] [-g [PATTERN [PATTERN ...]]]
%install_default_config:
%install_default_config has been deprecated.
%install_ext:
Download and install an extension from a URL, e.g.::
%install_profiles:
%install_profiles has been deprecated.
%killbgscripts:
Kill all BG processes started by %%script and its family.
%less:
Show a file through the pager.
%load:
#载入指定python文件的当前源码
Load code into the current frontend.
%load_ext:
Load an IPython extension by its module name.
%loadpy:
Alias of `%load`
%logoff:
Temporarily stop logging.
%logon:
Restart logging.
%logstart:
Start logging anywhere in a session.
%logstate:
Print the status of the logging system.
%logstop:
Fully stop logging and close log file.
%lsmagic:
List currently available magic functions.
%macro:
Define a macro for future re-execution. It accepts ranges of history,
%magic:
Print information about the magic function system.
%matplotlib:
%matplotlib [gui]
%more:
Show a file through the pager.
%notebook:
%notebook [-e] [-f FORMAT] filename
%page:
Pretty print the object and display it through a pager.
%pastebin:
Upload code to Github's Gist paste bin, returning the URL.
%pdb:
Control the automatic calling of the pdb interactive debugger.
%pdef:
Print the call signature for any callable object.
%pdoc:
Print the docstring for an object.
%pfile:
Print (or run through pager) the file where an object is defined.
%pinfo:
Provide detailed information about an object.
%pinfo2:
Provide extra detailed information about an object.
%popd:
Change to directory popped off the top of the stack.
%pprint:
Toggle pretty printing on/off.
%precision:
Set floating point precision for pretty printing.
%profile:
Print your currently active IPython profile.
%prun:
Run a statement through the python code profiler.
%psearch:
Search for object in namespaces by wildcard.
%psource:
Print (or run through pager) the source code for an object.
%pushd:
Place the current dir on stack and change directory.
%pwd:
Return the current working directory path.
%pycat:
Show a syntax-highlighted file through a pager.
%pylab:
%pylab [--no-import-all] [gui]
%qtconsole:
Open a qtconsole connected to this kernel.
%quickref:
Show a quick reference sheet
%recall:
Repeat a command, or get command to input line for editing.
%rehashx:
Update the alias table with all executable files in $PATH.
%reload_ext:
Reload an IPython extension by its module name.
%rep:
Alias for `%recall`.
%rerun:
Re-run previous input
%reset:
Resets the namespace by removing all names defined by the user, if
%reset_selective:
Resets the namespace by removing names defined by the user.
%run:
Run the named file inside IPython as a program.
%save:
Save a set of lines or a macro to a given filename.
%sc:
Shell capture - run shell command and capture output (DEPRECATED use !).
%store:
Lightweight persistence for python variables.
%sx:
Shell execute - run shell command and capture output (!! is short-hand).
%system:
Shell execute - run shell command and capture output (!! is short-hand).
%tb:
Print the last traceback with the currently active exception mode.
%time:
#一个python表达式的执行时间
Time execution of a Python statement or expression.
%timeit:
Time execution of a Python statement or expression
%unalias:
Remove an alias
%unload_ext:
Unload an IPython extension by its module name.
%who:
Print all interactive variables, with some minimal formatting.
%who_ls:
Return a sorted list of all interactive variables.
%whos:
Like %who, but gives some extra information about each variable.
%xdel:
Delete a variable, trying to clear it from anywhere that
%xmode:
Switch modes for the exception handlers.
%%!:
Shell execute - run shell command and capture output (!! is short-hand).
%%HTML:
Alias for `%%html`.
%%SVG:
Alias for `%%svg`.
%%bash:
%%bash script magic
%%capture:
%capture [--no-stderr] [--no-stdout] [output]
%%cmd:
%%cmd script magic
%%debug:
%debug [--breakpoint FILE:LINE] [statement [statement ...]]
%%file:
Alias for `%%writefile`.
%%html:
Render the cell as a block of HTML
%%javascript:
Run the cell block of Javascript code
%%latex:
Render the cell as a block of latex
%%perl:
%%perl script magic
%%powershell:
%%powershell script magic
%%prun:
Run a statement through the python code profiler.
%%pypy:
%%pypy script magic
%%python:
%%python script magic
%%python3:
%%python3 script magic
%%ruby:
%%ruby script magic
%%script:
%shebang [--proc PROC] [--bg] [--err ERR] [--out OUT]
%%sh:
%%sh script magic
%%svg:
Render the cell as an SVG literal
%%sx:
Shell execute - run shell command and capture output (!! is short-hand).
%%system:
Shell execute - run shell command and capture output (!! is short-hand).
%%time:
Time execution of a Python statement or expression.
%%timeit:
Time execution of a Python statement or expression
%%writefile:
%writefile [-a] filename
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
使用!做前缀可以执行shell命令,还可以用$来转换python变量,如下
for i in range(10):
s=“dir%s” % i
!mkdir $s
for i in !ls:
print i
特别的,如果普通的shell命令有的话,必须使用
的话,必须使用对原来的进行转义,如果原来是echo
进行转义,如果原来是echoPATH,需要使用shell时候,需要写成!echo $$PATH
打印对象属性
使用dir可以将对象属性打印出来,如
import os
dir(os)
SP基本规范
1. 页面构成
JSP页面页面包含了模板元素和JSP元素,JSP元素由JSP引擎直接处理,必须符合JSP语法。JSP元素包括 的内容:
(1)脚本元素:声明、脚本段、表达式。
(2) 注释:HTML注释、Java注释、JSP隐藏注释。
(3)指令元素:paga、include、taglib等。
(4) 动作元素:jsp:include、jsp:forward等。
在传统的HTML页面中加入Java程序片段就是和JSP标签就构成了一个JSP页面,其中Java程序片段由"<%"和"%>"作为开始和结束标记。JSP脚本段内定义的变量只在当前页面内有效,属于页面内的局部变量。
下面用一个例子说明:
在eclipse for JavaEE开发环境中新建一个项目,在webContent目录上右击,选择JSP File,输入文件名,创建一个JSP页面
在页面中输入下面的代码
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ page import="java.util.*" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<%
String name="王后";
if(Calendar.getInstance().get(Calendar.AM_PM)==Calendar.AM) {
out.println(name+",上午好!");
}
else {
out.println(name+",下午好!");
}
int i=0;
out.println("<br/>i的值为"+i);
out.println("<br/>下面修改局部变量i的值");
i++;
out.println("<br/>修改好i的值为"+i);
%>
</body>
</html>
然后,在页面上右击选择 Run AsRun on Server,可以在浏览器中看到运行效果
2. 声明
在JSP页面中,声明是一段Java代码,它用来定义JSP文件转换后的Servlet文件中类的属性和方法。声明的属性和方法在当前JSP页面的任何地方都可以使用,仅限当前页面。声明的语法格式如下:
<% !声明1;声明2;……%>
下面的例子声明一个方法visitor(),代码如下:
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>声明的使用</title>
</head>
<body>
<%! long i=0; %>
<%! String name="红桃"; %>
<%! public String visitor(String who) {
return "你好,"+who+"!";
}
%>
<h2>
<%
i++;
out.println(visitor(name));
out.println("<br/>");
out.print("你是本站第"+i+"为访客");
%>
</h2>
</body>
</html>
用同样的方法运行,运行结果如下:
由于声明定义的变量i是页面内的全局变量,当多次请求该JSP页面时,i的值会被改变。当我们刷新页面几次后
3. 表达式
表达式以<%=开始,%>结束,中间为一个合法的Java表达式。表达在JSP页面被请求时计算,结果转换为String类型字符串与其他模板数据淄河在一起。语法格式如下:
<%=符合Java语法的表达式(结尾不带分号)%>
表达式开始符号<%=之间不能有任何空格。
示例代码如下:
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<%! long i=0;
String name="红桃";
%>
<%! public String visitor(String who) {
return "你好,"+who+"!";
}
%>
<h2>
<%
i++;
%>
<%=visitor(name) %><br/>//表达式使用
你是本站第<%=i %>位访客。//表达式使用
</h2>
</body>
</html>
执行结果如下:
第一部分先介绍到这里。
多朋友想学一下网页制作,上网一看,只要涉及到网页制作,都离不开HTML这个词语,HTML是HyperText Markup Language的简称,想学习HTML语言,先得了解一些基本知识,今天这边内容可以作为学习HTML的菜鸟教程第一课。
HTML是什么?
一般我们说HTML是指超文本标记语言,英文名称为HyperText Markup Language,简称HTML,它是目前互联网上应用最广泛的语言。
如何查看HTML?
拿最常见的网页为例,如果用大家熟悉的IE浏览器的话,直接在网页上点右键,选择“查看源”即可查看当前网页的HTML源码;如果是其他浏览器的话,多数情况下点击右键,选择“查看源码”或者类似“查看网页源代码”这样的选项即可查看。
当然也可以通过专业的网页制作软件以及各种文本编辑器来查看。
HTML有什么用?
HTML语言可以方便地将网络上存储于不同位置的文字、图片、声音、视频等内容组织起来,方便用户浏览。对于我们来说,HTML是学习网页制作的基本功,熟练掌握HTML这项基本功,可以为以后的学习和工作打下良好的基础。
HTML如何入门?
要学习任何编程语言,都不好好高骛远,HTML的入门很简单,但是也要遵循学习的基本步骤,选择一本入门书籍,循序渐进地去学习每一张的内容。一边学习,一边查看网页代码对照来学,提升入门速度。
HTML案例
下面就是最基本的HTML案例,在这个案例中,用的是HTML5,
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>HTML菜鸟教程(runoob.com)</title>
</head>
<body>
<h1>我的第一个标题</h1>
<p>我的第一个段落。</p>
</body>
</html>如何编辑HTML?
这个就很多了 ,比如最出名的Dreamweaver,当然如果熟练之后,可以选择任意自己喜欢的编辑器,一些小的改动或者一小段代码的话,也可以用各种常见的文本编辑器来处理,比如我们在wodows系统上常见的记事本,总之只要自己觉得方便就好。
总结
以上是学习HTML菜鸟教程的第一课,首先保持一个良好的心态来学习,有好的心态,知识方面只要循序渐进,学会就是水到渠成的事情了 。
*请认真填写需求信息,我们会在24小时内与您取得联系。