﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>C++博客-★Snowhill ★-文章分类-python</title><link>http://www.cppblog.com/snowhill/category/20543.html</link><description>&lt;font color=#5555aa &gt;&lt;b&gt; 颠沛必于是，造次必于是！&lt;/b&gt;&lt;/font&gt;</description><language>zh-cn</language><lastBuildDate>Mon, 15 Jul 2013 13:04:18 GMT</lastBuildDate><pubDate>Mon, 15 Jul 2013 13:04:18 GMT</pubDate><ttl>60</ttl><item><title>python import os</title><link>http://www.cppblog.com/snowhill/articles/200826.html</link><dc:creator>snowhill</dc:creator><author>snowhill</author><pubDate>Thu, 06 Jun 2013 03:59:00 GMT</pubDate><guid>http://www.cppblog.com/snowhill/articles/200826.html</guid><wfw:comment>http://www.cppblog.com/snowhill/comments/200826.html</wfw:comment><comments>http://www.cppblog.com/snowhill/articles/200826.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/snowhill/comments/commentRss/200826.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/snowhill/services/trackbacks/200826.html</trackback:ping><description><![CDATA[OS相关<br />import os<br />可以用help(os);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; dir(os)查看<br /><br />
<p>os.sep 可以取代操作系统特定的路径分割符。 <br />os.name字符串指示你正在使用的平台。比如对于Windows，它是'nt'，而对于Linux/Unix用户，它是'posix'。 <br />os.getcwd()函数得到当前工作目录，即当前Python脚本工作的目录路径。 <br />os.getenv()和os.putenv()函数分别用来读取和设置环境变量。 <br />os.listdir()返回指定目录下的所有文件和目录名。 <br />os.remove()函数用来删除一个文件。 <br />os.system()函数用来运行shell命令。</p>
<p>os.linesep字符串给出当前平台使用的行终止符。例如，Windows使用'\r\n'，Linux使用'\n'而Mac使用'\r'。</p>
<p>os.path.split()函数返回一个路径的目录名和文件名。</p>
<p>os.path.isfile()和os.path.isdir()函数分别检验给出的路径是一个文件还是目录。</p>
<p>os.path.existe()函数用来检验给出的路径是否真地存在</p>
<p>os和os.path模块<br />os.listdir(dirname)：列出dirname下的目录和文件<br />os.getcwd()：获得当前工作目录<br />os.curdir:返回但前目录（'.')<br />os.chdir(dirname):改变工作目录到dirname</p>
<p>os.path.isdir(name):判断name是不是一个目录，name不是目录就返回false<br />os.path.isfile(name):判断name是不是一个文件，不存在name也返回false<br />os.path.exists(name):判断是否存在文件或目录name<br />os.path.getsize(name):获得文件大小，如果name是目录返回0L<br />os.path.abspath(name):获得绝对路径<br />os.path.normpath(path):规范path字符串形式<br />os.path.split(name):分割文件名与目录（事实上，如果你完全使用目录，它也会将最后一个目录作为文件名而分离，同时它不会判断文件或目录是否存在）<br />os.path.splitext():分离文件名与扩展名<br />os.path.join(path,name):连接目录与文件名或目录<br />os.path.basename(path):返回文件名<br />os.path.dirname(path):返回文件路径</p>eg:<br />if os.path.isdir("/tmp"):<br />...&nbsp;&nbsp;&nbsp;&nbsp; print "/tmp is a directory"<br />... else:<br />...&nbsp;&nbsp;&nbsp;&nbsp; print "/tmp is not " <img src ="http://www.cppblog.com/snowhill/aggbug/200826.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/snowhill/" target="_blank">snowhill</a> 2013-06-06 11:59 <a href="http://www.cppblog.com/snowhill/articles/200826.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>python连接oracle</title><link>http://www.cppblog.com/snowhill/articles/200825.html</link><dc:creator>snowhill</dc:creator><author>snowhill</author><pubDate>Thu, 06 Jun 2013 03:21:00 GMT</pubDate><guid>http://www.cppblog.com/snowhill/articles/200825.html</guid><wfw:comment>http://www.cppblog.com/snowhill/comments/200825.html</wfw:comment><comments>http://www.cppblog.com/snowhill/articles/200825.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/snowhill/comments/commentRss/200825.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/snowhill/services/trackbacks/200825.html</trackback:ping><description><![CDATA[一　安装cx_Oracle包<br />下载地址<br /><a href="http://www.python.net/crew/atuining/cx_Oracle/">http://www.python.net/crew/atuining/cx_Oracle/</a><br /><a href="http://cx-oracle.sourceforge.net/">http://cx-oracle.sourceforge.net/</a><br />二　设置环境变量<br />export LD_LIBRARY_PATH=/opt/oracle/product/11.2.0.3/dbhome_1/lib/<br />三　测试<br />#vim 1.py<br />import cx_Oracle<br />conn=cx_Oracle.connect("scott","oracle","demo189")<br />cursor=conn.cursor()<br />cursor.execute("""select empno,ename,job from scott.emp""")<br />for empno,ename,job in cursor :<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print "values:",empno,ename,job<br /><br />#chmod +x 1.py<br />#python 1.py<br />如果成功表未环境配成功了 <img src ="http://www.cppblog.com/snowhill/aggbug/200825.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/snowhill/" target="_blank">snowhill</a> 2013-06-06 11:21 <a href="http://www.cppblog.com/snowhill/articles/200825.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>