I\'m trying to write a python function not using any modules that will take a string that has tabs and replace the tabs with spaces appropriate for an inputted tabstop size.
I think Remi's answer is the simplest but it has a bug, it doesn't account for the case when you are already on a "tab stop" column. Tom Swirly pointed this out in the comments. Here's a tested fix to his suggestion:
def replace_tab(s, tabstop = 4):
result = str()
for c in s:
if c == '\t':
result += ' '
while ((len(result) % tabstop) != 0):
result += ' '
else:
result += c
return result