Python入门
来源:互联网 发布:软件项目经理工资待遇 编辑:程序博客网 时间:2024/04/28 18:02
作为一个javaer,脚本语言必须会几个才行,方便自己。在这里我就分享一下我的python入门学习经历。还有一个小例子供参考。
一、环境搭建。
工欲善其事必先利其器,环境是必备的。在这里我们就选择最常用的Eclipse+ PyDev的方式。
下载python,Python2orPython3自己选择。官网上的介绍很详细。在这里我们就用python2。
下载PyDev,可采用link的方式安装,也可直接在线安装。
Eclipse设置
二、实例学习
Python的入门教程很多,喜欢step by step方式的同学可以上网搜索学习。本人不太适应这种方式,所以就不赘述了。
解决问题是学习的动力,也是我比较喜欢的一种学习方式。通过自己的工具来解决工作中遇到的问题是一种享受。下面提供两个小例子.
Example1-缓存清理
在部署经常需要清理缓存,所以我就想找一个工具来清理缓存,刚好又对python感兴趣。写了第一个python工具,很简单。
import os
cacheDir = 'C:\\Oracle\\user_projects\\domains\\testprojects\\servers\\AdminServer\\cache';
tmpDir = "C:\\Oracle\\user_projects\\domains\\testprojects\\servers\\AdminServer\\tmp";
logDir = "C:\\Oracle\\user_projects\\domains\\testprojects\\servers\\AdminServer\\logs";
os.system('rd /S /Q ' + logDir);
os.system('rd /S /Q ' + tmpDir);
os.system('rd /S /Q ' + cacheDir);
Example2-数据统计
在后来的工作中,又经常性遇到需要统计文件行数和多个文件总行数的要求。所以就又自己准备了一个小工具,帮助自己统计数据。
import os
from dircache import listdir
def getFileList(p):
p = str(p)
a = listdir(p)
sumAll = 0
for x in a:
filepath = p + "/" +x
if os.path.isfile(filepath):
lineCount =len(open(filepath).readlines())
sumAll = sumAll + lineCount
content = x + ":" +str(lineCount)
print content
return sumAll
printgetFileList("E:/compare")
三、结语
大致就这么多吧。Python是非常强大的。大家可以一起学习交流,开发一些小工具。学以致用。
- Python入门
- python入门
- Python入门
- Python入门
- Python入门
- Python入门
- python入门
- Python入门
- Python 入门
- Python入门
- python入门
- Python入门
- python入门
- python入门
- Python入门
- python 入门
- python入门
- python入门
- 使用Intent启动组件
- 正则表达式的使用
- 黑马程序员——————————字符串和基本数据类型对象包装类
- 周世黑鸭---面向全球招商
- 【第一次】创建github repo过程
- Python入门
- Windows实现Oracle数据的备份
- lua学习之路(一)
- 针对已经感染该恶意木马程序变种的计算机用户
- IPv4地址空间,开始使用全球IPv4地址池
- leetcode: Combination Sum II
- Redis复习笔记2—Redis的数据类型
- 有码农变工程师
- ——“钱规则