摘要:__all__ 用于限制模块的导入from module import *若 module 中定义了__all__ 属性,则只有 __all__ 中指定的内容被导入。否则导入 module 中的所有内容。
阅读全文
摘要:Python 有两个内建的模块用于处理命令行参数:一个是 getopt,《Deep in python》一书中也有提到,只能简单处理 命令行参数;另一个是 optparse,它功能强大,而且易于使用,可以方便地生成标准的、符合Unix/Posix 规范的命令行说明。示例下面是一个使用 optparse 的简单示例:Python代码fromoptparseimportOptionParser[...]parser=OptionParser()parser.add_option("-f","--file",dest="filename",
阅读全文
摘要:题目来自 hacker.org 的Challenge 'Didactic Text' [Crypto]分析给出的文章,找出暗语。Four score and seven years ago our fathers brought forth on this continent, a new nation, conceived in Liberty, and dedicated to the proposition that all the men are created equal.Now we are engaged in a great civil war, testing
阅读全文
摘要:题目来自 hacker.org 的Challenge 'Didactic Bytes' [Crypto]给出一个01串组成的密码,求出破译后的单词01110101 01110011 01100101 00100000 01110111 01100101 01100100 01101110 01100101 01110011 01100100 01100001 01111001 00100000 01100110 01101111 01110010 00100000 01110100 01101000 01100101 00100000 01100001 01101110 011
阅读全文
摘要:题目来自 hacker.org 中的Challenge '3280' [Coding] 。要求找出RFC 3280 中出现次数最多的长度为9的单词。将 RFC 3280 的文本并保存到本地后用如下代码进行处理。----import retext = open("in.txt",'r').read()words = re.split('[^a-zA-Z]',text) di = {}for word in words: if len(word)==9: di.setdefault(word,0) di[word]+=1res =
阅读全文
摘要:通过在 Codeforces 上用 Python 过题来增加对 python 的理解。------------------------------------CodeForces 208A--s = raw_input()a = s.split('WUB')for t in a: if t!='': print t,--1、 raw_input()读取一行输入作为字符串,一般配合split()作为读取数据2、str.split(str="", num=string.count(str)) 该方法返回字符串中的所有单词的列表,使用str作为分隔
阅读全文