Re: .replace() to replace elements in a Pandas DataFrame

2020-08-05 Thread Michio Suginoo
That said, what remains mystery is why the original one worked this morning. Strange! On Wed, Aug 5, 2020 at 10:15 PM Michio Suginoo wrote: > Hi Bob and MRAB, > Both of you, very kind. > Thanks. > I tried with DataFrame as my original code, but this time, I inserted > regex=True and it worked.

Re: .replace() to replace elements in a Pandas DataFrame

2020-08-05 Thread Michio Suginoo
Hi Bob and MRAB, Both of you, very kind. Thanks. I tried with DataFrame as my original code, but this time, I inserted regex=True and it worked. Thank you very much! Best On Wed, Aug 5, 2020 at 9:50 PM Bob van der Poel wrote: > I don't think that string.replace() has an option for a dictionary

Re: .replace() to replace elements in a Pandas DataFrame

2020-08-05 Thread Bob van der Poel
I don't think that string.replace() has an option for a dictionary of replacements ... mind you, it might be nice if it did. In the meantime, have you tried looping through the dictionary and changing each possible character? On Wed, Aug 5, 2020 at 5:12 PM Michio Suginoo wrote: > Hi MRAB, > > S

Re: .replace() to replace elements in a Pandas DataFrame

2020-08-05 Thread Michio Suginoo
Hi MRAB, In addition,. I also found out the following does not work either in my Jupyter Notebook. correction_dic2={ "La Boca" : "BOCA", "La Paternal": "PATERNAL", "Villa General Mitre": "VILLA GRAL. MITRE"} df = df.replace({'Name' : correction_dic2}) This case, unlike the earlier case, is aiming

Re: .replace() to replace elements in a Pandas DataFrame

2020-08-05 Thread Michio Suginoo
Hi MRAB, Sorry, I simply do not understand the intention of your statement. If .replace() does not do what I want to do: to replace all ' í ' with 'i' in any form . Could you advise me other means to do it? I am still a learner, so I am not knowledgeable. But, I presume, this sort of needs--to r

Re: .replace() to replace elements in a Pandas DataFrame

2020-08-05 Thread MRAB
On 2020-08-06 00:06, Michio Suginoo wrote: Hi MRAB, Here is an example: In the original dataframe, I have something like, 'Agronomía'. And I try to transform it to 'Agronomia'. In this case, I try to replace í with i: the former with a Spanish accent, the latter without. That's what you want

Re: .replace() to replace elements in a Pandas DataFrame

2020-08-05 Thread Michio Suginoo
Hi MRAB, Here is an example: In the original dataframe, I have something like, 'Agronomía'. And I try to transform it to 'Agronomia'. In this case, I try to replace í with i: the former with a Spanish accent, the latter without. Thanks Best On Wed, Aug 5, 2020 at 8:00 PM MRAB wrote: > On 2020-

Re: .replace() to replace elements in a Pandas DataFrame

2020-08-05 Thread MRAB
On 2020-08-05 23:21, Michio Suginoo wrote: Hi, I have trouble with .replace() method in a Pandas DataFrame. My code is something like this: correction_dic1 = {'á': 'a', 'í': 'i', 'ú': 'u', 'ó': 'o'} df = df.replace({'Name' : correction_dic1}) Basically, what I am trying to do here is to replace

Re: .replace("a" or "b")

2018-07-03 Thread Steven D'Aprano
On Tue, 03 Jul 2018 07:52:42 +0400, Abdur-Rahmaan Janhangeer wrote: > .replace("a" or "b") Oh I *wish* Python accepted that syntax to mean what you thought it meant. That's a common error: a surprising number of beginners are fooled by how close Python is to natural language and try writing th

Re: .replace("a" or "b")

2018-07-02 Thread Cameron Simpson
On 03Jul2018 07:52, Abdur-Rahmaan Janhangeer wrote: that's another oddity i wanted to clear how do i know that string methods accept or and and in like .replace("a" or "b") i can't figure out how to deduce that it can accept that Well, it accepts an expression like that, but it doesn't do wh

Re: Replace weird error message?

2016-03-19 Thread Chris Angelico
On Thu, Mar 17, 2016 at 5:39 AM, Joel Goldstick wrote: > can you show the complete code? It doesn't start with "{:02} I don't think Actually, yes it does; I can confirm the OP's concern: $ python3 Python 3.6.0a0 (default:ae76a1046bb9, Mar 17 2016, 05:45:31) [GCC 5.3.1 20160121] on linux Type "h

Re: Replace weird error message?

2016-03-19 Thread Rick Johnson
On Wednesday, March 16, 2016 at 1:53:45 PM UTC-5, Dan Strohl wrote: > Actually, I think that was the complete code... give it a try... > > "{:02}".format("1") > > produces the error listed. > > I agree the error is not very clear, since the "=" was not > passed, it seems like an incorrect error.

Re: Replace weird error message?

2016-03-19 Thread Sven R. Kunze
On 16.03.2016 19:53, Ben Finney wrote: Do you think some better error message should be used? Yes, I think that error message needs to be improved. Please file a bug report in Python's issue tracker https://bugs.python.org/>. For example a hint that "0" does work for the given argument. I sug

Re: Replace weird error message?

2016-03-19 Thread Terry Reedy
On 3/16/2016 3:08 PM, Chris Angelico wrote: On Thu, Mar 17, 2016 at 5:53 AM, Ben Finney wrote: For example a hint that "0" does work for the given argument. I suggest: “zero-padding only allowed for numeric types, not 'str'”. That's very slightly misleading too; zero padding is perfectly le

RE: Replace weird error message?

2016-03-19 Thread Dan Strohl via Python-list
27;=' and '0' padding are not allowed in string format specifiers" > -Original Message- > From: Python-list [mailto:python-list-bounces+d.strohl=f5@python.org] > On Behalf Of Joel Goldstick > Sent: Wednesday, March 16, 2016 11:39 AM > Cc: python-list@p

Re: Replace weird error message?

2016-03-19 Thread Joel Goldstick
can you show the complete code? It doesn't start with "{:02} I don't think On Wed, Mar 16, 2016 at 2:34 PM, the.gerenuk--- via Python-list < python-list@python.org> wrote: > The following error message, makes it a bit hard to understand what went > wrong > > >>> "{:02}".format("1") > Traceback (

Re: Replace weird error message?

2016-03-19 Thread Ben Finney
"the.gerenuk--- via Python-list" writes: > The following error message, makes it a bit hard to understand what went wrong > > >>> "{:02}".format("1") > Traceback (most recent call last): > File "", line 1, in > ValueError: '=' alignment not allowed in string format specifier Meaning that the

Re: Replace weird error message?

2016-03-19 Thread Terry Reedy
On 3/16/2016 2:53 PM, Ben Finney wrote: "the.gerenuk--- via Python-list" writes: The following error message, makes it a bit hard to understand what went wrong "{:02}".format("1") Traceback (most recent call last): File "", line 1, in ValueError: '=' alignment not allowed in string form

Re: Replace weird error message?

2016-03-19 Thread Joel Goldstick
On Wed, Mar 16, 2016 at 2:53 PM, Ben Finney wrote: > "the.gerenuk--- via Python-list" writes: > > > The following error message, makes it a bit hard to understand what went > wrong > > > > >>> "{:02}".format("1") > > Traceback (most recent call last): > > File "", line 1, in > > ValueError: '

Re: Replace weird error message?

2016-03-18 Thread Chris Angelico
On Thu, Mar 17, 2016 at 5:53 AM, Ben Finney wrote: >> For example a hint that "0" does work for the given argument. > > I suggest: “zero-padding only allowed for numeric types, not 'str'”. That's very slightly misleading too; zero padding is perfectly legal as long as you force the alignment: >>

Re: Replace weird error message?

2016-03-18 Thread Chris Angelico
On Thu, Mar 17, 2016 at 7:55 AM, Terry Reedy wrote: > On 3/16/2016 3:08 PM, Chris Angelico wrote: >> >> On Thu, Mar 17, 2016 at 5:53 AM, Ben Finney >> wrote: For example a hint that "0" does work for the given argument. >>> >>> >>> I suggest: “zero-padding only allowed for numeric types

Re: replace only full words

2013-09-28 Thread cerr
On Saturday, September 28, 2013 11:17:19 AM UTC-7, Tim Chase wrote: > [mercy, you could have trimmed down that reply] > > > > On 2013-09-28 10:43, cerr wrote: > > > On Saturday, September 28, 2013 4:54:35 PM UTC, Tim Chase wrote: > > >> import re > > > > > > Great, only I don't have the re

Re: replace only full words

2013-09-28 Thread cerr
On Saturday, September 28, 2013 11:07:11 AM UTC-7, MRAB wrote: > On 28/09/2013 18:43, cerr wrote: > > [snip] > > > Great, only I don't have the re module on my system :( > > > > > Really? It's part of Python's standard distribution. Oh no, sorry, mis-nformation, i DO have module re availab

Re: replace only full words

2013-09-28 Thread Tim Chase
[mercy, you could have trimmed down that reply] On 2013-09-28 10:43, cerr wrote: > On Saturday, September 28, 2013 4:54:35 PM UTC, Tim Chase wrote: >> import re > > Great, only I don't have the re module on my system :( Um, it's a standard Python library. You sure about that? http://docs

Re: replace only full words

2013-09-28 Thread MRAB
On 28/09/2013 18:43, cerr wrote: [snip] Great, only I don't have the re module on my system :( Really? It's part of Python's standard distribution. -- https://mail.python.org/mailman/listinfo/python-list

Re: replace only full words

2013-09-28 Thread cerr
On Saturday, September 28, 2013 4:54:35 PM UTC, Tim Chase wrote: > On 2013-09-28 09:11, cerr wrote: > > > I have a list of sentences and a list of words. Every full word > > > that appears within sentence shall be extended by i.e. "I > > > drink in the house." Would become "I in the ." (and >

Re: replace only full words

2013-09-28 Thread Jussi Piitulainen
MRAB writes: > On 28/09/2013 17:11, cerr wrote: > > Hi, > > > > I have a list of sentences and a list of words. Every full word > > that appears within sentence shall be extended by i.e. "I > > drink in the house." Would become "I in the ." (and > > not "I in the .")I have attempted it like thi

Re: replace only full words

2013-09-28 Thread MRAB
On 28/09/2013 17:11, cerr wrote: Hi, I have a list of sentences and a list of words. Every full word that appears within sentence shall be extended by i.e. "I drink in the house." Would become "I in the ." (and not "I in the .")I have attempted it like this: for sentence in sentences:

Re: replace only full words

2013-09-28 Thread Tim Chase
On 2013-09-28 09:11, cerr wrote: > I have a list of sentences and a list of words. Every full word > that appears within sentence shall be extended by i.e. "I > drink in the house." Would become "I in the ." (and > not "I in the .") This is a good place to reach for regular expressions. It com

Re: Replace blanks with letter

2013-08-22 Thread Dave Angel
eschneide...@comcast.net wrote: > I wanted the program to stop only after all the letters were typed; why in > the world would I try to write a program with blanks for each letter that > seem intended to be filled, only to have it stop if the last letter is typed, > or have to type each letter

Re: Replace blanks with letter

2013-08-22 Thread eschneider92
I wanted the program to stop only after all the letters were typed; why in the world would I try to write a program with blanks for each letter that seem intended to be filled, only to have it stop if the last letter is typed, or have to type each letter so many times until its processed? If you

Re: Replace blanks with letter

2013-08-22 Thread eschneider92
I wanted the program to stop only after all the letters were typed; why in the world would I try to write a program with blanks for each letter that seem intended to be filled, only to have it stop if the last letter is typed, or have to type each letter so many times until its processed? If you

Re: Replace blanks with letter

2013-08-21 Thread John Gordon
In <89146bb1-fb60-4746-93e2-6cb59cfbc...@googlegroups.com> eschneide...@comcast.net writes: > Thanks. I am running into a bunch of problems with the following code, all > of which are clear when running the program No, they're not clear. We can see what the code does, obviously, but we don't kn

Re: Replace blanks with letter

2013-08-21 Thread Dave Angel
eschneide...@comcast.net wrote: > Thanks. I am running into a bunch of problems with the following code, all of > which are clear when running the program > > import random > letters='abcdefg' > blanks='_'*len(letters) > print('type letters from a to g') > print(blanks) > for i in range(len(let

Re: Replace blanks with letter

2013-08-21 Thread Chris Angelico
On Wed, Aug 21, 2013 at 5:49 PM, wrote: > Thanks. I am running into a bunch of problems with the following code, all of > which are clear when running the program Some of us don't have time to just execute arbitrary code in some safe environment, so we'd REALLY rather you paste in the exceptio

Re: Replace blanks with letter

2013-08-21 Thread eschneider92
Thanks. I am running into a bunch of problems with the following code, all of which are clear when running the program import random letters='abcdefg' blanks='_'*len(letters) print('type letters from a to g') print(blanks) for i in range(len(letters)): if letters[i] in input(): bla

Re: Replace blanks with letter

2013-08-20 Thread Dave Angel
eschneide...@comcast.net wrote: > Is there also a way to have the code remember what I typed and not stop after > the first letter the user types? For example, if I typed 'a' once, thus > returning 'a__', and then typed in 'b', I want the code to return > 'ab_' and so on. I wasn't clear

Re: Replace blanks with letter

2013-08-20 Thread eschneider92
Is there also a way to have the code remember what I typed and not stop after the first letter the user types? For example, if I typed 'a' once, thus returning 'a__', and then typed in 'b', I want the code to return 'ab_' and so on. I wasn't clear about this part in my original post. Tha

Re: Replace blanks with letter

2013-08-20 Thread Peter Otten
eschneide...@comcast.net wrote: > I'm trying to replace the blank(_) with the letter typed in by the user, > in the appropriate blank(_) spot where the letter should be (where is in > the letters list). > > letters='abcdefg' > blanks='_ '*len(letters) > print('type letter from a to g') > print(bl

Re: Replace blanks with letter

2013-08-20 Thread Fábio Santos
On 20 Aug 2013 09:42, wrote: > > I'm trying to replace the blank(_) with the letter typed in by the user, in the appropriate blank(_) spot where the letter should be (where is in the letters list). > > letters='abcdefg' > blanks='_ '*len(letters) > print('type letter from a to g') > print(blanks)

Re: Replace "dash" values in a field with new line- VB equivalent of Python

2013-03-19 Thread rusi
On Mar 19, 8:36 pm, Cathy James wrote: > Dear All, > I need some assistance with Python so that values in the "Name" field e.g. > Murray - James - Leo can be labeled as: > > Murray > James > Leo > > with a new line replacing every dash. > > Basically I need the equivalent of this VB in Python: > r

Re: Replace "dash" values in a field with new line- VB equivalent of Python

2013-03-19 Thread Neil Cerutti
On 2013-03-19, Cathy James wrote: > Dear All, > I need some assistance with Python so that values in the "Name" > field e.g. Murray - James - Leo can be labeled as: > > Murray > James > Leo > > with a new line replacing every dash. > > Basically I need the equivalent of this VB in Python: > replac

Re: Replace "dash" values in a field with new line- VB equivalent of Python

2013-03-19 Thread Dave Angel
On 03/19/2013 11:36 AM, Cathy James wrote: Dear All, I need some assistance with Python so that values in the "Name" field e.g. Murray - James - Leo can be labeled as: Murray James Leo with a new line replacing every dash. Basically I need the equivalent of this VB in Python: replace ( [Name]

Re: Replace "dash" values in a field with new line- VB equivalent of Python

2013-03-19 Thread Joel Goldstick
On Tue, Mar 19, 2013 at 11:36 AM, Cathy James wrote: > Dear All, > I need some assistance with Python so that values in the "Name" field e.g. > Murray - James - Leo can be labeled as: > > Murray > James > Leo > > with a new line replacing every dash. > > Basically I need the equivalent of this VB

Re: Replace pip installed package with latest git version?

2011-09-14 Thread Alec Taylor
Thanks, uninstalling first worked. :D On Thu, Sep 15, 2011 at 3:06 AM, Micky Hulse wrote: > On Wed, Sep 14, 2011 at 9:58 AM, Micky Hulse > wrote: >> Not sure if you got an answer yet, but this is how I would do it: >> sudo pip install --upgrade >> git+git://github.com/jedie/python-creole.git#e

Re: Replace pip installed package with latest git version?

2011-09-14 Thread Micky Hulse
On Wed, Sep 14, 2011 at 9:58 AM, Micky Hulse wrote: > Not sure if you got an answer yet, but this is how I would do it: > sudo pip install --upgrade > git+git://github.com/jedie/python-creole.git#egg=python-creole Having read your message more closely, it sounds like you did not install the packa

Re: Replace pip installed package with latest git version?

2011-09-14 Thread Micky Hulse
Hello, On Wed, Sep 14, 2011 at 1:44 AM, Alec Taylor wrote: > I've installed a version of python-creole from pip. How do I upgrade > it to the latest git version? Not sure if you got an answer yet, but this is how I would do it: sudo pip install --upgrade git+git://github.com/jedie/python-creole

Re: Replace pip installed package with latest git version?

2011-09-14 Thread Alec Taylor
--editable=git+https://github.com/jedie/python-creole.git is not the right forma t; it must have #egg=Package On Wed, Sep 14, 2011 at 10:54 PM, One Murithi wrote: > pip install -e > On Wed, Sep 14, 2011 at 11:44 AM, Alec Taylor > wrote: >> >> Good evening, >> >> I've installed a version of pyth

Re: replace random matches of regexp

2011-09-08 Thread gry
On Sep 8, 3:51 pm, gry wrote: To elaborate(always give example of desired output...) I would hope to get something like: SELECT public.max(PUBLIC.TT.I) AS SEL_0 FROM (SCHM.T RIGHT OUTER JOIN PUBLIC.TT ON (SCHM.T.I IS NULL)) WHERE (NOT(NOT((power(PUBLIC.TT.F, PUBLIC.TT.F) = cast(ceil(( SEL

Re: replace random matches of regexp

2011-09-08 Thread Peter Otten
gry wrote: > [Python 2.7] > I have a body of text (~1MB) that I need to modify. I need to look > for matches of a regular expression and replace a random selection of > those matches with a new string. There may be several matches on any > line, and a random selection of them should be replaced

Re: replace random matches of regexp

2011-09-08 Thread André Malo
* gry wrote: > I might want to replace '(max|min|cos|sqrt|ceil' with "public.\1", but > only with probability 0.7. I looked and looked for some computed > thing in re's that I could stick and expression, but could not find > such(for good reasons, I know). > Any ideas how to do this? I would go

Re: replace random matches of regexp

2011-09-08 Thread MRAB
On 08/09/2011 20:51, gry wrote: [Python 2.7] I have a body of text (~1MB) that I need to modify. I need to look for matches of a regular expression and replace a random selection of those matches with a new string. There may be several matches on any line, and a random selection of them should

Re: Replace all references to one object with references to other

2011-08-05 Thread Steven D'Aprano
Jack Bates wrote: > I have two objects, and I want to replace all references to the first > object - everywhere - with references to the second object. What can I > try? Another way of solving your *actual* problem. "Replace all references to object1 with object2 instead" is a means to an end, n

Re: Replace all references to one object with references to other

2011-08-05 Thread John Gordon
In John Gordon writes: > In Jack Bates > writes: > > I have two objects, and I want to replace all references to the first > > object - everywhere - with references to the second object. What can I > > try? > The simplest answer to your question is to assign object2 to object1 I think I ha

Re: Replace all references to one object with references to other

2011-08-05 Thread John Gordon
In Jack Bates writes: > I have two objects, and I want to replace all references to the first > object - everywhere - with references to the second object. What can I > try? The simplest answer to your question is to assign object2 to object1 at the very beginning of your code, but that is a v

Re: Replace all references to one object with references to other

2011-08-05 Thread Emile van Sebille
On 8/5/2011 12:37 PM Jack Bates said... I have two objects, and I want to replace all references to the first object - everywhere - with references to the second object. What can I try? Start with a proxy to your first and have it swap in to the second? EMile -- http://mail.python.org/mailma

Re: Replace all references to one object with references to other

2011-08-05 Thread Ken Watford
On Fri, Aug 5, 2011 at 3:37 PM, Jack Bates wrote: > I have two objects, and I want to replace all references to the first > object - everywhere - with references to the second object. What can I > try? If using PyPy instead of CPython is an option, the "thunk" object space's "become" function can

Re: replace regex in file using a dictionary

2011-04-05 Thread Martin De Kauwe
yes thanks both work nicely, I will ponder the suggestions. -- http://mail.python.org/mailman/listinfo/python-list

Re: replace regex in file using a dictionary

2011-04-05 Thread nn
On Apr 5, 3:59 am, Martin De Kauwe wrote: > Hi, > > So i want to replace multiple lines in a text file and I have reasoned > the best way to do this is with a dictionary. I have simplified my > example and broadly I get what I want however I am now printing my > replacement string and part of the

Re: replace regex in file using a dictionary

2011-04-05 Thread Yashwin Kanchan
How about creating a new string instead of replacing the original. def replace_keys(text, replacements_dict): text_list = text.split('\n') new_text = '' for line in text_list: key=line.split('=')[0] if key.strip() in replacements_dict: new_text = new_text +

Re: replace regex in file using a dictionary

2011-04-05 Thread Vlastimil Brom
2011/4/5 Martin De Kauwe : > Hi, > > So i want to replace multiple lines in a text file and I have reasoned > the best way to do this is with a dictionary. I have simplified my > example and broadly I get what I want however I am now printing my > replacement string and part of the original express

Re: Replace multiple lines in a txt file.

2010-08-23 Thread Emile van Sebille
On 8/23/2010 12:13 PM Emile van Sebille said... On 8/23/2010 11:22 AM Alban Nona said... Hi everybody, I would like to know if its possible to modify a list of entry that is define into a list and replace it by another list ? I try this piece of code, but Im pretty sure I messed something: htt

Re: Replace multiple lines in a txt file.

2010-08-23 Thread Emile van Sebille
On 8/23/2010 11:22 AM Alban Nona said... Hi everybody, I would like to know if its possible to modify a list of entry that is define into a list and replace it by another list ? I try this piece of code, but Im pretty sure I messed something: http://pastebin.com/HfdkGeB3 The code you posted

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

  1   2   3   >