使用Python读SEGY道头
自己遇到的一个问题, WestGeco的3D地震数据, 提取导航数据:
#!/bin/env python
import sys
import struct
try:
f=open(sys.argv[1],'rb')
except (IOError,Exception):
print '''usage:
scriptname segyfilename
'''
sys.exit(1)
#skip EBCDIC header
try:
f.seek(3200)
except Exception:
print 'Oops! your file is broken..'
#read binary header
binhead = f.read(400)
ns = struct.unpack('>h',binhead[20:22])[0]
if ns < 0:
print 'file read error'
sys.exit(1)
#read trace header
while True:
trchead = f.read(240)
if trchead == '':
break
nav = trchead[224:228]+\
trchead[228:232]+\
trchead[200:204]+\
trchead[204:208]+\
trchead[60:64]
#define output format
nl = struct.unpack('>5i',nav)
print 'QL%-4d%9s%10.2f%10.2f%5s' % (nl[0], nl[1], nl[2]/100.0, nl[3]/100.0, nl[4])
f.seek(ns*4,1)
f.close()
相关文档:
前两天理解了unicode、utf-8、gb2312这些编码之间的关系以后,今天终于弄明白了在python里面的编码问题。我们在写python脚本时如果有中文的字符串,在运行的时候有可能会报错也有可能会出现乱码。一般加上# -*- coding:utf-8 -*-就不会报错了,但是还可能有乱码问题,而且同样的代码在不同的编辑器中得出的结果 ......
万恶的编码
小菜对于老师上一节讲的不是很明白,因为没有一本书是将文件与web一起讲授的,他决定自己探究一下它们之间的不同:
首先,小菜在C盘建了一个文本文档 file.txt,输入四个字:我是小菜。
然后,小菜在shell中练习起来:
>>> file=open("c:\\file.txt","r")
>>> data=file.read()
>> ......
python的变参
*args和**dargs是Python的两个可
变参数,两者有所不同的是*args是个tuple,**dargs是个dict。
*args
和**dargs并用时,*args必须放在**dargs的前面。
例如:
def func(a,b, *c):
pass
函数func至少有两个参数变参数放在tuple c中
def func(*c): 或者 def func(**d ......
list.append(item)
list.extend(sequence)
http://docs.python.org/tutorial/datastructures.html
http://docs.python.org/library/functions.html 这几天看一下
python howto
恩。python documentation 确实很好很强大啊!
list.append(x)Add an item to the end of the list; equivalent to a[len(a):]&n ......
1. 手动制作python的exe可执行程序
转载---------------
Python没有内建一个编 ......