[Tutor] suggestion for group project

2004-12-17 Thread Brian van den Broek
Hi all,
A while ago, in a response:
Danny Yoo said unto the world upon 2004-11-29 17:14:
I just got in contact with Nick Parlante of the Nifty Assignments
project; he's been collecting material on fun projects:
http://nifty.stanford.edu/
The projects there look pretty nice.  In fact, I'm thinking of
adapting material on that page for us here on Python-Tutor.
Is there a particular project that sounds interesting to folks? 
Personally, I'm interested in:

http://nifty.stanford.edu/catandmouse/html/
But that's only because I helped tutor it back when I was at
Berkeley's Self-Paced Center...  *grin* But if people want, I'd be
happy to convert Professor Clancy's support code from C++ to Python.

I've got a suggestion: would there be any interest among list members in 
picking one of the assignments, working on it, and then doing a code 
comparison/critique?

When Danny posted, I did . 
I thought about posting what I had done to the list and inviting such 
comment/criticism, but was dissuaded by two things: 1) once I'd got my 
code to a reasonable polish, with docstrings and all, it seemed a bit 
long to just plunk onto the list, and, 2) I suspect much of the 
interest, fun, and learning might well emerge from having a go at the 
task and then seeing what others came up with. If I posted mine 
unannounced, others wouldn't have the chance to go at the problem fresh.

What do others think?
I wonder if the length of code, the possible undesirability of a bunch 
of answers to a collection of homework problems getting posted, and 
other considerations might make this better as an off-list endeavour. 
I'd be interested in doing it either here or on private channels. (If 
there was interest and we opt for private, I could probably get my uni 
to let me set up an unarchived listserv for the purpose.)

Best to all,
Brian vdB
___
Tutor maillist  -  [EMAIL PROTECTED]
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] "TypeError: 'int' object is not callable"??

2004-12-17 Thread Kent Johnson
Jacob S. wrote:
Ha! That's what I was looking for! The builtin apply function! The only way
I could send the *args to the function was through a list, and function
calls see a list as one argument. The apply argument doesn't! Thanks Bob.
apply() is deprecated; it has been replaced by 'extended call syntax'. 
Instead of
  apply(fn, args, kwds)
you can now write
  fn(*args, **kwds)
Kent
___
Tutor maillist  -  [EMAIL PROTECTED]
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] dbcp module

2004-12-17 Thread Kent Johnson
Please describe what you are looking for. A python version of the Jakarta 
Database Connection Pool?
Kent
Rene Bourgoin wrote:
Yah i came across that site and was trying to learn from that code.
I just cant seem to find a download for a python version.

i came across this site while searching.

http://jakarta.apache.org/






 --- On Wed 12/15, Kent Johnson < [EMAIL PROTECTED] > wrote:
From: Kent Johnson [mailto: [EMAIL PROTECTED]
To: 

 Cc: [EMAIL PROTECTED]
Date: Wed, 15 Dec 2004 20:19:22 -0500
Subject: Re: [Tutor] dbcp module

Googling for 'python dbcp' turns up this recipe, is this what you are looking for?http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/81189KentRene Bourgoin wrote:> Anyone know where I can 
download the dbcp module for Python> > > > > > > ___> No banners. No pop-ups. No kidding.> Make My 
Way your home on the Web - http://www.myway.com> ___> Tutor maillist  -  [EMAIL PROTECTED]> http://mail.python.org/mailman/listinfo/tutor> 
___Tutor maillist  -  [EMAIL PROTECTED]http://mail.python.org/mailman/listinfo/tutor
___
No banners. No pop-ups. No kidding.
Make My Way your home on the Web - http://www.myway.com
___
Tutor maillist  -  [EMAIL PROTECTED]
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Nifty

2004-12-17 Thread Matt Williams
I'd be interested,

Matt
On Fri, 2004-12-17 at 11:01, [EMAIL PROTECTED] wrote:
> Send Tutor mailing list submissions to
>   [EMAIL PROTECTED]
> 
> To subscribe or unsubscribe via the World Wide Web, visit
>   http://mail.python.org/mailman/listinfo/tutor
> or, via email, send a message with subject or body 'help' to
>   [EMAIL PROTECTED]
> 
> You can reach the person managing the list at
>   [EMAIL PROTECTED]
> 
> When replying, please edit your Subject line so it is more specific
> than "Re: Contents of Tutor digest..."
> 
> 
> Today's Topics:
> 
>1. suggestion for group project (Brian van den Broek)
> 
> 
> --
> 
> Message: 1
> Date: Fri, 17 Dec 2004 05:12:40 -0500
> From: Brian van den Broek <[EMAIL PROTECTED]>
> Subject: [Tutor] suggestion for group project
> To: Tutor <[EMAIL PROTECTED]>
> Message-ID: <[EMAIL PROTECTED]>
> Content-Type: text/plain; charset=ISO-8859-1; format=flowed
> 
> Hi all,
> 
> A while ago, in a response:
> 
> Danny Yoo said unto the world upon 2004-11-29 17:14:
> > 
> > I just got in contact with Nick Parlante of the Nifty Assignments
> > project; he's been collecting material on fun projects:
> > 
> > http://nifty.stanford.edu/
> > 
> > The projects there look pretty nice.  In fact, I'm thinking of
> > adapting material on that page for us here on Python-Tutor.
> > 
> > Is there a particular project that sounds interesting to folks? 
> > Personally, I'm interested in:
> > 
> > http://nifty.stanford.edu/catandmouse/html/
> > 
> > But that's only because I helped tutor it back when I was at
> > Berkeley's Self-Paced Center...  *grin* But if people want, I'd be
> > happy to convert Professor Clancy's support code from C++ to Python.
> 
> 
> I've got a suggestion: would there be any interest among list members in 
> picking one of the assignments, working on it, and then doing a code 
> comparison/critique?
> 
> When Danny posted, I did . 
> I thought about posting what I had done to the list and inviting such 
> comment/criticism, but was dissuaded by two things: 1) once I'd got my 
> code to a reasonable polish, with docstrings and all, it seemed a bit 
> long to just plunk onto the list, and, 2) I suspect much of the 
> interest, fun, and learning might well emerge from having a go at the 
> task and then seeing what others came up with. If I posted mine 
> unannounced, others wouldn't have the chance to go at the problem fresh.
> 
> What do others think?
> 
> I wonder if the length of code, the possible undesirability of a bunch 
> of answers to a collection of homework problems getting posted, and 
> other considerations might make this better as an off-list endeavour. 
> I'd be interested in doing it either here or on private channels. (If 
> there was interest and we opt for private, I could probably get my uni 
> to let me set up an unarchived listserv for the purpose.)
> 
> Best to all,
> 
> Brian vdB
> 
> 
> 
> --
> 
> ___
> Tutor maillist  -  [EMAIL PROTECTED]
> http://mail.python.org/mailman/listinfo/tutor
> 
> 
> End of Tutor Digest, Vol 10, Issue 72
> *

___
Tutor maillist  -  [EMAIL PROTECTED]
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Nifty

2004-12-17 Thread David Broadwell
>> I just got in contact with Nick Parlante of the Nifty
>> Assignments project; he's been collecting material on fun
>> projects:
>>
>> http://nifty.stanford.edu/

> What do others think?
Private channel or not, I'm in. (at least until classes spike up again in
early February) Sounds like a good way to burn through a winter.

Heck I don't even know if I CAN convert C++ to Python but I've never let a
problem like language stop me from playing Chinese chess on boats in china
... So even if I lack the ability, I'm for the idea of having running
'projects' for the tutor list to do. That way it's driven a bit less by
homework problems.

--

Programmer's mantra; Observe, Brainstorm, Prototype, Repeat

David Broadwell

___
Tutor maillist  -  [EMAIL PROTECTED]
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] A little Tkinter question

2004-12-17 Thread Marilyn Davis

On Wed, 15 Dec 2004, Gregor Lingl wrote:

> 
> 
> Marilyn Davis schrieb:
> > Hi Tutors,
> > 
> > I'm reviewing GUIs and wondering:
> > 
> > When you pack a component, and you specify fill = BOTH, how is this
> > different from expand = YES?
> > 
> Hi Marilyn,
> This is a bit tricky and hard to explain, so I recommend playing around 
> with this little program from John Grayson's Tkinter book:
> 
> from Tkinter import *
> 
> class App:
>  def __init__(self, master):
>  master.geometry("300x200")
>  fm = Frame(master)
>  Button(fm, text='Left').pack(side=LEFT, fill=BOTH, expand=1)
>  Button(fm, text='Center').pack(side=LEFT, fill=BOTH, expand=1)
>  Button(fm, text='Right').pack(side=LEFT, fill=BOTH, expand=1)
>  fm.pack(fill=BOTH, expand=YES)
> 
> 
> root = Tk()
> root.option_add('*font', ('verdana', 12, 'bold'))
> root.title("Pack - Example 9")
> display = App(root)
> root.mainloop()
> 
> Modify the three lines with Button().pack(...)
> for instance by setting expand = 0 (which is the default value)
> 
>  Button(fm, text='Left').pack(side=LEFT, fill=BOTH, expand=0)
>  Button(fm, text='Center').pack(side=LEFT, fill=BOTH, expand=0)
>  Button(fm, text='Right').pack(side=LEFT, fill=BOTH, expand=0)
> 
> or by tropping the fill option:
> 
>  Button(fm, text='Left').pack(side=LEFT, expand=1)
>  Button(fm, text='Center').pack(side=LEFT, expand=1)
>  Button(fm, text='Right').pack(side=LEFT, expand=1)
> 
> and so on.
> 
> These Examples are from Chapter 5, several others concerning the packer 
> can be found at:
> 
> https://secure.manning.com/catalog/view.php?book=grayson&item=source

Thanks for the pointer, Gregor.

I guess that the jist of it is that fill fills all available space.
And expand is about what happens to the widget when its master
expands.

But, the bit of the book I was looking at, I'm afraid, I found to be
difficult to follow.  There seemed to be outputs without matching
code, and the numbering system confused me.  And he pointed out the
difference between fill alone and fill with expand and they looked the
same.

I guess you are right.  One needs to experiment to get the desired
effect.

I have no desired effect.  I was just looking for intellectual
understanding.

Thank you.

Marilyn



> 
> Hope this helps
> Gregor
> 
> 
> > Thank you for any insight.
> > 
> > Marilyn Davis
> > 
> > 
> > ___
> > Tutor maillist  -  [EMAIL PROTECTED]
> > http://mail.python.org/mailman/listinfo/tutor
> > 
> > 
> 
> 

-- 

___
Tutor maillist  -  [EMAIL PROTECTED]
http://mail.python.org/mailman/listinfo/tutor


[Tutor] boa constructor font?

2004-12-17 Thread Jeff Peery
my eyes are going bad... anyone know how to change the font size in the editor window of the boa constructor? this seems to be a simple but not easy thing to do. thanks!
 
Jeff___
Tutor maillist  -  [EMAIL PROTECTED]
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Python structure advice ?

2004-12-17 Thread Dave S
Kent Johnson wrote:
Dave S wrote:
Dave S wrote:
The 'remembering where is was' seems a continuous stumbling block 
for me. I have though of coding each module as a class but this 
seems like a cheat. I could declare copious globals, this seems 
messy, I could define each module as a thread & get them talking via 
queues, given this serious thought but heeded warning in previous 
posts. I have thought about returning an list of saved 'pointers' 
which would be re-submitted when the function is called. I don't 
know which way to turn.

Having written this email, it has put my thoughts in order, though it 
seems a bit cheaty, wouldn't defining all modules that have to 
remember their internal state as classes be the best bet ?

Dave

Why do you say this is 'cheaty'? A class is basically a collection of 
data (state) and functions to operate on that state.
Sorry for the delay, real world work got in the way ...
Well I understand classes to be used when multiple instances are 
required, I will only need one instance and as such it seemed a bit of a 
cheat, The trouble is I now pretty well understand the tools, but don't 
know how you guys use them in the real world.

You might be interested in this essay:
http://www.pycs.net/users/323/stories/15.html

I found this particularly usefull,
It might well make sense to organize your program as a collection of 
cooperating classes, or maybe a collection of classes with a top-level 
function that stitches them all together.

Yes, this is the way I see things progressing, from 20,000ft this makes 
a lot of sense.

You might also want to learn about iterator classes and generator 
functions, they are a technique for returning a bit of data at a time 
while maintaining state. You might be able to structure your input 
stage as an iterator or generator.
http://docs.python.org/tut/node11.html#SECTION001190
http://docs.python.org/lib/typeiter.html
I remeber iterators from 'learning python', I was concerned about 
several modules all 'having a iterator' to the next, debuging would be 
scary ! I think I will go the class route.

Kent
___
Tutor maillist  -  [EMAIL PROTECTED]
http://mail.python.org/mailman/listinfo/tutor

___
Tutor maillist  -  [EMAIL PROTECTED]
http://mail.python.org/mailman/listinfo/tutor


RE: [Tutor] least squares

2004-12-17 Thread Danny Yoo


On Thu, 16 Dec 2004, mdcooper wrote:


> I am trying to get a corrolation between a large number of variables and for
> many similar equations :
>(Ca1 * xa^2) + (Ca2 * ya^2) + (Ca3 * za^2) + ... = ta
>(Cb1 * xb^2) + (Cb2 * yb^2) + (Cb3 * zb^2) + ... = tb
>
> which is solved to get:
>(C1 * x^2) + (C2 * y^2) + (C3 * z^2) + ... = t
>
> where the submitted values of x,y, and z should give the correct t
>
> and I am using the code to get C1, C2, C3,  These constants are not
> allowed to be negative and the submitted equations are such that there
> is no reason for the values to be negative, and although a good fit may
> allow them to be negative, another good fit will be found if they are
> all positive.


Hi Matt,


Ok.  I have to admit that my mathematical maturity is actually a little
low, but I'll try to follow along.  But this really doesn't sounds like a
problem specific to Python though, but more of a math problem.

So you may actually want to talk with folks with a real math background; I
would not be mathematically mature enough to know if your code is correct.
I'd strongly recommend talking to folks on the 'sci.math' or
'sci.math.num-analysis' newsgroups.


I haven't seen your code, so I'm still in the dark about how it works or
what its capabilities are.  I'll make a few assumptions that might not be
right, but I have to start somewhere.  *grin*

Does your code provide a way at getting at all possible solutions, or only
one particular solution?  If so, then you can just filter out for
solutions that satisfy the property you want.

For example, we can produce a function that generates all squares in the
world:

###
>>> import itertools
>>> def allSquares():
... for i in itertools.count():
... yield i*i
...
>>> squares = allSquares()
>>> squares.next()
0
>>> squares.next()
1
>>> squares.next()
4
>>> squares.next()
9
>>> squares.next()
16
>>> squares.next()
25
###


I can keep calling 'next()' on my 'squares' iteration, and keep getting
squares.  Even though this can produce an infinite sequence of answers, we
can still apply a filter on this sequence, and pick out the ones that are
"palindromic" in terms of their digits:

###
>>> def palindromic(n):
..."Returns true if n is 'palindromic'."
...return str(n) == str(n)[::-1]
...
>>> filteredSquares = itertools.ifilter(palindromic, allSquares())
>>> filteredSquares.next()
0
>>> filteredSquares.next()
1
>>> filteredSquares.next()
4
>>> filteredSquares.next()
9
>>> filteredSquares.next()
121
>>> filteredSquares.next()
484
>>> filteredSquares.next()
676
###


This sequence-filtering approach takes advantage of Python's ability to
work on a iteration of answers.  If your program can be written to produce
an infinite stream of answers, and if a solution set with all positive
coefficients is inevitable in that stream, then you can take this
filtering approach, and just capture the first solution that matches your
constraints.



Similarly, if your program only produces a single solution, does it do so
through an "iterative" algorithm?  By iterative, I mean: does it start off
with an initial guess and apply a process to improve that guess until the
solution is satisfactory?

For others on the Tutor list, here is an "iterative" way to produce the
square root of a number:

###
def mysqrt(x):
guess = 1.0  ## initial guess
while not goodEnough(guess, x):
guess = improve(guess, x)
return guess

def improve(guess, x):
"""Improves the guess of the square root of x."""
return average(guess, x / guess)

def average(x, y):
return (x + y) / 2.0

def goodEnough(guess, x):
"""Returns true if guess is close enough to the square root of x."""
return abs(guess**2 - x) < 0.1
###

(adapted/ripped off from material in SICP:
http://mitpress.mit.edu/sicp/full-text/book/book-Z-H-10.html#%_sec_1.1.7)



If your program tries to solve the problem through an iterative process,
then, again, does it inevitably produce a solution where all the constant
coefficients 'Cn' are positive?  If so, maybe you can just continue to
produce better and better solutions until its satisfactory, until all the
coefficients are positive.


Otherwise, without looking at your code, I'm stuck.  *grin* And even if I
do see your code, I might be stuck still.  If your code is short, feel
free to post it up, and we'll see how far we can get.  But you really may
want to talk with someone who has a stronger math background.

Good luck to you!

___
Tutor maillist  -  [EMAIL PROTECTED]
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Python structure advice ?

2004-12-17 Thread Jeff Shannon
Dave S wrote:
Kent Johnson wrote:
Why do you say this is 'cheaty'? A class is basically a collection of 
data (state) and functions to operate on that state.

Sorry for the delay, real world work got in the way ...
Well I understand classes to be used when multiple instances are 
required, I will only need one instance and as such it seemed a bit of a 
cheat, The trouble is I now pretty well understand the tools, but don't 
know how you guys use them in the real world.
For what it's worth, it seems to me to be perfectly normal to have 
classes that are only ever intended to have a single instance.  For 
example, you're never likely to need more than one HTML parser, and 
yet htmllib.HTMLParser is a class...

As Kent said, the main point of a class is that you have a collection 
of data and operations on that data bundled together.  Whether you 
have one set of data to operate on, or many such sets, is mostly 
irrelevant (though classes are even more valuable when there *are* 
many sets of data).  Defining a class isn't so much a statement that 
"I want lots of things like this", as it is a declaration of 
modularity -- "This stuff all belongs together as a unit".

Jeff Shannon
Technician/Programmer
Credit International
___
Tutor maillist  -  [EMAIL PROTECTED]
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Re: Opening and reading .cvs files in Python

2004-12-17 Thread Shantanoo Mahajan
+++ Johan Geldenhuys [14-12-04 15:18 +0200]:
| Hi,
| I want to find out how to open a .cvs file on a remote Windows machine
| and get file to my local linux folder.

.cvs file??


| 
| Any help would be appreciated.
| -- 
|Johan 
| 
| -- 
| This E-Mail has been scanned.
| Enjoy Your Day.
| 
| -- next part --
| An HTML attachment was scrubbed...
| URL: 
http://mail.python.org/pipermail/tutor/attachments/20041214/58bfe4e7/attachment-0001.htm
| 
| --
___
Tutor maillist  -  [EMAIL PROTECTED]
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Polish translation of my tutor

2004-12-17 Thread Alan Gauld
Are there any Polish speakers on the tutor list who would like 
to check a new version of my tutorial? There are no formal links 
to it yet as there are only a few pages but it can be found at:

http://www.freenetpages.co.uk/hp/alan.gauld/polish/

And any feedback can be sent to me and I'll forward to the 
translator.

Alan G
Author of the Learn to Program web tutor
http://www.freenetpages.co.uk/hp/alan.gauld
___
Tutor maillist  -  [EMAIL PROTECTED]
http://mail.python.org/mailman/listinfo/tutor


[Tutor] About Perl's Integer module

2004-12-17 Thread Mohamed Lrhazi
Hello all,
I ported to python a little Perl script that applies some math algorithm 
that I do not understand... My version seems to give the same results as 
the Perl version... but just to make sure I am asking the following:

The Perl version starts by testing whether Perl is in integer mode or not, 
and if not it exists! Is there an equivalent module in Python?

From what I gathered, in Integer mode, Perl convert (floors) all numbers to 
integers while doing any arithmetic (+ - * / bit shifting...)
Should I simply wrap every number involved in any arithmetic calculation 
with calls to floor()?

My python script, and the Perl original, follow. What it does is create a 
hash of the input string (which is supposed to be a DNS domain name) and 
returns the two layer directory tree where the domain should live in my 
filesystem :

site.company.com -->  X3/32/site.company.com
site2.company.com --> 6U/zv/site2.company.com
Given the lack of "use integer" from my code... can anyone tell these two 
programs are equivalent?

def complex(domain):
h=0
res=""
domain=domain.lower()
prefix=['x','x','/','x','x','/']
conv=[
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L',
'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X',
'Y', 'Z',
'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l',
'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x',
'y', 'z',
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
'-', '_'
]
for i in range(0,len(domain)):
h*=129
h+=ord(domain[i])
h+=987654321
if h == 0:
h=1
prefix[0] = conv[ h & 0x3f ]; h = h >> 6
prefix[1] = conv[ h & 0x3f ]; h = h >> 6
prefix[3] = conv[ h & 0x3f ]; h = h >> 6
prefix[4] = conv[ h & 0x3f ];

return "".join(prefix) + domain

print complex(sys.argv[1])
""" The Perl version :
# --
# Returns the complex hash of the website.
sub complex {
   my $site = shift;
   my $h = 0;
   my $res = "";
   $site = lc $site;
   my @prefix = ( 'x','x','/','x','x','/' );
   my @conv   = (
  'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L',
  'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X',
  'Y', 'Z',
  'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l',
  'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x',
  'y', 'z',
  '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
  '-', '_'
  );
   my @chars = split //, $site;
   my $i;
   for( $i = 0; $i < $#chars + 1; $i++ ) {
$h *= 129;
$h += ord( $chars[$i] );
$h += 987654321;
   }
   if( $h == 0 ) { $h = 1; }
   $prefix[0] = $conv[$h & 0x3f]; $h = $h >> 6;
   $prefix[1] = $conv[$h & 0x3f]; $h = $h >> 6;
   $prefix[3] = $conv[$h & 0x3f]; $h = $h >> 6;
   $prefix[4] = $conv[$h & 0x3f];
   return (join '', @prefix) . "$site";
}
"""
___
Tutor maillist  -  [EMAIL PROTECTED]
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Python structure advice ?

2004-12-17 Thread Dave S
Sorry for the delay, real world work took me away ...
everything was global, how you guys handle a modern structured
language
   

Don't worry this is one of the hardest bad habits to break.
You are not alone. The easiest way is to just pass the data
from function to function in the function parameters. Its not
at all unusual for functions to have lots of parameters, "global"
programmers tend to panic when they have more than a couple,
 

yep !
but its not at all bad to have 5 or 6 - more than that gets
unweildy I admit and is usually time to start thinking about
classes and objects.
 

I have ended up with my application in several separate directories.
   

Separate modules is good. Separate directories for anything
other than big programs (say 20 or more files?) is more hassle
than its worth. The files are better kept in a single directory
IMHO. The exception being modules designed for reuse...
It just makes life simpler!
 

Ive tried to be hyper organized and added my dirs in
/usr/lib/python2.3/site-packages/mypath.pth
/home/dave/mygg/gg1.3/live_datad
/home/dave/mygg/gg1.3/logger
/home/dave/mygg/gg1.3/utils
/home/dave/mygg/gg1.3/datacore
/home/dave/mygg/gg1.3
/home/dave/mygg/gg1.3/configs
This works OK but I sometimes have to search around a bit to find where 
the modules are.

Probarby part of the problem is I tend to write lots of small modules, 
debug them & then import them into one controlling script, It works OK 
but I start to drown in files, eg my live_datad contains ...

exact_sleep.py   garbage_collect.py   gg ftsed.e3p  html_strip.py   
live_datad.py  valid_day.pyc
exact_sleep.pyc  garbage_collect.pyc  gg ftsed.e3s  html_strip.pyc  
valid_day.py

When I get more experienced I will try & write fewer, bigger modules :-)
 

My problem is that pretty much all the modules need to fix where
   

they
 

are when they exit and pick up from that point later on,
   

There are two "classic" approaches to this kind of problem:
1) batch oriented - each step of the process produces its own
output file or data structure and this gets picked up by the
next stage. Tis usually involved processing data in chunks
- writing the first dump after every 10th set of input say.
This is a very efficient way of processing large chuinks of
data and avoids any problems of synchronisation since the
output chunks form the self contained input to the next step.
And the input stage can run ahead of the processing or the
processing aghead of the input. This is classic mainframe
strategy, ideal for big volumes. BUT it introduces delays
in the end to end process time, its not instant.
 

I see your point, like a static chain, one calling the next & passing 
data, the problem being that the links of the chain will need to 
remember their previous state when called again, so their output is a 
function of previous data + fresh data. I guess their state could be 
written to a file, then re-read.

2) Real time serial processing, typically constructs a
processing chain in a single process. Has a separate thread
reading the input data 

Got that working live_datad ...
and kicks off a separate processing
thread (or process) for each bit of data received. Each
thread then processes the data to completion and writes
the output.
OK
A third process or thread then assembles the
outputs into a single report.
 

Interesting ...
This produces results quickly but can overload the computer
if data starts to arrive so fast that the threads start to
back up on each other. Also error handling is harder since
with the batch job data errors can be fixed at the
intermediate files but with this an error anywhere means
that whole data processing chain will be broken with no way
to fix it other than resubmitting the initial data.
 

An interesting idea, I had not thought of this approach as an option 
even with its stated drawbacks. Its given me an idea for some scripting 
I have to do later on ...

With my code now running to a few hundred lines
(Don't laugh this is BIG for me :-D )
   

Its big for me in Python, I've only writtenone program with
more than a thousand lines of Python wheras I've written
many C/C++ programs in ecess of 10,000 lines 

Boy am I glad I chose to learn Python rather than C++, probarbly still 
be at 'hello world' ;-)

and worked
on several of more than a million lines. But few if any
Python programs get to those sizes.
HTH,
Alan G
Author of the Learn to Program web tutor
http://www.freenetpages.co.uk/hp/alan.gauld

 

___
Tutor maillist  -  [EMAIL PROTECTED]
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Python structure advice ?

2004-12-17 Thread Dave S
Jeff Shannon wrote:
Dave S wrote:
Kent Johnson wrote:
Why do you say this is 'cheaty'? A class is basically a collection 
of data (state) and functions to operate on that state.

Sorry for the delay, real world work got in the way ...
Well I understand classes to be used when multiple instances are 
required, I will only need one instance and as such it seemed a bit 
of a cheat, The trouble is I now pretty well understand the tools, 
but don't know how you guys use them in the real world.

For what it's worth, it seems to me to be perfectly normal to have 
classes that are only ever intended to have a single instance.  For 
example, you're never likely to need more than one HTML parser, and 
yet htmllib.HTMLParser is a class...
Well if its good enough for a Python lib ...
As Kent said, the main point of a class is that you have a collection 
of data and operations on that data bundled together.  Whether you 
have one set of data to operate on, or many such sets, is mostly 
irrelevant (though classes are even more valuable when there *are* 
many sets of data).  Defining a class isn't so much a statement that 
"I want lots of things like this", as it is a declaration of 
modularity -- "This stuff all belongs together as a unit".

OK Im a reformed ('L' plate programmer) its going to be classes :-)
Jeff Shannon
Technician/Programmer
Credit International
___
Tutor maillist  -  [EMAIL PROTECTED]
http://mail.python.org/mailman/listinfo/tutor

___
Tutor maillist  -  [EMAIL PROTECTED]
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] About Perl's Integer module

2004-12-17 Thread Jeff Shannon
Mohamed Lrhazi wrote:
Hello all,
I ported to python a little Perl script that applies some math algorithm 
that I do not understand... My version seems to give the same results as 
the Perl version... but just to make sure I am asking the following:

The Perl version starts by testing whether Perl is in integer mode or 
not, and if not it exists! Is there an equivalent module in Python?
No, there isn't.  However, the only operation in Python that should 
convert an integer into a float is division, and you should be able to 
use // (a double slash) to indicate integer division.  But there's no 
division in your script, so it shouldn't matter...  (Integers *will* 
automatically be converted to longs if they get too large, but this 
should be harmless unless you specifically need ints to 'wrap around'.)

Given the lack of "use integer" from my code... can anyone tell these 
two programs are equivalent?
I don't know perl, so I can't tell for certain, but I think so. 
However, there are many ways in which this could become more idiomatic 
Python code, and more efficient.

def complex(domain):
h=0
res=""
domain=domain.lower()
prefix=['x','x','/','x','x','/']
conv=[
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L',
'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X',
'Y', 'Z',
'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l',
'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x',
'y', 'z',
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
'-', '_'
]
In Python, strings are sequences, so you can index and slice and 
iterate over them.  This means that you can replace these lists of 
single characters with one string, instead.  Not only that, but given 
that you're using all letters and numbers, you can just get them from 
predefined lists in the string module --

.>> import string
.>> string.ascii_uppercase
'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
.>> string.ascii_lowercase
'abcdefghijklmnopqrstuvwxyz'
.>> string.digits
'0123456789'
.>>
With that in mind, the above line can be changed to:
conv = string.uppercase + string.lowercase + \
   string.digits + '-_'
(There's also a string.letters which contains both uppercase and 
lowercase, but it has the lowercase first while you have the uppercase 
first.  This will yield different, but equally valid, characters.)

for i in range(0,len(domain)):
h*=129
h+=ord(domain[i])
h+=987654321
Because you can iterate over strings, you can do this simpler by 
dropping the integer index and the range().  You can even chain the 
earlier call to lower() in-line here:

for ch in domain.lower():
h *= 129
h += ord(ch)
h += 987654321
if h == 0:
h=1

prefix[0] = conv[ h & 0x3f ]; h = h >> 6
prefix[1] = conv[ h & 0x3f ]; h = h >> 6
prefix[3] = conv[ h & 0x3f ]; h = h >> 6
prefix[4] = conv[ h & 0x3f ];

Here, instead of predefining prefix list and then replacing certain 
elements, I'd just create a blank list and append to it.  Given that 
your operation is identical each time (except when you need a /), I'd 
put it into a loop.

prefix = []
for i in range(6):
if i in (2, 5):
prefix.append('/')
else:
prefix.append(conv[ h & 0x3f ])
h = h >> 6


return "".join(prefix) + domain

print complex(sys.argv[1])
So, once more, all together:
.>> def complex(domain):
... h = 0
... conv = string.uppercase + string.lowercase + \
...  string.digits + '-_'
... for ch in domain.lower():
... h *= 129
... h += ord(ch)
... h += 987654321
... if h == 0:
... h = 1
... prefix = []
... for i in range(6):
... if i in (2, 5):
... prefix.append('/')
... else:
... prefix.append(conv[ h & 0x3f ])
... h = h >> 6
... return "".join(prefix) + domain
...
.>>
So, let's see how this works:
.>> complex('site.company.com')
'X3/32/site.company.com'
.>> complex('site2.company.com')
'6U/zv/site2.company.com'
.>> complex('www.python.org')
'ZF/4R/www.python.org'
.>>
So, each character is generated by looking at the hash (h), grabbing 
the least-significant six bits, and using the resulting number (which 
will be 0-63) to look up a character in conv.  The hash is then 
shifted six bits to drop the 'used' bits before grabbing the next 
chunk.  Two of these generated characters are used for each of two 
directory names.  Any given sitename will consistently produce the 
same four characters.

Now, here's a 'batteries-included' function that does much the same 
thing (though it'll be different characters).

.>> def complex2(domain):
... import md5
... digest = md5.new(domain)
... digeststring = digest.hexdigest()
... names = (digeststring[:2], digeststring[2:4], domain)
.

[Tutor] Tkinter questions

2004-12-17 Thread Mark Kels
Hi all ,
I got some Tkinter related questions for a project that I'm making:
1. How to add an image to a button ?
2. How can I print text using Tkinter (I want it to be cross platform,
so I cant use modules like win32print ) ?
3. How to I make the program to always open in a full window ?

Thanks allot.

-- 
1. The day Microsoft makes something that doesn't suck is probably the
day they start making vacuum cleaners.
2. Unix is user friendly - it's just picky about it's friends.
3. Documentation is like sex: when it is good, it is very, very good.
And when it is bad, it is better than nothing. - Dick Brandon
___
Tutor maillist  -  [EMAIL PROTECTED]
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] "TypeError: 'int' object is not callable"??

2004-12-17 Thread Jacob S.
Hey, could you give an example?
Thanks,
Jacob

>
> apply() is deprecated; it has been replaced by 'extended call syntax'.
Instead of
>apply(fn, args, kwds)
> you can now write
>fn(*args, **kwds)
>
> Kent
> ___
> Tutor maillist  -  [EMAIL PROTECTED]
> http://mail.python.org/mailman/listinfo/tutor
>
>

___
Tutor maillist  -  [EMAIL PROTECTED]
http://mail.python.org/mailman/listinfo/tutor


RE: [Tutor] "TypeError: 'int' object is not callable"??

2004-12-17 Thread Christian Wyglendowski
> -Original Message-
> From: [EMAIL PROTECTED] 
> [mailto:[EMAIL PROTECTED] On Behalf Of Jacob S.
> Sent: Friday, December 17, 2004 3:54 PM
> To: Kent Johnson
> Cc: [EMAIL PROTECTED]
> Subject: Re: [Tutor] "TypeError: 'int' object is not callable"??
> 
> Hey, could you give an example?
> Thanks,
> Jacob
> 
> >
> > apply() is deprecated; it has been replaced by 'extended 
> call syntax'.
> Instead of
> >apply(fn, args, kwds)
> > you can now write
> >fn(*args, **kwds)
> >
> > Kent

Here is a quick example I came up with:

>>> def spam(*args, **kwargs):
... print "Here are the args you supplied:"
... for item in args:
... print item
... print
... print "Here are the kwargs you supplied:"
... for key,value in kwargs.items():
... print key, '=', value
... 
>>> spam(1,'a','eggs',s=0, p=1, a=2, m=3)
Here are the args you supplied:
1
a
eggs

Here are the kwargs you supplied:
a = 2
p = 1
s = 0
m = 3

In the case of the spam() function, 1, 'a', and 'eggs' are all put into
the sequence args (not sure if it is a list or tuple).  The key/value
pairs are bundled into the dictionary kwargs.  The arguments have to be
given in the right order though:

>>> spam(t=1, b=1, 'this', 'will', 'fail')
Traceback (SyntaxError: non-keyword arg after keyword arg

HTH!

Christian
http://www.dowski.com


___
Tutor maillist  -  [EMAIL PROTECTED]
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Python structure advice ?

2004-12-17 Thread Kent Johnson
Dave S wrote:
Separate modules is good. Separate directories for anything
other than big programs (say 20 or more files?) is more hassle
than its worth. The files are better kept in a single directory
IMHO. The exception being modules designed for reuse...
It just makes life simpler!
 

Ive tried to be hyper organized and added my dirs in
/usr/lib/python2.3/site-packages/mypath.pth
/home/dave/mygg/gg1.3/live_datad
/home/dave/mygg/gg1.3/logger
/home/dave/mygg/gg1.3/utils
/home/dave/mygg/gg1.3/datacore
/home/dave/mygg/gg1.3
/home/dave/mygg/gg1.3/configs
This works OK but I sometimes have to search around a bit to find where 
the modules are.

Probarby part of the problem is I tend to write lots of small modules, 
debug them & then import them into one controlling script, It works OK 
but I start to drown in files, eg my live_datad contains ...

exact_sleep.py   garbage_collect.py   gg ftsed.e3p  html_strip.py   
live_datad.py  valid_day.pyc
exact_sleep.pyc  garbage_collect.pyc  gg ftsed.e3s  html_strip.pyc  
valid_day.py

When I get more experienced I will try & write fewer, bigger modules :-)
It's just a guess from the filenames, but it looks like your live_datad package (directory) contains 
everything needed by live_datad.py. I would like to suggest a different organization.

I tend to organize packages around a single functional area, and by looking at the dependencies of 
the modules in the package on other packages.

For example, in my current project some of the packages are:
- common.util - this is a catchall for modules that are not specific to this application, and don't 
depend on any other packages
- common.db - low-level database access modules
- cb.data - application-specific database access - the data objects and data access objects that the 
application works with
- cb.import - modules that import legacy data into the application
- cb.writer - modules that generate files
- cb.gui - GUI components
- cb.app - application-level drivers and helpers

Anyway, the point is, if you organize your modules according to what they do, rather than by who 
uses them, you might make a structure that is less chaotic.

HTH
Kent
___
Tutor maillist  -  [EMAIL PROTECTED]
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Polish translation of my tutor

2004-12-17 Thread Pawel Kraszewski
Dnia piątek, 17 grudnia 2004 20:59, Alan Gauld napisał:

|Are there any Polish speakers on the tutor list who would like
|to check a new version of my tutorial? There are no formal links
|to it yet as there are only a few pages but it can be found at:

That would be me. First of all 

content="text/html; charset=ISO-6682"

Ehm... Never heard of ISO-6682... Already contacted the author. The page looks 
OK, when you force Windows CP 1250.

-- 
 Pawel KraszewskiFreeBSD/Linux

E-Mail/Jabber Phone ICQ   GG
   [EMAIL PROTECTED]+48 604 777447   45615564   69381
___
Tutor maillist  -  [EMAIL PROTECTED]
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] "TypeError: 'int' object is not callable"??

2004-12-17 Thread Kent Johnson
Jacob S. wrote:
Hey, could you give an example?
I'll try...
Here is range with three explicit arguments
 >>> range(1, 10, 2)
[1, 3, 5, 7, 9]
Here is range with the arguments supplied in a list; it does the same thing
 >>> args = [1, 10, 2]
 >>> range(*args)
[1, 3, 5, 7, 9]
Here is an example with zip(). zip() normally takes multiple arguments, this makes it use elements 
of a single list:
 >>> l=[ [1,2], [3,4], [5,6] ]
 >>> zip(*l)
[(1, 3, 5), (2, 4, 6)]

Kent
Thanks,
Jacob

apply() is deprecated; it has been replaced by 'extended call syntax'.
Instead of
  apply(fn, args, kwds)
you can now write
  fn(*args, **kwds)
Kent
___
Tutor maillist  -  [EMAIL PROTECTED]
http://mail.python.org/mailman/listinfo/tutor



___
Tutor maillist  -  [EMAIL PROTECTED]
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] "TypeError: 'int' object is not callable"??

2004-12-17 Thread Jacob S.
Thank you!

Wait, though.

How do I do this?

def differentnoofvars(*args,**kwargs):  ## By the way, is it **kwargs or
**kwds?
print kwargs
another(kwargs)

def another(**kwargs):
for x,y in kwagrs.items():
print "%s = %s" % (x,y)

a = ['a=2','f=3','t=[1,2,3]']  ## A list of kwargs that I want to send
individually to differentnoofvars
differentnoofvars(a)


> > Hey, could you give an example?
> > Thanks,
> > Jacob
> >
> > >
> > > apply() is deprecated; it has been replaced by 'extended
> > call syntax'.
> > Instead of
> > >apply(fn, args, kwds)
> > > you can now write
> > >fn(*args, **kwds)
> > >
> > > Kent
>
> Here is a quick example I came up with:
>
> >>> def spam(*args, **kwargs):
> ... print "Here are the args you supplied:"
> ... for item in args:
> ... print item
> ... print
> ... print "Here are the kwargs you supplied:"
> ... for key,value in kwargs.items():
> ... print key, '=', value
> ...
> >>> spam(1,'a','eggs',s=0, p=1, a=2, m=3)
> Here are the args you supplied:
> 1
> a
> eggs
>
> Here are the kwargs you supplied:
> a = 2
> p = 1
> s = 0
> m = 3
>
> In the case of the spam() function, 1, 'a', and 'eggs' are all put into
> the sequence args (not sure if it is a list or tuple).  The key/value
> pairs are bundled into the dictionary kwargs.  The arguments have to be
> given in the right order though:
>
> >>> spam(t=1, b=1, 'this', 'will', 'fail')
> Traceback (SyntaxError: non-keyword arg after keyword arg
>
> HTH!
>
> Christian
> http://www.dowski.com
>
>
>
>

___
Tutor maillist  -  [EMAIL PROTECTED]
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] "TypeError: 'int' object is not callable"??

2004-12-17 Thread Jacob S.
Sorry about that last message. Kent just posted and answered my question
with his example.
Thank you all!

Jacob

> > -Original Message-
> > From: [EMAIL PROTECTED]
> > [mailto:[EMAIL PROTECTED] On Behalf Of Jacob S.
> > Sent: Friday, December 17, 2004 3:54 PM
> > To: Kent Johnson
> > Cc: [EMAIL PROTECTED]
> > Subject: Re: [Tutor] "TypeError: 'int' object is not callable"??
> >
> > Hey, could you give an example?
> > Thanks,
> > Jacob
> >
> > >
> > > apply() is deprecated; it has been replaced by 'extended
> > call syntax'.
> > Instead of
> > >apply(fn, args, kwds)
> > > you can now write
> > >fn(*args, **kwds)
> > >
> > > Kent
>
> Here is a quick example I came up with:
>
> >>> def spam(*args, **kwargs):
> ... print "Here are the args you supplied:"
> ... for item in args:
> ... print item
> ... print
> ... print "Here are the kwargs you supplied:"
> ... for key,value in kwargs.items():
> ... print key, '=', value
> ...
> >>> spam(1,'a','eggs',s=0, p=1, a=2, m=3)
> Here are the args you supplied:
> 1
> a
> eggs
>
> Here are the kwargs you supplied:
> a = 2
> p = 1
> s = 0
> m = 3
>
> In the case of the spam() function, 1, 'a', and 'eggs' are all put into
> the sequence args (not sure if it is a list or tuple).  The key/value
> pairs are bundled into the dictionary kwargs.  The arguments have to be
> given in the right order though:
>
> >>> spam(t=1, b=1, 'this', 'will', 'fail')
> Traceback (SyntaxError: non-keyword arg after keyword arg
>
> HTH!
>
> Christian
> http://www.dowski.com
>
>
>
>

___
Tutor maillist  -  [EMAIL PROTECTED]
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] "TypeError: 'int' object is not callable"??

2004-12-17 Thread Kent Johnson
Jacob S. wrote:
Thank you!
Wait, though.
How do I do this?
def differentnoofvars(*args,**kwargs):  ## By the way, is it **kwargs or
**kwds?
Call it what you like, it's an ordinary function parameter. kwds is commonly used but you can use 
kwargs.
print kwargs
another(kwargs)
Should be another(**kwargs). If you call another(kwargs) then kwargs will be an ordinary parameter 
of another and another would be defined as
def another(kwargs):
  ...

def another(**kwargs):
for x,y in kwagrs.items():
print "%s = %s" % (x,y)
a = ['a=2','f=3','t=[1,2,3]']  ## A list of kwargs that I want to send
Should be a dict, the **kwds parameter is a dict mapping keywords to values
a = {'a':2, 'f':3, 't':[1,2,3]}
There really are two different and complementary things going on here, at the point of call and at 
the point of function definition.

At the point of call, you can pass a dictionary instead of using explicit, named parameters. For 
example, given a function test() defined like this:
 >>> def test(a, b):
 ...  print a, b

you can call it with ordinary named arguments:
 >>> test(a='foo', b='bar')
foo bar
Or you can pass it a dictionary with the named arguments, using extended 
calling syntax:
 >>> d= {'a':'foo', 'b':'bar'}
 >>> test(**d)
foo bar
Inside the function, if you have a **kwds parameter, it will receive a dict containing any keyword 
arguments not explicitly declared. This allows you to pass keyword parameters that you don't 
anticipate when the function is defined. For example,

 >>> def test2(a, **kwds):
 ...   print a
 ...   for k,v in kwds.items():
 ... print k,v
 >>> test2(1)  # No keywords
1
 >>> test2(a=1)# a is a declared parameter so kwds is empty
1
 >>> test2(1, b=2, c=3) # b and c are passed in kwds
1
c 3
b 2
Kent
individually to differentnoofvars
differentnoofvars(a)

Hey, could you give an example?
Thanks,
Jacob

apply() is deprecated; it has been replaced by 'extended
call syntax'.
Instead of
  apply(fn, args, kwds)
you can now write
  fn(*args, **kwds)
Kent
Here is a quick example I came up with:

def spam(*args, **kwargs):
... print "Here are the args you supplied:"
... for item in args:
... print item
... print
... print "Here are the kwargs you supplied:"
... for key,value in kwargs.items():
... print key, '=', value
...
spam(1,'a','eggs',s=0, p=1, a=2, m=3)
Here are the args you supplied:
1
a
eggs
Here are the kwargs you supplied:
a = 2
p = 1
s = 0
m = 3
In the case of the spam() function, 1, 'a', and 'eggs' are all put into
the sequence args (not sure if it is a list or tuple).  The key/value
pairs are bundled into the dictionary kwargs.  The arguments have to be
given in the right order though:

spam(t=1, b=1, 'this', 'will', 'fail')
Traceback (SyntaxError: non-keyword arg after keyword arg
HTH!
Christian
http://www.dowski.com



___
Tutor maillist  -  [EMAIL PROTECTED]
http://mail.python.org/mailman/listinfo/tutor
___
Tutor maillist  -  [EMAIL PROTECTED]
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Python structure advice ?

2004-12-17 Thread Alan Gauld
> For what it's worth, it seems to me to be perfectly normal to have
> classes that are only ever intended to have a single instance.  For
> example, you're never likely to need more than one HTML parser, and
> yet htmllib.HTMLParser is a class...

That's true but the argument for a class in that case is that we
can subclass it for more specialized purposes. If there is only
to be a single instance and it will not be specialized by sub
classing then a simple module will do the job just nicely.

> As Kent said, the main point of a class is that you have a
collection
> of data and operations on that data bundled together.

Dunno if I'd agree that that was the *main point* of classes,
the main point I'd say was to act as a template for objects.
The fact that there might only be one instance is a side issue.

But creating classes that only have a single instance is certainly
OK, after all the original design patterns book by the GoF has a
singleton pattern to ensure that only one oinstance can be created!

> "I want lots of things like this", as it is a declaration of
> modularity -- "This stuff all belongs together as a unit".

So use a module... Python is blessed with both constructs and
we should use whichever is most appropriate. IMHO of course! :-)

Alan G
Author of the Learn to Program web tutor
http://www.freenetpages.co.uk/hp/alan.gauld

___
Tutor maillist  -  [EMAIL PROTECTED]
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] dbcp module

2004-12-17 Thread Rene Bourgoin


Yes i believe im looking for the python version of the Jakarta databse 
connection pool!!



 --- On Fri 12/17, Kent Johnson < [EMAIL PROTECTED] > wrote:
From: Kent Johnson [mailto: [EMAIL PROTECTED]
To: 
 Cc: [EMAIL PROTECTED]
Date: Fri, 17 Dec 2004 07:12:40 -0500
Subject: Re: [Tutor] dbcp module

Please describe what you are looking for. A python version of the Jakarta 
Database Connection Pool?KentRene Bourgoin wrote:> Yah 
i came across that site and was trying to learn from that code.> > I 
just cant seem to find a download for a python version.> > > > 
i came across this site while searching.> > > > 
http://jakarta.apache.org/> > > > > > > > > 
> > > > >  --- On Wed 12/15, Kent Johnson < [EMAIL 
PROTECTED] > wrote:> > From: Kent Johnson [mailto: [EMAIL 
PROTECTED]> > To: > >  Cc: [EMAIL PROTECTED]> > 
Date: Wed, 15 Dec 2004 20:19:22 -0500> > Subject: Re: [Tutor] dbcp 
module> > > > Googling for 'python dbcp' turns up this recipe, 
is this what you are looking 
for?http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/81189KentRene
 Bourgoin wrote:> Anyone know where I can dow!
 nload the dbcp module for Python> > > > > > > 
___> No banners. No pop-ups. No 
kidding.> Make My Way your home on the Web - http://www.myway.com> 
___> Tutor maillist  -  
[EMAIL PROTECTED]> http://mail.python.org/mailman/listinfo/tutor> 
___Tutor maillist  -  
[EMAIL PROTECTED]http://mail.python.org/mailman/listinfo/tutor> 
> ___> No banners. No 
pop-ups. No kidding.> Make My Way your home on the Web - 
http://www.myway.com> 
___Tutor maillist  -  
[EMAIL PROTECTED]http://mail.python.org/mailman/listinfo/tutor

___
No banners. No pop-ups. No kidding.
Make My Way your home on the Web - http://www.myway.com
___
Tutor maillist  -  [EMAIL PROTECTED]
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Python structure advice ?

2004-12-17 Thread Alan Gauld
> >1) batch oriented - each step of the process produces its own
> >output file or data structure and this gets picked up by the
> >next stage. Tis usually involved processing data in chunks
> >- writing the first dump after every 10th set of input say.
> >
> I see your point, like a static chain, one calling the next &
passing
> data, the problem being that the links of the chain will need to
> remember their previous state when called again, so their output is
a
> function of previous data + fresh data. I guess their state could be
> written to a file, then re-read.

Yes. Just to expand: the typical processing involves three files:
1) the input which is the output of the preceding stage
2) the output which will form input to the next stage
3) the job log. This will contain references to any input data
items that failed to process - typically these will be manually
inspected, corrected and a new file created and submitted at the
end of the batch run.

BUT 3) will also contain the sequence number of the last file and/or
last data item processed so that when the next cycle runs it knows
where to start. It is this belt and braces approach to data
processing and error recovery that makes mainframes so reliable,
not just the hardware, but the whole culture there is geared to
handling failure and being able to *recover* not just report on it.
After all its the mainframes where the really mission critical
software of any large enterprise runs!

As an ex Unix head I learned an awful lot about reliable computing
from the 18 months I spent working on a mainframe project. These
guys mostly live in a highly specialised microcosm of their own
but they have learned a lot of powerful tricks over the last 40
years that the rest of us ignore at our peril. I strongly
recommend that anyone who gets the chance of *a short* contract
in mainframe land, with training, to grab the opportunity with
both hands!

< Steps off soapbox now :-) >

Alan G
Author of the Learn to Program web tutor
http://www.freenetpages.co.uk/hp/alan.gauld

___
Tutor maillist  -  [EMAIL PROTECTED]
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Tkinter questions

2004-12-17 Thread Alan Gauld
> I got some Tkinter related questions for a project that I'm making:
> 1. How to add an image to a button ?

I find the easiest way is to create an PhotoImage object attach
the graphic file(jpg,bmp,gif) to that and assign the PhotoImage
object to the Button.image property. You can "animate" the image
by simply reassigning the file to the underlying PhotoImage onject.

> 2. How can I print text using Tkinter (I want it to be cross
platform,
> so I cant use modules like win32print ) ?

You mean print as in to a printer?
Personally I tend to generate an HTML file and use the
native OS Tools to print that. You can get fancy and
use the native OS priniting libraries but since its
very OS specific I find HTML is easier! OUtside Tkinter
you may well find the GUI libraries have done the cross
platform stuff for you, but not in Tkinter.

> 3. How to I make the program to always open in a full window ?

Define a full window? You mean full screen?
Thats usually better done as a parameter that the user can
set unless there is a very good reason not to. (Personally
I refuse to use any program that insists on opening full screen!)

If OTOH you mean that you don't want the DOS box in the background
thats easy, just rename the .py file to .pyw. But I suspect,
since you talk abouit cross platform you mean full screen.

HTH,

Alan G
Author of the Learn to Program web tutor
http://www.freenetpages.co.uk/hp/alan.gauld

___
Tutor maillist  -  [EMAIL PROTECTED]
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] dbcp module

2004-12-17 Thread Danny Yoo


On Fri, 17 Dec 2004, Rene Bourgoin wrote:

> Yes i believe im looking for the python version of the Jakarta databse
> connection pool!!

Hi Rene,


I haven't looked at this too closely yet, but there are projects out there
for connection pools.  For example:

http://sqlrelay.sourceforge.net/


Some prominent Python projects, though, appear to use their own homebrewed
connection pools.  Zope appears to do this:

http://zdp.zope.org/projects/zfaq/faq/DatabaseIntegration/954522163

SQLObject maintains its own database pool:

http://wiki.sqlobject.org/connections

but also refers to 'DBPool.py':

http://jonpy.sourceforge.net/dbpool.html

I'm not sure if one database pooling solution has emerged as a dominant
one yet, though.


Good luck to you!

___
Tutor maillist  -  [EMAIL PROTECTED]
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Python structure advice ?

2004-12-17 Thread Dave S
Alan Gauld wrote:
1) batch oriented - each step of the process produces its own
output file or data structure and this gets picked up by the
next stage. Tis usually involved processing data in chunks
- writing the first dump after every 10th set of input say.
 

I see your point, like a static chain, one calling the next &
   

passing
 

data, the problem being that the links of the chain will need to
remember their previous state when called again, so their output is
   

a
 

function of previous data + fresh data. I guess their state could be
written to a file, then re-read.
   

Yes. Just to expand: the typical processing involves three files:
1) the input which is the output of the preceding stage
2) the output which will form input to the next stage
3) the job log. This will contain references to any input data
items that failed to process - typically these will be manually
inspected, corrected and a new file created and submitted at the
end of the batch run.
BUT 3) will also contain the sequence number of the last file and/or
last data item processed so that when the next cycle runs it knows
where to start. It is this belt and braces approach to data
processing and error recovery that makes mainframes so reliable,
not just the hardware, but the whole culture there is geared to
handling failure and being able to *recover* not just report on it.
After all its the mainframes where the really mission critical
software of any large enterprise runs!
As an ex Unix head I learned an awful lot about reliable computing
from the 18 months I spent working on a mainframe project. These
guys mostly live in a highly specialised microcosm of their own
but they have learned a lot of powerful tricks over the last 40
years that the rest of us ignore at our peril. I strongly
recommend that anyone who gets the chance of *a short* contract
in mainframe land, with training, to grab the opportunity with
both hands!
< Steps off soapbox now :-) >
Alan G
Author of the Learn to Program web tutor
http://www.freenetpages.co.uk/hp/alan.gauld

 

You get on that soapbox whenever you want :-) , its good to hear a range 
of views !

Dave
___
Tutor maillist  -  [EMAIL PROTECTED]
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Python structure advice ?

2004-12-17 Thread Dave S
Kent Johnson wrote:
Dave S wrote:
Separate modules is good. Separate directories for anything
other than big programs (say 20 or more files?) is more hassle
than its worth. The files are better kept in a single directory
IMHO. The exception being modules designed for reuse...
It just makes life simpler!
 

Ive tried to be hyper organized and added my dirs in
/usr/lib/python2.3/site-packages/mypath.pth
/home/dave/mygg/gg1.3/live_datad
/home/dave/mygg/gg1.3/logger
/home/dave/mygg/gg1.3/utils
/home/dave/mygg/gg1.3/datacore
/home/dave/mygg/gg1.3
/home/dave/mygg/gg1.3/configs
This works OK but I sometimes have to search around a bit to find 
where the modules are.

Probarby part of the problem is I tend to write lots of small 
modules, debug them & then import them into one controlling script, 
It works OK but I start to drown in files, eg my live_datad contains ...

exact_sleep.py   garbage_collect.py   gg ftsed.e3p  html_strip.py   
live_datad.py  valid_day.pyc
exact_sleep.pyc  garbage_collect.pyc  gg ftsed.e3s  html_strip.pyc  
valid_day.py

When I get more experienced I will try & write fewer, bigger modules :-)

It's just a guess from the filenames, but it looks like your 
live_datad package (directory) contains everything needed by 
live_datad.py. 
Spot on
I would like to suggest a different organization.
I tend to organize packages around a single functional area, and by 
looking at the dependencies of the modules in the package on other 
packages.

For example, in my current project some of the packages are:
- common.util - this is a catchall for modules that are not specific 
to this application, and don't depend on any other packages
- common.db - low-level database access modules
- cb.data - application-specific database access - the data objects 
and data access objects that the application works with
- cb.import - modules that import legacy data into the application
- cb.writer - modules that generate files
- cb.gui - GUI components
- cb.app - application-level drivers and helpers

I have been getting in a muddle, html_strip.py, strips HTML, mines for 
data & when it finds specific patterns returns a dictionary containing them.

However I also use one of its functions in a utility convert_data.py 
reading in archived semi-processed HTML files.  This cross dependance 
has occured several times and is getting messy, yours is an interesting 
approach, Its started me thinking...

Anyway, the point is, if you organize your modules according to what 
they do, rather than by who uses them, you might make a structure that 
is less chaotic.

HTH
Kent
___
Tutor maillist  -  [EMAIL PROTECTED]
http://mail.python.org/mailman/listinfo/tutor

___
Tutor maillist  -  [EMAIL PROTECTED]
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] About Perl's Integer module

2004-12-17 Thread Mohamed Lrhazi

--On Friday, December 17, 2004 1:49 PM -0800 Jeff Shannon 
<[EMAIL PROTECTED]> wrote:
I don't know perl, so I can't tell for certain, but I think so. However,
there are many ways in which this could become more idiomatic Python
code, and more efficient.
Thanks so much for all the comments and the valuable tips and the 
explanation of the actual algorithm.

The Perl code come with the web server I am using: Zeus. I won't be able to 
use your improved md5 implementation because my own scripts to manage the 
web sites would need to agree with Zeus's idea of where a domain's root 
directory is :)

Thanks a lot.
Mohamed~
___
Tutor maillist  -  [EMAIL PROTECTED]
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] dbcp module

2004-12-17 Thread Rene Bourgoin

Ive been learning to interact with databases using python and i was looking for 
ways to return a SELECT  query result in a plain format. what i mean by plain 
format is :

name numberaddress
Fred Smith   2125553243 1 main st 

All the pratices ive done return the results in tuples or tuples within tuples.
(('fred smith','2125553243','1 main st'))

I saw some examples on activestate that use the dbcp module and import the pp ( 
pretty print ) function and the results from the examples were in the format i 
was looking for. just straight strings in a tabular format. no tuples.


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

 --- On Fri 12/17, Danny Yoo < [EMAIL PROTECTED] > wrote:
From: Danny Yoo [mailto: [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
 Cc: [EMAIL PROTECTED], [EMAIL PROTECTED]
Date: Fri, 17 Dec 2004 16:13:57 -0800 (PST)
Subject: Re: [Tutor] dbcp module

On Fri, 17 Dec 2004, Rene Bourgoin wrote:> Yes i believe im 
looking for the python version of the Jakarta databse> connection 
pool!!Hi Rene,I haven't looked at this too closely yet, but 
there are projects out therefor connection pools.  For example:
http://sqlrelay.sourceforge.net/Some prominent Python projects, 
though, appear to use their own homebrewedconnection pools.  Zope appears 
to do this:
http://zdp.zope.org/projects/zfaq/faq/DatabaseIntegration/954522163SQLObject
 maintains its own database pool:
http://wiki.sqlobject.org/connectionsbut also refers to 
'DBPool.py':http://jonpy.sourceforge.net/dbpool.htmlI'm not 
sure if one database pooling solution has emerged as a dominantone yet, 
though.Good luck to you!

___
No banners. No pop-ups. No kidding.
Make My Way your home on the Web - http://www.myway.com
___
Tutor maillist  -  [EMAIL PROTECTED]
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] dbcp module

2004-12-17 Thread Kent Johnson
The recipe you cite has the pp() function and an example of its use. It sounds like that is what you 
want.

Kent
Rene Bourgoin wrote:
Ive been learning to interact with databases using python and i was looking for 
ways to return a SELECT  query result in a plain format. what i mean by plain 
format is :

name numberaddress
Fred Smith   2125553243 1 main st 


All the pratices ive done return the results in tuples or tuples within tuples.
(('fred smith','2125553243','1 main st'))

I saw some examples on activestate that use the dbcp module and import the pp ( 
pretty print ) function and the results from the examples were in the format i 
was looking for. just straight strings in a tabular format. no tuples.


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

 --- On Fri 12/17, Danny Yoo < [EMAIL PROTECTED] > wrote:
From: Danny Yoo [mailto: [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
 Cc: [EMAIL PROTECTED], [EMAIL PROTECTED]
Date: Fri, 17 Dec 2004 16:13:57 -0800 (PST)
Subject: Re: [Tutor] dbcp module

On Fri, 17 Dec 2004, Rene Bourgoin wrote:> Yes i believe im looking for the python version of the Jakarta databse> connection pool!!Hi Rene,I haven't looked at this too closely yet, but 
there are projects out therefor connection pools.  For example:http://sqlrelay.sourceforge.net/Some prominent Python projects, though, appear to use their own homebrewedconnection pools.  Zope appears to do 
this:http://zdp.zope.org/projects/zfaq/faq/DatabaseIntegration/954522163SQLObject maintains its own database pool:http://wiki.sqlobject.org/connectionsbut also refers to 'DBPool.py':
http://jonpy.sourceforge.net/dbpool.htmlI'm not sure if one database pooling solution has emerged as a dominantone yet, though.Good luck to you!
___
No banners. No pop-ups. No kidding.
Make My Way your home on the Web - http://www.myway.com
___
Tutor maillist  -  [EMAIL PROTECTED]
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] least squares

2004-12-17 Thread Kent Johnson
Have you tried contacting the author of the Scientific package? His email address is on the main web 
page.

Kent
mdcooper wrote:
Hi Danny,
Thanks for the reply - I was purposely vague just to see what people would ask 
for.

The code uses LinearAlgebra.py from Numeric and LeastSquares.py from 
Scientific.
___
Tutor maillist  -  [EMAIL PROTECTED]
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] dbcp module

2004-12-17 Thread Danny Yoo


On Fri, 17 Dec 2004, Rene Bourgoin wrote:

> Ive been learning to interact with databases using python and i was
> looking for ways to return a SELECT query result in a plain format. what
> i mean by plain format is :
>
> name numberaddress
> Fred Smith   2125553243 1 main st
>
> All the pratices ive done return the results in tuples or tuples within 
> tuples.
> (('fred smith','2125553243','1 main st'))
>

> I saw some examples on activestate that use the dbcp module


Hi Rene,


Ok, let's pause for a moment.


I think I understand where all the confusion is coming from: it's a
namespace issue, as well as a case of really really bad naming.


You mentioned earlier that:

> Yes i believe im looking for the python version of the Jakarta
> database connection pool


However, that is probably not what you're looking for.  'dbcp' in the
context of the recipe that you've shown us:


> http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/81189


has nothing to do with connection pools!



The author of that recipe has unfortunatetly named their module so as to
make it easy to confuse it with the Apache Commons DBCP project:

http://jakarta.apache.org/commons/dbcp/

But this is NOT the same 'dbcp' thing that the Python Cookbook recipe is
talking about.




The 'dbcp' Python Cookbook module refers to this snippet of code at the
beginning of the recipe:

##
"""This is dbcp.py, a module for printing out a cursor's output."""
def pp(cursor, data=None, rowlens=0):
d = cursor.description
if not d:
return " NO RESULTS ###"
names = []
lengths = []
rules = []
if not data:
t = cursor.fetchall()
for dd in d:# iterate over description
l = dd[1]
if not l:
l = 12 # or default arg ...
l = max(l, len(dd[0])) # handle long names
names.append(dd[0])
lengths.append(l)
for col in range(len(lengths)):
if rowlens:
rls = [len(str(row[col])) for row in data if row[col]]
lengths[col] = max([lengths[col]]+rls)
rules.append("-"*lengths[col])
format = " ".join(["%%-%ss" % l for l in lengths])
result = [format % tuple(names)]
result.append(format % tuple(rules))
for row in data:
result.append(format % row)
return "\n".join(result)
##


So I think the confusion here is just more anecdotal support to how much a
short, badly named variable name can damage a program.  What bothers me is
that the code in the recipe itself shows a disregard for good variable
names.  What the heck does 't', 'pp', 'dd', or 'l' stand for, anyway?
*grin*

___
Tutor maillist  -  [EMAIL PROTECTED]
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] dbcp module

2004-12-17 Thread Danny Yoo


On Fri, 17 Dec 2004, Kent Johnson wrote:

> The recipe you cite has the pp() function and an example of its use. It
> sounds like that is what you want.


Part of the pandemonium was my fault.  I completely missed your earlier
post here:

http://mail.python.org/pipermail/tutor/2004-December/034107.html

where, if I had been reading your initial response more closely, I would
have been able to catch the real reason why Rene and I were getting so
confused.  Sorry about that.

___
Tutor maillist  -  [EMAIL PROTECTED]
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] am I missing another simpler structure?

2004-12-17 Thread Terry Carroll
On Thu, 16 Dec 2004, Alan Gauld wrote:

> In most debiggers ...

So *that's* the trick to writing compact code!


___
Tutor maillist  -  [EMAIL PROTECTED]
http://mail.python.org/mailman/listinfo/tutor