From 530ac9230d7774ed2409d1e45420e1922e05bf53 Mon Sep 17 00:00:00 2001 From: Walter Bender Date: Sun, 05 May 2013 12:22:37 +0000 Subject: change type()== to isisintance --- diff --git a/TurtleArt/sprites.py b/TurtleArt/sprites.py index de5a0b5..2c4ac5a 100644 --- a/TurtleArt/sprites.py +++ b/TurtleArt/sprites.py @@ -268,7 +268,7 @@ class Sprite: def set_label(self, new_label, i=0): ''' Set the label drawn on the sprite ''' self._extend_labels_array(i) - if type(new_label) is str or type(new_label) is unicode: + if isinstance(new_label, (str, unicode)): # pango doesn't like nulls self.labels[i] = new_label.replace("\0", " ") else: diff --git a/TurtleArt/tabasics.py b/TurtleArt/tabasics.py index ab26a79..81eba2d 100644 --- a/TurtleArt/tabasics.py +++ b/TurtleArt/tabasics.py @@ -79,11 +79,7 @@ def _color_to_num(c): def _num_type(x): """ Is x a number type? """ - if type(x) == int: - return True - if type(x) == float: - return True - if type(x) == ord: + if isinstance(x, (int, float, ord)): return True return False @@ -1028,7 +1024,7 @@ variable')) def _prim_box(self, x): """ Retrieve value from named box """ - if type(convert(x, float, False)) == float: + if isinstance(convert(x, float, False), float): if int(float(x)) == x: x = int(x) try: @@ -1120,7 +1116,7 @@ variable')) def _prim_setbox(self, name, x, val): """ Define value of named box """ if x is not None: - if type(convert(x, float, False)) == float: + if isinstance(convert(x, float, False), float): if int(float(x)) == x: x = int(x) self.tw.lc.boxes[name + str(x)] = val @@ -1133,7 +1129,7 @@ variable')) def _prim_stack(self, x): """ Process a named stack """ - if type(convert(x, float, False)) == float: + if isinstance(convert(x, float, False), float): if int(float(x)) == x: x = int(x) if 'stack3' + str(x) not in self.tw.lc.stacks or \ @@ -1191,7 +1187,7 @@ variable')) def _prim_careful_divide(self, x, y): """ Raise error on divide by zero """ - if type(x) == list and _num_type(y): + if isinstance(x, list) and _num_type(y): z = [] for i in range(len(x)): try: @@ -1215,7 +1211,7 @@ variable')) def _prim_equal(self, x, y): """ Numeric and logical equal """ - if type(x) == list and type(y) == list: + if isinstance(x, list) and isinstance(y, list): for i in range(len(x)): if x[i] != y[i]: return False @@ -1237,7 +1233,7 @@ variable')) def _prim_less(self, x, y): """ Compare numbers and strings """ - if type(x) == list or type(y) == list: + if isinstance(x, list) or isinstance(y, list): raise logoerror("#syntaxerror") try: return float(x) < float(y) @@ -1266,7 +1262,7 @@ variable')) y = _color_to_num(y) if _num_type(x) and _num_type(y): return(x + y) - elif type(x) == list and type(y) == list: + elif isinstance(x, list) and isinstance(y, list): z = [] for i in range(len(x)): z.append(x[i] + y[i]) @@ -1286,7 +1282,7 @@ variable')) """ Numerical subtraction """ if _num_type(x) and _num_type(y): return(x - y) - elif type(x) == list and type(y) == list: + elif isinstance(x, list) and isinstance(y, list): z = [] for i in range(len(x)): z.append(x[i] - y[i]) @@ -1300,12 +1296,12 @@ variable')) """ Numerical multiplication """ if _num_type(x) and _num_type(y): return(x * y) - elif type(x) == list and _num_type(y): + elif isinstance(x, list) and _num_type(y): z = [] for i in range(len(x)): z.append(x[i] * y) return(z) - elif type(y) == list and _num_type(x): + elif isinstance(y, list) and _num_type(x): z = [] for i in range(len(y)): z.append(y[i] * x) @@ -1364,18 +1360,16 @@ variable')) def _string_to_num(self, x): """ Try to comvert a string to a number """ - if type(x) is float: - return(x) - if type(x) is int: + if isinstance(x, (int, float)): return(x) - if type(x) is ord: + if isinstance(x, ord): return(int(x)) - if type(x) is list: + if isinstance(x, list): raise logoerror("#syntaxerror") if x in COLORDICT: return _color_to_num(x) xx = convert(x.replace(self.tw.decimal_point, '.'), float) - if type(xx) is float: + if isinstance(xx, float): return xx else: xx, xflag = chr_to_ord(x) diff --git a/TurtleArt/tablock.py b/TurtleArt/tablock.py index 6b9e5be..2658624 100644 --- a/TurtleArt/tablock.py +++ b/TurtleArt/tablock.py @@ -113,7 +113,7 @@ class Blocks: def get_similar_blocks(self, block_type, name): block_list = [] - if type(name) == type(''): + if isinstance(name, str): for block in self.list: if block.type == block_type and block.name == name: block_list.append(block) @@ -530,7 +530,7 @@ class Block: def _set_label_attributes(self): if self.spr is None: return - if type(self.name) == unicode: + if isinstance(self.name, unicode): self.name = self.name.encode('ascii', 'replace') if self.name in content_blocks: n = len(self.values) @@ -611,11 +611,11 @@ class Block: self._bottom = 0 self.svg.set_stroke_width(STANDARD_STROKE_WIDTH) self.svg.clear_docks() - if type(self.name) == unicode: + if isinstance(self.name, unicode): self.name = self.name.encode('ascii', 'replace') for k in block_styles.keys(): if self.name in block_styles[k]: - if type(self.block_methods[k]) == type([]): + if isinstance(self.block_methods[k], list): self.block_methods[k][0](svg, self.block_methods[k][1], self.block_methods[k][2]) else: diff --git a/TurtleArt/tacanvas.py b/TurtleArt/tacanvas.py index 1d07784..e446e46 100644 --- a/TurtleArt/tacanvas.py +++ b/TurtleArt/tacanvas.py @@ -619,9 +619,9 @@ class TurtleGraphics: fd = pango.FontDescription('Sans') fd.set_size(int(size * scale) * pango.SCALE) pl.set_font_description(fd) - if type(label) == str or type(label) == unicode: + if isinstance(label, (str, unicode)): pl.set_text(label.replace('\0', ' ')) - elif type(label) == float or type(label) == int: + elif isinstance(label, (float, int)): pl.set_text(str(label)) else: pl.set_text(str(label)) diff --git a/TurtleArt/taexportlogo.py b/TurtleArt/taexportlogo.py index ff3a8e6..8ddaf31 100644 --- a/TurtleArt/taexportlogo.py +++ b/TurtleArt/taexportlogo.py @@ -83,7 +83,7 @@ def save_logo(tw): skip = False continue blk = psuedocode[i] - if type(blk) == type((1, 2)): + if isinstance(blk, tuple): (blk, _blk_no) = blk if blk in logo_commands: logo_command = logo_commands[blk] @@ -106,7 +106,7 @@ def save_logo(tw): this_stack += logo_command else: # assume it is an argument if not blk in ['nop', 'nop1', 'nop2', 'nop3']: - if type(blk) == str and blk[0:2] == '#s': + if isinstance(blk, str) and blk[0:2] == '#s': this_stack += str(blk[2:]).replace(' ', '_') else: this_stack += str(blk).replace(' ', '_') @@ -129,8 +129,8 @@ def save_logo(tw): def _add_label(string): - if type(string) == str and string[0:8] in ['#smedia_', '#saudio_', - '#svideo_', '#sdescr_']: + if isinstance(string, str) and string[0:8] in ['#smedia_', '#saudio_', + '#svideo_', '#sdescr_']: string = string[8:] if HAS_DATASTORE: dsobject = datastore.get(string[8:]) @@ -148,28 +148,28 @@ def _add_label(string): def _add_named_stack(action): - if type(action) == str and action[0:2] == '#s': + if isinstance(action, str) and action[0:2] == '#s': return 'to %s\n' % (str(action[2:]).replace(' ', '_')) else: return 'to %s\n' % (str(action).replace(' ', '_')) def _add_reference_to_stack(action): - if type(action) == str and action[0:2] == '#s': + if isinstance(action, str) and action[0:2] == '#s': return '%s' % (str(action[2:]).replace(' ', '_')) else: return '%s' % (str(action).replace(' ', '_')) def _add_named_box(box_name): - if type(box_name) == str and box_name[0:2] == '#s': + if isinstance(box_name, str) and box_name[0:2] == '#s': return 'make "%s' % (str(box_name[2:]).replace(' ', '_')) else: return 'make "%s' % (str(box_name).replace(' ', '_')) def _add_reference_to_box(box_name): - if type(box_name) == str and box_name[0:2] == '#s': + if isinstance(box_name, str) and box_name[0:2] == '#s': return ':%s' % (str(box_name[2:]).replace(' ', '_')) else: return ':%s' % (str(box_name).replace(' ', '_')) diff --git a/TurtleArt/talogo.py b/TurtleArt/talogo.py index 91ae153..069a871 100644 --- a/TurtleArt/talogo.py +++ b/TurtleArt/talogo.py @@ -124,7 +124,6 @@ class LogoCode: self.def_prim(p, DEFPRIM[p][0], DEFPRIM[p][1], DEFPRIM[p][2]) self.symtype = type(self._intern('print')) - self.listtype = type([]) self.symnothing = self._intern('%nothing%') self.symopar = self._intern('(') self.iline = None @@ -248,7 +247,7 @@ class LogoCode: self.tw.showblocks() self.tw.running_blocks = False return None - if type(convert(x, float, False)) == float: + if isinstance(convert(x, float, False), float): if int(float(x)) == x: x = int(x) self.stacks['stack3' + str(x)] = self._readline(code) @@ -291,8 +290,7 @@ class LogoCode: code.append(float(ord(blk.values[0][0]))) elif blk.name == 'string' or \ blk.name == 'title': # deprecated block - if type(blk.values[0]) == float or \ - type(blk.values[0]) == int: + if isinstance(blk.values[0], (float, int)): if int(blk.values[0]) == blk.values[0]: blk.values[0] = int(blk.values[0]) code.append('#s' + str(blk.values[0])) @@ -342,7 +340,7 @@ class LogoCode: while line: token = line.pop(0) bindex = None - if type(token) == tuple: + if isinstance(token, tuple): (token, bindex) = token if isNumberType(token): res.append(token) @@ -358,7 +356,7 @@ class LogoCode: res.append(self._readline(line)) elif token == ']': return res - elif bindex is None or type(bindex) is not int: + elif bindex is None or not isinstance(bindex, int): res.append(self._intern(token)) else: res.append((self._intern(token), bindex)) @@ -406,7 +404,7 @@ class LogoCode: while self.iline: token = self.iline[0] self.bindex = None - if type(token) == tuple: + if isinstance(token, tuple): (token, self.bindex) = self.iline[0] # If the blocks are visible, highlight the current block. @@ -425,7 +423,7 @@ class LogoCode: # 'Stand-alone' booleans are handled here. if token == self.symopar: token = self.iline[1] - if type(token) == tuple: + if isinstance(token, tuple): (token, self.bindex) = self.iline[1] # Process the token and any arguments. @@ -456,11 +454,11 @@ class LogoCode: """ Evaluate the next token on the line of code we are processing. """ token = self.iline.pop(0) bindex = None - if type(token) == tuple: + if isinstance(token, tuple): (token, bindex) = token # Either we are processing a symbol or a value. - if type(token) == self.symtype: + if isinstance(token, self.symtype): # We highlight blocks here in case an error occurs... if not self.tw.hide and bindex is not None: self.tw.block_list.list[bindex].highlight() @@ -492,7 +490,7 @@ class LogoCode: yield True self.arglist.append(self.iresult) if self.cfun.rprim: - if type(self.cfun.fcn) == self.listtype: + if isinstance(self.cfun.fcn, list): # debug_output('evalsym rprim list: %s' % (str(token)), # self.tw.running_sugar) self.icall(self._ufuncall, self.cfun.fcn) @@ -588,7 +586,7 @@ class LogoCode: def _prim_define(self, name, body): """ Define a primitive """ - if type(name) is not self.symtype: + if not isinstance(name, self.symtype): name = self._intern(name) name.nargs, name.fcn = 0, body name.rprim = True @@ -613,11 +611,11 @@ class LogoCode: def int(self, n): """ Raise an error if n doesn't convert to int. """ - if type(n) == int: + if isinstance(n, int): return n - elif type(n) == float: + elif isinstance(n, float): return int(n) - elif type(n) == str: + elif isinstance(n, str): return int(ord(n[0])) else: self.tw.showblocks() @@ -655,7 +653,7 @@ class LogoCode: else: block.resize() elif self.update_values: - if type(value) == float: + if isinstance(value, float): valstring = str(round_int(value)).replace('.', self.tw.decimal_point) else: diff --git a/TurtleArt/tapalette.py b/TurtleArt/tapalette.py index 2d903e5..cda2b79 100644 --- a/TurtleArt/tapalette.py +++ b/TurtleArt/tapalette.py @@ -138,7 +138,7 @@ class Palette(): else: i = len(palette_names) - if position is not None and type(position) is int and position < i: + if position is not None and isinstance(position, int) and position < i: i = position if self._name not in palette_names: @@ -193,7 +193,7 @@ class Palette(): if not hidden: first_arg = None if special_name is None: - if type(label) == list: + if isinstance(label, list): first_arg = label[0] else: first_arg = label @@ -294,7 +294,7 @@ class Block(): debug_output('%s already in palette %s, skipping...' % ( self._name, self._palette)) else: - if position is not None and type(position) is int and \ + if position is not None and isinstance(position, int) and \ position < len(palette_blocks[i]): palette_blocks[i].insert(position, self._name) else: @@ -365,13 +365,13 @@ class Block(): self._special_name = name def set_label(self, label): - if type(label) == type([]): + if isinstance(label, list): self._label = label[:] else: self._label = [label] def set_default(self, default): - if type(default) == type([]): + if isinstance(default, list): self._default = default[:] else: self._default = [default] diff --git a/TurtleArt/taturtle.py b/TurtleArt/taturtle.py index 7acb90e..3176eda 100644 --- a/TurtleArt/taturtle.py +++ b/TurtleArt/taturtle.py @@ -61,7 +61,7 @@ class Turtles: else: if colors == None: Turtle(self, k) - elif type(colors) in [list, tuple]: + elif isinstance(colors, (list, tuple)): Turtle(self, k, colors) else: Turtle(self, k, colors.split(',')) diff --git a/TurtleArt/tautils.py b/TurtleArt/tautils.py index 69814c0..caeb047 100644 --- a/TurtleArt/tautils.py +++ b/TurtleArt/tautils.py @@ -110,9 +110,7 @@ def chr_to_ord(x): def strtype(x): ''' Is x a string type? ''' - if type(x) == str: - return True - if type(x) == unicode: + if isinstance(x, (str, unicode)): return True return False @@ -174,7 +172,7 @@ def json_load(text): def _tuplify(tup): ''' Convert to tuples ''' - if type(tup) is not list: + if not isinstance(tup, list): return tup return tuple(map(_tuplify, tup)) @@ -268,9 +266,9 @@ def data_from_file(ta_file): def data_from_string(text): ''' JSON load data from a string. ''' - if type(text) == str: + if isinstance(text, str): return json_load(text.replace(']],\n', ']], ')) - elif type(text) == unicode: + elif isinstance(text, unicode): text = text.encode('ascii', 'replace') return json_load(text.replace(']],\n', ']], ')) else: @@ -314,7 +312,7 @@ def save_picture(canvas, file_name): cr = cairo.Context(img_surface) cr.set_source_surface(x_surface) cr.paint() - if type(file_name) == unicode: + if isinstance(file_name, unicode): img_surface.write_to_png(str(file_name.encode('ascii', 'replace'))) else: img_surface.write_to_png(str(file_name)) @@ -523,7 +521,7 @@ def show_button_hit(spr, x, y): def numeric_arg(value): ''' Dock test: looking for a numeric value ''' - if type(convert(value, float)) is float: + if isinstance(convert(value, float), float): return True return False @@ -699,7 +697,7 @@ def find_blk_below(blk, namelist): ''' Find a specific block below this block. ''' if blk == None or len(blk.connections) == 0: return - if type(namelist) != list: + if not isinstance(namelist, list): namelist = [namelist] group = find_group(blk) for gblk in group: diff --git a/TurtleArt/tawindow.py b/TurtleArt/tawindow.py index d81b578..906a7d8 100644 --- a/TurtleArt/tawindow.py +++ b/TurtleArt/tawindow.py @@ -101,7 +101,7 @@ class TurtleArtWindow(): self.gst_available = GST_AVAILABLE self.running_sugar = False self.nick = None - if type(canvas_window) == gtk.DrawingArea: + if isinstance(canvas_window, gtk.DrawingArea): self.interactive_mode = True self.window = canvas_window self.window.set_flags(gtk.CAN_FOCUS) @@ -1412,13 +1412,13 @@ before making changes to your Turtle Blocks program')) # First look for a hat with _('action') as its label found_the_action_block = False bname = _('action') - if type(bname) == unicode: + if isinstance(bname, unicode): bname = bname.encode('ascii', 'replace') for sblk in similars: cblk = sblk.connections[1] if cblk is not None: blabel = cblk.spr.labels[0] - if type(blabel) == unicode: + if isinstance(blabel, unicode): blabel = blabel.encode('ascii', 'replace') if bname == blabel: found_the_action_block = True @@ -1547,9 +1547,9 @@ before making changes to your Turtle Blocks program')) def _update_action_names(self, name): ''' change the label on action blocks of the same name ''' - if type(name) in [float, int]: + if isinstance(name, (float, int)): return - if type(name) == 'unicode': + if isinstance(name, unicode): name = name.encode('ascii', 'replace') for blk in self.just_blocks(): if self._action_name(blk, hat=False): @@ -1565,9 +1565,9 @@ before making changes to your Turtle Blocks program')) def _update_box_names(self, name): ''' change the label on box blocks of the same name ''' - if type(name) in [float, int]: + if isinstance(name, (float, int)): return - if type(name) == 'unicode': + if isinstance(name, unicode): name = name.encode('ascii', 'replace') for blk in self.just_blocks(): if self._box_name(blk, storein=False): @@ -1583,9 +1583,9 @@ before making changes to your Turtle Blocks program')) def _update_storein_names(self, name): ''' change the label on storin blocks of the same name ''' - if type(name) in [float, int]: + if isinstance(name, (float, int)): return - if type(name) == 'unicode': + if isinstance(name, unicode): name = name.encode('ascii', 'replace') for blk in self.just_blocks(): if self._box_name(blk, storein=True): @@ -1608,11 +1608,11 @@ before making changes to your Turtle Blocks program')) # (2) The list of block styles # (3) The list of proto blocks on the palette # (4) The list of block names - if type(name) == unicode: + if isinstance(name, unicode): name = name.encode('ascii', 'replace') - if type(old) == unicode: + if isinstance(old, unicode): old = old.encode('ascii', 'replace') - if type(new) == unicode: + if isinstance(new, unicode): new = new.encode('ascii', 'replace') if old == new: @@ -1951,11 +1951,11 @@ before making changes to your Turtle Blocks program')) if argname == 'media': argname = 'journal' elif argname == 'number' and \ - (type(argvalue) is str or type(argvalue) is unicode): + isinstance(argvalue, (str, unicode)): argname = 'string' elif argname == 'string' and \ name in block_styles['number-style-1strarg'] and \ - type(argvalue) in [int, float]: + isinstance(argvalue, (float, int)): argname = 'number' elif argname == 'bool': argname = argvalue @@ -3536,7 +3536,7 @@ may not terminate.', False) if blk[1] == 'turtle': self.load_turtle(blk) return True - elif type(blk[1]) in [list, tuple] and blk[1][0] == 'turtle': + elif isinstance(blk[1], (list, tuple)) and blk[1][0] == 'turtle': if blk[1][1] == DEFAULT_TURTLE: if self.nick is not None and self.nick is not '': self.load_turtle(blk, self.nick) @@ -3565,9 +3565,9 @@ may not terminate.', False) # A block is saved as: (i, (btype, value), x, y, (c0,... cn)) # The x, y position is saved/loaded for backward compatibility btype, value = b[1], None - if type(btype) == tuple: + if isinstance(btype, tuple): btype, value = btype - elif type(btype) == list: + elif isinstance(btype, list): btype, value = btype[0], btype[1] # Replace deprecated sandwich blocks @@ -3703,7 +3703,7 @@ may not terminate.', False) self.set_userdefined(blk) if btype == 'string' and blk.spr is not None: value = blk.values[0] - if type(value) == unicode: + if isinstance(value, unicode): value = value.encode('ascii', 'replace') blk.spr.set_label(value.replace('\n', RETURN)) elif btype == 'start': # block size is saved in start block @@ -3768,7 +3768,7 @@ may not terminate.', False) blk.expand_in_x(value) elif btype in EXPANDABLE_FLOW: if value is not None: - if type(value) is int: + if isinstance(value, int): blk.expand_in_y(value) else: # thenelse blocks blk.expand_in_y(value[0]) @@ -3924,8 +3924,8 @@ may not terminate.', False) else: formatting = '%s — %s: %0.2f %s: %0.2f %s: %0.2f' self.parent.set_title( - formatting % (_('Turtle Art'), _('xcor'), x, _('ycor'), y, - _('heading'), h)) + formatting % (self.activity.name, _('xcor'), x, + _('ycor'), y, _('heading'), h)) self.update_counter = 0 def showlabel(self, shp, label=''): @@ -4156,16 +4156,16 @@ may not terminate.', False) def _find_proto_name(self, name, label, palette='blocks'): ''' Look for a protoblock with this name ''' - if type(name) == unicode: + if isinstance(name, unicode): name = name.encode('ascii', 'replace') - if type(label) == unicode: + if isinstance(label, unicode): label = label.encode('ascii', 'replace') i = palette_name_to_index(palette) for blk in self.palettes[i]: blk_label = blk.spr.labels[0] - if type(blk.name) == unicode: + if isinstance(blk.name, unicode): blk.name = blk.name.encode('ascii', 'replace') - if type(blk_label) == unicode: + if isinstance(blk_label, unicode): blk_label = blk_label.encode('ascii', 'replace') if blk.name == name and blk_label == label: return True @@ -4178,9 +4178,9 @@ may not terminate.', False) def _new_stack_block(self, name): ''' Add a stack block to the 'blocks' palette ''' - if type(name) in [float, int]: + if isinstance(name, (float, int)): return - if type(name) == unicode: + if isinstance(name, unicode): name = name.encode('ascii', 'replace') if name == _('action'): return @@ -4205,9 +4205,9 @@ may not terminate.', False) def _new_box_block(self, name): ''' Add a box block to the 'blocks' palette ''' - if type(name) in [float, int]: + if isinstance(name, (float, int)): return - if type(name) == unicode: + if isinstance(name, unicode): name = name.encode('ascii', 'replace') if name == _('my box'): return @@ -4233,9 +4233,9 @@ may not terminate.', False) def _new_storein_block(self, name): ''' Add a storin block to the 'blocks' palette ''' - if type(name) in [float, int]: + if isinstance(name, (float, int)): return - if type(name) == unicode: + if isinstance(name, unicode): name = name.encode('ascii', 'replace') if name == _('my box'): return @@ -4263,7 +4263,7 @@ variable')) def _prim_stack(self, x): ''' Process a named stack ''' - if type(convert(x, float, False)) == float: + if isinstance(convert(x, float, False), float): if int(float(x)) == x: x = int(x) if 'stack3' + str(x) not in self.lc.stacks or \ @@ -4278,7 +4278,7 @@ variable')) def _prim_box(self, x): ''' Retrieve value from named box ''' - if type(convert(x, float, False)) == float: + if isinstance(convert(x, float, False), float): if int(float(x)) == x: x = int(x) try: @@ -4289,7 +4289,7 @@ variable')) def _prim_setbox(self, name, x, val): """ Define value of named box """ if x is not None: - if type(convert(x, float, False)) == float: + if isinstance(convert(x, float, False), float): if int(float(x)) == x: x = int(x) self.lc.boxes[name + str(x)] = val diff --git a/pysamples/grecord.py b/pysamples/grecord.py index 84b1a5c..c53857d 100644 --- a/pysamples/grecord.py +++ b/pysamples/grecord.py @@ -202,7 +202,7 @@ def myblock(tw, arg): tw.grecord = Grecord(tw) # Sometime we need to parse multiple arguments, e.g., save, savename - save_name = _('Turtle Art') + ' ' + _('sound') + save_name = '%s_%s' % (tw.activity.name, _('sound')) if type(arg) == type([]): cmd = arg[0].lower() if len(arg) > 1: diff --git a/turtleblocks.py b/turtleblocks.py index 2fe9b45..ed2ebce 100755 --- a/turtleblocks.py +++ b/turtleblocks.py @@ -496,12 +496,12 @@ class TurtleMain(): save_type = '.lg' filename, self.tw.load_save_folder = get_save_name(save_type, self.tw.load_save_folder, 'logosession') - if type(filename) == unicode: - f = file(filename.encode('ascii', 'replace'), 'w') - else: + if isinstance(filename, unicode): + filename = filename.encode('ascii', 'replace') + if filename is not None: f = file(filename, 'w') - f.write(logocode) - f.close() + f.write(logocode) + f.close() def _do_resize_cb(self, widget, factor): ''' Callback to resize blocks. ''' -- cgit v0.9.1