Error Occurs: Replace a character in a String
Jimbo
nilly16 at yahoo.com
Sun Apr 11 01:01:51 EDT 2010
Hello, I am getting an error in my python script when I try to change
a character in a string. [b]But I dont know why or what to do to fix
it?[/b]
I have commented in my code where the error occurs
[code]
def format_file(filename):
HTML_file = open(filename,'r')
HTML_source = HTML_file.read()
HTML_file.close()
x = 0
# Format all ID's & classes correctly
temp_buf = HTML_source.lower()
class_occurence = temp_buf.count('class')
ID_occurence = temp_buf.count('id')
for n in range(class_occurence):
hit = temp_buf.find('class')
if not hit==-1:
temp_buf[hit] = '~' # Error: 'str' object does not support
item assignment
x = hit+5
# delete any spaces until we reach a letter or number
while x<temp_buf[x]:
if temp_buf[x] == ' ':
tempbuf[x] = ''
HTML_source[x] = ''
elif temp_buf[x] == '=':
pass
#elif temp_buf[x] == "'" or temp_buf[x] == '"'
isalpha(temp_buf[x])
else:
break
x += 1
[/code]
More information about the Python-list
mailing list