how to remove the blank lines?

2006-12-08 Thread boyeestudio

The following program have the same function as the linux's command:tail -f
logfile.log
But it print a lot of blank lines while showing on the stdout.
How to fix this problem and let it go ahead always
showing the end line as the log file's increasing.

#tail.py:

import os
import sys

class Tail:
   def __init__(self,inputstream):
   self.inputstream=inputstream

   def tail(self):
   self.inputstream.seek(0,2) #??Maybe this is where I'll need
fixed,But I don't know how to
   line=self.inputstream.readline().strip()
   print line

if __name__=="__main__":
   if len(sys.argv)<=1:
   print "You must type a log file name"
   sys.exit()
   arg=file(sys.argv[1],'r+')
   while(arg):
   try:
   t=Tail(arg)
t.tail()
   except KeyboardInterrupt:
   arg.close()
   print "File closed"
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Video stream server

2006-12-08 Thread Lad
Hi Paul,
I checked your video strem server.It seems interesting for me.
 Can you please answer these questions?
1. What is a price?
2.Do you support FLV format files, if not, why?
3. How many users do already use the server?
4. Can you name any of your customers ?

Thank you
Lad,


Paul Boddie wrote:
> Lad wrote:
> >
> > I love Python so I would like to implement video support  in Python.
> > That is how it is related to Python only
>
> I'm not sure if this is too low-level, but there's always the Flumotion
> platform [1]: an open source streaming solution based on Python,
> GStreamer and Twisted, and there's a Java applet for viewing in Web
> pages (I'll save my rant about Flash for another time). This PyCon 2005
> presentation slide takes you to the key points:
>
> http://www.flumotion.net/doc/flumotion/presentation/pycon2005/html/img4.html
>
> Of course, this is more about streaming than just video uploads and
> downloads, but if you're considering streaming (or if anyone else
> reading is), it's probably worth looking into.
> 
> Paul
> 
> [1] http://www.flumotion.net/

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


Re: python.org not current

2006-12-08 Thread Norbert


On 8 Dez., 08:40, Fredrik Lundh <[EMAIL PROTECTED]> wrote:
> Norbert wrote:
> > the python websitehttp://www.python.org/mentions Version 2.3.6 and
> > 2.4.4 on the most prominent place. Shouldn't this be changed to 2.5.x 
> > ?you're looking at the news section: the 2.3.6 and 2.4.4 maintenance
> releases were made after 2.5 was released.

Did not notice that, maybe a subheding  would be in order ?
> 
> 

Norbert

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


Re: Need Help Parsing From File

2006-12-08 Thread Duncan Booth
Gabriel Genellina <[EMAIL PROTECTED]> wrote:

> For the Borland C++ 3.1 help (about 1991):
>   If "t" or "b" is not given in the string, the mode is governed by
>   _fmode. 
>   If _fmode is set to O_BINARY, files are opened in binary mode.
>   If _fmode is set to O_TEXT, they are opened in text mode.
> MSC used to have a similar flag (perhaps using the same name).

I assume you are using 'used to have' in the sense of 'still have, although 
it is now deprecated in favour of the functions _get_fmode and _set_fmode'.

John Machin wrote:
> Indeed, and their docs say that the default for _fmode is text mode.

Quite apart from the scope for the program to change the value at runtime, 
the default may also be changed to binary mode by linking the program with 
binmode.obj.
-- 
http://mail.python.org/mailman/listinfo/python-list


autoadd class properties

2006-12-08 Thread manstey
I have a ClassWrapper that wraps around a third party database object.
Each database object has a set of properties, like columns in a
relational database.

I want my wrapper to generate a property for each database object and
load its value into it.

Thus, in my database (which is an oodbms) say I have a MyDbaseClass
with MyProperty1, MyProperty2, etc, after it is loaded, I have:

dbase_object = LoadMyDbaseClass
PythonDbaseClass = PythonWrapper(dbase_object)

I can then load in a list of ['MyProperty1','MyProperty2', etc].

But how can I turn these list elements into PythonDbaseClass
properties, so that I could then simply have:

print PythonDbaseClass.MyProperty1
PythonDbaseClass.MyProperty2="4" 

Is this clear?

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


Re: Need Help Parsing From File

2006-12-08 Thread Gabriel Genellina

At Friday 8/12/2006 05:30, Duncan Booth wrote:


> For the Borland C++ 3.1 help (about 1991):
>   If "t" or "b" is not given in the string, the mode is governed by
>   _fmode.
>   If _fmode is set to O_BINARY, files are opened in binary mode.
>   If _fmode is set to O_TEXT, they are opened in text mode.
> MSC used to have a similar flag (perhaps using the same name).
I assume you are using 'used to have' in the sense of 'still have, although
it is now deprecated in favour of the functions _get_fmode and _set_fmode'.


I meant "I have no idea whether it's still the case or not" - thanks 
for the info. And I was talking about the old MSC compiler, a quite 
different product from the current MSVC.



--
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: autoadd class properties

2006-12-08 Thread Gabriel Genellina

At Friday 8/12/2006 05:38, manstey wrote:


Is this clear?


I'm sorry, not for me. Some code showing how things are used now and 
how you would like it to be, would help.



--
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: SOAP Server with WSDL?

2006-12-08 Thread vasudevram

Ravi Teja wrote:
> tobiah wrote:
> > Actually, do I have to make a WSDL?  Do people hand write these, or
> > are there tools?  I don't really need to publish an interface.  I just
> > want some in house apps to communicate.
>
> Java and .NET based tools can auto-generate WSDL from code. Python does
> not have such because function definitions do not contain the type
> information required for such a tool. However , you can grab a free
> Java (Netbeans with Enterprise pack) or .NET (Visual Studio Express)
> IDE (or just the respective SDK if you don't mind reading through the
> docs), create a stub function, mark it as a WebMethod, let it generate
> the WSDL and pass it to wsdl2py that comes with ZSI. This is a twisted
> approach.
>
> But you state that you don't need to publish an interface. If that is
> the case, it can be as simple as this.
>
>   import SOAPpy
>   def hello():
> return "Hello World"
>
>   server = SOAP.SOAPServer(("localhost", 8080))
>   server.registerFunction(hello)
>   server.serve_forever()
>
> Pasted from
> http://pywebsvcs.sourceforge.net/soappy.txt
>
> > I can't figure out if I want SOAP, or CORBA, or would it just be
> > easier if I just starting opening sockets and firing data around
> > directly.  Ideally, I'd like to share complex objects.  That's why
> > I thought that I needed one of the above standards.
>
> I posted a few days ago a simple guide to choosing a remoting
> framework.
> http://groups.google.com/group/comp.lang.python/tree/browse_frm/thread/f53221adfca5c819/58057e83c0ad7c27?rnum=1&hl=en&q=webraviteja&_done=%2Fgroup%2Fcomp.lang.python%2Fbrowse_frm%2Fthread%2Ff53221adfca5c819%2F3f056c5c87279aca%3Flnk%3Dgst%26q%3Dwebraviteja%26rnum%3D4%26hl%3Den%26#doc_3f056c5c87279aca
>
> For *complex* objects, you need a stateful remoting mechanism. The
> choice is Pyro if both the server and all the clients are written in
> Python. Else, use CORBA or ICE with DMI. All of these are simple to use
> for simple remote object invocations although distributed computing in
> general does have a learning curve.
> 
> Ravi Teja.

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


Re: Common Python Idioms

2006-12-08 Thread George Sakkis
Steven D'Aprano wrote:

> On Thu, 07 Dec 2006 13:52:33 -0800, George Sakkis wrote:
>
> > I'm surprized that none of these pages mentions the incompatible type
> > comparison gotcha:
> >
>  5 < "4"
> > True
> >
> > I'm sure this has bitten many folks, particularly (ex) Perl'ers.
>
> Why is this a gotcha?
>
> I can't speak for others, but except for sorting,

Well, sorting alone is a big issue, don't you think ?

> I've never been tempted to compare ints to strings like that, but thinking 
> about the code I've
> written, I can't think of any bad consequences that would have happened if
> I had.

Of course nobody (except perhaps from newbies coming from perl) would
intentionally compare ints with strings. The gotcha is when you compare
two values whose type you *think* you know, and since duck typing is
typically preferred over explicit type checking, it's one of the very
few cases that the "errors should never pass silently" rule is
violated. Thankfully this will raise TypeError in 3.0.

George

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


Re: autoadd class properties

2006-12-08 Thread George Sakkis
manstey wrote:

> I have a ClassWrapper that wraps around a third party database object.
> Each database object has a set of properties, like columns in a
> relational database.
>
> I want my wrapper to generate a property for each database object and
> load its value into it.
>
> Thus, in my database (which is an oodbms) say I have a MyDbaseClass
> with MyProperty1, MyProperty2, etc, after it is loaded, I have:
>
> dbase_object = LoadMyDbaseClass
> PythonDbaseClass = PythonWrapper(dbase_object)
>
> I can then load in a list of ['MyProperty1','MyProperty2', etc].
>
> But how can I turn these list elements into PythonDbaseClass
> properties, so that I could then simply have:
>
> print PythonDbaseClass.MyProperty1
> PythonDbaseClass.MyProperty2="4"
>
> Is this clear?

Sounds as if you're reinventing a part of an ORM. Have you checked out
SQLAlchemy or Django's ORM, in case they provide what you want out of
the box ?

George

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


Re: I think Python is a OO and lite version of matlab

2006-12-08 Thread George Sakkis
Allen wrote:
> Does anyone agree with me?
> If you have used Matlab, welcome to discuss it.

Sure, and earth is a heavy version of a basketball. If all you have is
a hammer...

George

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


Re: I think Python is a OO and lite version of matlab

2006-12-08 Thread Allen

> Sure, and earth is a heavy version of a basketball. If all you have is
> a hammer...
>

It is not make sense to compare earth and basketball.
I think Python introduced many idea of matlab.

If you have used matlab, you will say that they are very very similar,
except that matlab was born years earlier and is used mainly in the
area
of matrix calculation.

I do not mean Python shall feel ashamed for it. We will be pleased that
Python 
does absorb many successful ideas of computer languages.

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


Re: Best way to split up lines - RE: About the 79 character linerecommendation

2006-12-08 Thread Marc 'BlackJack' Rintsch
In <[EMAIL PROTECTED]>, Gabriel
Genellina wrote:

> At Thursday 7/12/2006 16:46, Roy Smith wrote:
> 
>>I see your point.  Actually, I think you want to force the sequences to be
>>lists (regardless of what syntax we end up with), on the theory that tuples
>>are for heterogeneous sequences and lists are for homogeneous ones.
> 
> Any rationale for this theory?

The BDFL says so.  Don't question him.  ;-)

Ciao,
Marc 'BlackJack' Rintsch

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


Re: I think Python is a OO and lite version of matlab

2006-12-08 Thread Fredrik Lundh
Allen wrote:

> It is not make sense to compare earth and basketball.

why not?  they're both round, so surely they must have been inspired
by each other.  the question is if humanity invented balls before we 
figured out that the earth is round, or if it's the other way around...



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


Re: how to remove the blank lines?

2006-12-08 Thread Peter Otten
boyeestudio wrote:

> The following program have the same function as the linux's command:tail
> -f logfile.log
> But it print a lot of blank lines while showing on the stdout.
> How to fix this problem and let it go ahead always
> showing the end line as the log file's increasing.
> 
> #tail.py:
> 
> import os
> import sys
> 
> class Tail:
> def __init__(self,inputstream):
> self.inputstream=inputstream
> 
> def tail(self):
> self.inputstream.seek(0,2) ???Maybe this is where I'll need
> fixed,But I don't know how to

You probably want to move to the end of the file once at the
beginning of the script, not before every attempt to read from it...

> line=self.inputstream.readline().strip()

Don't strip() so fast. You lose the information whether you have reached the
(current) end of file or a blank line (readline() returns "" or "\n"
respectively).

> print line
> 
> if __name__=="__main__":
> if len(sys.argv)<=1:
> print "You must type a log file name"
> sys.exit()
> arg=file(sys.argv[1],'r+')
> while(arg):

That's always true, I think.

> try:
> t=Tail(arg)
>  t.tail()
> except KeyboardInterrupt:
> arg.close()
> print "File closed"

A no-fluff version might be

filename = sys.argv[1]
infile = open(filename, "r")
infile.seek(0, 2)
while True:
while True:
line = infile.readline()
if not line: # an empty string indicates eof 
break 
print line,
time.sleep(1) # give the writing program a chance to write more lines


The inner loop can also be written

for line in iter(infile.readline, ""):
print line,

Peter

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


why is this different?

2006-12-08 Thread Schüle Daniel
Hello snakes :)

In [38]: f = [lambda:i for i in range(10)]
In [39]: ff = map(lambda i: lambda : i, range(10))
In [40]: f[0]()
Out[40]: 9
In [41]: f[1]()
Out[41]: 9
In [42]: ff[0]()
Out[42]: 0
In [43]: ff[1]()
Out[43]: 1

I don't understand why in the first case f[for all i in 0..9]==9
what is different from (more usefull)

In [44]: f = ["%i" % i for i in range(10)]
In [45]: f
Out[45]: ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']


doing it like this works again

In [54]: def d(x):
: return lambda:x
:

In [55]: f = [d(i) for i in range(10)]
In [56]: f[0]()
Out[56]: 0
In [57]: f[1]()
Out[57]: 1

in a C programmer sence I would say there seems to be no "sequence 
point" which would separate "now" from "next"

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


Re: dict.has_key(x) versus 'x in dict'

2006-12-08 Thread Roel Schroeven
Hendrik van Rooyen schreef:
> <[EMAIL PROTECTED]> wrote:
> 
>> Hendrik> - as long as it works, and is fast enough, its not broken, so
>> Hendrik> don't fix it...
>>
>> That's the rub.  It wasn't fast enough.  I only realized that had been a
>> problem once I fixed it though.
> 
> LOL - this is kind of weird - it was working, nobody complained, you fiddled
> with it to make it faster, (just because you could, not because you had to, or
> were asked to), it became faster, and then, suddenly, retrospectively,
> it became a problem 
> 
> Would it have been no problem if it so happened that you were unable to make 
> it
> go faster?
> 
> I don't really follow that logic - but then I have never believed that I could
> change yesterday...

Have you never experienced the following:

A customer reports a bug. Upon investaging you find the source of the 
problem, but from studying the code you don't understand anymore how it 
has ever been able to function correctly. From that moment, it indeed 
stops working even on computers where it always have worked correctly.

You fix the bug and all is well again.

Very strange, but it has happened to me on a few occasions. There's 
probably a perfectly logical explanation for what happened, but I never 
found it.

-- 
If I have been able to see further, it was only because I stood
on the shoulders of giants.  -- Isaac Newton

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


apache & mod_python

2006-12-08 Thread m.banaouas
Hi,
bonjour,

witch versions are suitable to use for apache & mod_python ?

Can i install and use  "Apache 2.2.3" & "mod_python 3.2.10" (most recent 
versions) without facing any known major issue ?

thanks for any help.
-- 
http://mail.python.org/mailman/listinfo/python-list


merits of Lisp vs Python

2006-12-08 Thread Mark Tarver
How do you compare Python to Lisp?  What specific advantages do you
think that one has over the other?

Note I'm not a Python person and I have no axes to grind here.  This is
just a question for my general education.

Mark

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


Re: apache & mod_python

2006-12-08 Thread Maxim Sloyko
m.banaouas wrote:

> Can i install and use  "Apache 2.2.3" & "mod_python 3.2.10" (most recent
> versions) without facing any known major issue ?

Works fine for me.
The only "known major issue" you can face is general non-threadsafety
of Python interpreter. So, if you are using Apache MPM, you have to
allow for it, or use framework that does it for you.

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


Re: Subprocess with a Python Session?

2006-12-08 Thread Paul Boddie
Hendrik van Rooyen wrote:
> "Giovanni Bajo" <[EMAIL PROTECTED]>
> >
> > Yeah, but WHY was the API designed like this? Why can't I read and write
> > freely from a pipe connected to a process as many times as I want?
>
> you can - all you have to do is to somehow separate the "records" - else how 
> is
> the receiving side to know that there is not more data to follow?

This is one of the more reliable methods since upon receiving a packet
"delimiter" the receiver knows that the data is complete. It shouldn't
attempt to process anything which isn't yet complete.

> The simplest way is to use newline as separator, and to use readline() on the
> receiving side.

Agreed. Using the readline method on file objects created from sockets
is a tried and trusted approach.

> Or you can use read(1) and roll your own...

Indeed. There are a few tricks in this department: use select or poll
to test the status of file descriptors (which is what the standard
library asyncore module, Medusa and Twisted do), attempt to examine the
buffer status of sockets using the MSG_PEEK flag (something which
didn't prove to be appropriate for some work I've done since I was
using pipes, although more investigation may be required), or set
timeouts on the underlying sockets (reliable only in certain kinds of
communications, I would assert).

> To make sure the stuff is written from memory on the transmitting side, use
> flush(), if you want to do many records, or close() as Fredrik said if only 
> one
> thing is to be transferred.

Also good advice. However, as was mentioned elsewhere, if you're
invoking Python as a subprocess it can help to invoke it in unbuffered
mode (the -u option), otherwise flush and close don't always seem to do
their magic.

Paul

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


Re: merits of Lisp vs Python

2006-12-08 Thread Mathias Panzenboeck
Mark Tarver wrote:
> How do you compare Python to Lisp?  What specific advantages do you
> think that one has over the other?
> 
> Note I'm not a Python person and I have no axes to grind here.  This is
> just a question for my general education.
> 
> Mark
> 

I do not know much about Lisp. What I know is:
Python is a imperative, object oriented dynamic language with duck typing, List 
is a declarative,
functional dynamic language -> those two languages have different scopes.

For more Information:
http://en.wikipedia.org/wiki/Functional_programming
http://en.wikipedia.org/wiki/Object-oriented_programming
http://en.wikipedia.org/wiki/Dynamic_programming_language
http://en.wikipedia.org/wiki/Lisp_programming_language
http://en.wikipedia.org/wiki/Python_%28programming_language%29
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: I think Python is a OO and lite version of matlab

2006-12-08 Thread Gabriel Genellina
On 8 dic, 06:57, "Allen" <[EMAIL PROTECTED]> wrote:
>
> If you have used matlab, you will say that they are very very similar,
> except that matlab was born years earlier and is used mainly in the
> area
> of matrix calculation.
>
> I do not mean Python shall feel ashamed for it. We will be pleased that
> Python
> does absorb many successful ideas of computer languages.

Personally, I dont like the Matlab language. I like the "no surprises"
approach of Python, the consistency along different objects, and of
course the vast builtin data structures that let me model almost
anything. None of these are present in Matlab.
I hate gotchas like the degenerate case of sum(M) for a one-row matrix
(avoidable, yes, but "Special cases aren't special enough to break the
rules.").
Of course, if all you do is working with matrices, it's wonderful!

-- 
Gabriel Genellina

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


Re: merits of Lisp vs Python

2006-12-08 Thread Paul Rubin
"Mark Tarver" <[EMAIL PROTECTED]> writes:
> How do you compare Python to Lisp?  What specific advantages do you
> think that one has over the other?

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


Re: Common Python Idioms

2006-12-08 Thread Daniel Dittmar
John Machin wrote:
> No it doesn't look wrong to anyone who has read the docs on
> sys.modules. 

My point was really that there is no obvious implementation for 'in' on 
dictionaries, so it should have been left out. And that GvR thought so 
for quite some time as well (until he got mixed up with a crowd of ex 
C++ programmers).

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


Re: why is this different?

2006-12-08 Thread Gabriel Genellina
On 7 dic, 22:53, Schüle Daniel <[EMAIL PROTECTED]> wrote:

> In [38]: f = [lambda:i for i in range(10)]
> In [39]: ff = map(lambda i: lambda : i, range(10))
> In [40]: f[0]()
> Out[40]: 9
> In [41]: f[1]()
> Out[41]: 9
> In [42]: ff[0]()
> Out[42]: 0
> In [43]: ff[1]()
> Out[43]: 1
>
> I don't understand why in the first case f[for all i in 0..9]==9

In the first case, i is a free variable. That means that Python will
get it from other place (the global namespace, likely [surely?])

>>> f=[lambda:i for i in range(10)]
>>> f[0]()
9
>>> i=123
>>> f[0]()
123
>>> print f[0].func_closure
None

In the second case, the inner i is a free variable, but local to its
enclosing scope (outer lambda). It's a closure:
>>> ff = map(lambda i: lambda : i, range(10))
>>> ff[4]()
4
>>> ff[4].func_closure
(,)
>>> i=321
>>> ff[4]()
4

> what is different from (more usefull)
>
> In [44]: f = ["%i" % i for i in range(10)]
> In [45]: f
> Out[45]: ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']

This is a simple expression evaluated at each iteration

> doing it like this works again
>
> In [54]: def d(x):
> : return lambda:x
> :
x inside lambda is a free variable, but since it's local to d, this
becomes a closure:

>>> d(1)
 at 0x00A35EF0>
>>> d(1).func_closure
(,)

> In [55]: f = [d(i) for i in range(10)]
> In [56]: f[0]()
> Out[56]: 0
> In [57]: f[1]()
> Out[57]: 1
This is similar to the ff example above

> in a C programmer sence I would say there seems to be no "sequence
> point" which would separate "now" from "next"

No, the problem is that C has no way to express a closure; this is a
functional concept absolutely extraneous to the C language.

-- 
Gabriel Genellina

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


Re: merits of Lisp vs Python

2006-12-08 Thread Mark Tarver

Paul Rubin wrote:
> "Mark Tarver" <[EMAIL PROTECTED]> writes:
> > How do you compare Python to Lisp?  What specific advantages do you
> > think that one has over the other?
>
>

Thanks;  a quick read of your reference to Norvig's analysis

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

seems to show that Python is a cut down (no macros) version of Lisp
with a worse performance.  The only substantial advantage I can see is
that GUI, and Web libraries are standard.  This confirms my suspicion
that Lisp is losing out to newbies because of its
lack of standard support for the things many people want to do.

Mark

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


Re: merits of Lisp vs Python

2006-12-08 Thread Fredrik Lundh
Mark Tarver wrote:

> seems to show that Python is a cut down (no macros) version of Lisp
> with a worse performance.

"can be seen as, by a Lisp programmer", perhaps.  it's not like anybody set out
to make a Lisp-with-other-syntax but "failed"...

 



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


Re: merits of Lisp vs Python

2006-12-08 Thread Richard Brodie

"Mark Tarver" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]

> seems to show that Python is a cut down (no macros) version of Lisp
> with a worse performance.

Performance claims are always controversial. So, Python is much slower
doing array multiplication, when you hand roll it, instead of using the
standard numerical packages available.

I see that the effbot has already responded the first part.



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


Re: why is this different?

2006-12-08 Thread Schüle Daniel
Gabriel Genellina schrieb:
Gabriel Genellina schrieb:
> On 7 dic, 22:53, Schüle Daniel <[EMAIL PROTECTED]> wrote:
> 
>> In [38]: f = [lambda:i for i in range(10)]
>> In [39]: ff = map(lambda i: lambda : i, range(10))
>> In [40]: f[0]()
>> Out[40]: 9
>> In [41]: f[1]()
>> Out[41]: 9
>> In [42]: ff[0]()
>> Out[42]: 0
>> In [43]: ff[1]()
>> Out[43]: 1
>>
>> I don't understand why in the first case f[for all i in 0..9]==9
> 
> In the first case, i is a free variable. That means that Python will
> get it from other place (the global namespace, likely [surely?])
> 
 f=[lambda:i for i in range(10)]
 f[0]()
> 9
 i=123
 f[0]()
> 123
 print f[0].func_closure
> None
> 
> In the second case, the inner i is a free variable, but local to its
> enclosing scope (outer lambda). It's a closure:
 ff = map(lambda i: lambda : i, range(10))
 ff[4]()
> 4
 ff[4].func_closure
> (,)
 i=321
 ff[4]()
> 4
> 
>> what is different from (more usefull)
>>
>> In [44]: f = ["%i" % i for i in range(10)]
>> In [45]: f
>> Out[45]: ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']
> 
> This is a simple expression evaluated at each iteration
> 
>> doing it like this works again
>>
>> In [54]: def d(x):
>> : return lambda:x
>> :
> x inside lambda is a free variable, but since it's local to d, this
> becomes a closure:
> 
 d(1)
>  at 0x00A35EF0>
 d(1).func_closure
> (,)
> 
>> In [55]: f = [d(i) for i in range(10)]
>> In [56]: f[0]()
>> Out[56]: 0
>> In [57]: f[1]()
>> Out[57]: 1
> This is similar to the ff example above
> 
>> in a C programmer sence I would say there seems to be no "sequence
>> point" which would separate "now" from "next"
> 
> No, the problem is that C has no way to express a closure; this is a
> functional concept absolutely extraneous to the C language.
> 

> On 7 dic, 22:53, Schüle Daniel <[EMAIL PROTECTED]> wrote:
> 
>> In [38]: f = [lambda:i for i in range(10)]
>> In [39]: ff = map(lambda i: lambda : i, range(10))
>> In [40]: f[0]()
>> Out[40]: 9
>> In [41]: f[1]()
>> Out[41]: 9
>> In [42]: ff[0]()
>> Out[42]: 0
>> In [43]: ff[1]()
>> Out[43]: 1
>>
>> I don't understand why in the first case f[for all i in 0..9]==9
> 
> In the first case, i is a free variable. That means that Python will
> get it from other place (the global namespace, likely [surely?])
> 
 f=[lambda:i for i in range(10)]
 f[0]()
> 9
 i=123
 f[0]()
> 123
 print f[0].func_closure
> None

intersting
I think I got it

[]

I have two more examples, but now I understand the difference

In [70]: x = [eval("lambda:i") for i in range(10)]
In [71]: y = [eval("lambda:%i" % i) for i in range(10)]

I think [71] is most obvious what the programmer intends

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


Re: merits of Lisp vs Python

2006-12-08 Thread Istvan Albert
Mark Tarver wrote:

> seems to show that Python is a cut down (no macros) version of Lisp
> with a worse performance.

or maybe it shows that Lisp is an obfuscated version of Python with
lots of parentheses, backward logic, and complicated constructs that
run faster.

i.

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


Re: merits of Lisp vs Python

2006-12-08 Thread Tim Chase
> How do you compare Python to Lisp?  What specific advantages do you
> think that one has over the other?

Easy...
Python reads like pseudocode
Lisp reads like line-noise (much like most Perl or Ruby code)


Python makes better use of my time as a programmer because it 
maps fairly closely to how I think, as well as being easy to pick 
up when you've been away from the code for several months.

-tkc




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


Re: Video stream server

2006-12-08 Thread Paul Boddie
Lad wrote:
> I checked your video strem server.It seems interesting for me.

It's not my software, I'm afraid. I just read enough of Planet GNOME to
have become aware of the activities of various people, including people
who work at Fluendo [1] - the principal developers of that software.

>  Can you please answer these questions?
> 1. What is a price?

I guess you can get the different components at no cost from the site I
mentioned [2].

> 2.Do you support FLV format files, if not, why?
> 3. How many users do already use the server?
> 4. Can you name any of your customers ?

You would need to ask Fluendo all these questions. I was just telling
you what I've read about myself.

Paul

[1] http://www.fluendo.com/
[2] http://www.flumotion.net/

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


Re: dict.has_key(x) versus 'x in dict'

2006-12-08 Thread Roel Schroeven
Roel Schroeven schreef:
> Have you never experienced the following:
> 
> A customer reports a bug. Upon investaging you find the source of the 
> problem, but from studying the code you don't understand anymore how it 
> has ever been able to function correctly. From that moment, it indeed 
> stops working even on computers where it always have worked correctly.
> 
> You fix the bug and all is well again.
> 
> Very strange, but it has happened to me on a few occasions. There's 
> probably a perfectly logical explanation for what happened, but I never 
> found it.

BTW this is known as a Schroedinbug.

-- 
If I have been able to see further, it was only because I stood
on the shoulders of giants.  -- Isaac Newton

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


Re: I think Python is a OO and lite version of matlab

2006-12-08 Thread Harry George
Fredrik Lundh <[EMAIL PROTECTED]> writes:

> Allen wrote:
> 
> > It is not make sense to compare earth and basketball.
> 
> why not?  they're both round, so surely they must have been inspired
> by each other.  the question is if humanity invented balls before we
> figured out that the earth is round, or if it's the other way around...
> 
> 
> 

In keeping with the computer science flavor, we can say that no one
invented earth or balls to be round.  Rouindness is an emergent
behavior of a substance which has shape-forming adhesion and
shape-changing fluidity, and is subject to radially symmetric
shape-impacting processes.  Magma and gravity for the earth, leather
and air pressure for inflated balls, sand and accretion for beach
"cannonballs", and snow and hand pressure for snowballs.

-- 
Harry George
PLM Engineering Architecture
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: merits of Lisp vs Python

2006-12-08 Thread Harry George
"Mark Tarver" <[EMAIL PROTECTED]> writes:

> Paul Rubin wrote:
> > "Mark Tarver" <[EMAIL PROTECTED]> writes:
> > > How do you compare Python to Lisp?  What specific advantages do you
> > > think that one has over the other?
> >
> >
> 
> Thanks;  a quick read of your reference to Norvig's analysis
> 
> http://norvig.com/python-lisp.html
> 
> seems to show that Python is a cut down (no macros) version of Lisp
> with a worse performance.  The only substantial advantage I can see is
> that GUI, and Web libraries are standard.  This confirms my suspicion
> that Lisp is losing out to newbies because of its
> lack of standard support for the things many people want to do.
> 
> Mark
> 

It is not just a newbie thing.  Even people who are reasonably fluent
in Lisp use Python for many tasks, and some make python the default
with Lisp as a special case.  It would probably be fair to say that
the more you know about a variety of languages, the more you
appreciate Python.


-- 
Harry George
PLM Engineering Architecture
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: merits of Lisp vs Python

2006-12-08 Thread Alex Mizrahi
(message (Hello 'Richard)
(you :wrote  :on '(Fri, 8 Dec 2006 14:08:09 -))
(

 ??>> seems to show that Python is a cut down (no macros) version of Lisp
 ??>> with a worse performance.

 RB> Performance claims are always controversial. So, Python is much slower
 RB> doing array multiplication, when you hand roll it, instead of using the
 RB> standard numerical packages available.

heh, do you have "standard numeric packages" for everything? maybe then 
we'll make standard programs for everything -- that will obsolete "slow" 
"custom scripts" and we'll just use shell to select what program we want to 
run?
certainly, it's possible to write code in C and use FFI to access it, but 
it's not suitable for rapid prototyping/fast development, when requirements 
may change, or you're just experimenting with different methods.

it's interesting than as of bare "interpreter overhead", python is aprox 
order of magnitude (10 times) slower than lisp interpreters. it's also 
interesting, that python, perl, php and ruby show very similar peformance, 
while lisp and scheme implementations show large improvements -- it makes me 
think that there's something "pathalogically scripting" in their 
specifications (maybe some obligatory use of strings for method dispatch?).

note that i've mentioned "lisp interpreters" above. as for lisp _compilers_, 
they run lots faster than lisp interpreters.

please check http://shootout.alioth.debian.org/
to compare Python to Lisp SBCL. lisp is faster more then 10 times in many 
benchmarks, and even more than 100 times faster in two benchmarks.
unfortunately there's no lisp interpreters (CLISP) in the benchmark.

)
(With-best-regards '(Alex Mizrahi) :aka 'killer_storm)
"People who lust for the Feel of keys on their fingertips (c) Inity") 


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


IPython 0.7.3 beta 2 is out!

2006-12-08 Thread Ville Vainio
Yes, next version of IPython is closing in on final release around the
years end, with lots of new exiting features (full list TBD, but it
*does* include proper python 2.5 support if that's what you've been
waiting for).

Get the 0.7.3 beta 2 it at

http://projects.scipy.org/ipython/ipython/wiki/Release/0.7.3

And remember to run %upgrade if you are already using an older version.

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


Re: merits of Lisp vs Python

2006-12-08 Thread Alex Mizrahi
(message (Hello 'Istvan)
(you :wrote  :on '(8 Dec 2006 06:11:20 -0800))
(

 ??>> seems to show that Python is a cut down (no macros) version of Lisp
 ??>> with a worse performance.

 IA> or maybe it shows that Lisp is an obfuscated version of Python

hell no, lisp's syntax is much easier than python's since it's homogenous
(and certainly lisp was invented much 30 years before Python, so that's 
Python uses Lisp features)

 IA> with lots of parentheses,

that make logic more explicit

 IA>  backward logic,

??

 IA>  and complicated constructs that run faster.

no, there are no complicted constructs -- just it's designed with 30-year 
history in mind, not like "let's make another simple scripting language".

)
(With-best-regards '(Alex Mizrahi) :aka 'killer_storm)
"People who lust for the Feel of keys on their fingertips (c) Inity") 


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


Re: raw strings in regexps

2006-12-08 Thread Mike
"Gabriel Genellina" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]

...

> You have to quote metacharacters if you want to match them. The escape 
> method is useful for this:
>
> >>> re.escape('(a)')
> '\\(a\\)'

Doh! Of course! Thanks everyone.

-- Mike --


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


Re: merits of Lisp vs Python

2006-12-08 Thread Ken Tilton


Mark Tarver wrote:
> How do you compare Python to Lisp? 

Lisp programmers are smarter and better looking. And better programmers. 
Not sure if that is what you were after, though.

> What specific advantages do you
> think that one has over the other?

http://www.googlefight.com/index.php?lang=en_GB&word1=parentheses&word2=white+space

Ouch.

hth,kt

-- 
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-08 Thread Wade Humeniuk
Mark Tarver wrote:
> How do you compare Python to Lisp?  What specific advantages do you
> think that one has over the other?
> 

Since the late 1950's Lisp has participated in the development of
modern (present day) programming practises.  It has shaped and been
shaped by the minds of just not programmers, but people involved
in dealing with the larger impacts and possibilities.
Its been there, is here, and will continue to be there in the future.
Lisp is a human construct that is a force to be reckoned with.  Its
construction reflects something very deep and fundamental about
computing.  So, it depends on what you want.

What do you want?

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


Python's email module - problem with umlauts in some email clients

2006-12-08 Thread Nico Grubert
Hi there,

I wrote a short python script that sends an email using python's email 
module and I am using Python 2.3.5.
The problem is, that umlauts are not displayed properly in some email 
clients:

+ On a windows machine running thunderbird 1.0.2 umlauts are displayed
   properly.
   The email header contains "Content-type: text/plain; charset=utf-8"
   so the email client's character encoding automatically switches to
   "Unicode (UTF-8)"

+ On a solaris machine running thunderbird 1.5.0.8 and on a macintosh
   machine running eudora umlauts are *not* displayed properly.
   The email header does not contain any "Content-type". If I manually
   switch the email client's character encoding to "Unicode (UTF-8)", the
   umlauts are displayed properly. Therefore, I guess it has something to
   do with the missing "Content-type: text/plain; charset=utf-8"
   information in the email header.

Any idea why the "Content-type: text/plain; charset=utf-8" is missing?


Here is my script:

#--
# send email
from email.Header import Header
import email.Message
import email.Utils
import mimetypes
from smtplib import SMTP

host = 'mail.example.com'
mFrom = '[EMAIL PROTECTED]'
mTo = '[EMAIL PROTECTED]'
mSubj = u'f\xfcr'
mBody = u'f\xfcr foo bar'
mBody = mBody.encode('UTF-8')

mainMsg = email.Message.Message()

mainMsg['From'] = mFrom
mainMsg['To'] = mTo
mainMsg['Subject'] = mSubj
mainMsg.set_payload(mBody)

mainMsg['Date'] = email.Utils.formatdate(localtime=1)
mainMsg['Message-ID'] = email.Utils.make_msgid()
mainMsg['Mime-version'] = '1.0'
mainMsg['Content-type'] = 'text/plain; charset=utf-8'
mainMsg['Content-transfer-encoding'] = '8bit'
# 'quoted-printable' does not work either
# mainMsg['Content-Transfer-Encoding'] = 'quoted-printable'

s = SMTP(host)
s.sendmail(mFrom, [mTo], mainMsg.as_string())
s.close()
#--

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


Re: Python's email module - problem with umlauts in some email clients

2006-12-08 Thread Fredrik Lundh
Nico Grubert wrote:

> + On a solaris machine running thunderbird 1.5.0.8 and on a macintosh
>   machine running eudora umlauts are *not* displayed properly.
>   The email header does not contain any "Content-type". If I manually
>   switch the email client's character encoding to "Unicode (UTF-8)", the
>   umlauts are displayed properly. Therefore, I guess it has something to
>   do with the missing "Content-type: text/plain; charset=utf-8"
>   information in the email header.
>
> Any idea why the "Content-type: text/plain; charset=utf-8" is missing?

a misconfigured mail transfer agent ?

 



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


Re: merits of Lisp vs Python

2006-12-08 Thread Richard Brodie

"Alex Mizrahi" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]

> heh, do you have "standard numeric packages" for everything? maybe then we'll 
> make 
> standard programs for everything -- that will obsolete "slow" "custom 
> scripts" and we'll 
> just use shell to select what program we want to run?

No, I was observing that, faced with a matrix multiplication problem, most
sensible Python developers would do "apt-get install python-numeric" or
equivalent. Trying to do it in pure Python would be the wrong tool for the
job. If you think that's a weakness of Python compared to Lisp, then so
be it. 


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


Re: I think Python is a OO and lite version of matlab

2006-12-08 Thread Godson

On 8 Dec 2006 01:57:20 -0800, Allen <[EMAIL PROTECTED]> wrote:



> Sure, and earth is a heavy version of a basketball. If all you have is
> a hammer...
>

It is not make sense to compare earth and basketball.
I think Python introduced many idea of matlab.

If you have used matlab, you will say that they are very very similar,
except that matlab was born years earlier and is used mainly in the
area
of matrix calculation.

I do not mean Python shall feel ashamed for it. We will be pleased that
Python
does absorb many successful ideas of computer languages.

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



Yes starting from the prompt '>>>' to concept of name spaces, they are
alike, I came to know python first later Matlab in college.  The scope of
matlab is very narrow ,scientific computations and nothing else, To me
matlab seems to be a subset of python, and python being light weight, cause
it swallows what ever comes in it way!!! [
http://www.ibiblio.org/Dave/Dr-Fun/df24/df2406.jpg ]

--
Godson Gera,
http://godson.auroinfo.com
-- 
http://mail.python.org/mailman/listinfo/python-list

IMAP4 SEARCH question

2006-12-08 Thread Laszlo Nagy
  Hi,

I'm using imaplib to access an IMAP4 server. I'm reading the IMAP4 
specification, and I found something odd. The search command  can be 
used in conjuction with date values. For example, I would like to search 
for messages that are older than 30 days. However, the IMAP4 specs does 
not define date/time type(s). Here is a link:

http://tools.ietf.org/html/rfc3501#page-16

As you can see, there are some types: NIL, Number, String and 
Parenthesized List. So how do I specify a date? If it is encapsulated in 
a string, then what format should I use? The the RFC contains an example:

http://tools.ietf.org/html/rfc3501#page-49

  BEFORE 
 Messages whose internal date (disregarding time and timezone)
 is earlier than the specified date.

  Example:C: A282 SEARCH FLAGGED SINCE 1-Feb-1994 NOT FROM "Smith"
   S: * SEARCH 2 84 882


But of course I cannot tell what is the date format. I would like to use 
ISO8601 if possible. It is easy (at least from python) and it is well 
standardized. But will the IMAP4 server understand it? Okay, I know that 
I can try this with my IMAP server. But how strange it is that the RFC 
does not define the accepted date formats? Will my program work with any 
IMAP server? If any of you have experience with this, please respond.

(I'm sorry, I know it is not strictly related to Python, it is more 
likely an RFC/IMAP question.)

Best,

   Laszlo


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


Re: why is this different?

2006-12-08 Thread Marc 'BlackJack' Rintsch
In <[EMAIL PROTECTED]>, Schüle Daniel wrote:

> I have two more examples, but now I understand the difference
> 
> In [70]: x = [eval("lambda:i") for i in range(10)]
> In [71]: y = [eval("lambda:%i" % i) for i in range(10)]
> 
> I think [71] is most obvious what the programmer intends

But unnecessary use of `eval()` is evil.  You can spell it this way:

z = [lambda x=i: x for i in range(10)]

The `x` is a local name and default values are evaluated and bound when
the function is created.

Ciao,
Marc 'BlackJack' Rintsch
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: merits of Lisp vs Python

2006-12-08 Thread Rob Thorpe
Mathias Panzenboeck wrote:
> Mark Tarver wrote:
> > How do you compare Python to Lisp?  What specific advantages do you
> > think that one has over the other?
> >
> > Note I'm not a Python person and I have no axes to grind here.  This is
> > just a question for my general education.
> >
> > Mark
> >
>
> I do not know much about Lisp. What I know is:
> Python is a imperative, object oriented dynamic language with duck typing,

Yes, but Python also supports the functional style to some extent.

> List is a declarative,
> functional dynamic language

Lisp is only a functional language in that it support both functional
and imperative programming styles.  Duck typing is almost identical to
latent typing in Lisp.
And, Common Lisp at least is object orientated.

> -> those two languages have different scopes.

Their scope is actually very similar.  Learn about lisp and you will
soon discover their similarity.

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


Re: Common Python Idioms

2006-12-08 Thread Marc 'BlackJack' Rintsch
In <[EMAIL PROTECTED]>, Daniel Dittmar wrote:

> John Machin wrote:
>> No it doesn't look wrong to anyone who has read the docs on
>> sys.modules. 
> 
> My point was really that there is no obvious implementation for 'in' on 
> dictionaries, so it should have been left out. And that GvR thought so 
> for quite some time as well (until he got mixed up with a crowd of ex 
> C++ programmers).

Maybe there's no obvious implementation for ``in`` and dictionaries but
there is the semantics of ``in`` and iterables.  Dictionaries are iterable
so it's clearly defined what ``'answer' in {'answer': 42}`` should return.

In [84]: class A:
   : def __iter__(self):
   : return iter((1,2,3))
   :

In [85]: a = A()

In [86]: 2 in a
Out[86]: True

In [87]: 5 in a
Out[87]: False

If ``in`` shouldn't work with dictionaries, either `__contains__()` must
be implemented to throw an exception or dictionaries shouldn't be iterable.

Ciao,
Marc 'BlackJack' Rintsch
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: merits of Lisp vs Python

2006-12-08 Thread Kay Schluehr
Alex Mizrahi schrieb:

> it's also
> interesting, that python, perl, php and ruby show very similar peformance,
> while lisp and scheme implementations show large improvements -- it makes me
> think that there's something "pathalogically scripting" in their
> specifications (maybe some obligatory use of strings for method dispatch?).

"The most unusual features of the SBCL compiler (which is very similar
to the original CMUCL compiler, also known as Python) is its unusually
sophisticated understanding of the Common Lisp type system and its
unusually conservative approach to the implementation of type
declarations.

These two features reward the use of type declarations throughout
development, even when high performance is not a concern. Also, as
discussed in the chapter on performance (see Efficiency), the use of
appropriate type declarations can be very important for performance as
well."

http://www.sbcl.org/manual/Handling-of-Types.html#Handling-of-Types

If you'd read the docs of the tools you admire you might find the
answers yourself.

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


Re: IMAP4 SEARCH question

2006-12-08 Thread Laszlo Nagy
Sorry, I found it:

date= date-text / DQUOTE date-text DQUOTE
date-day= 1*2DIGIT ; Day of month
date-day-fixed  = (SP DIGIT) / 2DIGIT ; Fixed-format version of date-day
date-month  = "Jan" / "Feb" / "Mar" / "Apr" / "May" / "Jun" /
  "Jul" / "Aug" / "Sep" / "Oct" / "Nov" / "Dec"
date-text   = date-day "-" date-month "-" date-year



Is there a standard way to convert a datetime to this special, format or 
should I write my own function?

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


Re: merits of Lisp vs Python

2006-12-08 Thread Carl Banks
Mark Tarver wrote:
> This confirms my suspicion
> that Lisp is losing out to newbies because of its
> lack of standard support for the things many people want to do.

Whoa there, that's a pretty big logical jump there, don't you think?

Consumer choice can never be boiled down to one thing; there are so
many factors.  No one knows the whole answer.  I certainly don't.  (If
I did, I'd be courteously turning down the Nobel Prize for Economics on
account of being so rich I really didn't need the extra pocket change.)

I have no doubt that what you say is a contributing factor, but if I
had to guess the main reason why Lisp is losing out to newbies, I'd say
it's first impressions.  When newbies see Python they say, "Ok, I can
kind of follow that, it doesn't look too hard to learn."  When they see
Lisp they say, "WTF IS THAT???"

It's kind of sad, in a way, that a superficiality would be so crucial.
(Not that I think outward appearance is all superficial--I think humans
have evolved and/or learned to regard as beautiful that which minimizes
effort--but it's not the whole story and not basis for a whole
judgment.)


Carl Banks

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


Re: merits of Lisp vs Python

2006-12-08 Thread hankhero
One overlooked advantage for Lisp over Python is a better development
environment, for me that means Slime for Lisp. For Python I have
several years of experience with IDLE and the win32 Ide, and Slime is
the winner. Press a key and the function you are editing is recompiled
and loaded into memory. The crossreference and the object inspector is
very nice. How about fuzzy-complete, I only have to write de-me and
press tab, and I get define-method-combination.
Slime coupled with the paredit structured editing mode, which lets you
edit Lisp code as list structure rather than characters, is a dream.

Pythons advantages are:

Faster startup-time which makes it a good scripting language.

More platforms, there is no Common Lisp on Nokia phones.

Some clever details, like using minus to index vectors from the right.
(aref "hello" -1) gives an error on Lisp, but the character o on
Python.

Another detail I like is that you can choose how to quote strings, in
Python you can write three double-quotes to start a string that can
include anything, quotes, doublequotes and newlines.
You can use double-quote if you want to embed single-quotes "john's" or
single-quote if you want to embed double-quotes ''.

Talking about Lisps advantages will take me too long.

/hankhero, a switcher.

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


Re: Subprocess with a Python Session?

2006-12-08 Thread Fredrik Lundh
Paul Boddie wrote:

> This is one of the more reliable methods since upon receiving a packet
> "delimiter" the receiver knows that the data is complete.

and for people who want RELIABLE and not just "at least 
not entirely unreliable", there's always:

 http://cr.yp.to/proto/netstrings.txt

(if you control both ends, there's hardly ever any reason not to use 
netstrings.  they're trivial to generate from Python, and pretty simple 
to parse.).



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


Re: IMAP4 SEARCH question

2006-12-08 Thread Laszlo Nagy

Laszlo Nagy wrote:

Sorry, I found it:

date= date-text / DQUOTE date-text DQUOTE
date-day= 1*2DIGIT ; Day of month
date-day-fixed  = (SP DIGIT) / 2DIGIT ; Fixed-format version of date-day
date-month  = "Jan" / "Feb" / "Mar" / "Apr" / "May" / "Jun" /
  "Jul" / "Aug" / "Sep" / "Oct" / "Nov" / "Dec"
date-text   = date-day "-" date-month "-" date-year



Is there a standard way to convert a datetime to this special, format or 
should I write my own function?

If anyone is interested.

Keywords: IMAP, RFC3501, date format, search

"""Custom date class that 'knows' the date format as specified in RFC3501 
IMAP4rev1"""
import datetime

class IMAPDate(datetime.date):
MONTHNAMES = 
['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec']
def to_imapdate(self):
"""Format a date as described in RFC3501."""
return "%d-%s-%d" % (
self.day,
self.MONTHNAMES[self.month-1],
self.year
)
@classmethod
def from_imapdate(cls,s):
"""Convert an IMAP style date format to an IMAPDate object."""
if isinstance(s,basestring):
parts = s.split('-')
ok = False
if len(parts) == 3:
try:
day = int(parts[0])
month = cls.MONTHNAMES.index(parts[1])+1
year = int(parts[2])

except:
pass
return cls(year,month,day)
if not ok:
raise ValueError("Invalid IMAP date format. 
Please check RFC3501.")
else:
raise TypeError



if __name__ == '__main__':
date = IMAPDate.today()
fmt = date.to_imapdate()
print fmt
print IMAPDate.from_imapdate(fmt)
print IMAPDate.from_imapdate('32-Jan-2006')
-- 
http://mail.python.org/mailman/listinfo/python-list

Text Encoding - Like Wrestling Oiled Pigs

2006-12-08 Thread apotheos
So I've got a problem.

I've got a database of information that is encoded in Windows/CP1252.
What I want to do is dump this to a UTF-8 encoded text file (a RSS
feed).

While the overall problem seems to be related to the conversion, the
only error I'm getting is a

"UnicodeDecodeError: 'ascii' codec can't decode byte 0x92 in position
163: ordinal not in range(128)"

So somewhere I'm missing an implicit conversion to ASCII which is
completely aggrivating my brain.

So, what fundamental issue am I completely overlooking?

Code follows.

def GenerateNoticeRSS():


output = codecs.open(FILEBASE + 'noticeboard.xml','w','utf-8')


conn = psycopg.connect(DSN)


curs = conn.cursor()


sql_query = "select story.subject as subject, story.content as
content, story.summary as summary, story.sid as sid, posts.bid as
board, posts.date_to_publish as date from story$
curs.execute(sql_query)


rows = curs.fetchall()


output.write('\n')


output.write('\n')



output.write('\n')


output.write('U of L Notice Board\n')


output.write('http://www.uleth.ca/notice\n')


output.write('University of Lethbridge News and
Events\n')


for each in rows:




  output.write('\n')


  output.write('' + rssTitlePrefix(each[4]) +
unicode(each[0]) + '\n')


output.write('http://www.uleth.ca/notice/display.html?b=' +
str(each[4]) + '&s=' + str(each[3]) + '\n')


output.write('http://www.uleth.ca/notice/display.html?b=' +
str(each[4]) + '&s=' + str(each[3]) + '\n')
  descript = each[2] + '' + each[1]





  output.write(u'' + unicode(descript) +
u'\n') # this is the line that causes the error.


  output.write('\n')
output.write('\n')
output.write('\n')
output.close()

 
return 0

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


Re: merits of Lisp vs Python

2006-12-08 Thread Fredrik Lundh
Carl Banks wrote:

> Consumer choice can never be boiled down to one thing; there are so
> many factors.  No one knows the whole answer.  I certainly don't.

it's all due to Python's humongous marketing budget, of course.  just 
imagine what would have happened if someone had spent that much VC money 
on Lisp.



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


Re: merits of Lisp vs Python

2006-12-08 Thread Soni Bergraj
Mark Tarver wrote:
> seems to show that Python is a cut down (no macros) version of Lisp
> with a worse performance.

If you wont to put it this way, go for it. But if you care to give it a
closer look, you may understand that Pythons main advantage is not
seizable by feature and performance charts.

Regards,
-- 
Soni Bergraj
http://www.YouJoy.org/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Subprocess with a Python Session?

2006-12-08 Thread Paul Boddie
Fredrik Lundh wrote:
> Paul Boddie wrote:
>
> > This is one of the more reliable methods since upon receiving a packet
> > "delimiter" the receiver knows that the data is complete.
>
> and for people who want RELIABLE and not just "at least
> not entirely unreliable", there's always:
>
>  http://cr.yp.to/proto/netstrings.txt

That's why I hedged my bets and put "one of the more" rather than "the
most" in that sentence. ;-) I've been using netstrings myself, although
I didn't know that they had that particular name.

> (if you control both ends, there's hardly ever any reason not to use
> netstrings.  they're trivial to generate from Python, and pretty simple
> to parse.).

Indeed.

Paul

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


Re: merits of Lisp vs Python

2006-12-08 Thread Bjoern Schliessmann
Alex Mizrahi wrote:

> hell no, lisp's syntax is much easier than python's since it's
> homogenous 

Can you give an example? I cannot imagine how homogenity always
results in easiness.

> (and certainly lisp was invented much 30 years before 
> Python, so that's Python uses Lisp features)

I think you acknowledged that the syntax is different and not
borrowed?

[many parentheses]
> that make logic more explicit

Can you give an example?
 
Regards,


Björn

Xpost cll,clp

-- 
BOFH excuse #166:

/pub/lunch

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


Re: merits of Lisp vs Python

2006-12-08 Thread George Sakkis
Alex Mizrahi wrote:

> (message (Hello 'Istvan)
> (you :wrote  :on '(8 Dec 2006 06:11:20 -0800))
> (
>
>  ??>> seems to show that Python is a cut down (no macros) version of Lisp
>  ??>> with a worse performance.
>
>  IA> or maybe it shows that Lisp is an obfuscated version of Python
>
> hell no, lisp's syntax is much easier than python's since it's homogenous

It sure is easier... if you're a compiler rather than a human. Also a
lightbulb is much easier understood as a bunch of homogeneous elemental
particles.

George

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


Re: merits of Lisp vs Python

2006-12-08 Thread André Thieme
hankhero schrieb:

> Some clever details, like using minus to index vectors from the right.
> (aref "hello" -1) gives an error on Lisp, but the character o on Python.

It would not be difficult to add this feature to Lisp.


> Another detail I like is that you can choose how to quote strings, in
> Python you can write three double-quotes to start a string that can
> include anything, quotes, doublequotes and newlines.
> You can use double-quote if you want to embed single-quotes "john's" or
> single-quote if you want to embed double-quotes ''.

You could add a reader macro in Lisp that allows you to do the same.
At the moment I would say that one could pretty much add most Python
features to Lisp. Be it slicing, list comprehension, or, if one wants,
Pythons object system.

On the other hand can I see difficulties in adding macros to Python,
or inventing a new object system, or adding new keywords without
changing the sources of Python itself.


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


Re: [ctypes-users] comtypes

2006-12-08 Thread Niki Spahiev
Thomas Heller wrote:
> comtypes seems to gain some attention (comtypes is a pure Python, lightweight
> COM client and server framework, based on the ctypes Python FFI package.)
> 
> I'll try to release a new version over the next days.
> 
> However, I'm wondering what would be the correct list to discuss this 
> package...
> 
> - the python-win32 mailing list

IMO most of COM knowledge is in python-win32 list. It's better not to 
split due to python implementation details only.

Niki Spahiev

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


shell command needs whitespace characters escaped

2006-12-08 Thread metaperl
I downloaded a file which has a space in the filename. I want to run a
shell unzip on it, but it fails in my current code:

syscmd = "cd %s ; unzip %s" % (self.storage.input,
file.basename())
os.system(syscmd)

because no escaping was done.

Is there a more principled way to construct a shell command and execute
it so that all necessary characters are escaped?

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


Re: merits of Lisp vs Python

2006-12-08 Thread Petter Gustad
Bjoern Schliessmann <[EMAIL PROTECTED]> writes:

> Can you give an example? I cannot imagine how homogenity always
> results in easiness.

CL-USER> (+ 1 2 3 4 5 6 7 8 9 10)
55

CL-USER> (< 1 2 3 4 5 6 7 8 9 10)
T
CL-USER> (< 1 2 3 4 5 6 7 8 9 10 9)
NIL


Petter
-- 
A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
-- 
http://mail.python.org/mailman/listinfo/python-list


py2exe install script problem

2006-12-08 Thread Croteam
Hello,

I using py2exe for my script installing,and I have one problem about
it,actually the real problem is
tkinter window iconbitmap:

  import Tkinter
  root=Tkinter.Tk()
  root.iconbitmap('myicon.ico')  # I was try and with myicon.bmp


Then after I install myscript in .exe,and when I run it I got error in
some strange window:

window title: Error occurred
window message:  See the logfile
'c:\Python24\Lib\site-packages\dist\myscript.exe' for details

and tad and in that error "make" in install directory one log file, and
that file I run with notepad and
in that  notepad file
write error:

   Traceback (most recent call last):
  File "myscript.py", line 3, in ?
  File "Tkinter.pyc", line 1448, in wm_iconbitmap
_tkinter.TclError: bitmap "myicon.ico" not defined


   Thanks!

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


Re: How to create a global hotkey?

2006-12-08 Thread k04jg02
Sorry, I should have mentioned that I'm running Linux, and I only will
be running this app while X is running. pyHook doesn't seem to be an
option because it's win32 only. I'm guessing python-xlib is the way to
go, but it seems to be that it relies on you understanding the C xlib
library, which is old and heavily obfuscated. Any advice on how to use
python xlib to register a global hotkey? In the docs I found the
KeyEvent event type, but it seems to want a specific window too.

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


Re: merits of Lisp vs Python

2006-12-08 Thread Bill Atkins
Bjoern Schliessmann <[EMAIL PROTECTED]> writes:

> I think you acknowledged that the syntax is different and not
> borrowed?

Um, so does that mean that Python couldn't have borrowed other
features?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: merits of Lisp vs Python

2006-12-08 Thread Bill Atkins
"Mark Tarver" <[EMAIL PROTECTED]> writes:

> How do you compare Python to Lisp?  What specific advantages do you
> think that one has over the other?
>
> Note I'm not a Python person and I have no axes to grind here.  This is
> just a question for my general education.
>
> Mark

What was the reasoning behind cross-posting this to c.l.p and c.l.l?
This type of question inevitably leads to controversy.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Common Python Idioms

2006-12-08 Thread Daniel Dittmar
Marc 'BlackJack' Rintsch wrote:
> If ``in`` shouldn't work with dictionaries, either `__contains__()` must
> be implemented to throw an exception or dictionaries shouldn't be iterable.

I agree completely (in the sense that dictionaries shouldn't be iterable 
directly). Probably even more strongly, at least every time I see some 
code where someone iterates over the keys, only to use the key to look 
up the value (instead if using iteritms).

For strings, the 1:1 relationship between 'in' and iteration has already 
been broken. But then, iteration over strings happens in my code only 
when a pass a string where I should have passed a list of strings.

Daniel


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


Re: merits of Lisp vs Python

2006-12-08 Thread George Sakkis
André Thieme wrote:

> On the other hand can I see difficulties in adding macros to Python,
> or inventing a new object system, or adding new keywords without
> changing the sources of Python itself.

Actually, an even bigger difficulty is the rejection of programmable
syntax by Guido, both for the near and distant future:

"Programmable syntax is not in Python's future -- or at least it's not
for Python 3000. The problem IMO is that everybody will abuse it to
define their own language. And the problem with that is that it will
fracture the Python community because nobody can read each other's code
any more."

http://mail.python.org/pipermail/python-3000/2006-April/000286.html.


George

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


Re: shell command needs whitespace characters escaped

2006-12-08 Thread Klaus Alexander Seistrup
Metaperl wrote:

> I downloaded a file which has a space in the filename. I want 
> to run a shell unzip on it, but it fails in my current code:
>
> syscmd = "cd %s ; unzip %s" % (self.storage.input, file.basename())
> os.system(syscmd)
>
> because no escaping was done.

Using "cd '%s' ; unzip '%s'" as your formatting string should work.

Cheers,

-- 
Klaus Alexander Seistrup
http://klaus.seistrup.dk/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: merits of Lisp vs Python

2006-12-08 Thread Alex Mizrahi
(message (Hello 'Kay)
(you :wrote  :on '(8 Dec 2006 08:03:18 -0800))
(

 KS> http://www.sbcl.org/manual/Handling-of-Types.html#Handling-of-Types

 KS> If you'd read the docs of the tools you admire you might find the
 KS> answers yourself.

SBCL is a COMPILER that explains everything. it's interesting why 
INTERPRETER like CLISP is faster.
well, it can be type declarations as well, but maybe something other too..

for example, in languages like Python, PHP and JavaScript, as i understand, 
by semantics of the language interpreter MUST use dict to call objects 
method -- at any time it can be changed, for any object instance. i'm not 
sure whether it has to dynamically resolve package's methods doing lookup in 
packages dict.

however, in Common Lisp object methods are dispatched on object types, that 
is a special language entity, so as long as new types are not introduced, 
interpreter can optimize calls how it wants to. the difference is that while 
it's still dynamic, dispatch over types are more controlled/optimizable than 
dispatch using dict.
then, symbols in common-lisp package cannot be changed according to spec, 
thus compiler/interpreter is safe to do optimizations it wants when sees 
that symbols (if we want symbols with same names, we can make other package 
with them).

then, Common Lisp standard defines what inlining is. i bet most 
optimizations in dynamic languages are not possible if inlining is not 
enabled -- since any symbol that is not inlined can change it's meaning in 
any time.

)
(With-best-regards '(Alex Mizrahi) :aka 'killer_storm)
"People who lust for the Feel of keys on their fingertips (c) Inity") 


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


Problem in reading a URL

2006-12-08 Thread Χρυσάνθη Αϊναλή
Hi,

I get an error, when I am trying to read URL.
Where is the Problem?

Thank u very much for all ideas!!!

sincerely

Chrysanthi


from urllib2 import *

filename=urlopen('http://www.ncbi.nlm.nih.gov/entrez/viewer.fcgi?query_key=1&db=nucleotide&qty=1&c_start=1&uids=&dopt=fasta&dispmax=20&sendto=t')

for line in filename.readlines():

 print line,


Error: History is unavailable either because it has expired or because
your system cannot accept cookies
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: shell command needs whitespace characters escaped

2006-12-08 Thread Fredrik Lundh
metaperl wrote:

> I downloaded a file which has a space in the filename. I want to run a
> shell unzip on it, but it fails in my current code:
> 
> syscmd = "cd %s ; unzip %s" % (self.storage.input,
> file.basename())
> os.system(syscmd)
> 
> because no escaping was done.
> 
> Is there a more principled way to construct a shell command and execute
> it so that all necessary characters are escaped?

use subprocess.list2cmdline to create the command string (or better, 
subprocess.call).  see this FAQ entry for sample code:

http://effbot.org/pyfaq/why-can-t-raw-strings-r-strings-end-with-a-backslash.htm



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


MySQL-python-1.2.1_p2, Python 2.5 and OS X Tiger

2006-12-08 Thread scum
How do you install MySQL-python-1.2.1_p2 on a PPC OS X 10.4 machine
with MySQL 4.1?

>>> python setup.py build

...
...
_mysql.c:2854: error: parse error before ')' token
_mysql.c:2854: error: called object '&' is not a
function
_mysql.c:2854: error: called object '&' is not a
function
_mysql.c:2854: error: called object '*(&)' is not
a function
lipo: can't figure out the architecture type of: /var/tmp//ccurx79n.out
error: command 'gcc' failed with exit status 1

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


Re: MySQL-python-1.2.1_p2, Python 2.5 and OS X Tiger

2006-12-08 Thread scum
And I know about the precompiled binary...  I'm just sick of getting
this warning

Python 2.5 (r25:51918, Sep 19 2006, 08:49:13)
[GCC 4.0.1 (Apple Computer, Inc. build 5341)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import _mysql
__main__:1: RuntimeWarning: Python C API version mismatch for module
_mysql: This Python has API version 1013, module _mysql has version
1012.

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


Re: Problem in reading a URL

2006-12-08 Thread Fredrik Lundh
Χρυσάνθη Αϊναλή wrote:

> I get an error, when I am trying to read URL.
> Where is the Problem?

did you read the error message you got from the server?

> Error: History is unavailable either because it has expired or because
> your system cannot accept  href='/entrez/query/static/faq.html#Acceptscookies'>cookies



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

Re: Window, Windows, Linux, client and server...

2006-12-08 Thread Cameron Laird
In article <[EMAIL PROTECTED]>,
MRAB <[EMAIL PROTECTED]> wrote:
.
.
.
>I think he wants to be able to show the server desktop on a client (for
>example, to show a user how to do something) and also be able to see a
>client desktop on the server (for example, to see whether the user is
>doing it correctly).
>
>Is there and easy way to switch between showing the server on a client
>and seeing a client on the server?
>

Now I don't understand use of "server" and "client" in this thread.
Would teleconferencing software that allows two users to see each 
others' desktops, or portions of them, suffice?  I'll also repeat:
in what ways does VNC fail to meet the requirements?
-- 
http://mail.python.org/mailman/listinfo/python-list


*** C.L.L README/FAQ *** (Was: merits of Lisp vs Python)

2006-12-08 Thread [EMAIL PROTECTED]
Sounds like it's time for:

A Beginners' Meta FAQ for comp.lang.lisp:

  http://nostoc.stanford.edu/jeff/llisp/cllfaq.html

The purpose of this page is to help those new to Lisp (aka. "newbies")
gain some background before they enter the fray of comp.lang.lisp
(c.l.l). This is not a complete Lisp FAQ! Once you have a sense of Lisp

and of how c.l.l operates you should have no trouble finding all the
additional information you need, either by your own search efforts or
by asking the community. If you have issues with any of the below
please do not send me email. Rather, post on c.l.l in the weekly thread

where this is announced (heading: "*** C.L.L README/FAQ ***").

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


Re: Common Python Idioms

2006-12-08 Thread Fredrik Lundh
Daniel Dittmar wrote:

> I agree completely (in the sense that dictionaries shouldn't be iterable 
> directly). Probably even more strongly, at least every time I see some 
> code where someone iterates over the keys, only to use the key to look 
> up the value (instead if using iteritms).

so?  that's the original Python way of doing things, and is both very 
readable and surprisingly efficient:

$ timeit -s "d = vars()" "for k in d: v = d[k]"
100 loops, best of 3: 0.472 usec per loop

$ timeit -s "d = vars()" "for k, v in d.iteritems(): pass"
100 loops, best of 3: 0.663 usec per loop



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


Re: Problem in reading a URL

2006-12-08 Thread Simon Brunning
On 12/8/06, Χρυσάνθη Αϊναλή <[EMAIL PROTECTED]> wrote:
> Hi,
>
> I get an error, when I am trying to read URL.
> Where is the Problem?
>
> Thank u very much for all ideas!!!
>
> sincerely
>
> Chrysanthi
>
>
> from urllib2 import *
>
> filename=urlopen('http://www.ncbi.nlm.nih.gov/entrez/viewer.fcgi?query_key=1&db=nucleotide&qty=1&c_start=1&uids=&dopt=fasta&dispmax=20&sendto=t')
>
> for line in filename.readlines():
>
>  print line,
>
>
> Error: History is unavailable either because it has expired or because
> your system cannot accept  href='/entrez/query/static/faq.html#Acceptscookies'>cookies

Have you tried that URL on your browser?

-- 
Cheers,
Simon B
[EMAIL PROTECTED]
http://www.brunningonline.net/simon/blog/
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Text Encoding - Like Wrestling Oiled Pigs

2006-12-08 Thread John Machin

[EMAIL PROTECTED] wrote:
> So I've got a problem.
>
> I've got a database of information that is encoded in Windows/CP1252.
> What I want to do is dump this to a UTF-8 encoded text file (a RSS
> feed).
>
> While the overall problem seems to be related to the conversion, the
> only error I'm getting is a
>
> "UnicodeDecodeError: 'ascii' codec can't decode byte 0x92 in position
> 163: ordinal not in range(128)"
>
> So somewhere I'm missing an implicit conversion to ASCII which is
> completely aggrivating my brain.
>
> So, what fundamental issue am I completely overlooking?

That nowhere in your *code* do you mention "I've got a database of
information that is encoded in Windows/CP1252". This is not recorded
anywhere in your database. Python is fantastic, but we don't expect a
readauthorsmind() function until Python 4000 :-)

>
> Code follows.
>
[snip]
>
> sql_query = "select story.subject as subject, story.content as
> content, story.summary as summary, story.sid as sid, posts.bid as
> board, posts.date_to_publish as date from story$

The above line has been mangled ... fortunately it doesn't affect the
diagnostic outcome.

[snip]
>
>
>   output.write(u'' + unicode(descript) +
> u'\n') # this is the line that causes the error.

What is happening is that unicode(descript) has not been told what
encoding to use to decode your "Windows/CP1252" text, and it uses the
default encoding, "ascii". You need to put unicode(descript, 'cp1252').

Cheers,
John

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


Re: merits of Lisp vs Python

2006-12-08 Thread Alex Mizrahi
(message (Hello 'Bjoern)
(you :wrote  :on '(Fri, 08 Dec 2006 17:31:08 +0100))
(

 ??>> hell no, lisp's syntax is much easier than python's since it's
 ??>> homogenous

 BS> Can you give an example? I cannot imagine how homogenity always
 BS> results in easiness.

homogenity means that i can cut any expression and paste in any other 
expression, and as long as lexical variables are ok, i'll get correct 
results -- i don't have to reindent it or whatever.
this is aproximately what programmer does -- he paste pieces of code from 
his mind into the program.

 BS> [many parentheses]
 ??>> that make logic more explicit
 BS> Can you give an example?

also, there's no need for operator precendence to be taken in accound --  
order is explicitly defined. expressions are homogenous, they do not depend 
on other expressions near them (except lexical variables and side effects).

the other example of homogenous syntax is XML, that is very popular 
nowadays, and it's very similar to lisp's s-expressions.

certainly, it's a matter of taste what syntax to prefer -- i prefer lisp 
syntax, others might prefer Python, ML or Haskell syntax.
but homogenous syntax is very important for true macros.

 ??>> (and certainly lisp was invented much 30 years before
 ??>> Python, so that's Python uses Lisp features)

 BS> I think you acknowledged that the syntax is different and not
 BS> borrowed?

certainly

)
(With-best-regards '(Alex Mizrahi) :aka 'killer_storm)
"People who lust for the Feel of keys on their fingertips (c) Inity") 


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


is there a tutorial for creating packages in python?

2006-12-08 Thread krishnakant Mane
hello all,
I have got a lot of sets of functions and classes that do related
work.  so just like we get python libraries I too need to create such
libraries often called packages.
I want to put my code to re-use so will create these libraries and put
in the site-libs folder.
can any one suggest me a good tutorial on line which can teach me to
develop python packages and modules and most importantly to put them
in libraries?
I saw the official python tutorial and I think chapter 6 has quite a
bit on that.
but not what I could term as some thing complete in knowledge that one
needs to create libraries as huge as wxpython etc.

thanking all.
Krishnakant.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: *** C.L.L README/FAQ *** (Was: merits of Lisp vs Python)

2006-12-08 Thread Fredrik Lundh
[EMAIL PROTECTED] wrote:

> Sounds like it's time for:
> 
> A Beginners' Meta FAQ for comp.lang.lisp:
> 
>   http://nostoc.stanford.edu/jeff/llisp/cllfaq.html
> 
> The purpose of this page is to help those new to Lisp (aka. "newbies")
> gain some background before they enter the fray of comp.lang.lisp

so why are you posting this to comp.lang.python ?



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


RE: Text Encoding - Like Wrestling Oiled Pigs

2006-12-08 Thread Tim Golden
[EMAIL PROTECTED]

| I've got a database of information that is encoded in Windows/CP1252.
| What I want to do is dump this to a UTF-8 encoded text file (a RSS
| feed).

| "UnicodeDecodeError: 'ascii' codec can't decode byte 0x92 in position
| 163: ordinal not in range(128)"
| 
| So somewhere I'm missing an implicit conversion to ASCII which is
| completely aggrivating my brain.

[... snip ...]

  descript = each[2] + '' + each[1]

|   output.write(u'' + unicode(descript) +
| u'\n') # this is the line that causes the error.

Well, if the columns in the "each" row you're using are
unicode objects then that unicode(descript) is redundant
because descript will already be a unicode object. If
the columns are returned as encoded strings then you're 
not giving the unicode converter function any clues as
to what that encoding is.

You said above that the data is stored as cp1252, so why
not try unicode (descript, "cp1252")?


unicode ("\x92")
unicode ("\x92", "cp1252")



gives


>>> unicode ("\x92")
Traceback (most recent call last):
  File "", line 1, in ?
UnicodeDecodeError: 'ascii' codec can't decode byte 0x92 in position 0:
ordinal not in range(128)
>>> unicode ("\x92", "cp1252")
u'\u2019'



Or am *I* missing something more obvious?

TJG


This e-mail has been scanned for all viruses by Star. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:
http://www.star.net.uk

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


Re: Problem in reading a URL

2006-12-08 Thread scum
This is not a python problem.  That is the text of the site when you go
to it.  The site uses cookies to store a session of your visit.  Using
python bypasses that cookie and throws an error.  You will be better
served using teh mechanize library.

http://wwwsearch.sourceforge.net/mechanize/

Even though you may not get far, since the site you are attempting to
search prevents robots from scouring their site.

>>> import mechanize
>>> from mechanize import Browser
>>> br= Browser()
>>> br.open("http://www.ncbi.nlm.nih.gov/entrez/";)
Traceback (most recent call last):
  File "", line 1, in 
  File
"/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/mechanize-0.1.4b-py2.4.egg/mechanize/_mechanize.py",
line 156, in open
  File
"/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/mechanize-0.1.4b-py2.4.egg/mechanize/_mechanize.py",
line 214, in _mech_open
mechanize._response.httperror_seek_wrapper: HTTP Error 403: request
disallowed by robots.txt

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


Re: How to create a global hotkey?

2006-12-08 Thread Paul Boddie
[EMAIL PROTECTED] wrote:
> Sorry, I should have mentioned that I'm running Linux, and I only will
> be running this app while X is running.

Global "hot keys" are typically the domain of the desktop environment
(or window manager for archaic desktops). For example, KDE has a
configuration dialogue where you can define hot keys or key
combinations that do particular things: I've got the Windows key doing
useful stuff in combination with other keys, for example.

So programmatically setting hot keys may be something that requires
communication with the desktop environment, and it would appear that on
KDE you have to put hot key definitions in a file and then import them,
the latter possibly being achieved using the DCOP interprocess
communications mechanism provided in the environment (try "dcop
khotkeys khotkeys" at the shell). Here's the only documentation I've
found so far:

http://developer.kde.org/~seli/khotkeys/

I suppose you could just plug in at the X level and have something
define and intercept a hot key before the desktop environment has a
chance to process it, but I doubt that this would be a particularly
nice solution.

Paul

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


Re: merits of Lisp vs Python

2006-12-08 Thread Mark Tarver
Bill Atkins wrote:
> "Mark Tarver" <[EMAIL PROTECTED]> writes:
>
> > How do you compare Python to Lisp?  What specific advantages do you
> > think that one has over the other?
> >
> > Note I'm not a Python person and I have no axes to grind here.  This is
> > just a question for my general education.
> >
> > Mark
>
> What was the reasoning behind cross-posting this to c.l.p and c.l.l?
> This type of question inevitably leads to controversy.

I don't mind controversy - as long as there is intelligent argument.
And since it involves Python and Lisp, well it should be posted to both
groups.   The Lispers will tend to say that Lisp is better for sure -
so it gives the Python people a chance to defend this creation.

I'm looking at Python and I see that the syntax would appeal to a
newbie.  Its clearer than ML which is a mess syntactically.  But I
don't see where the action is in Python.   Not yet anyway.  Lisp syntax
is easy to learn.  And giving up an order of magnitude is a high price
to pay for using it over Lisp.

Mark

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


Re: merits of Lisp vs Python

2006-12-08 Thread Rob Thorpe
Alex Mizrahi wrote:
> (message (Hello 'Kay)
> (you :wrote  :on '(8 Dec 2006 08:03:18 -0800))
> (
>
>  KS> http://www.sbcl.org/manual/Handling-of-Types.html#Handling-of-Types
>
>  KS> If you'd read the docs of the tools you admire you might find the
>  KS> answers yourself.
>
> SBCL is a COMPILER that explains everything. it's interesting why
> INTERPRETER like CLISP is faster.
> well, it can be type declarations as well, but maybe something other too..

I agree with your other points.  Python allows the programmer to
override absolutely anything, including things like addition.  This
entails extra work.

It's also worth mentioning that Clisp is an hugely optimized
interpreter.  A much work has been put in to making it's bytecode
interpreting inner loops as fast as possible.

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


Using Py_InitModule3 -> [Linker Error] Unresolved external '_Py_InitModule4TraceRefs'

2006-12-08 Thread iwl
Hello

I copied the code from the Extending Embedded Python section in the
Python 2.5 but get an linker Error Unresolved external
_Py_InitModule4TraceRefs.
Who knows what's wrong?

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


Re: Using Py_InitModule3 -> [Linker Error] Unresolved external '_Py_InitModule4TraceRefs'

2006-12-08 Thread Fredrik Lundh
iwl wrote:

> I copied the code from the Extending Embedded Python section in the
> Python 2.5 but get an linker Error Unresolved external
> _Py_InitModule4TraceRefs.
> Who knows what's wrong?

you've mixed components compiled with Py_TRACE_REFS with components that 
aren't compiled with Py_TRACE_REFS.  don't do that.

(what is it with you C programmers these days, btw?  have they stopped 
teaching how to how use "grep" and library inspection tools when they 
teach C and C++ ?)



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


Re: is there a tutorial for creating packages in python?

2006-12-08 Thread Soni Bergraj
krishnakant Mane wrote:
> I saw the official python tutorial and I think chapter 6 has quite a
> bit on that.

I'm not sure what you are after. There is not much to say about building
python packages. I imagine that the important stuff should be in there
(I have not checked!).

If you are looking for ways to distribute your package look at distutils
or setuptools.

> but not what I could term as some thing complete in knowledge that one
> needs to create libraries as huge as wxpython etc.

wxPython is a C (or rather C++) extension (in contrast to a pure Python
package). For C bindings there are several choices, Python C API, SWIG
and ctypes come to mind. For C++ there i Boost.Python. For the usual
packaging work you would use dsitutlis.
http://en.wikibooks.org/wiki/Python_Programming/Extending_with_C gives a
short introduction on how to getting started.

Cheers,
-- 
Soni Bergraj
http://www.YouJoy.org/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Is PyGTK only for local - not web?

2006-12-08 Thread Gian Mario Tagliaretti
walterbyrd wrote:

> I have noticed that there is also pygtk-web project, I suppose that is
> what you use for the web?

It's the pygtk web site as you see it here www.pygtk.org

cheers
-- 
Gian Mario Tagliaretti
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: merits of Lisp vs Python

2006-12-08 Thread Kaz Kylheku
Mark Tarver wrote:
> I don't mind controversy - as long as there is intelligent argument.
> And since it involves Python and Lisp, well it should be posted to both
> groups.   The Lispers will tend to say that Lisp is better for sure -
> so it gives the Python people a chance to defend this creation.

And that would be our confirmation that this is another trolling
asshole.

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


mySql and multiple connection for threads

2006-12-08 Thread johnny
How do you create multiple connection in the treads.  Lets say I will
have at most 5 threads and I want to create at most 5 connections.  If
I create a connection in the "worker method", does it create connection
for each threads.

def worker(tq):
while True:
host, e = tq.get()

c = ftplib.FTP(host)
c.connect()
try:
c.login()
p = os.path.basename(e)
download_dir = r'H:/ftp_download/'
ps_dir = r'H:/ftp_download/'
filename = download_dir+p
fp = open(filename, 'wb')
try: c.retrbinary('RETR %s' % e, fp.write)
finally: fp.close()
finally: c.close()
if (p.lower().endswith('.ps') ):
partFileName = p.split('.', 1)
movedFile = download_dir + p
#movedFile = p
finalFile = ps_dir + partFileName[0]+'.pdf'
encode_cmd = r'ps2pdf '+ movedFile + ' '+ finalFile
os.system(encode_cmd)

conn = adodb.NewADOConnection('mysql')
conn.Connect('localhost', 'temp', 'temp', 'temp')
sql = r"update file where file_path='"+p+"' set
pdf_file_path='" +finalFile+"'"
cursor = conn.Execute(sql)
rows = cursor.Affected_Rows()

tq.task_done()

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


Re: merits of Lisp vs Python

2006-12-08 Thread Jan Dries
Alex Mizrahi wrote:
>  RB> Performance claims are always controversial. So, Python is much slower
>  RB> doing array multiplication, when you hand roll it, instead of using the
>  RB> standard numerical packages available.
> 
> heh, do you have "standard numeric packages" for everything? maybe then 
> we'll make standard programs for everything -- that will obsolete "slow" 
> "custom scripts" and we'll just use shell to select what program we want to 
> run?

I think you're missing the point. You must know your language's 
strengths and weaknesses, and use the approach/function/library that's 
right for the job in the given language.

For instance, on my machine the following Python-code:

 some_string = ""
 while len(some_string) < 10:
 some_string += "*"

outperforms the following C-code:

 strcpy(some_string,"");
 while(strlen(some_string) < 10)
 strcat(some_string,"*");

by roughly *factor 15*!

The point of course is you shouldn't be using strlen/strcat this way, 
nor use this piece of code as a reference for benchmarking C versus 
Python performance.
And for the same reason: in the presence of excellent optimized Python 
libraries for matrix multiplication, you probably shouldn't be doing 
that in pure Python if performance matters, nor use that as a reference 
case in benchmarking Python.

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


Re: shell command needs whitespace characters escaped

2006-12-08 Thread Nick Craig-Wood
Fredrik Lundh <[EMAIL PROTECTED]> wrote:
>  metaperl wrote:
> 
> > I downloaded a file which has a space in the filename. I want to run a
> > shell unzip on it, but it fails in my current code:
> > 
> > syscmd = "cd %s ; unzip %s" % (self.storage.input, file.basename())
> > os.system(syscmd)
> > 
> > because no escaping was done.
> > 
> > Is there a more principled way to construct a shell command and execute
> > it so that all necessary characters are escaped?
> 
>  use subprocess.list2cmdline to create the command string

That is windows only isn't it?

  >>> subprocess.list2cmdline(['a', "'b", 'c'])
  "a 'b c"

Doesn't make a unix shell friendly command line.

For unix you can use this

def quotemeta(args):
"""Quote all the metacharacters in the args for the unix shell"""
return " ".join([re.sub(r"([^A-Za-z0-9_])", r"\\\1", string) for string in 
args])

>>> print quotemeta(['a', "'b", 'c'])
a \'b c

> (or better, subprocess.call).

A good idea!

-- 
Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick
-- 
http://mail.python.org/mailman/listinfo/python-list


  1   2   3   >