[Tutor] Multipane windows using curses

2010-04-27 Thread mhw
Dear All,

I am looking for some advice about a design decision. I want to write a 
curses-based editor (for OWL ontologies). This should then be usable via ssh, 
etc. Ontology files may be large, and quite complex. Current editors (e.g. 
Protege) have multiple tabs to cope with this.

The simplest option would seem to be to have a single appliction, running 
through a single terminal. However, the data is often complex, and so it would 
be nice to have multiple terminals showing different bits of the ontologies at 
the same time. However, doing this with multiple instances of the app would be 
difficult, as each window would have to load the whole ontolog, etc.

My next thought was then to run a simple server that loads the data file and 
returns bits of it. Then one could open multiple ssh terminals, and each could 
run a client to allow one to view the data. However, this is obviously more 
complex.

Am I missing something simpler?

Thanks,

Matt
Sent from my BlackBerry® wireless device
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] For loop breaking string methods

2010-04-27 Thread Lie Ryan
On 04/27/10 12:19, Dave Angel wrote:
 Note also that if you insert or delete from the list while you're
 looping, you can get undefined results.  That's one reason it's common
 to build a new loop, and just assign it back when done.  Example would
 be the list comprehension you showed earlier.


I have to add to Dave's statement, if you modify the list's content
while looping there is no undefined behavior; you get undefined behavior
if you modify the list's structure.

Operations that modify a list's structure includes insertion, delete,
append, etc; those operations which can modify the len() of list.

Modifying the content, however, is perfectly safe.

However, even when just modifying list's content, I personally still
prefer list/generator comprehension. They're fast and simple.

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


Re: [Tutor] For loop breaking string methods

2010-04-27 Thread bob gailer

On 4/26/2010 10:19 PM, Dave Angel wrote:


Note also that if you insert or delete from the list while you're 
looping, you can get undefined results.




The results are not undefined. They m,ight be unexpected, but that is 
due to an invalid assumption.


The behavior is explained in section 7.3 of The Python Language 
Reference. Note especially:




There is a subtlety when the sequence is being modified by the loop 
(this can only occur for mutable sequences, i.e. lists). An internal 
counter is used to keep track of which item is used next, and this is 
incremented on each iteration. When this counter has reached the length 
of the sequence the loop terminates. This means that if the suite 
deletes the current (or a previous) item from the sequence, the next 
item will be skipped (since it gets the index of the current item which 
has already been treated). Likewise, if the suite inserts an item in the 
sequence before the current item, the current item will be treated again 
the next time through the loop. This can lead to nasty bugs that can be 
avoided by making a temporary copy using a slice of the whole sequence, 
e.g.,


for  x  in  a[:]:
if  x0:  a.remove(x)



--
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] Modify inherited methods

2010-04-27 Thread C M Caine
I'm writing a class that inherits the inbuilt dict class and want some
of my own code to run at initialisation, on the other hand, I still
want the original dict.__init__ function to run. Can I ask the class
to run the original __init__ and then my own function at
initialisation automatically? If so, how?

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


Re: [Tutor] Modify inherited methods

2010-04-27 Thread Steven D'Aprano
On Wed, 28 Apr 2010 07:24:48 am C M Caine wrote:
 I'm writing a class that inherits the inbuilt dict class and want
 some of my own code to run at initialisation, on the other hand, I
 still want the original dict.__init__ function to run. Can I ask the
 class to run the original __init__ and then my own function at
 initialisation automatically? If so, how?

This is the general technique for calling the superclass' method:

class MyDict(dict):
def __init__(self, *args, **kwargs):
# Call the superclass method.
dict.__init__(self, *args, **kwargs)
# Perform my own initialisation code.
print Calling my init code...


For advanced usage, replace the call to dict.__init__ with a call to 
super:

super(MyDict, self).__init__(*args, **kwargs)

And for guru-level mastery, replace to call to dict.__init__ with ... 
nothing at all, because dict.__init__ doesn't do anything.

Some people argue that you must call dict.__init__ even though it 
doesn't do anything. Their reasoning is, some day its behaviour might 
change, and if you don't call it in your subclass, then your class may 
break. This is true, as far as it goes, but what they say is that if 
the behaviour of dict.__init__ changes, and you *do* call it, your 
class may still break. (This is why dict is unlikely to change any time 
soon.)




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


Re: [Tutor] Modify inherited methods

2010-04-27 Thread Steven D'Aprano
On Wed, 28 Apr 2010 08:08:12 am Steven D'Aprano wrote:

 Some people argue that you must call dict.__init__ even though it
 doesn't do anything. Their reasoning is, some day its behaviour might
 change, and if you don't call it in your subclass, then your class
 may break. This is true, as far as it goes, but what they say is that
 if the behaviour of dict.__init__ changes, and you *do* call it, your
 class may still break. (This is why dict is unlikely to change any
 time soon.)

Oops, left out a word. I meant to say what they *don't* say is



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


Re: [Tutor] Modify inherited methods

2010-04-27 Thread Alan Gauld


Steven D'Aprano st...@pearwood.info wrote

On Wed, 28 Apr 2010 07:24:48 am C M Caine wrote:

I'm writing a class that inherits the inbuilt dict class and want
some of my own code to run at initialisation, on the other hand, I
still want the original dict.__init__ function to run. ...



This is the general technique for calling the superclass' method:

class MyDict(dict):
   def __init__(self, *args, **kwargs):
   # Call the superclass method.
   dict.__init__(self, *args, **kwargs)
   # Perform my own initialisation code.
   print Calling my init code...


And just to be clear that applies to any method not just __init__
Also you can do your intialisation before or after or both.
eg.

def __init__()
# do local pre processing(optional)
super().__init__(...)
#  do local post processing(optional)

Some people argue that you must call dict.__init__ even though it 
doesn't do anything. Their reasoning is, some day its behaviour might 
change, and if you don't call it in your subclass, then your class may 
break. 


I tend to argue for calling even if its a null call. Mainly because you 
sometimes don't know what the superclass does or doesn't do 
(eg you might not have access to the source) so its safer to call 
it...


the behaviour of dict.__init__ changes, and you *do* call it, your 
class may still break. 


... and if it breaks you at least have access to your own code to fix it...

But if you do have access to the superclass source then you can 
make an informed decision. In general I'm too lazy to go looking 
for it and just put the super call in :-)


HTH,


--
Alan Gauld
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] How can I display my float as a string???

2010-04-27 Thread Marco Rompré
Here is my code, I need to display my float value as a string.

item.set_prix str(float(prix))

Thank You
-- 
Marc-O. Rompré
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] (no subject)

2010-04-27 Thread Marco Rompré
Oups my posting was too big!!!

On Tue, Apr 27, 2010 at 11:04 PM, Marco Rompré marcodrom...@gmail.comwrote:

 Why is none of my items button works In this, I have two files and in
 my second file I imported all the function of the first one

 Here is my codes and my error code  for the two files please help me:
 Traceback (most recent call last):


   File F:\School\University\Session 4\Programmation
 SIO\magasingolfvues.py, line 426, in module
 app = App(racine, magasinmodele.txt)
   File F:\School\University\Session 4\Programmation
 SIO\magasingolfvues.py, line 23, in __init__
 ItemsFrame(contexte, item)
 NameError: global name 'item' is not defined
 


  1st fil called magasingolfmodele.py:

 # -*- coding: utf-8 -*-
 #
 # magasingolfmodele.py
 #
 # Magasin de golf -- Items de golf
 # Magasin de golf (nom, items, ville)
 # Items de golf(nom, prix)
 #
 # naming standards: http://www.python.org/dev/peps/pep-0008/
 #


 class Magasin:
 
 Le concept magasin pour la gestion d'inventaire des items de golf.
 
 def __init__(self, nom =, items =[], ville= ):
 self.nom = nom
 self.items = items
 self.ville = ville

 def set_nom(self, nom):
 self.nom = nom

 nom = property(None, set_nom)

 def set_items(self, items):
 self.items = items

 items = property(None, set_items)

 def set_ville(self, ville):
 self.ville = ville

 ville = property(None, set_ville)

 def __str__(self):
 return self.nom

 class Item:
 
 Le concept item pour la gestion d'inventaire des items de golf.
 
 def __init__(self, nom =, prix = 100):
 self.nom = nom
 self.prix = prix


 def set_nom(self, nom):
 self.nom = nom

 nom = property(None, set_nom)

 def set_prix(self, prix):
 self.prix = prix

 prix = property(None, set_prix)

 def __str__(self):
 return self.nom



 def initialiser(self):


 item01 = Item (Ensemble de fers Titleist)
 item01.set_prix(1099.99)

 item02 = Item (Ensemble de fers Callaway)
 item02.set_prix(1299.99)

 item03 = Item (Ensemble de fers Taylormade Burner Graphite)
 item03.set_prix(2499.99)

 item04 = Item (Ensemble de fers Cobra)
 item04.set_prix(999.99)

 item05 = Item (Ensemble de fers Ping)
 item05.set_prix(1399.99)

 item06 = Item (Ensemble de fers Ben Hogan)
 item06.set_prix(1199.99)

 items = [item01, item02, item03, item04, item05, item06]
 magasin01.set_items(items)

 items = [item01, item03, item04, item06]
 magasin02.set_items(items)

 items = [item01, item02, item03, item05]
 magasin03.set_items(items)

 magasins = [magasin01,
 magasin02,
 magasin03]

 self.set_magasins(magasins)

 self.sauvegarder()

 def afficher(self):
 print()
 print(Magasins)
 for magasin in self.magasins:
 print()
 print(magasin)
 print()
 for item in magasin.items:
 print(item)
 for prix in item.prix:
 print(prix)


 if __name__ == '__main__':
 modele = Modele(magasinmodele.txt)
 modele.charger()
 if modele.vide():
 modele.initialiser()
 modele.afficher()


 Here's the code of my second file:

 # -*- coding: utf-8 -*-
 #
 # magasingolfvues.py
 #
 # naming standards: http://www.python.org/dev/peps/pep-0008/
 #

 from Tkinter import *

 from magasingolfmodele import *

 class App:
 
 Application illustrant le concept d'un magasin de golf et des items
 qu'il vend.
 
 def __init__(self, contexte, nom_fichier):
 self.contexte = contexte
 self.modele = Modele(nom_fichier)
 self.modele.charger()
 if self.modele.vide():
 self.modele.initialiser()
 MagasinsFrame(self)
 ItemsFrame(contexte, item)


 class ItemsFrame(Toplevel):
 
 Liste des items.
 
 def __init__(self, contexte, items):
 Toplevel.__init__(self, contexte)
 self.contexte = contexte
 self.items = items

 self.title(Gestion des items de golf)
 titre = Label(self, text = Bâtons de golf disponibles (nom))
 titre.pack()

 self.liste = Listbox(self)
 for items in self.items:
 self.liste.insert(END, items)
 self.liste.pack()

 self.afficher_item_bouton = Button(
 self, text = Item, fg = blue, command = self.afficher_item
 )
 self.afficher_item_bouton.pack(side = LEFT)

 self.ajouter_item_bouton = Button(
 self, text = Ajouter, fg = blue, command =
 self.ajouter_item
 )
 self.ajouter_item_bouton.pack(side=LEFT)

 self.afficher_item_bouton = Button(
 self, text = Modifier, 

Re: [Tutor] How can I display my float as a string???

2010-04-27 Thread Lie Ryan
On 04/28/10 12:35, Marco Rompré wrote:
 Here is my code, I need to display my float value as a string.
 
 item.set_prix str(float(prix))

print prix

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


Re: [Tutor] (no subject)

2010-04-27 Thread Luke Paireepinart
On Tue, Apr 27, 2010 at 10:12 PM, Marco Rompré marcodrom...@gmail.com wrote:
 Oups my posting was too big!!!

 On Tue, Apr 27, 2010 at 11:04 PM, Marco Rompré marcodrom...@gmail.com
 wrote:

 Why is none of my items button works In this, I have two files and in
 my second file I imported all the function of the first one

 Here is my codes and my error code  for the two files please help me:
 Traceback (most recent call last):


   File F:\School\University\Session 4\Programmation
 SIO\magasingolfvues.py, line 426, in module
     app = App(racine, magasinmodele.txt)
   File F:\School\University\Session 4\Programmation
 SIO\magasingolfvues.py, line 23, in __init__
     ItemsFrame(contexte, item)
 NameError: global name 'item' is not defined
 

[snip lots of code]


You're not going to get a very good reply with a post like this.
First of all, it's homework, so we aren't going to give you answers
(not that we would anyway).
Secondly, if you have a problem, you need to clearly specify what the
problem is, and clearly outline what you did to try to solve it, and
why you think that didn't work, and some general indication that you
are trying things.
We're not here to just give people answers, we're here to help you
when you get stuck learning on your own.
It's much more rewarding in the end, trust me.

Also why do you think the problem you're having is your items button
[doesn't] work when it's pretty clear from the traceback that your
code crashes due to trying to access a variable that doesn't exist?

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