Search and Replace
-
Ok - now I see where my mistake is.
I did not understand that there are two files involved.
Even after the discussion with Alan I was still thinking
there is only one file. Doh.@Thx @PeterJones for clarifying and
sorry @Bert-Barber and @Alan-Kilborn for the confusion.Now the code makes much more sense.
So the important questions now is, which one is better.
Charcoal or propane grill? Just kidding :-D -
@PeterJones said in Search and Replace:
I doubt I’ll “turn the lights on”
Not a bad try though!
The “two-view”
editor1
andeditor2
thing does make a lot of sense for this application. I hadn’t thought of that. For the OP’s benefit, and what Peter didn’t explicitly say, is that you can access Pythonscript functions specific to an editor, like this:editor1.replace()
oreditor2.replace()
.Where it gets a little dicey is, how do you know which view on your screen contains which data (the data to be acted on or the lookup table data). Intuitively, one thinks that the view on the left is
editor1
and the view on the right iseditor2
, but it is possible for that to be reversed. Thus, be careful! Side note: If you close one of the views, don’t assume that the one remaining iseditor1
.Doing a mix of the two increases the chances that the wrong access will be applied to one of the files
Hmmm, kinda like what I just mentioned about mixing up the views.
I think it is getting bogged down because both of the data are text. If the lookup table was coming from a database, no one would have any complaint about the OP’s method [ or start talking about BBQ grills – :-) ].
it makes the code harder to read
Not a strong argument, but I’ll give it to you. :-)
so when you’re trying to figure out what you were doing in 6 months or 6 years
Probably the OP does this once and then throws it away.
Even after a long time, I think the code would make sense. -
@Ekopalypse said in Search and Replace:
I did not understand that there are two files involved.
Even after the discussion with Alan I was still thinking there is only one file.Yea, with these kind of table-lookup-replacement problems we usually end up with a regex solution where the table is appended below the actual data…in ONE file. Maybe that sent your thinking this way.
Since the OP mentioned Python before @guy038 could jump in with regex, though, it went a different way.
Charcoal or propane grill?
There is no debate possible here:
CHARCOAL
-
Because I can only upvote once, this is +1 for charcoal :-D
-
I am learning so, I certainly do not object to being told the simplest way to accomplish my task. At this time I have the following:
I have the following as an excel csv file:
the sample code I am experimenting with is:
And the script I am running is:
The results I am getting is:
So, it seems to be working except for the extra spaces and lines that are being added. What am I doing wrong that is causing the extra space to be added?
Thanks so very much in advance for your assistance!!!
-
@Bert-Barber said in Search and Replace:
working except for the extra spaces and lines that are being added.
I believe the extra lines are coming because
l
has the newline from the CSV still embedded, and when you split it,s[1]
will contain the newline… You need to remove the newline before doing the split, such ass = l.rstrip().split(',')
.As far as the extra spaces: you haven’t shown us the actual CSV, only the spreadsheet-interpretation of the CSV… but it may be that in the raw CSV, it’s something like
LEFT COLUMN, RIGHT COLUMN AFTER ONE OR MORE SPACES
The split would then leave all those spaces in
s[1]
. If you don’t want those spaces, you could strip all leading and trailing spaces off of a string using.strip()
:editor.rereplace(s[0], s[1].strip() )
-
@PeterJones YOU ARE AWESOME - THANK YOU SO VERY MUCH!!!