[Tutor] Tutor Digest, Vol 93, Issue 158
Pritesh Ugrankar
pritesh.ugrankar at gmail.com
Mon Nov 28 10:08:42 CET 2011
Hi,
Thank you very much Stefan Behnel for your reply.
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 "Go away/dont ask such stupid questions etc etc" You people
are amazingly patient and helpful.
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.
Thank you sir once again.
On Mon, Nov 28, 2011 at 2:12 PM, <tutor-request at python.org> wrote:
> Send Tutor mailing list submissions to
> tutor at python.org
>
> To subscribe or unsubscribe via the World Wide Web, visit
> http://mail.python.org/mailman/listinfo/tutor
> or, via email, send a message with subject or body 'help' to
> tutor-request at python.org
>
> You can reach the person managing the list at
> tutor-owner at python.org
>
> When replying, please edit your Subject line so it is more specific
> than "Re: Contents of Tutor digest..."
>
>
> Today's Topics:
>
> 1. Text Proccessing/Command Line Redirection/XML Parsing etc in
> Python. (Pritesh Ugrankar)
> 2. Re: Random order program (Charles Becker)
> 3. Re: Text Proccessing/Command Line Redirection/XML Parsing etc
> in Python. (Stefan Behnel)
>
>
> ----------------------------------------------------------------------
>
> Message: 1
> Date: Mon, 28 Nov 2011 13:26:06 +0530
> From: Pritesh Ugrankar <pritesh.ugrankar at gmail.com>
> To: tutor at python.org
> Subject: [Tutor] Text Proccessing/Command Line Redirection/XML Parsing
> etc in Python.
> Message-ID:
> <CAFXxuzxtMSpftbAaT5zaZ_3XScpVxXOx7giQZzRo2WYhGs8BsQ at mail.gmail.com
> >
> Content-Type: text/plain; charset="iso-8859-1"
>
> First of all, my apologies for writing this very long post.
>
> I have been through some related questions about this in Stack Overflow as
> well as googled it and found that Perl and Python are the two languages
> that offer most what I need. As a SAN Administrator, I have a very limited
> time to learn a scripting language so I can concentrate on only one. Most
> of my questions below may make you think that I prefer Perl, but its
> nothing like...Just that I tried learning Perl before for doing stuff I
> want to try, but am thinking now what advantages will I have if I try out
> Python?
>
> All my SAN Management Servers are Windows only.
>
> Following is what I am specifically looking at:
>
> 1) Consider the following output:
> symdev -sid 1234 list devs
> 0D62 Not Visible ???:? 07C:D13 RAID-5 N/A (DT) RW 187843
> 0D63 Not Visible ???:? 08C:C11 RAID-5 N/A (DT) RW 187843
> 0D64 Not Visible ???:? 07C:C12 RAID-5 N/A (DT) RW 62614
> 0D65 Not Visible ???:? 08C:D14 RAID-5 N/A (DT) RW 62614
> 0D66 Not Visible ???:? 07C:D15 RAID-5 N/A (DT) RW 31307
> 0D67 Not Visible ???:? 08C:C13 RAID-5 N/A (DT) RW 31307
> 0D68 Not Visible ???:? 07C:C14 RAID-5 N/A (DT) RW 31307
>
> Whats given above is only a small part of the output. There are many other
> fields that appear but I have left those out for brevity.
>
> The symdev commands generates a list of devices that can be used for SAN
> Allocation.
>
> What I want to do is, on the Windows Machines, do something like a grep or
> awk so that the 10th field, which contains the size of the devices will be
> filtered and I can generate an output like.
>
> Devices of 187 GB = 3
>
> Devices of 62 GB = 2
>
> Devices of 31 GB = 3
>
> Thing is, this output will differ on each storage box. Some may have 10
> devices, some may have 100....
>
> I can use grep or awk for Windows, but looking at a bigger picture here.
>
> what I want to do is do some kind of filtering of the command line output
> so that it will count the type of devices and seggregate them according to
> their size.
>
> Tried Perl, but I found that the syntax was a little difficult to remember.
> This is again my own shortcoming as I am not a trained programmer. I only
> got to work on the script after a gap of many weeks and by that time, I
> forgot what the script was supposed to do so had to start from the
> scratch....May be commenting will help :)
>
> I could only get to a point where I was able to store the out put of the
> whole line in an array but nothing beyond that because workload kept me
> really busy.
>
> When I did that, each element of the array seem to have one line of the
> output, like: The following was one element.
> 0D62 Not Visible ???:? 07C:D13 RAID-5 N/A (DT) RW 187843
>
> The following was the next element.
> 0D63 Not Visible ???:? 08C:C11 RAID-5 N/A (DT) RW 187843
>
> and so on.....
>
> What I wanted instead was a way to printout and count the last field.....I
> guess I will have to use hashes in Perl. Most examples of Hashes I have
> seen are pre created....But is there a way to create a Hash on the fly?
> Because I dont know how many devices will be a part of that hash....it will
> differ on each storage box....Is there something like this available in
> Python that will let me filter/add/printout the last field in a way that it
> will refer to it as a row and column kind of stuff? Is there a Hash
> equivalent in Python?
>
> Note I am giving Perl examples because I started with Perl first....though
> personally, I find Python syntax easier to understand...(Again, my
> bad....my limitation...not of the language)..
>
> 2) Automate storage allocation. Whats given below is only a small part of
> what I want to do.... Given is a brief output and explanation.
>
> All storage devices of my storage boxes have hexamdecimal LUN IDs.....
>
> Lets say I have a free available LUN IDs between say 5* to A .....meaning,
> the command output looks something like this:
> symcfg list -sid 1234 -sa 04B -p 0 -addresses -available
> Symmetrix ID: 000184501234
> Director Device Name Attr Address
> ---------------------- ----------------------------- ---- --------------
> Ident Symbolic Port Sym Physical VBUS TID LUN
> ------ -------- ---- ---- ----------------------- ---- --- ---
> FA-4B 04B 0 - AVAILABLE 0 0 000 *
> 0029 /dev/rdsk/c1t0d1s2 0 0 001
> 0033 /dev/rdsk/c1t0d2s2 0 0 002
> 003D /dev/rdsk/c1t0d3s2 0 0 003
> 0046 Not Visible 0 0 004
> - AVAILABLE 0 0 005 *
> 0075 Not Visible 0 0 00A
> - AVAILABLE 0 0 00B *
>
> When there is a "*", from there on, till the next hex number, th LUN IDs
> are available. Meaning, from 000* to 1, nothing is available, but from 005*
> to 00A I have 006 through 009 available. I want to redirect this output to
> an array or a hash or something like that, then filter the last field, and
> then on the fly generate the LUN IDs between the 005 to 009 as well..Then
> using some commands, automate the process of allocating the LUN IDs to some
> free avaiable LUNs which I found in the first command output....
>
> Is Perl better at manipulating hex or python?
>
> I know its possible to redirect the above output to a text file as well as
> a CSV file or an XML File and do I/Os on those files and then .but is Perl
> better for that or Python?
>
> 3) I want to generate reports on Performance, like which LUN has more
> IOs....What will be helpful here is a language that can help me create
> these graphs in excel....run the script and the output should generate a
> graph in Excel....
>
> Which language is better suited for my needs? I found Perl syntax a little
> cryptic, but if Perl will be faster and better suited than Python, then I
> am ready to invest more time with Perl....
>
> Which language will be faster for text processing/automation?
>
> Which language will generate Binary executable that is smaller in size and
> faster?
> I played a little with Python too...today is my third day....Found the
> syntax much easier to learn....Also came across cxfreeze which creates
> independent binary executables...is something such available in Perl?
>
> 4) I also want to try out playing with XML output....The storage commands I
> use allow me the output to be directed to an XML Format....Is Python better
> suited at this ?
>
> Few more questions pop up like, Which will give me more freedom and ease to
> maintain ? Which scripting language is better from the employability point
> of view?
>
> I dont want to start with one language and six months or a year down think
> "Heck, this was better in the other one".....because I really can
> concentrate on only one langauge.
>
> My apologies in advance if any questions above seem to be dumb or naive.
> -------------- next part --------------
> An HTML attachment was scrubbed...
> URL: <
> http://mail.python.org/pipermail/tutor/attachments/20111128/ded43c3c/attachment-0001.html
> >
>
> ------------------------------
>
> Message: 2
> Date: Mon, 28 Nov 2011 00:57:10 -0700
> From: Charles Becker <charleshbecker at gmail.com>
> To: "d at davea.name" <d at davea.name>
> Cc: "tutor at python.org" <tutor at python.org>, myles broomes
> <mylesbroomes at hotmail.co.uk>
> Subject: Re: [Tutor] Random order program
> Message-ID: <C59A2F2B-913B-47A4-B600-91692B4AD88C at gmail.com>
> Content-Type: text/plain; charset="us-ascii"
>
> Dave, Myles, et al,
>
> On Nov 27, 2011, at 4:25 PM, Dave Angel <d at davea.name> wrote:
>
> > On 11/27/2011 05:17 PM, myles broomes wrote:
> >>
> >>
> >>
> >>
> >>
> >>
> >>
> >> #random order list
> >> while len(random_word_list) != len(word_list):
> >> word = random.choice(word_list)
> >> if word not in random_word_list:
> >> random_word_list += word
> >>
> > If you use += operator with list on the left side, it assumes something
> compatible with list on the right. So either use
> > random_word_list += [word]
> > Or else use random_word_list.append(word)
> >>
> >>
> >>
> >>
> >>
>
> Everyone has offered some good feedback, I just wanted to throw in this,
> and hopefully everyone can say if I'm correct or not:
>
> A way to make the code more 'pythonic' and easier to read might be to
> replace the conditional
> while len(random_word_list) != len(word_list)
> With the following :
> For x in range(len(word_list))
> 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 'cheaper' than the original
> conditional? Or more 'pythonic'?
>
> Charles
>
> Sent from my iPhone
> -------------- next part --------------
> An HTML attachment was scrubbed...
> URL: <
> http://mail.python.org/pipermail/tutor/attachments/20111128/a1076e0e/attachment-0001.html
> >
>
> ------------------------------
>
> Message: 3
> Date: Mon, 28 Nov 2011 08:42:36 +0000
> From: Stefan Behnel <stefan_ml at behnel.de>
> To: tutor at python.org
> Subject: Re: [Tutor] Text Proccessing/Command Line Redirection/XML
> Parsing etc in Python.
> Message-ID: <javhht$llr$1 at dough.gmane.org>
> Content-Type: text/plain; charset=UTF-8; format=flowed
>
> Pritesh Ugrankar, 28.11.2011 07:56:
> > First of all, my apologies for writing this very long post.
>
> Welcome to the list. :)
>
>
> > I have been through some related questions about this in Stack Overflow
> as
> > well as googled it and found that Perl and Python are the two languages
> > that offer most what I need. As a SAN Administrator, I have a very
> limited
> > time to learn a scripting language so I can concentrate on only one. Most
> > of my questions below may make you think that I prefer Perl, but its
> > nothing like...Just that I tried learning Perl before for doing stuff I
> > want to try, but am thinking now what advantages will I have if I try out
> > Python?
>
> There are two anecdotes that people from both camps frequently report. With
> Perl, people write their script, and then, several months later, they come
> back, look at it, don't understand it anymore, and rewrite it. With Python,
> people write their script, forget about it over time, write it again when
> they need it, and when they happen to find the old one and compare it to
> the new one, they find that both look almost identical.
>
> It's all in the syntax.
>
>
> > All my SAN Management Servers are Windows only.
> >
> > Following is what I am specifically looking at:
> >
> > 1) Consider the following output:
> > symdev -sid 1234 list devs
> > 0D62 Not Visible ???:? 07C:D13 RAID-5 N/A (DT) RW 187843
> > 0D63 Not Visible ???:? 08C:C11 RAID-5 N/A (DT) RW 187843
> > 0D64 Not Visible ???:? 07C:C12 RAID-5 N/A (DT) RW 62614
> > 0D65 Not Visible ???:? 08C:D14 RAID-5 N/A (DT) RW 62614
> > 0D66 Not Visible ???:? 07C:D15 RAID-5 N/A (DT) RW 31307
> > 0D67 Not Visible ???:? 08C:C13 RAID-5 N/A (DT) RW 31307
> > 0D68 Not Visible ???:? 07C:C14 RAID-5 N/A (DT) RW 31307
> >
> > Whats given above is only a small part of the output. There are many
> other
> > fields that appear but I have left those out for brevity.
> >
> > The symdev commands generates a list of devices that can be used for SAN
> > Allocation.
> >
> > What I want to do is, on the Windows Machines, do something like a grep
> or
> > awk so that the 10th field, which contains the size of the devices will
> be
> > filtered and I can generate an output like.
> >
> > Devices of 187 GB = 3
> >
> > Devices of 62 GB = 2
> >
> > Devices of 31 GB = 3
> >
> > Thing is, this output will differ on each storage box. Some may have 10
> > devices, some may have 100....
> >
> > I can use grep or awk for Windows, but looking at a bigger picture here.
> >
> > what I want to do is do some kind of filtering of the command line output
> > so that it will count the type of devices and seggregate them according
> to
> > their size.
>
> That's really easy. You open the file (see the open() function) and it
> returns a file object. You can iterate over it with a for-loop, and it will
> return each line as a string. Use the split() method on the string object
> to split the string by whitespace. That returns a list of separate fields.
> Then, pick the fields you want. In code:
>
> with open('thefile.txt') as f:
> for line in f:
> fields = line.split()
> print(fields[9]) # the 10th field, for example
>
> If you are not reading the output from a file but from a process you
> started, take a look at the subprocess module in the standard library.
>
> http://docs.python.org/library/subprocess.html
>
> Also take a look at string formatting for output.
>
> http://docs.python.org/tutorial/inputoutput.html
>
> http://docs.python.org/library/stdtypes.html#string-formatting-operations
>
>
> > Tried Perl, but I found that the syntax was a little difficult to
> remember.
> > This is again my own shortcoming as I am not a trained programmer. I only
> > got to work on the script after a gap of many weeks and by that time, I
> > forgot what the script was supposed to do so had to start from the
> > scratch....May be commenting will help :)
>
> Yep, that's Perl at it's best.
>
>
> > Which language will generate Binary executable that is smaller in size
> and
> > faster?
>
> You usually don't do that. Instead, you'd install Python on all machines
> where you need it and then just run your code there.
>
> If you really want to go through the hassle to build a self-contained
> executable from each program you write, you will have to bundle the runtime
> for either language with it, so it won't be small.
>
>
> > 4) I also want to try out playing with XML output....The storage
> commands I
> > use allow me the output to be directed to an XML Format....Is Python
> better
> > suited at this ?
>
> Absolutely. Python has ElementTree. You'll just love working with it.
>
> http://docs.python.org/library/xml.etree.elementtree.html
>
> A quick tutorial is here:
>
> http://effbot.org/zone/element-index.htm
>
>
> > Few more questions pop up like, Which will give me more freedom and ease
> to
> > maintain ? Which scripting language is better from the employability
> point
> > of view?
> >
> > I dont want to start with one language and six months or a year down
> think
> > "Heck, this was better in the other one".....because I really can
> > concentrate on only one langauge.
>
> There are always certain types of problems that can be solved very
> beautifully in a particular language. That's why there's more than one
> language. You won't miss anything by choosing Python, though.
>
> Stefan
>
>
>
> ------------------------------
>
> _______________________________________________
> Tutor maillist - Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>
>
> End of Tutor Digest, Vol 93, Issue 158
> **************************************
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20111128/e49a7d65/attachment-0001.html>
More information about the Tutor
mailing list