<?xml version="1.0" encoding="utf-8"?><feed xmlns="http://www.w3.org/2005/Atom"><title type="text">博客园_学院派的驴</title><subtitle type="text"/><id>http://feed.cnblogs.com/blog/u/57461/rss</id><updated>2012-04-16T10:05:39Z</updated><author><name>finallyly</name><uri>http://www.cnblogs.com/finallyliuyu/</uri></author><generator>feed.cnblogs.com</generator><link rel="alternate" type="text/html" href="http://www.cnblogs.com/finallyliuyu/"/><link rel="self" type="application/atom+xml" href="http://feed.cnblogs.com/blog/u/57461/rss"/><entry><id>http://www.cnblogs.com/finallyliuyu/archive/2012/04/16/2452079.html</id><title type="text">perl  shell交换示例</title><summary type="text">a.sh 1 #/bin/sh 2 echo "haha"; 3 exit 1;perl脚本22 my $output=qx(sh a.sh);23 my $exitcode=$?;24 $exitcode&gt;&gt;=8;25 print "output=$output\n";26 print "exitcode=$exitcode\n";27 system("pwd");28 print STDERR "$0 has finished,congratulations!\n";29 pri</summary><published>2012-04-16T09:42:00Z</published><updated>2012-04-16T09:42:00Z</updated><author><name>finallyly</name><uri>http://www.cnblogs.com/finallyliuyu/</uri></author><link rel="alternate" href="http://www.cnblogs.com/finallyliuyu/archive/2012/04/16/2452079.html"/><link rel="alternate" type="text/html" href="http://www.cnblogs.com/finallyliuyu/archive/2012/04/16/2452079.html"/><content type="html">&lt;p&gt;a.sh&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&amp;nbsp; 1 #/bin/sh&lt;br /&gt;&amp;nbsp; 2 echo "haha";&lt;br /&gt;&amp;nbsp; 3 exit 1;&lt;br /&gt;perl脚本&lt;/p&gt;&lt;p&gt;22 my $output=qx(sh a.sh);&lt;br /&gt;&amp;nbsp;23 my $exitcode=$?;&lt;br /&gt;&amp;nbsp;24 $exitcode&amp;gt;&amp;gt;=8;&lt;br /&gt;&amp;nbsp;25 print "output=$output\n";&lt;br /&gt;&amp;nbsp;26 print "exitcode=$exitcode\n";&lt;br /&gt;&amp;nbsp;27 system("pwd");&lt;br /&gt;&amp;nbsp;28 print STDERR "$0 has finished,congratulations!\n";&lt;br /&gt;&amp;nbsp;29 print STDERR "Time elapsed:".(Time::HiRes::time-$tmStarted)."\n";&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;http://www.docin.com/p-56464488.html&lt;/p&gt;&lt;img src="http://www.cnblogs.com/finallyliuyu/aggbug/2452079.html?type=1" width="1" height="1" alt=""/&gt;&lt;p&gt;&lt;a href="http://www.cnblogs.com/finallyliuyu/archive/2012/04/16/2452079.html" target="_blank"&gt;本文链接&lt;/a&gt;&lt;/p&gt;</content></entry><entry><id>http://www.cnblogs.com/finallyliuyu/archive/2012/03/28/2422116.html</id><title type="text">perl双层哈希求长度</title><summary type="text">my $size=scalar keys%hash_ref;37 print STDERR "top-level hash_ref $size\n";38 foreach my $key (keys %hash_ref)39 {40 $size=scalar keys%{$hash_ref{$key}};41 print STDERR "second-level hash_ref $size\n";42 43 }44 foreach my $key (keys %hash_ref)45 {46 foreach my $subkey (keys %{$ha</summary><published>2012-03-28T13:44:00Z</published><updated>2012-03-28T13:44:00Z</updated><author><name>finallyly</name><uri>http://www.cnblogs.com/finallyliuyu/</uri></author><link rel="alternate" href="http://www.cnblogs.com/finallyliuyu/archive/2012/03/28/2422116.html"/><link rel="alternate" type="text/html" href="http://www.cnblogs.com/finallyliuyu/archive/2012/03/28/2422116.html"/><content type="html">&lt;p&gt;my $size=scalar keys%hash_ref;&lt;br /&gt;&amp;nbsp;37 print STDERR "top-level hash_ref $size\n";&lt;br /&gt;&amp;nbsp;38 foreach&amp;nbsp; my $key (keys %hash_ref)&lt;br /&gt;&amp;nbsp;39 {&lt;br /&gt;&amp;nbsp;40&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; $size=scalar keys%{$hash_ref{$key}};&lt;br /&gt;&amp;nbsp;41&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print STDERR "second-level hash_ref $size\n";&lt;br /&gt;&amp;nbsp;42 &lt;br /&gt;&amp;nbsp;43 }&lt;br /&gt;&amp;nbsp;44 foreach my $key (keys %hash_ref)&lt;br /&gt;&amp;nbsp;45 {&lt;br /&gt;&amp;nbsp;46&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; foreach my $subkey (keys %{$hash_ref{$key}})&lt;br /&gt;&amp;nbsp;47&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;&amp;nbsp;48&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print STDERR "$key\t$subkey\n";&lt;br /&gt;&amp;nbsp;49 &lt;br /&gt;&amp;nbsp;50&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;&amp;nbsp;51 } &lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;字符串数组相关:&lt;/p&gt;&lt;p&gt;use strict;&lt;br /&gt;use warnings;&lt;br /&gt;my $asc=ord("我");&lt;br /&gt;my $val=$asc &amp;amp; 0x80;&lt;br /&gt;print "$asc\n";&lt;br /&gt;print "$val\n" ;&lt;br /&gt;my $line="我是中国人";&lt;br /&gt;my $lenline= length $line;&lt;br /&gt;my @vec =split //,$line;&lt;br /&gt;my $size= scalar @vec;&lt;br /&gt;print "字符串的长度是 $lenline 数组的长度为$size\n" ;&lt;/p&gt;&lt;img src="http://www.cnblogs.com/finallyliuyu/aggbug/2422116.html?type=1" width="1" height="1" alt=""/&gt;&lt;p&gt;&lt;a href="http://www.cnblogs.com/finallyliuyu/archive/2012/03/28/2422116.html" target="_blank"&gt;本文链接&lt;/a&gt;&lt;/p&gt;</content></entry><entry><id>http://www.cnblogs.com/finallyliuyu/archive/2012/03/24/2415265.html</id><title type="text">【zz】Perl数字与字符串间的自动转换</title><summary type="text">http://developer.51cto.com/art/201007/211617.htm 本文和大家重点讨论一下Perl语言中Perl数字与字符串间的自动转换，这里从七个方面向大家介绍，相信通过过本文的学习你对Perl数字与字符串间的自动转换有一定的了解。Perl数字与字符串间的自动转换Perl会根据需要，在数字与字符串间进行自动转换：1、自动转换是根据操作符来的。如果操作符需要数字，它就会把字符串转换成数字；如果需要字符串，就会所数字转换成字符串。"12"."3"等同于"123""12"*"3&amp;</summary><published>2012-03-24T02:44:00Z</published><updated>2012-03-24T02:44:00Z</updated><author><name>finallyly</name><uri>http://www.cnblogs.com/finallyliuyu/</uri></author><link rel="alternate" href="http://www.cnblogs.com/finallyliuyu/archive/2012/03/24/2415265.html"/><link rel="alternate" type="text/html" href="http://www.cnblogs.com/finallyliuyu/archive/2012/03/24/2415265.html"/><content type="html">&lt;p&gt;&lt;a href="http://developer.51cto.com/art/201007/211617.htm"&gt;http://developer.51cto.com/art/201007/211617.htm&lt;/a&gt;&lt;/p&gt;&lt;p&gt;&lt;span class="Apple-style-span" style="word-spacing: 0px; font: 14px/28px 宋体; text-transform: none; color: rgb(51,51,51); text-indent: 0px; white-space: normal; letter-spacing: normal; background-color: rgb(248,248,248); orphans: 2; widows: 2; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px"&gt; &lt;/p&gt;&lt;p&gt;本文和大家重点讨论一下Perl语言中Perl数字与字符串间的自动转换，这里从七个方面向大家介绍，相信通过过本文的学习你对Perl数字与字符串间的自动转换有一定的了解。&lt;/p&gt;&lt;p&gt;&lt;strong style="font-weight: bold; text-align: center"&gt;Perl数字与字符串间的自动转换&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;Perl会根据需要，在数字与字符串间进行自动转换：&lt;/p&gt;&lt;p&gt;&lt;strong style="font-weight: bold; text-align: center"&gt;1、自动转换是根据操作符来的。&lt;/strong&gt;如果操作符需要数字，它就会把字符串转换成数字；如果需要字符串，就会所数字转换成字符串。&lt;/p&gt;&lt;p&gt;"12"."3"等同于"123"&lt;/p&gt;&lt;p&gt;"12"*"3"等同于36&lt;/p&gt;&lt;p&gt;"z".5*3"等同于"z".15等同于"z15"&lt;/p&gt;&lt;p&gt;&lt;strong style="font-weight: bold; text-align: center"&gt;2、数字转字符串没疑问&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;&lt;strong style="font-weight: bold; text-align: center"&gt;3、字符串转数字：&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;转换时，找到字符串第一个数字部分，然后后面的非数字部分和前面的去掉，比如"12adsfasdlkf34234fsd234"*3等同于12*3等于36。如果字符串中不含有数字，则会转换成0。&lt;br style="clear: both; width: 0px; height: 0px" /&gt;对于非十进制数，'0'前缀只对数字有效，对自动转换是没用的，如"0xab"*0x12并不会把前面的"0xab"当作十六进制数处理&lt;/p&gt;&lt;p&gt;&lt;strong style="font-weight: bold; text-align: center"&gt;4、Perl会记住转换的结果，所以不必担效率问题。&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;关于Perl的字符串，应该记住的一些东西：&lt;/p&gt;&lt;p&gt;1、有Perl中，最短的字符串是空串，最长的字符串是填满整个内存。&lt;/p&gt;&lt;p&gt;2、Perl中的字符串可以包括任意字符，意味着你可以创建、遍历、操作二进制数据&lt;/p&gt;&lt;p&gt;3、在Perl中，null并没有特殊意义。&lt;/p&gt;&lt;p&gt;4、单引号字符串&lt;/p&gt;&lt;p&gt;单引号代表字符串的开始与结束&lt;/p&gt;&lt;p&gt;只有单引号'和反斜线\是特殊字符，其它所有字符都代表其本身，包括换行符在内。换句话说，在单引号字符串中，只有用到了单引号和反斜线时才需要转义。比如在字符串中你写了\n，并不会当作换行符处理，而只是两个普通的字符\和n&lt;br style="clear: both; width: 0px; height: 0px" /&gt;对于\，只有它后面紧跟着\和'时，才会被当作特殊字符处理&lt;/p&gt;&lt;p&gt;&lt;strong style="font-weight: bold; text-align: center"&gt;5、双引号字符串&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;和我们熟悉的在其它语言中的字符串一样。\会被当作转义字符处理。&lt;br style="clear: both; width: 0px; height: 0px" /&gt;它还有一个特有的特质：变量内插。就是当字符串中含有一个变量名时，它会用变量值来代替它。&lt;/p&gt;&lt;p&gt;&lt;strong style="font-weight: bold; text-align: center"&gt;6、连接操作符.&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;比如："Hello".''."World!"结果就是"HelloWorld!"&lt;/p&gt;&lt;p&gt;&lt;br style="clear: both; width: 0px; height: 0px" /&gt;&lt;strong style="font-weight: bold; text-align: center"&gt;7、重复操作符x是一小写字母。&lt;/strong&gt;操作符左边是一个字符串，操作符右边是一个数字，操作结果会把字符串重复那个数字的次数。如"hello"x5,操作结果就是"hellohellohellohellohello"&lt;/p&gt;&lt;p&gt;注意：当x右边的数字是一个非整数时，将转换为小于等于它的整数，比如4.8会转换成4,而当这个数字小于1时，则会产生一个空串。&lt;/p&gt;&lt;p&gt;&lt;/span&gt;&amp;nbsp;&lt;/p&gt;&lt;img src="http://www.cnblogs.com/finallyliuyu/aggbug/2415265.html?type=1" width="1" height="1" alt=""/&gt;&lt;p&gt;&lt;a href="http://www.cnblogs.com/finallyliuyu/archive/2012/03/24/2415265.html" target="_blank"&gt;本文链接&lt;/a&gt;&lt;/p&gt;</content></entry><entry><id>http://www.cnblogs.com/finallyliuyu/archive/2012/03/24/2415230.html</id><title type="text">perl 语言学习——从C/C++到perl</title><summary type="text">use strict;use warnings;#数值比较大小和字符串比较大小my $str1="1 -the first str";my $str2="1 - the second str";if($str1==$str2){ print "numerically equal\n";}if($str1 eq $str2){ print "stringwise equal\n" ;}print "a.b"."haha" 有用的测试样例：usestrict;usewarning</summary><published>2012-03-24T02:31:00Z</published><updated>2012-03-24T02:31:00Z</updated><author><name>finallyly</name><uri>http://www.cnblogs.com/finallyliuyu/</uri></author><link rel="alternate" href="http://www.cnblogs.com/finallyliuyu/archive/2012/03/24/2415230.html"/><link rel="alternate" type="text/html" href="http://www.cnblogs.com/finallyliuyu/archive/2012/03/24/2415230.html"/><content type="html">&lt;p&gt;use strict;&lt;br /&gt;use warnings;&lt;br /&gt;#数值比较大小和字符串比较大小&lt;br /&gt;&amp;nbsp;my $str1="1 -the first str";&lt;br /&gt;&amp;nbsp;my $str2="1 - the second str";&lt;br /&gt;&amp;nbsp;if($str1==$str2)&lt;br /&gt;&amp;nbsp;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; print "numerically equal\n";&lt;br /&gt;&amp;nbsp;}&lt;br /&gt;&amp;nbsp;if($str1 eq $str2)&lt;br /&gt;&amp;nbsp;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; print "stringwise equal\n" ;&lt;br /&gt;&amp;nbsp;}&lt;br /&gt;&amp;nbsp;print "a.b"."haha" &lt;/p&gt;&lt;p&gt;有用的测试样例：&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;div style="background-color: #F5F5F5;border: 1px solid #CCCCCC;padding:10px;"&gt;&lt;div&gt;&lt;span style="color: #0000ff"&gt;use&lt;/span&gt;&amp;nbsp;strict;&lt;br /&gt;&lt;span style="color: #0000ff"&gt;use&lt;/span&gt;&amp;nbsp;warnings;&lt;br /&gt;&lt;span style="color: #0000ff"&gt;my&lt;/span&gt;&amp;nbsp;&lt;span style="color: #800080"&gt;$x&lt;/span&gt;=&lt;span style="color: #800000"&gt;1&lt;/span&gt;;&lt;br /&gt;&lt;span style="color: #0000ff"&gt;if&lt;/span&gt;(&lt;span style="color: #800080"&gt;$x&lt;/span&gt;)&lt;br /&gt;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&lt;span style="color: #0000ff"&gt;print&lt;/span&gt;&amp;nbsp;&lt;span style="font-weight: bold; color: #000000"&gt;"&lt;/span&gt;&lt;span style="font-weight: bold; color: #000000"&gt;x:yes\n&lt;/span&gt;&lt;span style="font-weight: bold; color: #000000"&gt;"&lt;/span&gt;;&lt;br /&gt;}&lt;br /&gt;&lt;span style="color: #0000ff"&gt;my&lt;/span&gt;&amp;nbsp;&lt;span style="color: #800080"&gt;$y&lt;/span&gt;=&lt;span style="color: #800000"&gt;0&lt;/span&gt;;&lt;br /&gt;&lt;span style="color: #0000ff"&gt;if&lt;/span&gt;(&lt;span style="color: #800080"&gt;$y&lt;/span&gt;)&lt;br /&gt;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&lt;span style="color: #0000ff"&gt;print&lt;/span&gt;&amp;nbsp;&lt;span style="font-weight: bold; color: #000000"&gt;"&lt;/span&gt;&lt;span style="font-weight: bold; color: #000000"&gt;y:yes\n&lt;/span&gt;&lt;span style="font-weight: bold; color: #000000"&gt;"&lt;/span&gt;;&lt;br /&gt;}&lt;br /&gt;&lt;span style="color: #0000ff"&gt;my&lt;/span&gt;&amp;nbsp;&lt;span style="color: #800080"&gt;$z&lt;/span&gt;=&lt;span style="color: #800000"&gt;0.0&lt;/span&gt;;&lt;br /&gt;&lt;span style="color: #0000ff"&gt;if&lt;/span&gt;(&lt;span style="color: #800080"&gt;$z&lt;/span&gt;)&lt;br /&gt;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&lt;span style="color: #0000ff"&gt;print&lt;/span&gt;&amp;nbsp;&lt;span style="font-weight: bold; color: #000000"&gt;"&lt;/span&gt;&lt;span style="font-weight: bold; color: #000000"&gt;z:yes\n&lt;/span&gt;&lt;span style="font-weight: bold; color: #000000"&gt;"&lt;/span&gt;;&lt;br /&gt;}&lt;br /&gt;&lt;span style="color: #0000ff"&gt;my&lt;/span&gt;&amp;nbsp;&lt;span style="color: #800080"&gt;$a&lt;/span&gt;=&lt;span style="font-weight: bold; color: #000000"&gt;"&lt;/span&gt;&lt;span style="font-weight: bold; color: #000000"&gt;0&lt;/span&gt;&lt;span style="font-weight: bold; color: #000000"&gt;"&lt;/span&gt;;&lt;br /&gt;&lt;span style="color: #0000ff"&gt;if&lt;/span&gt;(&lt;span style="color: #800080"&gt;$a&lt;/span&gt;)&lt;br /&gt;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&lt;span style="color: #0000ff"&gt;print&lt;/span&gt;&amp;nbsp;&lt;span style="font-weight: bold; color: #000000"&gt;"&lt;/span&gt;&lt;span style="font-weight: bold; color: #000000"&gt;a:yes\n&lt;/span&gt;&lt;span style="font-weight: bold; color: #000000"&gt;"&lt;/span&gt;;&lt;br /&gt;}&lt;br /&gt;&lt;span style="color: #0000ff"&gt;my&lt;/span&gt;&amp;nbsp;&lt;span style="color: #800080"&gt;$b&lt;/span&gt;=&lt;span style="font-weight: bold; color: #000000"&gt;'&lt;/span&gt;&lt;span style="font-weight: bold; color: #000000"&gt;00&lt;/span&gt;&lt;span style="font-weight: bold; color: #000000"&gt;'&lt;/span&gt;;&lt;br /&gt;&lt;span style="color: #0000ff"&gt;if&lt;/span&gt;(&lt;span style="color: #800080"&gt;$b&lt;/span&gt;)&lt;br /&gt;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&lt;span style="color: #0000ff"&gt;print&lt;/span&gt;&amp;nbsp;&lt;span style="font-weight: bold; color: #000000"&gt;"&lt;/span&gt;&lt;span style="font-weight: bold; color: #000000"&gt;b:\yes\n&lt;/span&gt;&lt;span style="font-weight: bold; color: #000000"&gt;"&lt;/span&gt;&amp;nbsp;;&lt;br /&gt;}&lt;br /&gt;&lt;span style="color: #0000ff"&gt;my&lt;/span&gt;&amp;nbsp;&lt;span style="color: #800080"&gt;$c&lt;/span&gt;=&amp;nbsp;&lt;span style="font-weight: bold; color: #000000"&gt;"&lt;/span&gt;&lt;span style="font-weight: bold; color: #000000"&gt;0.0&lt;/span&gt;&lt;span style="font-weight: bold; color: #000000"&gt;"&lt;/span&gt;;&lt;br /&gt;&lt;span style="color: #0000ff"&gt;if&lt;/span&gt;(&lt;span style="color: #800080"&gt;$c&lt;/span&gt;)&lt;br /&gt;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&lt;span style="color: #0000ff"&gt;print&lt;/span&gt;&amp;nbsp;&lt;span style="font-weight: bold; color: #000000"&gt;"&lt;/span&gt;&lt;span style="font-weight: bold; color: #000000"&gt;c:yes\n&lt;/span&gt;&lt;span style="font-weight: bold; color: #000000"&gt;"&lt;/span&gt;;&lt;br /&gt;}&lt;br /&gt;&lt;span style="color: #0000ff"&gt;my&lt;/span&gt;&amp;nbsp;&lt;span style="color: #800080"&gt;$d&lt;/span&gt;=&lt;span style="font-weight: bold; color: #000000"&gt;""&lt;/span&gt;;&lt;br /&gt;&lt;span style="color: #0000ff"&gt;if&lt;/span&gt;(&lt;span style="color: #800080"&gt;$d&lt;/span&gt;)&lt;br /&gt;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&lt;span style="color: #0000ff"&gt;print&lt;/span&gt;&amp;nbsp;&lt;span style="font-weight: bold; color: #000000"&gt;"&lt;/span&gt;&lt;span style="font-weight: bold; color: #000000"&gt;d:yes\n&lt;/span&gt;&lt;span style="font-weight: bold; color: #000000"&gt;"&lt;/span&gt;;&lt;br /&gt;}&lt;br /&gt;&lt;span style="color: #0000ff"&gt;my&lt;/span&gt;&amp;nbsp;&lt;span style="color: #800080"&gt;$e&lt;/span&gt;=&lt;span style="font-weight: bold; color: #000000"&gt;"&lt;/span&gt;&lt;span style="font-weight: bold; color: #000000"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-weight: bold; color: #000000"&gt;"&lt;/span&gt;;&lt;br /&gt;&lt;span style="color: #0000ff"&gt;if&lt;/span&gt;(&lt;span style="color: #800080"&gt;$e&lt;/span&gt;)&lt;br /&gt;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&lt;span style="color: #0000ff"&gt;print&lt;/span&gt;&amp;nbsp;&lt;span style="font-weight: bold; color: #000000"&gt;"&lt;/span&gt;&lt;span style="font-weight: bold; color: #000000"&gt;e:yes\n&lt;/span&gt;&lt;span style="font-weight: bold; color: #000000"&gt;"&lt;/span&gt;&lt;br /&gt;}&lt;br /&gt;&lt;span style="color: #0000ff"&gt;my&lt;/span&gt;&amp;nbsp;&lt;span style="color: #800080"&gt;$g&lt;/span&gt;=&lt;span style="font-weight: bold; color: #000000"&gt;"&lt;/span&gt;&lt;span style="font-weight: bold; color: #000000"&gt;0&lt;/span&gt;&lt;span style="font-weight: bold; color: #000000"&gt;"&lt;/span&gt;;&lt;br /&gt;&lt;span style="color: #0000ff"&gt;if&lt;/span&gt;(&lt;span style="color: #800080"&gt;$g&lt;/span&gt;==&lt;span style="color: #800080"&gt;$c&lt;/span&gt;)&lt;br /&gt;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&lt;span style="color: #0000ff"&gt;print&lt;/span&gt;&amp;nbsp;&lt;span style="font-weight: bold; color: #000000"&gt;"&lt;/span&gt;&lt;span style="font-weight: bold; color: #000000"&gt;numerically&amp;nbsp;equal&lt;/span&gt;&lt;span style="font-weight: bold; color: #000000"&gt;"&lt;/span&gt;&amp;nbsp;;&lt;br /&gt;}&lt;br /&gt;&lt;span style="color: #0000ff"&gt;if&lt;/span&gt;(&lt;span style="color: #800080"&gt;$g&lt;/span&gt;&amp;nbsp;eq&amp;nbsp;&lt;span style="color: #800080"&gt;$c&lt;/span&gt;)&lt;br /&gt;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&lt;span style="color: #0000ff"&gt;print&lt;/span&gt;&amp;nbsp;&lt;span style="font-weight: bold; color: #000000"&gt;"&lt;/span&gt;&lt;span style="font-weight: bold; color: #000000"&gt;string-wise&amp;nbsp;equal&lt;/span&gt;&lt;span style="font-weight: bold; color: #000000"&gt;"&lt;/span&gt;;&lt;br /&gt;}&lt;/div&gt;&lt;/div&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;img src="http://www.cnblogs.com/finallyliuyu/aggbug/2415230.html?type=1" width="1" height="1" alt=""/&gt;&lt;p&gt;&lt;a href="http://www.cnblogs.com/finallyliuyu/archive/2012/03/24/2415230.html" target="_blank"&gt;本文链接&lt;/a&gt;&lt;/p&gt;</content></entry><entry><id>http://www.cnblogs.com/finallyliuyu/archive/2012/03/22/2412225.html</id><title type="text">linux操作相关</title><summary type="text">查看vi打开的文件的文件名的命令。ctrl+G :f</summary><published>2012-03-22T11:49:00Z</published><updated>2012-03-22T11:49:00Z</updated><author><name>finallyly</name><uri>http://www.cnblogs.com/finallyliuyu/</uri></author><link rel="alternate" href="http://www.cnblogs.com/finallyliuyu/archive/2012/03/22/2412225.html"/><link rel="alternate" type="text/html" href="http://www.cnblogs.com/finallyliuyu/archive/2012/03/22/2412225.html"/><content type="html">查看vi打开的文件的文件名的命令。ctrl+G :f&lt;img src="http://www.cnblogs.com/finallyliuyu/aggbug/2412225.html?type=1" width="1" height="1" alt=""/&gt;&lt;p&gt;&lt;a href="http://www.cnblogs.com/finallyliuyu/archive/2012/03/22/2412225.html" target="_blank"&gt;本文链接&lt;/a&gt;&lt;/p&gt;</content></entry><entry><id>http://www.cnblogs.com/finallyliuyu/archive/2012/03/15/2397763.html</id><title type="text">转载 python每次读入文件一行的问题(血的教训啊)</title><summary type="text">http://blog.csdn.net/oldjwu/article/details/4329401Python每次读入文件一行的问题分类：Python2009-07-07 21:461612人阅读评论(0)收藏举报 注意到Python每次读入一个文件的一行时，可以有两种写法：[python]view plaincopyf=open("bigFile.txt","r")whileTrue:line=f.readline()ifline:pass#dosomethinghereelse:breakf.close() 另一种写法为：[python]view</summary><published>2012-03-15T04:06:00Z</published><updated>2012-03-15T04:06:00Z</updated><author><name>finallyly</name><uri>http://www.cnblogs.com/finallyliuyu/</uri></author><link rel="alternate" href="http://www.cnblogs.com/finallyliuyu/archive/2012/03/15/2397763.html"/><link rel="alternate" type="text/html" href="http://www.cnblogs.com/finallyliuyu/archive/2012/03/15/2397763.html"/><content type="html">&lt;span style="color: #333333; font-family: Arial, Console, Verdana, 'Courier New'; font-size: 12px; "&gt;&lt;div style="display: block; margin-top: 5px; margin-right: 0px; margin-bottom: 5px; margin-left: 0px; color: #000000; font: normal normal normal 20px/30px 'Microsoft YaHei'; "&gt;&amp;nbsp;&lt;span style="font-size: 11px;"&gt;http://blog.csdn.net/oldjwu/article/details/4329401&lt;/span&gt;&lt;p&gt;&lt;strong&gt;&lt;a href="http://blog.csdn.net/oldjwu/article/details/4329401" style="color: #000000; text-decoration: none; "&gt;Python每次读入文件一行的问题&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;&lt;/div&gt;&lt;div style="padding-top: 5px; padding-right: 0px; padding-bottom: 5px; padding-left: 0px; color: #999999; font: normal normal normal 12px/24px Arial; text-align: right; "&gt;&lt;span style="margin-top: 0px; margin-right: 5px; margin-bottom: 0px; margin-left: 5px; float: left; "&gt;分类：&amp;nbsp;&lt;a href="http://blog.csdn.net/oldjwu/article/category/377880" style="color: #336699; text-decoration: none; "&gt;Python&lt;/a&gt;&lt;/span&gt;&lt;span style="margin-top: 0px; margin-right: 5px; margin-bottom: 0px; margin-left: 0px; "&gt;2009-07-07 21:46&lt;/span&gt;&amp;nbsp;&lt;span title="阅读次数" style="margin-top: 0px; margin-right: 5px; margin-bottom: 0px; margin-left: 5px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 14px; background-image: url(http://static.blog.csdn.net/images/ico_view.png); background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; background-position: 0% 50%; background-repeat: no-repeat no-repeat; "&gt;1612人阅读&lt;/span&gt;&amp;nbsp;&lt;span title="评论次数" style="margin-top: 0px; margin-right: 5px; margin-bottom: 0px; margin-left: 5px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 14px; background-image: url(http://static.blog.csdn.net/images/ico_comm.png); background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; background-position: 0% 50%; background-repeat: no-repeat no-repeat; "&gt;&lt;a href="http://blog.csdn.net/oldjwu/article/details/4329401#comments" style="color: #336699; text-decoration: none; "&gt;评论&lt;/a&gt;(0)&lt;/span&gt;&amp;nbsp;&lt;span style="margin-top: 0px; margin-right: 5px; margin-bottom: 0px; margin-left: 5px; "&gt;&lt;a href="http://blog.csdn.net/oldjwu/article/details/4329401" title="收藏" style="color: #336699; text-decoration: none; "&gt;收藏&lt;/a&gt;&lt;/span&gt;&amp;nbsp;&lt;span style="margin-top: 0px; margin-right: 5px; margin-bottom: 0px; margin-left: 5px; "&gt;&lt;a href="http://blog.csdn.net/oldjwu/article/details/4329401#report" title="举报" style="color: #336699; text-decoration: none; "&gt;举报&lt;/a&gt;&lt;/span&gt;&lt;/div&gt;&lt;div id="article_content" style="margin-top: 20px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font-family: 'Courier New', Console, Verdana, 微软雅黑; font: normal normal normal 14px/26px Arial; "&gt;&lt;p&gt;注意到Python每次读入一个文件的一行时，可以有两种写法：&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;div bg_python"="" style="width: 687px; "&gt;&lt;div&gt;&lt;div&gt;&lt;strong&gt;[python]&lt;/strong&gt;&amp;nbsp;&lt;a href="http://blog.csdn.net/oldjwu/article/details/4329401#" title="view plain" style="background-image: url(http://static.blog.csdn.net/scripts/SyntaxHighlighter/styles/images/default/ico_plain.gif); border-width: initial; border-color: initial; padding-top: 1px; padding-right: 1px; padding-bottom: 1px; padding-left: 1px; display: inline-block; width: 16px; height: 16px; text-indent: -2000px; background-position: 0% 0%; background-repeat: no-repeat no-repeat; "&gt;view plain&lt;/a&gt;&lt;a href="http://blog.csdn.net/oldjwu/article/details/4329401#" title="copy" style="background-image: url(http://static.blog.csdn.net/scripts/SyntaxHighlighter/styles/images/default/ico_copy.gif); border-width: initial; border-color: initial; padding-top: 1px; padding-right: 1px; padding-bottom: 1px; padding-left: 1px; display: inline-block; width: 16px; height: 16px; text-indent: -2000px; background-position: 0% 0%; background-repeat: no-repeat no-repeat; "&gt;copy&lt;/a&gt;&lt;div style="position: absolute; left: 382px; top: 444px; width: 18px; height: 18px; z-index: 99; "&gt;&lt;embed id="ZeroClipboardMovie_1" src="http://static.blog.csdn.net/scripts/ZeroClipboard/ZeroClipboard.swf" loop="false" menu="false" quality="best" bgcolor="#ffffff" width="18" height="18" name="ZeroClipboardMovie_1" align="center" allowscriptaccess="always" allowfullscreen="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" flashvars="id=1&amp;amp;width=18&amp;amp;height=18" wmode="transparent"&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;ol start="1" style="border-width: initial; border-color: initial; "&gt;&lt;li style="border-width: initial; border-color: initial; line-height: 18px; "&gt;&lt;span style="border-width: initial; border-color: initial; "&gt;&lt;span style="border-width: initial; border-color: initial; "&gt;f&amp;nbsp;=&amp;nbsp;open(&lt;/span&gt;&lt;span style="border-width: initial; border-color: initial; "&gt;"bigFile.txt"&lt;/span&gt;&lt;span style="border-width: initial; border-color: initial; "&gt;,&amp;nbsp;&lt;/span&gt;&lt;span style="border-width: initial; border-color: initial; "&gt;"r"&lt;/span&gt;&lt;span style="border-width: initial; border-color: initial; "&gt;)&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;&lt;li style="border-width: initial; border-color: initial; line-height: 18px; "&gt;&lt;span style="border-width: initial; border-color: initial; "&gt;&lt;span style="border-width: initial; border-color: initial; "&gt;while&lt;/span&gt;&amp;nbsp;&lt;span style="border-width: initial; border-color: initial; "&gt;True&lt;/span&gt;&lt;span style="border-width: initial; border-color: initial; "&gt;:&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;&lt;li style="border-width: initial; border-color: initial; line-height: 18px; "&gt;&lt;span style="border-width: initial; border-color: initial; "&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;line&amp;nbsp;=&amp;nbsp;f.readline()&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/li&gt;&lt;li style="border-width: initial; border-color: initial; line-height: 18px; "&gt;&lt;span style="border-width: initial; border-color: initial; "&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="border-width: initial; border-color: initial; "&gt;if&lt;/span&gt;&lt;span style="border-width: initial; border-color: initial; "&gt;&amp;nbsp;line:&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;&lt;li style="border-width: initial; border-color: initial; line-height: 18px; "&gt;&lt;span style="border-width: initial; border-color: initial; "&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="border-width: initial; border-color: initial; "&gt;pass&lt;/span&gt;&lt;span style="border-width: initial; border-color: initial; "&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="border-width: initial; border-color: initial; "&gt;#&amp;nbsp;do&amp;nbsp;something&amp;nbsp;here&lt;/span&gt;&lt;span style="border-width: initial; border-color: initial; "&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;&lt;li style="border-width: initial; border-color: initial; line-height: 18px; "&gt;&lt;span style="border-width: initial; border-color: initial; "&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="border-width: initial; border-color: initial; "&gt;else&lt;/span&gt;&lt;span style="border-width: initial; border-color: initial; "&gt;:&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;&lt;li style="border-width: initial; border-color: initial; line-height: 18px; "&gt;&lt;span style="border-width: initial; border-color: initial; "&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="border-width: initial; border-color: initial; "&gt;break&lt;/span&gt;&lt;span style="border-width: initial; border-color: initial; "&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;&lt;li style="border-width: initial; border-color: initial; line-height: 18px; "&gt;&lt;span style="border-width: initial; border-color: initial; "&gt;f.close()&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/li&gt;&lt;/ol&gt;&lt;/div&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;&amp;nbsp;另一种写法为：&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;div bg_python"="" style="width: 687px; "&gt;&lt;div&gt;&lt;div&gt;&lt;strong&gt;[python]&lt;/strong&gt;&amp;nbsp;&lt;a href="http://blog.csdn.net/oldjwu/article/details/4329401#" title="view plain" style="background-image: url(http://static.blog.csdn.net/scripts/SyntaxHighlighter/styles/images/default/ico_plain.gif); border-width: initial; border-color: initial; padding-top: 1px; padding-right: 1px; padding-bottom: 1px; padding-left: 1px; display: inline-block; width: 16px; height: 16px; text-indent: -2000px; background-position: 0% 0%; background-repeat: no-repeat no-repeat; "&gt;view plain&lt;/a&gt;&lt;a href="http://blog.csdn.net/oldjwu/article/details/4329401#" title="copy" style="background-image: url(http://static.blog.csdn.net/scripts/SyntaxHighlighter/styles/images/default/ico_copy.gif); border-width: initial; border-color: initial; padding-top: 1px; padding-right: 1px; padding-bottom: 1px; padding-left: 1px; display: inline-block; width: 16px; height: 16px; text-indent: -2000px; background-position: 0% 0%; background-repeat: no-repeat no-repeat; "&gt;copy&lt;/a&gt;&lt;div style="position: absolute; left: 382px; top: 763px; width: 18px; height: 18px; z-index: 99; "&gt;&lt;embed id="ZeroClipboardMovie_2" src="http://static.blog.csdn.net/scripts/ZeroClipboard/ZeroClipboard.swf" loop="false" menu="false" quality="best" bgcolor="#ffffff" width="18" height="18" name="ZeroClipboardMovie_2" align="center" allowscriptaccess="always" allowfullscreen="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" flashvars="id=2&amp;amp;width=18&amp;amp;height=18" wmode="transparent"&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;ol start="1" style="border-width: initial; border-color: initial; "&gt;&lt;li style="border-width: initial; border-color: initial; line-height: 18px; "&gt;&lt;span style="border-width: initial; border-color: initial; "&gt;&lt;span style="border-width: initial; border-color: initial; "&gt;f&amp;nbsp;=&amp;nbsp;open(&lt;/span&gt;&lt;span style="border-width: initial; border-color: initial; "&gt;"bigFile.txt"&lt;/span&gt;&lt;span style="border-width: initial; border-color: initial; "&gt;,&amp;nbsp;&lt;/span&gt;&lt;span style="border-width: initial; border-color: initial; "&gt;"r"&lt;/span&gt;&lt;span style="border-width: initial; border-color: initial; "&gt;)&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;&lt;li style="border-width: initial; border-color: initial; line-height: 18px; "&gt;&lt;span style="border-width: initial; border-color: initial; "&gt;&lt;span style="border-width: initial; border-color: initial; "&gt;for&lt;/span&gt;&lt;span style="border-width: initial; border-color: initial; "&gt;&amp;nbsp;line&amp;nbsp;&lt;/span&gt;&lt;span style="border-width: initial; border-color: initial; "&gt;in&lt;/span&gt;&lt;span style="border-width: initial; border-color: initial; "&gt;&amp;nbsp;f:&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;&lt;li style="border-width: initial; border-color: initial; line-height: 18px; "&gt;&lt;span style="border-width: initial; border-color: initial; "&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="border-width: initial; border-color: initial; "&gt;pass&lt;/span&gt;&lt;span style="border-width: initial; border-color: initial; "&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="border-width: initial; border-color: initial; "&gt;#&amp;nbsp;do&amp;nbsp;something&amp;nbsp;here&lt;/span&gt;&lt;span style="border-width: initial; border-color: initial; "&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;&lt;li style="border-width: initial; border-color: initial; line-height: 18px; "&gt;&lt;span style="border-width: initial; border-color: initial; "&gt;f.close()&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/li&gt;&lt;/ol&gt;&lt;/div&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;很明显地，后一种写法更简洁，而且经过测试，效率似乎也略高一些，不过好像很少看见这样的写法。不知道这两种写法有什么区别。&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;hr style="width: 600px; " /&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;hr style="width: 1px; " /&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;刚刚看到PyDoc中的FileObject的next()说明&lt;br /&gt;-----------------------------------------&lt;br /&gt;next( )&lt;br /&gt;&lt;br /&gt;A file object is its own iterator, for example iter(f) returns f&lt;br /&gt;(unless f is closed). When a file is used as an iterator, typically in&lt;br /&gt;a for loop (for example, for line in f: print line), the next() method&lt;br /&gt;is called repeatedly. This method returns the next input line, or&lt;br /&gt;raises StopIteration when EOF is hit when the file is open for reading&lt;br /&gt;(behavior is undefined when the file is open for writing). In order to&lt;br /&gt;make a for loop the most efficient way of looping over the lines of a&lt;br /&gt;file (a very common operation), the next() method uses a hidden read-&lt;br /&gt;ahead buffer. As a consequence of using a read-ahead buffer, combining&lt;br /&gt;next() with other file methods (like readline()) does not work right.&lt;br /&gt;However, using seek() to reposition the file to an absolute position&lt;br /&gt;will flush the read-ahead buffer. New in version 2.3.&lt;/p&gt;&lt;/div&gt;&lt;/span&gt;&lt;img src="http://www.cnblogs.com/finallyliuyu/aggbug/2397763.html?type=1" width="1" height="1" alt=""/&gt;&lt;p&gt;&lt;a href="http://www.cnblogs.com/finallyliuyu/archive/2012/03/15/2397763.html" target="_blank"&gt;本文链接&lt;/a&gt;&lt;/p&gt;</content></entry><entry><id>http://www.cnblogs.com/finallyliuyu/archive/2012/03/15/2397487.html</id><title type="text">python语法测试</title><summary type="text">原组不能更新，但是元组作为字典值时可以更新。demo如下</summary><published>2012-03-15T01:45:00Z</published><updated>2012-03-15T01:45:00Z</updated><author><name>finallyly</name><uri>http://www.cnblogs.com/finallyliuyu/</uri></author><link rel="alternate" href="http://www.cnblogs.com/finallyliuyu/archive/2012/03/15/2397487.html"/><link rel="alternate" type="text/html" href="http://www.cnblogs.com/finallyliuyu/archive/2012/03/15/2397487.html"/><content type="html">&lt;p&gt;原组不能更新，但是元组作为字典值时可以更新。demo如下&lt;/p&gt;&lt;p&gt;&lt;img src="http://images.cnblogs.com/cnblogs_com/finallyliuyu/%E6%98%BE%E6%91%86%E5%9B%BE.JPG" width="498" height="174" alt="" /&gt;&amp;nbsp;&lt;/p&gt;&lt;img src="http://www.cnblogs.com/finallyliuyu/aggbug/2397487.html?type=1" width="1" height="1" alt=""/&gt;&lt;p&gt;&lt;a href="http://www.cnblogs.com/finallyliuyu/archive/2012/03/15/2397487.html" target="_blank"&gt;本文链接&lt;/a&gt;&lt;/p&gt;</content></entry><entry><id>http://www.cnblogs.com/finallyliuyu/archive/2012/03/14/2396702.html</id><title type="text">python使用带汉字的正则表达式</title><summary type="text">#!/usr/bin/python 2 # -*- coding: cp936 -*- 3 import sys; 4 import re; 5 ''' 6 原始文件，去重后文件，重复文件 7 ''' 8 if( __name__ == "__main__" ): 1 #!/usr/bin/python 2 # -*- coding: cp936 -*- 3 import sys; 4 import re; 5 ''' 6 原始文件，去重后文件，重复文件 7 ''' 8 if( </summary><published>2012-03-14T14:13:00Z</published><updated>2012-03-14T14:13:00Z</updated><author><name>finallyly</name><uri>http://www.cnblogs.com/finallyliuyu/</uri></author><link rel="alternate" href="http://www.cnblogs.com/finallyliuyu/archive/2012/03/14/2396702.html"/><link rel="alternate" type="text/html" href="http://www.cnblogs.com/finallyliuyu/archive/2012/03/14/2396702.html"/><content type="html">&lt;div&gt;#!/usr/bin/python&lt;/div&gt;&lt;div&gt;&amp;nbsp; 2 # -*- coding: cp936 -*-&amp;nbsp;&lt;/div&gt;&lt;div&gt;&amp;nbsp; 3 import sys;&lt;/div&gt;&lt;div&gt;&amp;nbsp; 4 import re;&lt;/div&gt;&lt;div&gt;&amp;nbsp; 5 '''&lt;/div&gt;&lt;div&gt;&amp;nbsp; 6 原始文件，去重后文件，重复文件&lt;/div&gt;&lt;div&gt;&amp;nbsp; 7 '''&lt;/div&gt;&lt;div&gt;&amp;nbsp; 8 if( __name__ == "__main__" ):&lt;/div&gt;&lt;div&gt;&amp;nbsp; 1 #!/usr/bin/python&lt;/div&gt;&lt;div&gt;&amp;nbsp; 2 # -*- coding: cp936 -*-&amp;nbsp;&lt;/div&gt;&lt;div&gt;&amp;nbsp; 3 import sys;&lt;/div&gt;&lt;div&gt;&amp;nbsp; 4 import re;&lt;/div&gt;&lt;div&gt;&amp;nbsp; 5 '''&lt;/div&gt;&lt;div&gt;&amp;nbsp; 6 原始文件，去重后文件，重复文件&lt;/div&gt;&lt;div&gt;&amp;nbsp; 7 '''&lt;/div&gt;&lt;div&gt;&amp;nbsp; 8 if( __name__ == "__main__" ):&lt;/div&gt;&lt;div&gt;&amp;nbsp; 9 &amp;nbsp; &amp;nbsp; fid_input = file(str(sys.argv[1]),'r');&lt;/div&gt;&lt;div&gt;&amp;nbsp;10 &amp;nbsp; &amp;nbsp; fid_pure=file(str(sys.argv[2]),'w');&lt;/div&gt;&lt;div&gt;&amp;nbsp;11 &amp;nbsp; &amp;nbsp; fid_assist=file(str(sys.argv[3]),'w');&lt;/div&gt;&lt;div&gt;&amp;nbsp;12 &amp;nbsp; &amp;nbsp; mydict={};&lt;/div&gt;&lt;div&gt;&amp;nbsp;13 &amp;nbsp; &amp;nbsp; phanzi=re.compile(u'[\u4e00-\u9fa5]');&lt;/div&gt;&lt;div&gt;&amp;nbsp;14 &amp;nbsp; &amp;nbsp; preturn=re.compile(u'(^\s+|\s+$)');#去掉首尾空白&lt;/div&gt;&lt;div&gt;&amp;nbsp;15 &amp;nbsp; &amp;nbsp; pfilter=re.compile(u'[&amp;#8221;&amp;#8220;（\(\)）]');#去掉无关字符&lt;/div&gt;&lt;div&gt;&amp;nbsp;16 &amp;nbsp; &amp;nbsp; for line in fid_input:&lt;/div&gt;&lt;div&gt;&amp;nbsp;17 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; uline=unicode(line,'gbk');&lt;/div&gt;&lt;div&gt;&amp;nbsp;18 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; candidates=phanzi.findall(uline);&lt;/div&gt;&lt;div&gt;&amp;nbsp;19 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; unewline=u'';&lt;/div&gt;&lt;div&gt;&amp;nbsp;20 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; for m in candidates:&lt;/div&gt;&lt;div&gt;&amp;nbsp;21 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; unewline=unewline+m;&lt;/div&gt;&lt;div&gt;&amp;nbsp;22 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; unewline=pfilter.sub('',unewline);&lt;/div&gt;&lt;div&gt;&amp;nbsp;23 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; unewline=preturn.sub('',unewline);&lt;/div&gt;&lt;div&gt;&amp;nbsp;24 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; newline=unewline.encode('gbk');&lt;/div&gt;&lt;div&gt;&amp;nbsp;25 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; fid_assist.write(newline);&lt;/div&gt;&lt;div&gt;&amp;nbsp;26 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; fid_assist.write('\n');&lt;/div&gt;&lt;div&gt;&amp;nbsp;27 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if(not mydict.has_key(newline)):&lt;/div&gt;&lt;div&gt;&amp;nbsp;28 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; mydict[newline]=1;&lt;/div&gt;&lt;div&gt;&amp;nbsp;29 &amp;nbsp; &amp;nbsp; for mykey in mydict.keys():&lt;/div&gt;&lt;div&gt;&amp;nbsp;30 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; fid_pure.write(mykey);&lt;/div&gt;&lt;div&gt;&amp;nbsp;31 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; fid_pure.write('\n');&lt;/div&gt;&lt;div&gt;&amp;nbsp;32 &amp;nbsp; &amp;nbsp; fid_pure.close();&lt;/div&gt;&lt;div&gt;&amp;nbsp;33 &amp;nbsp; &amp;nbsp; fid_input.close();&lt;/div&gt;&lt;div&gt;&amp;nbsp;34 &amp;nbsp; &amp;nbsp; fid_assist.close();&lt;/div&gt;&lt;div&gt;&amp;nbsp;35 &amp;nbsp; &amp;nbsp; print 'procedure %s finish!\n'%str( sys.argv[0] );&lt;/div&gt;&lt;img src="http://www.cnblogs.com/finallyliuyu/aggbug/2396702.html?type=1" width="1" height="1" alt=""/&gt;&lt;p&gt;&lt;a href="http://www.cnblogs.com/finallyliuyu/archive/2012/03/14/2396702.html" target="_blank"&gt;本文链接&lt;/a&gt;&lt;/p&gt;</content></entry><entry><id>http://www.cnblogs.com/finallyliuyu/archive/2012/03/08/2385842.html</id><title type="text">工程总结</title><summary type="text">数据路径尽量是绝对路径，且数据路径同一在一个代码文件中管理；代码路径尽量是相对路径，便于移植；代码目录与数据目录要分开，省得删除的时候乱七八糟的，自己写的通用脚本要注意备份。</summary><published>2012-03-08T13:32:00Z</published><updated>2012-03-08T13:32:00Z</updated><author><name>finallyly</name><uri>http://www.cnblogs.com/finallyliuyu/</uri></author><link rel="alternate" href="http://www.cnblogs.com/finallyliuyu/archive/2012/03/08/2385842.html"/><link rel="alternate" type="text/html" href="http://www.cnblogs.com/finallyliuyu/archive/2012/03/08/2385842.html"/><content type="html">&lt;span style="font-size: 36pt; "&gt;数据路径尽量是绝对路径，且数据路径同一在一个代码文件中管理；代码路径尽量是相对路径，便于移植；代码目录与数据目录要分开，省得删除的时候乱七八糟的，自己写的通用脚本要注意备份。&lt;/span&gt;&lt;img src="http://www.cnblogs.com/finallyliuyu/aggbug/2385842.html?type=1" width="1" height="1" alt=""/&gt;&lt;p&gt;&lt;a href="http://www.cnblogs.com/finallyliuyu/archive/2012/03/08/2385842.html" target="_blank"&gt;本文链接&lt;/a&gt;&lt;/p&gt;</content></entry><entry><id>http://www.cnblogs.com/finallyliuyu/archive/2012/03/04/2379289.html</id><title type="text">python完成文件按行拆分按列重组。</title><summary type="text">#!/usr/bin/pythonimport sys;import re;#-*- coding:cp936 -*-if(__name__=="__main__"): delim1='\t'; delim2=','; fid_input=file(str(sys.argv[1]),'r'); fid_output=file(str(sys.argv[2]),'w'); n=int(sys.argv[3]); p=re.compile('(^\s+|\s+$)'); amount_in=[]; </summary><published>2012-03-04T07:33:00Z</published><updated>2012-03-04T07:33:00Z</updated><author><name>finallyly</name><uri>http://www.cnblogs.com/finallyliuyu/</uri></author><link rel="alternate" href="http://www.cnblogs.com/finallyliuyu/archive/2012/03/04/2379289.html"/><link rel="alternate" type="text/html" href="http://www.cnblogs.com/finallyliuyu/archive/2012/03/04/2379289.html"/><content type="html">&lt;div&gt;#!/usr/bin/python&lt;/div&gt;&lt;div&gt;import sys;&lt;/div&gt;&lt;div&gt;import re;&lt;/div&gt;&lt;div&gt;#-*- coding:cp936 -*-&lt;/div&gt;&lt;div&gt;if(__name__=="__main__"):&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; delim1='\t';&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; delim2=',';&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; fid_input=file(str(sys.argv[1]),'r');&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; fid_output=file(str(sys.argv[2]),'w');&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; n=int(sys.argv[3]);&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; p=re.compile('(^\s+|\s+$)');&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; amount_in=[];&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; amount_total=[];&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; amount_entire=[];&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; lines=fid_input.readlines();&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; fid_input.close();&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; for tmp in lines:&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; line=p.sub('',tmp);&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; temps=line.split(delim1);&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; amount_in.append(temps[2]);&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; amount_total.append(temps[3]);&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; amount_entire.append(temps[4]);&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; data1=delim2.join(amount_in);&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; data2=delim2.join(amount_total);&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; data3=delim2.join(amount_entire);&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; str1="["+data1+"]";&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; str2="["+data2+"]";&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; str3="["+data3+"]";&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; fid_output.write(str1);&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; fid_output.write('\n');&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; fid_output.write(str2);&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; fid_output.write('\n');&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; fid_output.write(str3);&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; fid_output.write('\n');&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; print '%s has finished, congratulations!'%str(sys.argv[0]);&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/div&gt;&lt;div&gt;&lt;/div&gt;&lt;img src="http://www.cnblogs.com/finallyliuyu/aggbug/2379289.html?type=1" width="1" height="1" alt=""/&gt;&lt;p&gt;&lt;a href="http://www.cnblogs.com/finallyliuyu/archive/2012/03/04/2379289.html" target="_blank"&gt;本文链接&lt;/a&gt;&lt;/p&gt;</content></entry></feed>
