Environnement d'exploitation
Xeon E5-2620 v4 (8 noyaux) x 2
32GB RAM
CentOS 6.8 (64bit)
openmpi-1.8.x86_64 et ses-devel
mpich.x86_64 3.1-5.el6 et ses-devel
gcc version 4.4.7 (Et gfortran)
NCAR Command Language Version 6.3.0
WRF v3.7.Utilisez 1.
Python 2.6.6 (r266:84292, Aug 18 2016, 15:13:37)
Python 3.6.0 on virtualenv
Connexes: GAMESS> Éléments du fichier de sortie
Supposons qu'il y ait plusieurs espaces avant un caractère particulier.
$ cat sample.in
A B C
D E F
G H I
Je souhaite convertir le format ci-dessus en:
$ cat sample.md
###A B C
###D E F
###G H I
code
toMarkdown_170829.py
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import subprocess
import sys
# On Python 2.6.6
# coding rule:PEP8
# { Configuration----
# Set strings' lists for GAMESS output
targets = ("A B C",
"D E F",
"G H I"
)
# } Configuration----
if len(sys.argv) < 3:
print('ERROR: invalid runtime parameter')
print('\ntype:')
print('python %s [input file] [output file]' % sys.argv[0])
sys.exit()
IN_FILE = sys.argv[1]
OUT_FILE = sys.argv[2]
WRK_FILE = 'wrk.md'
for elem in targets:
# 1. replace
cmd = "sed 's/ *%s/###%s/g' %s > %s" % (
elem, elem, IN_FILE, WRK_FILE)
# print(cmd) # for debug
subprocess.call(cmd, shell=True)
# 2. move
# because (sed 's/A/B/g' in > in) will delete [in] file
cmd = 'mv %s %s' % (WRK_FILE, OUT_FILE)
subprocess.call(cmd, shell=True)
# sys.exit() # for debug
IN_FILE = OUT_FILE
run
$ python toMarkdown_170829.py sample.in sample.md
Lorsque vous exécutez sed's / A / B / g'out.md> out.md
, le contenu de out.md disparaît.
Par conséquent, l'implémentation ci-dessus utilise un fichier temporaire [WRK_FILE].