<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Flib &#187; Code</title>
	<atom:link href="http://blog.flib.me/category/code/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.flib.me</link>
	<description>flex&#039;s library</description>
	<lastBuildDate>Thu, 15 Dec 2011 11:05:03 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>python全局变量与命名空间</title>
		<link>http://blog.flib.me/2010/06/10/python%e5%85%a8%e5%b1%80%e5%8f%98%e9%87%8f%e4%b8%8e%e5%91%bd%e5%90%8d%e7%a9%ba%e9%97%b4/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=python%25e5%2585%25a8%25e5%25b1%2580%25e5%258f%2598%25e9%2587%258f%25e4%25b8%258e%25e5%2591%25bd%25e5%2590%258d%25e7%25a9%25ba%25e9%2597%25b4</link>
		<comments>http://blog.flib.me/2010/06/10/python%e5%85%a8%e5%b1%80%e5%8f%98%e9%87%8f%e4%b8%8e%e5%91%bd%e5%90%8d%e7%a9%ba%e9%97%b4/#comments</comments>
		<pubDate>Thu, 10 Jun 2010 14:22:58 +0000</pubDate>
		<dc:creator>flex</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[global]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[全局变量]]></category>

		<guid isPermaLink="false">http://blog.flib.me/?p=38191</guid>
		<description><![CDATA[[python] KEY_WORD = &#34;A&#34; def temp(): print KEY_WORD KEY_WORD = &#34;B&#34; [/python] 这段代码运行会提示变量KEY_WORD在定义前使用。原因是因为一旦在函数中修改全局变量，则python会将全局变量认成局部变量，在函数的命名空间内寻找其定义。如果要修改全局变量，要在函数内使用global关键字进行声明。如下： [python] KEY_WORD = &#34;A&#34; def temp(): global KEY_WORD print KEY_WORD KEY_WORD = &#34;B&#34; [/python] 当然，我个人更倾向将全局变量只作为常量。]]></description>
			<content:encoded><![CDATA[<p>[python]<br />
KEY_WORD = &quot;A&quot;</p>
<p>def temp():<br />
    print KEY_WORD<br />
    KEY_WORD = &quot;B&quot;<br />
[/python]</p>
<p>这段代码运行会提示变量KEY_WORD在定义前使用。原因是因为一旦在函数中修改全局变量，则python会将全局变量认成局部变量，在函数的命名空间内寻找其定义。如果要修改全局变量，要在函数内使用global关键字进行声明。如下：</p>
<p>[python]<br />
KEY_WORD = &quot;A&quot;</p>
<p>def temp():<br />
    global KEY_WORD<br />
    print KEY_WORD<br />
    KEY_WORD = &quot;B&quot;<br />
[/python]</p>
<p>当然，我个人更倾向将全局变量只作为常量。</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.flib.me/2010/06/10/python%e5%85%a8%e5%b1%80%e5%8f%98%e9%87%8f%e4%b8%8e%e5%91%bd%e5%90%8d%e7%a9%ba%e9%97%b4/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>shell中的$@与通配符</title>
		<link>http://blog.flib.me/2010/05/20/shell%e4%b8%ad%e7%9a%84%e4%b8%8e%e9%80%9a%e9%85%8d%e7%ac%a6/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=shell%25e4%25b8%25ad%25e7%259a%2584%25e4%25b8%258e%25e9%2580%259a%25e9%2585%258d%25e7%25ac%25a6</link>
		<comments>http://blog.flib.me/2010/05/20/shell%e4%b8%ad%e7%9a%84%e4%b8%8e%e9%80%9a%e9%85%8d%e7%ac%a6/#comments</comments>
		<pubDate>Thu, 20 May 2010 11:22:00 +0000</pubDate>
		<dc:creator>flex</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[$@]]></category>
		<category><![CDATA[引号]]></category>
		<category><![CDATA[通配符]]></category>

		<guid isPermaLink="false">http://blog.flib.me/?p=38185</guid>
		<description><![CDATA[$@在shell中表示所有参数，与$*不同的是，$@中的每个参数都相当于被双引号包含的独立字符串。 然而如果使用通配符传递文件名的时候，如果文件名中包含空格，$@会将包含空格的文件名理解成数个文件，这时只要使用引号将通配符引起再传递或者使用”$@”就可以了。]]></description>
			<content:encoded><![CDATA[<p>$@在shell中表示所有参数，与$*不同的是，$@中的每个参数都相当于被双引号包含的独立字符串。</p>
<p>然而如果使用通配符传递文件名的时候，如果文件名中包含空格，$@会将包含空格的文件名理解成数个文件，这时只要使用引号将通配符引起再传递或者使用”$@”就可以了。</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.flib.me/2010/05/20/shell%e4%b8%ad%e7%9a%84%e4%b8%8e%e9%80%9a%e9%85%8d%e7%ac%a6/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Shell编程中的光标控制</title>
		<link>http://blog.flib.me/2007/11/17/shell%e7%bc%96%e7%a8%8b%e4%b8%ad%e7%9a%84%e5%85%89%e6%a0%87%e6%8e%a7%e5%88%b6/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=shell%25e7%25bc%2596%25e7%25a8%258b%25e4%25b8%25ad%25e7%259a%2584%25e5%2585%2589%25e6%25a0%2587%25e6%258e%25a7%25e5%2588%25b6</link>
		<comments>http://blog.flib.me/2007/11/17/shell%e7%bc%96%e7%a8%8b%e4%b8%ad%e7%9a%84%e5%85%89%e6%a0%87%e6%8e%a7%e5%88%b6/#comments</comments>
		<pubDate>Sat, 17 Nov 2007 00:03:00 +0000</pubDate>
		<dc:creator>flex</dc:creator>
				<category><![CDATA[Code]]></category>

		<guid isPermaLink="false">http://frostynova.yo2.cn/articles/shell%e7%bc%96%e7%a8%8b%e4%b8%ad%e7%9a%84%e5%85%89%e6%a0%87%e6%8e%a7%e5%88%b6.html</guid>
		<description><![CDATA[这两天做选修课实验，有一个项目要求在屏幕中英显示信息，在网上搜了一下，发现没有太好的解决方法，唯一比较精确的是利用控制字符： 例: [shell] echo -ne &#34;\33[20;40H&#34; [/shell] #把光标移到20行40列 不过这样做有一个问题就是终端的行列数是不定的，没办法做到相对控制。今天在看Shell命令的时候发现了tput命令。tput -cols可以得到当前终端总列数，tput -lines可以得到总行数（不过奇怪的是man手册里没有lines这个参数，害得我开始还以为得不到行数），这样再结合echo就行了，如显示在屏幕右下角可以写成： [shell] #!/bin/bash lines=`tput lines` cols=`tput cols` echo -ne &#34;\33[$lines;${cols}H&#34; [/shell]]]></description>
			<content:encoded><![CDATA[<p>这两天做选修课实验，有一个项目要求在屏幕中英显示信息，在网上搜了一下，发现没有太好的解决方法，唯一比较精确的是利用控制字符：</p>
<p>例:</p>
<p>[shell]<br />
echo -ne &quot;\33[20;40H&quot;<br />
[/shell]</p>
<p>#把光标移到20行40列</p>
<p>不过这样做有一个问题就是终端的行列数是不定的，没办法做到相对控制。今天在看Shell命令的时候发现了tput命令。tput -cols可以得到当前终端总列数，tput -lines可以得到总行数（不过奇怪的是man手册里没有lines这个参数，害得我开始还以为得不到行数），这样再结合echo就行了，如显示在屏幕右下角可以写成：</p>
<pre lang="bash">[shell]
#!/bin/bash
lines=`tput lines`
cols=`tput cols`
echo -ne &quot;\33[$lines;${cols}H&quot;
[/shell]
</pre>
]]></content:encoded>
			<wfw:commentRss>http://blog.flib.me/2007/11/17/shell%e7%bc%96%e7%a8%8b%e4%b8%ad%e7%9a%84%e5%85%89%e6%a0%87%e6%8e%a7%e5%88%b6/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>shell脚本中配置文件的读取</title>
		<link>http://blog.flib.me/2007/11/15/shell%e8%84%9a%e6%9c%ac%e4%b8%ad%e9%85%8d%e7%bd%ae%e6%96%87%e4%bb%b6%e7%9a%84%e8%af%bb%e5%8f%96/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=shell%25e8%2584%259a%25e6%259c%25ac%25e4%25b8%25ad%25e9%2585%258d%25e7%25bd%25ae%25e6%2596%2587%25e4%25bb%25b6%25e7%259a%2584%25e8%25af%25bb%25e5%258f%2596</link>
		<comments>http://blog.flib.me/2007/11/15/shell%e8%84%9a%e6%9c%ac%e4%b8%ad%e9%85%8d%e7%bd%ae%e6%96%87%e4%bb%b6%e7%9a%84%e8%af%bb%e5%8f%96/#comments</comments>
		<pubDate>Wed, 14 Nov 2007 23:00:00 +0000</pubDate>
		<dc:creator>flex</dc:creator>
				<category><![CDATA[Code]]></category>

		<guid isPermaLink="false">http://frostynova.yo2.cn/articles/shell%e8%84%9a%e6%9c%ac%e4%b8%ad%e9%85%8d%e7%bd%ae%e6%96%87%e4%bb%b6%e7%9a%84%e8%af%bb%e5%8f%96.html</guid>
		<description><![CDATA[要做一个日志管理的shell脚本，希望做的通用一些，所以需要读取配置文件。在询问达人和网上搜索后，找到如下两种方法： 1.使用awk和正则表达式来匹配配置文件 2.将配置文件也写成脚本，在执行脚本中用source来载入 感觉上呢，第一种限制下，配置文件可以写的很灵活，但是稍稍麻烦一些；第二种则很简单，但受限制较多。]]></description>
			<content:encoded><![CDATA[<div>
<p>要做一个日志管理的shell脚本，希望做的通用一些，所以需要读取配置文件。在询问达人和网上搜索后，找到如下两种方法：</p>
<p>1.使用awk和正则表达式来匹配配置文件</p>
<p>2.将配置文件也写成脚本，在执行脚本中用source来载入</p>
<p>感觉上呢，第一种限制下，配置文件可以写的很灵活，但是稍稍麻烦一些；第二种则很简单，但受限制较多。</p>
</div>
]]></content:encoded>
			<wfw:commentRss>http://blog.flib.me/2007/11/15/shell%e8%84%9a%e6%9c%ac%e4%b8%ad%e9%85%8d%e7%bd%ae%e6%96%87%e4%bb%b6%e7%9a%84%e8%af%bb%e5%8f%96/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

