[PYTHON] Insert a date without line breaks in CotEditor

Script to insert date in CotEditor

Insert a date in "YYYYMMDD_" format

Sample script

Python:[email protected]


#!/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="")

Note

Since Mac is Python2 by default, print functions that can be processed by Python3 cannot be processed as they are.

If it is okay to have line breaks

The scripts that can be processed are as follows. But this script contains line breaks. If there is no problem with line breaks, this is OK.

Python:[email protected]


print (d.strftime("%Y%m%d_")

If you want to omit line breaks

In the print function of Python3, it is possible to omit line breaks by writing'end = ""'in the print function.

Python:[email protected]


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

But this script cannot be processed by CotEditor. So, if you declare the print function so that it can be processed in Python2, you can insert it in CotEditor without line breaks.

Python:[email protected]


from __future__ import print_function

Recommended Posts

Insert a date without line breaks in CotEditor
[Introduction] Insert line breaks in Python 3
Output a character string with line breaks in PyYAML
Display character strings without line breaks in python (personal memo)
Implement a date setter in Tkinter
Create a LINE Bot in Django
Change line breaks in iPython autoformatted output
Make a rock-paper-scissors game in one line (python)
[Python] Insert ":" in MAC address
Insert an object inside a string in Python
Look up the URL in sitemap.xml without too big line breaks with Linux commands
[LINE Messaging API] Create a rich menu in Python
Until you insert data into a spreadsheet in Python
[Simple procedure] To log in to ssh without a password