摘要: 代码如下: 点击查看代码 # -*-coding:utf-8- -*- # 函数和文件 from sys import argv script, input_file = argv def print_all(f): # 定义 print_all 读 f print f.read() def rew 阅读全文
posted @ 2022-10-06 04:52 TiramisuPS 阅读(45) 评论(0) 推荐(0) 编辑
摘要: 代码如下: 点击查看代码 # -*-coding:utf-8- -*- # 函数和变量 def cheese_and_crackers(cheese_count, boxs_of_crackers): print "You have %d cheeses!" % cheese_count print 阅读全文
posted @ 2022-10-06 02:15 TiramisuPS 阅读(17) 评论(0) 推荐(0) 编辑
摘要: 代码如下: 点击查看代码 # -*-coding:utf-8- -*- # 命名、变量、代码、函数 # this one is like your scripts with argv def print_two(*args): arg1, arg2 = args print "arg1: %r, a 阅读全文
posted @ 2022-10-05 07:41 TiramisuPS 阅读(17) 评论(0) 推荐(0) 编辑
摘要: 代码如下: 点击查看代码 # -*-coding:utf-8- -*- # 更多文件操作 from sys import argv from os.path import exists # exists 模块: 将文件名字符串作为参数,如果文件存在,返回 True # 如果文件不存在,返回 Fals 阅读全文
posted @ 2022-10-05 07:00 TiramisuPS 阅读(32) 评论(0) 推荐(0) 编辑
摘要: 代码如下: 点击查看代码 # -*-coding:utf-8- -*- # 读写文件 # close - 关闭文件(保存)。 # read - 读取文件内容,结果可赋值给一个变量。 # readline - 读取文本文件中的一行。 # truncate - 清空文件。 # write(stuff) 阅读全文
posted @ 2022-10-05 06:08 TiramisuPS 阅读(20) 评论(0) 推荐(0) 编辑
摘要: 代码如下: 点击查看代码 # -*-coding:utf-8- -*- # 读取文件 from sys import argv # 加载 argv script, filename = argv # 设置 fileame 参数 txt = open(filename) # 把 file object 阅读全文
posted @ 2022-10-05 04:34 TiramisuPS 阅读(52) 评论(0) 推荐(0) 编辑
摘要: 代码如下: 点击查看代码 # -*-coding:utf-8- -*- # 提示和传递 from sys import argv script, user_name = argv prompt = '>' print "Hi %s,I'm the %s script." % (user_name, 阅读全文
posted @ 2022-10-05 04:28 TiramisuPS 阅读(23) 评论(0) 推荐(0) 编辑
摘要: 代码如下: 点击查看代码 # -*-coding:utf-8- -*- # 参数、解包、变量 from sys import argv # argv 是所谓的 “参数变量” ,是一个非常标准的编程术语。 # 包含了你传递给 python 的参数。 script, first, second, thi 阅读全文
posted @ 2022-10-05 04:23 TiramisuPS 阅读(20) 评论(0) 推荐(0) 编辑
摘要: 代码如下: 点击查看代码 # -*-coding:utf-8- -*- # 提示别人 age = raw_input("How old are you?") height = raw_input("How tall are you?") weight = raw_input("How much do 阅读全文
posted @ 2022-10-05 04:09 TiramisuPS 阅读(20) 评论(0) 推荐(0) 编辑
摘要: 代码如下: 点击查看代码 # -*-coding:utf-8- -*- # 提问 print "How old are you?", age = raw_input() print "How tall are you?", height = raw_input() print "How much d 阅读全文
posted @ 2022-10-05 04:05 TiramisuPS 阅读(18) 评论(0) 推荐(0) 编辑