From 679bf360ed72f3749f616302072fdcd63c7833af Mon Sep 17 00:00:00 2001 From: Walter Bender Date: Wed, 25 Jul 2012 22:08:04 +0000 Subject: _2_2 -> _3 --- (limited to 'TurtleArt/tautils.py') 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 -- cgit v0.9.1