I want to be able to be able to format date/time input for my function.  Currently, I have a function that basically appends a 0 to a number if it is only 1 digit long.  def format_num(str(num)):     if len(num) &lt; 2:         return "0" + num     return num   I was wondering if there was a more pythonic way to do this.
1551
What is a Pythonic way to pad a numeric string with zeroes to the left, i.e. so the numeric string has a specific length?
81419
Is it possible to use the =today() function (or something else) to insert the current date but then not update each time the file is opened?  I want to create a numbers template for my invoices. I'd like it to auto fill invoice date and date due then, when I save the document, store the values, not the function.
10736
What is the recommended way of formatting TimeSpan objects into  a string with a custom format?
68699
Following on from my previous question, , I have now come across a problem regarding the timezone, and it turns out that it's not always going to be "+0200". So when strptime tries to parse it as such, it throws up an exception.  I thought about just chopping off the +0200 with [:-6] or whatever, but is there a real way to do this with strptime?  I am using Python 2.5.2 if it matters.  &gt;&gt;&gt; from datetime import datetime &gt;&gt;&gt; fmt = "%a, %d %b %Y %H:%M:%S +0200" &gt;&gt;&gt; datetime.strptime("Tue, 22 Jul 2008 08:17:41 +0200", fmt) datetime.datetime(2008, 7, 22, 8, 17, 41) &gt;&gt;&gt; datetime.strptime("Tue, 22 Jul 2008 08:17:41 +0300", fmt) Traceback (most recent call last):   File "&lt;stdin&gt;", line 1, in &lt;module&gt;   File "/usr/lib/python2.5/_strptime.py", line 330, in strptime     (data_string, format)) ValueError: time data did not match format:  data=Tue, 22 Jul 2008 08:17:41 +0300  fmt=%a, %d %b %Y %H:%M:%S +0200
14437
I have a datetime coming back from an XML file in the format:     20080916 11:02   as in      yyyymm hh:ss   How can i get the datetime.parse function to pick up on this? Ie parse it without erroring? Cheers
92574
I looked "$\divideontimes$" up on Google and now I know that it's Unicode U+22c7 but when would it be used?  I am guessing that $5 \divideontimes 5 = 25$ and $1$...?
40474
I have a Python function that takes a numeric argument that must be an integer in order for it behave correctly. What is the preferred way of verifying this in Python?  My first reaction is to do something like this:  def isInteger(n):     return int(n) == n   But I can't help thinking that this is 1) expensive 2) ugly and 3) subject to the tender mercies of machine epsilon.   Does Python provide any native means of type checking variables? Or is this considered to be a violation of the language's dynamically typed design?  EDIT: since a number of people have asked - the application in question works with IPv4 prefixes, sourcing data from flat text files. If any input is parsed into a float, that record should be viewed as malformed and ignored.
107508
I am working on a form widget for users to enter a time of day into a text input (for a calendar application). Using JavaScript (we are using jQuery FWIW), I want to find the best way to parse the text that the user enters into a JavaScript Date() object so I can easily perform comparisons and other things on it.  I tried the parse() method and it is a little too picky for my needs. I would expect it to be able to successfully parse the following example input times (in addition to other logically similar time formats) as the same Date() object:   1:00 pm 1:00 p.m. 1:00 p 1:00pm 1:00p.m. 1:00p 1 pm 1 p.m. 1 p 1pm 1p.m. 1p 13:00 13   I am thinking that I might use regular expressions to split up the input and extract the information I want to use to create my Date() object. What is the best way to do this?
18574
I'm trying to convert a date string into an age.  The string is like: "Mon, 17 Nov 2008 01:45:32 +0200" and I need to work out how many days old it is.  I have sucessfully converted the date using:  &gt;&gt;&gt; time.strptime("Mon, 17 Nov 2008 01:45:32 +0200","%a, %d %b %Y %H:%M:%S +0200") (2008, 11, 17, 1, 45, 32, 0, 322, -1)   For some reason %z gives me an error for the +0200 but it doesn't matter that much.  I can get the current time using:  &gt;&gt;&gt; time.localtime() (2009, 2, 3, 19, 55, 32, 1, 34, 0)   but how can I subtract one from the other without going though each item in the list and doing it manually?
1888
I want to do something like String.Format("[{0}, {1}, {2}]", 1, 2, 3) which returns:  [1, 2, 3]   How do I do this in Python?
9452
In Python, how can I parse a numeric string like "545.2222" to its corresponding float value, 545.2222? Or parse the string "31" to an integer, 31?  I just want to know how to parse a float str to a float, and (separately) an int str to an int.
4728
I can output the value of a counter in a LaTeX document via:  \setcounter{mycounter}{1} \arabic{mycounter}   Which inserts a 1. But how do I format the output by, for example, adding a leading zero if mycounter is less than 10 in a way similar to what  lets you do by specifying %02d as your format string?
568
I am looking for a Calculator which can do calculations in the terminal itself without any other extra prefixes and suffixes.  For example: If I typed something like 10000-9000 in the terminal, the answer should come out as 1000.  Once again I am saying, I just need a quick calculator in terminal, without any characters added. I know if I switch to Python, it can do that but I don't want it in such a way.
6721
I ended up writing a quick little script for this in Python, but I was wondering if there was a utility you could feed text into which would prepend each line with some text -- in my specific case, a timestamp.  Ideally, the use would be something like:  cat somefile.txt | prepend-timestamp   (Before you answer sed, I tried this:  cat somefile.txt | sed "s/^/`date`/"   But that only evaluates the date command once when sed is executed, so the same timestamp is incorrectly prepended to each line.)
65208
Is there a common way to get the current time in or with milliseconds?  There is os.time(), but it only provides full seconds.
37578
Interesting challenge. I was given a piece of code earlier, which I have modified as follows for the Posts page.  /* add time stamp */ add_filter('manage_posts_columns', 'posts_columns', 5); function posts_columns($defaults){     $defaults['your_date_col'] = __('Date');     $defaults['week_number'] = __('Wk#');     $defaults['week_in_quarter'] = __('Wk/Qtr');     return $defaults; } add_action('manage_posts_custom_column', 'posts_custom_columns', 5, 2); function posts_custom_columns($column_name, $id){     if($column_name === 'your_date_col'){     echo the_date('d M'),' ',the_time('Ha');     }     if($column_name === 'week_number'){     echo 'Here: ',the_date();     } }   Strangely, although the date format that I have given shows up in the first column ("your_date_col"), only "Here: " shows up in the second column ("week_number"). Any suggestions as to why the_date function doesn't work in the second column?
9415
I have been using AMPscript for a while and I know that there is no way to create custom functions. I was wondering if anybody has come up with an alternative for this?  thanks