tag:blogger.com,1999:blog-45613907768289001102024-02-07T13:26:23.979-08:00My ScriptsAnanta Acharyahttp://www.blogger.com/profile/07259109389692175071noreply@blogger.comBlogger14125tag:blogger.com,1999:blog-4561390776828900110.post-77246488993796301772012-08-04T12:21:00.001-07:002012-08-04T12:22:30.953-07:00Men's 100M track 9.66sec in 2012?<div dir="ltr" style="text-align: left;" trbidi="on">
while waiting for race on Aug 5. I just wanted to look historical timing (www.dabaseolympics.com). So, a simple linear regression with Excel (really?), gives me 9.66 sec (2008, 9.69 sec) for gold 2012.<br />
<br />
And readers of 2664, please let me know if the race is won in just a second.<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi9RL10NLPTQAYji_k3bLKZGoW01NSskMJIflgF8D32x80AnJwXVwyYeKpy2ezNUQZp7pRqCl1UfU-VNj1PVg57eZo37XChblx8HCeS65qX8UANS64QlV7lyL8HOudWwpl8uOisXzTDVG-l/s1600/100m.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" height="295" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi9RL10NLPTQAYji_k3bLKZGoW01NSskMJIflgF8D32x80AnJwXVwyYeKpy2ezNUQZp7pRqCl1UfU-VNj1PVg57eZo37XChblx8HCeS65qX8UANS64QlV7lyL8HOudWwpl8uOisXzTDVG-l/s400/100m.png" width="400" /></a></div>
<br /></div>Ananta Acharyahttp://www.blogger.com/profile/07259109389692175071noreply@blogger.com0tag:blogger.com,1999:blog-4561390776828900110.post-44307884095015737192012-07-27T11:36:00.000-07:002012-07-27T11:36:22.656-07:00rename files mac<div dir="ltr" style="text-align: left;" trbidi="on">
<span class="Apple-style-span" style="border-collapse: collapse; font-family: Arial, 'Liberation Sans', 'DejaVu Sans', sans-serif; font-size: 14px; line-height: 18px;"></span><br />
<pre style="background-attachment: initial; background-clip: initial; background-color: #eeeeee; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, serif; font-size: 14px; margin-bottom: 10px; margin-left: 0px; margin-right: 0px; margin-top: 0px; max-height: 600px; overflow-x: auto; overflow-y: auto; padding-bottom: 5px; padding-left: 5px; padding-right: 5px; padding-top: 5px; vertical-align: baseline; width: auto;"><code style="background-attachment: initial; background-clip: initial; background-color: #eeeeee; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, serif; font-size: 14px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;">for file in *.txt
do
mv "$file" "${file/.txt/.fasta}"
done</code></pre>
</div>Ananta Acharyahttp://www.blogger.com/profile/07259109389692175071noreply@blogger.com0tag:blogger.com,1999:blog-4561390776828900110.post-4586413385132774282012-04-04T10:55:00.004-07:002012-04-04T11:22:10.752-07:00Matrix to vector Excel formula<div dir="ltr" style="text-align: left;" trbidi="on">
Matrix is named range of matrix<br />
<br />
Horizontal
=OFFSET(Matrix,TRUNC((ROW()-ROW($A$12))/COLUMNS(Matrix)),MOD(ROW()-ROW($A$12),COLUMNS(Matrix)),1,1)<br />
<br />
Vertical
=OFFSET(Matrix,MOD(ROW()-ROW($A$12),ROWS(Matrix)),TRUNC((ROW()-ROW($A$12))/ROWS(Matrix)),1,1)<br />
<br />
source: http://www.cpearson.com/excel/MatrixToVector.aspx</div>Ananta Acharyahttp://www.blogger.com/profile/07259109389692175071noreply@blogger.com0tag:blogger.com,1999:blog-4561390776828900110.post-35501964310762913822012-02-16T20:40:00.000-08:002012-02-16T20:40:06.638-08:00batch rename and (move) files using python<div dir="ltr" style="text-align: left;" trbidi="on">
<br />
So, my friend asked me to rename the files. The file names are alphanumeric and they should be renamed with leading zeroes but in order. the default sort is 1,10,11….2, 20….etc but correct order would be 1,2,3,4,5…… So, I did some hit and trial and some binging, googling…<br />
Finally done<br />
here is the code<br />
<br />
<pre><pre style="background-color: white; font-family: consolas,'Courier New',courier,monospace; font-size: 12px; margin: 0em; width: 100%;"><span style="color: blue;">import</span> <span style="color: blue;">os</span></pre>
<pre style="background-color: white; font-family: consolas,'Courier New',courier,monospace; font-size: 12px; margin: 0em; width: 100%;"><span style="color: blue;">import</span> <span style="color: blue;">re</span></pre>
<pre style="background-color: white; font-family: consolas,'Courier New',courier,monospace; font-size: 12px; margin: 0em; width: 100%;"><span style="color: blue;">import</span> shutil</pre>
<pre style="background-color: white; font-family: consolas,'Courier New',courier,monospace; font-size: 12px; margin: 0em; width: 100%;"> </pre>
<pre style="background-color: white; font-family: consolas,'Courier New',courier,monospace; font-size: 12px; margin: 0em; width: 100%;"></pre>
<pre style="background-color: white; font-family: consolas,'Courier New',courier,monospace; font-size: 12px; margin: 0em; width: 100%;"></pre>
<pre style="background-color: white; font-family: consolas,'Courier New',courier,monospace; font-size: 12px; margin: 0em; width: 100%;"></pre>
<pre style="background-color: white; font-family: consolas,'Courier New',courier,monospace; font-size: 12px; margin: 0em; width: 100%;"><span style="color: blue;">def</span> main():</pre>
<pre style="background-color: white; font-family: consolas,'Courier New',courier,monospace; font-size: 12px; margin: 0em; width: 100%;">## Commented out are the codes to create file for working purposes </pre>
<pre style="background-color: white; font-family: consolas,'Courier New',courier,monospace; font-size: 12px; margin: 0em; width: 100%;">## for a in range(1,20):</pre>
<pre style="background-color: white; font-family: consolas,'Courier New',courier,monospace; font-size: 12px; margin: 0em; width: 100%;">## for b in ["<span style="color: darkred;">a</span>", "<span style="color: darkred;">b</span>", "<span style="color: darkred;">c</span>"]:</pre>
<pre style="background-color: white; font-family: consolas,'Courier New',courier,monospace; font-size: 12px; margin: 0em; width: 100%;">## filename="<span style="color: darkred;">sec</span>"+str(a)+b+"<span style="color: darkred;">.data</span>"</pre>
<pre style="background-color: white; font-family: consolas,'Courier New',courier,monospace; font-size: 12px; margin: 0em; width: 100%;">## c=<span style="color: blue;">open</span>(filename,"<span style="color: darkred;">a</span>")</pre>
<pre style="background-color: white; font-family: consolas,'Courier New',courier,monospace; font-size: 12px; margin: 0em; width: 100%;">## c.<span style="color: blue;">close</span>()</pre>
<pre style="background-color: white; font-family: consolas,'Courier New',courier,monospace; font-size: 12px; margin: 0em; width: 100%;"> directory="<span style="color: darkred;">oldnames</span>"</pre>
<pre style="background-color: white; font-family: consolas,'Courier New',courier,monospace; font-size: 12px; margin: 0em; width: 100%;"> directory2="<span style="color: darkred;">newnames</span>"</pre>
<pre style="background-color: white; font-family: consolas,'Courier New',courier,monospace; font-size: 12px; margin: 0em; width: 100%;"> fnames=<span style="color: blue;">os</span>.listdir(directory)</pre>
<pre style="background-color: white; font-family: consolas,'Courier New',courier,monospace; font-size: 12px; margin: 0em; width: 100%;"> #<span style="color: blue;">print</span>(str(fnames))</pre>
<pre style="background-color: white; font-family: consolas,'Courier New',courier,monospace; font-size: 12px; margin: 0em; width: 100%;"> sortedfnames=sorted(fnames, key=natural_sortkey)</pre>
<pre style="background-color: white; font-family: consolas,'Courier New',courier,monospace; font-size: 12px; margin: 0em; width: 100%;"> #<span style="color: blue;">print</span>(str(sortedfnames))</pre>
<pre style="background-color: white; font-family: consolas,'Courier New',courier,monospace; font-size: 12px; margin: 0em; width: 100%;"> for <span style="color: blue;">index</span>, fname in enumerate(sortedfnames):</pre>
<pre style="background-color: white; font-family: consolas,'Courier New',courier,monospace; font-size: 12px; margin: 0em; width: 100%;"></pre>
<pre style="background-color: white; font-family: consolas,'Courier New',courier,monospace; font-size: 12px; margin: 0em; width: 100%;"> <span style="color: blue;">index</span>2=str(<span style="color: blue;">index</span>).<span style="color: blue;">zfill</span>(4) ##change <span style="color: blue;">zfill</span> parameter to 3 <span style="color: blue;">if</span> 001, 4 <span style="color: blue;">if</span> 0001 etc</pre>
<pre style="background-color: white; font-family: consolas,'Courier New',courier,monospace; font-size: 12px; margin: 0em; width: 100%;"> #<span style="color: blue;">print</span> str(<span style="color: blue;">index</span>)+ fname</pre>
<pre style="background-color: white; font-family: consolas,'Courier New',courier,monospace; font-size: 12px; margin: 0em; width: 100%;"> shutil.<span style="color: blue;">copy</span>(<span style="color: blue;">os</span>.<span style="color: blue;">path</span>.<span style="color: blue;">join</span>(directory,fname), <span style="color: blue;">os</span>.<span style="color: blue;">path</span>.<span style="color: blue;">join</span>(directory2,(<span style="color: blue;">index</span>2+fname)))</pre>
<pre style="background-color: white; font-family: consolas,'Courier New',courier,monospace; font-size: 12px; margin: 0em; width: 100%;"> </pre>
<pre style="background-color: white; font-family: consolas,'Courier New',courier,monospace; font-size: 12px; margin: 0em; width: 100%;"></pre>
<pre style="background-color: white; font-family: consolas,'Courier New',courier,monospace; font-size: 12px; margin: 0em; width: 100%;">tokenize = <span style="color: blue;">re</span>.compile(r'(\d+)|(\D+)').<span style="color: blue;">findall</span></pre>
<pre style="background-color: white; font-family: consolas,'Courier New',courier,monospace; font-size: 12px; margin: 0em; width: 100%;"></pre>
<pre style="background-color: white; font-family: consolas,'Courier New',courier,monospace; font-size: 12px; margin: 0em; width: 100%;"><span style="color: blue;">def</span> natural_sortkey(<span style="color: blue;">string</span>): </pre>
<pre style="background-color: white; font-family: consolas,'Courier New',courier,monospace; font-size: 12px; margin: 0em; width: 100%;"> <span style="color: blue;">return</span> tuple(int(num) <span style="color: blue;">if</span> num <span style="color: blue;">else</span> alpha for num, alpha in tokenize(<span style="color: blue;">string</span>))</pre>
<pre style="background-color: white; font-family: consolas,'Courier New',courier,monospace; font-size: 12px; margin: 0em; width: 100%;"></pre>
<pre style="background-color: white; font-family: consolas,'Courier New',courier,monospace; font-size: 12px; margin: 0em; width: 100%;"></pre>
<pre style="background-color: white; font-family: consolas,'Courier New',courier,monospace; font-size: 12px; margin: 0em; width: 100%;">main()</pre>
<pre style="background-color: white; font-family: consolas,'Courier New',courier,monospace; font-size: 12px; margin: 0em; width: 100%;"></pre>
</pre>
<br />
Worked as magic!!<br />
<br />
<br />
<br />
note: I got the alphanumeric sort tips from stackoverflow user(<a href="http://stackoverflow.com/users/107366/ants-aasma" title="http://stackoverflow.com/users/107366/ants-aasma">http://stackoverflow.com/users/107366/ants-aasma</a>)</div>Ananta Acharyahttp://www.blogger.com/profile/07259109389692175071noreply@blogger.com0tag:blogger.com,1999:blog-4561390776828900110.post-30225162236040096352012-02-15T14:04:00.000-08:002012-02-15T14:04:18.106-08:00Alternate styling in word [With Macro]<div dir="ltr" style="text-align: left;" trbidi="on">
Call me lazy,<br />
<br />I would rather write a script to do alternate <b>bold</b> and not bold of paragraphs than do it manually.<br />
<br />
So, here is the script<br />
<br />
sub i_am_not_lazy()<br />
<br />
Dim para As Paragraph<br />
Dim i As Integer<br />
i = 1<br />
For Each para In Selection.Paragraphs<br />
If i Mod 2 = 0 Then<br />
para.Range.Font.Bold = True<br />
Else<br />
para.Range.Font.Bold = False<br />
End If<br />
i = i + 1<br />
Next<br />
<br />
end sub<br />
<br />
<br />
<br />
here is the result...<br />
<br />
<br />
<br />
Dear aaa,
<br />
<div class="MsoNormal">
<b style="mso-bidi-font-weight: normal;">I am not trying to be lazy but I have some 50 plus questions </b></div>
<div class="MsoNormal">
and</div>
<div class="MsoNormal">
<b style="mso-bidi-font-weight: normal;"><span style="mso-spacerun: yes;"> </span>I have to insert answers in between them in BOLD. </b></div>
<div class="MsoNormal">
I am trying to find out if we have some smart idea to do.</div>
<div class="MsoNormal">
<b style="mso-bidi-font-weight: normal;">Thank you for your post. I really was not looking for using CTRL B button because I have to press it everytime I enter answers. </b></div>
<div class="MsoNormal">
Your response for putting macros seemed useful, but I still did not get how to use it.</div>
<div class="MsoNormal">
<b style="mso-bidi-font-weight: normal;">Can you please guide me through the steps?</b></div>
<div class="MsoNormal">
Thank you so much</div>
<div class="MsoNormal">
<b style="mso-bidi-font-weight: normal;">aaa!!</b></div>
</div>Ananta Acharyahttp://www.blogger.com/profile/07259109389692175071noreply@blogger.com0tag:blogger.com,1999:blog-4561390776828900110.post-74086039307582540812012-01-12T09:43:00.000-08:002012-02-15T19:24:41.277-08:00find and replace in batch in excel<div dir="ltr" style="text-align: left;" trbidi="on">
Sub ReplaceText()<br />
'value to replace in D, value to be replaced by in E<br />
For Each vCell In Range("d1:d49").Cells
'range to replace b<br />
Columns("b:b").Cells.Replace What:=vCell, Replacement:=vCell.Offset(0, 1).Value, LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
Next vCell<br />
End Sub<br />
</div>Ananta Acharyahttp://www.blogger.com/profile/07259109389692175071noreply@blogger.com0tag:blogger.com,1999:blog-4561390776828900110.post-78226400180216632202011-11-01T08:58:00.001-07:002011-11-01T08:58:21.487-07:00alpha lattice designBackground
Design:
cycdesign
alphagen
alpha+
R (agricolae)
SAS (plan?)
Analyse:
With SAS
proc lattice
package (agricolae)Ananta Acharyahttp://www.blogger.com/profile/07259109389692175071noreply@blogger.com0tag:blogger.com,1999:blog-4561390776828900110.post-70691849572886309392011-09-14T13:50:00.000-07:002011-09-14T13:51:41.996-07:00R index search and subset dataind<-which(x$a>.5 & x$b>.5)<br /><br />subset<-x(ind,)Ananta Acharyahttp://www.blogger.com/profile/07259109389692175071noreply@blogger.com0tag:blogger.com,1999:blog-4561390776828900110.post-13191611200815266512011-09-07T13:12:00.000-07:002011-09-07T13:13:07.760-07:00Histogram in excelUse Frequency function and Command Enter or Ctrl Shift Enter to populate through all bins...Ananta Acharyahttp://www.blogger.com/profile/07259109389692175071noreply@blogger.com0tag:blogger.com,1999:blog-4561390776828900110.post-46003417747253030862010-09-29T11:53:00.001-07:002012-02-15T19:24:41.273-08:00Move multiple rows to Coulmns<p>Problem:</p> <p>I took data from field which are like this</p> <table cellspacing="0" cellpadding="0" border="0"> <tbody> <tr> <td width="36"> <p><font size="2">18-11</font></p></td> <td width="36"> <p><font size="2">16-11</font></p></td> <td width="36"> <p><font size="2">4-11</font></p></td> <td width="36"> <p><font size="2">31-13</font></p></td> <td width="36"> <p><font size="2">1-6</font></p></td> <td width="36"> <p><font size="2">7-10</font></p></td> <td width="36"> <p><font size="2">34-11</font></p></td> <td width="36"> <p><font size="2">5-16</font></p></td></tr> <tr> <td> <p><font size="2">3</font></p></td> <td> <p><font size="2">_</font></p></td> <td> <p><font size="2">3</font></p></td> <td> <p><font size="2">_</font></p></td> <td> <p><font size="2">3</font></p></td> <td> <p><font size="2">3</font></p></td> <td> <p><font size="2">1</font></p></td> <td> <p><font size="2">2</font></p></td></tr> <tr> <td> <p><font size="2">26-16</font></p></td> <td> <p><font size="2">4-14</font></p></td> <td> <p><font size="2">26-1</font></p></td> <td> <p><font size="2">18-9</font></p></td> <td> <p><font size="2">27-15</font></p></td> <td> <p><font size="2">15-7</font></p></td> <td> <p><font size="2">28-13</font></p></td> <td> <p><font size="2">26-14</font></p></td></tr> <tr> <td> <p><font size="2">3</font></p></td> <td> <p><font size="2">3</font></p></td> <td> <p><font size="2">3</font></p></td> <td> <p><font size="2">5</font></p></td> <td> <p><font size="2">7</font></p></td> <td> <p><font size="2">1</font></p></td> <td> <p><font size="2">5</font></p></td> <td> <p><font size="2">1</font></p></td></tr></tbody></table> <p>but I want convert it to</p> <table cellspacing="0" cellpadding="0" border="0"> <tbody> <tr> <td width="64">18-11</td> <td width="64">3</td></tr> <tr> <td>16-11</td> <td>_</td></tr> <tr> <td>4-11</td> <td>3</td></tr> <tr> <td>31-13</td> <td>_</td></tr> <tr> <td>1-6</td> <td>3</td></tr> <tr> <td>7-10</td> <td>3</td></tr> <tr> <td>34-11</td> <td>1</td></tr> <tr> <td>5-16</td> <td>2</td></tr> <tr> <td>26-16</td> <td>3</td></tr> <tr> <td>4-14</td> <td>3</td></tr> <tr> <td>26-1</td> <td>3</td></tr> <tr> <td>18-9</td> <td>5</td></tr> <tr> <td>27-15</td> <td>7</td></tr> <tr> <td>15-7</td> <td>1</td></tr> <tr> <td>28-13</td> <td>5</td></tr> <tr> <td>26-14</td> <td>1</td></tr></tbody></table> <p> </p> <p>So, here is the macro</p><pre><pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; background-color: #ffffff"><span style="color: #0000ff">Sub</span> alternateRowsToCol()<br /></pre><pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; background-color: #ffffff"></pre><pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; background-color: #ffffff"> <span style="color: #0000ff">Application</span>.ScreenUpdating = False<br /></pre><pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; background-color: #ffffff"> <span style="color: #0000ff">Dim</span> row, col As Integer<br /></pre><pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; background-color: #ffffff"> row = Sheets("<span style="color: #8b0000">Sheet3</span>").UsedRange.Rows.Count<br /></pre><pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; background-color: #ffffff"> col = Sheets("<span style="color: #8b0000">Sheet3</span>").UsedRange.Columns.Count<br /></pre><pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; background-color: #ffffff"> <br /></pre><pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; background-color: #ffffff"> <br /></pre><pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; background-color: #ffffff"> <span style="color: #0000ff">For</span> i = 1 To row Step 2<br /></pre><pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; background-color: #ffffff"> Sheets("<span style="color: #8b0000">Sheet3</span>").Activate<br /></pre><pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; background-color: #ffffff"> <br /></pre><pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; background-color: #ffffff"> Sheets("<span style="color: #8b0000">Sheet3</span>").Range("<span style="color: #8b0000">A</span>" & <span style="color: #0000ff">CStr</span>(i) & "<span style="color: #8b0000">:X</span>" & <span style="color: #0000ff">CStr</span>(i + 1)).<span style="color: #0000ff">Select</span><br /></pre><pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; background-color: #ffffff"> ' X here <span style="color: #0000ff">is</span> because I have 24 rows but <span style="color: #0000ff">in</span> example just 8<br /></pre><pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; background-color: #ffffff"> Selection.Copy<br /></pre><pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; background-color: #ffffff"> Sheets("<span style="color: #8b0000">Sheet4</span>").Activate<br /></pre><pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; background-color: #ffffff"> <br /></pre><pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; background-color: #ffffff"> Sheets("<span style="color: #8b0000">sheet4</span>").Range("<span style="color: #8b0000">A</span>" & <span style="color: #0000ff">CStr</span>(24 * ((i - 1) / 2) + 1)).<span style="color: #0000ff">Select</span><br /></pre><pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; background-color: #ffffff"> ' 24 here <span style="color: #0000ff">is</span> because I have 24 rows but <span style="color: #0000ff">in</span> example just 8<br /></pre><pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; background-color: #ffffff"> Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:= _<br /></pre><pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; background-color: #ffffff"> False, Transpose:=True<br /></pre><pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; background-color: #ffffff"> <br /></pre><pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; background-color: #ffffff"> <span style="color: #0000ff">Next</span> i<br /></pre><pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; background-color: #ffffff"> <span style="color: #0000ff">Application</span>.ScreenUpdating = True<br /></pre><pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; background-color: #ffffff"> <br /></pre><pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; background-color: #ffffff"><span style="color: #0000ff">End</span> <span style="color: #0000ff">Sub</span><br /></pre><pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; background-color: #ffffff"></pre></pre> Ananta Acharyahttp://www.blogger.com/profile/07259109389692175071noreply@blogger.com0tag:blogger.com,1999:blog-4561390776828900110.post-15206243064894729812010-06-03T10:59:00.001-07:002012-02-15T19:24:41.261-08:00Insert n rows after each row in EXCEL<p><a href="http://lh4.ggpht.com/_5tDgsxHFu4I/TAfteZjrPqI/AAAAAAAABr4/KIzRx6AM_QY/s1600-h/image%5B4%5D.png"><img title="image" style="border-right: 0px; border-top: 0px; display: inline; border-left: 0px; border-bottom: 0px" height="132" alt="image" src="http://lh3.ggpht.com/_5tDgsxHFu4I/TAfterfR8NI/AAAAAAAABr8/vfIl6W4JYmI/image_thumb%5B6%5D.png?imgmax=800" width="288" border="0" /></a> </p> <p><a href="http://lh4.ggpht.com/_5tDgsxHFu4I/TAfte9DNMiI/AAAAAAAABsA/mKUkWfw4-c4/s1600-h/image%5B10%5D.png"><img title="image" style="border-right: 0px; border-top: 0px; display: inline; border-left: 0px; border-bottom: 0px" height="344" alt="image" src="http://lh6.ggpht.com/_5tDgsxHFu4I/TAftfONW3UI/AAAAAAAABsE/oIXq7pAmJQc/image_thumb%5B21%5D.png?imgmax=800" width="303" border="0" /></a> </p> <div class="wlWriterEditableSmartContent" id="scid:f32c3428-b7e9-4f15-a8ea-c502c7ff2e88:42c24117-9e29-4960-ada8-bb63a129056d" style="padding-right: 0px; display: inline; padding-left: 0px; float: none; padding-bottom: 0px; margin: 0px; padding-top: 0px"><pre class="brush: vb">Sub InsertRows()<br />Application.ScreenUpdating = False<br />Dim numRows As Integer<br />Dim r As Long<br />r = Cells(Rows.Count, "A").End(xlUp).Row<br />numRows = 2<br />For r = r To 1 Step -1<br />Worksheets(4).Rows(r + 1).Resize(numRows).Insert<br />Next r<br />Application.ScreenUpdating = True<br />End Sub</pre></div> Ananta Acharyahttp://www.blogger.com/profile/07259109389692175071noreply@blogger.com0tag:blogger.com,1999:blog-4561390776828900110.post-31421075627372469622010-06-03T10:50:00.001-07:002012-02-15T19:24:41.265-08:00split a word with<p><span class="kwrd">Have you ever needed to split a word with certain character, yes I do, Mostly with _ or -</span></p> <span class="kwrd"></span> <p><span class="kwrd">here you go, an excel macro</span></p> <p><span class="kwrd"></span></p> <div class="wlWriterEditableSmartContent" id="scid:f32c3428-b7e9-4f15-a8ea-c502c7ff2e88:faf77690-8532-4c79-a1d0-1a824dc4f6b2" style="padding-right: 0px; display: inline; padding-left: 0px; float: none; padding-bottom: 0px; margin: 0px; padding-top: 0px"><pre class="brush: vb">Function split1(text) <br /><br />split1 = Split(text, "_")(0) <br /><br />End Function <br /><br />Function split2(text) <br /><br />split1 = Split(text, "_")(1) <br /><br />End Function<br /></pre></div> Ananta Acharyahttp://www.blogger.com/profile/07259109389692175071noreply@blogger.com0tag:blogger.com,1999:blog-4561390776828900110.post-31792425523378087962010-06-02T13:08:00.001-07:002012-02-15T19:24:41.270-08:00INDEX and MATCH in EXCEL<p><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh3bh1TEk9bIqc_hzt532HPyAx-foNaj20Bi6iyPxyTdvGRp1z0F-Eqp79HRokKHc7Qn6eN3yPnh6cJ5CTMFP_tW-_WctzP0Jo71htejDYbnVOgQGfDpmH6aJkgFoCdZaOjvy3OeMVYGhND/s1600-h/image%5B5%5D.png"><img title="image" style="border-right: 0px; border-top: 0px; display: inline; border-left: 0px; border-bottom: 0px" height="274" alt="image" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiLyCpSoQJ6m493et407I-o2nNAaNQO6eynXsvZ4G1BKSRYfIXN85PbGVbxtyGsoOlb8K13xIv__dmtM6byvkO6_xrHpO-Dbb5sWZscMRXTBog_M4h-OBaDXV9Er2LYU-LMCMZIwLPU2SEW/?imgmax=800" width="413" border="0" /></a> </p> <p>So, I needed to replace a number and its related value. So easy, the formula is </p> <p>=INDEX($I$2:$I$7,MATCH(B2,$H$2:$H$7,0))</p> Ananta Acharyahttp://www.blogger.com/profile/07259109389692175071noreply@blogger.com0tag:blogger.com,1999:blog-4561390776828900110.post-17508126168288859692010-05-27T07:53:00.001-07:002010-05-27T07:53:04.196-07:00Replace words in File (Python)<pre><pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; background-color: #ffffff">#batch renamer for contig and genBank Submission<br /></pre><pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; background-color: #ffffff">#written by ananta acharya, PBGG, UGA<br /></pre><pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; background-color: #ffffff">#May 28, 2010<br /></pre><pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; background-color: #ffffff"></pre><pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; background-color: #ffffff"></pre><pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; background-color: #ffffff">#This program reads a .csv or .txt file with names to be replaced in each line separated with comma, for example<br /></pre><pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; background-color: #ffffff">#oldname, newname<br /></pre><pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; background-color: #ffffff">#oldname2, newname2<br /></pre><pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; background-color: #ffffff"></pre><pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; background-color: #ffffff">#Then it replaces the oldnames in provided ace file with newnames<br /></pre><pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; background-color: #ffffff"></pre><pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; background-color: #ffffff">#to <span style="color: #0000ff">start</span>, u should give <span style="color: #0000ff">path</span> of the acefile and <span style="color: #0000ff">replace</span> file<br /></pre><pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; background-color: #ffffff">#It reports the number of lines that were replaced<br /></pre><pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; background-color: #ffffff"></pre><pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; background-color: #ffffff"><span style="color: #0000ff">import</span> <span style="color: #0000ff">os</span>.<span style="color: #0000ff">path</span><br /></pre><pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; background-color: #ffffff"><span style="color: #0000ff">import</span> <span style="color: #0000ff">os</span><br /></pre><pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; background-color: #ffffff"></pre><pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; background-color: #ffffff"><span style="color: #0000ff">def</span> OKtoRead(inputfile):<br /></pre><pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; background-color: #ffffff"> "<span style="color: #8b0000"></span>""Checks whether the input file is readable"<span style="color: #8b0000"></span>""<br /></pre><pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; background-color: #ffffff"> <br /></pre><pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; background-color: #ffffff"> <span style="color: #0000ff">if</span> not <span style="color: #0000ff">os</span>.<span style="color: #0000ff">path</span>.exists(inputfile):<br /></pre><pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; background-color: #ffffff"> <span style="color: #0000ff">print</span> "<span style="color: #8b0000">File does not Exist</span>"<br /></pre><pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; background-color: #ffffff"> <span style="color: #0000ff">return</span> False<br /></pre><pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; background-color: #ffffff"> <br /></pre><pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; background-color: #ffffff"> elif not <span style="color: #0000ff">os</span>.<span style="color: #0000ff">path</span>.isfile(inputfile):<br /></pre><pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; background-color: #ffffff"> <span style="color: #0000ff">print</span> "<span style="color: #8b0000">Is not a file</span>"<br /></pre><pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; background-color: #ffffff"> <span style="color: #0000ff">return</span> False<br /></pre><pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; background-color: #ffffff"></pre><pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; background-color: #ffffff"> <span style="color: #0000ff">return</span> True<br /></pre><pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; background-color: #ffffff"></pre><pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; background-color: #ffffff"></pre><pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; background-color: #ffffff"><span style="color: #0000ff">def</span> OKtoWrite(outputfile):<br /></pre><pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; background-color: #ffffff"> "<span style="color: #8b0000"></span>""Checks whether the input file is writable"<span style="color: #8b0000"></span>""<br /></pre><pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; background-color: #ffffff"> <br /></pre><pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; background-color: #ffffff"> <span style="color: #0000ff">if</span> not <span style="color: #0000ff">os</span>.<span style="color: #0000ff">path</span>.exists(<span style="color: #0000ff">os</span>.<span style="color: #0000ff">path</span>.dirname(outputfile)):<br /></pre><pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; background-color: #ffffff"> <span style="color: #0000ff">print</span> "<span style="color: #8b0000">Path Does Not Exist</span>"<br /></pre><pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; background-color: #ffffff"> <span style="color: #0000ff">return</span> False<br /></pre><pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; background-color: #ffffff"> <br /></pre><pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; background-color: #ffffff"> elif <span style="color: #0000ff">os</span>.<span style="color: #0000ff">path</span>.isdir(outputfile):<br /></pre><pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; background-color: #ffffff"> <span style="color: #0000ff">print</span> "<span style="color: #8b0000">Is not a file but folder</span>"<br /></pre><pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; background-color: #ffffff"> <span style="color: #0000ff">return</span> False<br /></pre><pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; background-color: #ffffff"> elif <span style="color: #0000ff">os</span>.<span style="color: #0000ff">path</span>.exists(outputfile):<br /></pre><pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; background-color: #ffffff"> <span style="color: #0000ff">print</span> "<span style="color: #8b0000">File already exists, Can not Overwite or Merge</span>"<br /></pre><pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; background-color: #ffffff"> <span style="color: #0000ff">return</span> False<br /></pre><pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; background-color: #ffffff"> <span style="color: #0000ff">else</span>:<br /></pre><pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; background-color: #ffffff"></pre><pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; background-color: #ffffff"> <span style="color: #0000ff">return</span> True<br /></pre><pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; background-color: #ffffff"> <br /></pre><pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; background-color: #ffffff"> <br /></pre><pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; background-color: #ffffff"></pre><pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; background-color: #ffffff"></pre><pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; background-color: #ffffff"></pre><pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; background-color: #ffffff"><span style="color: #0000ff">def</span> makeDict(txtFile):<br /></pre><pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; background-color: #ffffff"> <br /></pre><pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; background-color: #ffffff"> <span style="color: #0000ff">if</span> OKtoRead(txtFile):<br /></pre><pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; background-color: #ffffff"> txtFile=<span style="color: #0000ff">open</span>(txtFile)<br /></pre><pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; background-color: #ffffff"> renameDict={}<br /></pre><pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; background-color: #ffffff"> for line in txtFile:<br /></pre><pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; background-color: #ffffff"> aLine=line.<span style="color: #0000ff">strip</span>() <br /></pre><pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; background-color: #ffffff"> <br /></pre><pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; background-color: #ffffff"> sets=aLine.<span style="color: #0000ff">split</span>("<span style="color: #8b0000">,</span>")<br /></pre><pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; background-color: #ffffff"> <br /></pre><pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; background-color: #ffffff"> <span style="color: #0000ff">if</span> len(aLine)!=0:<br /></pre><pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; background-color: #ffffff"> <br /></pre><pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; background-color: #ffffff"> renameDict[sets[0]]=sets[1]<br /></pre><pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; background-color: #ffffff"> <br /></pre><pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; background-color: #ffffff"> <br /></pre><pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; background-color: #ffffff"> txtFile.<span style="color: #0000ff">close</span>()<br /></pre><pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; background-color: #ffffff"> <span style="color: #0000ff">return</span> renameDict<br /></pre><pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; background-color: #ffffff"></pre><pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; background-color: #ffffff"><span style="color: #0000ff">def</span> replaceNames(renameDict, aceFile):<br /></pre><pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; background-color: #ffffff"> aceFileNew=<span style="color: #0000ff">os</span>.<span style="color: #0000ff">path</span>.<span style="color: #0000ff">split</span>(aceFile)[0]+"<span style="color: #8b0000">/renamed</span>"+<span style="color: #0000ff">os</span>.<span style="color: #0000ff">path</span>.<span style="color: #0000ff">split</span>(aceFile)[1]<br /></pre><pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; background-color: #ffffff"> <br /></pre><pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; background-color: #ffffff"> #<span style="color: #0000ff">if</span> <span style="color: #0000ff">os</span>.<span style="color: #0000ff">path</span>.exists(aceFileNew):<br /></pre><pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; background-color: #ffffff"> # <span style="color: #0000ff">os</span>.remove(aceFileNew)<br /></pre><pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; background-color: #ffffff"> <span style="color: #0000ff">if</span> OKtoRead(aceFile):<br /></pre><pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; background-color: #ffffff"> aceFile=<span style="color: #0000ff">open</span>(aceFile,"<span style="color: #8b0000">r</span>")<br /></pre><pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; background-color: #ffffff"> newFile=<span style="color: #0000ff">open</span>(aceFileNew, "<span style="color: #8b0000">a</span>")<br /></pre><pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; background-color: #ffffff"> renameCount=0<br /></pre><pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; background-color: #ffffff"> lineCount=0<br /></pre><pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; background-color: #ffffff"> for line in aceFile:<br /></pre><pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; background-color: #ffffff"> lineCount+=1<br /></pre><pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; background-color: #ffffff"> for key, val in renameDict.iteritems():<br /></pre><pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; background-color: #ffffff"> <span style="color: #0000ff">if</span> key in line:<br /></pre><pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; background-color: #ffffff"> eachCount=line.<span style="color: #0000ff">count</span>(key)<br /></pre><pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; background-color: #ffffff"> renameCount+=1<br /></pre><pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; background-color: #ffffff"> newline=line.<span style="color: #0000ff">replace</span>(key, val)<br /></pre><pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; background-color: #ffffff"> <span style="color: #0000ff">print</span> "<span style="color: #8b0000">renaming in line %s, %s items found to replace</span>" %(lineCount, eachCount)<br /></pre><pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; background-color: #ffffff"> break<br /></pre><pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; background-color: #ffffff"> <span style="color: #0000ff">else</span>:<br /></pre><pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; background-color: #ffffff"> newline=line <br /></pre><pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; background-color: #ffffff"> newFile.<span style="color: #0000ff">write</span>(newline)<br /></pre><pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; background-color: #ffffff"> <br /></pre><pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; background-color: #ffffff"> aceFile.<span style="color: #0000ff">close</span>()<br /></pre><pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; background-color: #ffffff"> newFile.<span style="color: #0000ff">close</span>()<br /></pre><pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; background-color: #ffffff"> <span style="color: #0000ff">print</span> "<span style="color: #8b0000">number of replaced line=%s</span>" %renameCount<br /></pre><pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; background-color: #ffffff"> <span style="color: #0000ff">print</span> "<span style="color: #8b0000">File written in %s</span>" %aceFileNew<br /></pre><pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; background-color: #ffffff"> <br /></pre><pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; background-color: #ffffff"><span style="color: #0000ff">def</span> main():<br /></pre><pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; background-color: #ffffff"> aceFile=<span style="color: #0000ff">raw_input</span>("<span style="color: #8b0000">File location for .ace: (give full location, or relative starting ../: </span>") <br /></pre><pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; background-color: #ffffff"> while not OKtoRead(aceFile):<br /></pre><pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; background-color: #ffffff"> aceFile=<span style="color: #0000ff">raw_input</span>("<span style="color: #8b0000">File location for .ace: (give full location, or relative starting ../: </span>")<br /></pre><pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; background-color: #ffffff"> renameFile=<span style="color: #0000ff">raw_input</span>("<span style="color: #8b0000">File location for replacement , formatted as .txt or .csv , names separated with comma in each line: (give full location, or relative starting ../: </span>") <br /></pre><pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; background-color: #ffffff"> while not OKtoRead(renameFile):<br /></pre><pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; background-color: #ffffff"> renameFile=<span style="color: #0000ff">raw_input</span>("<span style="color: #8b0000">File location for replacement , formatted as .txt or .csv , names separated with comma in each line: (give full location, or relative starting ../: </span>")<br /></pre><pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; background-color: #ffffff"> <br /></pre><pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; background-color: #ffffff"> dictt=makeDict(renameFile)<br /></pre><pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; background-color: #ffffff"></pre><pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; background-color: #ffffff"> replaceNames(dictt,aceFile)<br /></pre><pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; background-color: #ffffff"></pre><pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; background-color: #ffffff">main()<br /></pre><pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; background-color: #ffffff"> </pre></pre> Ananta Acharyahttp://www.blogger.com/profile/07259109389692175071noreply@blogger.com0