string-formatting

StringFormat of Datetime object in binding gives back 0 for hour and minute

ぃ、小莉子 提交于 2019-12-02 09:16:27
I create a Datetime object with Datetime.Now and I have this as a property of a class. When I bind this to a grid view: <GridViewColumn Header="Date" Width="120" DisplayMemberBinding="{Binding transaction_date1, StringFormat=HH:mm}" /> The result is always 00:00. When I debug the code I see that the hour, minute etc. properties of the Datetime object contain non-zero values. I think that the StringFormat in this case gets the hour and minute from the Date object within the Datetime object that has the correct dates but always has 12:00:00 AM as hour. Is there any way to go past it and display

Extra spaces when printing

倖福魔咒の 提交于 2019-12-02 09:13:45
I've read through a number of the python whitespace removal questions and answers but haven't been able to find what I'm looking for. Here is a small program that shows a specific example of the issue. I greatly appreciate your help. import random math_score = random.randint(200,800) math_guess = int(input("\n\nWhat score do you think you earned on the math section (200 to 800)?\t")) print ("\n\n\nOn the math section, you guessed",math_guess,", and your actual score was",math_score,"!") So here's my issue: When I execute the program, I get the following results: On the math section, you

How to set variable precision for new python format option

有些话、适合烂在心里 提交于 2019-12-02 08:18:58
I am loving the new format option for strings containing variables, but I would like to have a variable that sets the precision through out my script and I am not sure how to do that. Let me give a small example: a = 1.23456789 out_str = 'a = {0:.3f}'.format(a) print(out_str) Now this is what I would want to do in pseudo code: a = 1.23456789 some_precision = 5 out_str = 'a = {0:.(some_precision)f}'.format(a) print(out_str) but I am not sure, if it is possibly and if it is possibly how the syntax would look like. You can nest placeholders, where the nested placeholders can be used anywhere in

what is the Pythonic way to implement a __str__ method with different format options?

拈花ヽ惹草 提交于 2019-12-02 07:30:57
I'd like to create a __str__ method that creates the string in various formats according to user choice. The best I have come up with is to make a __str__(**kwargs) method, and this seems to work ok, but it isn't compatible with str(obj) or print(obj) . In other words I have to use print(obj.__str__(style='pretty')) rather than print(obj, style='pretty') . Implement the object.__format__() method instead, and a user can then specify the formatting required with the format() function and str.format() method : print(format(obj, 'pretty')) or print('This object is pretty: {:pretty}'.format(obj))

FFMPEG command fails for file path with white spaces

狂风中的少年 提交于 2019-12-02 06:32:43
问题 I am executing the below ffmpeg command for trimming videos.The issue I am having is that if filepath contains spaces then the command fails.I tried many ways to handle spaces but none of them worked except moving file to a path that doesn't have space and then executing the command with new file path as source. Below is the command- execFFmpegBinary("-i " + filepath + " -ss " + startMs / 1000 + " -to " + endMs / 1000 + " -strict -2 -async 1 " + dest.getAbsolutePath()); private void

TextBox with CurrencyFormat and PropertyChanged trigger doesn't accept text right

主宰稳场 提交于 2019-12-02 04:59:58
I have a TextBox in a WPF window bound to a dependency property of the window of type double (see below). Whenever the user types in the TextBox when The TextBox is empty, or All of the text is selected, the typed text is accepted incorrectly. For example: If I type a '5' in either of these scenarios, the resulting text is "$5.00", but the caret is located before the '5', after the '$'. If I try to type "52.1", I get "$2.15.00". <Window x:Class="WPF.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title=

Python: Writing multiple nested dictionaries in one table in a text file separated by tab

一曲冷凌霜 提交于 2019-12-02 04:53:27
I am new to Python and I am struggling with printing multiple nested dictionaries in one table separated by tab. I wrote a script to read data from an input file and store the data in 3 different dictionaries: d1 = {'Ben': {'Skill': 'true', 'Magic': 'false'}, 'Tom': {'Skill': 'true', 'Magic': 'true'}} d2 = {'Ben': {'Strength': 'wo_mana', 'Int': 'wi_mana', 'Speed': 'wo_mana'}, 'Tom': {'Int': 'wi_mana', 'Agility': 'wo_mana'}} d3 = {'Ben': {'Strength': '1.10', 'Int': '1.20', 'Speed': '1.50'}, 'Tom': {'Int': '1.40', 'Agility': '1.60'}} I want to represent the data in a table format and when opened

How to use apostrophe in formatted xpath?

夙愿已清 提交于 2019-12-02 04:08:40
I have place the locator in properties file like : header.navigation.product.link = //div[contains(@class,'grid-')]//li/a[contains(.,'%s')] and while I'm using this locator in my code- String headerproductlink = String.format(ConfigurationManager.getBundle() .getString("header.navigation.category.link"), category) And category = Women's Gym Clothing While I'm trying to locate the element it unable to find. even i have tried as Women\'s Gym Clothing but no success. Can someone please suggest a way ? Below different ways worked for me: Locator in Property file: another.header=xpath=//h1[contains

Format string with all elements of a list

巧了我就是萌 提交于 2019-12-02 03:59:58
问题 words = ['John', 'nice', 'skateboarding'] statement = "%s you are so %s at %s" % w for w in words produces File "<stdin>", line 1 statement = "%s you are so %s at %s" % w for w in words ^ SyntaxError: invalid syntax What am I doing wrong here? The assumption is: len(words) == number of '%s' in statement 回答1: >>> statement = "%s you are so %s at %s" % tuple(words) 'John you are so nice at skateboarding' 回答2: You could also use the new .format style string formatting with the "splat" operator:

Reading float using scanf in c

风流意气都作罢 提交于 2019-12-02 03:53:19
问题 i have a structure which contains a float variable, struct MyStruct{ float p; }newMyStruct; And i am reading a value into it using scanf int main(){ scanf("%f",&(newMyStruct.p)); } The problem is when i print it using printf("%f",newMyStruct.p) it prints '0.000000'. Also i get a warning that says the arugment is double while the format expects it to be float(warning for the scanf("%f",&(newMyStruct.p)); statement).When i change scanf() syntax to scanf("%0f",&(newMyStruct.p)); , printf("%0f"