Example:
>>> import re
>>> st = "9394 811 813 815"
>>> result = [str(x) for x in filter(None, re.split('[ ,\n,\t]',st))]
>>> print result
['9394', '811', '813', '815']
>>>
QGIS Plugin and Python coding
>>> import re
>>> st = "9394 811 813 815"
>>> result = [str(x) for x in filter(None, re.split('[ ,\n,\t]',st))]
>>> print result
['9394', '811', '813', '815']
>>>
fp = open(ifile,"rb")
byte = fp.read(1)
block = fp.read(30)block = fp.read(30)
(Year,) = struct.unpack('b',block[3:4])
(Month,) = struct.unpack('b',block[4:5])
(Day,) = struct.unpack('b',block[5:6])
(Hour,) = struct.unpack('b',block[6:7])
(Minute,) = struct.unpack('b',block[7:8])
(Second,) = struct.unpack('b',block[8:9])
recdate = str(Year) + '-' + str(Month) + '-' + str(Day) + ' ' + str(Hour) + ':' + str(Minute)
(Cellname,) = struct.unpack('8s',blk[2:10])
| Format | C Type | Python type | Standard size | Notes |
|---|---|---|---|---|
| x | pad byte | no value | ||
| c | char | string of length 1 | 1 | |
| b | signed char | integer | 1 | (3) |
| B | unsigned char | integer | 1 | (3) |
| ? | _Bool | bool | 1 | (1) |
| h | short | integer | 2 | (3) |
| H | unsigned short | integer | 2 | (3) |
| i | int | integer | 4 | (3) |
| I | unsigned int | integer | 4 | (3) |
| l | long | integer | 4 | (3) |
| L | unsigned long | integer | 4 | (3) |
| q | long long | integer | 8 | (2), (3) |
| Q | unsigned long long | integer | 8 | (2), (3) |
| f | float | float | 4 | (4) |
| d | double | float | 8 | (4) |
| s | char[] | string | ||
| p | char[] | string | ||
| P | void * | integer | (5), (3) |
| Operator | Description | Example |
|---|---|---|
| & | Binary AND Operator copies a bit to the result if it exists in both operands. | (a & b) will give 12 which is 0000 1100 |
| | | Binary OR Operator copies a bit if it exists in eather operand. | (a | b) will give 61 which is 0011 1101 |
| ^ | Binary XOR Operator copies the bit if it is set in one operand but not both. | (a ^ b) will give 49 which is 0011 0001 |
| ~ | Binary Ones Complement Operator is unary and has the efect of 'flipping' bits. | (~a ) will give -60 which is 1100 0011 |
| << | Binary Left Shift Operator. The left operands value is moved left by the number of bits specified by the right operand. | a << 2 will give 240 which is 1111 0000 |
| >> | Binary Right Shift Operator. The left operands value is moved right by the number of bits specified by the right operand. | a >> 2 will give 15 which is 0000 1111 |
Copyright (c) 2010 Python Code Blog All rights reserved. Design by CSS Templates | Blogger Templates by TeknoMobi | Sponsored by Bodrum48.