% operator in python over string
What does the following Python statement mean? send_data="" str_len = "%#04d" % (len(send_data)/2) ...
What does the following Python statement mean? send_data="" str_len = "%#04d" % (len(send_data)/2) ...
I found the below code through Google. It almost does what I want it to do, except it doesn't provide a way to indicate the precision like '%.*f' does in C-type format strings. Also, it doesn't provide anything further than 5 decimal places. Am I going to have to stick with C strings and snprintf? #include <string> #include <sstream> #i...
I am looking at the format specifiers of C# and the patterns for formatting numeric strings in Java. I am wondering if anyone has any pointers as to translating from one form to another? ...
I have a decimal number, say 1234.500. I want to get it to display 1,234.4 Im currently converting it to a double to remove the trailing '0's. string.Format("{0:0,0}",1234.500) removes the decimal place, and other formatting options seem to use two decimal places regardless. Can anyone offer insight? ...
In Access 2003 I need to display numbers like this while keeping the leading zeroes: 080000 090000 070000 What is the best data type to use for this? ...
I'm using this simple function: def print_players(players): tot = 1 for p in players: print '%2d: %15s \t (%d|%d) \t was: %s' % (tot, p['nick'], p['x'], p['y'], p['oldnick']) tot += 1 and I'm supposing nicks are no longer than 15 characters. I'd like to keep each "column" aligned, is there a some syntactic suga...
I was just about to write this myself, but I know this has to exist and I'm just managing to avoid all the Google keywords that would lead me right to it. I would be looking for something like DDDMMMYYY where D, M, Y are the number of days, months, and years. So 00103000 would indicate a span of three months and one day, or 000000001 wo...
I'm currently writing a report in PHP that occasionally has to display negative currency amounts. Said currency amounts are stored in the database like "-44.00". Ideally this number would be output as "($44.00)" on the report. I know I can write some semi-complicated function to detect whether the number is negative and manually insert ...
How do you make the following code work? example = "%%(test)%" % {'test':'name',} print example Where the desired output is "%name%" Thanks ...
Following code: def __init__(self, url, **kwargs): for key in kwargs.keys(): url = url.replace('%%s%' % key, str(kwargs[key])) Throws the following exception: File "/home/wells/py-mlb/lib/fetcher.py", line 25, in __init__ url = url.replace('%%s%' % key, str(kwargs[key])) ValueError: incomplete format The string has a forma...
I need to send a command to a GIPB instrument and I can do it like this: power.write("volt 0.01"). This command sets the output of my power source to 0.01V, however, I'm trying to take an I-V curve and want to set the source to different values and take a measurement at each value. I basically need some sort of loop to do this for me, I ...
Silly question, I want to format an integer so that it appears with the 1000's separator (,), but also without decimal places and without a leading 0. My attempts so far have been: String.Format("{0} {1}", 5, 5000); // 5 5000 String.Format("{0:n} {1:n}", 5, 5000); // 5.00 5,000.00 String.Format("{0:0,0} {1:0,0}", 5, 5...
I'm trying to annotate a polar plot with data tips labelled with 'R:...,Theta:...' where theta is actually the Greek symbol, rather than the word spelled out. I'm familiar with string formatting using '\theta' resulting in the symbol, but it doesn't work in this case. Is there a way to apply the LaTeX interpreter to data tips? Here's wha...
Not sure what I'm doing wrong here. The extension method is not recognized. using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Text.RegularExpressions; using StringExtensions; namespace ConsoleApplication1 { class Program { static void Main(string[] args) { ...
I want to store a formatted string using something similar to what printf does in C. char *tmp = (char *)sqlite3_column_text(selectstmt, 2); const char *sqlAnswers = printf("select key from answer WHERE key = %s LIMIT 5;", tmp); The following is an error obviously, I am sure alot of c programmers out there would give me a quick answer...
I can't seem to find an easy way to do it. The exact thing I need is: [NSString stringWithFormat:@"%d doodads", n]; Where n is an int. So for 1234 I'd want this string (under my locale): @"1,234 doodads" Thanks. ...
I'm learning Python from a book and came across this example: >>> '%f, %.2f, %.*f % (1/3.0, 1/3.0, 4, 1/3.0) # Result: '0.333333, 0.33, 0.3333' Don't quite understand what's happening here, especially the '4' in between. ...
I am trying to get a formatted date string directly from a LINQ-to-Entities query expression. nonBusinessDays = (from ac in db.AdminCalendar where ac.DateTimeValue >= calendarStartDate && ac.DateTimeValue <= calendarEndDate && ac.IsBusinessDay == false select ac.MonthValue + "/" + ac.DayOfMonth + "/...
This may seem like a stupid question, but what are the symbols used for string replacement in string.format? can someone point me to a simple example of how to use it? ...
I have the following format: Value1 is {0} and Value2 is {1}. I need to replace the numbers in the brackets with strings. This is easily done in most languages using string.Format or something along those lines. How can I do this using only vbscript? I've tried: Replace (strFormat, "{0}", value1) Replace (strFormat, "{1}", value...