| | |
I don't know what is causing this error...please help
Thread Solved |
•
•
Join Date: Nov 2009
Posts: 58
Reputation:
Solved Threads: 0
Hi
I am ery new to Python. I've only started using it yesterday. Please keep that in mind, as the error might seem simple to you, but I can't understand it.
I am trying to run the following piece of code:
When I check the code using Python's built-in checker, everyhitng checks out fine. However, when I use the console to run the code, the following text is all that appears(It doesnt write to the file):
Traceback (most recent call last):
File "advanced.py", line 14, in (module)
out.write(special.sub(escape, text))
TypeError: expected string of buffer
I don't know if this is vital information: the file I am reading from contains XML, but it is in a text file, so I assumed it would handle everything as text. The goal of the code is to escape the backslashes in the XML.
Thanks
I am ery new to Python. I've only started using it yesterday. Please keep that in mind, as the error might seem simple to you, but I can't understand it.
I am trying to run the following piece of code:
Python Syntax (Toggle Plain Text)
import re foo = open("PREFIX.txt", "r+") text = foo.read # Read in from file foo.close() special = re.compile(r"[etn]") # Not sure what this does. def escape(match): # Specifies that any \ has to be escaped return "\\" + match.group(0) if __name__ == "__main__": out = open("WRITE.txt", "w") out.write(special.sub(escape, text)) # Write to file out.close()
When I check the code using Python's built-in checker, everyhitng checks out fine. However, when I use the console to run the code, the following text is all that appears(It doesnt write to the file):
Traceback (most recent call last):
File "advanced.py", line 14, in (module)
out.write(special.sub(escape, text))
TypeError: expected string of buffer
I don't know if this is vital information: the file I am reading from contains XML, but it is in a text file, so I assumed it would handle everything as text. The goal of the code is to escape the backslashes in the XML.
Thanks
![]() |
Similar Threads
- Python extension causing an error with numpy (Python)
- windows xp pro stop error, happens after only a few minutes of loading up (Troubleshooting Dead Machines)
- compile error (C++)
- Stmgr error in msvcrt.dll (Windows 95 / 98 / Me)
- Stop Error On Start-up (Windows NT / 2000 / XP)
- error pop-ups?? (Windows NT / 2000 / XP)
- Re: Hijack log-WMP Internal application error ha occured (Viruses, Spyware and other Nasties)
- Bogus "page cannot be displayed" error on URL http:/// (Viruses, Spyware and other Nasties)
- New Hardware Causing Error (Windows NT / 2000 / XP)
Other Threads in the Python Forum
- Previous Thread: problem with some functions
- Next Thread: Help with Pascal Triangle Program Please
| Thread Tools | Search this Thread |
address alarm anydbm app beginner changecolor cipher clear conversion coordinates corners curves cx-freeze data definedlines development dictionary directory dynamic events excel feet file float format function generator getvalue halp handling homework images import input ip itunes java keycontrol line linux list lists loan loop maintain matching maze millimeter mouse number numbers output parsing path port prime programming py2exe pygame pymailer python queue random rational raw_input recursion recursive screensaverloopinactive script scrolledtext searchingfile slicenotation split ssh string strings tails text threading time tlapse tooltip tuple tutorial type ubuntu unicode url urllib urllib2 valueerror variable variables ventrilo vigenere web webservice word wxpython xlwt





