我正试着把a端口处理.org应用到python中并有一些困难。在
我需要用python编写:
int[][] elevation; // elevations in meters
float[][] felevation; // scaled to range [0,1] where 1=max
int maxheight;
void setup(){
size(600,600,P2D);
// read srtm binary file
elevation=new int[1201][1201];
felevation=new float[1201][1201];
byte b[] = loadBytes("N30W091.hgt"); // THIS IS A BINARY FILE
int ix=0;
maxheight=0;
for (int row=0;row<1201;row++) {
for (int col=0;col<1201;col++) {
// bytes are signed, from -128 to 127, converts to unsigned...
int hi = b[ix] & 0xff;
int lo = b[ix+1] & 0xff;
int el=(int)((hi<<8)|lo); // big endian!
elevation[row][col]=el;
if (el>maxheight && el<32000) maxheight=el;
ix+=2;
}
}
。。。等等
到目前为止,我所做的是:
^{pr2}$我总是
Traceback (most recent call last):
File "C:\Users\CNA\workspace\Revitter\PatternAsignment.py", line 16, in <module>
TypeError: unsupported operand type(s) for +: 'str' and 'int'
有什么想法吗。。我是python新手,我没有处理字节的经验。。。在
我不确定是否有.respeme语法正确(将进一步测试)-但类似这样的东西应该可以满足您的需要:
在Python中,
'hello'[2]
也是字符串(在本例中=='l'
)。您需要使用ord
将它们转换为整数,并使用chr
将它们转换回字符串。在参见:http://docs.python.org/library/functions.html
一个惯用的翻译方法是完全不同的。在
在原始代码中,您需要执行一系列位旋转,将两个字节值转换为单个数值。{cd1>内置了Python}功能。事实证明,这个模块是为一次读取多个值而构建的。在
另外,对文件名使用正斜杠-这样更容易,而且可以保证工作。为了保证列表的完整性和完整性,请使用Python来自动停止列表和列表的构建。在
这给了我们:
你就完蛋了。欢迎使用Python:)
相关问题 更多 >
编程相关推荐