python 输入、输出、文件
来源:互联网 发布:淘宝网首页免火水煮锅 编辑:程序博客网 时间:2024/05/29 18:11
1、在很多时候,你会想要让你的程序与用户(可能是你自己)交互。你会从用户那里得到输入,然后打印一些结果。我们可以分别使用raw_input和print语句来完成这些功能。对于输出,你也可以使用多种多样的str(字符串)类。例如,你能够使用rjust方法来得到一个按一定宽度右对齐的字符串。利用help(str)获得更多详情。
2、另一个常用的输入/输出类型是处理文件。创建、读和写文件的能力是许多程序所必需的,我们将会在这章探索如何实现这些功能。
例:读写文件
#!/usr/bin/python
poem='''\
Programing is fun
When the work is done
if you want to make your work also fun:
use Python!
'''
f=file('poem.txt','w')
f.write(poem)
f.close()
f=file('poem.txt') #read mode is default
while True:
line=f.readline()
if len(line)==0: #indicates EOF
break
print line,
#avoid automatic newline added by python
f.close()
运行输出:
shiyan@ubuntu:~/Desktop/pythonLearn$ ./file.py
Programing is fun
When the work is done
if you want to make your work also fun:
use Python!
shiyan@ubuntu:~/Desktop/pythonLearn$
3、存储器
- python 输入、输出、文件
- python文件输入和输出
- python 文件输入和输出
- Python-文件输入和输出
- Python开发-Python文件处理-Python文件输入和输出
- Python一天入门17:输入/输出-文件
- python学习-文件的输入、输出
- [python]文件操作(输入、输出)
- python:8:文件的输入与输出
- python 输入和输出
- python输入和输出
- Python输入和输出
- python 输入与输出
- Python 输入和输出
- Python 输入与输出
- Python输入和输出
- 002_007 Python 随机输入/输出即随机读取文件
- Python菜鸟学习手册10----文件的输入与输出
- 出502错误,重启PHP报错
- 32位SH-2A CPU内核的SH7216系列产品
- 使用Spread Studio for .NET删除工作表
- TCP滑动窗口和socket缓冲区之间的关系(记录)
- 互联走向
- python 输入、输出、文件
- 关于C#中使用INI档Unicode的问题
- BitmapCutter实现截取图片功能不能拖动原因剖析
- python 字符编码 调用其他程序 的一些问题记录
- TopCoder SRM480 DIV1 Practise
- db2 导出数据 db2move &dbname export
- 毕设
- android 下的webview 设置多点触控
- ubuntu的sudo失效的问题