os.mkdir simple help

2006-02-18 Thread m . wanstall
Hi there,

I'm totally new to Python and was wondering why I was getting an error
for this. I'm just trying to create a folder based on user input:

import os

def setupProject(project):
os.mkdir(project)
os.chdir(project)

test = input("Please enter project name: ")
setupProject(test)

If I enter "roger" as my input I get : NameError: name 'roger' is not
defined

I know it's incredibly simple but help would be much appreciated!
Thanks in advance!

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: - Copy dictionary entries to attributes

2006-02-18 Thread Alex Martelli
Ben Wilson <[EMAIL PROTECTED]> wrote:

> Perhaps:
> 
> def dictionary_make_attributes(self, settings):
>  for k,v in settings:
>  setattr(self, k, v)

This is a very general solution and will work for all kinds of objects
with settable attributes, even if some of the attributes are properties,
slots or weirder descriptors yet.

For plain vanilla class instances, though,
  self.__dict__.update(settings)
may be sufficient.


Alex
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: aborting without killing the python interpreter

2006-02-18 Thread Robert Kern
Russ wrote:
> I wrote a simple little function for exiting with an error message:
> 
> def error ( message ): print_stack(); exit ("\nERROR: " + message +
> "\n")
> 
> It works fine for executing as a script, but when I run it
> interactively in the python interpreter it kills the interpreter.
> That's not what I want. Is there a simple way to have a script
> terminate but not have it kill the python interpreter when I run it
> interactively? I suspect I may need to use exceptions, but I'm hoping
> not to need them. Thanks.

Exceptions do *exactly* what you want in a very clean and simple way. They are a
fundamental feature of Python. Do not fear them. They are your friends.

-- 
Robert Kern
[EMAIL PROTECTED]

"In the fields of hell where the grass grows high
 Are the graves of dreams allowed to die."
  -- Richard Harter

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Any Tkinker based rich text widget?

2006-02-18 Thread Sullivan WxPyQtKinter
In addiiton, I hope it directly support basic HTML grammar.

[EMAIL PROTECTED] 写道:

> Hi all
> I am using the standard python GUI Tkinter as my program's main
> interface. Although I know wxPython has some widget to support rich
> text widget, but I do not have time to shift to wx series. Does
> anyone know any Tkinter based widget that support:
>
> 1. Blod, Italic, Underline and their combinations.
> 2. Several most commonly used fonts, like Times New Roman and Arial
> 3. Multiline text
> 4. Cross platform support. Available in Linux-RedHat and Mac OS series
> and Windows 2000 or above.
> 5.Image embedding. Support jpeg, gif, bmp. The more the better.
>
>
> and better support:
> Hyperlink, Text color, the more the better.
> 
> 
> Thank you so much for help!

-- 
http://mail.python.org/mailman/listinfo/python-list

Re: aborting without killing the python interpreter

2006-02-18 Thread Erik Max Francis
Terry Reedy wrote:

> How?  In the standard interpreter, 'exit' is bound to the string
> 'Use Ctrl-Z plus Return to exit.'
> so trying to call it as a function fails.

I'm _presuming_ there was a hidden `from sys import *` in there.  Hence 
calling exit with the string (the help for sys.exit shows that if a 
string is passed in, it will be printed before the process exits with 
failure -- something I wasn't aware of actually).

-- 
Erik Max Francis && [EMAIL PROTECTED] && http://www.alcyone.com/max/
San Jose, CA, USA && 37 20 N 121 53 W && AIM erikmaxfrancis
   God heals, and the doctor takes the fee.
   -- Benjamin Franklin
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python vs. Lisp -- please explain

2006-02-18 Thread gene tani

[EMAIL PROTECTED] wrote:

>
> I'm wondering if someone can explain to me please what it is about
> Python that is so different from Lisp that it can't be compiled into
> something as fast as compiled Lisp?  From this above website and
> others, I've learned that compiled Lisp can be nearly as fast as C/C++,
> so I don't understand why Python can't also eventually be as efficient?
>  Is there some *specific* basic reason it's tough?  Or is it that this
> type of problem in general is tough, and Lisp has 40+ years vs Python's
> ~15 years?
>
>

i'm not sure it'll answer question, but Brett cannon's thesis is good
background

http://www.ocf.berkeley.edu/~bac/thesis.pdf

-- 
http://mail.python.org/mailman/listinfo/python-list


Any Tkinker based rich text widget?

2006-02-18 Thread sullivanz . pku
Hi all
I am using the standard python GUI Tkinter as my program's main
interface. Although I know wxPython has some widget to support rich
text widget, but I do not have time to shift to wx series. Does
anyone know any Tkinter based widget that support:

1. Blod, Italic, Underline and their combinations.
2. Several most commonly used fonts, like Times New Roman and Arial
3. Multiline text
4. Cross platform support. Available in Linux-RedHat and Mac OS series
and Windows 2000 or above.
5.Image embedding. Support jpeg, gif, bmp. The more the better.


and better support:
Hyperlink, Text color, the more the better.


Thank you so much for help!

-- 
http://mail.python.org/mailman/listinfo/python-list


Any Tkinker bases rich text widget?

2006-02-18 Thread sullivanz . pku
Hi all
I am using the standard python GUI Tkinter as my program's main
interface. Although I know wxPython has some widget to support rich
text widget, but I do not have time to shift to wx series. Does
anyone know any Tkinter based widget that support:

1. Blod, Italic, Underline and their combinations.
2. Several most commonly used fonts, like Times New Roman and Arial
3. Multiline text
4. Cross platform support. Available in Linux-RedHat and Mac OS series
and Windows 2000 or above.
5.Image embedding. Support jpeg, gif, bmp. The more the better.

and better support:
Hyperlink, Text color, the more the better.

Thank you so much for help!

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: aborting without killing the python interpreter

2006-02-18 Thread Terry Reedy


"Terry Reedy" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> How?  In the standard interpreter, 'exit' is bound to the string
> 'Use Ctrl-Z plus Return to exit.'

This is, of course, Windows specific.  Other systems have other strings. 



-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python vs. Lisp -- please explain

2006-02-18 Thread Terry Reedy

<[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> In learning Python I've read more about Lisp than when I was actually
> trying to learn it, and it seems that the two languages have lots of
> similarities:
>
> http://www.norvig.com/python-lisp.html
>
> I'm wondering if someone can explain to me please what it is about
> Python that is so different from Lisp that it can't be compiled into
> something as fast as compiled Lisp?  From this above website and
> others, I've learned that compiled Lisp can be nearly as fast as C/C++,

In order to be that fast, some of the dynamism of intepreted Lisp must be 
given up.  In particular object code is not list data.  Python with 
type-dynamism eliminated can also be translated to decent C/C++ and then 
compiled.  See PyRex and Weave.  There is also Psyco, which I believe 
translates directly to machine code.

> so I don't understand why Python can't also eventually be as efficient?
> Is there some *specific* basic reason it's tough?  Or is it that this
> type of problem in general is tough, and Lisp has 40+ years vs Python's
> ~15 years?

Yes, *much* more work has gone into Lisp than Python.  (At least 10x, I am 
sure. and maybe up to 100x)  During the 1980s, there was a Lisp/AI 
boom/bust something like the dot.com boom/bust of the last 1990s with 
perhaps a billion invested in Lisp/AI companies.  I presume some of that 
went into Lisp itself (as opposed to AI applications thereof).

Terry Jan Reedy



-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python vs. Lisp -- please explain

2006-02-18 Thread DH
[EMAIL PROTECTED] wrote:
> A few years ago I
> had an AI class where we had to use Lisp, and I absolutely hated it,
> having learned C++ a few years prior.  They didn't teach Lisp at all
> and instead expected us to learn on our own.

CS classes haven't changed, I see.

> In learning Python I've read more about Lisp than when I was actually
> trying to learn it, and it seems that the two languages have lots of
> similarities:
> 
> http://www.norvig.com/python-lisp.html
> 
> I'm wondering if someone can explain to me please what it is about
> Python that is so different from Lisp that it can't be compiled into
> something as fast as compiled Lisp?  From this above website and
> others, I've learned that compiled Lisp can be nearly as fast as C/C++,
> so I don't understand why Python can't also eventually be as efficient?
>  Is there some *specific* basic reason it's tough?  Or is it that this
> type of problem in general is tough, and Lisp has 40+ years vs Python's
> ~15 years?

It is by design. Python is dynamically typed.  It is essentially an 
interpreted scripting language like javascript or ruby or perl, although 
python fans will be quick to tell you python is compiled to byte code. 
They'll also be quick to tell you:
-python has true closures (although nothing like ruby's blocks)
-is beginner friendly (despite being case sensitive and 3/4==0, for example)
-is not, in fact, slow at all (despite benchmarks as you noted showing 
otherwise).
Judge for yourself.

There are projects that combine static typing + the python syntax, which
result in dramatically faster code, but perhaps only 80% of python's
functionality and less flexibility you get from dynamic typing. 
Projects like shedskin.  But some python fans don't think 80% cuts it, 
even if you do get a 100 fold speed increase.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Seaching Active Directory via ADO

2006-02-18 Thread LittlePython
With help I have been able to put together a little example. It illustrates
several different ways..


import win32com.client

c = win32com.client.Dispatch("ADODB.Connection")
c.Open("Provider=ADSDSOObject")

##Check if connected to AD
if bool(c.state): print "Connected to AD"

## This uses sql dialect with no command object
##rs,rc=c.Execute("""
##SELECT adspath, title, name
##From 'LDAP://DC=AD,DC=LOCAL'
##where objectCategory='Person' and objectClass='user' and name='*'
##""")

##This uses ADSI dialect with not command object
##rs,rc=c.Execute("""
##;\
##(&(objectCategory=Person)(objectClass=user)(name=*));\
##name,adspath,title;\
##subtree
##""")

##Command com with properties in sql dialect
##comm = win32com.client.Dispatch("ADODB.Command")
##comm.ActiveConnection = c
##comm.Properties('Page size').value=1000
##comm.CommandText = ("""\
##SELECT adspath, title, name \
##From 'LDAP://DC=AD,DC=LOCAL' \
##where objectCategory='Person' and objectClass='user' and name='*'\
##""")
##rs,rc=comm.Execute()

##Command com with properties in ADSI dialect
##ADS_SCOPE_SUBTREE = 2
##ADS_SCOPE_ONELEVEL = 1
##ADS_SCOPE_BASE = 0
##comm = win32com.client.Dispatch("ADODB.Command")
##comm.ActiveConnection = c
##comm.Properties('Page size').value=1000
##comm.Properties('searchscope').value=ADS_SCOPE_SUBTREE
##comm.CommandText = (""";\
##(&(objectCategory=Person)(objectClass=user)(name=*));\
##name,adspath,title;""")
##rs,rc=comm.Execute()

##Connect using recordset object in ADSI Dialect
##rs = win32com.client.Dispatch("ADODB.recordset")
##rs.ActiveConnection = c
##rs.source = (""";\
##(&(objectCategory=Person)(objectClass=user)(name=*));\
##name,adspath,title;\
##subtree""")
##rs.Open()

##Connect using recordset object in sql Dialect
##rs = win32com.client.Dispatch("ADODB.recordset")
##rs.ActiveConnection = c
##rs.source = ("""\
##SELECT adspath, title, name \
##From 'LDAP://DC=AD,DC=LOCAL' \
##where objectCategory='Person' and objectClass='user' and name='*'\
##""")
##rs.Open()

##while not rs.EOF:
##for f in rs.Fields:
##print f.Name, f.Value
##rs.MoveNext()

c.close
c = None




-- 
http://mail.python.org/mailman/listinfo/python-list


Re: aborting without killing the python interpreter

2006-02-18 Thread Terry Reedy

"Russ" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
>I wrote a simple little function for exiting with an error message:
>
> def error ( message ): print_stack(); exit ("\nERROR: " + message +
> "\n")
>
> It works fine for executing as a script,

How?  In the standard interpreter, 'exit' is bound to the string
'Use Ctrl-Z plus Return to exit.'
so trying to call it as a function fails.

 but when I run it
> interactively in the python interpreter it kills the interpreter.
> That's not what I want. Is there a simple way to have a script
> terminate but not have it kill the python interpreter when I run it
> interactively? I suspect I may need to use exceptions, but I'm hoping
> not to need them. Thanks.

The interactive interpreter runs a statement at a time and gives a prompt 
after any output.  From a command shell, you can use a flag (-i I think) to 
enter interactive mode after the script end.

Terry Jan Reedy



-- 
http://mail.python.org/mailman/listinfo/python-list


Re: strange error I can't figure out...

2006-02-18 Thread Brian Beck
John Zenger wrote:
> Also, get rid of the comma at the end of that last print statement.

This would break the progress bar functionality I think, which is meant 
to update a single line.

-- 
Brian Beck
Adventurer of the First Order
-- 
http://mail.python.org/mailman/listinfo/python-list


Python vs. Lisp -- please explain

2006-02-18 Thread 63q2o4i02
Hi, I've been thinking about Python vs. Lisp.  I've been learning
Python the past few months and like it very much.  A few years ago I
had an AI class where we had to use Lisp, and I absolutely hated it,
having learned C++ a few years prior.  They didn't teach Lisp at all
and instead expected us to learn on our own.  I wasn't aware I had to
uproot my thought process to "get" it and wound up feeling like a
moron.

In learning Python I've read more about Lisp than when I was actually
trying to learn it, and it seems that the two languages have lots of
similarities:

http://www.norvig.com/python-lisp.html

I'm wondering if someone can explain to me please what it is about
Python that is so different from Lisp that it can't be compiled into
something as fast as compiled Lisp?  From this above website and
others, I've learned that compiled Lisp can be nearly as fast as C/C++,
so I don't understand why Python can't also eventually be as efficient?
 Is there some *specific* basic reason it's tough?  Or is it that this
type of problem in general is tough, and Lisp has 40+ years vs Python's
~15 years?


Thanks
Michael

-- 
http://mail.python.org/mailman/listinfo/python-list


aborting without killing the python interpreter

2006-02-18 Thread Russ
I wrote a simple little function for exiting with an error message:

def error ( message ): print_stack(); exit ("\nERROR: " + message +
"\n")

It works fine for executing as a script, but when I run it
interactively in the python interpreter it kills the interpreter.
That's not what I want. Is there a simple way to have a script
terminate but not have it kill the python interpreter when I run it
interactively? I suspect I may need to use exceptions, but I'm hoping
not to need them. Thanks.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Multiplication optimization

2006-02-18 Thread Jean-Paul Calderone
On 18 Feb 2006 16:48:38 -0800, Paul McGuire <[EMAIL PROTECTED]> wrote:
>Does Python's run-time do any optimization of multiplication
>operations, like it does for boolean short-cutting?

Here's the beginning of int_mul from Objects/intobject.c:

static PyObject *
int_mul(PyObject *v, PyObject *w)
{
long a, b;
long longprod;  /* a*b in native long arithmetic */
double doubled_longprod;/* (double)longprod */
double doubleprod;  /* (double)a * (double)b */

CONVERT_TO_LONG(v, a);
CONVERT_TO_LONG(w, b);
longprod = a * b;
doubleprod = (double)a * (double)b;
doubled_longprod = (double)longprod;

I think the rest of the function is probably irrelevant, as far as your 
question goes.

Jean-Paul
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: - Copy dictionary entries to attributes

2006-02-18 Thread Ben Wilson
Perhaps:

def dictionary_make_attributes(self, settings):
 for k,v in settings:
 setattr(self, k, v)

http://ftp.python.org/doc/lib/built-in-funcs.html#l2h-64

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Get parameters from URL using CGI

2006-02-18 Thread abcd
Ian Leitch wrote:
> >>> from urlparse import urlparse
> >>> dict([n for n in [i.split('=') for i in
> urlparse('http://www.somesite.com/cgi-bin/foo.cgi?name=john&age=90')[4].split('&')]])
> {'age': '90', 'name': 'john'}


Ian,  thanks for the reply, but that is not what I need to do.  Inside
foo.cgi how can I parse out the values given in the URL?

So if you visit: http://www.somesite.com/cgi-bin/foo.cgi?valA=1&valB=2
.I want the script, foo.cgi to print out the parameters and their
values.  It's dynamic so the values are url wont be the same all the
time.  How do i get the URL from the script?  does this make sense?

So I'm thinking foo.cgi will look like
[code]
url = getTheFullURL()
parse(url)

def parse(url):
# parse the parameter names and values
[/code]

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: define loop statement?

2006-02-18 Thread Benji York
David Isaac wrote:
> I would like to be able to define a loop statement
> (nevermind why) so that I can write something like
> 
> loop 10:
> do_something

Here's a flagrant hack:

import sys

VAR_NAME = '__repeat_counter'

def set_repeat_counter(value):
 frame = sys._getframe(2)
 frame.f_locals[VAR_NAME] = value

def get_repeat_counter(value):
 frame = sys._getframe(2)
 if VAR_NAME not in frame.f_locals:
 frame.f_locals[VAR_NAME] = value

 return frame.f_locals[VAR_NAME]

def repeat(limit):
 set_repeat_counter(get_repeat_counter(limit)-1)
 return get_repeat_counter(limit)

while repeat(10):
 print 'OK'

Without more work it doesn't allow nested loops though.

And for the record, if you're worrying about Python's counted loop 
construct you need better things to worry about. 

--
Benji York
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Multiplication optimization

2006-02-18 Thread Raymond Hettinger
[Paul McGuire]
> Does Python's run-time do any optimization of multiplication
> operations, like it does for boolean short-cutting?

Usually, it is safest (and typically true) to assume that Python
performs no optimizations.  To go beyond making assumptions, it is easy
to run a few timings:

>>> from timeit import Timer
>>> min(Timer('0*1234567').repeat(5))
0.11315376674968469
>>> min(Timer('1*1234567').repeat(5))
0.11920453577200618
>>> min(Timer('113*1234567').repeat(5))
0.11881482143680699

In your specific case, I can answer than the source shows no special
optimization for multiplications by specific values.  There is a
short-path for integer multiplications but it is not value specific.
In Py2.5, the compiler will do a limited amount of constant folding;
however, its scope is somewhat limited because expressions like a*3
vary depending on the a's type which is often not knowable by the
compiler without some form of global analysis.

One other thought:  Python is not assembly.  Run time is unlikely to be
dominated by the time to execute a multiplication.  With Python, it is
best to focus optimization efforts on making choosing the best data
structures and hoisting constants out of loops.


Raymond

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Multiplication optimization

2006-02-18 Thread Steven D'Aprano
On Sat, 18 Feb 2006 16:48:38 -0800, Paul McGuire wrote:

> Does Python's run-time do any optimization of multiplication
> operations, like it does for boolean short-cutting?

Do you know that these shortcuts are optimizations, or are you just
assuming it takes less time to do the comparison than it would for the
CPU to blast bits around?

I have no idea whether your shortcuts are optimizations or pessimizations.
I'm just asking whether you know, or if you are making assumptions.


-- 
Steven.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: 2-dimensional data structures

2006-02-18 Thread Kirk McDonald
anthonyberet wrote:
> Thanks for the advice (to everyone in the thread).
> I think I will go with nested lists.
> However, I am running into a conceptual problem.
> My approach will be firstly to remove all the impossible digits for a 
> square by searching the row and column for other occurances.
> 
> However, I wondering how to approach the search of the nine regions of 
> the grid. I am thinking of producing another nested list, again 9x9 to 
> store the contents of each region, and to update this after each pass 
> through -and update of- the main grid (row and column).
> 
> I am not sure how to most efficiently identify which region any given 
> square on the grid is actually in - any thoughts, for those that have 
> done this? - I don't want a massive list of IF conditionals if I can 
> avoid it.
> 

When I wrote my Sudoku solver (a terribly inefficient and naive 
recursive algorithm that I originally wrote in C++ and was the first 
thing I ever wrote in Python), I used numarray. It allows 
two-dimensional slicing:

def inBlock(x, y, val):
 blockX = x/size * size
 blockY = y/size * size

 return val in sudoku[blockX:blockX+size, blockY:blockY+size]

'size' in this example is a global variable equal to the size of the 
puzzle, so 3 for a normal puzzle. 'sudoku' is a global two-dimensional 
array simply holding the values in the puzzle.

(There are any number of things in this can be improved, such as using 
the // floor division operator rather than /, not using global 
variables, and so on. What can I say? It was a straight conversion from 
C++. I hardly knew what "Pythonic" meant.)

-Kirk McDonald
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: ANN: Release of NumPy 0.9.5

2006-02-18 Thread Travis E. Oliphant
vinjvinj wrote:
> I read some of the earlier threads which essentially said that numpy is
> about 3-4 times slower then Numeric for smaller arrays. I'm assuming
> that applies only to operations that apply to the whole arrays.
> 
> I was curious how the performance of the following operations would
> compare though:
> 1. Copying arrays
> 2. Creating arrays
> 3. Slicing Arrays
> 

It is really hard to say unless you show specific applications:

But, here are some facts.

1) NumPy is in C just like Numeric
2) NumPy is more flexible than Numeric and that means a few more 
if-statements and checks which can slow-down array creation and slicing.
3) Some optimizations have been done to remove unnecessary slowness 
(e.g. unnecessary checking but more could be done).

4) Ufuncs have more overhead primarily because of

 a) the ability to alter how errors are obtained using local / 
global variables (these must be looked-up in a dictionary which is most 
of the source of any performance penalty),
 b) the ability for other objects that can be converted to arrays to 
interact with ufuncs so that the original object is returned by the ufuncs
 c) the fact that excessive copying is not done in order to 
type-cast from one array to annother, this requires some "set-up" overhead

My understanding is that most of the "slow-downs" reported for small 
arrays can be attributed to ufuncs, but there will be slower paths 
through the C-code for other cases as well because of the increased 
flexibility.

Our goal is to be as fast as we can be so give it a spin and tell us how 
to improve...

Thanks,

-Travis

-- 
http://mail.python.org/mailman/listinfo/python-list


Multiplication optimization

2006-02-18 Thread Paul McGuire
Does Python's run-time do any optimization of multiplication
operations, like it does for boolean short-cutting?  That is, for a
product a*b, is there any shortcutting of (potentially expensive)
multiplication operations as in:

if a == 0
return 0
if a == 1
return b
return a*b

Of course, for the cases where a is not 0 or 1 we are adding two
comparisons to each multiply operation.  But in some applications
(sparse matrices? binary conversion?), the multiplication step could be
avoided in many cases, if the user was aware that left-to-right
short-cutting were implemented.

Or by adding two *more* comparisons, then all multiplications would be
"optimized":

if a == 0 or b == 0
return 0
if a == 1
return b
if b == 1
return a
return a*b

But this seems overkill, especially since boolean short-cutting only
works left-to-right.

Just curious...

-- Paul

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: define loop statement?

2006-02-18 Thread Felipe Almeida Lessa
Em Dom, 2006-02-19 às 11:08 +1100, Nigel Rowe escreveu:
> Felipe Almeida Lessa wrote:
> 
> > Em Sáb, 2006-02-18 às 20:04 +, Jeffrey Schwab escreveu:
> >> if __name__ == '__main__':
> >> loop = Loop(10)
> >> while loop:
> >> print "OK"
> > 
> > Maybe:
> > 
> > while Loop(10)():
> > print "OK"
> > 
> > Looks rather ugly but requires one less line ;-).
> > 
> Doesn't work.  You get a NEW Loop(10) instance on each pass through the
> 'while'.  This is just an expensive way to make an endless loop.

Oh, sorry, ignore me on that one. Now I think I should sleep =S...

-- 
"Quem excele em empregar a força militar subjulga os exércitos dos
outros povos sem travar batalha, toma cidades fortificadas dos outros
povos sem as atacar e destrói os estados dos outros povos sem lutas
prolongadas. Deve lutar sob o Céu com o propósito primordial da
'preservação'. Desse modo suas armas não se embotarão, e os ganhos
poderão ser preservados. Essa é a estratégia para planejar ofensivas."

  -- Sun Tzu, em "A arte da guerra"

-- 
http://mail.python.org/mailman/listinfo/python-list

Re: define loop statement?

2006-02-18 Thread Nigel Rowe
Felipe Almeida Lessa wrote:

> Em Sáb, 2006-02-18 às 20:04 +, Jeffrey Schwab escreveu:
>> if __name__ == '__main__':
>> loop = Loop(10)
>> while loop:
>> print "OK"
> 
> Maybe:
> 
> while Loop(10)():
> print "OK"
> 
> Looks rather ugly but requires one less line ;-).
> 
Doesn't work.  You get a NEW Loop(10) instance on each pass through the
'while'.  This is just an expensive way to make an endless loop.

-- 
Nigel Rowe
A pox upon the spammers that make me write my address like..
rho (snail) swiftdsl (stop) com (stop) au
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: general coding issues - coding style...

2006-02-18 Thread Justin Azoff
Dylan Moreland wrote:
> I would look into one of the many Vim scripts which automatically fold
> most large blocks without the ugly {{{.

Who needs a script?
"set foldmethod=indent"
works pretty well for most python programs.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: 2-dimensional data structures

2006-02-18 Thread [EMAIL PROTECTED]

anthonyberet wrote:
> Tim Chase wrote:
> >> I want to work on a sudoku brute-forcer, just for fun.
> >
> >
> > Well, as everybody seems to be doing these (self included...), the
> > sudoku solver may become the "hello world" of the new world :)
> >
> >> What is the equivalent way to store data in python? - It isn't obvious
> >> to me how to do it with lists.
> >
> >
> > Several other answers have crossed the list.  I've done it using a
> > dictionary of tuples:
> >
> > grid = {}
> > for row in range(1,10):
> > for col in range(1,10):
> > grid[(row,col)] = value
> >
> > item = grid[(3,2)]
> >
> > etc.
> >
> > Seemed fairly quick and worked for me.
> >
> Thanks for the advice (to everyone in the thread).
> I think I will go with nested lists.
> However, I am running into a conceptual problem.
> My approach will be firstly to remove all the impossible digits for a
> square by searching the row and column for other occurances.
>
> However, I wondering how to approach the search of the nine regions of
> the grid. I am thinking of producing another nested list, again 9x9 to
> store the contents of each region, and to update this after each pass
> through -and update of- the main grid (row and column).
>
> I am not sure how to most efficiently identify which region any given
> square on the grid is actually in - any thoughts, for those that have
> done this? - I don't want a massive list of IF conditionals if I can
> avoid it.

Here's another way:


def region_map():
for row in range(9):
for col in range(9):
region = (row/3,col/3)
print region,
print

def identify_region(cell):
return (cell[0]/3,cell[1]/3)

def create_regions():
regions = {}
for row in range(9):
for col in range(9):
rowcol = (row,col)
reg = (row/3,col/3)
if regions.has_key(reg):
regions[reg].append(rowcol)
else:
regions[reg] = [rowcol]
return regions


grid = [[0,0,6,0,7,0,0,0,0], \
[0,3,5,4,0,0,0,9,0], \
[0,0,0,0,0,6,1,2,0], \
[0,0,0,0,0,3,2,0,8], \
[0,0,0,0,6,0,0,0,0], \
[4,0,7,2,0,0,0,0,0], \
[0,5,2,1,0,0,0,0,0], \
[0,7,0,0,0,5,9,1,0], \
[0,0,0,0,4,0,3,0,0]]

print 'the grid:'
for g in grid: print g
print

print 'the region ids:'
region_map()
print

# create the region dictionary
regions = create_regions()

# pick an arbitrary cell
cell = (5,5)
reg_id = identify_region(cell)

print 'cell:',cell,'is in region:',reg_id
print

print 'region',reg_id,'contains:'

reg_data = regions[reg_id]
for c in reg_data:
print grid[c[0]][c[1]],


"""

the grid:
[0, 0, 6, 0, 7, 0, 0, 0, 0]
[0, 3, 5, 4, 0, 0, 0, 9, 0]
[0, 0, 0, 0, 0, 6, 1, 2, 0]
[0, 0, 0, 0, 0, 3, 2, 0, 8]
[0, 0, 0, 0, 6, 0, 0, 0, 0]
[4, 0, 7, 2, 0, 0, 0, 0, 0]
[0, 5, 2, 1, 0, 0, 0, 0, 0]
[0, 7, 0, 0, 0, 5, 9, 1, 0]
[0, 0, 0, 0, 4, 0, 3, 0, 0]

the region ids:
(0, 0) (0, 0) (0, 0) (0, 1) (0, 1) (0, 1) (0, 2) (0, 2) (0, 2)
(0, 0) (0, 0) (0, 0) (0, 1) (0, 1) (0, 1) (0, 2) (0, 2) (0, 2)
(0, 0) (0, 0) (0, 0) (0, 1) (0, 1) (0, 1) (0, 2) (0, 2) (0, 2)
(1, 0) (1, 0) (1, 0) (1, 1) (1, 1) (1, 1) (1, 2) (1, 2) (1, 2)
(1, 0) (1, 0) (1, 0) (1, 1) (1, 1) (1, 1) (1, 2) (1, 2) (1, 2)
(1, 0) (1, 0) (1, 0) (1, 1) (1, 1) (1, 1) (1, 2) (1, 2) (1, 2)
(2, 0) (2, 0) (2, 0) (2, 1) (2, 1) (2, 1) (2, 2) (2, 2) (2, 2)
(2, 0) (2, 0) (2, 0) (2, 1) (2, 1) (2, 1) (2, 2) (2, 2) (2, 2)
(2, 0) (2, 0) (2, 0) (2, 1) (2, 1) (2, 1) (2, 2) (2, 2) (2, 2)

cell: (5, 5) is in region: (1, 1)

region (1, 1) contains:
0 0 3 0 6 0 2 0 0


"""

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: general coding issues - coding style...

2006-02-18 Thread Dylan Moreland

calmar wrote:
> On 2006-02-18, Diez B. Roggisch <[EMAIL PROTECTED]> wrote:
> >   - why are these {{{ thingies there?
>
> markers for folding for vim
> http://www.calmar.ws/tmp/sc.png

I would look into one of the many Vim scripts which automatically fold
most large blocks without the ugly {{{.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: general coding issues - coding style...

2006-02-18 Thread plahey
Hi,

1585 if sys.path[0][-12:] == "\library.zip":  #for py2exe

how about

if sys.path[0].endswith( "\\library.zip" ):

(did you really mean one back-slash there?)


499 tuple = os.path.split(filename)

bad variable name... tuple(x) converts a sequence to a tuple.


You have a number of places where you check for len(x)==0:

674 if len(files) == 0:
853 if len(file_show) == 0:
950 if len(imgprocess["files_todo"]) == 0:

people usually recommend:

if not files:
if not file_show:
if not imgprocess["files_todo"]:


you should run your code through pychecker (it had a lot to say...).


You use global alot... that should be a red flag.  Like the poster
above mentioned,  you have things that are telling you they want to
be objects.


The #{{{ and #}}} stuff is very annoying to other programmers
(ok, to me...).  You might want to investigate a Python aware
editor (like SPE, which has pychecker built in).  This is
coming from someone who uses vim regularly.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: define loop statement?

2006-02-18 Thread Felipe Almeida Lessa
Em Sáb, 2006-02-18 às 20:04 +, Jeffrey Schwab escreveu:
> if __name__ == '__main__':
>   loop = Loop(10)
>   while loop:
>   print "OK"

Maybe:

while Loop(10)():
print "OK"

Looks rather ugly but requires one less line ;-).

-- 
"Quem excele em empregar a força militar subjulga os exércitos dos
outros povos sem travar batalha, toma cidades fortificadas dos outros
povos sem as atacar e destrói os estados dos outros povos sem lutas
prolongadas. Deve lutar sob o Céu com o propósito primordial da
'preservação'. Desse modo suas armas não se embotarão, e os ganhos
poderão ser preservados. Essa é a estratégia para planejar ofensivas."

  -- Sun Tzu, em "A arte da guerra"

-- 
http://mail.python.org/mailman/listinfo/python-list

Re: define loop statement?

2006-02-18 Thread David Isaac

> Alan Isaac wrote:
> > I would like to be able to define a loop statement
> > (nevermind why) so that I can write something like
> >
> > loop 10:
> > do_something
> >
> > instead of
> >
> > for i in range(10):
> > do_something
> >
> > Possible?  If so, how?


"Jeffrey Schwab" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> class Loop:
>  def __init__(self, n):
>   self.n = n
>  def __call__(self):
>   self.n = self.n - 1
>   return self.n != 0
>
>
> if __name__ == '__main__':
> loop = Loop(10)
> while loop():
>  print "OK"

OK, that's pretty good.
Thanks!
Alan Isaac


-- 
http://mail.python.org/mailman/listinfo/python-list


Re: 2-dimensional data structures

2006-02-18 Thread Diez B. Roggisch
Diez B. Roggisch schrieb:
> The question is not so much which region a give square is in, but more 
> which square contains which fields. If we assume that you number your 
> squares row-wise (top-left zero, top-right 3, bottom-right 9), this 
> function computes the field indices that a given square is composed of:

I'm confusing squares with fields here. What I meant by a square here is 
the 3x3 region, of which 9 exist. Each has 3x3=9 cells.

Diez
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: 2-dimensional data structures

2006-02-18 Thread Diez B. Roggisch
> However, I wondering how to approach the search of the nine regions of 
> the grid. I am thinking of producing another nested list, again 9x9 to 
> store the contents of each region, and to update this after each pass 
> through -and update of- the main grid (row and column).
> 
> I am not sure how to most efficiently identify which region any given 
> square on the grid is actually in - any thoughts, for those that have 
> done this? - I don't want a massive list of IF conditionals if I can 
> avoid it.

The question is not so much which region a give square is in, but more 
which square contains which fields. If we assume that you number your 
squares row-wise (top-left zero, top-right 3, bottom-right 9), this 
function computes the field indices that a given square is composed of:

def scoords(n):
 square_row = n / 3
 square_col = n % 3
 start_row = square_row * 3 # ( this is _not_ n!!)
 start_column = square_col * 3
 for x in xrange(start_column, start_column + 3):
 for y in xrange(start_row, start_row + 3):
 yield (x,y)

print list(coords(4))

Regards,

Diez
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Pyserial never read

2006-02-18 Thread luca72
Thanks for your help, but it don't solve the problem.
I receive only the echo and full stop.

Many Thanks

Best Regards

Luca

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: define loop statement?

2006-02-18 Thread Jeffrey Schwab
Jeffrey Schwab wrote:

> class Loop:
> def __init__(self, n):
> self.n = n
> def __call__(self):
> self.n = self.n - 1
> return self.n != 0
> 
> 
> if __name__ == '__main__':
> loop = Loop(10)
> while loop:

Whoops.  Should be "while loop()".

> print "OK"
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: 2-dimensional data structures

2006-02-18 Thread Kermit Rose






 
 

From: anthonyberet
Date: 02/18/06 17:11:01
To: python-list@python.org
Subject: Re: 2-dimensional data structures
 
 
I am not sure how to most efficiently identify which region any given
square on the grid is actually in - any thoughts, for those that have
done this? - I don't want a massive list of IF conditionals if I can
avoid it.
 
 
Kermit says:
 
There is a MUCH more efficient way to do this!
 
If you are doing a  9 by 9  soduku,
 
Each row and column has exactly the digits 1 through 9
 
Think of your data as being in a list 81 cells long that is accessed 3 different ways.
 
As a 9 by 9,  row wise,
 
As a 9 by 9  column wise
 
As a 3 by 3 by 9  where the first two subscripts identify the region, and the last identify one of
the 9 values within the region.
 
 
And ,  most important,
 
To search for a value not yet in a row, column, or region,
 
Define holding list of length 9.
 
Suppose a  row has 4,2,8 in it,
 
and the corresponding column has 2,3,1 in it
 
and the correspond region has 2,  7, 6 in it.
 
Then you  initialize your hold vector to -1,
 
and set
 
hold(4) = 4
hold(2) = 1
hold(8) = 1
hold(2) = 1
hold (3) = 1
hold(1) = 1
hold(2) = 1
hold(7) = 1
hold(6) = 1
 
Then by scaning only the nine elements of hold, you see that
 
hold(5) = -1, , and hold(9) = -1  are the only values not  reset, and 
 
only  5 and 9 are possible choices for the  target cell.
 
 
 
 
 
 
 







-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Tab Character?

2006-02-18 Thread Ben Finney
"[EMAIL PROTECTED]" <[EMAIL PROTECTED]> writes:
> How do I make a tab character in code to split a line read with tabs in
> it?

For such non-printing characters it's best not to have them literally
in your code, but to use an escape sequence to generate them at
run-time::

>>> foo = "\t"
>>> print foo

>>> print ord(foo)
9

This is explained in the "String literals" section of the Python
reference.

http://docs.python.org/dev/ref/strings.html>

-- 
 \   "A celebrity is one who is known by many people he is glad he |
  `\   doesn't know."  -- Henry L. Mencken |
_o__)  |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: share function argument between subsequent calls but not between class instances!

2006-02-18 Thread Ben Finney
Duncan Booth <[EMAIL PROTECTED]> writes:
> If you intend to only use the default some of the time, and at other
> times pass in a different list, then save the 'default' in the
> instance and use a special marker value to indicate when you intend
> the default to be used:

The most common idiom for such a marker is the None value.

class Test(object):
def __init__(self):
self.L = []
def f(self, a, L=None):
if L is None:
L = self.L
L.append(a)
return L

-- 
 \"Consider the daffodil. And while you're doing that, I'll be |
  `\   over here, looking through your stuff."  -- Jack Handey |
_o__)  |
Ben Finney 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: 2-dimensional data structures

2006-02-18 Thread anthonyberet
Tim Chase wrote:
>> I want to work on a sudoku brute-forcer, just for fun.
> 
> 
> Well, as everybody seems to be doing these (self included...), the 
> sudoku solver may become the "hello world" of the new world :)
> 
>> What is the equivalent way to store data in python? - It isn't obvious 
>> to me how to do it with lists.
> 
> 
> Several other answers have crossed the list.  I've done it using a 
> dictionary of tuples:
> 
> grid = {}
> for row in range(1,10):
> for col in range(1,10):
> grid[(row,col)] = value
> 
> item = grid[(3,2)]
> 
> etc.
> 
> Seemed fairly quick and worked for me.
> 
Thanks for the advice (to everyone in the thread).
I think I will go with nested lists.
However, I am running into a conceptual problem.
My approach will be firstly to remove all the impossible digits for a 
square by searching the row and column for other occurances.

However, I wondering how to approach the search of the nine regions of 
the grid. I am thinking of producing another nested list, again 9x9 to 
store the contents of each region, and to update this after each pass 
through -and update of- the main grid (row and column).

I am not sure how to most efficiently identify which region any given 
square on the grid is actually in - any thoughts, for those that have 
done this? - I don't want a massive list of IF conditionals if I can 
avoid it.


-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Tab Character?

2006-02-18 Thread John Zenger
Tab is \t .  As in:

print "coke\tpepsi"
tsvline.split("\t")

[EMAIL PROTECTED] wrote:
> How do I make a tab character in code to split a line read with tabs in
> it?
> 
> 
> Thanks.
> 
> Tom
> 
-- 
http://mail.python.org/mailman/listinfo/python-list


Tab Character?

2006-02-18 Thread [EMAIL PROTECTED]
How do I make a tab character in code to split a line read with tabs in
it?


Thanks.

Tom

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Get parameters from URL using CGI

2006-02-18 Thread Ian Leitch
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

abcd wrote:
> i want to create a CGI script which simply prints out values given via
> the URL (such as when a GET is performed).
> 
> So if I have a script named, foo.cgi and I access it by going to:
> 
> http://www.somesite.com/cgi-bin/foo.cgi?name=john&age=90
> 
> I want foo.cgi to print out:
> name: john
> age: 90
> 
> 
> how do i get the values from the URL like that?
> 
> thanks

>>> from urlparse import urlparse
>>> dict([n for n in [i.split('=') for i in
urlparse('http://www.somesite.com/cgi-bin/foo.cgi?name=john&age=90')[4].split('&')]])
{'age': '90', 'name': 'john'}
>>>

-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.1 (GNU/Linux)

iD8DBQFD94zrefZ4eWAXRGIRAlEhAJ49x7kaIe/VcU5DUbt8bv9tQCNrmQCfWOED
tmkTISLqzIKDz2c4mfR6+k8=
=OMOX
-END PGP SIGNATURE-
-- 
http://mail.python.org/mailman/listinfo/python-list


Tkinter / Aqua (OS X) question (canvas borders)

2006-02-18 Thread [EMAIL PROTECTED]
This is a beginner question.  I am using a Mac running OS X.  I have
TclTkAqua installed.  If I type:

import Tkinter

r = Tkinter.Tk()
c = Tkinter.Canvas(r)
c.pack()
c.create_line(0,0,100,0)

the line is not visible.  If I type:

c.create_line(3,4,100,4)

the line is visiable.  There appears to be an asymmetric "border"
around the inside of the canvas.  If I type

print c.cget('padx'), c.cget('pady')

I get zero.  How do I find out the size of the border?  Is this
specific to the Aqua version of Tk?

I have X Windows installed.  Would I be better off if I down loaded the
Unix version of Tk and Tkinter/python and compiled it for X?

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: define loop statement?

2006-02-18 Thread Georg Brandl
Jeffrey Schwab wrote:

> class Loop:
>   def __init__(self, n):
>   self.n = n
>   def __call__(self):
>   self.n = self.n - 1
>   return self.n != 0
> 
> 
> if __name__ == '__main__':
>   loop = Loop(10)
>   while loop:
>   print "OK"

Seems you forgot "()" after "while loop" above.

Georg
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: define loop statement?

2006-02-18 Thread Jeffrey Schwab
David Isaac wrote:
> I would like to be able to define a loop statement
> (nevermind why) so that I can write something like
> 
> loop 10:
> do_something
> 
> instead of
> 
> for i in range(10):
> do_something
> 
> Possible?  If so, how?

Ruby and Smalltalk are both good at this kind of thing, since they have 
syntactic support for associating a block with each method call.  In 
Python, I think you just have to do a little more setup.  How about 
something like this?

class Loop:
def __init__(self, n):
self.n = n
def __call__(self):
self.n = self.n - 1
return self.n != 0


if __name__ == '__main__':
loop = Loop(10)
while loop:
print "OK"
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Should we still be learning this?

2006-02-18 Thread B Mahoney
I was initally annoyed that "Dive into Python" has the UserDict, but it
was so
easy to discover it was deprecated
http://docs.python.org/lib/module-UserDict.html
(althought the term 'deprecated' is not specifically used), that anyone
on the
ball (the OP seemed to know) would not based their next big project on
UserDict.

I agree that Python has so many good concepts, and improvements with
each new version, that something in a course will be outdated. I can
concur
that knowing Python made it much easier to go back to C++ and Java and
understand the OO.

My tip for an book on Python with only the latest information, nothing
beats the Python Pocket Reference, 3rd edition,  (O'Reilly) which
is updated for  2.4 and seems to clearly label any deprecated features.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Numpy for PythonCE

2006-02-18 Thread Robert Kern
"G���" wrote:
> Hi,
> is there a version of Numpy (or Numarray) available
> that is compatible to PythonCE 2.3? 

I haven't heard of anyone trying. Perhaps you could try compiling the latest SVN
of numpy and tell us how it goes on [EMAIL PROTECTED] .

-- 
Robert Kern
[EMAIL PROTECTED]

"In the fields of hell where the grass grows high
 Are the graves of dreams allowed to die."
  -- Richard Harter

-- 
http://mail.python.org/mailman/listinfo/python-list

Re: PyProtocols, Components, and Inheritance

2006-02-18 Thread Terry Hancock
On Thu, 16 Feb 2006 23:53:51 -0600
Terry Hancock <[EMAIL PROTECTED]> wrote:
> I've been discussing PyProtocols with a a friend
> collaborating with me on a SF game project, about
> the benefits and design concept of "component
> architecture", and I'm a little confused by what I'm
> learning.
> [...]

Nevermind, he explained what he was doing -- it isn't
a PyProtocols issue after all.

He wanted components to be bound dynamically to
individual objects.  I agree with him that it's a useful
thing in this application.  It's still weird, but I
see why he wants it.

Now, I just have to figure out how to document it
clearly. ;-)

Thanks anyway,
Terry


-- 
Terry Hancock ([EMAIL PROTECTED])
Anansi Spaceworks http://www.AnansiSpaceworks.com

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python 3000 deat !? Is true division ever coming ?

2006-02-18 Thread Steve Holden
[EMAIL PROTECTED] wrote:
> Thank you very much, Magnus !
> This is the answer I had been waiting for:
> 
>>A problem as I see it today, is that this behaviour is
>>not actively encouraged. The tutorial, which is maintained
>>and updated, still describes old style classes, and the
>>old division behaviour.
> 
> 
> My main point was/is:  why is there not more discussion about "true
> division" !!?

You are about three years too late for the discussion. It was debated to 
death when Guido proposed that Python should behave more like 
non-programmers expected it to. Despite some fierce opposition this view 
eventually held sway, and now long-time Pythonistas accept it as the way 
forward.

So basically most people saw your question and probably thought "enough, 
already!".

> Just like the second answer to my posting clearly showed:
> PEOPLE THINK TRUE DIVISION IS "ONLY IN MATLAB"  !!
> 
> As you pointed out: the "true division" part of "Python3000" might be
> one of the "scariest" and should therefore be pointed out already in
> the tutorial !!  (It would look quite ugly to newcomers, though)
> 
> Having said that:  I would vote against EVER introducing true division
> as default - because it will just PISS too many (long time python)
> people OFF. ;-)
> 
I think you underestimate the power of the Python community to adapt to 
change when it's necessary for the long-term benefit of the language.

> Thanks,
> Sebastian Haase
> 
[...]

regards
  Steve
-- 
Steve Holden   +44 150 684 7255  +1 800 494 3119
Holden Web LLC www.holdenweb.com
PyCon TX 2006  www.python.org/pycon/

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Twisted book opinions?

2006-02-18 Thread Jacob Hallen
In article <[EMAIL PROTECTED]>,
Andrew Gwozdziewycz  <[EMAIL PROTECTED]> wrote:
>> It's really more of an example based tutorial book than cookbook.
>> What it does do really well is 'networking programming essentials'. I
>> found it quite a good book and managed to write a distributed ssh cron
>> tool in an evening after reading the sections on SSH.
>
>I would second that. The examples are very good, and it breaks down
>the code and explains the new concepts.
>
>> What I'd really like now is a 'Web Application Development with
>> Twisted/Nevow' book that takes off where this 'network protocol'
>> oriented book leaves off.
>
>I thought the O'Reilly book was pretty decent at describing how to
>setup a web application. It's not entirely complete, but I was able to
>piece together an application with a somewhat complex web application
>on top of it. Twisted made it quite easy.

The book does Twisted basics very well. The examples are many and they are
just the right size for grasping how to do things.

My only gripe is that the way it produces HTML code in the web examples
is very primitive. You should be using Stan (a very Pythonic DOM) instead
of the explicit strings that are used throughout the book. Fortunately
there is an on-line tutorial for Stan, which is very good.

http://www.kieranholland.com/code/documentation/nevow-stan/

Jacob Hallén

-- 
-- 
http://mail.python.org/mailman/listinfo/python-list

Making mouse wheel work with pmw ScrolledCanvas widget

2006-02-18 Thread dan . gass
Hi,

I am using the pmw tkinter package and having trouble getting the
ScrolledCanvas widget to respond to the mouse wheel.  I am running
Windows XP.  I've Googled it and came up empty.  I believe it should be
possible because Idle's editor window supports scrolling with a mouse
wheel.

Thanks in advance,

Dan Gass

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: commenting out blocks of code

2006-02-18 Thread Steve Holden
Steven D'Aprano wrote:
> On Fri, 17 Feb 2006 19:12:01 -0500, Peter Hansen wrote:
> 
> 
>>john peter wrote:
>>
>>>is there a similar mechanism in python, other than prefixing
>>>the '#' character to the start of each statement i do  not
>>>want to execute (which gets old very quickly if one needs to
>>>comment and uncomment several statements a couple of
>>>times while "playing around with code" say during initial design)?
>>
>>In addition to the approach Paul has suggested, you should also consider 
>>using a better editor, as most decent editors should have some kind of 
>>"block comment/uncomment" feature that prevents that operation from 
>>getting old very quickly...
>>
>>Scite, for example, lets me selected a block and hit Ctrl-Q to either 
>>comment or uncomment the block.
> 
> 
> I see the developers of Scite are either newbies to GUI programming, or
> they operate in a world of their own. Ctrl-Q is reserved for Quit (or
> Exit) in every GUI API I know of.
> 
I don't think this is common enough to regard as any kind of de facto 
standard.

Just to give two further counterexamples, neither TextPad nor Notepad 
action a Ctrl/Q in that way. Perhaps I'm just using the wrong operating 
system?
> 
> 
>>(It does this by prefixing each line 
>>with #~ instead of just #, which allows it to detect when a line is 
>>already so commented and reverse the operation.)  
> 
> 
> It is *easy* to detect when a line is already commented. It starts with a
> #. The ~ is superfluous.
> 
> Commenting and uncommenting should be two different commands: the whole
> point of nested comments is that it allows you to comment a block of text
> which may already contain comments. Having one command do both commenting
> and uncommenting according to the presence or absence of semantic clues in
> the text is a recipe for failure ("No you stupid computer, I want to
> COMMENT that block, not uncomment it!!!").
> 
> Imagine if your text editor used cntl-C for both copy and paste, somehow
> guessing whether you wanted to copy selected text or paste over it
> according to some subtle clue in the text itself. Wouldn't that be fun?
> 
I agree that's a less-than-sensible feature implementation.

regards
  Steve
-- 
Steve Holden   +44 150 684 7255  +1 800 494 3119
Holden Web LLC www.holdenweb.com
PyCon TX 2006  www.python.org/pycon/

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Another stupid newbie question

2006-02-18 Thread Steve Holden
Steven D'Aprano wrote:
> On Fri, 17 Feb 2006 11:51:08 -0800, Byte wrote:
> 
> 
>>Great, thanks all. Now, how come
>>
>>if x == mx: print x
>>break
>>
>>Dosnt work?
> 
> 
> Do yourself a HUGE favour and read this before posting any more questions
> to comp.lang.python. Trust me, you really will thank us.
> 
> http://www.catb.org/~esr/faqs/smart-questions.html
> 
> 
>  
If he doesn't lambast us I'll chalk it up as a win :-)

regards
  Steve
-- 
Steve Holden   +44 150 684 7255  +1 800 494 3119
Holden Web LLC www.holdenweb.com
PyCon TX 2006  www.python.org/pycon/

-- 
http://mail.python.org/mailman/listinfo/python-list


Get parameters from URL using CGI

2006-02-18 Thread abcd
i want to create a CGI script which simply prints out values given via
the URL (such as when a GET is performed).

So if I have a script named, foo.cgi and I access it by going to:

http://www.somesite.com/cgi-bin/foo.cgi?name=john&age=90

I want foo.cgi to print out:
name: john
age: 90


how do i get the values from the URL like that?

thanks

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [DICTIONARY] - Copy dictionary entries to attributes

2006-02-18 Thread Diez B. Roggisch
Ilias Lazaridis schrieb:
> remark: not sure if the term "dictionary" is correct here.
> 
> I have the following situation:
> 
> within a setup.cfg, settings are passed this way:
> 
> settings=project_page=theProjectPage.com
> myVar=myValue
> 
> those are accessible later like this:
> 
> settings['project_page'] / settings['myValue']
> 
> -
> 
> Now my question: is there any standard function to map the settings 
> directly to attributes?
> 
> something like:
> 
> dictionary_make_attributes(settings)
> 
> thus they can be accessed via:
> 
> settings.project_page / settings.myVar
> 
> or
> 
> copy_dictionary_entries_to_attributes(vars, settings)
> 
> vars.project_page / vars.myVar


Either you use __getitem__, or the "bunch"-recipe:

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

Diez

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: general coding issues - coding style...

2006-02-18 Thread calmar
On 2006-02-18, Diez B. Roggisch <[EMAIL PROTECTED]> wrote:

Hi Diez,

>   - why are these {{{ thingies there?

markers for folding for vim
http://www.calmar.ws/tmp/sc.png

>   - use string interpolation like "Foo %s %i" % ("bar", 1) instead of 
> concatenating strings.

I see, get's shorter and so, and I can break lines.
(seems to me, after  ( or [ or so, I can use a new line without
to worry)

>   - it seems that you could benefit from a class instead of a bunch of 
> functions & few globals. No need to go too crazy about OO, but it has 
> its merits

I see. Maybe I could then build some classes for that prog,
especially since I use only one file, it probably would make
some sense for getting a better structure.

>
>   - try using something like glade - creating GUIs by hand sucks 
> big-timer :)

I should (seriously) check out probably.

>   - read up about unicode and encodings, what they mean and why and when 
> to use what. Really. Most problems in that field stem from people being 
> sort of ignorant on that topic and just wiggling themselves through all 
> the time - in the end, messing up stuff. It really _isn't_ that complicated.

I read up. In fact, basically it does not seem to be that complicate.
Unicode just a 'numbered' list of all available character, and
e.g. uft-8 a organized way to 'store' those 'numbers' wisely
into bytes.

I still have some problems with that (and gave up), but since I begin to
now understand it somebit more, I should try/check again.

>   - when creating string-keyed dicts, the idiom
>
> dict(foo="bar",
>  baz="pillepalle")

I see, I changed too.

Thanks a lot,
marco

-- 
  calmar

  (o_  It rocks: LINUX + Command-Line-Interface
  //\
  V_/_ http://www.calmar.ws
-- 
http://mail.python.org/mailman/listinfo/python-list


[DICTIONARY] - Copy dictionary entries to attributes

2006-02-18 Thread Ilias Lazaridis
remark: not sure if the term "dictionary" is correct here.

I have the following situation:

within a setup.cfg, settings are passed this way:

settings=project_page=theProjectPage.com
 myVar=myValue

those are accessible later like this:

settings['project_page'] / settings['myValue']

-

Now my question: is there any standard function to map the settings 
directly to attributes?

something like:

dictionary_make_attributes(settings)

thus they can be accessed via:

settings.project_page / settings.myVar

or

copy_dictionary_entries_to_attributes(vars, settings)

vars.project_page / vars.myVar

?

.

-- 
http://lazaridis.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: share function argument between subsequent calls but not between class instances!

2006-02-18 Thread Felipe Almeida Lessa
Em Sáb, 2006-02-18 às 16:50 +, Duncan Booth escreveu:
> marker = object()
> 
> class Test(object):
> def __init__(self):
> self.L = []
> 
> def f(self,a, L=marker):
> if L is marker:
> L = self.L
> L.append(a)
> return L 

As hasattr(None, "append") == False, you could also do:

class Test(object):
def __init__(self):
self.L = []

def f(self, a, L=None):
if L is None:
L = self.L
L.append(a)
return L

-- 
"Quem excele em empregar a força militar subjulga os exércitos dos
outros povos sem travar batalha, toma cidades fortificadas dos outros
povos sem as atacar e destrói os estados dos outros povos sem lutas
prolongadas. Deve lutar sob o Céu com o propósito primordial da
'preservação'. Desse modo suas armas não se embotarão, e os ganhos
poderão ser preservados. Essa é a estratégia para planejar ofensivas."

  -- Sun Tzu, em "A arte da guerra"

-- 
http://mail.python.org/mailman/listinfo/python-list

Re: share function argument between subsequent calls but not between class instances!

2006-02-18 Thread Duncan Booth
K. Jansma wrote:

> as you can see, the b.f method shares L with a.f.
> How can I avoid this without using eg. self.L in an __init__?
> 

You cannot.

If a method argument has a default value then the same default is used 
whenever the method is called. If you want each instance to have its own 
value then you must use an attribute on the instance.

If you intend to only use the default some of the time, and at other times 
pass in a different list, then save the 'default' in the instance and use a 
special marker value to indicate when you intend the default to be used:

marker = object()

class Test(object):
def __init__(self):
self.L = []

def f(self,a, L=marker):
if L is marker:
L = self.L
L.append(a)
return L
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: share function argument between subsequent calls but not between class instances!

2006-02-18 Thread Felipe Almeida Lessa
Em Sáb, 2006-02-18 às 17:42 +0100, K. Jansma escreveu:
> How can I avoid this without using eg. self.L in an __init__?

Why not use it? That's how it's meant to be done!

> Thanks in advance,
> Karel.

Cya,
Felipe.

-- 
"Quem excele em empregar a força militar subjulga os exércitos dos
outros povos sem travar batalha, toma cidades fortificadas dos outros
povos sem as atacar e destrói os estados dos outros povos sem lutas
prolongadas. Deve lutar sob o Céu com o propósito primordial da
'preservação'. Desse modo suas armas não se embotarão, e os ganhos
poderão ser preservados. Essa é a estratégia para planejar ofensivas."

  -- Sun Tzu, em "A arte da guerra"

-- 
http://mail.python.org/mailman/listinfo/python-list

share function argument between subsequent calls but not between class instances!

2006-02-18 Thread K. Jansma
Hi,

given the following example class

class Test:
def f(self,a, L=[]):
L.append(a)
return L

and the following statements

a = Test()
a.f(0)
a.f(0)
a.f(0)
b = Test()
b.f(0)

this is the output I would like to have (i.e., expect)

>>> a = Test()
>>> a.f(0)
[0]
>>> a.f(0)
[0, 0]
>>> a.f(0)
[0, 0, 0]
>>> b = Test()
>>> b.f(0)
[0]

But this is what I get:

>>> a = Test()
>>> a.f(0)
[0]
>>> a.f(0)
[0, 0]
>>> a.f(0)
[0, 0, 0]
>>> b = Test()
>>> b.f(0)
[0, 0, 0, 0]


as you can see, the b.f method shares L with a.f.
How can I avoid this without using eg. self.L in an __init__?

Thanks in advance,
Karel.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Does Plone support distinct sets of users in subgroups?

2006-02-18 Thread wheel
I was shy of setting up to recieve a bunch of emails, but I'll scope out 
the nttp option. Thanks to both of you.

In article <[EMAIL PROTECTED]>, 
[EMAIL PROTECTED] says...
> wheel:
> >I'm not sure if this is the right venue for Plone questions, if not, 
> >could someone ref me to a better one? 
> 
> The plone-users mailing list. Highly recommended.
> 
> >The discussion groups on the plone site are mailing lists and I'd 
> >rather not subscribe quite yet.
> 
> Why not? It's free, takes 1 minute and you can unsubscribe at any time.
> 
> >Does plone support distinct sets of users? 
> 
> Yes. There's a user-group mechanism.
> http://plone.org/documentation/tutorial/understanding-permissions/tutorial-all-pages
> 
> >That is, on a public website running plone, can it be configured such 
> >that when a user logs in they are allowed access to a subgroup's main 
> >page, 
> 
> That can be done with local roles on the sharing tab. See the link above.
> 
> >get the subgroup's newsletter as well as the main site's newsletter etc?
> 
> I'm not sure about that. I guess it depends on how you implement the
> newsletter. It may require a little customization or programming.
> 
> 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Photo Management Python Application

2006-02-18 Thread [EMAIL PROTECTED]
You can play around with Pil, http://effbot.org/imagingbook/

I found this as being the date for a picture

>>> import Image
>>> i = Image.open('/media/hda8/Pictures/Elvis/dscn0178.jpg')
>>> i._getexif()[36867]
'2006:02:18 14:07:55'
>>>

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: GDI in python>?

2006-02-18 Thread al pacino
Thanks claudio, that should work out fine.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Difference between CPython, Python for .NET and IronPython?

2006-02-18 Thread Diez B. Roggisch
> For example, if I'm running IronPython, can I access modules such as Numeric
> and numarray?

AFAIK not. You can run pure python modules, but not extensions 
containing native code.

> As I understand it, interoperability with C# and .NET works in both
> directions with IronPython, but CPython modules cannot be imported, or? 

If they are pure python they can. However, there isn't e.g. a os-module 
in IronPython (at least on mono under MacOSX) - so I guess the situation 
is similar to Jython: you are basically limited to what the host-runtime 
delivers.

> With Python for .NET I can import the .NET Framework and continue using
> CPython modules, or?

Yes. It's a bridge. Problem is: you can't use Python-Objects in 
.NET-code, which is at least theoretically possible in IronPython (not 
sure if it has something like the jythonc of jython that makes that 
possible for jython, or if it can be done more automagically)

> 
> What is the roadmap for IronPython, will it be possible to import CPython
> modules in the near future?

I doubt it - it's just not the goal, after all you want the CLR 
precisely for _not_ needing bindings for C-libs on various platforms. 
However, I guess a goal is that you get all python modules in IronPython 
that are availablein the standard dist to make pure-python modules run 
out of the box. But I don't have any insights on that.

> One last question, is IronPython cross-platform. That is, can I use
> IronPython with Mono?


Yes, I did so under mono/MacOSX.

Diez
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: strange error I can't figure out...

2006-02-18 Thread Brian Blais
John Zenger wrote:
> It works fine for me.  You must be having an indentation problem.
> 
> Also, get rid of the comma at the end of that last print statement.
> 
> Brian Blais wrote:
>> Hello,
>>
>> I have an odd kind of Heisenbug in what looks like a pretty simple 
>>
>> If you uncomment the one print statement I added in the progressBar 
>> class, you get the error:

talk about a Heisenbug...it disappeared after reading this post...without 
changing 
anything.  :)

It reminds me of the many times that IT problems disappear then the tech looks 
at it.


thanks,


bb

-- 
-

 [EMAIL PROTECTED]
 http://web.bryant.edu/~bblais
-- 
http://mail.python.org/mailman/listinfo/python-list


2-3 Tree Implementation

2006-02-18 Thread timw07
Hi Group:

I am looking for some reference material to implement a 2-3 Tree in
Python... Can anyone lead me in the right direction?

thanks..

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Difference between CPython, Python for .NET and IronPython?

2006-02-18 Thread Claudio Grondi
Carl Johan Rehn wrote:
> What is the difference between CPython, Python for .NET, and IronPython?
> 
> For example, if I'm running IronPython, can I access modules such as Numeric
> and numarray?
>  
> As I understand it, interoperability with C# and .NET works in both
> directions with IronPython, but CPython modules cannot be imported, or? 
> 
> With Python for .NET I can import the .NET Framework and continue using
> CPython modules, or?
> 
> What is the roadmap for IronPython, will it be possible to import CPython
> modules in the near future?
> 
> One last question, is IronPython cross-platform. That is, can I use
> IronPython with Mono?
> 
> Carl
I have asked similar 'question' some weeks ago in the German Python 
newsgroup.
It seems, that that Pythonistas have generally not much interest in 
IronPython waiting for at least release 2.0 of it which is _perhaps_ 
expected to support Mono.
It seems, that usage of IronPython is currently limited to Windows 
platform, but I was not able to attract any expert on it to give a clear 
answer to that.
My own short test has shown, that compiled DLLs (extension modules) 
don't work in IronPython and the created .exe-s of simple Python scripts 
fail to run.
Curious to hear if there will be any expert response to your posting 
here (except replies from people like me, who have no idea about the 
subject themselves).

Claudio
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Multi-threaded SSL

2006-02-18 Thread Jean-Paul Calderone
On 17 Feb 2006 23:37:22 -0800, [EMAIL PROTECTED] wrote:
>Thanks Alex.  I hadn't noticed that example.  I gave it a shot and
>still have the synchronization problems.  While this may be because of
>a lack of understanding of twisted threads (again, perhaps I'm just not
>looking in the right places, but even the the API reference is sparse
>of explanation), I strongly suspect that there's something going on at
>a lower level, like the Open SSL wrapper or Open SSL on the system
>level.

You probably couldn't find an explanation of Twisted threads due to the fact 
that Twisted is implemented almost exclusively without using threads at all.  
Aside from the large library of protocol implementations, this is one of its 
main selling points. ;)

>At this point, I'd just like to know if I should cut my losses
>and try a very rapid polling solution (*cringes*).  Here are my
>attempts:
>
>Twisted SSL Foray:
>http://cixar.com/svn/mage/twisted_ssl_foray.py
>http://cixar.com/websvn/filedetails.php?repname=Cixar&path=%2Fmage%2Ftwisted_ssl_foray.py&rev=0&sc=0

After reading my comment above, hopefully it is clear what is awry in this 
code.  You cannot use sleep() in a Twisted application and expect anything to 
work well.  Instead, a scheduling primitive is provided, 
reactor.callLater(delay, function[, *a[, **kw]]).

However, rather than using the low-level APIs of twisted.web directly, you may 
be interested in using an implementation of this idea which already exists.  
Take a look at .  The tutorial 
builds up a web page which does something very like what your code seems to be 
attempting.

If you pursue the Twisted version, keep in mind the web-dedicated Twisted 
mailing list you can use as a resource: 
.

Jean-Paul
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Photo Management Python Application

2006-02-18 Thread Peter Hansen
Bill wrote:
> Does anyone know of a Python program that will re-name digital photo 
> files in a date-time format based on the date stamp of the file?

Not entirely sure since I can't parse the above sentence fully.

Could you please reread it and consider rephrasing it?  It really 
doesn't look like it makes sense as written.  (renaming _in_ a date-time 
format?  a format _based on_ the date stamp of a file?)

-Peter

-- 
http://mail.python.org/mailman/listinfo/python-list


Difference between CPython, Python for .NET and IronPython?

2006-02-18 Thread Carl Johan Rehn
What is the difference between CPython, Python for .NET, and IronPython?

For example, if I'm running IronPython, can I access modules such as Numeric
and numarray?
 
As I understand it, interoperability with C# and .NET works in both
directions with IronPython, but CPython modules cannot be imported, or? 

With Python for .NET I can import the .NET Framework and continue using
CPython modules, or?

What is the roadmap for IronPython, will it be possible to import CPython
modules in the near future?

One last question, is IronPython cross-platform. That is, can I use
IronPython with Mono?

Carl
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: commenting out blocks of code

2006-02-18 Thread Steven D'Aprano
On Sat, 18 Feb 2006 03:14:49 +, Neil Hodgson wrote:

> I am the developer responsible for SciTE and the Ctrl+Q decision.
> Ctrl+Q is not reserved for Quit on every platform. 

[snip]


Thank you for your thoughtful response. Although I'm not convinced by your
reasoning, I will concede that perhaps my post was a little hasty.


-- 
Steven.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: GDI in python>?

2006-02-18 Thread Peter Hansen
al pacino wrote:
> is it possible to address the  'screen pixels' using python , like
> analogous to older dos( functions that graphics.h provides') or win api
> calls for gdi.
> 
> what i want is to display clusters (in differetn colours) on screen
> using python.

Almost any (or just "any") GUI toolkit can do that.  Check out wxPython, 
Tkinter, PyQT, Pygame, etc.

For example, in the wxPython demo (two easy downloads to install and run 
on a Windows box), the Miscellaneous->DrawXXXList demo page shows how to 
draw sets of points, lines, rectangles, etc, directly to the display via 
a DeviceContext object.

-Peter

-- 
http://mail.python.org/mailman/listinfo/python-list


Numpy for PythonCE

2006-02-18 Thread G�nter Reusing
Hi,
is there a version of Numpy (or Numarray) available
that is compatible to PythonCE 2.3? 


-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Difference: __iadd__ and __add__

2006-02-18 Thread Peter Hansen
Jonathan Gardner wrote:
> I would like to point out that it isn't entirely obvious where to find
> documentation for this particular thing. I know from experience where
> to go, but I remember spending a long time trying to hunt this down.

I'd like to point out it should be obvious, at least as far as going to 
http://docs.python.org and typing "__iadd__" into the Search field in 
the upper right should be an obvious first step...

> For reference, you may want to check out the index of the language
> reference manual.
> 
> http://www.python.org/doc/2.4.2/ref/genindex.html

That one is the second hit in those results...

(It does seem to require reading a few of those pages to learn enough to 
answer the original question.  To be fair, I didn't find (in a few 
minutes) any page that explicitly states what [EMAIL PROTECTED] 
said, about += falling back to __add__ if __iadd__ is not defined, 
though I didn't try searching for it directly.)

-Peter

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Komodo - Will it Lock Me In?

2006-02-18 Thread F. Petitjean
Le Fri, 17 Feb 2006 18:14:26 -0800, Trent Mick a écrit :
>
> Nope. Komodo adds no goo to your code (TM).
> TM's my name, not a trademark on "Komodo adds no goo to your code" --
> but I'm thinking about it. :)
+1 JOTW (Joke of the week)
>
> Cheers,
> Trent
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: general coding issues - coding style...

2006-02-18 Thread Diez B. Roggisch
calmar schrieb:
> Hi all,
> 
> since I'm just a 'handicraft'/beginner or so,
> 
> could anybody provide me with some (rough) hints, about how to enhance the 
> code
> here:

  - why are these {{{ thingies there?

  - use string interpolation like "Foo %s %i" % ("bar", 1) instead of 
concatenating strings.

  - it seems that you could benefit from a class instead of a bunch of 
functions & few globals. No need to go too crazy about OO, but it has 
its merits

  - try using something like glade - creating GUIs by hand sucks 
big-timer :)

  - read up about unicode and encodings, what they mean and why and when 
to use what. Really. Most problems in that field stem from people being 
sort of ignorant on that topic and just wiggling themselves through all 
the time - in the end, messing up stuff. It really _isn't_ that complicated.

  - when creating string-keyed dicts, the idiom

dict(foo="bar",
 baz="pillepalle")

has its merits.

Besides that - looks ok to me.

Diez
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Activestate python installation

2006-02-18 Thread Chris Smith
> "mik3" == mik3  <[EMAIL PROTECTED]> writes:

mik3> hi this is a question regarding installing Activestate
mik3> python whenever i try to install the latest Activestate
mik3> Python on WinXP SP2, it gives me error saying "The wizard
mik3> was interrupted before Activestate 2.4.2 could be completely
mik3> installed. Your system has not been modified ."  any
mik3> ideas why this is going on?  thanks

Administrator?
Writeable drive?
Is there an install log file you could locate?
R,
C
-- 
http://mail.python.org/mailman/listinfo/python-list


general coding issues - coding style...

2006-02-18 Thread calmar
Hi all,

since I'm just a 'handicraft'/beginner or so,

could anybody provide me with some (rough) hints, about how to enhance the code
here:

http://calmar.ws/tmp/cal.html

Cheers and thanks a lot
calmar


-- 
  calmar

  (o_  It rocks: LINUX + Command-Line-Interface
  //\
  V_/_ http://www.calmar.ws
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How many web framework for python ?

2006-02-18 Thread Bo Yang
Thank you very much !
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Should we still be learning this?

2006-02-18 Thread John Zenger
Don't overly concern yourself with your course being 100% up to date. 
When learning programming, the concepts are what is important, not the 
syntax or libraries you happen to be using.  Even if they were to teach 
you the latest and greatest features of 2.4.2, that would be out of date 
in a few months/years when the next version comes along and the Python 
gods decide to deprecate the entire os module or something.

Syntax and libraries change; just roll with it.  When you are a student, 
the important thing is learning the mental skills of how to put it all 
together.  When I was a wee lad, they taught me Pascal, a language that 
is now as dead as Latin, but I now realize that the language did not 
matter; all that mattered was that I learned the basics of how to design 
and put together a program in a (procedural) language.  Once I knew 
that, it was a cinch to teach myself C in an afternoon, and only 
slightly tougher to learn C++ and then Java.

Python is a good teaching language because by learning one language you 
learn three major programming paradigms: procedural, OO, and functional. 
  It doesn't matter if, three years from now, a Dark Age descends upon 
the land and Python becomes as extinct as Pascal.  If your course was 
decent, you spent your time learning programming, not just learning 
today's syntax and libraries, and you'll be able to learn Microsoft 
Visual C#++.Net.Com.Org or whatever other language happens to be 
fashionable in the future.

And BTW, map and filter are such useful concepts that it makes sense to 
teach them to students even if they will one day be deprecated in 
Python.  If you want to teach yourself Haskell or a Lisp dialect (and 
you should!), knowing those concepts will come in very handy.

Max wrote:
> On monday I start a semester course in Python (the alternative was 
> Java). I was looking through the course outline and noticed the following:
> 
> 1) UserDict is used. This is deprecated, right?
> 2) There is no mention of list comprehensions, but map and filter are 
> taught early and then revisited later. I don't think this is good: list 
> comprehensions are, IMO, one of Python's great features, Psyco prefers 
> them, they're more pythonic, and map and filter seem to be going out the 
> window for Python 3000.
> 
> What do you think?
> 
> --Max
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: GDI in python>?

2006-02-18 Thread F. Petitjean
Le 17 Feb 2006 22:02:23 -0800, al pacino a écrit :
> hi,
>
> is it possible to address the  'screen pixels' using python , like
> analogous to older dos( functions that graphics.h provides') or win api
> calls for gdi.
Some possibilities (all on Win32 only):
ctypes by Thomas Heller
venster (uses ctypes) on sourceforge
win32all by Marc Hammond
>
> what i want is to display clusters (in differetn colours) on screen
> using python.
>
> thanks.
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [ANN] Movable python Trial Version

2006-02-18 Thread Claudio Grondi
Felipe Almeida Lessa wrote:
> Em Sáb, 2006-02-18 às 04:24 -0800, Fuzzyman escreveu:
> 
>>It is set to expire on the 22nd May, and displays a nag screen on
>>startup. Other than that, it is the full version. Have fun.
> 
> 
> Attached is the cracked version with no expiration limit and my own
> bitmap on the startup. Enjoy!
> 
> 
>>Fuzzyman
>>http://www.voidspace.org.uk/python/index.shtml
> 
> 
> Just kidding ;-),
> Felipe.
To make it really funny, just beware from sending me the appropriate 
link to my personal email address ;-) .

Claudio
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: strange error I can't figure out...

2006-02-18 Thread John Zenger
It works fine for me.  You must be having an indentation problem.

Also, get rid of the comma at the end of that last print statement.

Brian Blais wrote:
> Hello,
> 
> I have an odd kind of Heisenbug in what looks like a pretty simple 
> program.  The program is a progress bar code I got at the Python Cookbook:
> 
> http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/168639
> 
> (including the code below)
> 
> 
> If you uncomment the one print statement I added in the progressBar 
> class, you get the error:
> 
>   File "test_progress2.py", line 19
> diffFromMin = float(self.amount - self.min)
> ^
> SyntaxError: invalid syntax
> 
> 
> yet, without the print statement, it works fine.  what am I overlooking 
> here?
> 
> 
> thanks,
> 
> 
> bb
> 
> #
> 
> class progressBar:
> def __init__(self, minValue = 0, maxValue = 10, totalWidth=12):
> self.progBar = "[]"   # This holds the progress bar string
> self.min = minValue
> self.max = maxValue
> self.span = maxValue - minValue
> self.width = totalWidth
> self.amount = 0   # When amount == max, we are 100% done
> self.updateAmount(0)  # Build progress bar string
> 
> def updateAmount(self, newAmount = 0):
> if newAmount < self.min: newAmount = self.min
> if newAmount > self.max: newAmount = self.max
> self.amount = newAmount
> 
> #print "hello"   #<--  uncomment line to break
> 
> # Figure out the new percent done, round to an integer
> diffFromMin = float(self.amount - self.min)
> percentDone = (diffFromMin / float(self.span)) * 100.0
> percentDone = round(percentDone)
> percentDone = int(percentDone)
> 
> # Figure out how many hash bars the percentage should be
> allFull = self.width - 2
> numHashes = (percentDone / 100.0) * allFull
> numHashes = int(round(numHashes))
> 
> # build a progress bar with hashes and spaces
> self.progBar = "[" + '#'*numHashes + ' '*(allFull-numHashes) + "]"
> 
> # figure out where to put the percentage, roughly centered
> percentPlace = (len(self.progBar) / 2) - len(str(percentDone))
> percentString = str(percentDone) + "%"
> 
> # slice the percentage into the bar
> self.progBar = self.progBar[0:percentPlace] + percentString + 
> self.progBar[percentPlace+len(percentString):]
> 
> def __str__(self):
> return str(self.progBar)
> 
> 
> if __name__ == "__main__":
> 
> import time
> prog = progressBar(0, 100, 77)
> for i in xrange(101):
> prog.updateAmount(i)
> print prog, "\r",
> time.sleep(.05)
> 
> 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Movable python Trial Version

2006-02-18 Thread Fuzzyman

Felipe Almeida Lessa wrote:
> Em Sáb, 2006-02-18 às 04:24 -0800, Fuzzyman escreveu:
> > It is set to expire on the 22nd May, and displays a nag screen on
> > startup. Other than that, it is the full version. Have fun.
>
> Attached is the cracked version with no expiration limit and my own
> bitmap on the startup. Enjoy!
>

I'm sure it wouldn't be that hard to do. Seriously not worth the effort
though. ;-)

Fuzzy


> > Fuzzyman
> > http://www.voidspace.org.uk/python/index.shtml
>
> Just kidding ;-),
> Felipe.
>
> --
> "Quem excele em empregar a força militar subjulga os exércitos dos
> outros povos sem travar batalha, toma cidades fortificadas dos outros
> povos sem as atacar e destrói os estados dos outros povos sem lutas
> prolongadas. Deve lutar sob o Céu com o propósito primordial da
> 'preservação'. Desse modo suas armas não se embotarão, e os ganhos
> poderão ser preservados. Essa é a estratégia para planejar ofensivas."
> 
>   -- Sun Tzu, em "A arte da guerra"

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Should we still be learning this?

2006-02-18 Thread Max
Felipe Almeida Lessa wrote:
> Em Sáb, 2006-02-18 às 14:38 +0200, Max escreveu:
> 
> Urgh. This sucks. Did they mention generators, at least? Sometimes list
> comprehensions are even faster (I didn't check, but I think this one can
> be an example of this: [i*2+2 for i in iterator] vs. map(lambda x: x*2
> +2, iterator)).
> 

No mention of generators in the outline.

> They should have taught both.
> 
> 
>>What do you think?
> 
> 
> I wonder if they need some updating.
> 

And so does Dive Into Python (our textbook, diveintopython.org) which 
has the same deficiencies in its outline.

> 
> Just my two cents,
> Felipe.
> 

Thanks,
Max
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: strange error I can't figure out...

2006-02-18 Thread Fabrizio Milo
Is well indented ?
-- 
http://mail.python.org/mailman/listinfo/python-list


strange error I can't figure out...

2006-02-18 Thread Brian Blais
Hello,

I have an odd kind of Heisenbug in what looks like a pretty simple program.  
The 
program is a progress bar code I got at the Python Cookbook:

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

(including the code below)


If you uncomment the one print statement I added in the progressBar class, you 
get 
the error:

   File "test_progress2.py", line 19
 diffFromMin = float(self.amount - self.min)
 ^
SyntaxError: invalid syntax


yet, without the print statement, it works fine.  what am I overlooking here?


thanks,


bb

#

class progressBar:
def __init__(self, minValue = 0, maxValue = 10, totalWidth=12):
self.progBar = "[]"   # This holds the progress bar string
self.min = minValue
self.max = maxValue
self.span = maxValue - minValue
self.width = totalWidth
self.amount = 0   # When amount == max, we are 100% done
self.updateAmount(0)  # Build progress bar string

def updateAmount(self, newAmount = 0):
if newAmount < self.min: newAmount = self.min
if newAmount > self.max: newAmount = self.max
self.amount = newAmount

#print "hello"   #<--  uncomment line to break

# Figure out the new percent done, round to an integer
diffFromMin = float(self.amount - self.min)
percentDone = (diffFromMin / float(self.span)) * 100.0
percentDone = round(percentDone)
percentDone = int(percentDone)

# Figure out how many hash bars the percentage should be
allFull = self.width - 2
numHashes = (percentDone / 100.0) * allFull
numHashes = int(round(numHashes))

# build a progress bar with hashes and spaces
self.progBar = "[" + '#'*numHashes + ' '*(allFull-numHashes) + 
"]"

# figure out where to put the percentage, roughly centered
percentPlace = (len(self.progBar) / 2) - len(str(percentDone))
percentString = str(percentDone) + "%"

# slice the percentage into the bar
self.progBar = self.progBar[0:percentPlace] + percentString + 
self.progBar[percentPlace+len(percentString):]

def __str__(self):
return str(self.progBar)


if __name__ == "__main__":

 import time
 prog = progressBar(0, 100, 77)
 for i in xrange(101):
 prog.updateAmount(i)
 print prog, "\r",
 time.sleep(.05)


-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Should we still be learning this?

2006-02-18 Thread Felipe Almeida Lessa
Em Sáb, 2006-02-18 às 14:38 +0200, Max escreveu:
> On monday I start a semester course in Python (the alternative was 
> Java). I was looking through the course outline and noticed the following:
> 
> 1) UserDict is used. This is deprecated, right?

LOL... it's the first time I see someone talking about this module.

/me checks the documentation.

Yep, looks like this module is deprecated since Python 2.2.

> 2) There is no mention of list comprehensions, but map and filter are 
> taught early and then revisited later. I don't think this is good: list 
> comprehensions are, IMO, one of Python's great features, Psyco prefers 
> them, they're more pythonic, and map and filter seem to be going out the 
> window for Python 3000.

Urgh. This sucks. Did they mention generators, at least? Sometimes list
comprehensions are even faster (I didn't check, but I think this one can
be an example of this: [i*2+2 for i in iterator] vs. map(lambda x: x*2
+2, iterator)).

They should have taught both.

> What do you think?

I wonder if they need some updating.

> --Max

Just my two cents,
Felipe.

-- 
"Quem excele em empregar a força militar subjulga os exércitos dos
outros povos sem travar batalha, toma cidades fortificadas dos outros
povos sem as atacar e destrói os estados dos outros povos sem lutas
prolongadas. Deve lutar sob o Céu com o propósito primordial da
'preservação'. Desse modo suas armas não se embotarão, e os ganhos
poderão ser preservados. Essa é a estratégia para planejar ofensivas."

  -- Sun Tzu, em "A arte da guerra"

-- 
http://mail.python.org/mailman/listinfo/python-list

Re: [ANN] Movable python Trial Version

2006-02-18 Thread Felipe Almeida Lessa
Em Sáb, 2006-02-18 às 04:24 -0800, Fuzzyman escreveu:
> It is set to expire on the 22nd May, and displays a nag screen on
> startup. Other than that, it is the full version. Have fun.

Attached is the cracked version with no expiration limit and my own
bitmap on the startup. Enjoy!

> Fuzzyman
> http://www.voidspace.org.uk/python/index.shtml

Just kidding ;-),
Felipe.

-- 
"Quem excele em empregar a força militar subjulga os exércitos dos
outros povos sem travar batalha, toma cidades fortificadas dos outros
povos sem as atacar e destrói os estados dos outros povos sem lutas
prolongadas. Deve lutar sob o Céu com o propósito primordial da
'preservação'. Desse modo suas armas não se embotarão, e os ganhos
poderão ser preservados. Essa é a estratégia para planejar ofensivas."

  -- Sun Tzu, em "A arte da guerra"

-- 
http://mail.python.org/mailman/listinfo/python-list

Should we still be learning this?

2006-02-18 Thread Max
On monday I start a semester course in Python (the alternative was 
Java). I was looking through the course outline and noticed the following:

1) UserDict is used. This is deprecated, right?
2) There is no mention of list comprehensions, but map and filter are 
taught early and then revisited later. I don't think this is good: list 
comprehensions are, IMO, one of Python's great features, Psyco prefers 
them, they're more pythonic, and map and filter seem to be going out the 
window for Python 3000.

What do you think?

--Max
-- 
http://mail.python.org/mailman/listinfo/python-list


Photo Management Python Application

2006-02-18 Thread Bill
Does anyone know of a Python program that will re-name digital photo 
files in a date-time format based on the date stamp of the file?



-- 
http://mail.python.org/mailman/listinfo/python-list


[ANN] Movable python Trial Version

2006-02-18 Thread Fuzzyman
Hot on the heels of `Movable Python 1.0.1
`_, is the release of a free
trial version of **Movable Python**.

This is the full distribution for Python 2.3.5. To download (and play
with it), visit `Movable python Demo
`_.

You can obtain the full version from the `Groups Page
`_.

It is set to expire on the 22nd May, and displays a nag screen on
startup. Other than that, it is the full version. Have fun.

Fuzzyman
http://www.voidspace.org.uk/python/index.shtml

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: embedding python in HTML

2006-02-18 Thread Christoph Zwerschke
Rene Pijlman wrote:
> There's also PSP:
> http://www.ciobriefings.com/psp/

Another incarnation of PSP can be used as part of Webware for Python 
(http://www.w4py.org).

And one of the more modern solutions that should be mentioned is Kid 
(http://kid.lesscode.org).

-- Christoph
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: commenting out blocks of code

2006-02-18 Thread Duncan Booth
Steven D'Aprano wrote:

>> Scite, for example, lets me selected a block and hit Ctrl-Q to either 
>> comment or uncomment the block.
> 
> I see the developers of Scite are either newbies to GUI programming, or
> they operate in a world of their own. Ctrl-Q is reserved for Quit (or
> Exit) in every GUI API I know of.

Your experience obviously differs from mine. I just tried Ctrl-Q on both 
windows and ubuntu and in neither case did it exit applications 
consistently: For example Firefox uses Alt-F4 in both cases.

My own favourite editor (Epsilon) uses Ctrl-Q for the 'quoted-insert' 
command (hardly suprising given its similarity to emacs).

>> (It does this by prefixing each line 
>> with #~ instead of just #, which allows it to detect when a line is 
>> already so commented and reverse the operation.)  
> 
> It is *easy* to detect when a line is already commented. It starts with a
> #. The ~ is superfluous.
> 
Not so easy if the lines to be commented already contain some lines 
starting with comments. Messing around with the comments themselves sounds 
highly unsatisfactory though.

I agree with you that the best solution is to use different commands (or as 
Epsilon does a single command which can be modified with a prefix Ctrl-U). 
That way I can select a large region and comment it all out, or uncomment 
disjoint parts of it as I choose.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: GDI in python>?

2006-02-18 Thread Diez B. Roggisch
al pacino schrieb:
> hi,
> 
> is it possible to address the  'screen pixels' using python , like
> analogous to older dos( functions that graphics.h provides') or win api
> calls for gdi.


Use one of the available GUI-Toolkits - Tkinter is included already. Or 
pygame.

Diez
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: GDI in python>?

2006-02-18 Thread Claudio Grondi
al pacino wrote:
> hi,
> 
> is it possible to address the  'screen pixels' using python , like
> analogous to older dos( functions that graphics.h provides') or win api
> calls for gdi.
> 
> what i want is to display clusters (in differetn colours) on screen
> using python.
> 
> thanks.
> 
Sure. The problem will be to choose the right tool from the myriads of 
available ones.

I have some experience with PyGame
   http://www.pygame.org/news.html
which is built on top of SDL
   http://www.libsdl.org/index.php
and find it easy to understand and use.

Don't be fooled by the 'Game' part - PyGame is as useful as SDL (a very 
good library).

Claudio
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Does Plone support distinct sets of users in subgroups?

2006-02-18 Thread Duncan Booth
wheel wrote:

> I'm not sure if this is the right venue for Plone questions, if not, 
> could someone ref me to a better one? The discussion groups on the plone 
> site are mailing lists and I'd rather not subscribe quite yet.

Use gmane.org: you get NNTP access to all the plone mailing lists (and 
several thousand others) and it will subscribe you automatically under 
its own email address if you choose to post (you have to respond to a 
confirmation email from gmane before first time you post to each 
newsgroup).

http://dir.gmane.org/index.php?prefix=gmane.comp.web.zope.plone
-- 
http://mail.python.org/mailman/listinfo/python-list


  1   2   >