diff options
author | Walter Bender <walter.bender@gmail.com> | 2012-07-25 22:08:04 (GMT) |
---|---|---|
committer | Walter Bender <walter.bender@gmail.com> | 2012-07-25 22:08:04 (GMT) |
commit | 679bf360ed72f3749f616302072fdcd63c7833af (patch) | |
tree | 7cf8719bc0f50b36f0782054de4f0b4be304f859 /TurtleArt/tautils.py | |
parent | 6cd74547b67c97ea22ff2a8a4f391c05e9fda2d0 (diff) |
_2_2 -> _3
Diffstat (limited to 'TurtleArt/tautils.py')
-rw-r--r-- | TurtleArt/tautils.py | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/TurtleArt/tautils.py b/TurtleArt/tautils.py index 676c4ca..c54c65f 100644 --- a/TurtleArt/tautils.py +++ b/TurtleArt/tautils.py @@ -24,6 +24,7 @@ import cairo import pickle import subprocess import os +import string from gettext import gettext as _ try: @@ -109,6 +110,23 @@ def strtype(x): return False +def increment_name(name): + ''' If name is of the form foo_2, change it to foo_3. Otherwise, + return name_2''' + if '_' in name: + parts = name.split('_') + try: + i = int(parts[-1]) + i += 1 + parts[-1] = str(i) + newname = string.join(parts, '_') + except ValueError: + newname = '%s_2' % (name) + else: + newname = '%s_2' % (name) + return newname + + def magnitude(pos): ''' Calculate the magnitude of the distance between to blocks. ''' x, y = pos |