473,378 Members | 1,619 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

strftime replacement which supports Unicode format strings?

Is there a library with a strftime replacement which supports Unicode
format strings?
Bye,
Dennis
Aug 6 '06 #1
1 4444
Dennis Benzinger wrote:
Is there a library with a strftime replacement which supports Unicode
format strings?
Not that I know of.

I presume that you're not happy with workarounds like:

#>>import datetime
#>>now = datetime.datetime.now()
#>>now.strftime('Year=%Y Month=%m Day=%d')
'Year=2006 Month=08 Day=07'
#>>now.strftime(u'Year=%Y Month=%m Day=%d')
Traceback (most recent call last):
File "<stdin>", line 1, in ?
TypeError: strftime() argument 1 must be str, not unicode
#>>u'Year=%s Month=%s Day=%s' %
tuple(now.strftime('%Y/%m/%d').split('/'))
u'Year=2006 Month=08 Day=07'
#>>>

You could generalise that by lashing up a function uniftime(obj,
unifmt) which would work on any obj with a strftime method: parse the
unifmt, build a strfmt with the components you want and some carefully
chosen separator (maybe a control character e.g. FS), call
obj.strftime(strfmt).split(FS) to get your components, then blend the
components into the unicode constant parts of your unifmt -- easy :-)

Cheers,
John

Aug 6 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: John Hunter | last post by:
>>> from datetime import date >>> dt = date(1005,1,1) >>> print dt.strftime('%Y') Traceback (most recent call last): File "<stdin>", line 1, in ? ValueError: year=1005 is before 1900; the...
48
by: Zenobia | last post by:
Recently I was editing a document in GoLive 6. I like GoLive because it has some nice features such as: * rewrite source code * check syntax * global search & replace (through several files at...
4
by: webdev | last post by:
lo all, some of the questions i'll ask below have most certainly been discussed already, i just hope someone's kind enough to answer them again to help me out.. so i started a python 2.3...
5
by: Jamie | last post by:
I have a file that was written using Java and the file has unicode strings. What is the best way to deal with these in C? The file definition reads: Data Field Description CHAR File...
2
by: richard | last post by:
I'm just dealing with a Roundup bug report in which it's pointed out that time.strftime() doesn't produce RFC2822-compliant date strings when in a locale other than "C". My reading of the RFC...
4
by: laxmikiran.bachu | last post by:
Can we have change a unicode string Type object to a Tuple type object.. If so how ????
24
by: Donn Ingle | last post by:
Hello, I hope someone can illuminate this situation for me. Here's the nutshell: 1. On start I call locale.setlocale(locale.LC_ALL,''), the getlocale. 2. If this returns "C" or anything...
2
by: Giovanni Bajo | last post by:
Hello, I am trying to find a good way to portably get the output of strftime() and put it onto a dialog (I'm using PyQt, but it doesn't really matter). The problem is that I need to decode the...
3
by: Andrii V. Mishkovskyi | last post by:
2008/5/7 Alexandr N Zamaraev <tonal@promsoft.ru>: Unicode and str objects are not the same. Why do you think that this is a bug? Anyway, you can always use 'encode' method of unicode objects: ...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.