我想做相同的以下内容:
#define print_max(TYPE) \
# ifdef TYPE##_MAX \
printf("%lld\n", TYPE##_MAX); \
# endif
print_max(INT);
Run Code Online (Sandbox Code Playgroud)
现在#ifdef,就我在函数宏中看到的那样,不允许使用任何嵌套的预处理程序指令.有任何想法吗?
更新:所以看起来这是不可能的.即使是在运行时检查的黑客也无法实现.所以我想我会选择以下内容:
#ifndef BLAH_MAX
# define BLAH_MAX 0
#endif
# etc... for each type I'm interested in
#define print_max(TYPE) \
if (TYPE##_MAX) \
printf("%lld\n", TYPE##_MAX);
print_max(INT);
print_max(BLAH);
Run Code Online (Sandbox Code Playgroud) 我可以使用输出区域敏感时间格式strftime('%X'),但这总是包括秒.如何在没有秒的情况下显示此时间格式?
>>> import locale
>>> import datetime
>>> locale.setlocale(locale.LC_ALL, 'en_IE.utf-8')
'en_IE.utf-8'
>>> print datetime.datetime.now().strftime('%X')
12:22:43
>>> locale.setlocale(locale.LC_ALL, 'zh_TW.utf-8')
'zh_TW.utf-8'
>>> print datetime.datetime.now().strftime('%X')
12?22?58?
Run Code Online (Sandbox Code Playgroud)
我能想到这样做的唯一方法是尝试解析输出locale.nl_langinfo(locale.T_FMT)并删除秒位,但这带来了它自己的诡计.
>>> print locale.nl_langinfo(locale.T_FMT)
%H?%M?%S?
>>> locale.setlocale(locale.LC_ALL, 'en_IE.utf-8')
'en_IE.utf-8'
>>> print locale.nl_langinfo(locale.T_FMT)
%T
Run Code Online (Sandbox Code Playgroud)
(根据pixelbeat的回答.)
# -*- coding: utf-8 -*-
import locale
def locale_time(t, show_seconds=False):
if show_seconds:
return t.strftime('%X')
replacement_fmts = [
(u'.%S', u''),
(u':%S', u''),
(u',%S', u''),
(u':%OS', ''),
(u'?????%S', u''),
(u' %S?', u''),
(u'%S?', u''),
(u'%r', '%I:%M %p'),
(u'%t', '%H:%M'),
(u'%T', …Run Code Online (Sandbox Code Playgroud) 我很惊讶CSS中没有"text-decoration:reverse",因为使用JavaScript实现起来似乎很尴尬.IE将元素的前景色和背景色分别设置为父级的背景和前景.
我在这里注意到了JavaScript技术
当然不是那么复杂吗?