string-formatting

StringFormat on Combobox Displaymemberpath

北城以北 提交于 2020-01-29 03:23:24
问题 I am trying to use StringFormat on DisplayMemberPath property of a ComboBox (WPF). But i don't know even if this is possible. can someone help me with some ideas. I am trying to do something like this: <ComboBox DisplayMemberPath="{Binding Path=MyDateField, StringFormat={}{0:dd/MM/yyyy}}" Name="CmbName" Width="120" /> But it isn't working... Thx All 回答1: simply use the ItemStringFormat property (works only if IsEditable="False") <ComboBox ItemsSource="{Binding YourItems}" DisplayMemberPath=

Optional keys in string formats using '%' operator?

微笑、不失礼 提交于 2020-01-25 20:38:27
问题 Is is possible to have optional keys in string formats using '%' operator? I’m using the logging API with Python 2.7, so I can't use Advanced String Formatting. My problem is as follow: >>> import logging >>> FORMAT = '%(asctime)-15s %(message)s %(user)s' >>> logging.basicConfig(format=FORMAT) >>> logging.warning("It works for:", extra={'user': 'me'}) 2016-08-29 11:24:31,262 It works for: me >>> logging.warning("It does't work!") Traceback (most recent call last): ... KeyError: 'user' Logged

Optional keys in string formats using '%' operator?

浪子不回头ぞ 提交于 2020-01-25 20:38:09
问题 Is is possible to have optional keys in string formats using '%' operator? I’m using the logging API with Python 2.7, so I can't use Advanced String Formatting. My problem is as follow: >>> import logging >>> FORMAT = '%(asctime)-15s %(message)s %(user)s' >>> logging.basicConfig(format=FORMAT) >>> logging.warning("It works for:", extra={'user': 'me'}) 2016-08-29 11:24:31,262 It works for: me >>> logging.warning("It does't work!") Traceback (most recent call last): ... KeyError: 'user' Logged

From string with locale to date on iphone sdk

柔情痞子 提交于 2020-01-25 04:39:28
问题 I trying to find a way to convert a string into a date with a given locale identifier. I have for example an italian date (locale: it_IT) I want to convert into a valid date object. NSDate *GLDateWithString(NSString *string, NSString *localeIdentifier) { [NSDateFormatter setDefaultFormatterBehavior:NSDateFormatterBehavior10_4]; NSDateFormatter *formatter = [[NSDateFormatter alloc] init]; NSLocale *locale = [[NSLocale alloc] initWithLocaleIdentifier:localeIdentifier]; [formatter setLocale

Indentation preserving formatting of multiline strings

时间秒杀一切 提交于 2020-01-25 04:34:06
问题 I generate bits of (C++) code using format strings such as memfn_declaration = '''\ {doc} {static}auto {fun}({formals}){const} -> {result}; ''' Format strings are nice for this, but is there a way to make them keep the indentation level for {doc} here? It's typically multiline. I know I can just indent the string corresponding to doc by two spaces, I know there are plenty of functions to this end, but that's not what I'm asking: I'm looking for something that would work without tweaking the

Unexpected '{' in field name when doing string formatting

て烟熏妆下的殇ゞ 提交于 2020-01-22 17:17:55
问题 I'm trying to write a small script that will automate some PHP boilerplate that I need to write. It should write a copy of the string code to the output file with the various replacement fields filled in for each dict in the fields list. However, I'm getting the error: Traceback (most recent call last): File "writefields.py", line 43, in <module> formatted = code.format(**field) ValueError: unexpected '{' in field name As far as I can tell, there are no extra braces in either the replacement

Unexpected '{' in field name when doing string formatting

拟墨画扇 提交于 2020-01-22 17:16:26
问题 I'm trying to write a small script that will automate some PHP boilerplate that I need to write. It should write a copy of the string code to the output file with the various replacement fields filled in for each dict in the fields list. However, I'm getting the error: Traceback (most recent call last): File "writefields.py", line 43, in <module> formatted = code.format(**field) ValueError: unexpected '{' in field name As far as I can tell, there are no extra braces in either the replacement

cucumber/ruby: possible to output the “puts” to a --format html file?

本小妞迷上赌 提交于 2020-01-21 11:44:01
问题 I've got some ruby tests that are calling different modules, classes where they detail what they're doing with some "puts" commands during execution. If you run those tests in the console then you will see the output of the "puts" command in the console but if you run the tests with the option: ruby --format html --output file.html then all that information is lost. Is there a way to log simple string messages inside the HTML report? 回答1: I tried the following steps: When /^I do something$/

cucumber/ruby: possible to output the “puts” to a --format html file?

半世苍凉 提交于 2020-01-21 11:42:37
问题 I've got some ruby tests that are calling different modules, classes where they detail what they're doing with some "puts" commands during execution. If you run those tests in the console then you will see the output of the "puts" command in the console but if you run the tests with the option: ruby --format html --output file.html then all that information is lost. Is there a way to log simple string messages inside the HTML report? 回答1: I tried the following steps: When /^I do something$/

How to use a dot in Python format strings?

岁酱吖の 提交于 2020-01-21 06:34:37
问题 I want to format a string and be able to use the dot operator, so that I can construct template strings containing e.g. {user.name} , {product.price} . I tried this: 'Hello {user.name}'.format( {'user': { 'name': 'Markus' } } ) KeyError: 'user' 'Hello {user.name}'.format( **{'user': { 'name': 'Markus' } } ) AttributeError: 'dict' object has no attribute 'name' Is there a way to do it? 回答1: Python dict objects are unfortunately not attribute accessible (i.e. with the dot notation) by default.