[Tutor] python 2.4 reading files - unexpected behaviour

2007-11-23 Thread John Gerdeman
Hello, 

I got a csv file, in which I have to count the occurrences of certain
numbers in columns. I can do this for one arbitrary column, but not for
all.

The problem I encountered is as follows. Iterating through the rows of a
file works, but as soon as I try to iterate through the same file again,
it seems it returns nothing.

Code-example

import csv
file = csv.reader(open("some.csv", "rb"))
for i in file:
print i

for i in file:
print i

some.csv:
3, 4, 5
4, 3, 2

The above program only returns:
['3', ' 4', ' 5']
['4', ' 3', ' 2']

instead of:
['3', ' 4', ' 5']
['4', ' 3', ' 2']
['3', ' 4', ' 5']
['4', ' 3', ' 2']

Any help would be welcome.

John


signature.asc
Description: Dies ist ein digital signierter Nachrichtenteil
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] update a ws.ListBox

2007-11-28 Thread John Gerdeman
Hello,

I'm trying to create a gui using wxpython on ubuntu 6.10 (read, that
some functions of wx differ on different OS). 

I have two Listbox items, Listbox1 and Listbox2. I want to update
Listbox2 according to the choice made in Listbox1.
I already looked at the wx API doc, but only found methods to insert
items or (de)select.

I know I can update a textctrl, but I need a way to make a choice based
on the first.

Here a Minimal example:

#!/usr/bin/python

import wx

class MyFrame(wx.Frame):
def __init__(self, parent, id, title):
wx.Frame.__init__(self, parent, id, title, wx.DefaultPosition,
(550, 350))

self.listbox1_items = [ 'item1', 'item2']
self.listbox2_items = ['select a item from the right']

hbox1 = wx.BoxSizer(wx.HORIZONTAL)
vbox = wx.BoxSizer(wx.VERTICAL)

panel = wx.Panel(self, -1)

self.listbox1 = wx.ListBox(panel, 1, wx.DefaultPosition, (170,
130), self.listbox1_items, wx.LB_SINGLE)
self.listbox1.SetSelection(0)
self.listbox2 = wx.ListBox(panel, 2, wx.DefaultPosition, (170,
130), self.listbox2_items, wx.LB_SINGLE)
self.listbox2.SetSelection(0)
hbox1.Add(self.listbox1, 0, wx.TOP, 40)
hbox1.Add(self.listbox2, 0, wx.TOP, 40)
vbox.Add(hbox1, 0, wx.ALIGN_CENTRE)
panel.SetSizer(vbox)

self.Bind(wx.EVT_LISTBOX, self.OnListBox1, id=1)
self.Bind(wx.EVT_LISTBOX, self.OnListBox2, id=2)

def OnListBox1(self, event):
index = event.GetSelection()
choice = self.listbox1_items[index]
print "You chose " + str(choice)
if choice == 'item1':
ret = ['choice1', 'choice2']
elif choice == 'item2':
ret = ['choice3', 'choice4']
else:
ret = ['Ooops']
print "Now I somehow need a way to pass to self.listbox2 I can 
set
self.listbox2_items to ret, but self.listbox2 doesn't get updated"
print ret
def OnListBox2(self, event):
return True


class MyApp(wx.App):
def OnInit(self):
frame = MyFrame(None, -1, 'minexample.py')
frame.Centre()
frame.Show(True)
return True

app = MyApp(0)
app.MainLoop()



signature.asc
Description: Dies ist ein digital signierter Nachrichtenteil
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor