| | |
I don't know what is causing this error...please help
Thread Solved |
•
•
Join Date: Nov 2009
Posts: 61
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 |
abrupt ansi anti apache approximation array assignment avogadro backend beginner binary bluetooth book builtin calculator character code converter countpasswordentry curved customdialog dan08 dictionaries dictionary dynamic examples exe file float format function gnu graphics gui heads homework ideas import inches input java launcher library line lines linux list lists loop mouse mysqlquery number numbers numeric output parsing path phonebook plugin pointer port prime programming progressbar projects py2exe pygame python random recursion redirect scrolledtext software statictext statistics string strings sum table terminal text textarea thread threading time tlapse trick tricks tuple tutorial twoup ubuntu unicode urllib urllib2 variable wordgame write wxpython xlib





