Re: [Tutor] Placing entire Application inside a class

2007-12-18 Thread Tiger12506
It is helpful for GUI applications because of what it says about halfway 
down the page, within __init__ you can bind certain messages to methods of 
the class.

I would not say that it is recommended persé but I'm sure that there are 
those out there that cannot write a program without putting it into a class. 
And yet there are those out there who cannot write a program without making 
it all functional in nature. Do what feels right to you.

This sort of thing is very popular in C++ because of the way MFC is 
structured, but no one here likes MFC right? ;-)

As I said, do what you like, just as long as it doesn't get messy.



- Original Message - 
From: "Jim Morcombe" <[EMAIL PROTECTED]>
To: "python tutor mailing list" 
Sent: Tuesday, December 18, 2007 8:54 PM
Subject: [Tutor] Placing entire Application inside a class


I have just read through "Creating a GUI in Python - by Dakota Lemaster"

In it, Dakota recomends placing the entire application within a class.

Why is this so?  Surely in many cases you end up with a constructor for the 
class that is cumbersome and complex?

Is this a recomended Python programming technique?

http://student-iat.ubalt.edu/sde/students/lemaster/COSC330/Final/sec4_AppClass.html


Why is this so?  Surely in many cases you end up with a constructor for the 
class that is cumbersome and complex?

Is this a recomended Python programming technique?

Jim






> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
> 

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Required method to make foo(*Vector(0,0,0)) work.

2007-12-18 Thread Tiger12506
> Sorry I wasn't quite sure how to explain it it's a vector class i've 
> written
> myself.
> I've worked it out now, I was using a vector as part of a quaternion and
> wanted to
> be able to pass a vector or individual numbers so it seemed the easiest 
> way
> to be
> able to use the *sequence syntax. Apparently you have to have to have a
> __getitem__ method for it to work.

Actually I think you can define a __list__ method. Hmmm. A quick python doc 
check shows that I lied. Nevermind. Please disregard this email. Or I 
suppose I could just not send it. But then again, I would have wasted all of 
this time writing this. Gee. What to do? Hmmm hmm... I think it's 
getting late. Yeah, I think you have the __getitem__ idea right. 

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Placing entire Application inside a class

2007-12-18 Thread Jim Morcombe
I have just read through "Creating a GUI in Python - by Dakota Lemaster"

In it, Dakota recomends placing the entire application within a class.

Why is this so?  Surely in many cases you end up with a constructor for the 
class that is cumbersome and complex?

Is this a recomended Python programming technique?

http://student-iat.ubalt.edu/sde/students/lemaster/COSC330/Final/sec4_AppClass.html


Why is this so?  Surely in many cases you end up with a constructor for the 
class that is cumbersome and complex?

Is this a recomended Python programming technique?

Jim
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Required method to make foo(*Vector(0,0,0)) work.

2007-12-18 Thread Adam Bark
On 19/12/2007, John Fouhy <[EMAIL PROTECTED]> wrote:
>
> On 19/12/2007, Adam Bark <[EMAIL PROTECTED]> wrote:
> > I want to be able to get the values for my vector class but I don't know
> > what method you need to get the * thing to work ie how to make it a
> sequence
> > i think. Anybody know how to do this?
> > Thanks in advance.
>
> If you're confused about python's *args / **kwargs syntax, this post I
> wrote a while ago might help:
> http://mail.python.org/pipermail/tutor/2007-April/053725.html
>
> Otherwise, as Kent says, we need more information.
>
> --
> John.
>

Sorry I wasn't quite sure how to explain it it's a vector class i've written
myself.
I've worked it out now, I was using a vector as part of a quaternion and
wanted to
be able to pass a vector or individual numbers so it seemed the easiest way
to be
able to use the *sequence syntax. Apparently you have to have to have a
__getitem__ method for it to work.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Required method to make foo(*Vector(0,0,0)) work.

2007-12-18 Thread John Fouhy
On 19/12/2007, Adam Bark <[EMAIL PROTECTED]> wrote:
> I want to be able to get the values for my vector class but I don't know
> what method you need to get the * thing to work ie how to make it a sequence
> i think. Anybody know how to do this?
> Thanks in advance.

If you're confused about python's *args / **kwargs syntax, this post I
wrote a while ago might help:
http://mail.python.org/pipermail/tutor/2007-April/053725.html

Otherwise, as Kent says, we need more information.

-- 
John.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Required method to make foo(*Vector(0,0,0)) work.

2007-12-18 Thread Kent Johnson
Adam Bark wrote:
> I want to be able to get the values for my vector class but I don't know 
> what method you need to get the * thing to work ie how to make it a 
> sequence i think. Anybody know how to do this?

I'm not a very good mind reader!

What vector class are you talking about? What are you trying to do with 
it? Why do you need a sequence?

Some context, maybe some code you have tried and the error messages you 
got, would be very helpful.

Kent
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] MAKING MONEY WITH OUR PYTHON CODE-A YULE GIFT TO ALL

2007-12-18 Thread Kirk Bailey
OK, who's a large customer base? Folk i the world running around with laptops,
non geek business folk. they knowfrom Adam when it comes to hand installing 
code.

So when we write things hard to install, who buys it? not very many. A few 
geeks maybe.
So we need to make our code easy to install and use if we want to sell much of 
it
to real no kidding non geek customers.

So I started learning the inno free windows installer. It's good, and it is 
free.

To practice and learn, I wrote an installer for the very nice and robust but 
totally
manual install tinyweb http server. And in classic refuse to give upmanner, 
finally
succeeded.

It works, and is located on the web HERE:
http://www.tinylist.org/tinyweb193Asetup.exe
So anyone can have a small good utility server in their windows computer.

SO WHAT?

So now all that fine python code has a ready windows market is so what.

(And I can start marketing my windows wiki, which requires a server for it to 
talk through.)

Happy Yule, one and all. Thanks for helping me to learn python.

-- 
Salute!
-Kirk Bailey
   Think
  +-+
  | BOX |
  +-+
   knihT

Fnord.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Required method to make foo(*Vector(0,0,0)) work.

2007-12-18 Thread Adam Bark
I want to be able to get the values for my vector class but I don't know
what method you need to get the * thing to work ie how to make it a sequence
i think. Anybody know how to do this?
Thanks in advance.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Something I don't understand

2007-12-18 Thread Eric Brunson
Jim Morcombe wrote:
> Below, "student_seats" is a list of the class "student".
>
> Why does this code set every student.row to zero when there is only one 
> student in the list with row > 5?
> It still sets them all to zero if I change the test to ">200" when there are 
> no student.rows > 200.
> But if I change the test to "<1" then nothing gets set to zero.
>
>
> Jim
>
>
> class student:
>  def __init__ (self, name, row, column):
>  self.name = name
>  self.row = row
>  self.column = column
>
>
>
> for student in student_seats:
>   

Try making your index variable (student) something that is not the same 
name as the class.

> print student.name, "row = ", student.row, "column = ", 
> student.column
> if student.row > 5:
> student.row = 0
>  print student.name, "row = ", student.row, "column = ", 
> student.column
>
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
>   

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Application Tutorials

2007-12-18 Thread Kent Johnson
Michael Schultz wrote:

> What I'm looking for are nicely structured intermediate tutorials that 
> focus on creating actual applications, even if fairly useless :) But 
> mainly something that can give me an understanding of how you can 
> structure an app.

Not tutorials, but application skeletons:
http://www.artima.com/weblogs/viewpost.jsp?thread=4829
http://aspn.activestate.com/ASPN/search_results/index?cx=005567415255730122040%3A9qxhdmxv2eq&cof=FORID%3A9&q=+skeleton+site%3Ahttp%3A%2F%2Faspn.activestate.com%2FASPN%2FCookbook%2FPython&sa.x=0&sa.y=0&category=#1072

HTH,
Kent
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Application Tutorials

2007-12-18 Thread Michael Schultz
Hello everyone.

I'm one of those people stuck in that odd space between total noob and
partially competent :)

What I'm looking for are nicely structured intermediate tutorials that focus
on creating actual applications, even if fairly useless :) But mainly
something that can give me an understanding of how you can structure an app.

I hope this isn't an arcane request, but I've been having problems finding
tutes like this.

Thanks in advance!


~Mike
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] detecting a change in a iterable object (list, array, etc.)

2007-12-18 Thread Alan Gauld

"Tim Michelsen" <[EMAIL PROTECTED]> wrote


>> A list comprehension will work for this. If data is a list of 
>> triples of
>> (year, month, volume) then this will give you a list of the 1997 
>> triples:
>>
>> data1997 = [ item for item in data if item[0]==1997 ]

Note4 that for this to work it assumes a *list of triples*

> I tried your code out (see below).

> for line in input_data:
>#~ print line
>#~ year month day temp_3hr
>year = int(line[1])
>month = int(line[2])-1
>day = int(line[3])
>value = float(line[6])*0.5
>compact_list = [year, month, day, value]

You are overwriting the same list with a new set of values so your
final list is just the last set of 4 values. I suspect you meant to 
have

compact_list.append( (year,month,day,value) )

>res_rows = [ item for item in compact_list if compact_list[0] == 
> 1990 ]

And this becomes the same as the original suggestion

res_rows = [ item for item in compact_list if item[0] == 1990 ]

If I understand what you are trying to do...

HTH,

-- 
Alan Gauld
Author of the Learn to Program web site
http://www.freenetpages.co.uk/hp/alan.gauld 


___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Something I don't understand

2007-12-18 Thread Remco Gerlich
On Dec 18, 2007 2:44 AM, Jim Morcombe <[EMAIL PROTECTED]> wrote:

> Below, "student_seats" is a list of the class "student".


How do you create the list?

And yes, the naming is confusing, but I believe that only masks the class,
it shouldn't cause this problem.

Remco Gerlich
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] detecting a change in a iterable object (list, array, etc.)

2007-12-18 Thread Tim Michelsen
Hello,
> A list comprehension will work for this. If data is a list of triples of 
> (year, month, volume) then this will give you a list of the 1997 triples:
> 
> data1997 = [ item for item in data if item[0]==1997 ]

I tried your code out (see below).

Here is the output:


[]
[]
[]
[]
[]
[1990, 0, 1, -18.0]
[1990, 0, 2, -0.5]
[1990, 0, 3, -14.0]
[1990, 0, 4, -21.0]

How do I avoid the []?

What whould be the easiest way to save this list (without the "[]") into a file
and append a newline after each row?

Thanks for your help in advance,
Timmie

Here's the code:
#!/usr/bin/env python
# currently used modules
import csv

# SOME VARIABLES
#~ stattion_name = 'Sosan'
input_file_name = '../data/filter_test_data.csv'
output_file_name = '../data/filter_test_data_result.csv'

# prepare files
input_file = open(input_file_name, 'r')
output_file = open(output_file_name ,'w')
header = u"Year, Month, Day, Hour_of_day [h], values, \n"
input_data = csv.reader(input_file, delimiter=';')

#~ skip the first rows
line1 = input_file.readline()
line2 = input_file.readline()

#~ write the header
output_file.write(header.encode('utf-8'))

counter = 0
value_col = 6
for line in input_data:
#~ print line
#~ year month day temp_3hr
year = int(line[1])
month = int(line[2])-1
day = int(line[3])
value = float(line[6])*0.5
compact_list = [year, month, day, value]
res_rows = [ item for item in compact_list if compact_list[0] == 1990 ]
print res_rows
input_file.close()
output_file.close()




___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Something I don't understand

2007-12-18 Thread Tiger12506
> Below, "student_seats" is a list of the class "student".
>
> Why does this code set every student.row to zero when there is only one
> student in the list with row > 5?
> It still sets them all to zero if I change the test to ">200" when there 
> are
> no student.rows > 200.
> But if I change the test to "<1" then nothing gets set to zero.
>
>
> Jim
>
>
> class student:
> def __init__ (self, name, row, column):
> self.name = name
> self.row = row
> self.column = column
>
>
>
> for student in student_seats:
>print student.name, "row = ", student.row, "column = ",
> student.column
>if student.row > 5:
>student.row = 0
> print student.name, "row = ", student.row, "column = ",
> student.column

Probably a naming clash. You have student defined as a class, yet when you 
run the for loop, student is named for each instance of that class in the 
list. Python is most likely getting confused when you say student.row = 0, 
thinking that you mean All student classes' rows set to zero. At any rate, 
it's a bad idea to mix names like that. 

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor