HI everybody.
In an effort to teach myself the basics of Python, I set out to create a script that would read a PHP file, remove any comments and then save it to another location.
I've got it all pretty much worked out now, except...
I have this re.sub regex that is meant to remove /*...*/ comments.
It works fine on small files, but causes Python to hang on larger files.
(By large I mean over 20kb files, sometimes containing a few thousand lines of code)
[code=python]
inFile = open(inPath + cfile)
outFile = open(outPath + cfile, "w")
inText = inFile.read()
outText = re.sub("\/\*(.|\s)*\*\/", "", inText)
outFile.write(o utText)
inFile.close()
outFile.close()
[/code]
Running this causes Python to hang, and when closing it (crl+c) this is what I get:
I'm running Python 2.5.2 on Ubuntu 8.04.
Any input would be greatly appreciated.
Thanks
In an effort to teach myself the basics of Python, I set out to create a script that would read a PHP file, remove any comments and then save it to another location.
I've got it all pretty much worked out now, except...
I have this re.sub regex that is meant to remove /*...*/ comments.
It works fine on small files, but causes Python to hang on larger files.
(By large I mean over 20kb files, sometimes containing a few thousand lines of code)
[code=python]
inFile = open(inPath + cfile)
outFile = open(outPath + cfile, "w")
inText = inFile.read()
outText = re.sub("\/\*(.|\s)*\*\/", "", inText)
outFile.write(o utText)
inFile.close()
outFile.close()
[/code]
Running this causes Python to hang, and when closing it (crl+c) this is what I get:
Code:
Traceback (most recent call last):
File "./scandir.py", line 60, in <module>
listdirrec(inPath, outPath)
File "./scandir.py", line 44, in listdirrec
listdirrec(inPath + entry +"/", outPath + entry +"/")
File "./scandir.py", line 53, in listdirrec
outText = re.sub("\/\*(.|\s)*\*\/", "", inText)
File "/usr/lib/python2.5/re.py", line 150, in sub
return _compile(pattern, 0).sub(repl, string, count)
KeyboardInterrupt
Any input would be greatly appreciated.
Thanks
Comment