我有UTM x,y坐标的.dat文件,但x,y对是沿5列的行。我想把它们放到一个简单的x,y列中。
由此:
10 11 12 13 14 15 16 17 18 19
20 21 22 23 24 25 26 27 28 29
30 31 32 33 34 35
对此:
10 11
12 13
14 15
16 17
18 19
20 21
22 23
24 25
26 27
28 29
30 31
32 33
34 35
一位同事有一个VBA脚本为此工作,但他在测试后忘了保存它,现在我自己。我使用Python并且VBA经验很少。
答案 0 :(得分:1)
看起来你可以在双倍空格处打破线条:
Jun 02, 2015 1:03:56 PM org.springframework.web.context.ContextLoader initWebApplicationContext
INFO: Root WebApplicationContext: initialization started
Jun 02, 2015 1:03:56 PM org.springframework.web.context.support.AnnotationConfigWebApplicationContext prepareRefresh
INFO: Refreshing Root WebApplicationContext: startup date [Tue Jun 02 13:03:56 CEST 2015]; root of context hierarchy
Jun 02, 2015 1:03:56 PM org.springframework.web.context.support.AnnotationConfigWebApplicationContext loadBeanDefinitions
INFO: Registering annotated classes: [class com.tmlink.springmvc.springAdmin.RootConfig]
Jun 02, 2015 1:03:57 PM org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter initControllerAdviceCache
INFO: Looking for @ControllerAdvice: Root WebApplicationContext: startup date [Tue Jun 02 13:03:56 CEST 2015]; root of context hierarchy
Jun 02, 2015 1:03:57 PM org.springframework.web.context.ContextLoader initWebApplicationContext
INFO: Root WebApplicationContext: initialization completed in 924 ms
Jun 02, 2015 1:04:00 PM org.apache.catalina.util.SessionIdGenerator createSecureRandom
INFO: Creation of SecureRandom instance for session ID generation using [SHA1PRNG] took [3,122] milliseconds.
Jun 02, 2015 1:04:00 PM org.springframework.web.servlet.DispatcherServlet initServletBean
INFO: FrameworkServlet 'dispatcher': initialization started
Jun 02, 2015 1:04:00 PM org.springframework.web.context.support.AnnotationConfigWebApplicationContext prepareRefresh
INFO: Refreshing WebApplicationContext for namespace 'dispatcher-servlet': startup date [Tue Jun 02 13:04:00 CEST 2015]; parent: Root WebApplicationContext
Jun 02, 2015 1:04:00 PM org.springframework.web.context.support.AnnotationConfigWebApplicationContext loadBeanDefinitions
INFO: Registering annotated classes: [class com.xxxxx.springmvc.springAdmin.ServletConfig]
Jun 02, 2015 1:04:00 PM org.springframework.web.servlet.DispatcherServlet initServletBean
INFO: FrameworkServlet 'dispatcher': initialization completed in 49 ms
Tomcat version: 7.0.56, Java version: 1.7.0.67.
或者拆分值然后经过x,y对:
>>> data = '''10 11 12 13 14 15 16 17 18 19
20 21 22 23 24 25 26 27 28 29
30 31 32 33 34 35'''
>>> print(data.replace(' ', '\n'))
10 11
12 13
14 15
16 17
18 19
20 21
22 23
24 25
26 27
28 29
30 31
32 33
34 35
答案 1 :(得分:0)
在Python 3.4.3下,这似乎对我很好:
with \
open('C:/Users/Gord/Desktop/thing.dat', 'r') as fin, \
open('C:/Users/Gord/Desktop/thing.txt', 'w') as fout:
for line in fin:
items = line.split()
for i in range(0, len(items), 2):
print(items[i] + ' ' + items[i+1], file=fout)