本篇将介绍python中sys, getopt模块处理命令行参数
如果想对python脚本传参数,python中对应的argc, argv(c语言的命令行参数)是什么呢?
需要模块:sys
参数个数:len(sys.argv)
脚本名: sys.argv[0]
参数1: sys.argv[1]
参数2: sys.argv[2]
test.py
1
import sys
2
print "脚本名:", sys.argv[0]
3
for i in range(1, len(sys.argv)):
4
print "参数", i, sys.argv[i]
>>>python test.py hello world
脚本名:test.py
参数 1 hello
参数 2 world
python中使用命令行选项:
例如我们需要一个convert.py脚本。它的作用是处理一个文件,并将处理后的结果输出到另一个文件中。
要求该脚本满足以下条件:
1.通过-i -o选项来区别参数是输入文件还是输出文件.
>>> python convert.py -i inputfile -o outputfile
2.当不知道convert.py需要哪些参数时,用-h打印出帮助信息
>>> python convert.py -h
getopt函数原形:
getopt.getopt(args, options[, long_options])
convert.py
01
import sys, geto ......
Python太火了,不学点都感觉自己不是学计算机的,今天看了个不错的《简明python教程》,很不错。不过在学习过程中,居然发现了一个Python的bug,
#!/usr/bin/python
#coding=UTF-8
class Person:
'''Represents a person.'''
population = 0
def __init__(self, name):
'''Initializes the person's data.'''
self.name = name
print '(Initializing %s)' % self.name
Person.population += 1
def __del__(self):
'''I am dying'''
print '%s syas bye.' % self.name
Person.population -= 1
if Person.population == 0:
print 'I am the last one.'
else:
print 'There are still %d people left.' % \
Person.population
def sayHi(self):
'''Greeting by the person.
Really, that's all it does'''
print 'Hi, my name is %s.' % self.name
def howMany(self):
'''Prints the current population'''
if Person.population == 1:
print "I am the only person here"
else:
print 'We have %d persons here.' % Person.population
luolei = Person('luolei')
luolei.sayHi()
luolei. ......
此例子在 Ruby Ruport实践—简单报表系统 及 Ruby Ruport实践—中文PDF报表之PRAWN 的基础上进行完善,添加了对报表参数的设计及实现。
一、创建数据表report_parameters
create table report_parameters
(report_parameter_id integer not null auto_increment,
report_execute_id integer not null,
parameter_name varchar(240),
parameter_value varchar(240),
primary key "report_parameter_id")
ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8
二、修改controllers/ReportExecutionsController.rb
将report_parameters的基本操作添加到report_executions界面
class ReportExecutionsController < ApplicationController
# GET /report_executions
# GET /report_executions.xml
Ruport::Formatter::Template.create(:simple) do |format|
eval("format.page = {:layout => :landscape}
format.grouping = {:style => :separated}
format.text = {:font_size => 20,:justification => :center}
format.table = {:font_size => 10,:heading_font_size => ......
ACCESS远程备份一直是个令人头疼的问题 看到一个不错的备份方法 分享下:
原文地址:http://www.cnblogs.com/catcat811/archive/2009/12/31/1637186.html
网站又关了~~~关得很突然,数据也来不及备份。因为公司有个仓库的系统在租用服务器上,如果停了就得重新点仓,那是很累人的事。最近网站时常关,真让人头痛。为了避免下次又被关拿不到数据,需要实现每天远程数据备份。可是仓库系统用的是ACCESS,每天去备份下来很累人,所以想用自动备份的方法。
方法很简单,先给数据库位置开个FTP,让远程机器自动连FTP把数据库下载,下载回来以后就可以进行移动或改名。windows下有个ftp的命令行程序,就可以实现FTP连接,而且它可以通过运行文件脚本的方式自动执行FTP指令,再配合WINDOWS的任务计划程序实现定时运行就可以。
ftp.txt内容如下
open www.example.com
用户名
密码
binary
get data.mdb
bye
exit
ftp.bat 内容如下
ftp -s:ftp.txt
两个文件放在同一个目录,之后用任务计划程序设定每天运行ftp.bat就可以了。数据库文件会放在ftp.bat的所在目录。 ......
新建表tb
ID cc xm
1 a hello
2 dd text,doc
3 dd text,jpg
4 aa mo
新建模块,加入代码
Function test(a As String, d As String) As Boolean
test = False
s = Split(a, ",")
For Each p In s
If InStr(1, p, d, vbTextCompare) > 0 Then
test = True
Exit For
End If
Next
End Function
新建查询,查询包含jpg字符串的行
SELECT *
from tb
WHERE (((test([xm],"jpg"))<>False));
运行结果
ID cc xm
3 dd text,jpg ......
微软的SQL SERVER提供了两种索引:聚集索引(clustered index,也称聚类索引、簇集索引)和非聚集索引(nonclustered index,也称非聚类索引、非簇集索引)……
(一)深入浅出理解索引结构
实际上,您可以把索引理解为一种特殊的目录。微软的SQL SERVER提供了两种索引:聚集索引(clustered index,也称聚类索引、簇集索引)和非聚集索引(nonclustered index,也称非聚类索引、非簇集索引)。下面,我们举例来说明一下聚集索引和非聚集索引的区别:
其实,我们的汉语字典的正文本身就是一个聚集索引。比如,我们要查“安”字,就会很自然地翻开字典的前几页,因为“安”的拼音是“an”,而按照拼音 排序汉字的字典是以英文字母“a”开头并以“z”结尾的,那么“安”字就自然地排在字典的前部。如果您翻完了所有以“a”开头的部分仍然找不到这个字,那 么就说明您的字典中没有这个字;同样的,如果查“张”字,那您也会将您的字典翻到最后部分,因为“张”的拼音是“zhang”。也就是说,字典的正文部分 本身就是一个目录,您不需要再去查其他目录来找到您需要找的 ......