Re: Replace and inserting strings within .txt files with the use of regex

2010-08-16 Thread Νίκος
On 10 Αύγ, 01:43, MRAB wrote: > Íßêïò wrote: > > D:\>convert.py > >   File "D:\convert.py", line 34 > > SyntaxError: Non-ASCII character '\xce' in file D:\convert.py on line > > 34, but no > >  encoding declared; seehttp://www.python.org/peps/pep-0263.htmlfor > > details > > > D:\> > > > What does

Re: Replace and inserting strings within .txt files with the use of regex

2010-08-11 Thread Νίκος
On 10 Αύγ, 18:12, MRAB wrote: > Νίκος wrote: > > [snip] > > > > > > > The ID number of each php page was contained in the old php code > > within this string > > > PageID = some_number > > > So instead of create a new ID number for eaqch page i have to pull out > > this number to store to the begi

Re: Replace and inserting strings within .txt files with the use of regex

2010-08-10 Thread MRAB
Νίκος wrote: [snip] The ID number of each php page was contained in the old php code within this string PageID = some_number So instead of create a new ID number for eaqch page i have to pull out this number to store to the beginnign to the file as comment line, because it has direct relations

Re: Replace and inserting strings within .txt files with the use of regex

2010-08-10 Thread Νίκος
Please help me with these last changes before i try to perform an overall change. its almost done! -- http://mail.python.org/mailman/listinfo/python-list

Re: Replace and inserting strings within .txt files with the use of regex

2010-08-09 Thread Νίκος
On 10 Αύγ, 01:43, MRAB wrote: > Íßêïò wrote: > > D:\>convert.py > >   File "D:\convert.py", line 34 > > SyntaxError: Non-ASCII character '\xce' in file D:\convert.py on line > > 34, but no > >  encoding declared; seehttp://www.python.org/peps/pep-0263.htmlfor > > details > > > D:\> > > > What does

Re: Replace and inserting strings within .txt files with the use of regex

2010-08-09 Thread MRAB
Νίκος wrote: D:\>convert.py File "D:\convert.py", line 34 SyntaxError: Non-ASCII character '\xce' in file D:\convert.py on line 34, but no encoding declared; see http://www.python.org/peps/pep-0263.html for details D:\> What does it refering too? what character cannot be identified? Line 34

Re: Replace and inserting strings within .txt files with the use of regex

2010-08-09 Thread MRAB
Νίκος wrote: On 9 Αύγ, 23:17, MRAB wrote: Νίκος wrote: On 9 Αύγ, 21:05, Thomas Jollans wrote: On Monday 09 August 2010, it occurred to Νίκος to exclaim: On 9 Αύγ, 19:21, Peter Otten <__pete...@web.de> wrote: Νίκος wrote: Please tell me that no matter what weird charhs has inside ic an sti

Re: Replace and inserting strings within .txt files with the use of regex

2010-08-09 Thread Νίκος
D:\>convert.py File "D:\convert.py", line 34 SyntaxError: Non-ASCII character '\xce' in file D:\convert.py on line 34, but no encoding declared; see http://www.python.org/peps/pep-0263.html for details D:\> What does it refering too? what character cannot be identified? Line 34 is: src_data

Re: Replace and inserting strings within .txt files with the use of regex

2010-08-09 Thread Νίκος
On 9 Αύγ, 23:28, MRAB wrote: > Íßêïò wrote: > > On 9 Áýã, 10:07, Íßêïò wrote: > >> Now the code looks as follows: > > >> = > >> #!/usr/bin/python > > >> import re, os, sys > > >> id = 0  # unique page_id > > >> for currdir, files, dirs in os.walk('test'): > > >>      

Re: Replace and inserting strings within .txt files with the use of regex

2010-08-09 Thread Νίκος
On 9 Αύγ, 23:17, MRAB wrote: > Νίκος wrote: > > On 9 Αύγ, 21:05, Thomas Jollans wrote: > >> On Monday 09 August 2010, it occurred to Νίκος to exclaim: > > >>> On 9 Αύγ, 19:21, Peter Otten <__pete...@web.de> wrote: > Νίκος wrote: > > Please tell me that no matter what weird charhs has ins

Re: Replace and inserting strings within .txt files with the use of regex

2010-08-09 Thread MRAB
Νίκος wrote: On 9 Αύγ, 10:07, Νίκος wrote: Now the code looks as follows: = #!/usr/bin/python import re, os, sys id = 0 # unique page_id for currdir, files, dirs in os.walk('test'): for f in files: if f.endswith('php'): [snip] I jus

Re: Replace and inserting strings within .txt files with the use of regex

2010-08-09 Thread MRAB
Νίκος wrote: On 9 Αύγ, 21:05, Thomas Jollans wrote: On Monday 09 August 2010, it occurred to Νίκος to exclaim: On 9 Αύγ, 19:21, Peter Otten <__pete...@web.de> wrote: Νίκος wrote: Please tell me that no matter what weird charhs has inside ic an still open thosie fiels and make the neccessary

Re: Replace and inserting strings within .txt files with the use of regex

2010-08-09 Thread Νίκος
On 9 Αύγ, 10:07, Νίκος wrote: > Now the code looks as follows: > > = > #!/usr/bin/python > > import re, os, sys > > id = 0  # unique page_id > > for currdir, files, dirs in os.walk('test'): > >         for f in files: > >                 if f.endswith('php'): > >      

Re: Replace and inserting strings within .txt files with the use of regex

2010-08-09 Thread Νίκος
On 9 Αύγ, 21:05, Thomas Jollans wrote: > On Monday 09 August 2010, it occurred to Νίκος to exclaim: > > > > > > > On 9 Αύγ, 19:21, Peter Otten <__pete...@web.de> wrote: > > > Νίκος wrote: > > > > Please tell me that no matter what weird charhs has inside ic an still > > > > open thosie fiels and m

Re: Replace and inserting strings within .txt files with the use of regex

2010-08-09 Thread Νίκος
On 8 Αύγ, 20:29, John S wrote: > When replacing text in an HTML document with re.sub, you want to use > the re.S (singleline) option; otherwise your pattern won't match when > the opening tag is on one line and the closing is on another. Thats exactly the problem iam facing now with this stateme

Re: Replace and inserting strings within .txt files with the use of regex

2010-08-09 Thread Thomas Jollans
On Monday 09 August 2010, it occurred to Νίκος to exclaim: > On 9 Αύγ, 19:21, Peter Otten <__pete...@web.de> wrote: > > Νίκος wrote: > > > Please tell me that no matter what weird charhs has inside ic an still > > > open thosie fiels and make the neccessary replacements. > > > > Go back to 2.6 for

Re: Replace and inserting strings within .txt files with the use of regex

2010-08-09 Thread Νίκος
On 9 Αύγ, 19:21, Peter Otten <__pete...@web.de> wrote: > Νίκος wrote: > > Please tell me that no matter what weird charhs has inside ic an still > > open thosie fiels and make the neccessary replacements. > > Go back to 2.6 for the moment and defer learning about unicode until you're > done with th

Re: Replace and inserting strings within .txt files with the use of regex

2010-08-09 Thread Peter Otten
Νίκος wrote: > Please tell me that no matter what weird charhs has inside ic an still > open thosie fiels and make the neccessary replacements. Go back to 2.6 for the moment and defer learning about unicode until you're done with the conversion job. -- http://mail.python.org/mailman/listinfo/py

Re: Replace and inserting strings within .txt files with the use of regex

2010-08-09 Thread Νίκος
Please tell me that no matter what weird charhs has inside ic an still open thosie fiels and make the neccessary replacements. -- http://mail.python.org/mailman/listinfo/python-list

Re: Replace and inserting strings within .txt files with the use of regex

2010-08-09 Thread MRAB
Νίκος wrote: On 9 Αύγ, 16:52, MRAB wrote: Νίκος wrote: On 8 Αύγ, 17:59, Thomas Jollans wrote: Two problems here: str.replace doesn't use regular expressions. You'll have to use the re module to use regexps. (the re.sub function to be precise) '.' matches a single character. Any character, b

Re: Replace and inserting strings within .txt files with the use of regex

2010-08-09 Thread Νίκος
On 9 Αύγ, 16:52, MRAB wrote: > Νίκος wrote: > > On 8 Αύγ, 17:59, Thomas Jollans wrote: > > >> Two problems here: > > >> str.replace doesn't use regular expressions. You'll have to use the re > >> module to use regexps. (the re.sub function to be precise) > > >> '.'  matches a single character. An

Re: Replace and inserting strings within .txt files with the use of regex

2010-08-09 Thread Νίκος
On 9 Αύγ, 13:47, Peter Otten <__pete...@web.de> wrote: > Νίκος wrote: > > On 9 Αύγ, 13:06, Peter Otten <__pete...@web.de> wrote: > > >> > So since its utf-8 what the problem of opening it? > > >> Python says it's not, and I tend to believe it. > > > You are right! > > > I tried to do the same exact

Re: Replace and inserting strings within .txt files with the use of regex

2010-08-09 Thread MRAB
Νίκος wrote: On 8 Αύγ, 17:59, Thomas Jollans wrote: Two problems here: str.replace doesn't use regular expressions. You'll have to use the re module to use regexps. (the re.sub function to be precise) '.' matches a single character. Any character, but only one. '.*' matches as many characte

Re: Replace and inserting strings within .txt files with the use of regex

2010-08-09 Thread Peter Otten
Νίκος wrote: > On 9 Αύγ, 13:06, Peter Otten <__pete...@web.de> wrote: > >> > So since its utf-8 what the problem of opening it? >> >> Python says it's not, and I tend to believe it. > > You are right! > > I tried to do the same exact openign via IDLE enviroment and i goth > the encoding of the

Re: Replace and inserting strings within .txt files with the use of regex

2010-08-09 Thread Νίκος
On 9 Αύγ, 13:06, Peter Otten <__pete...@web.de> wrote: > > So since its utf-8 what the problem of opening it? > > Python says it's not, and I tend to believe it. You are right! I tried to do the same exact openign via IDLE enviroment and i goth the encoding of the file from there! >>> open("d:\

Re: Replace and inserting strings within .txt files with the use of regex

2010-08-09 Thread Peter Otten
Νίκος wrote: > On 9 Αύγ, 11:45, Peter Otten <__pete...@web.de> wrote: >> Νίκος wrote: >> > On 9 Αύγ, 10:38, Peter Otten <__pete...@web.de> wrote: >> >> Νίκος wrote: >> >> > Now the code looks as follows: >> >> > for currdir, files, dirs in os.walk('test'): >> >> >> > for f in files: >> >> >> > if

Re: Replace and inserting strings within .txt files with the use of regex

2010-08-09 Thread Νίκος
On 9 Αύγ, 11:45, Peter Otten <__pete...@web.de> wrote: > Νίκος wrote: > > On 9 Αύγ, 10:38, Peter Otten <__pete...@web.de> wrote: > >> Νίκος wrote: > >> > Now the code looks as follows: > >> > for currdir, files, dirs in os.walk('test'): > > >> > for f in files: > > >> > if f.endswith('php'): > > >>

Re: Replace and inserting strings within .txt files with the use of regex

2010-08-09 Thread Peter Otten
Νίκος wrote: > On 9 Αύγ, 10:38, Peter Otten <__pete...@web.de> wrote: >> Νίκος wrote: >> > Now the code looks as follows: >> > for currdir, files, dirs in os.walk('test'): >> >> > for f in files: >> >> > if f.endswith('php'): >> >> > # get abs path to filename >> > src_f = join(currdir, f) >> > I

Re: Replace and inserting strings within .txt files with the use of regex

2010-08-09 Thread Νίκος
On 9 Αύγ, 10:38, Peter Otten <__pete...@web.de> wrote: > Νίκος wrote: > > Now the code looks as follows: > > for currdir, files, dirs in os.walk('test'): > > >         for f in files: > > >                 if f.endswith('php'): > > >                         # get abs path to filename > >          

Re: Replace and inserting strings within .txt files with the use of regex

2010-08-09 Thread Peter Otten
Νίκος wrote: > Now the code looks as follows: > for currdir, files, dirs in os.walk('test'): > > for f in files: > > if f.endswith('php'): > > # get abs path to filename > src_f = join(currdir, f) > I just tried to test i

Re: Replace and inserting strings within .txt files with the use of regex

2010-08-09 Thread Νίκος
Now the code looks as follows: = #!/usr/bin/python import re, os, sys id = 0 # unique page_id for currdir, files, dirs in os.walk('test'): for f in files: if f.endswith('php'): # get abs path to filename

Re: Replace and inserting strings within .txt files with the use of regex

2010-08-08 Thread Νίκος
On 8 Αύγ, 17:59, Thomas Jollans wrote: > Two problems here: > > str.replace doesn't use regular expressions. You'll have to use the re > module to use regexps. (the re.sub function to be precise) > > '.'  matches a single character. Any character, but only one. > '.*' matches as many characters a

Re: Replace and inserting strings within .txt files with the use of regex

2010-08-08 Thread Joel Goldstick
� wrote: Hello dear Pythoneers, I have over 500 .php web pages in various subfolders under 'data' folder that i have to rename to .html and and ditch the '' tages from within and also insert a very first line of where id must be an identification unique number of every page for counter tracking

Re: Replace and inserting strings within .txt files with the use of regex

2010-08-08 Thread John S
On Aug 8, 10:59 am, Thomas Jollans wrote: > On 08/08/2010 04:06 PM, Νίκος wrote: > > > > > > > On 8 Αύγ, 15:40, Thomas Jollans wrote: > >> On 08/08/2010 01:41 PM, Νίκος wrote: > > >>> I was so dizzy and confused yesterday that i forgot to metnion that > >>> not only i need removal of php openign

Re: Replace and inserting strings within .txt files with the use of regex

2010-08-08 Thread Thomas Jollans
On 08/08/2010 04:06 PM, Νίκος wrote: > On 8 Αύγ, 15:40, Thomas Jollans wrote: >> On 08/08/2010 01:41 PM, Νίκος wrote: >> >>> I was so dizzy and confused yesterday that i forgot to metnion that >>> not only i need removal of php openign and closing tags but whaevers >>> data lurks inside those tags

Re: Replace and inserting strings within .txt files with the use of regex

2010-08-08 Thread Νίκος
On 8 Αύγ, 15:40, Thomas Jollans wrote: > On 08/08/2010 01:41 PM, Νίκος wrote: > > > I was so dizzy and confused yesterday that i forgot to metnion that > > not only i need removal of php openign and closing tags but whaevers > > data lurks inside those tags as well ebcause now with the 'counter.py

Re: Replace and inserting strings within .txt files with the use of regex

2010-08-08 Thread Thomas Jollans
On 08/08/2010 01:41 PM, Νίκος wrote: > I was so dizzy and confused yesterday that i forgot to metnion that > not only i need removal of php openign and closing tags but whaevers > data lurks inside those tags as well ebcause now with the 'counter.py' > script i wrote the html fiels would open ftm t

Re: Replace and inserting strings within .txt files with the use of regex

2010-08-08 Thread Νίκος
On 8 Αύγ, 13:13, Thomas Jollans wrote: > On 08/08/2010 11:21 AM, Νίκος wrote: > > > Please help me adjust it, if need extra modification for more php tags > > replacing. > > Have you tried it ? I haven't, but I see no immediate reason why it > wouldn't work with multiple PHP blocks. > > > > > > >

Re: Replace and inserting strings within .txt files with the use of regex

2010-08-08 Thread Thomas Jollans
On 08/08/2010 11:21 AM, Νίκος wrote: > Please help me adjust it, if need extra modification for more php tags > replacing. Have you tried it ? I haven't, but I see no immediate reason why it wouldn't work with multiple PHP blocks. > #!/usr/bin/python > > import cgitb; cgitb.enable() > import cgi

Re: Replace and inserting strings within .txt files with the use of regex

2010-08-08 Thread Thomas Jollans
On 08/08/2010 04:46 AM, rantingrick wrote: > *facepalm*! I really must stop Usenet-ing whilst consuming large > volumes of alcoholic beverages. THAT explains a lot. Cheers -- http://mail.python.org/mailman/listinfo/python-list

Re: Replace and inserting strings within .txt files with the use of regex

2010-08-08 Thread Νίκος
Script so far: #!/usr/bin/python import cgitb; cgitb.enable() import cgi, re, os print ( "Content-type: text/html; charset=UTF-8 \n" ) id = 0 # unique page_id for currdir, files, dirs in os.walk('data'): for f in files: if f.endswith('php'): # get abs path to filen

Re: Replace and inserting strings within .txt files with the use of regex

2010-08-08 Thread Νίκος
On 8 Αύγ, 11:09, Steven D'Aprano wrote: > On Sat, 07 Aug 2010 17:20:24 -0700, Νίκος wrote: > > I don't know how to handle such a big data replacing problem and cannot > > play with fire because those 500 pages are my cleints pages and data of > > those filesjust cannot be messes up. > > Take a bac

Re: Replace and inserting strings within .txt files with the use of regex

2010-08-08 Thread Steven D'Aprano
On Sat, 07 Aug 2010 17:20:24 -0700, Νίκος wrote: > I don't know how to handle such a big data replacing problem and cannot > play with fire because those 500 pages are my cleints pages and data of > those filesjust cannot be messes up. Take a backup copy of the files, and only edit the copies. Do

Re: Replace and inserting strings within .txt files with the use of regex

2010-08-07 Thread Νίκος
On 8 Αύγ, 05:56, John S wrote: >"How can I use RE string replacement to find PHP tags and convert them >to Django template tags?" No, not at all John, at least not yet! I have only 1 week that i'm learnign python(changing from php & perl) so i'm very fresh at this beautifull and straighforwrd la

Re: Replace and inserting strings within .txt files with the use of regex

2010-08-07 Thread Νίκος
On 8 Αύγ, 05:42, John S wrote: > If the 500 web pages are PHP only in the sense that there is only one > pair of tags in each file, surrounding the entire content, then > what you ask for is doable. First of all, thank you very much John for your BIG effort to help me(i'm still readign your post

Re: Replace and inserting strings within .txt files with the use of regex

2010-08-07 Thread John S
Even though I just replied above, in reading over the OP's message, I think the OP might be asking: "How can I use RE string replacement to find PHP tags and convert them to Django template tags?" Instead of saying source_contents = source_contents.replace(...) say this instead: import re de

Re: Replace and inserting strings within .txt files with the use of regex

2010-08-07 Thread rantingrick
On Aug 7, 8:42 pm, MRAB wrote: > That should be: > >    data = data.replace('    data = data.replace('?>', '') Yes, Thanks MRAB. I did forget that important detail. > Strings don't have an 'insert' method! *facepalm*! I really must stop Usenet-ing whilst consuming large volumes of alcoholic be

Re: Replace and inserting strings within .txt files with the use of regex

2010-08-07 Thread John S
On Aug 7, 8:20 pm, Νίκος wrote: > Hello dear Pythoneers, > > I have over 500 .php web pages in various subfolders under 'data' > folder that i have to rename to .html and and ditch the '' > tages from within and also insert a very first line of > where id must be an identification unique number o

Re: Replace and inserting strings within .txt files with the use of regex

2010-08-07 Thread Νίκος
# rename ALL php files to html in every subfolder of the folder 'data' os.rename('*.php', '*.html') # how to tell python to rename ALL php files to html to ALL subfolder under 'data' ? # current path of the file to be processed path = './data' # this must be somehow in a

Re: Replace and inserting strings within .txt files with the use of regex

2010-08-07 Thread MRAB
rantingrick wrote: On Aug 7, 7:20 pm, Νίκος wrote: Hello dear Pythoneers, I prefer Pythonista, but anywho.. I have over 500 .php web pages in various subfolders under 'data' folder that i have to rename to .html import os os.rename(old, new) and and ditch the '' tages from within path

Re: Replace and inserting strings within .txt files with the use of regex

2010-08-07 Thread rantingrick
On Aug 7, 7:20 pm, Νίκος wrote: > Hello dear Pythoneers, I prefer Pythonista, but anywho.. > I have over 500 .php web pages in various subfolders under 'data' > folder that i have to rename to .html import os os.rename(old, new) > and and ditch the '' tages from within path = 'some/valid/path

Replace and inserting strings within .txt files with the use of regex

2010-08-07 Thread Νίκος
Hello dear Pythoneers, I have over 500 .php web pages in various subfolders under 'data' folder that i have to rename to .html and and ditch the '' tages from within and also insert a very first line of where id must be an identification unique number of every page for counter tracking purposes.