Re: merits of Lisp vs Python

2006-12-13 Thread Ken Tilton


Ken Tilton wrote:
> 
> 
> Ken Tilton wrote:
> 
>>
>>
>> Paul Rubin wrote:
>>
>>> Ken Tilton <[EMAIL PROTECTED]> writes:
>>>
 don't know. The point is, we need code (not just data) in defskill
 (apologies for nasty formatting):
>>>
>>>
>>>
>>>
>>> Man that whole thing is messy.
> 
> 
> I do not see much difference, except that the character count is 25% 
> less in the macro version:
> 
> (defskill absolute-value
> (title "Absolute Value")
>   (annotations
>"Absolute value of #strn# is the 'distance' of #strn# from zero."
>"Absolute value is always zero or positive: #str|n|=n#, and 
> #str|-n|=n#.")
>   (hints
>"Some examples: #str|+42|=42#, #str|-42|=42#, and #str|0|=0#."
>"To get the absolute value of a number such as #signed-value#, we 
> simply drop any minus sign.")
>   (reverse
>(ensure-cloning resx
>  (make-instance 'mx-number
>:value (loop with op1 = (car opnds)
>   with log = (max 1 (ceiling (log (abs (value op1)) 10)))
>   for n = (* (signum (value op1))
> (+ 2 (random (expt 10 log
>   when (/= n (value op1))
>   return n)
>:representation (representation resx)
> 
> (defmethod skill-title ((tf-id (eql 'absolute-value)))
>   (list "absolute value"))
> 
> (defmethod skill-annotations ((tf-id (eql 'absolute-value)))
>   (list "absolute value of #strn# is the 'distance' of #strn# from zero."
> "absolute value is always zero or positive: #strn=n#, and #str-n=n#."))
> 
> (defmethod skill-hints ((tf-id (eql 'absolute-value)))
>   (list "some examples: #str+42=42#, #str-42=42#, and #str0=0#."
> "to get the absolute value of a number such as #signed-value#, we 
> simply drop any minus sign."))
> 
> (defmethod tf-reverse ((id (eql 'absolute-value)) resx opnds)
>   (declare (ignorable resx opnds))
>   (ensure-cloning resx
> (make-instance 'mx-number :value
>   (loop with op1 = (car opnds) with log = (max 1 (ceiling (log (abs 
> (value op1)) 10))) for n =
> (* (signum (value op1)) (+ 2 (random (expt 10 log when 
> (/= n (value op1)) return n)
>   :representation (representation resx)

Even better. That "(car opnds)" up there is an unpleasant hard-coding 
that must align with how operands get recorded by the transformation 
code that built the TF log entry that is being reversed. Ewww. What the 
first opnds is supposed to be is the signed value of which the absolute 
vale is being taken. Wouldn't it be nice to just say "signed-value"?:

We can just look at the reverse option now:

(defskill absolute-value
 
   (reverse (signed-value)
 (ensure-cloning resx
   (make-instance 'mx-number
 :value (loop with svn = (value signed-value)
with log = (max 1 (ceiling (log (abs svn) 10)))
for n = (* (signum svn)(+ 2 (random (expt 10 log
when (/= n svn)
return n)
 :representation (representation resx)

A major point here is that the above (trust me) is the exact syntax of 
FLET and LABELS in Lisp. The big hobgoblin (and precise objection 
offered by GvR) is that macro use yields unrecognizably (in this case) 
Lisp code. But we love lisp and its patterns, and one ethic for macro 
writers is to follow those patterns in extending the language.

Maybe that poor horse can be allowed to rest in peace, or must we flog 
it some more for youse people?

Now operands and results get tagged at TF time with symbols. How on 
earth does a local variable of the same name get bound to the operand 
logged at TF time? Easy, look it up. But where is the code? Not outside 
the function; the caller of the reversal function does not know which 
logged operand to pass in which function parameter position. So the 
lookup code has to be in the reverse function source, like this:

(defmethod tf-reverse ((id (eql 'absolute-value)) tf drv
 &aux (opnds (drv-opnds tf drv)))
   (declare (ignorable opnds))
   (let ((signed-value (tf-drv-lookup tf drv 'signed-value))) <=
 (loop for resx in (results drv) do
   (ensure-cloning resx
 (make-instance 'mx-number :value
   (loop with svn = (value signed-value)
 with log = (max 1 (ceiling (log (abs svn) 10)))
 for n = (* (signum svn)
(+ 2 (random (expt 10 log
 when (/= n svn) return n)
   :representation (representation resx))

WordPerfect says thats 405 characters, 64 words vs 241/38 for the actual 
source.

Now in this case I happen to be just starting on this mechanism, so i do 
not really have 42 I do not have to change, but I am about to start 
churning these things out and I expect refinements to continue.

No problem.

ken

-- 
Algebra: http://www.tilton-technology.com/LispNycAlgebra1.htm

"Well, I've wrestled with reality for t

Re: Conditional iteration

2006-12-13 Thread Paul Rubin
at <[EMAIL PROTECTED]> writes:
> >   for x in (x for x in [-2, -1, 0, 1, 2, 3, 4] if x > 0):
> >... more code ...

> Do you know if this generates a new list internally (memory consumption?)

It does not.  That parenthesized expression is a called generator
expression.  It compiles to a small subroutine, more or less, that
gets invoked repeatedly as you iterate through it.

A similar expression with square brackets is called a list
comprehension and does generate a new list.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: merits of Lisp vs Python

2006-12-13 Thread Paul Rubin
Ken Tilton <[EMAIL PROTECTED]> writes:
> btw, you called the defskill messy (repeated below) "messy". The only
> text not specific to absolute value is D-E-F-S-K-I-L-L.

No, the messiness was not in the macro instantation (defskill blah...),
but in the defmacro that tells the compiler how to expand it.  Python
function defs are lightweight enough that I don't experience a big pain
from using an extra one for a thing like that.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: The Famous Error Message: "ImportError: No module named python_script"

2006-12-13 Thread Eric Pederson
rich murphy wrote:

>So, I assumed "the current directory" is C:\Python25 which did not
>work. Then I placed the fibo.py file in C: director. That did not work
>either. What directory does it mean then?
>
OK, forgive me for using 2.4...  Can you import "sys"?  Assuming you've 
got python_script.py at path:  "C:\\python_script.py" you might try this 
quick test:
  
 >>> import sys
 >>> sys.path
['C:\\Python24\\Lib\\idlelib', 'C:\\windows\\system32\\python24.zip', 
'C:\\Python24', 'C:\\Python24\\DLLs', 'C:\\Python24\\lib', 
'C:\\Python24\\lib\\plat-win', 'C:\\Python24\\lib\\lib-tk', 
'C:\\Python24\\lib\\site-packages', 
'C:\\Python24\\lib\\site-packages\\win32', 
'C:\\Python24\\lib\\site-packages\\win32\\lib']   ## your ouput may be 
different
 >>> sys.path.append("C:\\")
 >>> sys.path
['C:\\Python24\\Lib\\idlelib', 'C:\\windows\\system32\\python24.zip', 
'C:\\Python24', 'C:\\Python24\\DLLs', 'C:\\Python24\\lib', 
'C:\\Python24\\lib\\plat-win', 'C:\\Python24\\lib\\lib-tk', 
'C:\\Python24\\lib\\site-packages', 
'C:\\Python24\\lib\\site-packages\\win32', 
'C:\\Python24\\lib\\site-packages\\win32\\lib', 'C:\\']
 >>> import python_script


6.1.1 The Module Search Path

When a module named spam is imported, the interpreter searches for a 
file named spam.py in the current directory [...]

Actually, modules are searched in the list of directories given by the 
variable |sys.path| which is initialized from the directory containing 
the input script (or the current directory), PYTHONPATH and the 
installation-dependent default. This allows Python programs that know 
what they're doing to modify or replace the module search path. Note 
that because the directory containing the script being run is on the 
search path, it is important that the script not have the same name as a 
standard module, or Python will attempt to load the script as a module 
when that module is imported. This will generally be an error. See 
section 6.2 <#standardModules>, ``Standard Modules,'' for more information.


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


Re: merits of Lisp vs Python

2006-12-13 Thread Ken Tilton


Paul Rubin wrote:
> Ken Tilton <[EMAIL PROTECTED]> writes:
> 
>>>Man that whole thing is messy.  I can't for the life of me understand
>>>why it's so important to use a macro for that.  Even in Lisp, I'd
>>>probably set up the reverse thingie as an auxiliary function.
>>
>>And when you got to skill 42 and you discovered you needed a new
>>optional argument to the reversal method you would throw up your hands
>>and register for bartending school rather than go edit the other 41.
> 
> 
> I don't see the problem.  Python uses keyword args sort of like
> Lisp's, and the called function (if it asks) receives a dictionary
> containing any keyword args not bound explicitly in the arg list.
> So you can invent new args whenever you want.

I am not making this up. I just decided to change the signature to the 
reversal function(s). I had been clever, trying to pass in just what I 
deemed necessary from a transformation (TF) data structure that needed 
reversing, now I recall -- because I needed something else from the TF 
-- I should never try to be smart, just pass in the whole frickin TF (duh).

So this:
 (defmethod tf-reverse (id (eql ',sub-id)) resx (drv-opnds tf drv))
 ,@reverser)

becomes this:

 (defmethod tf-reverse ((id (eql ',sub-id)) tf drv
 &aux (opnds (drv-opnds tf drv)))
(loop for resx in (results drv)
  ,@reverser))

I pass in drv (a derivation, a part of a transformation) because (I 
forgot) reversal code has to reverse each derivation of a TF separately.

In the new macroexpansion I preserve the bindings RESX and OPNDS 
expected by the 41 (not really, but it could be) existing uses of the 
defskill macro, and then  move an iteration across possible 
multiple results (RESXs) of a TF into the generate tf-reverse method 
(and the poor body of code has no idea I did that).

At this point if I had to redo these manually we can forget bartending 
school, I'd be going straight to the Betty Ford clinic .

btw, you called the defskill messy (repeated below) "messy". The only 
text not specific to absolute value is D-E-F-S-K-I-L-L. Expanding that 
into "tidy" separate methods adds 25% of dead weight boilerplate. In 4-5 
separate toplevel definitions instead of one. How is that less messy?

ken

(defskill absolute-value
 (title "Absolute Value")
   (annotations
"Take the absolute value of #signed-value#."
"The vertical bars around #signed-value# mean 'the absolute value 
of' #signed-value#."
"Absolute value of #strn# is the 'distance' of #strn# from zero."
"Absolute value is always zero or positive: #str|n|=n#, and 
#str|-n|=n#.")
   (hints
"What do those vertical bars around #signed-value# mean?"
"Have you learned about 'absolute value'?"
"Absolute value can be thought of as the 'distance' of a value from 
zero on the number line, and distance is always positive."
"The rule is:#str|-n|=|n|##str=n#.  Can you apply that to 
#signed-value#?"
"Some examples: #str|+42|=42#, #str|-42|=42#, and #str|0|=0#."
"To get the absolute value of a number such as #signed-value#, we 
simply drop any minus sign.")
   (reverse
(ensure-cloning resx
  (make-instance 'mx-number
:value (loop with op1 = (car opnds)
   with log = (max 1 (ceiling (log (abs (value op1)) 10)))
   for n = (* (signum (value op1))
 (+ 2 (random (expt 10 log
   when (/= n (value op1))
   return n)
:representation (representation resx)




-- 
Algebra: http://www.tilton-technology.com/LispNycAlgebra1.htm

"Well, I've wrestled with reality for thirty-five
years, Doctor, and I'm happy to state I finally
won out over it." -- Elwood P. Dowd

"I'll say I'm losing my grip, and it feels terrific."
-- Smiling husband to scowling wife, New Yorker cartoon
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Conditional iteration

2006-12-13 Thread at
Hi Greg,

Well point is that the condition is the only thing happening and does not
really apply to the indented code section, but basically to the list used
in the indented code section.

When I read this code back its like, 'oh we use this list' and by the if
some_condition the next thing I think is 'hm, not all of the list' and even
worse should I worry if more restrictions can be found when I read
further...

All the best,

@

greg wrote:

> at wrote:
> 
>> It is not the addional line containing 'if x > 0:' that bothers me, but
>> the additional indentation.
> 
> I don't find the additional indentation bothersome.
> In fact I think it's helpful, because it makes it
> obvious that there is something else going on besides
> just a loop.
> 
> --
> Greg

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


Pythonic style involves lots of lightweight classes (for me)

2006-12-13 Thread metaperl
I find it arduous to type dictionary['key'] and also feel that any data
I create for a program deserves to have its operations tied to it. As a
result, I often create lots of lightweight classes. Here's a small
example:


vlc = '/Applications/VLC.app/Contents/MacOS/VLC'

class song(object):
def __init__(self, title, url):
self.title = title
self.url   = url



urls = [
song(title='breath',
 url='mms://ra.colo.idt.net/ginsburgh/eng/med/breath.mp3'),
song(title='waking',
 url= 'mms://ra.colo.idt.net/ginsburgh/eng/med/modeh.mp3')
]

for url in urls:
print url.title


 The above program started out as a list of dictionaries, but I
like the current approach much better.

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


Re: Conditional iteration

2006-12-13 Thread at
Thanx Paul!

Do you know if this generates a new list internally (memory consumption?)

@


Paul Rubin wrote:

> at <[EMAIL PROTECTED]> writes:
>> You proposal, seems nice to me but it doesn't work with Python 2.4.3,
>> should it work with 2.5?
>> 
>> Again I am just wondering if the approach for
>> 
>> [x for c x in some_list if some_condition]
>> 
>> and
>> x = a if b else c
>> 
>> could be generalized for normal straight forward iterations:
>> 
>> for x in some_list if some_condition:
> 
> Sorry, I got it wrong.  Should have said:
> 
>for x in (x for x in some_list if some_condition):
>   ...
> 
> So your example would have been:
> 
>   for x in (x for x in [-2, -1, 0, 1, 2, 3, 4] if x > 0):
>... more code ...
> 
> It should work in 2.4.

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


Re: Conditional iteration

2006-12-13 Thread at
My comments below.

Kind regards,
@


Carl Banks wrote:

> at wrote:
>> Well, all I can say that for me as a user it would make sense...
> 
> Which is, like, step one out of a hundred for getting a syntax change
> into the language.
> 
>> Curiosity: in what sense is it redundant?
> 
> It creates syntactical support for two different ways to do something.
> If your plan were adopted, then we'd have two different spellings for
> the same thing:
> 
> for i in a:
> if i != 0:
> use(i)
> 
> for i in a if i != 0:
> use(i)

With the current Python syntax, I can create for every two lines of code a
dozen alternative implementations:

# example 1
a = {}
a['b'] = 'c'

versus:
a = {'b': 'c'}


# example 2
l = []
for l in some_list:
if some_condition:
l.append(l)

versus:
l = []
for x in some_list:
if some_condition:
l = l + [x]

or:
l = [x for x in some_list if some_condition]

(the beautiful one)

So your argument doesn't mean much I would say! 

> 
> Now, redundant syntax isn't a deal breaker by itself.  You have to ask
> what is buys you.  In this case, all it does is save you a single level
> of indentation--that's it.  There's no performance benefit.  It doesn't
> simplify logic.  It doesn't make the code any more readable of clear.
> It's only a minor improvement in conciseness.  It hardly saves any
> typing (unless you indent by hand).  Even its one clear benefit, saving
> indentation, is something you can already get with "if not x:
> continue".


Well there is a clear performance benefit, or more precisely a productivity
benefit. And -please- do not underestimate this for a language like Python,
which has many supporters due to its perceived and high productivity and
challenged on this point by languages like Ruby.

'for x in some_list if some_condition:'

is psychological very strong, because the brain will most likely treat the
in the same way as :

for every apple in the fruitbasket take one if green


Basically upon reading this first line you know exactly to what list of
items your next section of code applies. 

But again everything is a matter of taste and I assume that's why the change
control body is put into the hand of one person.



> Considering how little this syntax change buys, it really doesn't make
> a lot of sense for a language that places high emphasis on avoiding
> redundancy.
> 
> 
>> All solution/workarounds I have seen so far involve creation of new lists
>> (subsets) adding to more processing/computation/memory usage. Redundant
>> suggests that you know alternatives that don't do that.
>>
>> Does Guido ever change his mind?
> 
> Yes, but I guarantee "it makes sense for me" isn't going to convince
> him.  By the way, I'd suggest when posting to comp.lang.python and/or
> python-list in the future, you put your replies beneath the quoted text
> for the benefit of any future readers (not to mention present readers).
>
I hope this this thread will support the "it makes sense for me" with
arguments. Again it is not my intention to fight windmills, but to see if
there are strong arguments against it on one hand and if there supporters
on the other hand.


> 
> Carl Banks

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


Re: The Famous Error Message: "ImportError: No module named python_script"

2006-12-13 Thread rich murphy

Ben Finney wrote:
> "rich murphy" <[EMAIL PROTECTED]> writes:
>
> > I am studying Python language.
>
> Welcome! Allow me to direct you to the Python tutorial:
>
> http://docs.python.org/tut/>
>
> Please take the time to work through all the exercises in that
> document, understanding each one before moving on.
>
> I recommend this because:
>
> > I placed the the script called "python_script" in C:\Python25
> > directory where all the other Python files are.
>
> you would not make this mistake if you had already worked through the
> tutorial.

The tutorial says: "For instance, use your favorite text editor to
create a file called fibo.py in the current directory with the
following contents:"

So, I assumed "the current directory" is C:\Python25 which did not
work. Then I placed the fibo.py file in C: director. That did not work
either. What directory does it mean then?


>
> Enjoy!
>
> --
>  \ "On the other hand, you have different fingers."  -- Steven |
>   `\Wright |
> _o__)  |
> Ben Finney

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


Re: The Famous Error Message: "ImportError: No module named python_script"

2006-12-13 Thread Fredrik Lundh
rich murphy wrote:

> Thank you both for responding.
> 
> Yes of course the file has the ".py" extension and yes I went through
> the tutorial.

since everyone on this forum is importing modules successfully hundreds 
of times every day, that's not obvious at all.

try running the interpreter as

 python -vv

and see what it prints when you type

 import python_script



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


Re: merits of Lisp vs Python

2006-12-13 Thread Paul Rubin
Ken Tilton <[EMAIL PROTECTED]> writes:
> >> Man that whole thing is messy.
> 
> I do not see much difference, except that the character count is 25%
> less in the macro version:

The macro calls aren't so bad, but the macro definition is pretty
horrendous.  There's no need to invent and program all that new syntax
when Python's existing syntax does the job perfectly well.

> I don't know, perhaps the best argument against macros is that no
> Pythonista wants them. That is actually a damn good reason.

I've wanted macros from time to time, but this isn't a situation that
calls for them.  They're just less important in Python than in Lisp.
Python already has enough syntax to not constantly need new syntax
extensions.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: merits of Lisp vs Python

2006-12-13 Thread Ken Tilton


Ken Tilton wrote:
> 
> 
> Paul Rubin wrote:
> 
>> Ken Tilton <[EMAIL PROTECTED]> writes:
>>
>>> don't know. The point is, we need code (not just data) in defskill
>>> (apologies for nasty formatting):
>>
>>
>>
>> Man that whole thing is messy.

I do not see much difference, except that the character count is 25% 
less in the macro version:

(defskill absolute-value
 (title "Absolute Value")
   (annotations
"Absolute value of #strn# is the 'distance' of #strn# from zero."
"Absolute value is always zero or positive: #str|n|=n#, and 
#str|-n|=n#.")
   (hints
"Some examples: #str|+42|=42#, #str|-42|=42#, and #str|0|=0#."
"To get the absolute value of a number such as #signed-value#, we 
simply drop any minus sign.")
   (reverse
(ensure-cloning resx
  (make-instance 'mx-number
:value (loop with op1 = (car opnds)
   with log = (max 1 (ceiling (log (abs (value op1)) 10)))
   for n = (* (signum (value op1))
 (+ 2 (random (expt 10 log
   when (/= n (value op1))
   return n)
:representation (representation resx)

(defmethod skill-title ((tf-id (eql 'absolute-value)))
   (list "absolute value"))

(defmethod skill-annotations ((tf-id (eql 'absolute-value)))
   (list "absolute value of #strn# is the 'distance' of #strn# from zero."
 "absolute value is always zero or positive: #strn=n#, and #str-n=n#."))

(defmethod skill-hints ((tf-id (eql 'absolute-value)))
   (list "some examples: #str+42=42#, #str-42=42#, and #str0=0#."
 "to get the absolute value of a number such as #signed-value#, we 
simply drop any minus sign."))

(defmethod tf-reverse ((id (eql 'absolute-value)) resx opnds)
   (declare (ignorable resx opnds))
   (ensure-cloning resx
 (make-instance 'mx-number :value
   (loop with op1 = (car opnds) with log = (max 1 (ceiling (log (abs 
(value op1)) 10))) for n =
 (* (signum (value op1)) (+ 2 (random (expt 10 log when 
(/= n (value op1)) return n)
   :representation (representation resx)


Let's lose the strings and count again, since they are a fixed cost. OK, 
now the macro version is 30% shorter.

>>  I can't for the life of me understand
>> why it's so important to use a macro for that.

Pythonistas, when arguing about macros, always seem to forget that one 
of the primary design imperatives of Python is cleaner code. Indentation 
is use to avoid single characters { and }. But when macros come up you 
all suddenly become the Mavis Beacon of programmers.

And, again, perhaps the bigger thing going on here is that the 30% is 
boilerplate code representing implementation, which can change.

I don't know, perhaps the best argument against macros is that no 
Pythonista wants them. That is actually a damn good reason.

ken

-- 
Algebra: http://www.tilton-technology.com/LispNycAlgebra1.htm

"Well, I've wrestled with reality for thirty-five
years, Doctor, and I'm happy to state I finally
won out over it." -- Elwood P. Dowd

"I'll say I'm losing my grip, and it feels terrific."
-- Smiling husband to scowling wife, New Yorker cartoon
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: merits of Lisp vs Python

2006-12-13 Thread Paul Rubin
Ken Tilton <[EMAIL PROTECTED]> writes:
> > Man that whole thing is messy.  I can't for the life of me understand
> > why it's so important to use a macro for that.  Even in Lisp, I'd
> > probably set up the reverse thingie as an auxiliary function.
> 
> And when you got to skill 42 and you discovered you needed a new
> optional argument to the reversal method you would throw up your hands
> and register for bartending school rather than go edit the other 41.

I don't see the problem.  Python uses keyword args sort of like
Lisp's, and the called function (if it asks) receives a dictionary
containing any keyword args not bound explicitly in the arg list.
So you can invent new args whenever you want.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: merits of Lisp vs Python

2006-12-13 Thread Ken Tilton


Paul Rubin wrote:
> Ken Tilton <[EMAIL PROTECTED]> writes:
> 
>>don't know. The point is, we need code (not just data) in defskill
>>(apologies for nasty formatting):
> 
> 
> Man that whole thing is messy.  I can't for the life of me understand
> why it's so important to use a macro for that.  Even in Lisp, I'd
> probably set up the reverse thingie as an auxiliary function.

And when you got to skill 42 and you discovered you needed a new 
optional argument to the reversal method you would throw up your hands 
and register for bartending school rather than go edit the other 41.

defskill is writing my code for me. When things change, I have it write 
different code. Implementation is hidden, even from the programmer. I am 
one step removed from the code when writing a macro. This is the "meta" 
in metaprogramming.

ken

-- 
Algebra: http://www.tilton-technology.com/LispNycAlgebra1.htm

"Well, I've wrestled with reality for thirty-five
years, Doctor, and I'm happy to state I finally
won out over it." -- Elwood P. Dowd

"I'll say I'm losing my grip, and it feels terrific."
-- Smiling husband to scowling wife, New Yorker cartoon
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: job posting: nothing about Python there

2006-12-13 Thread Paul Rubin
Looks like a generic Windows weenie gig:

Will serve as a programmer in the following program languages: RPGIII,
RPGILE, Microsoft Access, SQL, Microsoft SQL Server, XML, Cold Fusion,
and other web development tools.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: merits of Lisp vs Python

2006-12-13 Thread Paul Rubin
Ken Tilton <[EMAIL PROTECTED]> writes:
> don't know. The point is, we need code (not just data) in defskill
> (apologies for nasty formatting):

Man that whole thing is messy.  I can't for the life of me understand
why it's so important to use a macro for that.  Even in Lisp, I'd
probably set up the reverse thingie as an auxiliary function.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: job posting: Sr Systems Programmer needed

2006-12-13 Thread Terry Reedy

<[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> View the Job Descriptions: www.myspace.com/agcocorp

I did and it has nothing to do with Python.
So in the context of this newgroup, this announcement is spam.
Please desist in the future.
If everyone else with an unreleated programmer job posted here,
the newsgroup would become useless.

tjr






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


Re: speed of python vs matlab.

2006-12-13 Thread Jonathan Curran
On Wednesday 13 December 2006 18:07, Chao wrote:
> I've been trying to develop some numerical codes with python, however
> got disappointed.
>
> A very simple test,
>
> a = 1.0
>
> for i in range(1000):
>  for j in range(1000):
>a = a+1
>
> unfortunately, it took 4.5 seconds to finish(my machines is fine. P4
> 3.0G, 1G RAM, it varies according to machine configuration, but should
> be in the same level)
>
> for matlab, the same operation took 0.1 seconds,
>
> I use numpy & scipy, they solve the problem most of the times, but
> there are cases you can't avoid loops by vectors. I appreciate the
> elegancy of python so much, but I guess I have to gave it up in these
> numerical codes.(image processing algorithms),  for application
> dev/scripting, it's still my first choice.
>
> A good news is that the same code takes ruby 9.8 seconds.

[EMAIL PROTECTED] ~]$ time python foo # where foo contained your exact code

real0m0.469s
user0m0.443s
sys 0m0.017s

4.5 seconds? ouch. I've got somewhere near 1 second. Something sounds a little 
fishy b/c my machine is an AMD 3200+ (2.2GHz) w/ 1GB RAM. Yours is a lot 
faster in terms of clock speed.

Anyway, do take a look at some of the available python compilers. They should 
help considerably.

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


Re: Is anyone using Python for embedded applications?

2006-12-13 Thread Hendrik van Rooyen
"Paul Boddie" <[EMAIL PROTECTED]> wrote:

> Interesting! Any links, or is it related to the Telit hardware already
> discussed?

telit it was...

- Hendrik

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


Re: merits of Lisp vs Python

2006-12-13 Thread Paddy

Ken Tilton wrote:
> (apologies for nasty formatting):
;-)

- Paddy!

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


Re: merits of Lisp vs Python

2006-12-13 Thread Ken Tilton


greg wrote:
> Ken Tilton wrote:
> 
>> pps. How would Python do this?
> 
> 
> Here's one way it could look:
> 
>   defskill("absolute-value",
> title = "Absolute Value",
> annotations = [
>  "Take the absolute value of #op#.",
>  "The vertical bars around #op# mean 'the absolute value of' #op#.",
>  "Absolute value of #strn# is the 'distance' of #strn# from zero.",
>  "Absolute value is always zero or positive: #str|n|=n#, and 
> #str|-n|=n#."
> ],
> hints = [
>  "What do those vertical bars around #op# mean?",
>  "Have you learned about 'absolute value'?",
>  """Absolute value can be thought of as the 'distance' of a value from
> zero on the number line, and distance is always positive.""",
>  "The rule is:#str|-n|=|n|##str=n#.  Can you apply that to #op#?",
>  "Some examples: #str|+42|=42#, #str|-42|=42#, and #str|0|=0#.",
>  """To get the absolute value of a number such as #op#, we simply drop
> any minus sign."""
> ]
>   )
> 
>  > Is it possible to avoid committing to an
>  > implementation mechanism?
> 
> The defskill function could do just about anything with this.
> Here's one possibility:
> 
>   skills = {}
> 
>   class Skill:
> pass # fill in whatever methods you need here
> 
>   def defskill(name, title, annotations, hints):
> skill = Skill()
> skill.title = title
> skill.annotations = annotations
> skill.hints = hints
> skills[name] = skill
> 
> This gives you a dictionary of Skill instances indexed by name,
> each one having a title and lists of annotation and hint strings.
> The rest of the system can process this however required.

Ok, not too bad, not much syntax in there. But now I have a tougher 
requirement for you, which I noticed only after posting. (I tried 
running the damn thing and it whined about not knowing how to "reverse" 
absolute-value (to clone one problem into a similar problem).) A 
reversal must be able to yield any given a result, and sometimes must 
use given operands already settled on by the larger reversing algorithm. 
In the simpler case, to reverse absolute-value with result 42 we produce 
either |42| or |-42|. In the more complicated case, the multiply-literal 
  reverser may discover 6 is an operand and 42 is the result (meaning it 
does no randomization, it just supplies the (* 6 7) reversal. Why am I 
telling you all this? I don't know. The point is, we need code (not just 
data) in defskill (apologies for nasty formatting):

(defmacro defskill (id &body skill-info)
   `(progn
  ,@(loop with sub-id = id
  for (q . q-def) in skill-info
  collecting (ecase q
   ((title annotations hints)
`(defmethod ,(intern (conc$ 'skill- q)) 
((tf-id (eql ',sub-id)))
   (list ,@q-def)))
   (reverse
`(defmethod tf-reverse ((id (eql ',sub-id)) 
resx opnds)
   (declare (ignorable resx opnds))
   ,@q-def))

--- (Abbreviated) Example --

(defskill absolute-value
 (title "Absolute Value")
   (annotations
"Absolute value is always zero or positive: #str|n|=n#, and 
#str|-n|=n#.")
   (hints
"What do those vertical bars around #op# mean?")
   (reverse
(ensure-cloning resx
  (make-instance 'mx-number
:value (loop with op1 = (car opnds)
   with log = (max 1 (ceiling (log (abs (value op1)) 10)))
   for n = (* (signum (value op1))
 (+ 2 (random (expt 10 log
   when (/= n (value op1))
   return n)
:representation (representation resx)

-- Producing -


(progn (defmethod skill-title ((tf-id (eql 'absolute-value))) (list 
"absolute value"))
(defmethod skill-annotations ((tf-id (eql 'absolute-value)))
  (list "absolute value is always zero or positive: #strn=n#, 
and #str-n=n#."))
(defmethod skill-hints ((tf-id (eql 'absolute-value)))
  (list "what do those vertical bars around #op# mean?"))
(defmethod tf-reverse ((id (eql 'absolute-value)) resx opnds)
  (declare (ignorable resx opnds))
  (ensure-cloning resx
(make-instance 'mx-number :value
  (loop with op1 = (car opnds) with log = (max 1 (ceiling 
(log (abs (value op1)) 10))) for n =
(* (signum (value op1)) (+ 2 (random (expt 10 
log when (/= n (value op1)) return n)
  :representation (representation resx)

How close can Python get when code is involved? The reverse function 
signature is fixed, so can lambda help?

ken

-- 
Algebra: http://www.tilton-technology.com/LispNycAlgebra1.htm

"Well, I've wrestled with reality for thirty-five
years, Doctor, and I'm happy to state I finally
won 

job posting: Sr Systems Programmer needed

2006-12-13 Thread lmsteadman
AGCO, Jackson Operations is nestled in the picturesque Des Moines River
Valley---in the welcoming town of Jackson, Minnesota (56143). Jackson
is a town of approximately 3600 neighbors, and is centrally located
between the booming town of Sioux Falls, SD and the resort area of the
Okoboji Lakes.

AGCO's award-winning facility is jut the tip of the iceberg! Our
employees enjoy an outstanding quality of life, great advancement
opportunities, a results-oriented work environment all while nestled
into a scenic rural area (which supports a reduced cost of living and
unbelievably low crime rate). Enjoy the outdoors? You can't beat the
fishing, hunting, golfing, hiking and biking opportunities in Jackson
County. Do you prefer the adrenalin of watching sports live and in
action? Jackson is also home to the famous Jackson Speedway
(NASCAR/racing), and you can easily catch a Minnesota Vikings game or
visit the Mall of America with a quick trip north up to Minneapolis for
the day.

Jackson's public school has just undergone a $20 million renovation to
make it one of the nicest high schools in the area. The athletic
facilities alone would make some colleges jealous. Currently, the City
Council and the County Commission are working together on a new
community center to house several city and county offices along with a
training facility.

The AGCO facility is a 100-acre campus that houses over 587,000 sq feet
full fabrication and welding operation under one roof! AGCO currently
employs over 900 team members (we have several employees that have
worked here for over 20-30 years!). We are now looking for
process-oriented MIS members to drive our continuous improvement effort
at our state-of-the-art manufacturing campus. Target start date would
be in 1st Quarter 2007, however we are starting to interview now!

AGCO Jackson is a launch pad for long-term careers within AGCO
Corporation! We over a very competitive compensation package,
relocation package, continuing education opportunities, and a chance to
have an immediate effect on our operations. Perhaps more importantly,
we offer you old-fashioned Midwest hospitality. Come join us and get
the experience you really want!

View the detailed job descriptions and educational requirements by
clicking on the links below! We are looking for a talented person to
fill the role of Senior Systems Programmer, with a target of starting
during 1st Quarter 2007.

View the Job Descriptions: www.myspace.com/agcocorp

Check out our corporate website by going to www.agcocorp.com.

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


Re: how to determine Operating System in Use?

2006-12-13 Thread James Cunningham
On 2006-12-13 19:28:14 -0500, [EMAIL PROTECTED] said:

> 
> 
> On Dec 13, 6:32 pm, "Ian F. Hood" <[EMAIL PROTECTED]> wrote:
>> Hi
>> In typically windows environments I have used:
>> if 'Windows' in os.environ['OS']...
>> to prove it, but now I need to properly support different environments.
>> To do so I must accurately determine what system the python instance is
>> running on (linux, win, mac, etc).
>> Is there a best practises way to do this?
>> TIA
>> Ian
> 
> I would do this:
> 
> if os.name == ''posix':
> linuxStuff()
> elif os.name == 'nt':
> windowsStuff()
> elif os.name == 'os2': ...
> ---
> os.name is  'posix', 'nt', 'os2', 'mac', 'ce' or 'riscos'
> 
> -N

Bearing in mind, of course, that Mac will return "posix", too. And 
Cygwin might. Erg.

Best,
James

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


Re: how to determine Operating System in Use?

2006-12-13 Thread Ian F. Hood
excellent, ty

<[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
>
>
> On Dec 13, 6:32 pm, "Ian F. Hood" <[EMAIL PROTECTED]> wrote:
>> Hi
>> In typically windows environments I have used:
>> if 'Windows' in os.environ['OS']...
>> to prove it, but now I need to properly support different environments.
>> To do so I must accurately determine what system the python instance is
>> running on (linux, win, mac, etc).
>> Is there a best practises way to do this?
>> TIA
>> Ian
>
> I would do this:
> 
> if os.name == ''posix':
>linuxStuff()
> elif os.name == 'nt':
>windowsStuff()
> elif os.name == 'os2': ...
> ---
> os.name is  'posix', 'nt', 'os2', 'mac', 'ce' or 'riscos'
>
> -N
>
> -- 
> http://mail.python.org/mailman/listinfo/python-list
> 



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


Re: how to determine Operating System in Use?

2006-12-13 Thread Ian F. Hood
I am integrating with an existing cross-platform system that provides 
different shell scripts and/or batch files for each environment.  Normally 
the selection is performed manually but my utility needs to automate this. 
To select the correct utility I need to know what platform my code is 
running on.

"Paul Watson" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> Ian F. Hood wrote:
>> Hi
>> In typically windows environments I have used:
>> if 'Windows' in os.environ['OS']...
>> to prove it, but now I need to properly support different environments.
>> To do so I must accurately determine what system the python instance is
>> running on (linux, win, mac, etc).
>> Is there a best practises way to do this?
>> TIA
>> Ian
>
> The more significant question is "why" do you want to do this?  Are you
> writing an asset management tool?  Do you just want to tell the user
> what operating system they are using?  The reason may lead to a
> different solution.
> -- 
> http://mail.python.org/mailman/listinfo/python-list
> 



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


Re: Conditional iteration

2006-12-13 Thread greg
at wrote:

> It is not the addional line containing 'if x > 0:' that bothers me, but the
> additional indentation.

I don't find the additional indentation bothersome.
In fact I think it's helpful, because it makes it
obvious that there is something else going on besides
just a loop.

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


Re: merits of Lisp vs Python

2006-12-13 Thread greg
Ken Tilton wrote:

> pps. How would Python do this?

Here's one way it could look:

   defskill("absolute-value",
 title = "Absolute Value",
 annotations = [
  "Take the absolute value of #op#.",
  "The vertical bars around #op# mean 'the absolute value of' #op#.",
  "Absolute value of #strn# is the 'distance' of #strn# from zero.",
  "Absolute value is always zero or positive: #str|n|=n#, and #str|-n|=n#."
 ],
 hints = [
  "What do those vertical bars around #op# mean?",
  "Have you learned about 'absolute value'?",
  """Absolute value can be thought of as the 'distance' of a value from
 zero on the number line, and distance is always positive.""",
  "The rule is:#str|-n|=|n|##str=n#.  Can you apply that to #op#?",
  "Some examples: #str|+42|=42#, #str|-42|=42#, and #str|0|=0#.",
  """To get the absolute value of a number such as #op#, we simply drop
 any minus sign."""
 ]
   )

 > Is it possible to avoid committing to an
 > implementation mechanism?

The defskill function could do just about anything with this.
Here's one possibility:

   skills = {}

   class Skill:
 pass # fill in whatever methods you need here

   def defskill(name, title, annotations, hints):
 skill = Skill()
 skill.title = title
 skill.annotations = annotations
 skill.hints = hints
 skills[name] = skill

This gives you a dictionary of Skill instances indexed by name,
each one having a title and lists of annotation and hint strings.
The rest of the system can process this however required.

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


Re: how to determine Operating System in Use?

2006-12-13 Thread Paul Watson
Ian F. Hood wrote:
> Hi
> In typically windows environments I have used:
> if 'Windows' in os.environ['OS']...
> to prove it, but now I need to properly support different environments.
> To do so I must accurately determine what system the python instance is 
> running on (linux, win, mac, etc).
> Is there a best practises way to do this?
> TIA
> Ian

The more significant question is "why" do you want to do this?  Are you 
writing an asset management tool?  Do you just want to tell the user 
what operating system they are using?  The reason may lead to a 
different solution.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Password, trust and user notification

2006-12-13 Thread placid

Gabriel Genellina wrote:
> At Wednesday 13/12/2006 21:44, Aidan Steele wrote:
>
> >While what you said is technically correct, I think you misread
> >their original question. They want to send email *from* the Gmail
> >account *to* the work account. I suggested that he use Gmail's SMTP
> >server to send the email.

This is correct.

> They were concerned about putting sensitive information (password)
> inside the script, in order to connect to Gmail to send the mail 
> notifications.
> I say that there is no need to use Gmail smtp services: to send mail
> *to* [EMAIL PROTECTED], you only have to connect to the right SMTP
> server for anywhere.com. The *from* email address is irrelevant and
> can even be faked.
> Of course a spam filter could block such mails, but you have to test it.

I was concerned that how does the person who will enter her password
trust the script or the developer in that the script will not create an
email containing her details i.e password and send it off to himself?
(See the assumptions i also posted above in my original post)

Is there any other way of notifying the user of events occurring in the
script which will run as a daemon process.


Cheers

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


Re: The Famous Error Message: "ImportError: No module named python_script"

2006-12-13 Thread rich murphy
Thank you both for responding.

Yes of course the file has the ".py" extension and yes I went through
the tutorial.


Gabriel Genellina wrote:
> At Wednesday 13/12/2006 22:16, rich murphy wrote:
>
> >I am studying Python language. I have Python 2.5 installed in my PC
> >which is running on Windows XP. I placed the the script called
> >"python_script" in C:\Python25 directory where all the other Python
> >files are.
>
> Verify the file name, should be "python_script.py"
>
> You may want to un-select "Hide extensions for known file types" in
> Windows Explorer options.
>
>
> --
> Gabriel Genellina
> Softlab SRL
>
> __
> Correo Yahoo!
> Espacio para todos tus mensajes, antivirus y antispam ¡gratis!
> ¡Abrí tu cuenta ya! - http://correo.yahoo.com.ar

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


Python training in Colorado, January 2007

2006-12-13 Thread Mark Lutz
Python author and trainer Mark Lutz will be teaching another
3-day Python class at a conference center in Longmont, Colorado,
on January 23-25, 2007.

This is a public training session open to individual enrollments,
and covers the same topics as the 3-day onsite sessions that Mark
teaches, with hands-on lab work.

For more information on this, and our other 2007 public classes,
please visit these web pages:

http://home.earthlink.net/~python-training/longmont-public-classes.htm

http://home.earthlink.net/~python-training/public_classes.html

Thanks for your interest.
--Python Training Services, Inc.

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


Re: Conditional iteration

2006-12-13 Thread Paul Rubin
at <[EMAIL PROTECTED]> writes:
> You proposal, seems nice to me but it doesn't work with Python 2.4.3, should
> it work with 2.5?
> 
> Again I am just wondering if the approach for 
> 
> [x for c x in some_list if some_condition]
> 
> and
> x = a if b else c
> 
> could be generalized for normal straight forward iterations:
> 
> for x in some_list if some_condition:

Sorry, I got it wrong.  Should have said:

   for x in (x for x in some_list if some_condition): 
  ...

So your example would have been:

  for x in (x for x in [-2, -1, 0, 1, 2, 3, 4] if x > 0):
   ... more code ...

It should work in 2.4.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Conditional iteration

2006-12-13 Thread Carl Banks
at wrote:
> Well, all I can say that for me as a user it would make sense...

Which is, like, step one out of a hundred for getting a syntax change
into the language.

> Curiosity: in what sense is it redundant?

It creates syntactical support for two different ways to do something.
If your plan were adopted, then we'd have two different spellings for
the same thing:

for i in a:
if i != 0:
use(i)

for i in a if i != 0:
use(i)

Now, redundant syntax isn't a deal breaker by itself.  You have to ask
what is buys you.  In this case, all it does is save you a single level
of indentation--that's it.  There's no performance benefit.  It doesn't
simplify logic.  It doesn't make the code any more readable of clear.
It's only a minor improvement in conciseness.  It hardly saves any
typing (unless you indent by hand).  Even its one clear benefit, saving
indentation, is something you can already get with "if not x:
continue".

Considering how little this syntax change buys, it really doesn't make
a lot of sense for a language that places high emphasis on avoiding
redundancy.


> All solution/workarounds I have seen so far involve creation of new lists
> (subsets) adding to more processing/computation/memory usage. Redundant
> suggests that you know alternatives that don't do that.
>
> Does Guido ever change his mind?

Yes, but I guarantee "it makes sense for me" isn't going to convince
him.  By the way, I'd suggest when posting to comp.lang.python and/or
python-list in the future, you put your replies beneath the quoted text
for the benefit of any future readers (not to mention present readers).


Carl Banks

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


Re: newb: Creating Exception

2006-12-13 Thread johnny
I checked out couple of books from Library, one that I like called
"Foundation of Python Network Programming", this is what I needed, code
with understandable explantion.  ;)  Thread pooling and many others.
Thanks all of you for the help.


Dustan wrote:
> Dennis Lee Bieber wrote:
> > On 13 Dec 2006 03:52:49 -0800, "Dustan" <[EMAIL PROTECTED]>
> > declaimed the following in gmane.comp.python.general:
> >
> > >
> > > I didn't complete my thought. If you run into a situation like this,
> > > then you might want to look to the python documentation on the web for
> > > help; think of the web documentation as a reference manual rather than
> > > a tutorial, even though it does provide a tutorial.
> >
> > I believe it was stated that the installation was using the
> > ActiveState build. The documentation is supplied in Windows CHM format,
> > which is likely much faster to search/read locally than loading a chain
> > of web pages.
>
> I couldn't think of a better word to describe the 'official'
> documentation.
>
> > Including, last time I checked, an electronic copy of "Dive into
> > Python"

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


Re: The Famous Error Message: "ImportError: No module named python_script"

2006-12-13 Thread Ben Finney
"rich murphy" <[EMAIL PROTECTED]> writes:

> I am studying Python language.

Welcome! Allow me to direct you to the Python tutorial:

http://docs.python.org/tut/>

Please take the time to work through all the exercises in that
document, understanding each one before moving on.

I recommend this because:

> I placed the the script called "python_script" in C:\Python25
> directory where all the other Python files are.

you would not make this mistake if you had already worked through the
tutorial.

Enjoy!

-- 
 \ "On the other hand, you have different fingers."  -- Steven |
  `\Wright |
_o__)  |
Ben Finney

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


Re: merits of Lisp vs Python

2006-12-13 Thread Paul Rubin
Ken Tilton <[EMAIL PROTECTED]> writes:
> pps. How would Python do this? Is it possible to avoid committing to
> an implementation mechanism? Compare and contrast. k

You'd just write a function.  Python's expression syntax is comparable
to a Lisp reader (you can have nested values of mixed types etc.) so
you can use Python expressions to initialize pretty much anything.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Iterating over several lists at once

2006-12-13 Thread Michael Spencer
John Henry wrote:
> Carl Banks wrote:
> 
>> The function can be extended to allow arbitrary arguments.  Here's a
>> non-minmal recursive version.
>>
>> def cartesian_product(*args):
>> if len(args) > 1:
>> for item in args[0]:
>> for rest in cartesian_product(*args[1:]):
>> yield (item,) + rest
>> elif len(args) == 1:
>> for item in args[0]:
>> yield (item,)
>> else:
>> yield ()
>>
>>
> 
> Very nice.
> 
another implementation of cartesian_product using 'reduce' to add 
mystery ;-)

def star(outer, inner):
 for rest in outer:
 for item in inner:
 yield rest + (item,)

def cartesian_product(*args):
 return reduce(star, args, ((),))

  >>> list(cartesian_product("01","01","01"))
  [('0', '0', '0'), ('0', '0', '1'), ('0', '1', '0'), ('0', '1', '1'), 
('1', '0', '0'), ('1', '0', '1'), ('1', '1', '0'), ('1', '1', '1')]
  >>>

Michael

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


Re: newb: Creating Exception

2006-12-13 Thread Dustan
Dennis Lee Bieber wrote:
> On 13 Dec 2006 03:52:49 -0800, "Dustan" <[EMAIL PROTECTED]>
> declaimed the following in gmane.comp.python.general:
>
> >
> > I didn't complete my thought. If you run into a situation like this,
> > then you might want to look to the python documentation on the web for
> > help; think of the web documentation as a reference manual rather than
> > a tutorial, even though it does provide a tutorial.
>
>   I believe it was stated that the installation was using the
> ActiveState build. The documentation is supplied in Windows CHM format,
> which is likely much faster to search/read locally than loading a chain
> of web pages.

I couldn't think of a better word to describe the 'official'
documentation.

>   Including, last time I checked, an electronic copy of "Dive into
> Python"

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


Re: The Famous Error Message: "ImportError: No module named python_script"

2006-12-13 Thread Gabriel Genellina

At Wednesday 13/12/2006 22:16, rich murphy wrote:


I am studying Python language. I have Python 2.5 installed in my PC
which is running on Windows XP. I placed the the script called
"python_script" in C:\Python25 directory where all the other Python
files are.


Verify the file name, should be "python_script.py"

You may want to un-select "Hide extensions for known file types" in 
Windows Explorer options.



--
Gabriel Genellina
Softlab SRL 


__
Correo Yahoo!
Espacio para todos tus mensajes, antivirus y antispam ¡gratis! 
¡Abrí tu cuenta ya! - http://correo.yahoo.com.ar
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: speed of python vs matlab.

2006-12-13 Thread Chao
My Bad,  the time used by python is 0.46~0.49 sec,
I tried xrange, but it doesn't make things better.

import time
tic = time.time()
a = 1.0

array = range(1000)

for i in array:
for j in array:
a = a + 0.1

toc = time.time()
print toc-tic,' has elapsed'

used by matlab is 0.012sec

tic
a = 1;
for i=1:1000
for j=1:1000
a = a + 1;
end
end
toc

used by ruby is 0.94~0.96sec

a = 1
start = Time.now()

1000.times do
  1000.times do
a = a + 1
  end
end

finish = Time.now()

puts finish - start


Andrew Sackville-West wrote:
> On Wed, Dec 13, 2006 at 04:07:20PM -0800, Chao wrote:
> > I've been trying to develop some numerical codes with python, however
> > got disappointed.
> >
> > A very simple test,
> >
> > a = 1.0
> >
> > for i in range(1000):
> >  for j in range(1000):
> >a = a+1
> >
> > unfortunately, it took 4.5 seconds to finish(my machines is fine. P4
> > 3.0G, 1G RAM, it varies according to machine configuration, but should
> > be in the same level)
>
> somethings not right there.
>
> [EMAIL PROTECTED]:~$ cat pytimetest.py
> a=1.0
> for i in range (1000):
> for j in range (1000):
>  a=a+1
>
>
> [EMAIL PROTECTED]:~$ time python pytimetest.py
>
> real0m0.534s
> user0m0.528s
> sys 0m0.000s
>
>
> [EMAIL PROTECTED]:~$ cat /proc/cpuinfo  | grep name
> model name  : Intel(R) Celeron(R) CPU 2.53GHz
>
> [EMAIL PROTECTED]:~$ uname -a
> Linux debian 2.6.18-3-686 #1 SMP Mon Dec 4 16:41:14 UTC 2006 i686
> GNU/Linux
>
> A
>
> --7AUc2qLy4jB3hD7Z
> Content-Type: application/pgp-signature
> Content-Disposition: inline;
>   filename="signature.asc"
> Content-Description: Digital signature
> X-Google-AttachSize: 190

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


Re: Defining classes

2006-12-13 Thread Michael Spencer
Nick Maclaren wrote:
> 
> Well, I am already doing that, and regretting the fact that Python
> doesn't seem to allow a class instantiation to return a new class :-)
> 

  >>> class Fake(object):
  ... def __new__(cls):
  ... return 42
  ...
  >>> Fake()
  42
  >>>

"instantiation" (i.e., calling the __new__ method) of new-style classes 
can return whatever you like, but I'm not sure how that helps.

One way of having a class member refer to the class, is to use the 
descriptor protocol, e.g.,:

  >>> def brinjal(cls): return cls.__name__
  ...
   >>> class Brinjal(object): # must be new-style
  ... def __get__(self, obj, cls):
  return brinjal(cls)

  ...
  >>> class Weeble(object): # should be new-style
  ... wumpus = Brinjal()
  ...
  >>> Weeble.wumpus
  'Weeble'
  >>> Weeble().wumpus
  'Weeble'
  >>>


Michael

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


The Famous Error Message: "ImportError: No module named python_script"

2006-12-13 Thread rich murphy

I am studying Python language. I have Python 2.5 installed in my PC
which is running on Windows XP. I placed the the script called
"python_script" in C:\Python25 directory where all the other Python
files are.

When I tried to import the script called "python_script", it kept
printing the famous error message: "ImportError: No module named
python_script".

I took the file out of "C:\Python25" directory, placed it in
'C:\PythonTests'. The error message kept coming.

The "import" commnand will not work at all.


>>> import python_script

Traceback (most recent call last):
  File "", line 1, in 
ImportError: No module named python_script

>>> import sys

>>> sys.path
['', 'C:\\WINDOWS\\system32\\python25.zip', 'C:\\Python25\\DLLs',
'C:\\Python25\
\lib', 'C:\\Python25\\lib\\plat-win', 'C:\\Python25\\lib\\lib-tk',
'C:\\Python25
', 'C:\\Python25\\lib\\site-packages']

>>> sys.path
['', 'C:\\WINDOWS\\system32\\python25.zip', 'C:\\Python25\\DLLs',
'C:\\Python25\
\lib', 'C:\\Python25\\lib\\plat-win', 'C:\\Python25\\lib\\lib-tk',
'C:\\Python25
', 'C:\\Python25\\lib\\site-packages']

>>> sys.path.append('C:\PythonTests')

>>> sys.path
['', 'C:\\WINDOWS\\system32\\python25.zip', 'C:\\Python25\\DLLs',
'C:\\Python25\
\lib', 'C:\\Python25\\lib\\plat-win', 'C:\\Python25\\lib\\lib-tk',
'C:\\Python25
', 'C:\\Python25\\lib\\site-packages', 'C:\\PythonTests']


I uninstall Python2.5, installed Python2.4: the result is the same. The
result is the same with older versions of Python also.

Does anybody know a remedy for this???

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


Re: Password, trust and user notification

2006-12-13 Thread Aidan Steele

On 12/14/06, Gabriel Genellina <[EMAIL PROTECTED]> wrote:


At Wednesday 13/12/2006 21:44, Aidan Steele wrote:

>While what you said is technically correct, I think you misread
>their original question. They want to send email *from* the Gmail
>account *to* the work account. I suggested that he use Gmail's SMTP
>server to send the email.

They were concerned about putting sensitive information (password)
inside the script, in order to connect to Gmail to send the mail
notifications.
I say that there is no need to use Gmail smtp services: to send mail
*to* [EMAIL PROTECTED], you only have to connect to the right SMTP
server for anywhere.com. The *from* email address is irrelevant and
can even be faked.
Of course a spam filter could block such mails, but you have to test it.


--
Gabriel Genellina
Softlab SRL

__
Correo Yahoo!
Espacio para todos tus mensajes, antivirus y antispam ¡gratis!
¡Abrí tu cuenta ya! - http://correo.yahoo.com.ar



Rather than "could block such mails" [sic], I'm fairly certain any
respectable server would drop the mail. The prevalence of SPF and other
assorted tools combat this, when used for malicious purposes. Sure, it's
worth trying, but I doubt it will work. Good luck to them. ;-)

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

Re: Password, trust and user notification

2006-12-13 Thread Gabriel Genellina

At Wednesday 13/12/2006 21:44, Aidan Steele wrote:

While what you said is technically correct, I think you misread 
their original question. They want to send email *from* the Gmail 
account *to* the work account. I suggested that he use Gmail's SMTP 
server to send the email.


They were concerned about putting sensitive information (password) 
inside the script, in order to connect to Gmail to send the mail notifications.
I say that there is no need to use Gmail smtp services: to send mail 
*to* [EMAIL PROTECTED], you only have to connect to the right SMTP 
server for anywhere.com. The *from* email address is irrelevant and 
can even be faked.

Of course a spam filter could block such mails, but you have to test it.


--
Gabriel Genellina
Softlab SRL 


__
Correo Yahoo!
Espacio para todos tus mensajes, antivirus y antispam ¡gratis! 
¡Abrí tu cuenta ya! - http://correo.yahoo.com.ar
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: speed of python vs matlab.

2006-12-13 Thread Andrew Sackville-West
On Wed, Dec 13, 2006 at 04:07:20PM -0800, Chao wrote:
> I've been trying to develop some numerical codes with python, however
> got disappointed.
> 
> A very simple test,
> 
> a = 1.0
> 
> for i in range(1000):
>  for j in range(1000):
>a = a+1
> 
> unfortunately, it took 4.5 seconds to finish(my machines is fine. P4
> 3.0G, 1G RAM, it varies according to machine configuration, but should
> be in the same level)

somethings not right there.

[EMAIL PROTECTED]:~$ cat pytimetest.py
a=1.0
for i in range (1000):
for j in range (1000):
 a=a+1


[EMAIL PROTECTED]:~$ time python pytimetest.py

real0m0.534s
user0m0.528s
sys 0m0.000s


[EMAIL PROTECTED]:~$ cat /proc/cpuinfo  | grep name
model name  : Intel(R) Celeron(R) CPU 2.53GHz

[EMAIL PROTECTED]:~$ uname -a
Linux debian 2.6.18-3-686 #1 SMP Mon Dec 4 16:41:14 UTC 2006 i686
GNU/Linux

A


signature.asc
Description: Digital signature
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: speed of python vs matlab.

2006-12-13 Thread Gabriel Genellina

At Wednesday 13/12/2006 21:07, Chao wrote:


I've been trying to develop some numerical codes with python, however
got disappointed.

A very simple test,

a = 1.0

for i in range(1000):
 for j in range(1000):
   a = a+1

unfortunately, it took 4.5 seconds to finish(my machines is fine. P4
3.0G, 1G RAM, it varies according to machine configuration, but should
be in the same level)


How do you measure it? 4.5 secs is far too much. Anyway, try using 
xrange instead of range. This is the standard way to do timings:


--- cut ---
def test():
a = 1.0
for i in xrange(1000):
 for j in xrange(1000):
 a = a+1

if __name__=='__main__':
from timeit import Timer
t = Timer("test()", "from __main__ import test")
print t.repeat(repeat=3,number=1)
--- cut ---

I got about 0.24 secs with far less hardware.

For vector-oriented operations the NumArray package is well suited.


--
Gabriel Genellina
Softlab SRL 


__
Correo Yahoo!
Espacio para todos tus mensajes, antivirus y antispam ¡gratis! 
¡Abrí tu cuenta ya! - http://correo.yahoo.com.ar
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Password, trust and user notification

2006-12-13 Thread Aidan Steele

On 12/14/06, Gabriel Genellina <[EMAIL PROTECTED]> wrote:


At Wednesday 13/12/2006 20:45, placid wrote:

> > You DON'T need the password for the receiving account just to send him
> > an email!
> > And you don't even need that special Gmail library, smtplib should be
> > fine.
>
>Yes you dont need a password to receive email, but to access Gmail and
>send an email you do. Yes you do need the Gmail library to access Gmail
>because the script will run on a computer that doesnt have a smtp
>server.
>
>Is there other way's of notifying the user?

Use the standard SMTP class to connect to the destination SMTP server.
To determine the right server, issue a DNS request for MX records on
the destination domain. (You may have to search for any suitable DNS
module since none is available in the standard Python distribution).

If you are really too lazy and you *know* the destination will
*always* be a gmail account and you don't bother if things go wrong
tomorrow, these are some current MX records for gmail.com:



While what you said is technically correct, I think you misread their
original question. They want to send email *from* the Gmail account *to* the
work account. I suggested that he use Gmail's SMTP server to send the email.

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

Re: Password, trust and user notification

2006-12-13 Thread Gabriel Genellina

At Wednesday 13/12/2006 20:45, placid wrote:


> You DON'T need the password for the receiving account just to send him
> an email!
> And you don't even need that special Gmail library, smtplib should be
> fine.

Yes you dont need a password to receive email, but to access Gmail and
send an email you do. Yes you do need the Gmail library to access Gmail
because the script will run on a computer that doesnt have a smtp
server.

Is there other way's of notifying the user?


Use the standard SMTP class to connect to the destination SMTP server.
To determine the right server, issue a DNS request for MX records on 
the destination domain. (You may have to search for any suitable DNS 
module since none is available in the standard Python distribution).


If you are really too lazy and you *know* the destination will 
*always* be a gmail account and you don't bother if things go wrong 
tomorrow, these are some current MX records for gmail.com:

- Name=gmail.com
Preference=5, Mail Exchange=gmail-smtp-in.l.google.com
Preference=10, Mail Exchange=alt1.gmail-smtp-in.l.google.com
Preference=10, Mail Exchange=alt2.gmail-smtp-in.l.google.com
Preference=50, Mail Exchange=gsmtp163.google.com
Preference=50, Mail Exchange=gsmtp183.google.com


--
Gabriel Genellina
Softlab SRL 


__
Correo Yahoo!
Espacio para todos tus mensajes, antivirus y antispam ¡gratis! 
¡Abrí tu cuenta ya! - http://correo.yahoo.com.ar
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: How do I edit a PythonWin path to import custom built modules???

2006-12-13 Thread BartlebyScrivener
jay graves wrote:
> 
> Do you have any *.pth files in the C:\Python24 directory?
> 

No.

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


Re: how to determine Operating System in Use?

2006-12-13 Thread nanjundi


On Dec 13, 6:32 pm, "Ian F. Hood" <[EMAIL PROTECTED]> wrote:
> Hi
> In typically windows environments I have used:
> if 'Windows' in os.environ['OS']...
> to prove it, but now I need to properly support different environments.
> To do so I must accurately determine what system the python instance is
> running on (linux, win, mac, etc).
> Is there a best practises way to do this?
> TIA
> Ian

I would do this:

if os.name == ''posix':
linuxStuff()
elif os.name == 'nt':
windowsStuff()
elif os.name == 'os2': ...
---
os.name is  'posix', 'nt', 'os2', 'mac', 'ce' or 'riscos'

-N

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


Re: How do I edit a PythonWin path to import custom built modules???

2006-12-13 Thread BartlebyScrivener
Fredrik Lundh wrote:

> what do you get if you do:

> > python -S
> ...
>>> import sys
>>> sys.path

['', 'C:\\WINDOWS\\system32\\python24.zip', 'd:\\python',
'C:\\Python24\\DLLs', 'C:\\Python24\\lib',
'C:\\Python24\\lib\\plat-win', 'C:\\Python24\\lib\\lib-tk', 'C:\
\Python24']

> and then

>>> import site
>>> sys.path

['d:\\python', 'C:\\WINDOWS\\system32\\python24.zip',
'C:\\Python24\\DLLs', 'C:\\Python24\\lib',
'C:\\Python24\\lib\\plat-win', 'C:\\Python24\\lib\\lib-tk', 'C:\\Pyt
hon24', 'C:\\Python24\\lib\\site-packages',
'C:\\Python24\\lib\\site-packages\\win32',
'C:\\Python24\\lib\\site-packages\\win32\\lib',
'C:\\Python24\\lib\\site-packa
ges\\Pythonwin', 'C:\\Python24\\lib\\site-packages\\wx-2.7.1-msw-ansi']

rd

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


Re: merits of Lisp vs Python

2006-12-13 Thread Ken Tilton


Ken Tilton wrote:
> 
> 
> Paul Rubin wrote:
> 
>> Ken Tilton <[EMAIL PROTECTED]> writes:
>>
>>> Have you read On Lisp by Paul Graham? It is on-line. Just the preface
>>> will do, I think, maybe also Chapter One where he raves on macros. Do
>>> you think he is mistaken? Confused? Lying? Mutant?
>>
>>
>>
>> I remember Paul Graham's piece about macros that made him sound like
>> someone who went nuts with them, as is certainly possible to do.
> 
> 
> But you could have just flipped thru the rest of the pages to see if he 
> /had/ gone nuts with them!
> 
>>  In
>> my experience, good coders write for clarity and that includes in
>> their use of Lisp macros.  All in all Lisp's macro system is something
>> like the C preprocessor.  Yes, you can obfuscate things horribly with
>> it, but you can also use it to make things clearer, and that's what
>> good programmers do.
> 
> 
> One has to be from the US and of a certain age to remember this, but 
> this old line from a commercial for high-octane gasoline says it for me: 
> power to be used, not abused.

Here is a bit of concrete I just tossed off:

(defmacro defskill (id &body skill-info)
   `(progn
  ,@(loop with sub-id = id
  for (q . q-def) in skill-info
  collecting
(ecase q
   ((title annotations hints)
`(defmethod ,(intern (conc$ 'skill- q)) ((tf-id (eql 
',sub-id)))
  ,@q-def))

It lets me code this:

(defskill absolute-value
 (title "Absolute Value")
   (annotations
"Take the absolute value of #op#."
"The vertical bars around #op# mean 'the absolute value of' #op#."
"Absolute value of #strn# is the 'distance' of #strn# from zero."
"Absolute value is always zero or positive: #str|n|=n#, and 
#str|-n|=n#.")
   (hints
"What do those vertical bars around #op# mean?"
"Have you learned about 'absolute value'?"
"Absolute value can be thought of as the 'distance' of a value from 
zero on the number line, and distance is always positive."
"The rule is:#str|-n|=|n|##str=n#.  Can you apply that to #op#?"
"Some examples: #str|+42|=42#, #str|-42|=42#, and #str|0|=0#."
"To get the absolute value of a number such as #op#, we simply drop 
any minus sign."))


...and get this:

(PROGN
  (DEFMETHOD SKILL-TITLE ((TF-ID (EQL 'ABSOLUTE-VALUE)))
 "Absolute Value")
  (DEFMETHOD SKILL-ANNOTATIONS ((TF-ID (EQL 'ABSOLUTE-VALUE)))
  "Take the absolute value of #op#." "The vertical bars around #op# 
mean 'the absolute value of' #op#."
  "Absolute value of #strn# is the 'distance' of #strn# from zero." 
"Absolute value is always zero or positive: #strn=n#, and #str-n=n#.")
   (DEFMETHOD SKILL-HINTS ((TF-ID (EQL 'ABSOLUTE-VALUE)))
  "What do those vertical bars around #op# mean?" "Have you learned 
about 'absolute value'?"
  "Absolute value can be thought of as the 'distance' of a value 
from zero on the number line, and distance is always positive."
  "The rule is:#str-n=n##str=n#.  Can you apply that to #op#?" "Some 
examples: #str+42=42#, #str-42=42#, and #str0=0#."
  "To get the absolute value of a number such as #op#, we simply 
drop any minus sign."))

The above is how my upcoming death-defying interactive Algebra 
tutor-in-a-drum ("You'll laugh! You'll cry!") will know how to coax some 
  befuddled teen through |-42| -> 42 if they get stuck. And a hundred 
other subskills (so there will be a hundred of these definitions).

If I hire someone they will look at defskill and not fall to the ground 
frothing at the mouth. They likely will not even macroexpand it because 
it is self-explanatory. If they wonder if there are other options they 
can alt-. to the source. The language has been extended, but I followed 
a pattern familiar to Lispniks. Zero confusion results.

If I decide not to use generic method dispatch to "look up" the hints I 
just have to change the macro and then write a DEFUN (no dispatch on 
type) to, say, look up the symbol in a hash table.

hth,ken

ps. I won't mention the other benefit, which is that I want educators to 
edit these if they have a better idea on how to tutor absolute value. I 
am not mentioning it because I am as impatient with superfluous syntax 
as a non-programmer would be. k

pps. How would Python do this? Is it possible to avoid committing to an 
implementation mechanism? Compare and contrast. k

-- 
Algebra: http://www.tilton-technology.com/LispNycAlgebra1.htm

"Well, I've wrestled with reality for thirty-five
years, Doctor, and I'm happy to state I finally
won out over it." -- Elwood P. Dowd

"I'll say I'm losing my grip, and it feels terrific."
-- Smiling husband to scowling wife, New Yorker cartoon
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Password, trust and user notification

2006-12-13 Thread Aidan Steele

On 13 Dec 2006 15:45:09 -0800, placid <[EMAIL PROTECTED]> wrote:



Gabriel Genellina wrote:


> You DON'T need the password for the receiving account just to send him
> an email!
> And you don't even need that special Gmail library, smtplib should be
> fine.

Yes you dont need a password to receive email, but to access Gmail and
send an email you do. Yes you do need the Gmail library to access Gmail
because the script will run on a computer that doesnt have a smtp
server.

Is there other way's of notifying the user?


Cheers

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




What Gabriel said was correct.  You can use smtplib to connect to Gmail's
SMTP server as the library supports SSL/TLS required by Gmail (see here:
http://mail.google.com/support/bin/answer.py?answer=13287&topic=1556)

You do not need a local SMTP server to use smtplib, just use the values
found in that provided URL. Hope this helps,

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

how to determine Operating System in Use?

2006-12-13 Thread Ian F. Hood
Hi
In typically windows environments I have used:
if 'Windows' in os.environ['OS']...
to prove it, but now I need to properly support different environments.
To do so I must accurately determine what system the python instance is 
running on (linux, win, mac, etc).
Is there a best practises way to do this?
TIA
Ian 



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


Re: mod_python.so is garbled mod_python.so is garbled

2006-12-13 Thread Graham Dumpleton

blbmdsmith wrote:
> Has anyone seen the following error while starting httpd:
>
> Starting httpd: httpd: Syntax error on line 54 of
> /usr/local/apache2/conf/httpd.conf: API module structure
> `python_module' in file /usr/local/apache/modules/mod_python.so is
> garbled - perhaps this is not an Apache module DSO
>
> I am running python2.5 with apache server 2.2.3, using
> mod_python-3.2.10
> I ran mod_python configure with-apxs= /usr/local/apache/bin/apxs
> --with-python=/usr/bin/python
>
> I have configured httpd.conf with the follwing lines:
>
> LoadModule python_module /usr/local/apache/modules/mod_python.so
>
> 
> AllowOverride FileInfo
> AddHandler mod_python .py
> PythonHandler mptest
> PythonDebug On
> 
>
> Thanks,
> Bill
>
> I have posted the same message on the mod_python group.  Is this a
> better group to post his message?

The "mod_python" Google group doesn't get used. You should be
subscribing to and posting on the mod_python mailing list for best
chances of a response. Mailing list details are on the mod_python web
site.

Should you have perhaps used:

  --with-apxs=/usr/local/apache2/bin/apxs

Ie., is the version of Apache you compiled for actually the version you
are running it with?

Do you have multiple versions of Apache installed on your system?

Graham

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


Re: speed of python vs matlab.

2006-12-13 Thread Aidan Steele

On 13 Dec 2006 16:07:20 -0800, Chao <[EMAIL PROTECTED]> wrote:


I've been trying to develop some numerical codes with python, however
got disappointed.

A very simple test,

a = 1.0

for i in range(1000):
 for j in range(1000):
   a = a+1

unfortunately, it took 4.5 seconds to finish(my machines is fine. P4
3.0G, 1G RAM, it varies according to machine configuration, but should
be in the same level)

for matlab, the same operation took 0.1 seconds,

I use numpy & scipy, they solve the problem most of the times, but
there are cases you can't avoid loops by vectors. I appreciate the
elegancy of python so much, but I guess I have to gave it up in these
numerical codes.(image processing algorithms),  for application
dev/scripting, it's still my first choice.

A good news is that the same code takes ruby 9.8 seconds.

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



Have you considered looking into Psyco? (http://psyco.sourceforge.net/) For
all the numeric operations that image processing algorithms entail, such a
tool will probably make a tremendous difference in terms of speed of
execution for you. Do yourself a favour and check it out.

Hope this helps,
Aidan Steele.
-- 
http://mail.python.org/mailman/listinfo/python-list

speed of python vs matlab.

2006-12-13 Thread Chao
I've been trying to develop some numerical codes with python, however
got disappointed.

A very simple test,

a = 1.0

for i in range(1000):
 for j in range(1000):
   a = a+1

unfortunately, it took 4.5 seconds to finish(my machines is fine. P4
3.0G, 1G RAM, it varies according to machine configuration, but should
be in the same level)

for matlab, the same operation took 0.1 seconds,

I use numpy & scipy, they solve the problem most of the times, but
there are cases you can't avoid loops by vectors. I appreciate the
elegancy of python so much, but I guess I have to gave it up in these
numerical codes.(image processing algorithms),  for application
dev/scripting, it's still my first choice.

A good news is that the same code takes ruby 9.8 seconds.

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


Re: call of __del__ non-deterministic in python 2.4 (cpython)?

2006-12-13 Thread Mathias Panzenboeck
Anthony Baxter wrote:
> On 12/13/06, Holger Joukl <[EMAIL PROTECTED]> wrote:
>> I did read this but didn't think it applied to my situation. I'm quite
>> sure that the refcount of the local variable is 1 before the local scope
>> is left.
>> So let me rephrase the question: Even if I can make sure that non of the
>> problematic situtions apply, might it _still_ happen that __del__ gets
>> called
>> after some other code has already been "entered"?
> 
> You shouldn't rely on __del__ being called exactly when you expect it,
> particularly in a threaded application. Make explicit cleanup calls,
> instead.

a nice way to do such things in python 2.5 is using the with statement. this 
ensures to call a
__exit__ (cleanup) function after a __enter__ function was called, no matter if 
there is a exception
or something other in between.

with open("foo.txt","w") as fp:
fp.write("foo")

translates to:

mgr = open("foo.txt","w")

# well, in the case of files, __enter__ just returns self
fp = mgr.__enter__()

try:
fp.write("foo")
finally:
mgr.__exit__() # this calls fp.close()


this of course is a simplified translation of the with statement.
see more details here: http://www.python.org/dev/peps/pep-0343/

with is also cool for using it in combination with mutexes and similar stuff.
it would also be possible to write a transaction manager which calls commit() 
or abort()
automatically, so you can just write:

with new_transaction():
# if do_stuff() returns, commit() will be called
# if it raises an exception abort() will be called
do_stuff()

But if you can't use python 2.5, there is no other way then:

try:
do_stuff()
finally:
cleanup()
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Password, trust and user notification

2006-12-13 Thread placid

Gabriel Genellina wrote:


> You DON'T need the password for the receiving account just to send him
> an email!
> And you don't even need that special Gmail library, smtplib should be
> fine.

Yes you dont need a password to receive email, but to access Gmail and
send an email you do. Yes you do need the Gmail library to access Gmail
because the script will run on a computer that doesnt have a smtp
server.

Is there other way's of notifying the user?


Cheers

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


mod_python.so is garbled mod_python.so is garbled

2006-12-13 Thread blbmdsmith
Has anyone seen the following error while starting httpd:

Starting httpd: httpd: Syntax error on line 54 of
/usr/local/apache2/conf/httpd.conf: API module structure
`python_module' in file /usr/local/apache/modules/mod_python.so is
garbled - perhaps this is not an Apache module DSO

I am running python2.5 with apache server 2.2.3, using
mod_python-3.2.10
I ran mod_python configure with-apxs= /usr/local/apache/bin/apxs
--with-python=/usr/bin/python

I have configured httpd.conf with the follwing lines:

LoadModule python_module /usr/local/apache/modules/mod_python.so


AllowOverride FileInfo
AddHandler mod_python .py
PythonHandler mptest
PythonDebug On


Thanks,
Bill

I have posted the same message on the mod_python group.  Is this a
better group to post his message?

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


Re: Obtaining SSL certificate info from SSL object - proposal

2006-12-13 Thread John Nagle
John Nagle wrote:
> Michael Ströder wrote:
> 
>> John Nagle wrote:
>>
>>>The Python SSL object offers two methods from obtaining
>>> the info from an SSL certificate, "server()" and "issuer()".
>>> The actual values in the certificate are a series of name/value
>>> pairs in ASN.1 binary format.  But what "server()" and "issuer()"
>>> return are strings, with the pairs separated by "/".  The
>>> documentation at "http://docs.python.org/lib/ssl-objects.html";
>>> says "Returns a string containing the ASN.1 distinguished name
>>> identifying the server's certificate. (See below for an example showing
>>> what distinguished names look like.)"  There is, however, no "below".

Since I really need this, I'm looking at modifying the Python SSL
interface to SSL objects by adding a function "certificate()" which
returns an X.509 certificate in the following format:

SSL certificates are trees, represented in a format, "ASN.1", which
allows storing numbers, strings, and flags.
Fields are identified by names or by assigned "OID numbers"
(see RFC 2459).

The tree is returned as tuples.  The first element of the tuple
is always a string giving the name of the field, and the second
element is a string, Boolean, or number giving the value, or
a list of more tuples.  The result is a tree, which will
resemble the tree typically displayed by browsers displaying
SSL certificates.

The top tuple's field name is the domain for which the certificate
applies.

Note that it is straightforward to implement "issuer" and "subject"
using "certificate", which provides a way out of the current problems
with those fields.

Example:

(   'www.google.com',
 (   'Certificate',
 [   ('Version', 3),
 (   'Serial Number',
 '4B:A5:AE:59:DE:DD:1C:C7:80:7C:89:22:91:F0:E2:43'),
 (   'Certificate Signature Algorithm',
 'PKCS #1 MD5 With RSA Encryption'),
 (   'Issuer',
 [   ('CN', 'Thawte SGC CA'),
 ('O', 'Thawte Consulting (Pty) Ltd.'),
 ('C', 'ZA')]),
 (   'Validity',
 [   ('Not Before', '5/15/2006 23:18:11 PM GMT'),
 ('Not After', '5/15/2007 23:18:11 PM GMT')]),
 (   'Subject',
 [   ('CN', 'www.google.com'),
 ('O', 'Google Inc'),
 ('L', 'Mountain View'),
 ('ST', 'California'),
 ('C', 'US')]),
 (   'Subject Public Key Info',
 [   (   'Subjects Public Key Algorithm',
 'PKCS #1 RSA Encryption'),
 (   'Subjects Public Key',
 '30 81 89 02 81 81 00 e6 c5 c6 8d cd 0b a3 03 
04dc ae cc  c9 46 be bd cc 9d bc 73 34 48 fe d3 7564 d0 c9 
c9 7
6 27 72 0f a9 96 1a 3b 81 f3 14 f6ae 90 56 e7 19 d2 73
68 a7 85 a4 ae ca 24 14 3000 ba e8 36 5d 81 73 3a 71 05 8f b1 af 11 87 da5c f
1 3e bf 53 51 84 6f 44 0e b7 e8 26 d7 2f b26f f2 f2 5d df a7 cf 8c a5 e9 1e 6f 
30 48 94 210b 01 ad ba 0e 71 01 0d 10 ef bf ee 2c d3
8d fe54 a8 fe d3 97 8f cb 02 03 01 00 01')]),
 (   'Certificate Signature Algorithm',
 'PKCS #1 MD5 With RSA Encryption'),
 (   'Certificate Signature Value',
 '57 4b bc a4 43 e7 e0 01 92 a0 96 35 f9 18 08 881d 7b 70 19 8f 
f9 36 b2 05 3a 05 ca 14 59 4d 240e e5 8a af 4e 87 5a
f7 1c 2a 96 8f cb 61 40 9ed2 b4 38 40 21 24 c1 4f 1f cb 13 4a 8f 95 02 df91 3d 
d6 40 eb 11 6f 9b 10 a1 6f ce 91 5e 30 f66d 13 5e 15
a4 2e c2 18 9e 00 c3 d8 32 67 47 fcb8 1e 9a d9 9a 8e cc ff 7c 12 b7 03 bf 52 20 
cf21 f4 f3 77 dd 12 15 f0 94 fa 90 d5 e3 59 68 81')]
))

 Comments?

John Nagle


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


Re: Defining classes

2006-12-13 Thread Nick Maclaren

In article <[EMAIL PROTECTED]>,
Duncan Booth <[EMAIL PROTECTED]> writes:
|> > 
|> > I am defining a class, and I need to refer to that class when
|> > setting up its static data - don't ask - like this:
|> > 
|> > Class weeble :
|> > wumpus = brinjal(weeble)
|> 
|> You cannot refer to weeble until it has been created which isn't until 
|> after all of the statements in the class body have executed. The usual way 
|> to achieve what you want is to assign the static member from outside the 
|> class.
|> 
|> class weeble:
|> pass
|> 
|> weeble.wumpus = brinjal(weeble)

Thanks (and to Gabriel Genellina).  That is what I am doing, but it is
not ideal in other respects - for example, I want to make that item
read-only!  It would be much cleaner not to have to fiddle with static
members after the class is initialised.

|> Alternatively you can play tricks with metaclasses for a similar effect.

Well, I am already doing that, and regretting the fact that Python
doesn't seem to allow a class instantiation to return a new class :-)

What I am trying to do is very simple, but is somewhat unusual.  That
is the story of my life, so I am used to having problems.


Regards,
Nick Maclaren.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Iterating over several lists at once

2006-12-13 Thread John Henry

Carl Banks wrote:

>
> The function can be extended to allow arbitrary arguments.  Here's a
> non-minmal recursive version.
>
> def cartesian_product(*args):
> if len(args) > 1:
> for item in args[0]:
> for rest in cartesian_product(*args[1:]):
> yield (item,) + rest
> elif len(args) == 1:
> for item in args[0]:
> yield (item,)
> else:
> yield ()
> 
> 

Very nice.

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


Re: Conditional iteration

2006-12-13 Thread at
Dear Carl,

Well, all I can say that for me as a user it would make sense...

Curiosity: in what sense is it redundant?
All solution/workarounds I have seen so far involve creation of new lists
(subsets) adding to more processing/computation/memory usage. Redundant
suggests that you know alternatives that don't do that.

Does Guido ever change his mind?

Cheers,

@


Carl Banks wrote:

> at wrote:
>> I am not looking for a work around but more interest if other people
>> might judge this syntax would come in handy?
> 
> Of course people have expressed interest in this in the past, but it's
> not going to happen.  There's a way to nest for and if statements, and
> a different way to nest for and if clauses in listcomps, and the two
> methods are considered distinct.  Although Guido has said that saving
> indentation levels is important, he hasn't said  anything (that I'm
> aware of) that suggests it's important enough to add this complexity
> and redundancy to the language.  Sorry.
> 
> 
> Carl Banks

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


Re: Conditional iteration

2006-12-13 Thread at
No offense, but my conclusions from your mail is that readability is a
matter of taste. 

My brains need to process a whole lot more information with your solution
than in my proposal...

but I read somewhere else that GvR rejected the proposal :-(

Ciao,
@


[EMAIL PROTECTED] wrote:

> The proposed solution impairs readability because there's a "surprise"
> at the end.  List comprehensions already open the language up to
> readability abuse.  Lets not add more.
> 
> To avoid the unwanted indentation, I would go with the already
> suggested "if not x>0: continue" solution or else something like this:
> 
> positiveMembers = [x for x in [-2, -1, 0, 1, 2, 3, 4] if x>0]
> for x in positiveMembers:
> #do stuff
> 
> This has the advantage of being more self-documenting.
> 
> at wrote:
>> I would like to spark the discussion about the following syntax problem I
>> encounter.
>>
>> THE PROBLEM
>>
>> I have a lot times the following code:
>>
>> for x in [-2, -1, 0, 1, 2, 3, 4]:
>> if x > 0:
>> ... more code...
>>
>>
>> It is not the addional line containing 'if x > 0:' that bothers me, but
>> the additional indentation.
>>
>>
>> THE SOLUTION
>>
>> More pythonic in view would be:
>>
>> for x in [-2, -1, 0, 1, 2, 3, 4] if x > 0:
>> ... more code ...
>>
>>
>> This blends basically
>>
>> [x for x in [-2, -1, 0, 1, 2, 3, 4] if x > 0]
>>
>> and
>>
>> x = y if x > 0 else 10
>>
>>
>> EXTENDING
>>
>> And maybe a few usefull variants, like:
>>
>> for x in [-2, -1, 0, 1, 2, 3, 4] if x > 0 else -x:
>> ... more code ...
>> 
>> In this case x will be 2, 1, 0, 1, 2, 3, 4.

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


Re: how can i write a hello world in chinese with python

2006-12-13 Thread MRAB

Dennis Lee Bieber wrote:
> On 12 Dec 2006 23:40:41 -0800, "kernel1983" <[EMAIL PROTECTED]>
> declaimed the following in gmane.comp.python.general:
>
> > and I tried unicode and utf-8
> > I tried to both use unicode&utf-8 head just like "\xEF\xBB\xBF" and not
> > to use
> >
>   "unicode" is a term covering many sins. "utf-8" is a specification
> for encoding elements of specific unicode characters using 8-bit
> elements (I believe by using certain codes x00 to x7F alone as "normal",
> and then x80 to xFF to represent an "escape" to higher [16-bit] element
> sets).
>
>   "\xEF\xBB\xBF" is just a byte string with no identifier of what
> encoding is in use (unless the first one or two are supposed to be
> BOM)... In the "Windows: Western" character set, it is equivalent to
> small-i-diaeresis/right-guillemot/upside-down? () In MS-DOS: Western
> Europe, those same bytes represent an
> acute-accent/double-down&left-box-drawing/solid-down&left
>
>   I've not done any unicode work (iso-latin-1, or subset thereof, has
> done for me). I also don't know Mac's, so I don't know if the windowing
> API has specific calls for Unicode data... But you probably have to
> encode or decod that bytestring into some compatible unicode
> representation.
>
When you save a textfile as UTF-8 in Notepad.exe (Windows) it puts the
bytestring "\xEF\xBB\xBF" at the start to indicate that it's UTF-8 and
not ANSI (ie 8-bit characters). The bytes are actually the BOM
bytestring "\xFE\xFF" encoded in UTF-8.

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

Re: merits of Lisp vs Python

2006-12-13 Thread David Golden
Actually, in English, "parenthesis" means the bit in between the
brackets.

The various kinds of brackets (amongst other punctuation marks
including, in most english texts, commas) *demarcate* parentheses.

Wikipedia's "Parenthesis (rhetoric)" is, at time of writing, the correct
British English definition, citing the OED:
http://en.wikipedia.org/wiki/Parenthesis_%28rhetoric%29

"An explanatory or qualifying word, clause, or sentence inserted into a
passage with which it has not necessarily any grammatical connection,
and from which it is usually marked off by round or square brackets,
dashes, or commas"

The use of round brackets to demarcate parentheses in america eventually
somehow led to round brackets themselves being called parentheses in
america, but that usage still makes little sense to many native
speakers of British (or Hiberno-) English outside the computing field.

It's like calling a quotation mark a "quote" instead of a "quotation
mark".  And lo, guess who does that too...

Calling round brackets "parenthesis marks" would be acceptable but
perhaps ambiguous in British English, probably needing further
qualification like "double quotation mark", "single quotation mark".












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


CLPython (was Re: merits of Lisp vs Python)

2006-12-13 Thread Paul Boddie
Willem Broekema wrote:
> Paul Rubin wrote:
> > Does this count as a "children of a lesser Python"?
>
> This sounds like a quite derogatory first question.

I wouldn't take it that way: it's only a quote from an opinion piece
about alternative Python implementations (albeit a contentious one).

> CLPython is not a dead and abandoned project, nor is execution speed
> its main goal, nor are Python semantics bended anywhere (it can run
> the Pie-thon benchmark). Sure, some recently introduced language
> features are missing, but with just a little effort that's solved...

What would it take to get Python people more interested in it? I've
been monitoring the site [1] and the mailing list [2] for some time,
but nothing particularly visible seems to be happening. And wouldn't a
more prominent announcement be the first step to some real publicity? I
think it only got announced on comp.lang.lisp [3] with someone picking
up on it in comp.lang.python. Perhaps getting it on the python.org
front page would attract some attention, although I accept that a lot
of Python developers would rather mess around writing C than writing
Lisp.

Anyway, I'm happy to hear that you're still working on CLPython.

Paul

P.S. Follow-ups set to comp.lang.python.

[1] http://trac.common-lisp.net/clpython/
[2] http://common-lisp.net/pipermail/clpython-devel/
[3] http://groups.google.com/group/comp.lang.lisp/msg/57ae88c5f9a59143

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


Re: Windows SetLocalTime

2006-12-13 Thread Podi
Thank you. It works :-)
P

Rob Williscroft wrote:

> Ok I see, you will probably need these 2 bits of the ctypes
> documentation:
>
>   http://docs.python.org/lib/ctypes-structures-unions.html
>   http://docs.python.org/lib/ctypes-pointers.html
> 
> From there on geting to this is farly straight forward:

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


Re: merits of Lisp vs Python

2006-12-13 Thread Kaz Kylheku
Rob Warnock wrote:
> And for any of you who are rejecting this because you don't want to
> learn or use Emacs, Raffael's point is even true in the Vi family of
> editors ("nvi" & "vim", at least). The "y%" command yanks (copies)
> everything through the matching paren into the anonymous buffer;
> "d%" deletes likewise [and saves in the anonymous buffer]; "p" (or "P")
> pastes after (or before) the current location. All can be prefixed
> with a buffer ("Q-register") name for more flexibility.

If you're on Vim, you also have the "ib" and "ab" commands that work
under visual selection. You repeat them to broaden the selection to the
next level of nesting.

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


Stupid email disclaimers (was: [unicode] inconvenient unicode conversion of non-string arguments)

2006-12-13 Thread Ben Finney
"Marc 'BlackJack' Rintsch" <[EMAIL PROTECTED]> writes:

> In <[EMAIL PROTECTED]>, Holger Joukl
> wrote:
> > [a meaningless disclaimer text at the bottom of every message]
>
> Maybe you should rethink if it really makes sense to add this huge
> block of "nonsense" to a post to a newsgroup or public mailing list.
> If it's confidential, just keep it secret.  ;-)

In all likelihood, the OP isn't choosing specifically to attach it;
these things are often done to *every* outgoing message at an
organisational level by people who don't think the issue through very
well.

http://goldmark.org/jeff/stupid-disclaimers/>

Please, those with such badly-configured systems, discuss the issue of
public discussion forums with the boneheads who think these disclaimer
texts are a good idea and at least try to change that behaviour.

Alternatively, post from some other mail system that doesn't slap
these obnoxious blocks onto your messages.

-- 
 \ "I wish there was a knob on the TV to turn up the intelligence. |
  `\  There's a knob called 'brightness' but it doesn't work."  -- |
_o__)  Eugene P. Gallagher |
Ben Finney

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


Re: How do I edit a PythonWin path to import custom built modules???

2006-12-13 Thread jay graves

BartlebyScrivener wrote:
> Yup. Did that before. That's what I mean. The d:\\python is there and
> it doesn't come from the PythonPath in my windows registry. Maybe it
> scans for any directory with python in the name?

Do you have any *.pth files in the C:\Python24 directory?

...
jay

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


Re: How do I edit a PythonWin path to import custom built modules???

2006-12-13 Thread Fredrik Lundh
BartlebyScrivener wrote:


> Yup. Did that before. That's what I mean. The d:\\python is there and
> it doesn't come from the PythonPath in my windows registry.

what do you get if you do:

 > python -S
...
 >>> import sys
 >>> sys.path

and then

 >>> import site
 >>> sys.path

?



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


Re: merits of Lisp vs Python

2006-12-13 Thread Slawomir Nowaczyk
On Sat, 09 Dec 2006 21:59:58 -0500
Ken Tilton <[EMAIL PROTECTED]> wrote:

#> > Could it be because of people like J Shrager who writes things like this?
#> > 
#> > "Can't you just expand the language via macros to create whatever facility
#> > of this sort [major new features with new syntax] you need..."
#> 
#> The context was CLOS. Something that big needs new syntax. 

Really? What if we *do not want* anything that big in Python?

#> > (This thread, dated 8 Dec 2006 23:38:02 -0800)
#> > 
#> > To someone outside of Lisp, that looks like "I can make Lisp look like any
#> > language I like in just a few lines."
#> 
#> On the contrary,

And you are the right person to say how things look like for *someone
outside Lisp* exactly why?

#> Your hands must be getting sore from banging that drum so hard and so
#> long -- has it ever occurred to you that good programmers concerned
#> with power do not obfuscate code?

Has it ever occurred to you that some of us need to read code written by
not-so-good programmers?

#> We love the chance to preach to the unsaved, so we are indebted to
#> you for the many chances to clarify, but something tells me I should
#> check the c.l.p archives to make sure I am not chatting away happily
#> with the village idiot. :)

Would you do me a favour and check the same thing on c.l.l while you are
at it?

#> > And that implies that to read a Lisp program, one might need to be
#> > able to read code that looks like Lisp, or Smalltalk, or Prolog, or
#> > Fortran, or all of those, or whatever bizarre syntax the developer
#> > wanted it to look like.
#> 
#> "I don't want to think, I just want to bang on de drum all day. I
#> don't want to learn, just want to bang on de drum all day."

Too bad for you.

Steven has a valid point here, BTW.

#> > Sure. But in the real world of programming, most developers aren't
#> > good developers, they are merely average
#> 
#> Two questions: do you really voluntarily use libraries from crappy
#> developers?

Voluntarily as in "in my work place"? I mean, I *am* voluntarily staying
employed, if you wish look at it this way...

#> Second, you think a language can stop people from writing bad code?

No. But writing bad code can be made more or less difficult.

-- 
 Best wishes,
   Slawomir Nowaczyk
 ( [EMAIL PROTECTED] )

"Consequences, shmonsequences! So long as I'm rich!" -- Daffy Duck

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


Re: merits of Lisp vs Python

2006-12-13 Thread Slawomir Nowaczyk
On Tue, 12 Dec 2006 20:38:14 -0800
"[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote:

#> > > Because it's the language for which indentation is automatically
#> > > determinable. That is, one can copy/paste a chunk of code, hit a
#> > > key and suddenly everything is nicely indented.
#> >
#> > Cool, so in other languages I need to set block marks like () and
#> > {} and also indent the code for readability, and in Python I indent
#> > only. From my POV that's less work.
#> 
#> Try reading again. In Lisp, you use () and *your editor*
#> automatically indents according to the universal standard,

How does that differ from "In Python, you use  and your editor
automatically indents according to the universal standard"?

#> or you leave it sloppy until other folks reading your code convince
#> you to get a proper programming editor.

Well, in Python you never need to leave it sloppy.

#> Indentation does not get out of sync with semantics because the
#> editor virtually never misses parentheses that the Lisp compiler
#> sees. 

What makes you think Python indentation ever gets out of sync with
semantics?

#> In Python, you group in your mind, and press indentation keys to make
#> it happen in your editor.

In Lisp, you group in your mind, and press parentheses keys to make it
happen in your editor.

#> The editor cannot help that much, because it cannot read your mind.

The editor cannot help that much, because it cannot read your mind.

-- 
 Best wishes,
   Slawomir Nowaczyk
 ( [EMAIL PROTECTED] )

You can't wake a person who is pretending to be asleep.

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


Re: merits of Lisp vs Python

2006-12-13 Thread Slawomir Nowaczyk
On Sun, 10 Dec 2006 17:11:20 +0200
"Dmitry V. Gorbatovsky" <[EMAIL PROTECTED]> wrote:

#> Steven D'Aprano wrote:
#> 
#> > So which is it? If Lisp is so self-evidently better than every other
#> > language, and if nobody has any fears or concerns with Lisp, why is Lisp a
#> > fringe language?

#> Because shifting to lisp somewhere in the middle of
#> your project or carear is VERY EXPENSIVE STEP.

Doesn't that say something about Lisp? Switching to most other useful
languages is a nice experience.

Luckily, that claim is obviously false.

-- 
 Best wishes,
   Slawomir Nowaczyk
 ( [EMAIL PROTECTED] )

Integrated Software:  A single product that deftly performs hundreds
of functions that the user never needs and awkwardly performs
the half-dozen he uses constantly.

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


Re: merits of Lisp vs Python

2006-12-13 Thread Slawomir Nowaczyk
On Sun, 10 Dec 2006 10:11:37 -0500
Ken Tilton <[EMAIL PROTECTED]> wrote:

#> Lisp has all the cool qualities you like in your pets, plus native 
#> compilation in most implementations, plus maturity and a standard, plus 
#> a better OO, plus macros, plus a dozen more small wins. Including 
#> automatic indentation. :)

Automatic indentation? Wow, that's cool... we in Python need to press
RET and sometimes even use this ugly ":" or "" key to get proper
indentation.

Oh, wait, you mean you need to type "(" and ")" in Lisp?

What's automatic about *that*???

-- 
 Best wishes,
   Slawomir Nowaczyk
 ( [EMAIL PROTECTED] )

Grossman's Law: Complex problems have simple,
easy-to-understand, wrong answers.

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


Re: Defining classes

2006-12-13 Thread Duncan Booth
[EMAIL PROTECTED] (Nick Maclaren) wrote:

> 
> I am defining a class, and I need to refer to that class when
> setting up its static data - don't ask - like this:
> 
> Class weeble :
> wumpus = brinjal(weeble)

You cannot refer to weeble until it has been created which isn't until 
after all of the statements in the class body have executed. The usual way 
to achieve what you want is to assign the static member from outside the 
class.

class weeble:
pass

weeble.wumpus = brinjal(weeble)


Alternatively you can play tricks with metaclasses for a similar effect.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Defining classes

2006-12-13 Thread Gabriel Genellina

At Wednesday 13/12/2006 18:04, Nick Maclaren wrote:


I am defining a class, and I need to refer to that class when
setting up its static data - don't ask - like this:

Class weeble :
wumpus = brinjal(weeble)


Move it below the class:

class weeble:


weeble.wumpus = brinjal(weeble)

Not perfect but manageable I think...


--
Gabriel Genellina
Softlab SRL 


__
Correo Yahoo!
Espacio para todos tus mensajes, antivirus y antispam ¡gratis! 
¡Abrí tu cuenta ya! - http://correo.yahoo.com.ar
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: How do I edit a PythonWin path to import custom built modules???

2006-12-13 Thread BartlebyScrivener

Gabriel Genellina wrote:
>
> import sys
> print sys.path
> and see what's there.

Yup. Did that before. That's what I mean. The d:\\python is there and
it doesn't come from the PythonPath in my windows registry. Maybe it
scans for any directory with python in the name?

['', 'C:\\WINDOWS\\system32\\python24.zip', 'd:\\python',
'C:\\Python24\\DLLs', 'C:\\Python24\\lib',
'C:\\Python24\\lib\\plat-win', 'C:\\Python24\\lib\\lib-tk',
'C:\\Python24\\Lib\\site-packages\\pythonwin', 'C:\\Python24',
'C:\\Python24\\lib\\site-packages',
'C:\\Python24\\lib\\site-packages\\win32',
'C:\\Python24\\lib\\site-packages\\win32\\lib',
'C:\\Python24\\lib\\site-packages\\wx-2.7.1-msw-ansi']

rd

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


Re: Windows SetLocalTime

2006-12-13 Thread Rob Williscroft
Podi wrote in news:[EMAIL PROTECTED] in 
comp.lang.python:

> Rob Williscroft wrote:
>>
>> Google will usually find the documentation of anything in the
>> Windows API however sometimes it also helps to add "msdn" to
>> your search as in:

> Yes, thank you.
> 
> I found the function SetLocalTime or SetSystemTime to set the time from
> MSDN http://msdn2.microsoft.com/en-us/library/ms724942.aspx. I am
> having trouble passing parameter to the functions in Python.
> 

Ok I see, you will probably need these 2 bits of the ctypes
documentation:

  http://docs.python.org/lib/ctypes-structures-unions.html
  http://docs.python.org/lib/ctypes-pointers.html

>From there on geting to this is farly straight forward:
 
from ctypes import *
from ctypes.wintypes import WORD

class SYSTEMTIME(Structure):
  _fields_ = [
  ( 'wYear', WORD ),
  ( 'wMonth', WORD ),
  ( 'wDayOfWeek', WORD ),
  ( 'wDay', WORD ),
  ( 'wHour', WORD ),
  ( 'wMinute', WORD ),
  ( 'wSecond', WORD ),
  ( 'wMilliseconds', WORD ),
]

GetSystemTime = windll.kernel32.GetSystemTime

st = SYSTEMTIME()

GetSystemTime( pointer( st ) )

print st.wYear, st.wMonth, st.wDayOfWeek

A bit more digging into the docs will get to this:

prototype = WINFUNCTYPE( None, POINTER( SYSTEMTIME ) )
paramflags = (1, "lpSystemTime" ),
GetSystemTime = prototype(("GetSystemTime", windll.kernel32), paramflags )

st = SYSTEMTIME()
GetSystemTime( st )
print st.wYear, st.wMonth, st.wDayOfWeek

Which will give a much better error message if you try to
pass something other than a SYSTEMTIME, as well as wrapping
the argument in pointer for you.

Rob.
-- 
http://www.victim-prime.dsl.pipex.com/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How do I edit a PythonWin path to import custom built modules???

2006-12-13 Thread Gabriel Genellina

At Wednesday 13/12/2006 10:10, BartlebyScrivener wrote:


> Python does *not* use the Path when searching for modules; sys.path is
> initialized based on the contents of PYTHONPATH, the location of the
> Python executable (or PYTHONHOME), some heuristics, and certain registry
> entries.

Now I'm stumped. Unless it's heuristics. The registry entry for
PythonPath does NOT reference the location of my Python scripts
(d:/Python). And Python is installed in the usual place on C:\Python24.
The only place that I can see where I've told it the location of my
scripts is in the Path variable.

I have no doubt that you're correct. Just confused as usual.


import sys
print sys.path

and see what's there.


--
Gabriel Genellina
Softlab SRL 


__
Correo Yahoo!
Espacio para todos tus mensajes, antivirus y antispam ¡gratis! 
¡Abrí tu cuenta ya! - http://correo.yahoo.com.ar
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: merits of Lisp vs Python

2006-12-13 Thread Ravi Teja

Robert Uhl wrote:
> "Ravi Teja" <[EMAIL PROTECTED]> writes:
>
> > Mark Tarver wrote:
> >>
> >> seems to show that Python is a cut down (no macros) version of Lisp
> >> with a worse performance.
> >
> > By that standard, every other mainstream dynamically typed language
> > for you is a cut-down version of Lisp with worse performance.
>
> Pretty much;-)
>
> Fewer features, worse performance.  Why use 'em?

Usability. Especially when users quote a very significant difference
here.

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


Re: pycrypto 3DES keysize

2006-12-13 Thread hg
hg wrote:

> Ning wrote:
> 
>> I'm trying to write an IM client which sends encrypted messages to the
>> server.  I tried to use pycrypto library, but when I came to 3DES
>> cypher I was confused about the keysize to use.  In the standard it
>> said that it should be either 112 bits or 168 bits, whereas it's 16
>> bytes or 24 bytes in pycrypto.  If I use 16 bytes key to encrypt and
>> send this key to the server which is expecting a 112 bits key, there'll
>> be a problem.  How I should solve this?
> 
> You need to account for the parity bits:
> http://en.wikipedia.org/wiki/Triple_DES
> 
> 
> If that may reassure you ;-) I use PyCrypto to "talk" to smart cards
> without any problem.
> 
> hg


PS: as stated in the wiki, I would seriously consider AES as it is safer /
faster / supported by pycrypto

hg


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


Re: pycrypto 3DES keysize

2006-12-13 Thread hg
Ning wrote:

> I'm trying to write an IM client which sends encrypted messages to the
> server.  I tried to use pycrypto library, but when I came to 3DES
> cypher I was confused about the keysize to use.  In the standard it
> said that it should be either 112 bits or 168 bits, whereas it's 16
> bytes or 24 bytes in pycrypto.  If I use 16 bytes key to encrypt and
> send this key to the server which is expecting a 112 bits key, there'll
> be a problem.  How I should solve this?

You need to account for the parity bits:
http://en.wikipedia.org/wiki/Triple_DES


If that may reassure you ;-) I use PyCrypto to "talk" to smart cards without
any problem.

hg






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


Defining classes

2006-12-13 Thread Nick Maclaren

I am defining a class, and I need to refer to that class when
setting up its static data - don't ask - like this:

Class weeble :
wumpus = brinjal(weeble)

Does anyone know how I can achieve this?  Naturally, I don't need
anything more than the address of the class in brinjal, as it won't
be used until after the class has been created properly.  Actually,
it won't be used except to test for class equivalence, but I may
want to extend later.


Regards,
Nick Maclaren.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: merits of Lisp vs Python

2006-12-13 Thread tac-tics
> > I use 'French units' instead of the term 'metric system' because the
> > latter means 'measurement system,' and of course could validly be
> > applied to _any_ system.Now we know how one contractor ended up using 
> > English units when the
> other was using French units and an entire Mars mission was lost: they
> were both using the metric system.

LISP is better than Python, because it does not have a American
Empirical Measurements library, preventing horrible spaceborne
disasters.

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


Re: YouTube written in Python

2006-12-13 Thread Will McGugan
Terry Reedy wrote:
> In a thread on the PyDev list, Guido van Rossum today wrote:
> 
>>And I just found out (after everyone else probably :-) that YouTube is
>>almost entirely written in Python. (And now I can rub shoulders with
>>the developers since they're all Googlers now... :-)
> 

Nice quote re youtube on Python.org

http://www.python.org/about/quotes/

Will McGugan
--
blog: http://www.willmcgugan.com
-- 
http://mail.python.org/mailman/listinfo/python-list


test

2006-12-13 Thread Eric Price

test

_
Get the latest Windows Live Messenger 8.1 Beta version. Join now. 
http://ideas.live.com


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

Re: Mark Lutz Python interview

2006-12-13 Thread Jack Diederich
They eventually got this once posted on the website.
http://techtalk.imi-us.com/Archives/2006/20061001/

The Lutz interview starts at 10:00 minutes in.

-Jack

On Fri, Sep 29, 2006 at 11:25:34AM -0700, Mark Lutz wrote:
> Python author and trainer Mark Lutz will be interviewed
> on the radio show Tech Talk this Sunday, October 1st,
> at 6PM Eastern time.  He'll be answering questions about
> Python, his books, and his Python training services.
> 
> For more details about the show, see Tech Talk's website
> at http://techtalk.imi-us.com.  You can also listen to
> the live webcast of the show on KFNX's website,
> http://www.1100kfnx.com.
> 
> --Python Training Services 
>   http://home.earthlink.net/~python-training
> 
> -- 
> http://mail.python.org/mailman/listinfo/python-list
> 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Windows SetLocalTime

2006-12-13 Thread Podi
Yes, thank you.

I found the function SetLocalTime or SetSystemTime to set the time from
MSDN http://msdn2.microsoft.com/en-us/library/ms724942.aspx. I am
having trouble passing parameter to the functions in Python.

Rob Williscroft wrote:
>
> Google will usually find the documentation of anything in the
> Windows API however sometimes it also helps to add "msdn" to
> your search as in:
>

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


Re: Iterating over several lists at once

2006-12-13 Thread Mike Erickson
* at ([EMAIL PROTECTED]) wrote:
> Sorry for breaking into this thread, but I agree completely that any
> unnecessary indentations should be avoided. For the same reason I advocate
> that the following syntax should work:
> 
> for x in some_list if some_condition:
> ... code ...
> 
> in stead of 
> 
> for x in some_list 
> if some_condition:
> ... code ...

It is possible to avoid the extra level of indentaion, but I think it's
much less readable than the 2-level verbose expresion:

>>> a
[1, 2, 3, 4, 5, 6, 7]
>>> for odd in (num for num in a if num % 2 == 1):
... print odd
... 
1
3
5
7

there is also continue, which I think is a good compromise:

>>> for num in a:
... if num % 2 == 0:
... continue
... print num
...
1
3
5
7

HTH (and not lead astray),

mike

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


Re: Windows SetLocalTime

2006-12-13 Thread Rob Williscroft
Podi wrote in news:[EMAIL PROTECTED]
in comp.lang.python: 

> I am trying to set the system time on my Windows computer, but avoid
> using the DOS command (date, time).
> 
> Does anyone know what parameter to pass to function SetLocalTime?

http://msdn.microsoft.com/library/default.asp?url=/library/en-
us/sysinfo/base/setlocaltime.asp>

Google will usually find the documentation of anything in the 
Windows API however sometimes it also helps to add "msdn" to 
your search as in:

http://www.google.com/search?client=firefox-a&rls=org.mozilla%3Aen-
US%3Aofficial_s&hl=en&q=setlocaltime+msdn&btnG=Google+Search>

Adding site:msdn.microsoft.com is even better (but alas more typing):

http://www.google.com/search?hl=en&lr=&client=firefox-
a&rls=org.mozilla%3Aen-US%3Aofficial_s&q=setlocaltime+site%
3Amsdn.microsoft.com&btnG=Search>



Rob.
-- 
http://www.victim-prime.dsl.pipex.com/
-- 
http://mail.python.org/mailman/listinfo/python-list


Windows SetLocalTime

2006-12-13 Thread Podi
I am trying to set the system time on my Windows computer, but avoid
using the DOS command (date, time).

Does anyone know what parameter to pass to function SetLocalTime?

CSharp ref
http://groups.google.com/group/microsoft.public.dotnet.languages.csharp/browse_thread/thread/813b4ef504f77a43/24fc37c6c9148961?lnk=gst&q=SetLocalTime&rnum=2#24fc37c6c9148961

Thanks a bunch,
P

>>> import ctypes
>>> import pywintypes
>>> t = pywintypes.Time(time.time())
>>> ctypes.windll.kernel32.SetLocalTime(t)
Traceback (most recent call last):
  File "", line 1, in ?
ArgumentError: argument 1: exceptions.TypeError: Don't know how to
convert parameter 1
>>> ctypes.windll.kernel32.SetLocalTime(ctypes.addressof(t))
Traceback (most recent call last):
  File "", line 1, in ?
TypeError: invalid type

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


Re: merits of Lisp vs Python

2006-12-13 Thread Willem Broekema
Paul Rubin wrote:
> Does this count as a "children of a lesser Python"?

This sounds like a quite derogatory first question. CLPython is not a
dead and abandoned project, nor is execution speed its main goal, nor
are Python semantics bended anywhere (it can run the Pie-thon
benchmark). Sure, some recently introduced language features are
missing, but with just a little effort that's solved...

Moreover, in Common Lisp source code analysis and manipulation can be
expressed easily. CLPython thus provides ample opportunities to analyze
type inference or caching schemes. Most of that is unexplored
territory, I think. I like the journey so far.

> How does clpython implement Python's immutable strings, for example?

Normal Python strings are represented by normal Lisp strings. Instances
of subclasses of 'str' are represented by CLOS instances. That's for
performance reasons. This dual-representation aspect is nicely hidden
behind macros, so that even in the code of CLPython itself there's no
need to worry, or even know, about it.

Why not take a look in the code -- I'll be happy to explain things.

- Willem

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


Re: Is anyone using Python for embedded applications?

2006-12-13 Thread Carl J. Van Arsdall
Hendrik van Rooyen wrote:
>  
>>
>> 
>
> It depends a *lot* on what is meant by "embedded" :
>   
Ha, very true

> This definition seems to cover everything from:
> - a cut down PC in a non standard box, through
> - a processor in a Washing Machine, to
> - a bare PIC processor in a Burglar Alarm...
>   
We are considering now are mobile phone and pocket pc-esque devices.  I 
know that several phones with arm processors are running an arm version 
of linux now, we're thinking how reasonable it might be to run python 
applications on a phone, and which python might best apply.  Is there a 
good way to determine the "minimum requirements" for a python 
application?  I'd imagine these might be something like the min 
requirements of python (cpython, pymite, etc) + additional requirements 
placed by the design of the application.  Is there a good way to study a 
python application and figure that type of thing out?


> I think the main hassles are that you need something big enough
> to run a reasonable OS in, and it must support being programmed in C,
> (which most things do), and it must have some MegaBytes of RAM 
> loose for the Python. (where more is merrier)
>
> Trying to run this on say an AVR or 8031 with a 64k address space and
> a scarcity of RAM, will, to say the least, be a bit of a challenge...
>
> As far as the OS goes, Linux is probably the best bet, if you can get it to
> fit in your hardware - It has been ported to ARM type processors from
> various companies (Atmel springs to mind), and is free, which is a help
> in a personal project.  You could of course also roll your own kernel, 
> which will be good practice, as with a limited set of peripherals its not 
> THAT hard to do, but its a bit far away from Python -   :- )
>   

Yea, we are thinking on the more robust end of the embedded side.  So a 
system capable of running Linux or Windows CE (or something similar)
> What display device are you going to use, or is it going to be a webserver
> sitting on a power over ethernet link?
>
> I haven't actually taken the plunge myself yet to put Python on any of the 
> hardware we make, as it seems to add a lot of overhead to a simple device 
> - but I come from the bottom up, as it were, and the idea is intriguing, 
> as I in fact discovered Python because it is embedded in a GPS module 
> we were evaluating for building into a device - so I will follow your 
> progress with interest...
>
>   


-- 

Carl J. Van Arsdall
[EMAIL PROTECTED]
Build and Release
MontaVista Software

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


pycrypto 3DES keysize

2006-12-13 Thread Ning
I'm trying to write an IM client which sends encrypted messages to the
server.  I tried to use pycrypto library, but when I came to 3DES
cypher I was confused about the keysize to use.  In the standard it
said that it should be either 112 bits or 168 bits, whereas it's 16
bytes or 24 bytes in pycrypto.  If I use 16 bytes key to encrypt and
send this key to the server which is expecting a 112 bits key, there'll
be a problem.  How I should solve this?

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


Re: Conditional iteration

2006-12-13 Thread Carl Banks
at wrote:
> I am not looking for a work around but more interest if other people might
> judge this syntax would come in handy?

Of course people have expressed interest in this in the past, but it's
not going to happen.  There's a way to nest for and if statements, and
a different way to nest for and if clauses in listcomps, and the two
methods are considered distinct.  Although Guido has said that saving
indentation levels is important, he hasn't said  anything (that I'm
aware of) that suggests it's important enough to add this complexity
and redundancy to the language.  Sorry.


Carl Banks

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


Re: merits of Lisp vs Python

2006-12-13 Thread Ken Tilton


Robert Uhl wrote:
> Christophe <[EMAIL PROTECTED]> writes:
> 
>>Robert Uhl a écrit :
>>
>>
>>>The argument from popularity is invalid.  French units have overtaken
>>>standard units,
>>
>>Never heard of that French unit thing. Unless you talk about that
>>archaic unit system that was in use before the metric system was
>>created.
> 
> 
> I use 'French units' instead of the term 'metric system' because the
> latter means 'measurement system,' and of course could validly be
> applied to _any_ system.
> 

Now we know how one contractor ended up using English units when the 
other was using French units and an entire Mars mission was lost: they 
were both using the metric system.

[cue NASA aopologist Ron (or his sidekick Al) for some scenery-chewing 
outrage over my condescension and arrogance.]

ken

-- 
Algebra: http://www.tilton-technology.com/LispNycAlgebra1.htm

"Well, I've wrestled with reality for thirty-five
years, Doctor, and I'm happy to state I finally
won out over it." -- Elwood P. Dowd

"I'll say I'm losing my grip, and it feels terrific."
-- Smiling husband to scowling wife, New Yorker cartoon
-- 
http://mail.python.org/mailman/listinfo/python-list

  1   2   3   >