《笨办法学 Python》 学习笔记02

来源:互联网 发布:隋文帝杨坚 知乎 编辑:程序博客网 时间:2024/04/30 03:12

Input

x = raw_input()y = raw_input("Name?")  #这句话会用 “Name?” 提示用户z = raw_input("> ")

Import

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 variable is:", third

Read and Write file

txt = open("d:\text.txt")#txt = open("d:\text.txt", 'w')print txt.read()txt.close()

close – 关闭文件。
read – 读取文件内容。你可以把结果赋给一个变量。
readline – 读取文本文件中的一行。
truncate – 清空文件,请小心使用该命令。
write(stuff) – 将stuff写入文件。


原创粉丝点击