Python input and output
来源:互联网 发布:js面向对象高级编程 编辑:程序博客网 时间:2024/05/16 17:45
1. output a. string b. %=>like printf
2. str(make a string) or repr(convert for interpreter)
'the value is x = ' + repr(x) + 'the value is y = ' + repr(y)
The repr() of a string adds string quotes and backslashes
The argument to repr() may be any Python object:
hello = 'hello,world\n'
hellos = repr(hello)
print hellos
import string
for x in range(1,11):
print string.rjust(repr(x),2),string.rjust(repr(x*x),3),
print string.rjust(repr(x*x*x),5) # similar function ljust(),center()
string.zfill('123',5) #00123
string.zfill('-123',5) #-00123
print '%5.3s'%math.pi # comma take one position
print 'jack:%(jack)d;Sjoerd:%(addf)d;Dcab:%(Dcab)d'%table # return a locally dictionary
3. f = open('path','w') # w only write, r only write, r+ read and write, a write at the end
print f
f.read(size)
f.readline()
f.readlines() # return a list
f.write(string)
f = open('path','r+')
f.write('0123456789')
f.seek(5) # go to 6th byte in the file
f.read(1) # read one element
f.tell() # the index
f.seek(offset,from_what) 0 begin,1current,2 end,default is 0
f.close()
4. pickle module
pickling object pickle.dump(x,f)
unpickling object x = pickle.load(f)
- Python input and output
- [Python]Input/Output and str Formatting
- Python Intro - System Input and Output
- The Python Tutorial - Input and Output
- input and output
- itk input and output
- Input and Output
- 7. Input and Output
- 8 Input and Output
- The Python Tutorial 7——Input and Output
- Python 3.3 Tutorial Notes - 5:Input and Output
- [译]The Python Tutorial#7. Input and Output
- Python--Input Output,Unicode
- Input and output of iostream.
- Ch.7 - Input and Output
- Hadoop Streaming Input and Output
- Redirecting standard input and output
- File Input and Output(1)
- Linux iostat监测IO状态
- 利用神经网络方法进行复杂函数的求导
- 数据挖掘开发工具
- SpringMVC和Struts2比较
- 副标题:利用ant脚本 自动构建svn增量/全量 系统程序升级包
- Python input and output
- win快捷键学习
- PTS PCR DTS
- 基于Flume的美团日志收集系统(一)架构和设计
- 黑马程序员 多线程
- Android手势源码浅析-----手势绘制(GestureOverlayView)
- python 学习笔记(十九)
- 面试题23:从上往下打印二叉树
- Java中的反射机制