Betriebsumgebung
Xeon E5-2620 v4 (8 Kerne) x 2
32GB RAM
CentOS 6.8 (64bit)
openmpi-1.8.x86_64 und seine-devel
mpich.x86_64 3.1-5.el6 und seine-devel
gcc version 4.4.7 (Und Gfortran)
NCAR Command Language Version 6.3.0
WRF v3.7.Verwende 1.
Python 3.6.0 on virtualenv
Ich möchte die Zeichenkette 20170324 in die Zeichenkette 2017/03/24 konvertieren.
test_python_170324k.py
orgstr = "20170324" # YYYYMMDD
print(orgstr)
# 1
newstr = orgstr[:4] + '/' + orgstr[4:6] + '/' + orgstr[6:]
print(newstr)
# 2
from datetime import datetime as dt
adt = dt.strptime(orgstr, '%Y%m%d')
newstr = adt.strftime('%Y/%m/%d')
print(newstr)
Ergebnis
$ python test_python_170324k.py
20170324
2017/03/24
2017/03/24
Zuerst dachte ich über Insert etc. nach. http://stackoverflow.com/questions/4022827/insert-some-string-into-given-string-at-given-index-in-python gemäß
answered Oct 26 '10 at 12:02 bgporter An important point that often bites new Python programmers but the other posters haven't made explicit is that strings in Python are immutable -- you can't ever modify them in place
Und das.
Recommended Posts