From ed52cd4af0bc62f0064f40ab55adf1cdc37fc712 Mon Sep 17 00:00:00 2001 From: wirawan Date: Wed, 24 Feb 2010 14:28:13 +0000 Subject: [PATCH] * Added slice_str for easy printout of a slice object in python typical slice syntax (e.g. 0:10: or 0:10:3 or :10:3, etc). --- text_tools.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/text_tools.py b/text_tools.py index e5ed822..d79f502 100644 --- a/text_tools.py +++ b/text_tools.py @@ -1,4 +1,4 @@ -# $Id: text_tools.py,v 1.2 2010-01-22 18:50:09 wirawan Exp $ +# $Id: text_tools.py,v 1.3 2010-02-24 14:28:13 wirawan Exp $ # # wpylib.text_tools # Created: 20091204 @@ -8,6 +8,7 @@ # import numpy +from wpylib.sugar import ifelse def make_matrix(Str, debug=None): """Simple tool to convert a string like @@ -103,4 +104,11 @@ def str_expand(template, params, maxiter=100): return str1 +def slice_str(s): + return "%s:%s:%s" % ( + ifelse(s.start == None, "", str(s.start)), + ifelse(s.stop == None, "", str(s.stop)), + ifelse(s.step == None, "", str(s.step)), + ) +