[wxPython] String Formating

Hi,

I read that we can use "%f" to format a float number output. Could somebody tell me that if I can use "%s" to format a string to make an output from '2001-5-12 13:22:00.00' to '2001-5-12 13:22'?

Thank you.

Jenny

···

_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com

%s does exist, but it won't really help you for that. As far as I know,
the % operator won't let you cut characters
Why don't you just slice it?

'2001-5-12 13:22:00.00'[:-6] -- > '2001-5-12 13:22'
or
'2001-5-12 13:22:00.00'[:15] -- > '2001-5-12 13:22'

This is more Python like anyways
Raul

qun liu wrote:

···

Hi,

I read that we can use "%f" to format a float number output. Could somebody
tell me that if I can use "%s" to format a string to make an output from
'2001-5-12 13:22:00.00' to '2001-5-12 13:22'?

Thank you.

Jenny
_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com

_______________________________________________
wxpython-users mailing list
wxpython-users@lists.wxwindows.org
http://lists.wxwindows.org/mailman/listinfo/wxpython-users

Raul Cota wrote:

Why don't you just slice it?

'2001-5-12 13:22:00.00'[:-6] -- > '2001-5-12 13:22'
or
'2001-5-12 13:22:00.00'[:15] -- > '2001-5-12 13:22'

This is more Python like anyways

exactly. some other options:

split and join (see:
http://www.python.org/doc/current/lib/string-methods.html )

s = '2001-5-12 13:22:00.00'

s.split(":")

['2001-5-12 13', '22', '00.00']

":".join(s.split(":")[:-1])

'2001-5-12 13:22'

If you want to do something really fancy, you could use regular
expressions:

http://www.python.org/doc/current/lib/module-re.html#l2h-663
and
http://py-howto.sourceforge.net/regex/regex.html

If you want to manipulate times, I highly reccomend mxDateTime:

A general note: wxWindows is intended to be a complete cross-platform
application framework. Python is already has a pretty complete set of
tools for cross platform develpment, with teh exception of GUI stuff.
That's we wxPython comes in, so, as a rule, if it GUI related, look for
a wxPython solution, if it is not GUI related, look for a "pure" python
solution.

-Chris

···

--
Christopher Barker,
Ph.D.
ChrisHBarker@home.net --- --- ---
http://members.home.net/barkerlohmann ---@@ -----@@ -----@@
                                   ------@@@ ------@@@ ------@@@
Oil Spill Modeling ------ @ ------ @ ------ @
Water Resources Engineering ------- --------- --------
Coastal and Fluvial Hydrodynamics --------------------------------------
------------------------------------------------------------------------

I read that we can use "%f" to format a float number output. Could somebody
tell me that if I can use "%s" to format a string to make an output from
'2001-5-12 13:22:00.00' to '2001-5-12 13:22'?

If you can, print out the Python library reference, and look through
that. Lots of interesting toys, including routines to manipulate date
and time. For example, try:

from time import * # Play with dates
from string import * # Monkey with strings
now = localtime(time()) # Current time: yyyy,mm,dd,hh,mm,ss,wd,jd,DST
yyyy,mm,dd,hh,nn,ss,wd,jd,dst = now
print strftime("%a %b %d %H:%M:%S %Y",now)

Tue Jul 17 19:11:52 2001

The localtime returns a tuple with the following values:
(Year,Month,Day,Hour,Minute,Second,WeekDay,JulianDay,DaylightSavingsFlag)
strftime() formats the time tuple in many different ways.

···

On Tue, 17 Jul 2001, qun liu wrote:

--
Kevin Cole, RHCE, Linux Admin | E-mail: kjcole@gri.gallaudet.edu
Gallaudet Research Institute | WWW: http://gri.gallaudet.edu/~kjcole/
Hall Memorial Bldg S-419 | Voice: (202) 651-5135
Washington, D.C. 20002-3695 | FAX: (202) 651-5746