python
坚持到底cw
奋斗青年
展开
-
shell和python中互调
一.在shell脚本中调用python脚本,执行结果给予赋值#!/bin/bash#在shell中掉用python脚本执行结果赋值给keykey=`python /usr/local/pythonstudy/print.py`a=$key#对key进行过滤b=`echo $key | awk -F\? '{print $3}'`echo $b原创 2014-05-16 10:27:34 · 1500 阅读 · 0 评论 -
makefile write
#!/usr/bin/python'makeTextFile.py--create text file'import osls = os.linesep#get filenamewhile True: fname = raw_input("file name is :") if os.path.exists(fname):原创 2014-05-13 17:37:36 · 515 阅读 · 0 评论 -
os os.path
#! /usr/bin/python#coding=utf-8import osusrdir = '/usr/local'os.chdir(usrdir)cwd = os.getcwd()print'***当前目录为: ',cwdprint '创建文件'os.mkdir('example')os.chdir('example')cwd=os.getcwd()print '原创 2014-05-13 17:38:28 · 757 阅读 · 0 评论 -
queue stack
#!/usr/bin/pythonstack = []def pushit(): stack.append(raw_input('enter new string: ').strip())def popit(): if len(stack)==0: print 'cannot pop from an empty stack' else:原创 2014-05-13 17:40:35 · 476 阅读 · 0 评论 -
url
#!/usr/bin/python#coding=utf-8import urllibprint '将赶集首页的html抓取到本地,保存在g.txt文件中,同时显示下载的进度。'def fun(blocknum , blocksize ,totalsize): percent = 100.0*blocknum*blocksize/totalsize if percent原创 2014-05-13 17:43:14 · 518 阅读 · 0 评论 -
usrpasswd
#!/usr/bin/pythondb = {}def newuser(): prompt='login desired: ' while True: name = raw_input(prompt) if db.has_key(name): prompt='name take, try another: '原创 2014-05-13 17:41:55 · 523 阅读 · 0 评论 -
python学习
一.python的类型:1.数字:int,long,float,complex(复数)2.字符串:两种取值顺序:从左到右索引默认0开始的,最大范围是字符串长度少1从右到左索引默认-1开始的,最大范围是字符串开头加号(+)是字符串连接运算符,星号(*)是重复操作print str[2:5](左取又不取)print a[-5:-2]3.列表:列表用[ ]原创 2014-12-21 15:42:49 · 1037 阅读 · 0 评论