<div>Hi,</div><div> </div><div>Thank you very much Stefan Behnel for your reply.</div><div> </div><div>I never thought you guys would go through my whole mail. Heck, no one bashed me about asking so many questions here (untill now)....no direct/indirect &quot;Go away/dont ask such stupid questions etc etc&quot; You people are amazingly patient and helpful.</div>
<div> </div><div>I am sure that there will be something in Python that will let me generate the hex stuff that I was talking about. I will spend more time learning this language. From what I understand, if something can be done in one scripting language, same can be done in any other, and definitely in Python.</div>
<div> </div><div> </div><div>Thank you sir once again.<br><br></div><div class="gmail_quote">On Mon, Nov 28, 2011 at 2:12 PM,  <span dir="ltr">&lt;<a href="mailto:tutor-request@python.org">tutor-request@python.org</a>&gt;</span> wrote:<br>
<blockquote style="margin: 0px 0px 0px 0.8ex; padding-left: 1ex; border-left-color: rgb(204, 204, 204); border-left-width: 1px; border-left-style: solid;" class="gmail_quote">Send Tutor mailing list submissions to<br>
        <a href="mailto:tutor@python.org">tutor@python.org</a><br>
<br>
To subscribe or unsubscribe via the World Wide Web, visit<br>
        <a href="http://mail.python.org/mailman/listinfo/tutor" target="_blank">http://mail.python.org/mailman/listinfo/tutor</a><br>
or, via email, send a message with subject or body &#39;help&#39; to<br>
        <a href="mailto:tutor-request@python.org">tutor-request@python.org</a><br>
<br>
You can reach the person managing the list at<br>
        <a href="mailto:tutor-owner@python.org">tutor-owner@python.org</a><br>
<br>
When replying, please edit your Subject line so it is more specific<br>
than &quot;Re: Contents of Tutor digest...&quot;<br>
<br>
<br>
Today&#39;s Topics:<br>
<br>
   1. Text Proccessing/Command Line Redirection/XML Parsing etc in<br>
      Python. (Pritesh Ugrankar)<br>
   2. Re: Random order program (Charles Becker)<br>
   3. Re: Text Proccessing/Command Line Redirection/XML Parsing etc<br>
      in Python. (Stefan Behnel)<br>
<br>
<br>
----------------------------------------------------------------------<br>
<br>
Message: 1<br>
Date: Mon, 28 Nov 2011 13:26:06 +0530<br>
From: Pritesh Ugrankar &lt;<a href="mailto:pritesh.ugrankar@gmail.com">pritesh.ugrankar@gmail.com</a>&gt;<br>
To: <a href="mailto:tutor@python.org">tutor@python.org</a><br>
Subject: [Tutor] Text Proccessing/Command Line Redirection/XML Parsing<br>
        etc     in Python.<br>
Message-ID:<br>
        &lt;<a href="mailto:CAFXxuzxtMSpftbAaT5zaZ_3XScpVxXOx7giQZzRo2WYhGs8BsQ@mail.gmail.com">CAFXxuzxtMSpftbAaT5zaZ_3XScpVxXOx7giQZzRo2WYhGs8BsQ@mail.gmail.com</a>&gt;<br>
Content-Type: text/plain; charset=&quot;iso-8859-1&quot;<br>
<br>
First of all, my apologies for writing this very long post.<br>
<br>
I have been through some related questions about this in Stack Overflow as<br>
well as googled it and found that Perl and Python are the two languages<br>
that offer most what I need. As a SAN Administrator, I have a very limited<br>
time to learn a scripting language so I can concentrate on only one. Most<br>
of my questions below may make you think that I prefer Perl, but its<br>
nothing like...Just that I tried learning Perl before for doing stuff I<br>
want to try, but am thinking now what advantages will I have if I try out<br>
Python?<br>
<br>
All my SAN Management Servers are Windows only.<br>
<br>
Following is what I am specifically looking at:<br>
<br>
1) Consider the following output:<br>
symdev -sid 1234 list devs<br>
0D62 Not Visible    ???:? 07C:D13 RAID-5        N/A     (DT) RW  187843<br>
0D63 Not Visible    ???:? 08C:C11 RAID-5        N/A     (DT) RW  187843<br>
0D64 Not Visible    ???:? 07C:C12 RAID-5        N/A     (DT) RW  62614<br>
0D65 Not Visible    ???:? 08C:D14 RAID-5        N/A     (DT) RW  62614<br>
0D66 Not Visible    ???:? 07C:D15 RAID-5        N/A     (DT) RW  31307<br>
0D67 Not Visible    ???:? 08C:C13 RAID-5        N/A     (DT) RW  31307<br>
0D68 Not Visible    ???:? 07C:C14 RAID-5        N/A     (DT) RW  31307<br>
<br>
 Whats given above is only a small part of the output. There are many other<br>
fields that appear but I have left those out for brevity.<br>
<br>
The symdev commands generates a list of devices that can be used for SAN<br>
Allocation.<br>
<br>
What I want to do is, on the Windows Machines, do something like a grep or<br>
awk so that the 10th field, which contains the size of the devices will be<br>
filtered and I can generate an output like.<br>
<br>
Devices of 187 GB = 3<br>
<br>
Devices of 62 GB = 2<br>
<br>
Devices of 31 GB = 3<br>
<br>
Thing is, this output will differ on each storage box. Some may have 10<br>
devices, some may have 100....<br>
<br>
I can use grep or awk for Windows, but looking at a bigger picture here.<br>
<br>
what I want to do is do some kind of filtering of the command line output<br>
so that it will count the type of devices and seggregate them according to<br>
their size.<br>
<br>
Tried Perl, but I found that the syntax was a little difficult to remember.<br>
This is again my own shortcoming as I am not a trained programmer. I only<br>
got to work on the script after a gap of many weeks and by that time, I<br>
forgot what the script was supposed to do so had to start from the<br>
scratch....May be commenting will help :)<br>
<br>
I could only get to a point where I was able to store the out put of the<br>
whole line in an array but nothing beyond that because workload kept me<br>
really busy.<br>
<br>
When I did that, each element of the array seem to have one line of the<br>
output, like: The following was one element.<br>
0D62 Not Visible    ???:? 07C:D13 RAID-5        N/A     (DT) RW  187843<br>
<br>
 The following was the next element.<br>
0D63 Not Visible    ???:? 08C:C11 RAID-5        N/A     (DT) RW  187843<br>
<br>
 and so on.....<br>
<br>
What I wanted instead was a way to printout and count the last field.....I<br>
guess I will have to use hashes in Perl. Most examples of Hashes I have<br>
seen are pre created....But is there a way to create a Hash on the fly?<br>
Because I dont know how many devices will be a part of that hash....it will<br>
differ on each storage box....Is there something like this available in<br>
Python that will let me filter/add/printout the last field in a way that it<br>
will refer to it as a row and column kind of stuff? Is there a Hash<br>
equivalent in Python?<br>
<br>
Note I am giving Perl examples because I started with Perl first....though<br>
personally, I find Python syntax easier to understand...(Again, my<br>
bad....my limitation...not of the language)..<br>
<br>
2) Automate storage allocation. Whats given below is only a small part of<br>
what I want to do.... Given is a brief output and explanation.<br>
<br>
All storage devices of my storage boxes have hexamdecimal LUN IDs.....<br>
<br>
Lets say I have a free available LUN IDs between say 5* to A .....meaning,<br>
the command output looks something like this:<br>
symcfg list -sid 1234 -sa 04B -p 0 -addresses -available<br>
Symmetrix ID: 000184501234<br>
Director Device Name Attr Address<br>
---------------------- ----------------------------- ---- --------------<br>
Ident Symbolic Port Sym Physical VBUS TID LUN<br>
------ -------- ---- ---- ----------------------- ---- --- ---<br>
FA-4B 04B 0 - AVAILABLE 0 0 000 *<br>
0029 /dev/rdsk/c1t0d1s2 0 0 001<br>
0033 /dev/rdsk/c1t0d2s2 0 0 002<br>
003D /dev/rdsk/c1t0d3s2 0 0 003<br>
0046 Not Visible        0 0 004<br>
- AVAILABLE             0 0 005 *<br>
0075 Not Visible        0 0 00A<br>
- AVAILABLE             0 0 00B *<br>
<br>
 When there is a &quot;*&quot;, from there on, till the next hex number, th LUN IDs<br>
are available. Meaning, from 000* to 1, nothing is available, but from 005*<br>
to 00A I have 006 through 009 available. I want to redirect this output to<br>
an array or a hash or something like that, then filter the last field, and<br>
then on the fly generate the LUN IDs between the 005 to 009 as well..Then<br>
using some commands, automate the process of allocating the LUN IDs to some<br>
free avaiable LUNs which I found in the first command output....<br>
<br>
Is Perl better at manipulating hex or python?<br>
<br>
I know its possible to redirect the above output to a text file as well as<br>
a CSV file or an XML File and do I/Os on those files and then .but is Perl<br>
better for that or Python?<br>
<br>
3) I want to generate reports on Performance, like which LUN has more<br>
IOs....What will be helpful here is a language that can help me create<br>
these graphs in excel....run the script and the output should generate a<br>
graph in Excel....<br>
<br>
Which language is better suited for my needs? I found Perl syntax a little<br>
cryptic, but if Perl will be faster and better suited than Python, then I<br>
am ready to invest more time with Perl....<br>
<br>
Which language will be faster for text processing/automation?<br>
<br>
Which language will generate Binary executable that is smaller in size and<br>
faster?<br>
I played a little with Python too...today is my third day....Found the<br>
syntax much easier to learn....Also came across cxfreeze which creates<br>
independent binary executables...is something such available in Perl?<br>
<br>
4) I also want to try out playing with XML output....The storage commands I<br>
use allow me the output to be directed to an XML Format....Is Python better<br>
suited at this ?<br>
<br>
Few more questions pop up like, Which will give me more freedom and ease to<br>
maintain ? Which scripting language is better from the employability point<br>
of view?<br>
<br>
I dont want to start with one language and six months or a year down think<br>
&quot;Heck, this was better in the other one&quot;.....because I really can<br>
concentrate on only one langauge.<br>
<br>
My apologies in advance if any questions above seem to be dumb or naive.<br>
-------------- next part --------------<br>
An HTML attachment was scrubbed...<br>
URL: &lt;<a href="http://mail.python.org/pipermail/tutor/attachments/20111128/ded43c3c/attachment-0001.html" target="_blank">http://mail.python.org/pipermail/tutor/attachments/20111128/ded43c3c/attachment-0001.html</a>&gt;<br>

<br>
------------------------------<br>
<br>
Message: 2<br>
Date: Mon, 28 Nov 2011 00:57:10 -0700<br>
From: Charles Becker &lt;<a href="mailto:charleshbecker@gmail.com">charleshbecker@gmail.com</a>&gt;<br>
To: &quot;<a href="mailto:d@davea.name">d@davea.name</a>&quot; &lt;<a href="mailto:d@davea.name">d@davea.name</a>&gt;<br>
Cc: &quot;<a href="mailto:tutor@python.org">tutor@python.org</a>&quot; &lt;<a href="mailto:tutor@python.org">tutor@python.org</a>&gt;,      myles broomes<br>
        &lt;<a href="mailto:mylesbroomes@hotmail.co.uk">mylesbroomes@hotmail.co.uk</a>&gt;<br>
Subject: Re: [Tutor] Random order program<br>
Message-ID: &lt;<a href="mailto:C59A2F2B-913B-47A4-B600-91692B4AD88C@gmail.com">C59A2F2B-913B-47A4-B600-91692B4AD88C@gmail.com</a>&gt;<br>
Content-Type: text/plain; charset=&quot;us-ascii&quot;<br>
<br>
Dave, Myles, et al,<br>
<br>
On Nov 27, 2011, at 4:25 PM, Dave Angel &lt;<a href="mailto:d@davea.name">d@davea.name</a>&gt; wrote:<br>
<br>
&gt; On 11/27/2011 05:17 PM, myles broomes wrote:<br>
&gt;&gt;<br>
&gt;&gt;<br>
&gt;&gt;<br>
&gt;&gt;<br>
&gt;&gt;<br>
&gt;&gt;<br>
&gt;&gt;<br>
&gt;&gt; #random order list<br>
&gt;&gt; while len(random_word_list) != len(word_list):<br>
&gt;&gt;         word = random.choice(word_list)<br>
&gt;&gt;         if word not in random_word_list:<br>
&gt;&gt;                 random_word_list += word<br>
&gt;&gt;<br>
&gt; If you use  += operator with list on the left side, it assumes something compatible with list on the right.  So either use<br>
&gt;             random_word_list  +=  [word]<br>
&gt; Or else use random_word_list.append(word)<br>
&gt;&gt;<br>
&gt;&gt;<br>
&gt;&gt;<br>
&gt;&gt;<br>
&gt;&gt;<br>
<br>
Everyone has offered some good feedback, I just wanted to throw in this, and hopefully everyone can say if I&#39;m correct or not:<br>
<br>
A way to make the code more &#39;pythonic&#39; and easier to read might be to replace the conditional<br>
while len(random_word_list) != len(word_list)<br>
With the following :<br>
For x in range(len(word_list))<br>
This will prevent infinite loops, easier to read, and allows for a lot of other uses (even if x is never used).  Any thoughts people?  And would this method (on a small or large scale) be &#39;cheaper&#39; than the original conditional? Or more &#39;pythonic&#39;?<br>

<br>
Charles<br>
<br>
Sent from my iPhone<br>
-------------- next part --------------<br>
An HTML attachment was scrubbed...<br>
URL: &lt;<a href="http://mail.python.org/pipermail/tutor/attachments/20111128/a1076e0e/attachment-0001.html" target="_blank">http://mail.python.org/pipermail/tutor/attachments/20111128/a1076e0e/attachment-0001.html</a>&gt;<br>

<br>
------------------------------<br>
<br>
Message: 3<br>
Date: Mon, 28 Nov 2011 08:42:36 +0000<br>
From: Stefan Behnel &lt;<a href="mailto:stefan_ml@behnel.de">stefan_ml@behnel.de</a>&gt;<br>
To: <a href="mailto:tutor@python.org">tutor@python.org</a><br>
Subject: Re: [Tutor] Text Proccessing/Command Line Redirection/XML<br>
        Parsing etc in Python.<br>
Message-ID: &lt;javhht$llr$<a href="mailto:1@dough.gmane.org">1@dough.gmane.org</a>&gt;<br>
Content-Type: text/plain; charset=UTF-8; format=flowed<br>
<br>
Pritesh Ugrankar, 28.11.2011 07:56:<br>
&gt; First of all, my apologies for writing this very long post.<br>
<br>
Welcome to the list. :)<br>
<br>
<br>
&gt; I have been through some related questions about this in Stack Overflow as<br>
&gt; well as googled it and found that Perl and Python are the two languages<br>
&gt; that offer most what I need. As a SAN Administrator, I have a very limited<br>
&gt; time to learn a scripting language so I can concentrate on only one. Most<br>
&gt; of my questions below may make you think that I prefer Perl, but its<br>
&gt; nothing like...Just that I tried learning Perl before for doing stuff I<br>
&gt; want to try, but am thinking now what advantages will I have if I try out<br>
&gt; Python?<br>
<br>
There are two anecdotes that people from both camps frequently report. With<br>
Perl, people write their script, and then, several months later, they come<br>
back, look at it, don&#39;t understand it anymore, and rewrite it. With Python,<br>
people write their script, forget about it over time, write it again when<br>
they need it, and when they happen to find the old one and compare it to<br>
the new one, they find that both look almost identical.<br>
<br>
It&#39;s all in the syntax.<br>
<br>
<br>
&gt; All my SAN Management Servers are Windows only.<br>
&gt;<br>
&gt; Following is what I am specifically looking at:<br>
&gt;<br>
&gt; 1) Consider the following output:<br>
&gt; symdev -sid 1234 list devs<br>
&gt; 0D62 Not Visible    ???:? 07C:D13 RAID-5        N/A     (DT) RW  187843<br>
&gt; 0D63 Not Visible    ???:? 08C:C11 RAID-5        N/A     (DT) RW  187843<br>
&gt; 0D64 Not Visible    ???:? 07C:C12 RAID-5        N/A     (DT) RW  62614<br>
&gt; 0D65 Not Visible    ???:? 08C:D14 RAID-5        N/A     (DT) RW  62614<br>
&gt; 0D66 Not Visible    ???:? 07C:D15 RAID-5        N/A     (DT) RW  31307<br>
&gt; 0D67 Not Visible    ???:? 08C:C13 RAID-5        N/A     (DT) RW  31307<br>
&gt; 0D68 Not Visible    ???:? 07C:C14 RAID-5        N/A     (DT) RW  31307<br>
&gt;<br>
&gt;   Whats given above is only a small part of the output. There are many other<br>
&gt; fields that appear but I have left those out for brevity.<br>
&gt;<br>
&gt; The symdev commands generates a list of devices that can be used for SAN<br>
&gt; Allocation.<br>
&gt;<br>
&gt; What I want to do is, on the Windows Machines, do something like a grep or<br>
&gt; awk so that the 10th field, which contains the size of the devices will be<br>
&gt; filtered and I can generate an output like.<br>
&gt;<br>
&gt; Devices of 187 GB = 3<br>
&gt;<br>
&gt; Devices of 62 GB = 2<br>
&gt;<br>
&gt; Devices of 31 GB = 3<br>
&gt;<br>
&gt; Thing is, this output will differ on each storage box. Some may have 10<br>
&gt; devices, some may have 100....<br>
&gt;<br>
&gt; I can use grep or awk for Windows, but looking at a bigger picture here.<br>
&gt;<br>
&gt; what I want to do is do some kind of filtering of the command line output<br>
&gt; so that it will count the type of devices and seggregate them according to<br>
&gt; their size.<br>
<br>
That&#39;s really easy. You open the file (see the open() function) and it<br>
returns a file object. You can iterate over it with a for-loop, and it will<br>
return each line as a string. Use the split() method on the string object<br>
to split the string by whitespace. That returns a list of separate fields.<br>
Then, pick the fields you want. In code:<br>
<br>
     with open(&#39;thefile.txt&#39;) as f:<br>
         for line in f:<br>
             fields = line.split()<br>
             print(fields[9])       # the 10th field, for example<br>
<br>
If you are not reading the output from a file but from a process you<br>
started, take a look at the subprocess module in the standard library.<br>
<br>
<a href="http://docs.python.org/library/subprocess.html" target="_blank">http://docs.python.org/library/subprocess.html</a><br>
<br>
Also take a look at string formatting for output.<br>
<br>
<a href="http://docs.python.org/tutorial/inputoutput.html" target="_blank">http://docs.python.org/tutorial/inputoutput.html</a><br>
<br>
<a href="http://docs.python.org/library/stdtypes.html#string-formatting-operations" target="_blank">http://docs.python.org/library/stdtypes.html#string-formatting-operations</a><br>
<br>
<br>
&gt; Tried Perl, but I found that the syntax was a little difficult to remember.<br>
&gt; This is again my own shortcoming as I am not a trained programmer. I only<br>
&gt; got to work on the script after a gap of many weeks and by that time, I<br>
&gt; forgot what the script was supposed to do so had to start from the<br>
&gt; scratch....May be commenting will help :)<br>
<br>
Yep, that&#39;s Perl at it&#39;s best.<br>
<br>
<br>
&gt; Which language will generate Binary executable that is smaller in size and<br>
&gt; faster?<br>
<br>
You usually don&#39;t do that. Instead, you&#39;d install Python on all machines<br>
where you need it and then just run your code there.<br>
<br>
If you really want to go through the hassle to build a self-contained<br>
executable from each program you write, you will have to bundle the runtime<br>
for either language with it, so it won&#39;t be small.<br>
<br>
<br>
&gt; 4) I also want to try out playing with XML output....The storage commands I<br>
&gt; use allow me the output to be directed to an XML Format....Is Python better<br>
&gt; suited at this ?<br>
<br>
Absolutely. Python has ElementTree. You&#39;ll just love working with it.<br>
<br>
<a href="http://docs.python.org/library/xml.etree.elementtree.html" target="_blank">http://docs.python.org/library/xml.etree.elementtree.html</a><br>
<br>
A quick tutorial is here:<br>
<br>
<a href="http://effbot.org/zone/element-index.htm" target="_blank">http://effbot.org/zone/element-index.htm</a><br>
<br>
<br>
&gt; Few more questions pop up like, Which will give me more freedom and ease to<br>
&gt; maintain ? Which scripting language is better from the employability point<br>
&gt; of view?<br>
&gt;<br>
&gt; I dont want to start with one language and six months or a year down think<br>
&gt; &quot;Heck, this was better in the other one&quot;.....because I really can<br>
&gt; concentrate on only one langauge.<br>
<br>
There are always certain types of problems that can be solved very<br>
beautifully in a particular language. That&#39;s why there&#39;s more than one<br>
language. You won&#39;t miss anything by choosing Python, though.<br>
<br>
Stefan<br>
<br>
<br>
<br>
------------------------------<br>
<br>
_______________________________________________<br>
Tutor maillist  -  <a href="mailto:Tutor@python.org">Tutor@python.org</a><br>
<a href="http://mail.python.org/mailman/listinfo/tutor" target="_blank">http://mail.python.org/mailman/listinfo/tutor</a><br>
<br>
<br>
End of Tutor Digest, Vol 93, Issue 158<br>
**************************************<br>
</blockquote></div><br>