Re: [Tutor] Tkinter grid manager question

2011-11-27 Thread Peter Otten
Chris Hare wrote:


> I am attempting to create a form for the user to complete.  I have the
> basic layout and supporting code working, but I am having a problem with
> getting things to display in the grid the way I want them.
> 
> self.label1 = Label(self.frame, text = "Double
> click on a name from the list in the right.  Make
> your changes in the field below and press the Save
> button.", fg="Blue", bg=backColor) self.label2 =
> Label(self.frame, text = "Current Animal Types",
> fg="Blue", bg=backColor)
> …...
> self.label1.grid(row=1, column=0,columnspan=3, sticky=W)
> self.label2.grid(row=2, column=0,columnspan=1, sticky=W)
> self.list.grid(row=2, column=3, columnspan=2, sticky=W)
> self.label3.grid(row=3, column=0,columnspan=1, sticky=W)
> 
> My problem is that the cell which contains the text for label2 is the same
> size as the text in label1.  What I am trying to accomplish is to have the
> text in label1 span the entire window, instead of having a huge cell with
> all of the label1 text in it.
> 
> Ideas?

Columns are indexed from 0 to n-1, the rightmost column in the code above is 
3 for the list widget, so you have 4 columns already. Add another column for 
the list widget's columnspan=2 and you end up with 5 columns in total. 
Therefore

self.label1.grid(row=1, column=0, columnspan=5, sticky=W)

should accomplish the desired layout.

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Take a look at this...

2011-11-27 Thread Mario Cavett
Hola.
finally my aunt gave me a push in the right direction this turned my luck 
around now im making my way to the top I promise youll love it
http://gabfair.com/profile/29DavidScott/
see you later
  ___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] how to delete some quasi-duplicated keys

2011-11-27 Thread Andreas Perstinger

On 2011-11-26 03:49, lina wrote:


 for k, v in occurence.items():
 print(v,k)

292 frozenset({66, 69})
222 frozenset({24, 27})


How can I let the result like:

292 {66,69}
222 {24,27}

don't output the frozenset


If you want to use your own output format you have to provide it.

For example, you could use a combination of string formatting and 
".join()" to get what you want:


for k, v in occurence.items():
print("{0} {{{1}}}".format(v, ",".join([str(x) for x in k])))

Bye, Andreas
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] How to raise error without the stack trace

2011-11-27 Thread Karim

Le 26/11/2011 15:20, Rich Lovely a écrit :

On 26 November 2011 11:41, Steven D'Aprano  wrote:

Hugo Arts wrote:

On Sat, Nov 26, 2011 at 11:16 AM, Karim  wrote:

Hello,

I want to fire my own exception without having the (useful but ugly in my
case) stack trace display.

How to modify a Exception type class for that purpose which looks like:

classs MyError(Exception):
  pass

Cheers
Karim


The stack trace is what happens when an exception is uncaught. You
don't need to modify it. What you want to do is catch the exception,
print it, then, depending on whether you can recover from the error,
possibly do a sys.exit(-1).

If you can recover from the error, by all means catch the exception. That's
what exceptions are for!

But otherwise, please think very, very, VERY carefully before printing an
error message and exiting. This is normally the wrong thing to do.

Stack traces are useful. They show you exactly what has gone wrong, and
where (although sadly not why!). There is very little worse than a "helpful"
programmer who turns a sensible, useful stack trace into a useless, stupid
message:

"An error has occurred"

or worse.

Perhaps the most sensible example I can think of is this:


def main():
# your code goes here...


if __name__ == '__main__':
try:
main()
except KeyboardInterupt:
# Not an error, so no need for a stack trace.
print "operation cancelled by user"
sys.exit(1)


and that's it. Any other exception is a bug in your code, and so the stack
trace should be printed so the user can report it.


--
Steven

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Although there's nothing wrong with taking the stack trace and
cleaning it up - perhaps dumping it to a logfile, using the Traceback
module.  Asking your users to send a file (or even automating the
process in your except: block is much more user friendly than
expecting them to be able to copy and paste from a (potentially
hidden, for GUI apps) console.  It also ensures you get the entire
stack trace, rather than just what they think is useful.



Sorry,

I did not explain myself clearly. I Kow when I fired it because it is in 
code like:


If not value:
raise MyError('You did wrong here!')

And in that case I did not want the stack trace because I know perfectly 
where the message is triggered.


To avoid stack trace in try/except I use print(e) then sys.exit(1) or 
return 1.
I just wanted to know if it is possible to control the stack trace 
display when

raising my own exception.

And sure, Steven I hate message like 'Problem happens exitting...'.
My error messages are acute I just wanted to filter the stack trace.

Thanks all for you answers.
Cheers
Karim
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Shorten this code

2011-11-27 Thread Mic

God morning!


That's right, because your SeatButton init doesn't check to see if a
file exists for it, it always colors it green. You need to read the
directory and see whether a file for that seat exists. If it does
color it red. (Hint: look at os.path.exists() )



Alright, I think I now managed to solve this problem. Here is the code:

from tkinter import*
import tkinter as tk
import os

FREE = "green"
OCCUPIED = "red"

class Mainwindow(Frame):
def __init__(self,master):
super(Mainwindow,self).__init__(master)
self.grid()
self.create_mainwidgets()

def create_mainwidgets(self):
self.klicka=Button(self, text="Press the button",
   command=self.uppdatera)
self.klicka.grid()

def uppdatera(self):
SeatWindow(root)

class SeatButton(tk.Button):
def __init__(self, master, index):
text = str(index+1)
super(SeatButton, self).__init__(master,
 text=text, bg=FREE,
 command=self.clicked)
self.filename = "Germany_France{}.txt".format(index+1)
self.occupied = False
if os.path.exists(self.filename):
 self["bg"]=OCCUPIED

def clicked(self):
self.occupied = not self.occupied
if self.occupied:
self["bg"] = OCCUPIED
text_file=open(self.filename,"w")
text_file.write(self.filename)
text_file.close()
else:
self["bg"] = FREE
os.remove(self.filename)

class SeatWindow(tk.Toplevel):
 def __init__(self, master):
 super (SeatWindow, self).__init__(master)
 self.grid()
 self.create_widgets()

 def create_widgets(self):
 for index in range(20):
 button = SeatButton(self, index)
 row, column = divmod(index, 4)
 button.grid(row=row, column=column)

root=Tk()
root.title("testV2")
app=Mainwindow(root)
root.mainloop()






This is one case where I think it will be easier to show you than tell
you so I've pasted my modified version of your code. Note that I've
moved all the clsses to the outer level and made the second window(which
I've renamed SeatWindow) inherit from Toplevel rather than Frame so that
you can create it as a child of the Mainwindow. That then allows a
single mainloop. It will be worth while studying the differences to see
if you understand why I've done what I've done.



Yeah, well, the main difference I can see is that you only uses one tk 
object while I used more. Hmm, otherwise I can see that you have bound the 
button in the main window to the function

def uppdatera(self):
SeatWindow(root)
which opens the SeatWindow right? I probably missed things, but I noticed 
that this is much smoother than my alternative!



Thanks !

Mic



___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Shorten this code

2011-11-27 Thread Peter Otten
Mic wrote:

> class SeatButton(tk.Button):
>  def __init__(self, master, index):
>  text = str(index+1)
>  super(SeatButton, self).__init__(master,
>   text=text, bg=FREE,
>   command=self.clicked)
>  self.filename = "Germany_France{}.txt".format(index+1)
>  self.occupied = False
>  if os.path.exists(self.filename):
>   self["bg"]=OCCUPIED

In the above snippet button color and the occupied-flag can get out of sync. 
If a seat is occupied the color is correcly updated to red bot the 
self.occupied remains False.
A simple fix:

self.occupied = os.path.exists(self.filename)
if self.occupied:
self["bg"] = OCCUPIED 


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Writing Game in python

2011-11-27 Thread surya k

Hi,

Actually, I want to develop a multiplayer Bingo game. So, I would like to 
develop it in python & C. As I am not familiar with game development, could you 
please tell me what libraries I should use for development?... etc  
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Writing Game in python

2011-11-27 Thread Wayne Werner
On Sun, Nov 27, 2011 at 7:52 AM, surya k  wrote:

>  Hi,
>
>
> Actually, I want to develop a multiplayer Bingo game. So, I would like to
> develop it in python & C. As I am not familiar with game development, could
> you please tell me what libraries I should use for development?... etc
>

You could easily develop the game entirely in Python. As for libraries...
well it depends on what you're trying to do.

If you want a GUI you'll want to look at one of the frameworks like
Tkinter, PyGTK+, wxPython, or QtPython. Alternatively you could look at the
PyGame library which is geared towards game development.

If you want to do internet communication, you'll want to investigate the
socket module, and possibly the threading module.

How familiar are you with Python? Have you written any programs before?

What would really help is if you gave us some psuedocode of your algorithm
or the steps you think each piece should need to accomplish. We like to see
that you've at least tried to do something.

HTH,
Wayne
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Writing Game in python

2011-11-27 Thread surya k

Thanks for your reply.
Actually, I am good at writing code in C and still learning python(Familiar 
with basics). Now, I am much inclined towards python than C and trying to use 
it more. I love it.
Coming back to the game I want to develop.. I didn't put any code yet but I 
finished with the algorithm part. All I can tell you is.. Its a small board 
game, Bingo!. Its typical game we seldom use to play in school on a piece of 
paper.


From: waynejwer...@gmail.com
Date: Sun, 27 Nov 2011 08:05:46 -0600
Subject: Re: [Tutor] Writing Game in python
To: sur...@live.com
CC: tutor@python.org

On Sun, Nov 27, 2011 at 7:52 AM, surya k  wrote:







Hi,

Actually, I want to develop a multiplayer Bingo game. So, I would like to 
develop it in python & C. As I am not familiar with game development, could you 
please tell me what libraries I should use for development?... etc


You could easily develop the game entirely in Python. As for libraries... well 
it depends on what you're trying to do.
If you want a GUI you'll want to look at one of the frameworks like Tkinter, 
PyGTK+, wxPython, or QtPython. Alternatively you could look at the PyGame 
library which is geared towards game development.


If you want to do internet communication, you'll want to investigate the socket 
module, and possibly the threading module.
How familiar are you with Python? Have you written any programs before?


What would really help is if you gave us some psuedocode of your algorithm or 
the steps you think each piece should need to accomplish. We like to see that 
you've at least tried to do something.


HTH,Wayne ___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Writing Game in python

2011-11-27 Thread surya k

I think I have got enough tail to catch up and start my project..Thanks to all 
who have spared some time to help me.

From: waynejwer...@gmail.com
Date: Sun, 27 Nov 2011 08:05:46 -0600
Subject: Re: [Tutor] Writing Game in python
To: sur...@live.com
CC: tutor@python.org

On Sun, Nov 27, 2011 at 7:52 AM, surya k  wrote:







Hi,

Actually, I want to develop a multiplayer Bingo game. So, I would like to 
develop it in python & C. As I am not familiar with game development, could you 
please tell me what libraries I should use for development?... etc


You could easily develop the game entirely in Python. As for libraries... well 
it depends on what you're trying to do.
If you want a GUI you'll want to look at one of the frameworks like Tkinter, 
PyGTK+, wxPython, or QtPython. Alternatively you could look at the PyGame 
library which is geared towards game development.


If you want to do internet communication, you'll want to investigate the socket 
module, and possibly the threading module.
How familiar are you with Python? Have you written any programs before?


What would really help is if you gave us some psuedocode of your algorithm or 
the steps you think each piece should need to accomplish. We like to see that 
you've at least tried to do something.


HTH,Wayne ___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Random order program

2011-11-27 Thread myles broomes
Im trying to make a program where the user enters 5 words and then the list of 
words a is returned in a random order. Heres the code I have come up with so 
far:

#random word order program
#the user gives the program a list of words
#the program then returns them in a random order

import random

#explain the purpose of the program to the user
print("At the prompt, type in a list of words and they will be returned in a 
random order.")

#get the users input for the list of words, one by one
first_word = input("Please enter your first word: ")
second_word = input("Please enter your second word: ")
third_word = input("Please enter your third word: ")
fourth_word = input("Please enter your fourth word: ")
fifth_word = input("Please enter your fifth word: ")

#create a tuple containing the users words of the words
word_list = (first_word,second_word,third_word,fourth_word,fifth_word)

#create an empty list that the words will go into to be returned in a random 
order
random_word_list = []

print("Now your list will be displayed in a random order.")

#random order list
while random_word_list != len(word_list):
word = random.choice(word_list)
if word not in random_word_list:
random_word_list += word

#display the random word list
print(random_word_list)

input("Press enter to exit...")

When I run the program, this is what is displayed:

At the prompt, type in a list of words and they will be returned in a random 
order.
Please enter your first word: one
Please enter your second word: two
Please enter your third word: three
Please enter your fourth word: four
Please enter your fifth word: five
Now your list will be displayed in a random order.


...And then nothing happens after that - no error, no nothing. Any help would 
be much appreciated.
Thanks in advance.

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Writing Game in python

2011-11-27 Thread Alan Gauld

On 27/11/11 13:52, surya k wrote:


Actually, I want to develop a multiplayer Bingo game.


When you say multiplayer do you mean many client
desktops or a web game? The solutions will be
very different.


 to develop it in python & C.


Since Bingo is not a high speed game Python should
be perfectly capable of doing all you need.


could you please tell me what libraries I should

> use for development?... etc

If its desktop based look at pyGame for the
game bits(obviously!) and Twisted for the
networking bits. Twisted is quite a complex
framework but very powerful and once you get
your head around it perfect for your needs.

If it's a web game then Django or some of the
other Python web frameworks will do all you need.
Take a look at the various web pages and FAQs on
the Python web site before choosing a framework.
Consider whether you need database support,
security features, etc etc. Some are better in
those areas than others.

--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] How to raise error without the stack trace

2011-11-27 Thread Alan Gauld

On 27/11/11 12:11, Karim wrote:


I just wanted to know if it is possible to control the stack trace
display when raising my own exception.


No, and you should not try.

You can control the stacktrace display where you catch it, but not where 
you raise it. And that's the point, you are raising it because you don't 
want to handle it there. You are expecting the user to deal with the 
error, including how it is displayed.


Peter has already showed you how to do that by overridding the standard 
exception hook sys.excepthook..



--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] How to use try and except in this case?

2011-11-27 Thread Mic


Mic wrote:


class SeatButton(tk.Button):
 def __init__(self, master, index):
 text = str(index+1)
 super(SeatButton, self).__init__(master,
  text=text, bg=FREE,
  command=self.clicked)
 self.filename = "Germany_France{}.txt".format(index+1)
 self.occupied = False
 if os.path.exists(self.filename):
  self["bg"]=OCCUPIED


In the above snippet button color and the occupied-flag can get out of 
sync.

If a seat is occupied the color is correcly updated to red bot the
self.occupied remains False.
A simple fix:



self.occupied = os.path.exists(self.filename)
if self.occupied:

   >self["bg"] = OCCUPIED


Thanks!

Say that I want to try and open 10 files. If none of these exists, I want an 
error

message to appear. But only if NONE of these files exists.

I know how to handle this with one file. But I don't know how to do that 
with more than one.
So the program should try and open all 10 files and if, and only if, none 
of the files exists I want en error message to appear.



Thanks for your help guys!




___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Random order program

2011-11-27 Thread bob gailer

On 11/27/2011 11:28 AM, myles broomes wrote:

Im trying to make a program where the user enters 5 words and then the list of 
words a is returned in a random order. Heres the code I have come up with so 
far:

#random word order program
#the user gives the program a list of words
#the program then returns them in a random order

import random

#explain the purpose of the program to the user
print("At the prompt, type in a list of words and they will be returned in a random 
order.")

#get the users input for the list of words, one by one
first_word = input("Please enter your first word: ")
second_word = input("Please enter your second word: ")
third_word = input("Please enter your third word: ")
fourth_word = input("Please enter your fourth word: ")
fifth_word = input("Please enter your fifth word: ")

#create a tuple containing the users words of the words
word_list = (first_word,second_word,third_word,fourth_word,fifth_word)

#create an empty list that the words will go into to be returned in a random 
order
random_word_list = []

print("Now your list will be displayed in a random order.")

#random order list
while random_word_list != len(word_list):
 word = random.choice(word_list)
 if word not in random_word_list:
 random_word_list += word

#display the random word list
print(random_word_list)

input("Press enter to exit...")

When I run the program, this is what is displayed:

At the prompt, type in a list of words and they will be returned in a random 
order.
Please enter your first word: one
Please enter your second word: two
Please enter your third word: three
Please enter your fourth word: four
Please enter your fifth word: five
Now your list will be displayed in a random order.


...And then nothing happens after that - no error, no nothing.


 random_word_list != len(word_list) will always be true. Therefore the loop 
will never end.

What should that expression be? See if you can figure out why it is always true 
and what to change to get the desired result.

In theory the loop could run for a long time, as you could get an arbitrarily 
long run of words that are already in the random_word_list. How could you fix 
that?

There are any number of ways to simplify and improve the program. Are you 
interested in hearing about them?

For one study the functions in the random module.


--
Bob Gailer
919-636-4239
Chapel Hill NC

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] How to handle conjunction operators

2011-11-27 Thread surya k

Hi,
Could you please tell me why this isn't working and how can I make it 
possible...
Consider this code..name = raw_input("Enter your first name: ")
if name[0] == ("m" or "f" or "b") :
   rhyme = name[1:]What I want here is.. If the name starts with 'm' or 'f' or 
'b', The first letter should be removed.But this isn't happening here.  
   ___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] How to handle conjunction operators

2011-11-27 Thread Hugo Arts
On Sun, Nov 27, 2011 at 7:52 PM, surya k  wrote:
> Hi,
> Could you please tell me why this isn't working and how can I make it
> possible...
> Consider this code..
>
> name = raw_input("Enter your first name: ")
> if name[0] == ("m" or "f" or "b") :
>rhyme = name[1:]
>
> What I want here is.. If the name starts with 'm' or 'f' or 'b', The first
> letter should be removed.
> But this isn't happening here.

This is a very common error. Fact is, the or operator just isn't
distributive with respect to the == operator like that, and for good
reason. What you want is either this:

if name[0] == "m" or name[0] == "f" or name[0] == "b":

or, more idiomatically, you can use the in operator like this:

if name[0] in ("m", "f", "b"):

HTH,
Hugo
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] How to use try and except in this case?

2011-11-27 Thread Andreas Perstinger

On 2011-11-27 17:58, Mic wrote:

Say that I want to try and open 10 files. If none of these exists, I want an
error
message to appear. But only if NONE of these files exists.

I know how to handle this with one file. But I don't know how to do that
with more than one.
So the program should try and open all 10 files and if, and only if, none
of the files exists I want en error message to appear.


Use a counter which increments with every existing file. After opening 
all files check if the counter is bigger than 0.


Or, if you need to know which files exist, use a list, append existing 
files to it and check at the end if it's not empty.


Do you need more help?

Bye, Andreas


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Parsing

2011-11-27 Thread Deanna Wilson
 Project 4: Parsing rhinoceros sightings

In this project, I’m  working for a wildlife conservation group that is
tracking rhinos in the African savannah. My  field workers' software
resources and GIS expertise are limited, but you have managed to obtain an
Excel 
spreadsheetshowing
the positions of several rhinos over time. Each record in the
spreadsheet shows the latitude/longitude coordinate of a rhino along with
the rhino's name (these rhinos are well known to your field workers).

I want to write a script that will turn the readings in the spreadsheet
into a vector dataset that I can place on a map. This will be a polyline
dataset showing the tracks the rhinos followed over the time the data was
collected.

I will deliver:

A Python script that reads the data from the spreadsheet and creates, from
scratch, a polyline shapefile with *n* polylines, *n* being the number of
rhinos in the spreadsheet. Each polyline should represent a rhino's track
chronologically from the beginning of the spreadsheet to the end of the
spreadsheet. Each polyline should also have a text attribute containing the
rhino's name. The shapefile should use the WGS 1984 geographic coordinate
system.

*Challenges*

The data is in a format (XLSX) that you cannot easily parse. The first step
I must do is manually open the file in Excel and save it as a
comma-delimited format that I can easily read with a script. Choose the
option *CSV (comma-delimited) (*.csv)*. I did this

   - The rhinos in the spreadsheet appear in no guaranteed order, and not
   all the rhinos appear at the beginning of the spreadsheet. As I parse each
   line, I must determine which rhino the reading belongs to and update that
   rhino's polyline track accordingly. *I am not allowed to sort the Rhino
   column in Excel before I export to the CSV file. My script must be "smart"
   enough to work with an unsorted spreadsheet in the order that the records
   appear.*
   - I do not immediately know how many rhinos are in the file or even what
   their names are. Although I could visually comb the spreadsheet for this
   information and hard-code each rhino's name, your script is required to
   handle all the rhino names programmatically. The idea is that I should be
   able to run this script on a different file, possibly containing more
   rhinos, without having to make many manual adjustments.

sample of my code:

import arcpy



shapefile = "C:\\...shp"

pointFilePath = "C:\\...csv"



pointFile = open(pointFilePath, "r")

lineOfText = pointFile.readline()



dataPairList = lineOfText.split(",")



def addVertex(lat, lon, array):

vertex = arcpy.CreateObject("Point")

vertex.X = lon

vertex.Y = lat

array.add(vertex)



def addPolyline(cursor, array):

   feature = cursor.newRow()

   feature.shape = array

   cursor.insertRow(feature)

   array.removeAll()





def rhinoName(Rhino, dictionary):

if rhinoName in rhinoDictionary:

dictionary[rhinoName].append([latValue, lonValueIndex])



if rhinoName not in dictionary:

dictionary[rhinoName] = []



else:

dictionary[rhinoName]= ([latValue, lonValue])







latValueIndex = dataPairList.index("X")

lonValueIndex = dataPairList.index("Y")

vertexArray = arcpy.CreateObject("Array")







for line in pointFile.readlines():

segmentedLine = line.split(",")

latValue = segmentedLine[latValueIndex]

lonValue = segmentedLine[lonValueIndex]

vertex = arcpy.CreateObject("Point")

vertex.X = lonValue

vertex.Y = latValue

vertexArray.add(vertex)





polylineArray.add(currentPoint)





cursor = arcpy.InsertCursor(shapefile)

row = cursor.newRow()

row.Shape = vertexArray

cursor.insertRow(row)



del cursor
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] How to handle conjunction operators

2011-11-27 Thread bob gailer

On 11/27/2011 1:52 PM, surya k wrote:

Hi,

Could you please tell me why this isn't working and how can I make it 
possible...


Consider this code..

name = raw_input("Enter your first name: ")
if name[0] == ("m" or "f" or "b") :
   rhyme = name[1:]

What I want here is.. If the name starts with 'm' or 'f' or 'b', The 
first letter should be removed.

But this isn't happening here.

Hugh answered your question.

PLEASE in future post in plain text rather than HTML.

--
Bob Gailer
919-636-4239
Chapel Hill NC

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] How to handle conjunction operators

2011-11-27 Thread bob gailer

On 11/27/2011 1:52 PM, surya k wrote:

Hi,

Could you please tell me why this isn't working and how can I make it 
possible...


Consider this code..

name = raw_input("Enter your first name: ")
if name[0] == ("m" or "f" or "b") :
   rhyme = name[1:]

What I want here is.. If the name starts with 'm' or 'f' or 'b', The 
first letter should be removed.

But this isn't happening here.

Hugh answered your question.

I add - let's analyze name[0] == ("m" or "f" or "b")

"m" or "f" or "b" gets evaluated first. The result is "m" (the first 
non-false value)


then name[0] == "m" gets evaluated, which may be true or false.


the shortest way is name[0] in "mfb"

--
Bob Gailer
919-636-4239
Chapel Hill NC

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Parsing

2011-11-27 Thread bob gailer

Welcome to the Tutor List.

We are a few volunteers who enjoy tutoring folk on specific Python 
learning issues.


We like posts that are in plain text rather than HTML. Please post plain 
text in future. Also your code has a blank line between every LOC, 
Please remove these in future posts


I failed to see any specific request in your post so all I can say is 
welcome and how can we help you. Did you run the code? Did you get 
errors or unexpected results? Please report these.


Errors usually appear as a traceback. Include the entire traceback 
(after putting in some effort to figure out the error on your own).


unexpected results? Tell us what you expected and how the results differ.

Good luck!

On 11/27/2011 3:45 PM, Deanna Wilson wrote:

Project 4: Parsing rhinoceros sightings

In this project, I'm  working for a wildlife conservation group that 
is tracking rhinos in the African savannah. My  field workers' 
software resources and GIS expertise are limited, but you have managed 
to obtain an Excel spreadsheet 
 
showing the positions of several rhinos over time. Each record in the 
spreadsheet shows the latitude/longitude coordinate of a rhino along 
with the rhino's name (these rhinos are well known to your field workers).


I want to write a script that will turn the readings in the 
spreadsheet into a vector dataset that I can place on a map. This will 
be a polyline dataset showing the tracks the rhinos followed over the 
time the data was collected.


I will deliver:

A Python script that reads the data from the spreadsheet and creates, 
from scratch, a polyline shapefile with n polylines, n being the 
number of rhinos in the spreadsheet. Each polyline should represent a 
rhino's track chronologically from the beginning of the spreadsheet to 
the end of the spreadsheet. Each polyline should also have a text 
attribute containing the rhino's name. The shapefile should use the 
WGS 1984 geographic coordinate system.


Challenges

The data is in a format (XLSX) that you cannot easily parse. The first 
step I must do is manually open the file in Excel and save it as a 
comma-delimited format that I can easily read with a script. Choose 
the option CSV (comma-delimited) (*.csv). I did this


  * The rhinos in the spreadsheet appear in no guaranteed order, and
not all the rhinos appear at the beginning of the spreadsheet. As
I parse each line, I must determine which rhino the reading
belongs to and update that rhino's polyline track accordingly. I
am not allowed to sort the Rhino column in Excel before I export
to the CSV file. My script must be "smart" enough to work with an
unsorted spreadsheet in the order that the records appear.
  * I do not immediately know how many rhinos are in the file or even
what their names are. Although I could visually comb the
spreadsheet for this information and hard-code each rhino's name,
your script is required to handle all the rhino names
programmatically. The idea is that I should be able to run this
script on a different file, possibly containing more rhinos,
without having to make many manual adjustments.

sample of my code:

import arcpy

shapefile = "C:\\...shp"

pointFilePath = "C:\\...csv"

pointFile = open(pointFilePath, "r")

lineOfText = pointFile.readline()

dataPairList = lineOfText.split(",")

def addVertex(lat, lon, array):

vertex = arcpy.CreateObject("Point")

vertex.X = lon

vertex.Y = lat

array.add(vertex)

def addPolyline(cursor, array):

   feature = cursor.newRow()

   feature.shape = array

   cursor.insertRow(feature)

   array.removeAll()

def rhinoName(Rhino, dictionary):

if rhinoName in rhinoDictionary:

dictionary[rhinoName].append([latValue, lonValueIndex])

if rhinoName not in dictionary:

dictionary[rhinoName] = []

else:

dictionary[rhinoName]= ([latValue, lonValue])

latValueIndex = dataPairList.index("X")

lonValueIndex = dataPairList.index("Y")

vertexArray = arcpy.CreateObject("Array")

for line in pointFile.readlines():

segmentedLine = line.split(",")

latValue = segmentedLine[latValueIndex]

lonValue = segmentedLine[lonValueIndex]

vertex = arcpy.CreateObject("Point")

vertex.X = lonValue

vertex.Y = latValue

vertexArray.add(vertex)

polylineArray.add(currentPoint)

cursor = arcpy.InsertCursor(shapefile)

row = cursor.newRow()

row.Shape = vertexArray

cursor.insertRow(row)

del cursor





___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor



--
Bob Gailer
919-636-4239
Chapel Hill NC

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Parsing

2011-11-27 Thread Andreas Perstinger

On 2011-11-27 21:45, Deanna Wilson wrote:

  Project 4: Parsing rhinoceros sightings


Please confirm that this is homework. At least I've found this site:
https://www.e-education.psu.edu/geog485/node/144

[snip]

sample of my code:


What are your problems?
I've skimmed your sample and found a number of errors. Since your task 
looks like homework, you should be more specific about your problems.


Bye, Andreas
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Random order program

2011-11-27 Thread myles broomes
I requested help for this code earlier and I thought it had been corrected but 
apparently, there is still a problem with it...

#random word order program
#the user gives the program a list of words
#the program then returns them in a random order

import random

#explain the purpose of the program to the user
print("At the prompt, type in a list of words and they will be returned in a 
random order.")

#get the users input for the list of words, one by one
first_word = input("Please enter your first word: ")
second_word = input("Please enter your second word: ")
third_word = input("Please enter your third word: ")
fourth_word = input("Please enter your fourth word: ")
fifth_word = input("Please enter your fifth word: ")

#create a tuple containing the users words of the words
word_list = (first_word,second_word,third_word,fourth_word,fifth_word)

#create an empty list that the words will go into to be returned in a random 
order
random_word_list = []

print("Now your list will be displayed in a random order.")

#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

#display the random word list
print(random_word_list)

input("Press enter to exit...")

And once again, the following is displayed

At the prompt, type in a list of words and they will be returned in a random 
order.
Please enter your first word: one
Please enter your second word: two
Please enter your third word: three
Please enter your fourth word: four
Please enter your fifth word: five
Now your list will be displayed in a random order.

Then the program just stops for some reason. Again, any help is much 
appreciated.

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Blacklist?

2011-11-27 Thread Alexander Etter
I'm top posting because the link below is spam. Does the email address who sent 
the message get blacklisted or punished?

Alexander

On Nov 27, 2011, at 4:45, Mario Cavett  wrote:

> Hola.
> finally my aunt gave me a push in the right direction this turned my luck 
> around now im making my way to the top I promise youll love it
> http://gabfair.com/profile/29DavidScott/
> see you later
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Blacklist?

2011-11-27 Thread Steven D'Aprano

Alexander Etter wrote:

I'm top posting because the link below is spam.



Why on earth do you think that it is acceptable to repeat spam on the list 
just because you top post?


If you have to reply to spam, does your backspace key not work? ESPECIALLY the 
spammer's URL.




--
Steven

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Blacklist?

2011-11-27 Thread Alexander Etter
On Nov 27, 2011, at 17:55, Steven D'Aprano  wrote:

> Alexander Etter wrote:
>> I'm top posting because the link below is spam.
> 
> 
> Why on earth do you think that it is acceptable to repeat spam on the list 
> just because you top post?
> 
> If you have to reply to spam, does your backspace key not work? ESPECIALLY 
> the spammer's URL.
> 
> -- 
> Steven
> 

Sorry Steven! I've learned my lesson.
Alexander.
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Random order program

2011-11-27 Thread Andreas Perstinger

On 2011-11-27 23:17, myles broomes wrote:

#get the users input for the list of words, one by one
first_word = input("Please enter your first word: ")
second_word = input("Please enter your second word: ")
third_word = input("Please enter your third word: ")
fourth_word = input("Please enter your fourth word: ")
fifth_word = input("Please enter your fifth word: ")

#create a tuple containing the users words of the words
word_list = (first_word,second_word,third_word,fourth_word,fifth_word)


You could shorten the input procedure by using a for-loop and appending 
every word to a list instead using five different "word"-variables and 
building a tuple with them.



#create an empty list that the words will go into to be returned in a random 
order
random_word_list = []

print("Now your list will be displayed in a random order.")

#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


Bob told you already that you are creating an infinite-loop. Try this:

Python 3.2 (r32:88445, Mar 25 2011, 19:28:28)
[GCC 4.5.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> l = []
>>> s = "test"
>>> l += s
>>> l
['t', 'e', 's', 't']

Do you see your problem? You want to "add" a string to a list but with 
the inplace operator "+=" "word" is interpreted as a sequence (a list of 
letters). You can't "add" a string to a list:


>>> l = l + s
Traceback (most recent call last):
  File "", line 1, in 
TypeError: can only concatenate list (not "str") to list

If you want to add an element to a list you should use the 
".append"-method of lists:

http://docs.python.org/py3k/tutorial/datastructures.html#more-on-lists

Bob mentioned also the problem with your algorithm. Everytime you get a 
word from "random.choice" which is already in "random_word_list" you 
have to loop again:


>>> counter = 0
>>> random_word_list = []
>>> word_list = ["a", "b", "c", "d", "e"]
>>> while len(random_word_list) != len(word_list):
...   counter += 1
...   word = random.choice(word_list)
...   if word not in random_word_list:
... random_word_list.append(word)
...
>>> print(counter)

If you are lucky, "counter" is close to the minimum 5. But in one of my 
test runs it was 25.
This is unnecessary because you don't need more iterations than the 
length of "word_list" (5 in your case)


Anyways, there is already a shuffle-method in the "random"-module:
docs.python.org/py3k/library/random.html

Bye, Andreas
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Random order program

2011-11-27 Thread Dave Angel

On 11/27/2011 05:17 PM, myles broomes wrote:

I requested help for this code earlier and I thought it had been corrected but 
apparently, there is still a problem with it...

To start with, tell us what version of Python, and what operating system 
platform you're using.  I'm assuming Python 3.x and Linux.   In this 
case the first matters, the second probably does not.



#random word order program
#the user gives the program a list of words
#the program then returns them in a random order

import random

#explain the purpose of the program to the user
print("At the prompt, type in a list of words and they will be returned in a random 
order.")

#get the users input for the list of words, one by one
first_word = input("Please enter your first word: ")
second_word = input("Please enter your second word: ")
third_word = input("Please enter your third word: ")
fourth_word = input("Please enter your fourth word: ")
fifth_word = input("Please enter your fifth word: ")

#create a tuple containing the users words of the words
word_list = (first_word,second_word,third_word,fourth_word,fifth_word)

#create an empty list that the words will go into to be returned in a random 
order
random_word_list = []

print("Now your list will be displayed in a random order.")

#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)

As it's currently coded, it take each character of the word and adds 
them to the list, so the list doesn't match the original at all.


Next problem you might encounter is if the user doesn't give unique 
words.  If they repeat one of them, the loop will never terminate.  You 
figure  out why.



#display the random word list
print(random_word_list)

input("Press enter to exit...")

And once again, the following is displayed

At the prompt, type in a list of words and they will be returned in a random 
order.
Please enter your first word: one
Please enter your second word: two
Please enter your third word: three
Please enter your fourth word: four
Please enter your fifth word: five
Now your list will be displayed in a random order.

Then the program just stops for some reason. Again, any help is much 
appreciated.



As others have pointed out, there is at least one function in random 
that's a better match to  your problem.  You could collapse the loop to 
one line, and duplicates wouldn't be an issue.


Another approach would be to make a set out of the original input.  
Duplicates will be thrown out (you might want to tell the user, 
though).  Then you take the set as an argument to the function I just 
hinted at, and out comes your answer.



--

DaveA

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Parsing

2011-11-27 Thread Andreas Perstinger
[Please reply to the list. Your indentation also got lost during the 
mail delivery.]


On 2011-11-27 23:21, Deanna Wilson wrote:

Yes it is homework, but not from Penn state. It is a Geog690 class. I'm
having difficulties with determining where the rhino is referenced in the
split line, determining if the dictionary has a key for the rhino and if no
key exists, creating a new array object. So pretty much writing the
dictionary. I think I got the rest of the script just not understanding the
dictionary portion. I would appreciate any help/advice.

Here is part of my script where I tried to create a dictionary

rhinoLocalDictionary = {}

def rhinoName(Rhino, Lat, Lon, dictionary):
if rhinoName in dictionary:
dictionary[rhinoName].append([Lat, Lon])
else:
dictionary[rhinoName]= ([Lat, Lon])


You define the function "rhinoName" with the parameter "Rhino" but 
inside the function you use "rhinoName" which is the function's name.


You want to build a list of lists for each dictionary-value. But then 
you need to start the list with a nested-list in the else-branch. 
Otherwise your list will start with two elements followed by 
two-elements lists:


>>> d = {}
>>> d[1] = [1, 2]
>>> d[1].append([3, 4])
>>> d[1]
[1, 2, [3, 4]] # That's not what you want
>>> d[2] = [[1, 2]]
>>> d[2].append([3, 4])
>>> d[2]
[[1, 2], [3, 4]]   # Better

But assuming that your lat/lon-values don't change I would suggest using 
tuples.


HTH, Andreas
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] How to handle conjunction operators

2011-11-27 Thread Alan Gauld

On 27/11/11 19:02, Hugo Arts wrote:


if name[0] == "m" or name[0] == "f" or name[0] == "b":

or, more idiomatically, you can use the in operator like this:

if name[0] in ("m", "f", "b"):


And you might want to force it to lower case too:

if name[0].lower() in ("m", "f", "b"):

OTOH you might want it to be case sensitive...


--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Coin game

2011-11-27 Thread Guess?!?
Hello All,

I am learning python and hence was writing code for school assignments I
could find online. I wrote my solution for this problem below. Please find
it attached.

I would like someone to review and give me comments on it. Basically
improvements/ comments to make it more efficient

problem.py has print statements in them. problem_clean is cleaner version
of the same.

Thanks,

G


Two players take turns flipping a fair coin. The game ends when the same
outcome occurs on three flips in a row. Whichever player flipped the coin
last, wins. For example:

Player 1 flips H
Player 2 flips T
Player 1 flips T
Player 2 flips H
Player 1 flips H
Player 2 flips H <<< player 2 wins

or

Player 1 flips T
Player 2 flips T
Player 1 flips T <<< player 1 wins

or

Player 1 flips H
Player 2 flips H
Player 1 flips T
Player 2 flips H
Player 1 flips T
Player 2 flips H
Player 1 flips T
Player 2 flips T
Player 1 flips H
Player 2 flips H
Player 1 flips H <<< player 1 wins


problem_clean.py
Description: Binary data


problem.py
Description: Binary data
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Parsing

2011-11-27 Thread Alan Gauld

On 27/11/11 20:45, Deanna Wilson wrote:


  Project 4: Parsing rhinoceros sightings


OK, You've told us this is homework, and you appear to have made some 
start but we need some more information.


Can you program in any other language other than Python?
Which version of Python are you using? Obviously 2.X but which X?
Which OS are you running?
What is arcpy? It is not one of the standard Python libraries.

What is the arrray that you are trying to use? Its not a builtin type in 
Python and you don;t seem to import it from anywhere?


You are obviously allowed to use arcopy, so do we assume you could also 
use  the csv module to process the csv file?


Your rhinoName function is badly broken...
And addVertex is not used vbut duplicated in the code.
Inserting a few print statements at strategic places should help you see 
what is happening in your code.


Now where would you like us to start?



sample of my code:

import arcpy

shapefile = "C:\\...shp"
pointFilePath = "C:\\...csv"
pointFile = open(pointFilePath, "r")
lineOfText = pointFile.readline()
dataPairList = lineOfText.split(",")

def addVertex(lat, lon, array):
 vertex = arcpy.CreateObject("Point")
 vertex.X = lon
 vertex.Y = lat
 array.add(vertex)

def addPolyline(cursor, array):
feature = cursor.newRow()
feature.shape = array
cursor.insertRow(feature)
array.removeAll()

def rhinoName(Rhino, dictionary):
 if rhinoName in rhinoDictionary:
 dictionary[rhinoName].append([latValue, lonValueIndex])
 if rhinoName not in dictionary:
 dictionary[rhinoName] = []
 else:
 dictionary[rhinoName]= ([latValue, lonValue])

latValueIndex = dataPairList.index("X")
lonValueIndex = dataPairList.index("Y")
vertexArray = arcpy.CreateObject("Array")
for line in pointFile.readlines():
 segmentedLine = line.split(",")
 latValue = segmentedLine[latValueIndex]
 lonValue = segmentedLine[lonValueIndex]
 vertex = arcpy.CreateObject("Point")
 vertex.X = lonValue
 vertex.Y = latValue
 vertexArray.add(vertex)
 polylineArray.add(currentPoint)

cursor = arcpy.InsertCursor(shapefile)
row = cursor.newRow()
row.Shape = vertexArray
cursor.insertRow(row)
del cursor


--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Coin game

2011-11-27 Thread Dave Angel

On 11/27/2011 07:43 PM, Guess?!? wrote:

Hello All,

I am learning python and hence was writing code for school assignments I
could find online. I wrote my solution for this problem below. Please find
it attached.

I would like someone to review and give me comments on it. Basically
improvements/ comments to make it more efficient

problem.py has print statements in them. problem_clean is cleaner version
of the same.

Thanks,

G

This program is far too complex for the problem.  It doesn't document 
what the various variables are really supposed to mean, but there are 
far more of 'em than there really needs to be.


Your for-loop doesn't need two separate conditions.  You don't care how 
many iterations it takes, but if you really want to limit to 10, then do 
a loop:


for counter in range(10):

then when you want to exit the loop early, use the 'break' statement.  
And the modulo test can be a simple assignment.  If you make player an 
integer (0 or 1), you can just do:

   player = counter %2

The next roll can be something like
   random.choice("H", "T")




You also don't care about the history, only the last three values.  So 
seed the list with illegal values, like

  tracklist = ["*", "*", "*"]

then you just add the new roll as:
  tracklist.pop(0)
  tracklist.append(random.choice("H","T")

Now the if statement only has two choice.  Either all 3 are identical, 
or they're not.  If they are, print your "win" message and break.


After the loop you could use an else clause to detect the case that the 
loop finished without a win.


Any time you have to print out the player name, you could use something like
["player 1", "player 2"] [player]

But of course if you have a list of real names, you'd use that instead 
of the two literals I gave.


If you make it a set of functions, it gets quite small and easier to read.


--

DaveA

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Text Proccessing/Command Line Redirection/XML Parsing etc in Python.

2011-11-27 Thread Pritesh Ugrankar
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-5N/A (DT) RW  187843
0D63 Not Visible???:? 08C:C11 RAID-5N/A (DT) RW  187843
0D64 Not Visible???:? 07C:C12 RAID-5N/A (DT) RW  62614
0D65 Not Visible???:? 08C:D14 RAID-5N/A (DT) RW  62614
0D66 Not Visible???:? 07C:D15 RAID-5N/A (DT) RW  31307
0D67 Not Visible???:? 08C:C13 RAID-5N/A (DT) RW  31307
0D68 Not Visible???:? 07C:C14 RAID-5N/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
scratchMay 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-5N/A (DT) RW  187843

 The following was the next element.
0D63 Not Visible???:? 08C:C11 RAID-5N/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 createdBut is there a way to create a Hash on the fly?
Because I dont know how many devices will be a part of that hashit will
differ on each storage boxIs 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 firstthough
personally, I find Python syntax easier to understand...(Again, my
badmy 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 Visible0 0 004
- AVAILABLE 0 0 005 *
0075 Not Visible0 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.