- 博客(43)
- 资源 (10)
- 收藏
- 关注
原创 【Python】Learn Python the hard way, ex40 模块,类和对象,这个解释比较容易理解
#coding:utf-8'''理解类和模块Python是一种面向对象编程(OOP)语言。这个说法的意思是,Python里边有一种叫做类(class)的结构,通过它可以用一种特殊的方法构造软件。通过使用类,可以让程序架构更为整齐,使用起来也更加干净 -- 至少理论上应该是这样的。首先,使用字典来帮助理解模块比如,定义以下一个字典mystuff = {'apple': "I AM
2015-10-17 17:38:18 1507
原创 【Python】 2种实现文件复制的方法
#coding:utf-8# 方法1:使用read()和write()模拟实现文件拷贝# 创建文件hello.txtsrc = file("hello.txt", "w")li = ["Hello world \n", "Hello China \n"]src.writelines(li)src.close()#把hello.txt 拷贝到hello2.txtsrc =
2015-10-18 13:36:33 13806
原创 【Python】三种遍历文件目录的方法
#coding:utf-8# 方法1:递归遍历目录import osdef visitDir(path): li = os.listdir(path) for p in li: pathname = os.path.join(path,p) if not os.path.isfile(pathname): #判断路径是否为文件,如果不
2015-10-18 13:14:13 5014
翻译 【Python】Learn Python the hard way, ex47 自动化测试,环境变量设置
class Room(object): def __init__(self, name, description): self.name = name self.description = description self.paths = {} def go(self, direction):
2015-10-18 10:25:59 1739
原创 【Python】Learn Python the hard way, ex46 项目骨架搭建练习
一个项目由多个py模块,类文件构成,在项目建立时,需要搭好架子本例子给出了一个很好的模板框架,供后续复制和直接使用1,首先,建立以下文件夹和py文件(其中NAME就是将来自己的项目名称)bogon:~ myRMBP$ mkdir projectsbogon:~ myRMBP$ cd projectsbogon:projects myRMBP$ mkdir skeletonb
2015-10-17 23:42:36 3276
原创 【Python】pip - 安装第三方包的神器
使用Python,肯定希望使用大量成熟的第三方包,从而快速用到自己的项目。还在一个个寻找,手动下载吗?pip就是这样一个神器,自动搜索、下载和安装第三方包:1,首先请安装pip自己,下载地址(也可以通过附件下载):http://www.pip-installer.org/en/latest/installing.html#python-os-support
2015-10-17 22:57:22 34658
翻译 【Python】Learn Python the hard way, ex42 对、类及从属关系
# Animal is-a object (yes, sort of confusing) look at the extra creditclass Animal(object): pass# is-aclass Dog(Animal): def __init__(self, name): ## has-a self.name = name
2015-10-17 21:58:15 1696
原创 【Python】Learn Python the hard way, ex41 面向对象术语练习
# coding:utf-8# 导入模块import randomfrom urllib import urlopenimport sys# 定义一个变量,字符串内容为一个urlWORD_URL = "http://learncodethehardway.org/words.txt"# 定义一个空列表WORDS = []# 定义一个字符串常量,内容为多个字符串PHRASE
2015-10-17 21:27:19 2012 1
原创 【Python】Learn Python the hard way, ex39 字典操作
# create a mapping of state to abbreviationstates = { 'Oregon': 'OR', 'Florida': 'FL', 'California': 'CA', 'New York': 'NY', 'Michigan': 'MI'}# create a basic set of states and
2015-10-14 22:55:42 736
原创 【Python】Learn Python the hard way, ex38 列表操作
ten_things = "Apples Oranges Crows Telephone Light Sugar"print "Wait there's not 10 things in that list, let's fix that."stuff = ten_things.split(' ')more_stuff = ["Day", "Night", "Song", "Frisb
2015-10-14 22:24:16 1116
翻译 【Python】if语句使用规则
Rules for If-StatementsEvery if-statement must have an else.If this else should never run because it doesn't make sense, then you must use a die function in the else that prints out an error m
2015-10-11 21:45:37 2826
原创 【Python】Learn Python the hard way, ex35 通过一个简单游戏,练习循环和分支语句
from sys import exitdef gold_room(): print "This room is full of gold. How much do you take?" next = raw_input("> ") if "0" in next or "1" in next: how_much = int(next)
2015-10-11 21:31:20 1404
原创 【Python】Learn Python the hard way, ex33 while循环
i = 0numbers = []while i < 6: print "At the top i is %d" % i numbers.append(i) i += 1 print "Numbers now: ", numbers print "At the bottom i is %d" % iprint "The numbers: "fo
2015-10-11 21:03:52 788
原创 【Python】Learn Python the hard way, ex32 for循环
the_count = [1, 2, 3, 4, 5]fruits = ['apples', 'oranges', 'pears', 'apricots']change = [1, 'pennies', 2, 'dimes', 3, 'quarters']# this first kind of for-loop goes through a listfor number in the_
2015-10-11 20:55:52 823
原创 【Python】Learn Python the hard way, ex29 if语句
people = 20cats = 30dogs = 15if people < cats: print "Too many cats! The world is doomed!"if people > cats: print "Not many cats! The world is saved!" if people < dogs: print "T
2015-10-11 20:35:26 499
原创 【Python】Learn Python the hard way, ex26 修改代码错误
#coding:utf-8#修改后的代码如下import ex25def break_words(stuff): """This function will break up words for us.""" words = stuff.split(' ') return wordsdef sort_words(words): """Sorts the
2015-10-11 20:07:55 925
原创 【Python】Learn Python the hard way, ex25 函数综合练习
def break_words(stuff): """This function will break up words for us.""" words = stuff.split(" ") return words def sort_words(words): """Sorts the words.""" return sorted(words
2015-10-11 19:33:11 711
原创 【Python】Learn Python the hard way, ex24 函数综合练习
#coding:utf-8print "Let's practice everything."print "You\'d need to konw \'bout escapes with \\ that do \n newlines and \t tabs."poem = '''\tThe lovely worldwith logic so firmly plantedcannot
2015-10-11 18:02:40 813
原创 【Python】Learn Python the hard way, ex21 函数返回值return
def add(a, b): print "ADDING %d + %d" % (a, b) return a + b def subtract(a, b): print "SUBTRACTING %d - %d" % (a, b) return a - b def multiply(a, b): print "MULTIPLYING %
2015-10-11 17:30:16 554
原创 【Python】Learn Python the hard way, ex20 用函数读文件readline
from sys import argvscript, input_file = argvdef print_all(f): print f.read() def rewind(f): f.seek(0) def print_a_line(line_count, f): print line_count, f.readline() cu
2015-10-11 17:09:34 588
原创 【Python】Learn Python the hard way, ex19 函数和变量
We can just give the function numbers directly:You have 20 cheeses!You have 30 boxes of crackers!Man that's enough for a party!Get a blanket. OR, we can use variables from our script:You have 1
2015-10-11 16:53:47 485
原创 【Python】Learn Python the hard way, ex18 def函数
# this one is like your scripts with argvdef print_two(*args): arg1, arg2 = args print "arg1: %r ,arg2: %r" % (arg1, arg2)# ok, that *args is actually pointless, we can just do thisdef pri
2015-10-11 16:38:43 541
原创 【Python】Learn Python the hard way, ex17 文件复制
from sys import argvfrom os.path import existsscript, from_file, to_file = argvprint "Copying from %s to %s " % (from_file, to_file)# we could do these two on one line too, how?in_file = open(
2015-10-08 21:58:21 735
原创 【Python】Learn Python the hard way, ex16 读写文件
# coding:utf-8#方法1'''from sys import argvscript, filename = argvprint "We're going to erase %r." % filenameprint "If you don't want that, hit CTRL-C(^C)."print "If you do want that, hit RETUR
2015-10-08 21:30:48 610
原创 【Python】Learn Python the hard way, ex15 读取文件
from sys import argvscript, filename = argvtxt = open(filename)print "Here's your file %r:" % filenameprint txt.read()print "Type the filename again:"file_again = raw_input("> ")txt_again
2015-10-07 15:09:20 790
原创 【Python】Learn Python the hard way, ex14 argv参数传值
from sys import argvscript, user_name = argvprompt = '>'print "Hi %s, I'm the %s script." % (user_name, script)print "I'd like to ask you a few questions."print "Do you like me %s?" % user_name
2015-10-07 14:54:12 487
原创 【Python】Learn Python the hard way, ex13 传递参数
from sys import argvscript, first, second, third = argvprint "The script is called:", scriptprint "Your first variable is:", firstprint "Your second variable is:", secondprint "Your third varia
2015-10-07 11:21:29 743
原创 【Python】Learn Python the hard way, ex12 raw_input 提示别人
age = raw_input("How old are you? ")height = raw_input("How tall are you? ")weight = raw_input("How much do you weigh? ")print "So, you're %r old, %r tall and %r heavy." %( age, height, weight
2015-10-07 11:06:53 564
原创 【Python】Learn Python the hard way, ex11 raw_input
print "How old are you?"age = raw_input()print "How tall are you?",height = raw_input()print "How much do you weigh?"weight = raw_input()print "So, you're %r old, %r tall and %r heavy.
2015-10-07 10:56:09 532
原创 【Python】Learn Python the hard way, ex10 转义字符
# coding: utf-8# 转义字符 escape sequencetabby_cat = "\tI'm tabbed in."persian_cat = "I'm split\non a line."backslash_cat = "I'm \\a \\ cat."fat_cat = """I'll do a list:\t* Cat food\t* Fishies\t
2015-10-07 10:28:16 571
原创 【Python】Learn Python the hard way, ex9 换行符,打印多行字符
# Here's some new stange stuff, remember type it exactly.days = "Mon Tue Wed Thu Fri Sat Sun"months = "Jan\nFeb\nMar\nApr\nMay\nJun\nJul\nAug"print "Here are the days: ", daysprint "Here are the
2015-10-07 10:09:30 966
原创 【Python】Learn Python the hard way, ex8 格式化字符串
formatter = "%r %r %r %r"print formatter % (1, 2, 3, 4)print formatter % ("one", "two", "three", "four")print formatter % (True, False, False, True)print formatter % (formatter, formatter, format
2015-10-07 09:34:25 522
原创 【Python】Learn Python the hard way, ex7 字符串连接
print "Mary had a little lamb."print "Its fleece was white as %s." % 'snow'print "And everywhere that Mary went."print "." * 10 #what's that do?end1 = "C"end2 = "h"end3 = "e"end4 = "e"end5 =
2015-10-07 08:59:25 503
原创 【Python】Learn Python the hard way, ex6 格式化字符串,多行文本
x = "There are %d types of people." % 10binary = "binary"do_not = "don't"y = "Those who konw %s and those who %s." % (binary, do_not)print xprint yprint "I said: %r." % xprint "I also said: '
2015-10-07 08:44:13 495
原创 【Python】Learn Python the hard way, ex5 格式化字符串
my_name = 'Gao'my_age = 31 # not a liemy_height = 174 # cmmy_weight = 80 # kgmy_eyes = 'Black'my_teeth = 'White'my_hair = 'Black'print "Let's talk about %s." % my_nameprint "He's %d cm tall."
2015-10-06 22:45:07 731
原创 【Python】Learn Python the hard way, ex4 使用变量
cars = 100space_in_a_car = 4.0drivers = 30passengers = 90cars_not_driven = cars - driverscars_driven = driverscarpool_capacity = cars_driven * space_in_a_caraverage_passengers_per_car = passeng
2015-10-06 21:45:57 453
原创 【Python】Learn Python the hard way, ex3 运算符,浮点数
print "I will now count my chicken:"print "Hens", 25 + 30 / 6print "Roosters", 100 - 25 * 3 % 4print "Now i will count the eggs:"print 3 + 2 + 1 - 5 + 4 % 2 -1 / 4 + 6print "Is it true 3 + 2
2015-10-06 21:25:17 803
原创 【Python】Learn Python the hard way, ex2 注释
# A comment, this is so you can read your program later.# Anything after the # is ignored by python.print "i could have code like this." # and the comment after is ignored# You can also use a com
2015-10-06 21:09:12 497
原创 【Python】Learn Python the hard way, ex1 简单print语句
print "Hello World!"print "Hello Again"print "I like typing this."print "This is fun."print 'Yay! Printing.'print "I'd much rather you 'not'."print 'i "said" do not touch this.''''#The test r
2015-10-06 21:07:20 522
原创 【Python】Learn Python the hard way, ex0 学习使用Terminal
Mac OS:-bash: /Users/myRMBP/.bash_profile: line 5: `export path=${PATH}: : 'bogon:~ myRMBP$ pythonPython 2.7.10 (v2.7.10:15c95b7d81dc, May 23 2015, 09:33:12) [GCC 4.2.1 (Apple Inc. build 5666
2015-10-06 20:48:09 615
海外运营商准入NFC测试标准GSMA TS.27
2017-04-04
ISO 10373-6 2010 NFC射频测试标准
2017-04-04
C#删除Excel行实例,Microsoft.Office.Interop.Excel
2016-04-24
使用NeatUpload控件实现ASP.NET大文件上传
2015-12-21
《C# 2.0实例自学手册 通过200个例子掌握Web开发捷径》一书配套光盘
2013-05-12
2010年考研政治大纲变动,任汝芬解析大纲变动
2009-09-20
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人