Re: [Tutor] Classes in multiple files - code included

2013-04-04 Thread Alan Gauld
On 04/04/13 08:51, Phil wrote: By the way, I notice that it can take several hours for my postings to appear on the list. Possibly due to moderation? Nope, the only posts that get moderated are the ones where the poster has not subscribed to the list (or is using a different email address th

Re: [Tutor] Classes in multiple files - code included

2013-04-04 Thread Steven D'Aprano
On 04/04/13 13:12, Phil wrote: On 04/04/13 11:58, Steven D'Aprano wrote: On 04/04/13 12:47, Phil wrote: And this is the error message; "global name 'Ui_satListDialog' is not defined" On its own, that is almost useless. Python gives you more debugging information than that: it gives you a c

Re: [Tutor] Classes in multiple files - code included

2013-04-04 Thread Phil
On 04/04/13 16:58, Peter Otten wrote: Phil wrote: I think I must be very close now so I'll post just the code that I think is relevant. This the main window class: import satListDialog Here you are importing the module "satListDialog" class MainWindow(QMainWindow, Ui_MainWindow): This

Re: [Tutor] Classes in multiple files - code included

2013-04-03 Thread Peter Otten
Phil wrote: > I think I must be very close now so I'll post just the code that I think > is relevant. > > This the main window class: > import satListDialog Here you are importing the module "satListDialog" > class MainWindow(QMainWindow, Ui_MainWindow): > > This is the function to show the

Re: [Tutor] Classes in multiple files - code included

2013-04-03 Thread Phil
On 04/04/13 11:58, Steven D'Aprano wrote: On 04/04/13 12:47, Phil wrote: And this is the error message; "global name 'Ui_satListDialog' is not defined" On its own, that is almost useless. Python gives you more debugging information than that: it gives you a complete traceback, which include

Re: [Tutor] Classes in multiple files - code included

2013-04-03 Thread Steven D'Aprano
On 04/04/13 12:47, Phil wrote: And this is the error message; "global name 'Ui_satListDialog' is not defined" On its own, that is almost useless. Python gives you more debugging information than that: it gives you a complete traceback, which includes the actual line of code causing the prob

Re: [Tutor] Classes in multiple files - code included

2013-04-03 Thread Phil
On 04/04/13 09:32, Alan Gauld wrote: Reme,ber that in python its the file name you need to use to import So if SatelliteListDialog is defined in satellite.py you need import satellite in your main window file. And satellite.py has to be in your library path too... The Eric IDE must take ca

Re: [Tutor] Classes in multiple files

2013-04-03 Thread Phil
On 04/04/13 09:32, Alan Gauld wrote: On 04/04/13 00:14, Phil wrote: If this was C++ then I'd need to include a class header and so I'm thinking that an import statement is needed in the main window class referring to the dialog class. Import SatelliteListDialog isn't correct. Reme,ber that in

Re: [Tutor] Classes in multiple files

2013-04-03 Thread Alan Gauld
On 04/04/13 00:14, Phil wrote: If this was C++ then I'd need to include a class header and so I'm thinking that an import statement is needed in the main window class referring to the dialog class. Import SatelliteListDialog isn't correct. Reme,ber that in python its the file name you need to

[Tutor] Classes in multiple files

2013-04-03 Thread Phil
Thank you for reading this. The recent question relating to classes has prompted to ask this one. I have a main window class and a dialog class and they are defined in separate files. I'm attempting to display the dialog when a menu item is selected in the main window but it doesn't work becau

Re: [Tutor] classes : post-declaration attributes

2013-02-09 Thread neubyr
On Sat, Feb 9, 2013 at 3:24 AM, Alan Gauld wrote: > On 09/02/13 07:01, neubyr wrote: > >> >> I am learning Python 2.7 classes and objects. It seems like attributes >> (data attributes and methods) can be added to a class/object even after >> it's first declaration. For example, >> > > You can do

Re: [Tutor] classes : post-declaration attributes

2013-02-09 Thread Alan Gauld
On 09/02/13 07:01, neubyr wrote: I am learning Python 2.7 classes and objects. It seems like attributes (data attributes and methods) can be added to a class/object even after it's first declaration. For example, You can do that, but mostly you shouldn't. Usually when classes/objects are use

Re: [Tutor] classes : post-declaration attributes

2013-02-08 Thread Steven D'Aprano
On 09/02/13 18:01, neubyr wrote: I understand that all attributes are stored in a dictionary, but I am not following when adding an attribute after initial declaration approach should be used. The official documentation also suggests that valid attributes are all the names present when the class

Re: [Tutor] classes : post-declaration attributes

2013-02-08 Thread Mitya Sirenef
On 02/09/2013 02:01 AM, neubyr wrote: > I am learning Python 2.7 classes and objects. It seems like attributes (data attributes and methods) can be added to a class/object even after it's first declaration. For example, > > > class A(object): > def __init__(self,arg): > self.val1 = arg > > a

[Tutor] classes : post-declaration attributes

2013-02-08 Thread neubyr
I am learning Python 2.7 classes and objects. It seems like attributes (data attributes and methods) can be added to a class/object even after it's first declaration. For example, class A(object): def __init__(self,arg): self.val1 = arg a = A(1) print a.val1 Now another data attribute v

[Tutor] classes for setting 2D envelopes

2010-12-22 Thread Matt Gregory
Hi all, I've been working on creating 2D bounding box (envelope) classes to describe spatial data. Variations of these are available in other spatial libraries (e.g. Shapely), although I haven't found envelopes specific to raster data that also specifies cell size. Could be I just haven't fo

Re: [Tutor] classes passing information

2010-04-21 Thread Alan Gauld
"Stefan Lesicnik" wrote Caveat: I know zilch about pyGtk. My question is maybe more generic with functions as opposed to classes, but i've been trying some pyGtk and I am unsure how i get values back from other classes. They should be returned by the methods. So you just assign the method r

[Tutor] classes passing information

2010-04-21 Thread Stefan Lesicnik
Hi Guys, I'm slowly starting to understand classes coming from basic non oo scripting. I guess the problem comes in that you think you understand, and then look at code and its totally different and confusing. My question is maybe more generic with functions as opposed to classes, but i've be

Re: [Tutor] Classes that do operator overloading

2009-11-08 Thread Alan Gauld
"spir" wrote English is terrible. From wiktionary (abstracts)/ Indeed. and the fact that computer Scientists often abuse English makes it worse! header Text, or other visual information, used to mark off a quantity of text, often titling or summarizing it. This is probaly the closest to

Re: [Tutor] Classes that do operator overloading

2009-11-07 Thread spir
Le Sat, 7 Nov 2009 14:06:15 -, "Alan Gauld" s'exprima ainsi: > "C.T. Matsumoto" wrote > > > class Foo: # the book says this is a class header > >pass > > Hmm, that's pretty dubious usage of header in my view. > Its the class definition and there is nothing "header" about it. Engli

Re: [Tutor] Classes that do operator overloading

2009-11-07 Thread Alan Gauld
"C.T. Matsumoto" wrote class Foo: # the book says this is a class header pass Hmm, that's pretty dubious usage of header in my view. Its the class definition and there is nothing "header" about it. As for my question it looks like the convention is if a class only has operator overload

Re: [Tutor] Classes that do operator overloading

2009-11-07 Thread Tim Golden
Hugo Arts wrote: On Sat, Nov 7, 2009 at 12:25 PM, C.T. Matsumoto wrote: class indexer(): def ___getitem__(self, index): return index ** 2 I thought I was missing some special style, or rule. The class above is take from Learning Python, and there are several other examples too. fo

Re: [Tutor] Classes that do operator overloading

2009-11-07 Thread Hugo Arts
On Sat, Nov 7, 2009 at 12:25 PM, C.T. Matsumoto wrote: > Thanks Hugo, > > Do methods like __add__, __del__, count as built-in types? I'm aware of the > rule you explained and use it and that's why when  I saw: > Built-in types are only those classes 'built in' to the python interpreter. They incl

Re: [Tutor] Classes that do operator overloading

2009-11-07 Thread C.T. Matsumoto
Thanks Hugo, Do methods like __add__, __del__, count as built-in types? I'm aware of the rule you explained and use it and that's why when I saw: class indexer(): def ___getitem__(self, index): return index ** 2 I thought I was missing some special style, or rule. The class above i

Re: [Tutor] Classes that do operator overloading

2009-11-07 Thread Hugo Arts
On Sat, Nov 7, 2009 at 10:39 AM, C.T. Matsumoto wrote: > yes, > > class Foo: # the book says this is a class header >   pass > > As for my question it looks like the convention is if a class only has > operator overloading then the class receives a lowercase class name. > If the class has a mix, o

Re: [Tutor] Classes that do operator overloading

2009-11-07 Thread C.T. Matsumoto
yes, class Foo: # the book says this is a class header pass As for my question it looks like the convention is if a class only has operator overloading then the class receives a lowercase class name. If the class has a mix, operator overloading and a normal method then the class name gets sta

Re: [Tutor] Classes that do operator overloading

2009-11-07 Thread Alan Gauld
"C.T. Matsumoto" wrote I'm reading Learning Python's section 'Operator Overloading' and I was wondering why class headers that implement and overload are lowercase? I'm not sure what you mean by class headers? Can you post an example? -- Alan Gauld Author of the Learn to Program web site

[Tutor] Classes that do operator overloading

2009-11-07 Thread C.T. Matsumoto
Hello All, I'm reading Learning Python's section 'Operator Overloading' and I was wondering why class headers that implement and overload are lowercase? Cheers, T ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options:

Re: [Tutor] Classes and Databases

2008-11-16 Thread Alan Gauld
"Jojo Mwebaze" <[EMAIL PROTECTED]> wrote Thanks Allan... we have used CVS for the base system.. but for users provided functions, we think for having them persistent in the database.. Thats what I don't understand. I can't think of a single good reason to do that. I can see the point of putt

Re: [Tutor] Classes and Databases

2008-11-15 Thread Rich Lovely
Jojo, am reading your problem correctly? If you have (for example) x=2 and y=4, you want the database to return functions like x+2, 2x and 3x-2? (I know this is probably much simpler than the actual functions you'll be using). And you the want to use those functions in your code? @list: pi

Re: [Tutor] Classes and Databases

2008-11-14 Thread Jojo Mwebaze
Sorry Alan, What u described below is exactly what i want to do.. if given x, y as two datatums and such that f(x) --> y, given y can we determine f or x? Assuming the x, y and f are stored in the database, then we can be able to write queries to search/extract for the f's that are responsible f

Re: [Tutor] Classes and Databases

2008-11-13 Thread ALAN GAULD
> Thanks Allan... we have used CVS for the base system.. but for users provided > functions, > we think for having them persistent in the database.. I'm puzzled. CVS provides much better facilities for handling code, especially with multiple versions (visibility of diffs, who changed what and w

Re: [Tutor] Classes and Databases

2008-11-13 Thread Jojo Mwebaze
Thanks Allan... we have used CVS for the base system.. but for users provided functions, we think for having them persistent in the database.. Cheers Johnson On Thu, Nov 13, 2008 at 7:18 PM, Alan Gauld <[EMAIL PROTECTED]>wrote: > > "Jojo Mwebaze" <[EMAIL PROTECTED]> wrote > > Because we have

Re: [Tutor] Classes and Databases

2008-11-13 Thread Alan Gauld
"Jojo Mwebaze" <[EMAIL PROTECTED]> wrote Because we have very many such cases, we can not incorporate such adhoc changes in the system.. we are thinking of storing such classes in the database and have classes run from the database. if anyone else feels they need to use someone's algorithm

[Tutor] Classes and Databases

2008-11-13 Thread Jojo Mwebaze
Hello There, I would like store python classes in a database and then execute these classes from the database? Scientists do always want apply their own algorithms at the same time we want to keep this information. (knowing which class is responsible for which data) Because we have very many such

Re: [Tutor] Classes in separate files

2008-08-02 Thread Alan Gauld
"James" <[EMAIL PROTECTED]> wrote Another question on classes in separate files... It could just as well be about functions. The issue is about visibility of names not classes. main.py instantiates a class called 'testClass' inside of a file temp.py. In main.py: t = temp.testClass() ...

Re: [Tutor] Classes in separate files

2008-08-02 Thread Alan Gauld
"James" <[EMAIL PROTECTED]> wrote The issue is, however, that I'm not sure the "best" way to pass things into classes, and the "best" way to get something back. In an OOP syustem you don;t normally have to pass a lot into a method since most of the data should be internal to the object Often

Re: [Tutor] Classes in separate files

2008-08-02 Thread James
Another question on classes in separate files... main.py instantiates a class called 'testClass' inside of a file temp.py. In main.py: t = temp.testClass() So now I can access some of the variables inside of 't'. For example, let's say that in main.py, I do the following: # get a variable fr

[Tutor] Classes in separate files

2008-08-02 Thread James
All, I've started tinkering (just a little) with classes, primarily because I have to. (I've never been a huge fan of OOP, but can tolerate it when used properly). I'll be the first to admit that I don't know much about how to program "correctly" when dealing with objects, however, so any thought

Re: [Tutor] Classes v2, thoughts/suggestions please

2008-07-12 Thread Kent Johnson
On Sat, Jul 12, 2008 at 9:47 AM, Paul Melvin <[EMAIL PROTECTED]> wrote: > And how can i go about testing that i get appropriate values during the > testing/building phase (generally speaking), is it lots of print/return > statements and then remove them? Take a look at the doctest and unittest mo

Re: [Tutor] Classes v2, thoughts/suggestions please

2008-07-12 Thread Paul Melvin
> -Original Message- > From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On > Behalf Of Alan Gauld > Sent: 12 July 2008 18:08 > To: tutor@python.org > Subject: Re: [Tutor] Classes v2, thoughts/suggestions please > > > "Paul Melvin" <[EMAIL PROTECT

Re: [Tutor] Classes v2, thoughts/suggestions please

2008-07-12 Thread Alan Gauld
"Paul Melvin" <[EMAIL PROTECTED]> wrote i have come up with a working class for a square, Well done. It might not be the most elegant solution on the inside but it isn't too bad from the users point of view and thats what you should aim for IMHO. I was thinking about using *args to get may

[Tutor] Classes v2, thoughts/suggestions please

2008-07-12 Thread Paul Melvin
Thanks to Alans insights i have come up with a working class for a square, overcomplicated probably but it lays the groundwork for my polygon class which will iterate over something to generate an n-sided polygon. If anyone is interested in actually running/testing this you need to get hold of pgyl

Re: [Tutor] Classes

2008-07-12 Thread Alan Gauld
"Alan Gauld" <[EMAIL PROTECTED]> wrote class Square: def __init__(self,p1,p2,p3,p4): self.points = [p1,p2,p3,p4] def draw(self): myTookKitDrawSquare(p1.x,p1.y, p1.col, p2.x,p2.y, p2.col,

Re: [Tutor] Classes

2008-07-11 Thread Alan Gauld
<[EMAIL PROTECTED]> wrote 1. What is the difference between a classmethod and a staticmethod, and when would i use either? Kent pointed you at the recent discussion but from your later comments I thibnk its pretty safe to say that for now you don't need to care. The vast majority of classes yo

Re: [Tutor] Classes

2008-07-11 Thread Kent Johnson
On Fri, Jul 11, 2008 at 4:58 AM, <[EMAIL PROTECTED]> wrote: > 1. What is the difference between a classmethod and a staticmethod, and when > would i use either? We discussed this recently: http://thread.gmane.org/gmane.comp.python.tutor/47054/focus=47108 Kent

[Tutor] Classes

2008-07-11 Thread paul
hi,I have two questions please:1. What is the difference between a classmethod and a staticmethod, and when would i use either?2. I want to create an object, presumably a class, to handle attributes of an open gl object.For example, if i wanted to create a 2d square i need 4 points, each with an x,

Re: [Tutor] classes and the deepcopy function

2008-01-07 Thread Tiger12506
> Hi > > I was trying to learn about classes in Python and have been playing > around but I am having a problem with the deepcopy function. I want to > have a function that returns a clean copy of an object that you can > change without it changing the original, but no matter what I do the > origin

Re: [Tutor] classes and the deepcopy function

2008-01-06 Thread bob gailer
Michael wrote: > Okay > > Just when I think I am getting it you throw this in. You're welcome. > So why does a become local to each variable but b seem global? > A better way to ask that is "why does a become an instance property but b remain a class property?" f.a = 3 This is an assignment

Re: [Tutor] classes and the deepcopy function

2008-01-06 Thread Michael
Okay Just when I think I am getting it you throw this in. So why does a become local to each variable but b seem global? Michael bob gailer wrote: > Michael wrote: >> Hi Michael >> >> Thanks for the quick reply, I think I get it. So becuase I did not >> declare them withing the init method usi

Re: [Tutor] classes and the deepcopy function

2008-01-05 Thread bob gailer
Michael wrote: > Hi Michael > > Thanks for the quick reply, I think I get it. So becuase I did not > declare them withing the init method using self they are shared by every > object that is created, even completely brand new ones? > > Is it normal practice to declare your variables in a class? I

Re: [Tutor] classes and the deepcopy function

2008-01-05 Thread Alan Gauld
"Michael" <[EMAIL PROTECTED]> wrote > Is it normal practice to declare your variables in a class? I notice > that you don't have to, you can create them as you go, but i thought > declaring and initialising them in the class would make it easier to > understand and see what the class is for and s

Re: [Tutor] classes and the deepcopy function

2008-01-04 Thread Michael
Hi Michael Thanks for the quick reply, I think I get it. So becuase I did not declare them withing the init method using self they are shared by every object that is created, even completely brand new ones? Is it normal practice to declare your variables in a class? I notice that you don't hav

[Tutor] classes and the deepcopy function

2008-01-04 Thread Michael H. Goldwasser
Hi Michael, This is a very interesting example. You do indeed have two distinct copies. The interdependence you are observing is because you have defined CLASS-LEVEL variables (akin to static in Java) rather than instance-level variables. This is because of their declaration within th

[Tutor] classes and the deepcopy function

2008-01-04 Thread Michael
Hi I was trying to learn about classes in Python and have been playing around but I am having a problem with the deepcopy function. I want to have a function that returns a clean copy of an object that you can change without it changing the original, but no matter what I do the original change

Re: [Tutor] Classes: global name not defined

2007-09-12 Thread Alan Gauld
"Ara Kooser" <[EMAIL PROTECTED]> wrote > File "/Users/ara/Documents/yeast/oop_yeast_nocaps.py", line 87, in > >first_instance.print_world() > File "/Users/ara/Documents/yeast/oop_yeast_nocaps.py", line 40, in > print_world >m, n = world['dimensions'] > NameError: global name 'world'

[Tutor] Classes: global name not defined

2007-09-12 Thread Ara Kooser
So taking the advice given my John, Kent, and Michael I reworked the program and created a class for world. I was able to solve the first several errors that came up as a I moved functions into class methods but this one stumps me. The error I am getting is: Traceback (most recent call last):

Re: [Tutor] classes and functions

2006-06-30 Thread Mike Hansen
> -Original Message- > From: [EMAIL PROTECTED] > [mailto:[EMAIL PROTECTED] On Behalf Of anil maran > Sent: Thursday, June 29, 2006 12:51 PM > To: Tutor > Subject: [Tutor] classes and functions > > how to use classes and functions in python > thanks What do

Re: [Tutor] classes and functions

2006-06-29 Thread Alan Gauld
> how to use classes and functions in python > thanks Most of the online tutorials, including mine, will have a section on OOP. Try reading one and if you have specific questions come back here and we will try to answer them. Alan Gauld Author of the Learn to Program web site http://www.freene

[Tutor] classes and functions

2006-06-29 Thread anil maran
how to use classes and functions in python thanks __ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com ___ Tutor maillist - Tutor@python.org http://ma

Re: [Tutor] Classes

2005-02-02 Thread Alan Gauld
> I was just wondering, what magic can you do with classes? You can define your own types. Thats what classes are for. Those types can be as 'magic' as your imagination (and programming skills!) allow. > other classes are interesting to subclass? I've seen Object too, but I > don't understand wha

Re: [Tutor] Classes

2005-02-01 Thread Max Noel
On Feb 1, 2005, at 23:08, Ismael Garrido wrote: Hello. I was just wondering, what magic can you do with classes? I mean, things like "class Name(Exception)" or "class Name(threading.Thread), which other classes are interesting to subclass? I've seen Object too, but I don't understand what it doe

[Tutor] Classes

2005-02-01 Thread Ismael Garrido
Hello. I was just wondering, what magic can you do with classes? I mean, things like "class Name(Exception)" or "class Name(threading.Thread), which other classes are interesting to subclass? I've seen Object too, but I don't understand what it does. Thanks Ismael __