0
0

More than 3 years have passed since last update.

CotEditorで改行なしの日付を挿入する

Last updated at Posted at 2020-05-23

CotEditorで日付を挿入するスクリプト

"YYYYMMDD_"形式の日付を挿入する

サンプルスクリプト
sample.~@e.py
#!/usr/bin/env python
# *-# -*- coding: utf-8 -*-
# %%%{CotEditorXOutput=ReplaceSelection}%%%
from __future__ import print_function
import datetime

d=datetime.datetime.today()
print (d.strftime("%Y%m%d_"), end="")

メモ

MacはデフォルトでPython2なので、Python3で処理できるプリント関数はそのままでは処理できない。

改行ありでもいい場合

処理できるスクリプトは次の通り。でも、このスクリプトは改行を含んでしまう。改行して問題ないならこれでOK。

sample.~@e.py
print (d.strftime("%Y%m%d_")

改行を省きたい場合

Python3のprint関数では、’end=""'をprint関数内に記述してあげれば改行を省くことが可能

sample.~@e.py
print (d.strftime("%Y%m%d_"), end="")

でもこのスクリプトはCotEditorで処理できない。
そこで、print関数をPython2でも処理できるように宣言すると、CotEditorでも改行なしで挿入できる。

sample.~@e.py
from __future__ import print_function
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0