Re: [Tutor] OOP - have I done it right or could it be better?

2007-01-24 Thread Original Brownster

--- Kent Johnson <[EMAIL PROTECTED]> wrote:

> Original Brownster wrote:
> > Hi,
> > I'm fairly new to using OOP and very new to Python, my first
> program is
> > coming along well and I have split the code into 2 modules.
> > 
> > The program finds stream urls, downloads them, re-encodes them to
> othe
> > formats, all this functionality I have created in one module with
> one
> > class called Streamrip and methods to handle this.
> > The second module contains all the code to handle the pygtk
> interface
> > and written as a separate class called Windowapp()
> > 
> > You call the Windowapp() routine, in its' init method I have a call
> to
> > create an instance of the streamrip class:
> > 
> > self.UC = Streamrip(var=)
> > 
> > from then on within the Windowapp class i refer to the methods in
> > streamrip like
> > 
> > self.UC.Dumpstream(...)  etc.
> 
> This all sounds good. You have a module, Streamrip, that implements
> the 
> core functionality you need. From your description, this module
> doesn't 
> know about the GUI so it could be reused by another kind of client, 
> tested, etc. You also have a module that implements a GUI front-end
> to 
> Streamrip. All good. Just make sure the Streamrip module doesn't know
> 
> anything about the Windowapp module - keep the dependencies one-way.

That's good then as that's how it works, it looks like I'll be adding a
command line interface too as I am thinking this and cron will be a
good way to schedule jobs. With the modular approach it means I'll
pretty much not have to touch the core functionality routines.

Thanks for your advice I feel I'm getting there!
The hardest part for me so far has being moving from VB interface
programming, when I first looked at some of the gui programming
toolkits in linux I was a bit overwhelmed however, once I made a start
I soon got some little programs running. 

Wayne.






___ 
New Yahoo! Mail is the ultimate force in competitive emailing. Find out more at 
the Yahoo! Mail Championships. Plus: play games and win prizes. 
http://uk.rd.yahoo.com/evt=44106/*http://mail.yahoo.net/uk 
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Global values & import scope

2007-01-24 Thread Wesley Brooks
Dear Users,

I'm using global values to create a unique ID, or name for each
instance of a class. If I import the following in one file and test it
it works fine. If the following class was imported in two different
files run by the same program would each instance of the class have a
unique name, or would they only be unique within the scope of the file
which contains the import of the bellow class?

itemID = 0
class AssemblyItem:
def __init__(self):
global itemID
self.ID = "assemblyItem" + str(itemID)
itemID += 1

Thanks for any help,

Yours Faithfully,

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


Re: [Tutor] Global values & import scope

2007-01-24 Thread Luke Paireepinart
Wesley Brooks wrote:
> Dear Users,
>
> I'm using global values to create a unique ID, or name for each
> instance of a class. If I import the following in one file and test it
> it works fine. If the following class was imported in two different
> files run by the same program would each instance of the class have a
> unique name, or would they only be unique within the scope of the file
> which contains the import of the bellow class?
>   
I believe that, if your program is importing 2 other packages, each of 
which import some other package,
that other doubly-imported package will only be executed once, by 
whichever one you import first.
> itemID = 0
> class AssemblyItem:
> def __init__(self):
> global itemID
> self.ID = "assemblyItem" + str(itemID)
> itemID += 1
>   
I'm 99% sure you can accomplish the same thing with a variable that is 
global to all instances of the class.
something like (may not work):

class Foo:
itemID = 0
def __init__(self):
itemID += 1

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


Re: [Tutor] Difference between filter and map

2007-01-24 Thread Kent Johnson
vanam wrote:
> Yes i did a mistake in expressing my problem below are the instances of 
> the script and its corresponding output,for each instance its giving 
> contrasting result i want explanation for that

This has pretty much been explained already. Do you have some question 
with the explanation?

> [1]:def squ(n):
>return n*n
>  filter(squ,range(3))>output is not seen on the interpreter
>  map(squ,range(3))->output  not seen on the interpreter
> print filter(squ,range(3))->output is [1,2]
> print map(squ,range(3))-->output is [0,1,4]
> 
> [2]:def squ(n):
>   y = n*n
>   print y
>   filter(squ,range(3))-->Below is the output

Note that in a script, the results of function calls are not printed 
unless you explicitly ask for it with a print statement. So the output 
here is from the "print y" in squ(), it is not the result of filter().

>   0
>   1
>   4
>   map(squ,range(3))-->Below is the output
>   0
>   1
>   4

Again, this is just the output from "print y"

>   print filter(squ,range(3))--->Below is the output
>   0
>   1
>   4

This is the result from filter():
>   []
>   print map(squ,range(3))-->Below is the output
>   0
>   1
>   4

This is the result from map():
>   [None,None,None]
> I want to know why in each case its giving different results and diff 
> between filter and map

Please reread the previous replies, all of this is explained.

Kent

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


Re: [Tutor] OOP - have I done it right or could it be better?

2007-01-24 Thread Kent Johnson
Original Brownster wrote:
> --- Kent Johnson <[EMAIL PROTECTED]> wrote:
>> This all sounds good. You have a module, Streamrip, that implements
>> the 
>> core functionality you need. From your description, this module
>> doesn't 
>> know about the GUI so it could be reused by another kind of client, 
>> tested, etc. You also have a module that implements a GUI front-end
>> to 
>> Streamrip. All good. Just make sure the Streamrip module doesn't know
>>
>> anything about the Windowapp module - keep the dependencies one-way.
> 
> That's good then as that's how it works, it looks like I'll be adding a
> command line interface too as I am thinking this and cron will be a
> good way to schedule jobs. With the modular approach it means I'll
> pretty much not have to touch the core functionality routines.

Exactly the point. You might need to add or modify functionality for new 
requirements but the core should be easily reusable.

Kent

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


Re: [Tutor] Difference between filter and map

2007-01-24 Thread Alan Gauld

"vanam" <[EMAIL PROTECTED]> wrote

> Yes i did a mistake in expressing my problem below are the instances 
> of the
> script and its corresponding output,for each instance its giving 
> contrasting
> result i want explanation for that
> [1]:def squ(n):
>   return n*n

> filter(squ,range(3))>output is not seen on the interpreter
> map(squ,range(3))->output  not seen on the interpreter

I don;t know why you aren't seeing the output, I would expect
more or less the same output as the next two lines.
What tool are you using? Is it IDLE or something else?

> print filter(squ,range(3))->output is [1,2]
> print map(squ,range(3))-->output is [0,1,4]

The first one returns the actual items from the list where
squ(item) evaluates to Ture,  ie non zero. The first item (0)
squared is zero so it is not included - it is filtered out, leaving
1 and 2 as the only output.

The second one returns the result of passing each item
through squ()each item. So you get 0,1,4 which are the
squares of 0,1,2

> [2]:def squ(n):
>  y = n*n
>  print y

This function prrints the values then returns None (Python's
default return value) which is equivalent to False in a boolean
context.

>  filter(squ,range(3))-->Below is the output
>  0
>  1
>  4

filter applies squ to each item. squ prints the square.
filter then returns an empty list since squ always returns
None, which is false, so all items are filtered out.
Why it is not printed by the interpreter I don't know.

>  map(squ,range(3))-->Below is the output
>  0
>  1
>  4

As above but this time map returns a list of 3 Nones.
Why it is not printed I don't know.

>  print filter(squ,range(3))--->Below is the output
>  0
>  1
>  4
>  []
>  print map(squ,range(3))-->Below is the output
>  0
>  1
>  4
>  [None,None,None]

Exactly as above except the output from the functions is
actually being printed.


> I want to know why in each case its giving different results and 
> diff
> between filter and map

Hopefully my explanation has made that clear.
Why the versions without print do not display the result of the
functions is a mystery.

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] Python Branches

2007-01-24 Thread Kent Johnson
vanam wrote:
> 
> i started slowly learning python as i dont have much exposure to it and  
> i wanted to know what are all branches there in python actually i 
> installed py 2.5 recently i come across question in groups about the gui 
> where in pygtk should be installed.My question is without this 
> installation could i able to develop any application using py2.5?One 
> more thing is what is tkinter?Can  any one explain what are all branches 
> in python and how it could be used?

You need to install pygtk if you want to develop applications that use 
the GTK GUI toolkit.

I don't know what you mean by "branches", can you explain?

Kent

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


Re: [Tutor] Global values & import scope

2007-01-24 Thread Kent Johnson
Luke Paireepinart wrote:
> I believe that, if your program is importing 2 other packages, each of 
> which import some other package,
> that other doubly-imported package will only be executed once, by 
> whichever one you import first.

Yes, that's right.

>> itemID = 0
>> class AssemblyItem:
>> def __init__(self):
>> global itemID
>> self.ID = "assemblyItem" + str(itemID)
>> itemID += 1
>>   
> I'm 99% sure you can accomplish the same thing with a variable that is 
> global to all instances of the class.
> something like (may not work):
> 
> class Foo:
> itemID = 0
> def __init__(self):
> itemID += 1

That should be Foo.itemID += 1; the class namespace is not part of the 
default name search path.

Kent

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


Re: [Tutor] Global values & import scope

2007-01-24 Thread Kent Johnson
Wesley Brooks wrote:
> Dear Users,
> 
> I'm using global values to create a unique ID, or name for each
> instance of a class. If I import the following in one file and test it
> it works fine. If the following class was imported in two different
> files run by the same program would each instance of the class have a
> unique name, or would they only be unique within the scope of the file
> which contains the import of the bellow class?
> 
> itemID = 0
> class AssemblyItem:
> def __init__(self):
> global itemID
> self.ID = "assemblyItem" + str(itemID)
> itemID += 1

That will work fine. When a module is imported twice, the second import 
received a cached copy of the same module; the module is only 
instantiated once. The variable itemID will just exist in one place, in 
the single instance of the module, and AssemblyItems created from 
different clients will all share the same counter.

Kent

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


Re: [Tutor] Python Branches

2007-01-24 Thread Alan Gauld

"vanam" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
>i started slowly learning python as i dont have much exposure to it 
>and  i
> wanted to know what are all branches there in python

I assume by branches you mean all the different libraries available?
Thats difficult to answer because there are literally hundreds if not
thousands available. Anything not in the core release will need to
be synchronised with the core release before you can use it. Thus
a library built for version 2.4 may need slight modification before
it can be used in version 2.5. That is the responsibility of the
library author. (Or if its open source you might try doing it
yourself!)

> 2.5 recently i come across question in groups about the gui where in 
> pygtk
> should be installed.

That will also usually depend on the author of the library.
They normally provide an installation script that puts it in
the right place for your platform.

> My question is without this installation could i able to
> develop any application using py2.5?

You can develop standard Python applications but you
couldn't develop anything using pygtk until you install it.

> One more thing is what is tkinter?

Tkinter is the standard GUI toolkit library for Python.
It is based on the Tcl/Tk toolkit and as such is not particularly
modern in appearance, but it is widely supported, well documented
and fairly easy to use and extend. pygtk is a similar library based
on the GTk GUI toolit.

The other two popular GUI libraries for Python are wxPython
and pyQT.

If that doesn't answer your questions can you be more
specific, possibly with more examples?

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


[Tutor] Python code to connect using PPPoE

2007-01-24 Thread Johan Geldenhuys
Hi all,
 
I don't know if this the right place to ask the question, but I did some
Googling and struggled to get decent examples of code to use for PPPoE
connection.
 
I have a wireless modem that uses PPPoE to connect and want to use Python to
connect to the internet through this modem using PPPoE.
 
Does anybody know where I can get something like this? Is it in Twisted or
is there possibly a "cleaner" example of this?
 
Thanks 
 
Johan

-- 
No virus found in this outgoing message.
Checked by AVG Free Edition.
Version: 7.5.432 / Virus Database: 268.17.8/649 - Release Date: 2007/01/23
08:40 PM
 
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Python code to connect using PPPoE

2007-01-24 Thread Kent Johnson
Johan Geldenhuys wrote:
> Hi all,
>  
> I don't know if this the right place to ask the question, but I did some 
> Googling and struggled to get decent examples of code to use for PPPoE 
> connection.
>  
> I have a wireless modem that uses PPPoE to connect and want to use 
> Python to connect to the internet through this modem using PPPoE.
>  
> Does anybody know where I can get something like this? Is it in Twisted 
> or is there possibly a "cleaner" example of this?

I'm not too sure what you want to do. Are you trying to use Python to 
establish the connection, or do you want to access the internet over an 
established connection?

If it is the former, I don't have an answer for you. For the latter, 
check out urllib, urllib2, httplib, etc.

Kent

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


Re: [Tutor] Python code to connect using PPPoE

2007-01-24 Thread Johan Geldenhuys
Kent,
I want to establish the connection with Python. I think in Linux you can use
a PPPoE package to make life easier, but I don't want to use the Kernel to
do that.

Johan 

-Original Message-
From: Kent Johnson [mailto:[EMAIL PROTECTED] 
Sent: 24 January 2007 03:52 PM
To: [EMAIL PROTECTED]
Cc: tutor@python.org
Subject: Re: [Tutor] Python code to connect using PPPoE

Johan Geldenhuys wrote:
> Hi all,
>  
> I don't know if this the right place to ask the question, but I did 
> some Googling and struggled to get decent examples of code to use for 
> PPPoE connection.
>  
> I have a wireless modem that uses PPPoE to connect and want to use 
> Python to connect to the internet through this modem using PPPoE.
>  
> Does anybody know where I can get something like this? Is it in 
> Twisted or is there possibly a "cleaner" example of this?

I'm not too sure what you want to do. Are you trying to use Python to
establish the connection, or do you want to access the internet over an
established connection?

If it is the former, I don't have an answer for you. For the latter, check
out urllib, urllib2, httplib, etc.

Kent

--
No virus found in this incoming message.
Checked by AVG Free Edition.
Version: 7.5.432 / Virus Database: 268.17.8/649 - Release Date: 2007/01/23
08:40 PM
 

-- 
No virus found in this outgoing message.
Checked by AVG Free Edition.
Version: 7.5.432 / Virus Database: 268.17.8/649 - Release Date: 2007/01/23
08:40 PM
 

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


Re: [Tutor] Global values & import scope

2007-01-24 Thread Wesley Brooks
Thanks for your help I tested what you two said as follows and it
worked great. Thank you.

(Bellow in file TEST_ClassID.py)
class AssemblyItem:
itemID = 0
def __init__(self):
self.ID = "assemblyItem" + str(AssemblyItem.itemID)
AssemblyItem.itemID += 1

def ReturnID(self):
return self.ID

(Bellow in file TEST_ImportID1.py)
from TEST_ClassID import AssemblyItem

class Parent1:
def __init__(self):
self.testList = []

def PrintID(self):
self.testList.append(AssemblyItem())
print self.testList[-1].ReturnID()

(Bellow in file TEST_ImportID2.py)
from TEST_ClassID import AssemblyItem

class Parent2:
def __init__(self):
self.testList = []

def PrintID(self):
self.testList.append(AssemblyItem())
print self.testList[-1].ReturnID()

(Bellow, the commands run in the python terminal in the same directory)
>>> from TEST_ClassID1 import Parent1
>>>from TEST_ClassID2 import Parent2
>>>a = Parent1()
>>>b = Parent2()
>>>a.PrintID()
assemblyItem0
>>>a.PrintID()
assemblyItem1
>>>b.PrintID()
assemblyItem2
>>>b.PrintID()
assemblyItem3
>>>a.PrintID()
assemblyItem4
>>>b.PrintID()
assemblyItem5

Thanks again for your help.

Wesley Brooks.


On 24/01/07, Kent Johnson <[EMAIL PROTECTED]> wrote:
> Wesley Brooks wrote:
> > Dear Users,
> >
> > I'm using global values to create a unique ID, or name for each
> > instance of a class. If I import the following in one file and test it
> > it works fine. If the following class was imported in two different
> > files run by the same program would each instance of the class have a
> > unique name, or would they only be unique within the scope of the file
> > which contains the import of the bellow class?
> >
> > itemID = 0
> > class AssemblyItem:
> > def __init__(self):
> > global itemID
> > self.ID = "assemblyItem" + str(itemID)
> > itemID += 1
>
> That will work fine. When a module is imported twice, the second import
> received a cached copy of the same module; the module is only
> instantiated once. The variable itemID will just exist in one place, in
> the single instance of the module, and AssemblyItems created from
> different clients will all share the same counter.
>
> Kent
>
>
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Global values & import scope

2007-01-24 Thread Kent Johnson
Wesley Brooks wrote:
> Thanks for your help I tested what you two said as follows and it
> worked great. Thank you.
> 
> (Bellow in file TEST_ClassID.py)
> class AssemblyItem:
> itemID = 0
> def __init__(self):
> self.ID = "assemblyItem" + str(AssemblyItem.itemID)
> AssemblyItem.itemID += 1
> 
> def ReturnID(self):
> return self.ID
> 
> (Bellow in file TEST_ImportID1.py)
> from TEST_ClassID import AssemblyItem
> 
> class Parent1:
> def __init__(self):
> self.testList = []
> 
> def PrintID(self):
> self.testList.append(AssemblyItem())
> print self.testList[-1].ReturnID()

That's a bit convoluted if all you are trying to do is test 
AssemblyItem. You could just write

from TEST_ClassID import AssemblyItem

def printID():
item = AssemblyItem()
print tem.ReturnID()

or even

def printID():
print AssemblyItem().ReturnID()

Kent

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


Re: [Tutor] Python code to connect using PPPoE

2007-01-24 Thread Kent Johnson
Johan Geldenhuys wrote:
> Kent,
> I want to establish the connection with Python. I think in Linux you can use
> a PPPoE package to make life easier, but I don't want to use the Kernel to
> do that.

If you are on Linux, maybe you can use os.command() to control rp-pppoe.
http://www.roaringpenguin.com/penguin/openSourceProducts/rpPppoe

If you are on Windows maybe win32ras does what you want?

Kent

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


Re: [Tutor] Python code to connect using PPPoE

2007-01-24 Thread Johan Geldenhuys
Is there a module that I can use for this or is it a "os" function?

Johan

-Original Message-
From: Kent Johnson [mailto:[EMAIL PROTECTED] 
Sent: 24 January 2007 04:39 PM
To: [EMAIL PROTECTED]
Cc: tutor@python.org
Subject: Re: [Tutor] Python code to connect using PPPoE

Johan Geldenhuys wrote:
> Kent,
> I want to establish the connection with Python. I think in Linux you 
> can use a PPPoE package to make life easier, but I don't want to use 
> the Kernel to do that.

If you are on Linux, maybe you can use os.command() to control rp-pppoe.
http://www.roaringpenguin.com/penguin/openSourceProducts/rpPppoe

If you are on Windows maybe win32ras does what you want?

Kent

--
No virus found in this incoming message.
Checked by AVG Free Edition.
Version: 7.5.432 / Virus Database: 268.17.8/649 - Release Date: 2007/01/23
08:40 PM
 

-- 
No virus found in this outgoing message.
Checked by AVG Free Edition.
Version: 7.5.432 / Virus Database: 268.17.8/649 - Release Date: 2007/01/23
08:40 PM
 

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


Re: [Tutor] Python code to connect using PPPoE

2007-01-24 Thread Kent Johnson
Johan Geldenhuys wrote:
> Is there a module that I can use for this or is it a "os" function?

I haven't found any module for Linux.

Kent

> 
> Johan
> 
> -Original Message-
> From: Kent Johnson [mailto:[EMAIL PROTECTED] 
> Sent: 24 January 2007 04:39 PM
> To: [EMAIL PROTECTED]
> Cc: tutor@python.org
> Subject: Re: [Tutor] Python code to connect using PPPoE
> 
> Johan Geldenhuys wrote:
>> Kent,
>> I want to establish the connection with Python. I think in Linux you 
>> can use a PPPoE package to make life easier, but I don't want to use 
>> the Kernel to do that.
> 
> If you are on Linux, maybe you can use os.command() to control rp-pppoe.
> http://www.roaringpenguin.com/penguin/openSourceProducts/rpPppoe
> 
> If you are on Windows maybe win32ras does what you want?
> 
> Kent
> 
> --
> No virus found in this incoming message.
> Checked by AVG Free Edition.
> Version: 7.5.432 / Virus Database: 268.17.8/649 - Release Date: 2007/01/23
> 08:40 PM
>  
> 


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


Re: [Tutor] metaclass question

2007-01-24 Thread Kent Johnson
Kim Branson wrote:
> Hi,
> 
> what i've ended up doing is the following
> 
> define a EmpiricalScore class that has all the methods for computing  
> results
> 
> define a single method in  the evaluation class that is called   
> Score. This method simply walks though a list and executes the  
> methods in that list. There may be one or many.
> 
> 
>  def score(self):
>  """
>  this function computes the interaction energy and returns a
>  dict of key=value pairs for the scoring functions requested
>  """
>  for x in self.functionList:
>  x()
>  return(self.scoreResults)

That looks fine, presumably the functions in functionList affect 
scoreResults...
> 
> The factory class takes as agument some input data and determine  
> which of the methods in the Evaluation class should be called.
> it then produces an instance of the EmpiricalScore class,   (called  
> scoreObject,) and then append the methods from that instance to its  
> internal list.
> 
>  scoreObject=EmpiricalScore()
> 
>  #for each valid scoring function in the functions
>  #tuple we call the method which adds the attribute
>  for x in self.functionsToUse:
>  #we need to check if we want both smog and smogh
>  if x == "smog":
>  if bothSmog == True:
>  continue
>  for y in self.functionsToUse:
>  if y == "smog_h":
>  scoreObject.functionList.append 
> (scoreObject.calBothSmog)

This could be much simpler:
if "smog" in self.functionsToUse and "smog_h" in self.functionsToUse:
   scoreObject.functionList.append(scoreObject.calBothSmog)
> 
> This is possibly not the best way to approach this, the factory class  
> is possibly not required and could be added to the  EmpiricalScore  
> class. I think its probably better to separate these to keep things  
> clean.  

 From what you have said I don't see any need for a factory class, it 
sounds like it could be a factory function. You could also put the 
initialization into the EmpiricalScore constructor and just pass the 
list of functions to use to the constructor instead of the factory function.

> In a way this method is constructing a decorator for the  
> EmpiricalScore.score  method.  Is there a way of appending a method  
> to the class after it is initialized.

Yes, you can add a method to a class easily:

In [1]: class Foo(object): pass
...:

In [2]: def sayHello(self):
...: print 'Hello'
...:

In [3]: f = Foo()

In [4]: f.sayHello()

Traceback (most recent call last):
   File "", line 1, in 
: 'Foo' object has no attribute 'sayHello'


In [5]: Foo.sayHello = sayHello

In [6]: f.sayHello()
Hello

However I think you actually want to add a method to an instance, not to 
the class. But the way you have it seems pretty simple.

> Or adding decorators to the  
> method after it is defined?

Yes, you can re-assign a new value to a method which is basically what a 
decorator does. But again it sounds like you want to complicate a clean, 
simple design.

Kent

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


[Tutor] Python connecting to an exchange server

2007-01-24 Thread Jalil

I just wanted to know if its possible or if anyone can point me to a place
where I can get info on howto to get  python to talk to an MS exchange
server.
I would basically want the python code to  parse  the appointsments  in my
outlook calendar.


Is this possible?


Thank You
--
Shoot for the moon. Even if you miss, you'll land among the stars.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Python connecting to an exchange server

2007-01-24 Thread Ted Roche
On 1/24/07, Jalil <[EMAIL PROTECTED]> wrote:
>
> I would basically want the python code to  parse  the appointsments  in my
> outlook calendar.
>

Then it's most likely you don't want to talk to exchange at all, but
rather talk with Outlook. Outlook supports a COM Automation interface
and you can use it to do most of the things Outlooks does via the GUI,
although some of them are rather difficult. An example of COM
Automation with Outlook and Python can be found:

http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/266625

A paper on COM Automation and Outlook I wrote some time ago (in a
different programming language) has some pretty good references at the
end:

http://www.tedroche.com/Present/2003/OutlookAutomation.html

-- 
Ted Roche
Ted Roche & Associates, LLC
http://www.tedroche.com
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Cause-Effect, Isikawa, fishbone diagram

2007-01-24 Thread János Juhász
Dear All,

does someone know any python based solution to draw a 
cause-effect diagram into PDF from a simple textfile ?

It is also called a Fishbone Diagram, because of its shape, 
or an Ishikawa Chart, after its originator, Kaoru Ishikawa
I feel, it can be converted from a structure like this.

Title
Effect
  Cause1
Secundary
  Tertiary
  Tertiary
  Cause2
Secundary
  Tertiary
  Cause3
Secundary
  Tertiary

It is probably a simple function.



Yours sincerely,
__
Janos Juhasz
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Tracking time

2007-01-24 Thread Michael Key
I am trying to develop a project tracking program that would allow you to track 
hours and minutes spent on several different projects and store he data in a 
database for printing. Any help would be appreciated.
 
Mike___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Tracking time

2007-01-24 Thread Luke Paireepinart
Michael Key wrote:
> I am trying to develop a project tracking program that would allow you 
> to track hours and minutes spent on several different projects and 
> store he data in a database for printing. Any help would be appreciated.
You could store the start time using the time module.
when they're done with whatever you're timing,
get the current time again.
The difference between these two times is how long it took them to 
complete the task.
Decide on a database (oracle, postgre, mysql) and get the python library 
that lets you interface with your database and learn how to use it.
It's unclear what exactly a 'project' is from your e-mail so my reply is 
similarly vague, sorry.

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


[Tutor] Send binary/hex data to a TCP socket

2007-01-24 Thread Tod Haren
I need to send a server at the other end of a socket a 36 byte
"frame", where each byte represents a specific field in the custom
data structure.(If there are any Ham operators reading this, I'm
talking about the AGW Packet Engine)

The documentation for the server says to initialize each field to a
binary zero(0x00).  How do I get a binary zero in Python?  The next
step is to send this all to the server and subsequently receive a
similarly formated frame.

A very basic frame looks something like this(modified from documentation):

|00 00 00 00 4D 00 00 00 00 00 00 00 00 00 00 00 |M...
|00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |
|00 00 00 00 |

My problem is that hex(0) return '0x0' and hex(ord('M')) returns
'0x4d'.  If I concatonate these all together then the socket receives
109 bytes instead of 36.  The documentation examples are in C++, so
they are little help to me.  The examples make use of the MoveMemory
function for building the frames, but I'm clueless what that does.

Pseudo code for the frame above:

  l = []
  for i in xrange(36):
l.append(hex(0))

  l[4]=hex(ord('M'))

  d=''
  d=d.join(l)  #I need some other data type to send besides a string!
  sock.send(d)  #send the 36 bytes to the socket

Any pointers or references would be greatly appreciated.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Send binary/hex data to a TCP socket

2007-01-24 Thread Adam Bark

On 25/01/07, Tod Haren <[EMAIL PROTECTED]> wrote:


I need to send a server at the other end of a socket a 36 byte
"frame", where each byte represents a specific field in the custom
data structure.(If there are any Ham operators reading this, I'm
talking about the AGW Packet Engine)

The documentation for the server says to initialize each field to a
binary zero(0x00).  How do I get a binary zero in Python?  The next
step is to send this all to the server and subsequently receive a
similarly formated frame.

A very basic frame looks something like this(modified from documentation):

|00 00 00 00 4D 00 00 00 00 00 00 00 00 00 00 00 |M...
|00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |
|00 00 00 00 |

My problem is that hex(0) return '0x0' and hex(ord('M')) returns
'0x4d'.  If I concatonate these all together then the socket receives
109 bytes instead of 36.  The documentation examples are in C++, so
they are little help to me.  The examples make use of the MoveMemory
function for building the frames, but I'm clueless what that does.

Pseudo code for the frame above:

  l = []
  for i in xrange(36):
l.append(hex(0))

  l[4]=hex(ord('M'))

  d=''
  d=d.join(l)  #I need some other data type to send besides a string!
  sock.send(d)  #send the 36 bytes to the socket

Any pointers or references would be greatly appreciated.



This should do what you need:
http://docs.python.org/lib/module-struct.html
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Best IDE for Python

2007-01-24 Thread Shadab Sayani
Hi,
  I am using vim editor to code my project in python.Is there a good  IDE  
where in I type the name of the class object and then dot  then all the 
attributes of the object are displayed so on.I tried to  install IDLE but I 
have no idea how to install tkinter?
  Any help that enables me to use good IDE as soon as possible is appreciated
  Thanks and Regards,
  Shadab
  
 Send instant messages to your online friends http://uk.messenger.yahoo.com ___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Optimal solution in dealing with huge databases in python

2007-01-24 Thread Shadab Sayani
Hi,
  I am working in a biodatabases project.The data I need to deal with is  in 
100s of GB.I am using postgresql backend and SQLALCHEMY ORM.I need  to read the 
bio datafiles and parse them and then store them in  database.I am in the 
process of storing them.
  I used the session,flush concept in SQLALCHEMY.Initially I used to  flush 
every query immediately.Later I realised that the queries are  independent of 
each other and so started flushing 3-5 Lakh insert  queries at a time.This 
increased the response time.But the memory is  overflowing.Then I released 
not-in-use memory using del command in  python still there is no use as this 
del statement can only free part  of memory.I need to increase the above 3-5 
lakh number to a much large  one to get a real time response.Other wise my 
estimation is it will  take 1 year to just insert the data into the 
database.From postgresql  side also I turned off WAL.
  Please suggest some viable solution to handle such enormous data from  
python.Is there a better solution than SQL alchemy?Any solution that  speeds up 
my program is highly appreciated.
  Thanks and Regards,
  Shadab.
  
 Send instant messages to your online friends http://uk.messenger.yahoo.com ___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Tracking time

2007-01-24 Thread johnf
On Wednesday 24 January 2007 14:34, Michael Key wrote:
> I am trying to develop a project tracking program that would allow you to
> track hours and minutes spent on several different projects and store he
> data in a database for printing. Any help would be appreciated.
>
> Mike

Take a good look at Dabo @ www.dabodev.com
Check out the latest screencast.  Dabo was designed from bottom to support 
database and GUI apps.
-- 
John Fabiani
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Best IDE for Python

2007-01-24 Thread Dick Moores
At 07:12 PM 1/24/2007, Shadab Sayani wrote:
>Hi,
>I am using vim editor to code my project in python.Is there a good 
>IDE  where in I type the name of the class object and then dot then 
>all the attributes of the object are displayed so on.

I believe IPython does this. Check out .

Dick Moores



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


[Tutor] Python re without string consumption

2007-01-24 Thread Jacob Abraham
Dear Tutors,

   I'm having a little trouble while using the re module.

eg

>>> import re
>>> re.findall("abca", "abcabcabca")
["abca", "abca"]

While I am expecting.

["abca", "abca", "abca"]

How do I modify my regular expression to do the same.

Thanks for the help.

Regards,
Jacob Abraham




 

Never miss an email again!
Yahoo! Toolbar alerts you the instant new Mail arrives.
http://tools.search.yahoo.com/toolbar/features/mail/
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Python re without string consumption

2007-01-24 Thread Danny Yoo


On Wed, 24 Jan 2007, Jacob Abraham wrote:

 import re
 re.findall("abca", "abcabcabca")
> ["abca", "abca"]
>
> While I am expecting.
>
> ["abca", "abca", "abca"]


Hi Jacob,

Just to make sure: do you understand, though, why findall() won't give you 
the results you want?  The documentation on findall() says:

""" Return a list of all non-overlapping matches of pattern in string. If 
one or more groups are present in the pattern, return a list of groups; 
this will be a list of tuples if the pattern has more than one group. 
Empty matches are included in the result unless they touch the beginning 
of another match. New in version 1.5.2. Changed in version 2.4: Added the 
optional flags argument. """

It's designed not to return overlapping items.



> How do I modify my regular expression to do the same.

We can just write our own helper function to restart the match.  That is, 
we can expliciltely call search() ourselves, and pass in a new string 
that's a fragment of the old one.


Concretely,

#
>>> import re
>>> text = "abcabcabca"
>>> re.search("abca", text)
<_sre.SRE_Match object at 0x50d40>
>>> re.search("abca", text).start()
0
#

Ok, so we know the first match starts at 0.  So let's just restart the 
search, skipping that position.

##
>>> re.search("abca", text[1:])
<_sre.SRE_Match object at 0x785d0>
>>> re.search("abca", text[1:]).start()
2
##

There's our second match.  Let's continue.  We have to be careful, though, 
to make sure we're skipping the right number of characters:

###
>>> re.search("abca", text[4:]).start()
2
>>> re.search("abca", text[7:])
>>> 
###

And there are no matches after this point.


You can try writing this helper function yourself.  If you need help doing 
so, please feel free to ask the list for suggestions.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Python re without string consumption

2007-01-24 Thread Jacob Abraham
Hi Danny Yoo,

   I would like to thank you for the solution and the helper funtion that I 
have written is as follows. But I do hope that future versions of Python 
include a regular expression syntax to handle such cases simply because this 
method seems very process and memory intensive. I also notice that 
fall_back_len is a very crude solution.

def searchall(expr, text, fall_back_len=0):

while True:

match =  re.search(expr, text)

if not match:

break

yield match

end = match.end()

text = text[end-fallbacklen:]



for match in searchall("abca", "abcabcabca", 1):

   print match.group()

Thanks Again.

Jacob Abraham





- Original Message 
From: Danny Yoo <[EMAIL PROTECTED]>
To: Jacob Abraham <[EMAIL PROTECTED]>
Cc: python 
Sent: Thursday, January 25, 2007 12:14:31 PM
Subject: Re: [Tutor] Python re without string consumption



On Wed, 24 Jan 2007, Jacob Abraham wrote:

 import re
 re.findall("abca", "abcabcabca")
> ["abca", "abca"]
>
> While I am expecting.
>
> ["abca", "abca", "abca"]


Hi Jacob,

Just to make sure: do you understand, though, why findall() won't give you 
the results you want?  The documentation on findall() says:

""" Return a list of all non-overlapping matches of pattern in string. If 
one or more groups are present in the pattern, return a list of groups; 
this will be a list of tuples if the pattern has more than one group. 
Empty matches are included in the result unless they touch the beginning 
of another match. New in version 1.5.2. Changed in version 2.4: Added the 
optional flags argument. """

It's designed not to return overlapping items.



> How do I modify my regular expression to do the same.

We can just write our own helper function to restart the match.  That is, 
we can expliciltely call search() ourselves, and pass in a new string 
that's a fragment of the old one.


Concretely,

#
>>> import re
>>> text = "abcabcabca"
>>> re.search("abca", text)
<_sre.SRE_Match object at 0x50d40>
>>> re.search("abca", text).start()
0
#

Ok, so we know the first match starts at 0.  So let's just restart the 
search, skipping that position.

##
>>> re.search("abca", text[1:])
<_sre.SRE_Match object at 0x785d0>
>>> re.search("abca", text[1:]).start()
2
##

There's our second match.  Let's continue.  We have to be careful, though, 
to make sure we're skipping the right number of characters:

###
>>> re.search("abca", text[4:]).start()
2
>>> re.search("abca", text[7:])
>>> 
###

And there are no matches after this point.


You can try writing this helper function yourself.  If you need help doing 
so, please feel free to ask the list for suggestions.





 

Do you Yahoo!?
Everyone is raving about the all-new Yahoo! Mail beta.
http://new.mail.yahoo.com
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Python re without string consumption

2007-01-24 Thread Luke Paireepinart

>
> def searchall(expr, text, fall_back_len=0):
> [snip]
>
> text = text[end-fallbacklen:]
oops, those look like two different variables to me.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor