Re: Parsing a date-time string?

2005-12-23 Thread Tim Roberts
"Tim N. van der Leeuw" <[EMAIL PROTECTED]> wrote:
>
>I want to parse strings containing date-time, which look like the
>following:
>
> "Mon Dec 19 11:06:12:333 CET 2005"
>
>That's a problem for strptime it seems, b/c I cannot find any
>format-spec for the milliseconds-part in here. (I'm also not sure about
>the validity of the tz part, but ...)

Central European Time.  GMT +1 hour.  Quite valid.
-- 
- Tim Roberts, [EMAIL PROTECTED]
  Providenza & Boekelheide, Inc.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: sorting with expensive compares?

2005-12-23 Thread gene tani

Dan Stromberg wrote:
> Hi folks.
>
> Python appears to have a good sort method, but when sorting array elements
> that are very large, and hence have very expensive compares, is there some
> sort of already-available sort function that will merge like elements into
> a chain, so that they won't have to be recompared as many times?
>
> Thanks!

might be simpler to memoize  cmp(), look in online cookbook or
something like this decorator

http://mail.python.org/pipermail/python-list/2005-October/303035.html
http://aspn.activestate.com/ASPN/Python/Cookbook/

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


Re: sorting with expensive compares?

2005-12-23 Thread bonono

Dan Stromberg wrote:
> Hi folks.
>
> Python appears to have a good sort method, but when sorting array elements
> that are very large, and hence have very expensive compares, is there some
> sort of already-available sort function that will merge like elements into
> a chain, so that they won't have to be recompared as many times?
> 
> Thanks!
Sounds like DSU time.

[a] -> [ (hash(a), a) ]

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


Re: Which Python web framework is most like Ruby on Rails?

2005-12-23 Thread Paul Rubin
Robert Kern <[EMAIL PROTECTED]> writes:
> RMS has said precisely the opposite, in fact.
> http://lists.debian.org/debian-legal/2002/11/msg00217.html

I guess you mean:

> [RMS:]
> As for the more general question, we think that a program that uses
> Emacs facilities needs to be GPL-covered, but a program that just uses
> the Lisp language could have any license--it is not affected by the
> license of Emacs. 

Hmmm.  That seems to say that calling Emacs-specific editing
functions, doing stuff with buffers, etc. implicates the GPL, but
writing a general purpose Lisp program (non-Emacs-specific) and
running it under Emacs does not.  That's different from what I'd
thought he'd said about it before, which was that Lisp code that only
used the documented Emacs API didn't implicate the GPL.  Thanks for
the link.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: problem adding list values

2005-12-23 Thread gene tani

David M. Synck wrote:

>
> """ This function asks the user to input any credits not shown on their 
> bank statement
>

(OT I know, but just so you know, you *may* get away with using floats
for financial calculations if you're handling small numbers of floats
of  roughly same order of magnitude, but if your calculations have to
be exact to the penny, and you have lots of numbers not of the same
magnitudes, you probably don't want to do this.

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


Re: sorting with expensive compares?

2005-12-23 Thread gene tani

[EMAIL PROTECTED] wrote:
> Dan Stromberg wrote:
> > Hi folks.
> >
> > Python appears to have a good sort method, but when sorting array elements
> > that are very large, and hence have very expensive compares, is there some
> > sort of already-available sort function that will merge like elements into
> > a chain, so that they won't have to be recompared as many times?
> >
> > Thanks!
> Sounds like DSU time.
>
> [a] -> [ (hash(a), a) ]

Aha!  OR: take a log of the array, e.g. log base 10 or some other
monotonic transform and permutation order indexes
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/306862

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


Re: sorting with expensive compares?

2005-12-23 Thread bonono

gene tani wrote:
> [EMAIL PROTECTED] wrote:
> > Dan Stromberg wrote:
> > > Hi folks.
> > >
> > > Python appears to have a good sort method, but when sorting array elements
> > > that are very large, and hence have very expensive compares, is there some
> > > sort of already-available sort function that will merge like elements into
> > > a chain, so that they won't have to be recompared as many times?
> > >
> > > Thanks!
> > Sounds like DSU time.
> >
> > [a] -> [ (hash(a), a) ]
>
> Aha!  OR: take a log of the array, e.g. log base 10 or some other
> monotonic transform and permutation order indexes
> http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/306862
I may have made a mistaken in that hash(a) should be some function that
returns the "order" of a, rather than the built-in hash() function.

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


Re: sorting with expensive compares?

2005-12-23 Thread Ben Sizer
Dan Stromberg wrote:
> Python appears to have a good sort method, but when sorting array elements
> that are very large, and hence have very expensive compares, is there some
> sort of already-available sort function that will merge like elements into
> a chain, so that they won't have to be recompared as many times?

It's not really practical - if the list is unsorted, it's non-trivial
to determine how many times a given element is duplicated until you've
compared it with everything else. That is roughly an O(N*N/2) operation
whereas sorting typically is O(NlogN). This is why C++'s 'std::unique'
function only operates on sorted lists.

So instead, one alternative would be to use a comparison function that
takes the 2 objects and looks for the pair in a dictionary: if that
pair is not found, perform the normal comparison and store it in the
dictionary for next time, and if it is found, just return it. This way
the actual comparison is only done once for each pair.

Alternatively you might be able to produce a cheap comparison from the
expensive one if you can summarise the information in a simpler form.
Perhaps each sorting criterion can be represented as an integer, and
you can instead sort a list of lists containing integers.

-- 
Ben Sizer

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


Re: Python IMAP4 Memory Error

2005-12-23 Thread Jean-Paul Calderone
On Fri, 23 Dec 2005 14:21:27 +1100, Dody Suria Wijaya <[EMAIL PROTECTED]> wrote:
>Noah wrote:
>> This looks like a bug in your build of Python 2.4.2 for Windows.
>> Basically it means that C's malloc() function in the Python interpreter
>> failed.
>>
>
>On a second trial, it's also failed on Python 2.3.5 for Windows, Python
>2.3.3 for Windows, and Python 2.2.3 for Windows. So this seems to me as
>a Windows system related bug, not a particular version of Python bug.

Arguably, it's a bug in Python's imaplib module.  Sure, the Windows memory 
allocator is feeble and falls over when asked to do perfectly reasonable 
things.  But Python runs on Windows, so Python should do what it takes to work 
on Windows (or mark imaplib UNIX-only).

This particular issue can be avoided most of the time by reading in smaller 
chunks.

You might also address it as a deployment issue, and run fewer programs on the 
host in question, or reboot it more frequently.

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


RE: Parsing a date-time string?

2005-12-23 Thread Leeuw van der, Tim








Hi Tim,

 

Thanks a lot! That sounds like quite a
useful routine, that I can use without going through extra documentation and
adding extra libraries!

 

Cheers,

 

--Tim J

 









From: Tim Williams
(gmail) [mailto:[EMAIL PROTECTED] 
Sent: donderdag 22 december 2005
16:38
To: Leeuw van der, Tim
Cc: python-list@python.org
Subject: Re: Parsing a date-time
string?



 

 



On 21 Dec 2005 01:43:13 -0800, Tim N. van der Leeuw <[EMAIL PROTECTED]>
wrote: 

Hi,

I want to parse strings containing date-time, which look like the
following:

"Mon Dec 19 11:06:12:333 CET 2005"
[snipped]
What I want to get is some sort of sortable date; either as a number or
(if nothing else) as a string in ISO8601 format.




Its slow in the office today, so: ..

##

from email import Utils
import time

zones = {'CET': '+0100', 'GMT': '', 'EST': '-0500', 'PST': '-0800'}

def get_sortable_time(a_date):
    split_date = a_date.split()

    split_time =
split_date[3].split(':') 
# split the time
    microsecs = float('0.'+ split_time[-1])   # get
the microseconds
    split_date[3] = ':'.join(split_time[:-1])   
# join time, without microseconds 
    
    split_date[4] = zones[split_date[4]]     # convert
the timezone to '-0800' format
    split_date = ' '.join(split_date) 
# eg "Mon Dec 19 11:06:12 +0100 2005"

    gmt_time_as_num =
Utils.mktime_tz(Utils.parsedate_tz(split_date) )   # eg 1134993972.0

    return gmt_time_as_num + microsecs #
time in GMT,  eg 1134993972.33 
    
sortable_time = get_sortable_time( "Mon Dec 19 11:06:12:333 CET 2005"
)

print sortable_time          # = 1134993972.33 
(in time.time() format )

print
time.ctime(sortable_time) 
# Mon Dec 19 12:06:12 2005




##




You could remove the 2 "microsecs" references if you don't need that
level of granularity

 HTH :)



 








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

Re: Python IMAP4 Memory Error

2005-12-23 Thread Fredrik Lundh
Jean-Paul Calderone wrote:

> >On a second trial, it's also failed on Python 2.3.5 for Windows, Python
> >2.3.3 for Windows, and Python 2.2.3 for Windows. So this seems to me as
> >a Windows system related bug, not a particular version of Python bug.
>
> Arguably, it's a bug in Python's imaplib module.  Sure, the Windows memory
> allocator is feeble and falls over when asked to do perfectly reasonable 
> things.

if you look at the debug output (which you may already have done),
it's an obvious case of fragmentation-inducing behaviour.  any malloc-
based system may choke on the sequence

for a large number of attempts:
allocate a 15 megabyte block
shrink block to a couple of kilobytes
occasionally allocate a medium-sized block

from what I can tell, replacing the

data = self.sslobj.read(size-read)

line with

data = self.sslobj.read(min(size-read, 16384))

should do the trick.





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


Re: newbie: concatenate literals (using jython)

2005-12-23 Thread razornl
Note that
"getListenPort()" returns an int.  Is that a problem?

yes, that's a problem. Python needs strings for concatenation
apparently. you can use the .toString() methon on the int to convert it
to a string ;)

a=1
s='hello'
print s+a

TypeError: __add__ nor __radd__ defined for these operands


print s+a.toString()
hello1

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


email package and line ending

2005-12-23 Thread Manlio Perillo
Regards.

The problem is this code:

 >>> import email.Message
 >>> msg = email.Message.Message()
 >>> msg["subject"] = "email bug"
 >>> msg["from"] = "Manlio Perillo"
 >>> print repr(msg.as_string())
'subject: email bug\nfrom: Manlio Perillo\n\n'


Why line ending is '\n' and not '\r\n' ?
RFC 2822 says that the delimiter must(?) be '\r\n'.

The same problem is presente in email.Generator and email.Header (for 
multiline headers).


P.S.
email.Header has a bug:

this code causes an infinite recursion:

 >>> from email.Header import Header
 >>> h = Header('multiline header', 'iso-8859-1', maxlinelen=4)
 >>> e.encode()




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


questions about locale and Windows

2005-12-23 Thread Manlio Perillo
Regards.

I have a few questions about locale handling on Windows.

The first: why getlocale() returns (None, None) when the locale is 'C'?

The second is: why this code fails?:

 >>> loc, enc = locale.getdefaultlocale()
 >>> print loc, enc
it_IT cp1252
 >>> locale.setlocale(locale.LC_ALL, (loc, enc))

Traceback (most recent call last):
   File "", line 1, in -toplevel-
 locale.setlocale(locale.LC_ALL, (loc, enc))
   File "C:\Python2.4\lib\locale.py", line 381, in setlocale
 return _setlocale(category, locale)
Error: unsupported locale setting


Fortunately
 >>> locale.setlocale(locale.LC_ALL, '')
'Italian_Italy.1252'

and
locale.setlocale(locale.LC_ALL)
'C'

works...



Thanks  Manlio Perillo
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to check if a string "is" an int?

2005-12-23 Thread Fredrik Lundh
Grant Edwards wrote:

> > So? the isdigit method tests whether all characters are digits.
> >
>  '15'.isdigit()
> > True
>
> But that is "obviously" wrong, since '15' is not a digit.

no, but all characters in the string belongs to the "digit" character
class, which is what the "is" predicates look for.

cf.

>>> "\t".isspace()
True
>>> "Life of Brian".istitle()
False
>>> u"\N{GREEK CAPITAL LETTER BETA}".isalpha()
True

and so on.





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


why does Py_Finalize() always crashes?

2005-12-23 Thread Moon In Pale

I used Python as embeded in C++ program, which is made up of a EXE and a 
DLL. Py_Initialize() and Py_Finalize() are put in DllMain().
But everytime after the program starts, an "Access Violation" will be 
thrown. I looked up the Assembly code, the crash appears after 
Py_Finalize() returns:
 }else if(dwReason == DLL_PROCESS_DETACH){1000B4B9  test    
eax,eax 1000B4BB  
jne DllMain+23h (1000B4C3h) 
  Py_Finalize();1000B4BD  call    
dword ptr [__imp__Py_Finalize (1000E1A0h)] 
 } return true;1000B4C3  
mov 
al,1    
<-- 0xC005 thrown by 
here}1000B4C5  
ret 0Ch  
 
What may be the probable reason that caused this error? Thank 
you:)
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: How to check if a string "is" an int?

2005-12-23 Thread Paul Rubin
"Fredrik Lundh" <[EMAIL PROTECTED]> writes:
> no, but all characters in the string belongs to the "digit" character
> class, which is what the "is" predicates look for.

That description is not quite right.  All characters in the empty
string belong to the "digit" character class, but isdigit returns
false (which it probably should).

Python 2.3.4 (#1, Feb  2 2005, 12:11:53)
[GCC 3.4.2 20041017 (Red Hat 3.4.2-6.fc3)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> ''.isdigit()
False
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to check if a string "is" an int?

2005-12-23 Thread Fredrik Lundh
Paul Rubin wrote:

> That description is not quite right.  All characters in the empty
> string belong to the "digit" character class

A: are there any blue cars on the street?
B: no.  not a single one.
A: you're wrong! all cars on the street are blue!
B: no, the street is empty.
A: yeah, so all the cars that are on the street are blue!
B: oh, please.
A: admit that you're wrong! admit that you're wrong! admit that you're 
wrong!
*smack*
B: (muttering) moron.





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


Desc of packages for XML processing

2005-12-23 Thread ankit
There are various packages availaible for XML processing using python.
So which to choose and when. I summarized some of the features,
advantages and disadvantages of some packages int the following text.
Have a look to it. May this get out of the dillema of choice.

Here we go:

OPTIONS
=
- libxml2
- lxml
- Pyxml
- 4Suite



DESCRIPTION
=


---
libxml2
---
A quote by Mark Pilgrim: "Programming with libxml2 is like the
thrilling embrace of an exotic stranger. It seems to have the potential
to fulfill your wildest dreams, but there's a nagging voice somewhere
in  your head warning you that you're about to get screwed in the worst
way."

Features:
=
  - Namespaces in XML
  - XPath, Xpointer, XInclude XML Base
  - XML Schemas Part 2 : DataTypes
  - Relax NG
  - SAX: a SAX2 like interface and a minimal SAX1 implementation
compatible
with early expat versions
  - NO DOM:  It provide support for DOM to some extent BUT it does not

implement the API itself, gdome2 .
  - It is written in plain C, making as few assumptions as possible,
and sticking
 closely to   ANSI C/POSIX for easy embedding.
  - Platform: Linux/Unix/Windows


Advantages
==
  - Standards-compliant XML support.
  - Full-featured.
 - Actively maintained by XML experts.
 - fast. fast! FAST!
 - Stable.

Disadvantages
=
This library already ship with Python bindings, but
these Python bindings have
someproblems:
   - Very low level and C-ish (not Pythonic).
   - Underdocumented and huge, you get lost in them.
   - UTF-8 in API, instead of Python unicode strings.
- Can cause segfaults from Python.
- Have to do manual memory management. As the
library calls are more or
 less an exact mapping on the C API, and thus
require to think about
memory management

   For Those who want ot go for DOM API:
Packages for DOM

- gdome2: gdome2 provides support for dom on top of
libxml2.C-Based
 (http://gdome2.cs.unibo.it/)
- libxml2dom: Other option availabile is libxml2dom.

(http://cheeseshop.python.org/pypi/libxml2dom/0.3.3)
- libxml_domlib:libxml_domlib is a Python extension module that
enables you
   to use the DOM  interface to libxml2

(http://www.rexx.com/~dkuhlman/libxml_domlib.html)


Resources
==
  - http://xmlsoft.org/index.html
  - http://codespeak.net/lxml/intro.html



lxml
-
lxml follows the ElementTree API as much as possible, building it on
top of the native libxml2 tree.

Features

 - lxml provides all above features as of libxml2 but using
ElementTreet API.

Advantages
==
 - Pythonic API.
 - Documented.
 - Use Python unicode strings in API.
 - Safe (no segfaults).
 - No manual memory management


Disadvantages
==
- No DOM support as in libxml2.
- It is in its initial release (latest is lxml 0.7)


Resources
=
- http://codespeak.net/lxml/


--
Pyxml
--
Features
=
 - xmlproc: a validating XML parser.
 - Expat: a fast non-validating parser.
 - sgmlop: a C helper module that can speed-up xmllib.py and
sgmllib.py by a
  factor of 5.
 - PySAX: SAX 1 and SAX2 libraries with drivers for most of the
parsers.
 - 4DOM: A fully compliant DOM Level 2 implementation
 - pulldom: a DOM implementation that supports lazy instantiation of
nodes.
 - marshal: a module with several options for serializing Python
objects to XML


Advantages
==
 - A lot of documentation is availaible and almost all resources and
examples
   based on it.

Disadvantages
=
- No Schema support

Pacakges for Schema(For those who want schema support too)
===
XSV: currently in progress, and provides XML schema Part 1:
Structures.
Dependent on some other pacakage PyLTXML
(http://www.ltg.ed.ac.uk/~ht/xsv-status.html)




---
4Suite
---
  Features:
  =
  - XML,XSLT,XPath,DOM,XInclude,XPointer,XLink,XUpdate,RELAX NG,XML
   Catalogs
  - Platform: Posix, Windows

  Advantages
 
  - As, this provides Relax NG: RELAX NG, a simple schema language for
XML,
   

Detect File System changes

2005-12-23 Thread Lukas Meyer
Hello,

I'm trying to detect changes in a directory. E.g if someone crates a
file, i'll execute another function on this file.

I tried to solve this by creating a loop that permanently checks the
contents of this directory with os.listdir() and compares it with the
one before. But this isn't really working properly.

Can anyone give me a hint to get this working?

best regards,

Lukas

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


Re: Guido at Google

2005-12-23 Thread bearophileHUGS
This topic is discussed on Slashdot too:
http://slashdot.org/articles/05/12/22/1832226.shtml?tid=217

There are some interesting comments, for example from curious Java or
Perl programmers, etc.
Some of them can probably appreciate this:
http://cheeseshop.python.org/pypi/typecheck

Among the noise there is some signal too, there are lists of some
problems of Python. Taking some of those things seriously can be
useful, I think.

Bye,
bearophile

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


Re: Herds of cats (was: Guido at Google)

2005-12-23 Thread Nicola Musatti

Cameron Laird wrote:
> In article <[EMAIL PROTECTED]>,
> Nicola Musatti <[EMAIL PROTECTED]> wrote:
>   .
> >Ah, the closed source days! Back then you could just buy the company
> >and be done with it. Now you have to chase developers one by one all
> >over the world... ;-)
>   .
> You propellor-heads (I write that in all fondness, Nicola) are
> all laughing, but I'm certain that the right elaboration of
> that proposition could make it into the *Harvard Business Review*
> (or *IBM Systems Journal*, which seems to have tilted irreversibly
> in that direction).

I was only half joking, actually. Compare Python to Delphi. If a
company wanted to acquire control over Delphi, they'd try and buy
Borland; to acquire control over Python what are they to do? Well,
hiring Guido and Alex is probably a step in the right direction ;-) but
would it be enough? Programming languages are not the best example, but
if you change it to Mozilla and Opera my argument makes more sense.

> Actually, there's already a considerable literature on how pro-
> grammers are like other nasty professionals in exhibiting more
> loyalty to their community than to their employers.  Generalize
> as desired.

Well, it's still better than PHB's who, in my experience, are only
loyal to themselves and in general have more power to put other
people's jobs at risk than programmers. 

Cheers,
Nicola Musatti

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


Re: How to check if a string "is" an int?

2005-12-23 Thread Paul Rubin
"Fredrik Lundh" <[EMAIL PROTECTED]> writes:
> A: are there any blue cars on the street?
> B: no.  not a single one.
> A: you're wrong! all cars on the street are blue!

B and A are both correct.  It's just logic ;-).
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Detect File System changes

2005-12-23 Thread Fuzzyman
The proper way to do this is to use the facilities provided by the
operating system. This means the solution is going to be different for
different platforms. I've *not* done this before - but certainly for
Windows I've seen discussions about this in this group previously.

The win32 extensions expose this capability for windows. I hope this
helps your googling.

All the best,

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

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


Re: How to check if a string "is" an int?

2005-12-23 Thread Duncan Booth
Fredrik Lundh wrote:

> no, but all characters in the string belongs to the "digit" character
> class, which is what the "is" predicates look for.
> 

then gave examples including:

 "Life of Brian".istitle()
> False

I don't see how istitle() matches your definition of what the "is" 
predicates look for.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Detect File System changes

2005-12-23 Thread Noah
In the UNIX world the common tool is FAM -- File Allocation Monitor.
This is a daemon that will report filesystem changes to clients.
There is a Python interface to libfam called "Python FAM" here:
http://python-fam.sourceforge.net/
It looks mature, but I have never used it.

There are also some alternatives to FAM, but I don't remember the names
of them right now.

Yours,
Noah

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


Some errors when running code in diveintopython: (

2005-12-23 Thread iclinux
Environment:
WinXP SP2 + Python 2.4.2, with SOAPpy-0.11.6.zip, fpconst-0.7.2.zip,
and  PyXML-0.8.4.win32-py2.4.exe installed.

Problem:
I'm reading DiveIntoPython these days. When running code of "Example
12.11. Calling A Web Service Through A WSDL Proxy", I got some errors
as follow. Will you please give me some suggestion?

IDLE 1.1.2's Output:
>>> from SOAPpy import WSDL
>>> wsdlFile = 'http://www.xmethods.net/sd/2001/TemperatureService.wsdl'
>>> server = WSDL.Proxy(wsdlFile)
>>> server.methods.keys()
[u'getTemp']
>>> server.getTemp('90210')

Traceback (most recent call last):
  File "", line 1, in -toplevel-
server.getTemp('90210')
  File "E:\Program Files\Python\Lib\site-packages\SOAPpy\Client.py",
line 453, in __call__
return self.__r_call(*args, **kw)
  File "E:\Program Files\Python\Lib\site-packages\SOAPpy\Client.py",
line 475, in __r_call
self.__hd, self.__ma)
  File "E:\Program Files\Python\Lib\site-packages\SOAPpy\Client.py",
line 347, in __call
config = self.config)
  File "E:\Program Files\Python\Lib\site-packages\SOAPpy\Client.py",
line 187, in call
r.endheaders()
  File "E:\Program Files\Python\lib\httplib.py", line 795, in
endheaders
self._send_output()
  File "E:\Program Files\Python\lib\httplib.py", line 676, in
_send_output
self.send(msg)
  File "E:\Program Files\Python\lib\httplib.py", line 643, in send
self.connect()
  File "E:\Program Files\Python\lib\httplib.py", line 611, in connect
socket.SOCK_STREAM):
gaierror: (11001, 'getaddrinfo failed')
>>>

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


Some errors when running code in diveintopython: (

2005-12-23 Thread iclinux
Environment:
WinXP SP2 + Python 2.4.2, with SOAPpy-0.11.6.zip, fpconst-0.7.2.zip,
and  PyXML-0.8.4.win32-py2.4.exe installed.

Problem:
I'm reading DiveIntoPython these days. When running code of "Example
12.11. Calling A Web Service Through A WSDL Proxy", I got some errors
as follow. Will you please give me some suggestion?

IDLE 1.1.2's Output:
>>> from SOAPpy import WSDL
>>> wsdlFile = 'http://www.xmethods.net/sd/2001/TemperatureService.wsdl'
>>> server = WSDL.Proxy(wsdlFile)
>>> server.methods.keys()
[u'getTemp']
>>> server.getTemp('90210')

Traceback (most recent call last):
  File "", line 1, in -toplevel-
server.getTemp('90210')
  File "E:\Program Files\Python\Lib\site-packages\SOAPpy\Client.py",
line 453, in __call__
return self.__r_call(*args, **kw)
  File "E:\Program Files\Python\Lib\site-packages\SOAPpy\Client.py",
line 475, in __r_call
self.__hd, self.__ma)
  File "E:\Program Files\Python\Lib\site-packages\SOAPpy\Client.py",
line 347, in __call
config = self.config)
  File "E:\Program Files\Python\Lib\site-packages\SOAPpy\Client.py",
line 187, in call
r.endheaders()
  File "E:\Program Files\Python\lib\httplib.py", line 795, in
endheaders
self._send_output()
  File "E:\Program Files\Python\lib\httplib.py", line 676, in
_send_output
self.send(msg)
  File "E:\Program Files\Python\lib\httplib.py", line 643, in send
self.connect()
  File "E:\Program Files\Python\lib\httplib.py", line 611, in connect
socket.SOCK_STREAM):
gaierror: (11001, 'getaddrinfo failed')
>>>

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


Re: Some errors when running code in diveintopython: (

2005-12-23 Thread Fredrik Lundh
[EMAIL PROTECTED] wrote:

> I'm reading DiveIntoPython these days. When running code of "Example
> 12.11. Calling A Web Service Through A WSDL Proxy", I got some errors
> as follow. Will you please give me some suggestion?

> gaierror: (11001, 'getaddrinfo failed')

this usually means that your computer (or your nameserver) have problems
looking up the host name.  it's not a python problem.

have you checked your firewall settings (and/or firewall logs) ?

can you reach www.xmethods.net and services.xmethods.net from your
browser?

what happens if you do

>>> import socket
>>> socket.getaddrinfo("www.xmethods.net", 80)
>>> socket.getaddrinfo("services.xmethods.net", 80)

?





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


Re: Guido at Google

2005-12-23 Thread elegans
Of the three languages, Java, C# and Python, Python is my pet. c# is
very 90tyish and VS is showing it's age reminding me of Borland's
old c++ IDE.
Python represents the new direction in program language development and
has the needed flexibility.
I look forward to Google making Python, or it's sister into the next
industry standard. With 30 years of programming behind me, I have
always been fascinated by the gap between practice, wisdom and formal
programming language development, Python has narrowed the gap better
than most.

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


Re: sorting with expensive compares?

2005-12-23 Thread Kent Johnson
[EMAIL PROTECTED] wrote:
> Dan Stromberg wrote:
>>Python appears to have a good sort method, but when sorting array elements
>>that are very large, and hence have very expensive compares, is there some
>>sort of already-available sort function that will merge like elements into
>>a chain, so that they won't have to be recompared as many times?
> 
> Sounds like DSU time.
> 
> [a] -> [ (hash(a), a) ]

This won't work - elements with different hashes will sort by hash and 
elements with the same hash will still be compared which is exactly what 
the OP is trying to avoid.

If there is some function of the arrays which sorts in the same order as 
the natural comparison then that function can be used as a sort key.
sort(arrayList, key=some_proxy_function)

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


Re: Guido at Google

2005-12-23 Thread Bengt Richter
On 22 Dec 2005 23:06:43 -0800, "Anand" <[EMAIL PROTECTED]> wrote:

My newsreader automatically (and configurably) generates the above line.
Has a new reader come into frequent use that by default does not?
ISTM that I've seen a lot of unattributed quotes posted recently.

>> It's like having James Bond as your very own personal body guard ;)
>
>That is such a nice quote that I am going to put it in my email
>signature ! :)
>
>-Anand
>
Maybe look into fixing the above problem while you're at it?

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


Re: Some errors when running code in diveintopython: (

2005-12-23 Thread iclinux
I can visit those two websites above, but when I run your code, I get
those errors(BTW,I have closed my firewall
):

>>> import socket
>>> socket.getaddrinfo("www.xmethods.net", 80)

Traceback (most recent call last):
  File "", line 1, in -toplevel-
socket.getaddrinfo("www.xmethods.net", 80)
gaierror: (11001, 'getaddrinfo failed')
>>> socket.getaddrinfo("services.xmethods.net", 80)

Traceback (most recent call last):
  File "", line 1, in -toplevel-
socket.getaddrinfo("services.xmethods.net", 80)
gaierror: (11001, 'getaddrinfo failed')
>>> 

what can I do?

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


Re: "Humane" programmer interfaces

2005-12-23 Thread Kent Johnson
Dave Benjamin wrote:
> There's been a lot of discussion lately regarding Ruby and the notion of 
> a "humane" interface to objects like arrays and maps, as opposed to
> "minimalist" ones. I believe the article that started the debates was 
> this one by Martin Fowler:
> 
> http://www.developertesting.com/archives/month200512/20051218-HumaneInterfaceOfMinimalInterface.html
>  
> 
> 
> And this one was posted in response by Bruce Eckel:
> 
> http://www.artima.com/forums/flat.jsp?forum=106&thread=141312

It was actually Elliotte Rusty Harold's response to Martin Fowler that 
kicked of the discussion. The first one is here, there are several 
followups:
http://www.cafeaulait.org/oldnews/news2005December6.html

> One last comment I'd like to make is regarding the notion that 
> minimalist and humane are mutually exclusive. This is a false dichotomy. 
> According to Webster:
> 
> Main Entry: minimalism
> Pronunciation: 'mi-n&-m&-"li-z&m
> Function: noun
> 1 : MINIMAL ART
> 2 : a style or technique (as in music, literature, or design) that is 
> characterized by extreme spareness and simplicity
> 
> Main Entry: humane
> Pronunciation: hy-'mAn, y-
> Function: adjective
> Etymology: Middle English humain
> 1 : marked by compassion, sympathy, or consideration for humans or animals
> 2 : characterized by or tending to broad humanistic culture : HUMANISTIC 
> 
> 
> Accepting both of these definitions as (potentially) ideal, we have 
> humane minimalism: a style or technique that is characterized by extreme 
> spareness and simplicity, marked by compassion and sympathy, in 
> consideration of humans. In a world of increasing software complexity, 
> this doesn't sound half bad to me.

ISTM that Python does better than Java or Ruby in finding a sweet spot 
between awkward minimalism (Java) and 
everything-including-the-kitchen-sink generalism (Ruby, at least in the 
List example that is being used so much).

Access to the last element of a list is a great example. Java forces you 
to use the awkward list.get(list.size() - 1). Ruby gives you the 
specialized list.last. Python generalizes to a way to access any index 
from the end, with list[-1] as a concise special case of a general facility.

I think this is one of the great strengths of Python - that those who 
create the language have been able to discover very powerful, general 
concepts and apply them broadly and consistently to solve a variety of 
problems.

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


Re: Desc of packages for XML processing

2005-12-23 Thread Kent Johnson
ankit wrote:
> There are various packages availaible for XML processing using python.
> So which to choose and when. I summarized some of the features,
> advantages and disadvantages of some packages int the following text.
> Have a look to it. May this get out of the dillema of choice.
> 
> Here we go:
> 
> OPTIONS
> =
> - libxml2
> - lxml
> - Pyxml
> - 4Suite

Also ElementTree, Amara

> 
> lxml
> -
>   Disadvantages
>   ==

- No Windows release to date :-(

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


Re: Detect File System changes

2005-12-23 Thread Kent Johnson
Lukas Meyer wrote:
> Hello,
> 
> I'm trying to detect changes in a directory. E.g if someone crates a
> file, i'll execute another function on this file.
> 
> I tried to solve this by creating a loop that permanently checks the
> contents of this directory with os.listdir() and compares it with the
> one before. But this isn't really working properly.
> 
> Can anyone give me a hint to get this working?

We just had a thread on this topic:
http://groups.google.com/group/comp.lang.python/browse_frm/thread/b8808c14ecd333ab/ca7110a9776904eb?rnum=4#ca7110a9776904eb

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


Re: sorting with expensive compares?

2005-12-23 Thread Paul Rubin
Kent Johnson <[EMAIL PROTECTED]> writes:
> > [a] -> [ (hash(a), a) ]
> 
> This won't work - elements with different hashes will sort by hash and
> elements with the same hash will still be compared which is exactly
> what the OP is trying to avoid.

ds = sorted([(hash(c), i) for i,c in enumerate(a)])
dsu = [a[i] for hc,i in ds]

Is that what you mean?  I didn't answer the OP because I couldn't
understand the original question.  The above brings together clusters
of elements with the same hash, so if the clusters are large you can
finish the sort with relatively few comparisons.
-- 
http://mail.python.org/mailman/listinfo/python-list


Vaults of Parnassus hasn't been updated for months

2005-12-23 Thread Wolfgang Grafen
What happened to the Vaults of Parnassus? It was always my
favourite resource for Python code since ever. The latest
entry is now 8/23. It has been up to date for years but now...
What a pity!

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


Re: Some errors when running code in diveintopython: (

2005-12-23 Thread Istvan Albert

must be something with your settings ...

I remeber once I had truly puzzling problem that manifested itself the
same way ... Firefox and cygwin python would work fine but the windows
python would raise errors when trying to connect via http ...

... finally I realized that the day before IE was set to use a proxy
server ( to capture traffic for testing but the proxy was not on that
moment) ... I know little on how Windows works but it was quite a
surprise that setting IE to work some way had some unwanted
reprecussions somewhere else ...

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


Re: File object question

2005-12-23 Thread S. D. Rose
Yes, len() will do what I want.  I didn't realize it would work with binary,
I thought it was good only for variables, lists, etc.

Thanks!
-Dave

"Kent Johnson" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> S. D. Rose wrote:
> > Hello all.
> >   If I read a binary file:
> >
> > file = open('c:\\logo.gif', 'rw'') # Read from FS as one way to get the
> > object, d/l from website another...
> > file.read()
> >
> > is there anyway I can determine the 'size' of the object file? (Without
> > going to the filesystem and reading the filesize from the directory ...)
>
> Once you have read the data you can get the size of that:
> d = file.read()
> print len(d)
>
> Is that what you mean? Otherwise I don't know how you can get the size of
a file without
> asking the filesystem...
>
> Kent
> -- 
> http://mail.python.org/mailman/listinfo/python-list
>



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


Re: Vaults of Parnassus hasn't been updated for months

2005-12-23 Thread Olivier Grisel
Wolfgang Grafen a écrit :
> What happened to the Vaults of Parnassus? It was always my
> favourite resource for Python code since ever. The latest
> entry is now 8/23. It has been up to date for years but now...
> What a pity!

Everybody is using the cheeseshop now:

http://cheeseshop.python.org/pypi?%3Aaction=browse

-- 
Olivier

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


Re: How to check if a string "is" an int?

2005-12-23 Thread Grant Edwards
On 2005-12-23, Fredrik Lundh <[EMAIL PROTECTED]> wrote:
> Grant Edwards wrote:
>
>> > So? the isdigit method tests whether all characters are digits.
>> >
>>  '15'.isdigit()
>> > True
>>
>> But that is "obviously" wrong, since '15' is not a digit.
>
> no, but all characters in the string belongs to the "digit"
> character class, which is what the "is" predicates look for.

I know.  

My point was that '15'.isdigit() returning True is in my
opinion "surprising" since '15' is not a digit in the most
obvious meaning of the phrase.  In language design, "surprise"
is a bad quality.

It's like saying that [1,2,3,4] is an integer.

-- 
Grant Edwards   grante Yow!  Join the PLUMBER'S
  at   UNION!!
   visi.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: print UTF-8 file with BOM

2005-12-23 Thread Kevin Yuan
Sorry, I'm newbie in python. I can't help you further, indeed I don't know either.:)2005/12/23, David Xiao <[EMAIL PROTECTED]>:
Hi Kuan:Thanks a lot! One more question here: How to write if I want tospecify locale other than current locale?For example, running on Korea locale system, and try read a UTF-8 filethat save chinese.
Regards, David2005/12/23, Kevin Yuan <[EMAIL PROTECTED]>:> import codecs> def read_utf8_txt_file (filename):> fileObj = codecs.open
( filename, "r", "utf-8" )> content = fileObj.read()> content = content[1:] #exclude BOM> print content>  fileObj.close()>> read_utf8_txt_file("e:\\u.txt")
>> 22 Dec 2005 18:12:28 -0800, [EMAIL PROTECTED] < [EMAIL PROTECTED]>:> > Hi Friends:> >> > fileObj = 
codecs.open( filename, "r", "utf-8" )> > u = fileObj.read() # Returns a Unicode string from the UTF-8 bytes> in> > the file> > print u> >
> > It says error:> > UnicodeEncodeError: 'gbk' codec can't encode character u'\ufeff'> in> > position 0:> > illegal multibyte sequence> >> > I want to know how read from UTF-8 file, and convert to specified
> > locale (default is current system locale) and print out string. I hope> > put away BOM header automatically.> >> > Rgds, David> >> > --> > 
http://mail.python.org/mailman/listinfo/python-list> >>>
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Detect File System changes

2005-12-23 Thread Lukas Meyer
Hello,

Thank you for your assistance. I could manage it using your link to the
already discussed thread.

best regards,

Lukas

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


Re: print UTF-8 file with BOM

2005-12-23 Thread davihigh
FYI. I had just receive something from a friend, he give me following
nice example!

I have one more question on this: How to write if I want to specify
locale other than current locale? For example, program runn on Korea
locale system, and try reading a UTF-8 file that save chinese
characters.

-- The code is here 
import codecs
def read_utf8_txt_file (filename):
fileObj = codecs.open( filename, "r", "utf-8" )
content = fileObj.read()
content = content[1:] #exclude BOM
print content
fileObj.close()

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


Re: print UTF-8 file with BOM

2005-12-23 Thread Carsten Haese
> 2005/12/23, David Xiao <[EMAIL PROTECTED]>:
> Hi Kuan:
> 
> Thanks a lot! One more question here: How to write if I want
> to
> specify locale other than current locale?
> 
> For example, running on Korea locale system, and try read a
> UTF-8 file
> that save chinese. 

Use the encode method to translate the unicode object into whatever
encoding you want.

unicodeStr = ...
print unicodeStr.encode('big5')

Hope this helps,

Carsten.


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


Re: Guido at Google

2005-12-23 Thread rbt
Anand wrote:
>> It's like having James Bond as your very own personal body guard ;)
> 
> That is such a nice quote that I am going to put it in my email
> signature ! :)
> 
> -Anand
> 

Go right ahead. Perhaps we should do one for Perl too:

It's like having King Kong as your very own personal body guard ;)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: sorting with expensive compares?

2005-12-23 Thread Aahz
In article <[EMAIL PROTECTED]>,
Dan Stromberg  <[EMAIL PROTECTED]> wrote:
>
>Python appears to have a good sort method, but when sorting array
>elements that are very large, and hence have very expensive compares,
>is there some sort of already-available sort function that will merge
>like elements into a chain, so that they won't have to be recompared as
>many times?

I'll just note that Python's sort is specifically designed to reduce the
number of compares precisely because *all* compares in Python are
relatively expensive.  I'll suggest a variant on the previous suggestion
of hash:

[a] -> [hash(a), index(a), a]
-- 
Aahz ([EMAIL PROTECTED])   <*> http://www.pythoncraft.com/

"Don't listen to schmucks on USENET when making legal decisions.  Hire
yourself a competent schmuck."  --USENET schmuck (aka Robert Kern)
-- 
http://mail.python.org/mailman/listinfo/python-list


Logging: Formatter: name of the function

2005-12-23 Thread Gregor Horvath
Hi,

Is there a possibility to format a log message to give the function name 
where the log appears?

Example

import logging

def aTestFunction():
   logger.debug("This is a message")

The log should read:

aTestFunction  This is a message.

There is a possibilty to format the module namewith %(module)s, but I 
did not find one for the function name.

Is there a possibilty or can I create it myself?
How can I determine the function name within a function?
Introspection?

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


urlretrieve() questions

2005-12-23 Thread Rene Lopez
I'm building an app that needs to download a file from the
web.  

I'm trying to make sure I catch any issues with the download
but I've run into a problem. 

here's what I have so far:

try:
urllib.urlretrieve(url,filename)
print "File: ", filename, " downloaded"
except IOError:
print "IOError File Not Found: ", url

Pretty straight forward...but what I'm finding is if the
url is pointing to a file that is not there, the server
returns a file that's a web page displaying a 404 error. 

Anyone have any recommendations for handling this? 
-- 

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


Re: Providing 'default' value with raw_input()?

2005-12-23 Thread planetthoughtful
My intention is to build a GUI for this app, yes, but given that I'm
about a week old in my learning of Python, I thought a command-line app
was a better place to start. I'm actually quite surprised at how
featured I've managed to make this app all things considered, and now
I'm running into things that aren't easy to do in Python (and probably
also not easy to do in any scripting language on a Win machine), as
opposed to not easy for me to work out.

I had thought to build GUIs in wxPython - is Tkinter any easier to
learn?

Much warmth,

planetthoughtful

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


Re: Providing 'default' value with raw_input()?

2005-12-23 Thread planetthoughtful
Thank you for the suggestion, I'll have a look at this as an
alternative.

I must admit, it seems a little like a 'kludge', though -- but probably
a necessary one, given the limitations of the OS.

I'm assuming os.popen() keeps track of when the editor closes? Or would
I have to manually fire an 'ok, now update the record in the db' event
after editing the value?

Much warmth,

planetthoughtful

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


Re: GUI and graph

2005-12-23 Thread Fabrizio Milo
> pydot is pretty amazing in its abilitity to make nice, readable renderings of 
> graph data.
> http://dkbza.org/pydot.html

Well It's thanks to graphwiz..

http://www.research.att.com/sw/tools/graphviz/

I suggest to read the DOT language specification ( it is really easy )
and to roll up your own python script to build your dot file.

Fabrizio Milo aka Misto
-- 
http://mail.python.org/mailman/listinfo/python-list


Have a very Pythonic Christmasolstihanukwanzaa

2005-12-23 Thread infidel
Happy holidays to my fellow Pythonistas.

Love,

Saint Infidel the Skeptic

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


Re: print UTF-8 file with BOM

2005-12-23 Thread John Bauman
UTF-8 shouldn't need a BOM, as it is designed for character streams, and 
there is only one logical ordering of the bytes. Only UTF-16 and greater 
should output a BOM, AFAIK. 


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


Re: GUI and graph

2005-12-23 Thread bearophileHUGS
Maybe this graph library can be useful to you:
http://sourceforge.net/projects/pynetwork/

Bye,
bearophile

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


Re: Some errors when running code in diveintopython: (

2005-12-23 Thread David Wahler
Istvan Albert wrote:
> I remeber once I had truly puzzling problem that manifested itself the
> same way ... Firefox and cygwin python would work fine but the windows
> python would raise errors when trying to connect via http ...
>
> ... finally I realized that the day before IE was set to use a proxy
> server ( to capture traffic for testing but the proxy was not on that
> moment) ... I know little on how Windows works but it was quite a
> surprise that setting IE to work some way had some unwanted
> reprecussions somewhere else ...

See the documentation for urllib.urlopen:

"""
In a Windows environment, if no proxy environment variables are set,
proxy settings are obtained from the registry's Internet Settings
section.
"""

-- David

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


Re: Guido at Google

2005-12-23 Thread David E. Konerding DSD staff
In article <[EMAIL PROTECTED]>, Greg Stein wrote:
> Guido would acknowledge a query, but never announce it. That's not his
> style.
> 
> This should have a positive impact on Python. His job description has a
> *very* significant portion of his time dedicated specifically to
> working on Python. (much more than his previous "one day a week" jobs
> have given him)

Well, given that he's going to be spending his 80% time working on python,
it makes one wonder how he'll be spending his 20% time :-)

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


Re: Detect File System changes

2005-12-23 Thread Lawrence Oluyede
Il 2005-12-23, Lukas Meyer <[EMAIL PROTECTED]> ha scritto:
> Hello,
>
> I'm trying to detect changes in a directory. E.g if someone crates a
> file, i'll execute another function on this file.

pyinotify (wrapper of inotify) is for you (it's not portable however)

http://pyinotify.sourceforge.net/

-- 
Lawrence - http://www.oluyede.org/blog
"Anyone can freely use whatever he wants but the light at the end
of the tunnel for most of his problems is Python"
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Herds of cats

2005-12-23 Thread Alex Martelli
Nicola Musatti <[EMAIL PROTECTED]> wrote:
   ...
> > >Ah, the closed source days! Back then you could just buy the company
> > >and be done with it. Now you have to chase developers one by one all
> > >over the world... ;-)
> > .
> > You propellor-heads (I write that in all fondness, Nicola) are
> > all laughing, but I'm certain that the right elaboration of
> > that proposition could make it into the *Harvard Business Review*
> > (or *IBM Systems Journal*, which seems to have tilted irreversibly
> > in that direction).
> 
> I was only half joking, actually. Compare Python to Delphi. If a
> company wanted to acquire control over Delphi, they'd try and buy
> Borland; to acquire control over Python what are they to do? Well,
> hiring Guido and Alex is probably a step in the right direction ;-) but
> would it be enough? Programming languages are not the best example, but
> if you change it to Mozilla and Opera my argument makes more sense.

Not a bad point at all, although perhaps not entirely congruent to open
source: hiring key developers has always been a possibility (net of
non-compete agreements, but I'm told California doesn't like those).
E.g., Microsoft chose to hire Anders Hejlsberg away from Borland (to
develop J++, the WFC, and later C# and other key parts of dotNet) rather
than buying Borland and adapting Delphi; while acquiring companies is
often also a possibility (e.g., Novell chose to buy SuSE GmbH, rather
than trying to hire specific people off it, despite SuSE's roots in open
source and free software).


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


Re: Providing 'default' value with raw_input()?

2005-12-23 Thread Alex Martelli
planetthoughtful <[EMAIL PROTECTED]> wrote:

> Thank you for the suggestion, I'll have a look at this as an
> alternative.
> 
> I must admit, it seems a little like a 'kludge', though -- but probably
> a necessary one, given the limitations of the OS.

Hmmm, what OS?  The recipe I mentioned is probably the best approach on
Windows, MacOS, Linux, and other Unix variants -- what other OS do you
have in mind, that would let you submit to the user hundreds of
characters for editing without in fact using an editor?

> I'm assuming os.popen() keeps track of when the editor closes? Or would

It has to, because it needs to supply all the subprocess's output as the
contents of the file object it returns, and it couldn't be sure it has
all of the output until the subprocess has finished.  There are, of
course, other ways to control sub-processes (Python 2.4's subprocess
module, in particular).

> I have to manually fire an 'ok, now update the record in the db' event
> after editing the value?

In some situations it may be impractical to rely on the editor closing;
for example, the user's favorite editor might be a multitab one that's
big, heavy, and slow to start, so that the user doesn't close the whole
process but rather just a specific tab.  In such cases, unless you can
build in some hook specific to the user's favorite editor (so you can
know when a specific tab/file is done getting edited), you may end up
requiring the user to press enter at your prompt to indicate he or she's
done editing, or some such semi-kludge.  I cannot think of a
sufficiently general solution, given the variety of editors around, to
just magically divine the crucial "done with editing" condition...


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


Re: print UTF-8 file with BOM

2005-12-23 Thread Walter Dörwald
John Bauman wrote:

> UTF-8 shouldn't need a BOM, as it is designed for character streams, and 
> there is only one logical ordering of the bytes. Only UTF-16 and greater 
> should output a BOM, AFAIK. 

However there's a pending patch (http://bugs.python.org/1177307) for a 
new encoding named utf-8-sig, that would output a leading BOM on writing 
and skip it on reading.

Bye,
Walter Dörwald
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Logging: Formatter: name of the function

2005-12-23 Thread Bengt Richter
On Fri, 23 Dec 2005 16:23:57 +0100, Gregor Horvath <[EMAIL PROTECTED]> wrote:

>Hi,
>
>Is there a possibility to format a log message to give the function name 
>where the log appears?
>
>Example
>
>import logging
>
>def aTestFunction():
>   logger.debug("This is a message")
>
>The log should read:
>
>aTestFunction  This is a message.
>
>There is a possibilty to format the module namewith %(module)s, but I 
>did not find one for the function name.
>
>Is there a possibilty or can I create it myself?
>How can I determine the function name within a function?
>Introspection?
>
There's not a nice way that I know of, but you can do something like

 >>> import sys
 >>> def foo():
 ... print 'logger string containing function name 
"%s"'%sys._getframe().f_code.co_name
 ...
 >>> foo()
 logger string containing function name "foo"

However, you might want to consider using a decorator that could
wrap a function if debugging and leave it alone otherwise. Also you
can log before and after calling the function. E.g.,

 >>> def debugdeco(f):
 ... if not __debug__: return f
 ... def wrap(*args, **kw):
 ... print 'before entering function "%s" ...'%f.func_name
 ... result = f(*args, **kw)
 ... print 'after returning from function "%s" ...'%f.func_name
 ... return result
 ... wrap.func_name = f.func_name # make it look the same if desired
 ... return wrap
 ...
 >>> @debugdeco
 ... def foo(something): print something; return 'whatever'
 ...
 >>> foo('hello')
 before entering function "foo" ...
 hello
 after returning from function "foo" ...
 'whatever'
 >>> __debug__ = False
   File "", line 1
 SyntaxError: can not assign to __debug__

Oops, can't experiment that way ;-)
 >>> ^Z

We'll just start it with -O to set __debug__ False:
 
 [ 8:45] E:\Info\Politics>py24 -O
 Python 2.4b1 (#56, Nov  3 2004, 01:47:27)
 [GCC 3.2.3 (mingw special 20030504-1)] on win32
 Type "help", "copyright", "credits" or "license" for more information.
 >>> def debugdeco(f):
 ... if not __debug__: return f
 ... def wrap(*args, **kw):
 ... print 'before entering function "%s" ...'%f.func_name
 ... result = f(*args, **kw)
 ... print 'after returning from function "%s" ...'%f.func_name
 ... return result
 ... wrap.func_name = f.func_name # make it look the same if desired
 ... return wrap
 ...
 >>> @debugdeco
 ... def foo(something): print something; return 'whatever'
 ...
 >>> foo('hello')
 hello
 'whatever'

You could still do stuff unconditionally of course, and also inside foo.

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


Re: Guido at Google

2005-12-23 Thread Luis M. González

rbt wrote:
> Go right ahead. Perhaps we should do one for Perl too:
>
> It's like having King Kong as your very own personal body guard ;)

Good analogy:
You know, they call Perl the "eight-hundred-pound gorilla" of scripting
languages.
Although most of the time, it would be a a very unsuitable body guard
(can't get into a car, into a plane, go to a party, etc..).

OTHOH James Bond is always perfect. He would sleep with your wife
though...

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


Re: What is unique about Python?

2005-12-23 Thread D H
Kay Schluehr wrote:
> gsteff wrote:
> 
> 
>>So I'm wondering, what is
>>innovative about Python, either in its design or implementation?  Or is
>>its magic really just in combining many useful features of prior
>>languages in an unusually pleasant way?
>>
>>Greg
> 
> 
> The latter.
> 
> http://www.python-in-business.org/ep2005/download.cpy?document=8599
> 
> As Guido described in his presentation Python is a decendent of ABC
> developed at the university where he studied.
> 
> Here is some material about the primary motivations of ABC:
> 
> http://homepages.cwi.nl/~steven/abc/language.html
> 
> Python seems to proof that eclecticism can be done right. 

Python has as much resemblance to ABC as an airplane does to a car.
The design principles used by ABC (like colons at the end of lines)
may have a certain justification in the context of ABC, but you cannot
simply transfer that justification to python.
ABC is designed specifically and entirely to be beginner-friendly. 
Python is not.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to get started in GUI Programming?

2005-12-23 Thread D H
Kay Schluehr wrote:
> [EMAIL PROTECTED] wrote:
> 
>>I am trying to learn GUI programming in Python, but have to confess I
>>am finding it difficult.
> 
> 
> Don't do it if you can prevent it.

What kind of helpful advice is that?

> Conclusion: if you are already familiar with BASIC I would just
> continue writing BASIC apps using VisualBasic dotNet, Windows Forms as
> the underlying GUI toolktit and VisualStudio as IDE. Forget the
> coolness factor of the language. Cool people never care a lot what
> other people think. If you finally want to glue assemblys/controls
> together in Python this is still possible with IronPython or
> Python-dotNet ( which is a CPython binding to the CLR, available at
> Zope.org ).

So you recommend VB.NET on comp.lang.python, and then later publicly 
flame me for mentioning boo a year ago, as well as spew FUD about other
languages you don't like.  Doesn't the python community already have 
enough assholes as it is?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to get started in GUI Programming?

2005-12-23 Thread Tim Peters
[D H]
> ...
> Doesn't the python community already have enough assholes as it is?

The Python Software Foundation may well wish to fund a study on that. 
Write a proposal!  My wild-ass guess is that, same as most other Open
Source communities, we average about one asshole per member.  I'd love
to proven wrong, though.

at-my-age-you-need-all-the-evacuation-routes-you-can-get-ly y'rs  - tim
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python IMAP4 Memory Error

2005-12-23 Thread Dody Suria Wijaya
like magic it did the trick :D

This should be applied to future Python release. Thanks.

Fredrik Lundh wrote:
> Jean-Paul Calderone wrote:
> if you look at the debug output (which you may already have done),
> it's an obvious case of fragmentation-inducing behaviour.  any malloc-
> based system may choke on the sequence
> 
> for a large number of attempts:
> allocate a 15 megabyte block
> shrink block to a couple of kilobytes
> occasionally allocate a medium-sized block
> 
> from what I can tell, replacing the
> 
> data = self.sslobj.read(size-read)
> 
> line with
> 
> data = self.sslobj.read(min(size-read, 16384))
> 
> should do the trick.

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


Re: Herds of cats

2005-12-23 Thread Steve Holden
Alex Martelli wrote:
> Nicola Musatti <[EMAIL PROTECTED]> wrote:
>...
> 
Ah, the closed source days! Back then you could just buy the company
and be done with it. Now you have to chase developers one by one all
over the world... ;-)
>>>
>>>.
>>>You propellor-heads (I write that in all fondness, Nicola) are
>>>all laughing, but I'm certain that the right elaboration of
>>>that proposition could make it into the *Harvard Business Review*
>>>(or *IBM Systems Journal*, which seems to have tilted irreversibly
>>>in that direction).
>>
>>I was only half joking, actually. Compare Python to Delphi. If a
>>company wanted to acquire control over Delphi, they'd try and buy
>>Borland; to acquire control over Python what are they to do? Well,
>>hiring Guido and Alex is probably a step in the right direction ;-) but
>>would it be enough? Programming languages are not the best example, but
>>if you change it to Mozilla and Opera my argument makes more sense.
> 
> 
> Not a bad point at all, although perhaps not entirely congruent to open
> source: hiring key developers has always been a possibility (net of
> non-compete agreements, but I'm told California doesn't like those).
> E.g., Microsoft chose to hire Anders Hejlsberg away from Borland (to
> develop J++, the WFC, and later C# and other key parts of dotNet) rather
> than buying Borland and adapting Delphi; while acquiring companies is
> often also a possibility (e.g., Novell chose to buy SuSE GmbH, rather
> than trying to hire specific people off it, despite SuSE's roots in open
> source and free software).

The essential difference, it seems to me, is that buying the company 
gets you control over the company's proprietary technologies, whereas 
hiring the developer only gets you access to the development skills of 
the people who've been involved open source developments.

The open source projects remain outwith the control of the company; I 
don't expect Google's employment of Guido to have a significant effect 
on the development directions for Python. I'm happy to say I *do* expect 
  Python's development rate to improve hereafter.

I'm also happy that Google are a significant and public supporter of the 
Python Software Foundation through (among other things) their sponsor 
membership of the Foundation, and their sponsorship of PyCon.

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

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


Re: sorting with expensive compares?

2005-12-23 Thread Dan Stromberg
On Thu, 22 Dec 2005 22:06:42 +, Dan Stromberg wrote:

> 
> Hi folks.
> 
> Python appears to have a good sort method, but when sorting array elements
> that are very large, and hence have very expensive compares, is there some
> sort of already-available sort function that will merge like elements into
> a chain, so that they won't have to be recompared as many times?
> 
> Thanks!

I probably should've been more specific.

I'm wanting to sort a large number of files, like a bunch of output files
from a large series of rsh or ssh outputs on a large series of distinct
machines, a music collection in .ogg format (strictly redistributable and
legally purchased music), a collection of .iso cdrom images (strictly
redistributable and legally purchased software), and so forth.

I'm not sorting the content of each file individually.

I'm treating each file as a potentially very large string, and "sorting
the strings".

I've been using the following compare function, which in short checks, in
order:

1) device number
2) inode number
3) file length
4) the beginning of the file
5) an md5 hash of the entire file
6) the entire file

(If #1 and #2 are identical, then the file must be a hardlink to the other
file.  Also, files that do not have the same length can never be
identical.  And of course these items are generated on demand, making it
frequently possible to avoid doing full-file-length compare on a lot of
files)

However, my program is still doing more #6 comparisons than seems
strictly necessary when I could just toss all the filenames describing
identical files into a list, and avoid re-comparing files with identical
content over and over - I don't want to compare them to each other again
and again), when there are a lot of identical files in the input list.

Thanks!

def __cmp__(self,other):
#   sys.stderr.write('Comparing %s and %s\n' % (self.name, 
other.name))
if verbosity >= 1:
sys.stderr.write('Comparing file_class objects %s and 
%s\n' %
(self.name, other.name))
if self.device == -1:
if verbosity:
sys.stderr.write('Getting stat data for file 
%s\n' % self.name)
result = os.stat(self.name)
self.device = result[stat.ST_DEV]
self.inode = result[stat.ST_INO]
self.size = result[stat.ST_SIZE]
if other.device == -1:
if verbosity:
sys.stderr.write('Getting stat data for file 
%s\n' % other.name)
result = os.stat(other.name)
other.device = result[stat.ST_DEV]
other.inode = result[stat.ST_INO]
other.size = result[stat.ST_SIZE]
if self.device == other.device and self.inode == other.inode:
# same device, same inode, must be identical files 
return 0
if self.length < other.length:
return -1
elif self.length > other.length:
return 1
# if we've reached this point, the files are not hardlinks, and 
their
lengths are identical # so slurp in the prefixes if needed, 
then compare
them if self.prefix == -1:
if verbosity:
sys.stderr.write('Getting prefix for file %s\n' 
% self.name)
file = open(self.name, 'r')
self.prefix = file.read(self.max_prefix_length) 
file.close()
if other.prefix == -1:
if verbosity:
sys.stderr.write('Getting prefix for file %s\n' 
% other.name)
file = open(other.name, 'r')
other.prefix = file.read(self.max_prefix_length) 
file.close()
if self.prefix < other.prefix:
return -1
elif self.prefix > other.prefix:
return 1
# if we've reached this point, we know that: # 1) The files are 
not
hardlinks of each other # 2) They have identical sizes # 3) 
Their
prefixes are identical
# 4) We haven't yet tried doing a cryptographic hash, so 
compute them if
needed, and compare them if self.hash == '':
self.gen_hash()
if other.hash == '':
other.gen_hash()
if self.hash < other.hash:
return -1
elif self.hash > other.hash:
return 1
# if we've reached this point, we know that: # 1) The files are 
not
hardlinks of each other # 2) They have identical sizes # 3) 
Their
prefixes are id

Re: Vaults of Parnassus hasn't been updated for months

2005-12-23 Thread Wolfgang Grafen
 > Everybody is using the cheeseshop now:
 >
 > http://cheeseshop.python.org/pypi?%3Aaction=browse
 >

Everybody excluding me. Looks like a huge pile of cheese thrown above
a table. Sorry, I don't find what I am looking for. Can somebody
explain the improvement over Parnassus for me?

It is not only that Parnassus (http://py.vaults.ca/apyllo.py?a=tree) has
2000+ Entries compared to 673 at the cheeseshop
(http://cheeseshop.python.org/pypi?:action=browse&asdf=214) but its
appearence and user interface is also much better. Where is the
search button, where can I find the latest additions?

Instead I have to scroll over a alphabetical sorted list of 673 items
what I definitely don't like. Invisible unless you scroll to the bottom
of the page there is a grouped/cluttered bunch of links to more specific
collections...

Well, at least I am very upset! This site shows the least possible
implementation of a repository. There are a *lot* books about GUI
design around for years pointing out the does and don't does. Why should
this be an improvement? Why does such a inferiour solution substitute a
already useable solution like Parassus?

I know that setup.py gives the opportunity to registrate a module
automatically there. As long this is used to build up a computer
accessible repository it is a good thing. But just now it is no option
as the user's usability constraints are not met! And the completeness
lacks compared to the Vaults of Parnassus.

I am not a very organized person. Nevertheless, I like to click through
responsive and clearly designed sites. I want to search by means of a
search engine and get relevant hits. Often Google hits were better than
dedicated engines but this changes recently. If this is the new Python way
I cry for the past...

Just a poll: Who misses the Vaults of Parnassus like me?


Olivier Grisel wrote:
> Wolfgang Grafen a écrit :
> 
>> What happened to the Vaults of Parnassus? It was always my
>> favourite resource for Python code since ever. The latest
>> entry is now 8/23. It has been up to date for years but now...
>> What a pity!
> 
> 
> Everybody is using the cheeseshop now:
> 
> http://cheeseshop.python.org/pypi?%3Aaction=browse
> 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: sorting with expensive compares?

2005-12-23 Thread bonono

Dan Stromberg wrote:
> On Thu, 22 Dec 2005 22:06:42 +, Dan Stromberg wrote:
>
> >
> > Hi folks.
> >
> > Python appears to have a good sort method, but when sorting array elements
> > that are very large, and hence have very expensive compares, is there some
> > sort of already-available sort function that will merge like elements into
> > a chain, so that they won't have to be recompared as many times?
> >
> > Thanks!
>
> I probably should've been more specific.
>
> I'm wanting to sort a large number of files, like a bunch of output files
> from a large series of rsh or ssh outputs on a large series of distinct
> machines, a music collection in .ogg format (strictly redistributable and
> legally purchased music), a collection of .iso cdrom images (strictly
> redistributable and legally purchased software), and so forth.
>
> I'm not sorting the content of each file individually.
>
> I'm treating each file as a potentially very large string, and "sorting
> the strings".
>
> I've been using the following compare function, which in short checks, in
> order:
>
> 1) device number
> 2) inode number
> 3) file length
> 4) the beginning of the file
> 5) an md5 hash of the entire file
> 6) the entire file
>
> (If #1 and #2 are identical, then the file must be a hardlink to the other
> file.  Also, files that do not have the same length can never be
> identical.  And of course these items are generated on demand, making it
> frequently possible to avoid doing full-file-length compare on a lot of
> files)
>
> However, my program is still doing more #6 comparisons than seems
> strictly necessary when I could just toss all the filenames describing
> identical files into a list, and avoid re-comparing files with identical
> content over and over - I don't want to compare them to each other again
> and again), when there are a lot of identical files in the input list.
>
Why would #5 not enough as an indicator that the files are indentical ?

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


Re: How to get started in GUI Programming?

2005-12-23 Thread Heiko Wundram
Tim Peters wrote:
> My wild-ass guess is that, same as most other Open
> Source communities, we average [at] about one asshole per member.

Tim, you saved my day. QOTW!

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


Re: urlretrieve() questions

2005-12-23 Thread Dan M
> Pretty straight forward...but what I'm finding is if the
> url is pointing to a file that is not there, the server
> returns a file that's a web page displaying a 404 error. 
> 
> Anyone have any recommendations for handling this?

You're right, that is NOT documented in a way that's easy to find! 

What I was able to find is how to what you want using urllib2 instead of
urllib. I found an old message thread that touches on the topic:
http://groups.google.com/group/comp.lang.python/browse_thread/thread/3f02bee97a689927/88c7bfec87e18ba9?q=%22http+status%22+%2Burllib&rnum=3#88c7bfec87e18ba9
(also accessable as http://tinyurl.com/952dw). Here's a quick summary:
---

Ivan Karajas
Apr 28 2004, 11:03 pm   show options
Newsgroups: comp.lang.python
From: Ivan Karajas <[EMAIL PROTECTED]> - Find messages by this author
Date: Wed, 28 Apr 2004 23:03:54 -0800
Local: Wed, Apr 28 2004 11:03 pm
Subject: Re: 404 errors
Reply to Author | Forward | Print | Individual Message | Show original | Report 
Abuse

On Tue, 27 Apr 2004 10:46:47 +0200, Tut wrote:
> Tue, 27 Apr 2004 11:00:57 +0800, Derek Fountain wrote:

>> Some servers respond with a nicely formatted bit of HTML explaining the
>> problem, which is fine for a human, but not for a script. Is there some
>> flag or something definitive on the response which says "this is a 404
>> error"?

> Maybe catch the urllib2.HTTPError?

This kind of answers the question. urllib will let you read whatever it
receives, regardless of the HTTP status; you need to use urllib2 if you
want to find out the status code when a request results in an error (any
HTTP status beginning with a 4 or 5). This can be done like so:

import urllib2
try:
asock = urllib2.urlopen("http://www.foo.com/qwerty.html";)
except urllib2.HTTPError, e:
print e.code

The value in urllib2.HTTPError.code comes from the first line of the web
server's HTTP response, just before the headers begin, e.g. "HTTP/1.1 200
OK", or "HTTP/1.1 404 Not Found".

One thing you need to be aware of is that some web sites don't behave as
you would expect them to; e.g. responding with a redirection rather than a
404 error when you when you request a page that doesn't exist. In these
cases you might still have to rely on some clever scripting.
--

I hope that helps.

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


Indentation/whitespace

2005-12-23 Thread Joe
Is Python going to support s syntax the does not use it's infamous
whitespace rules? I recall reading that Python might include such a
feature. Or, maybe just a brace-to-indentation preprocessor would be
sufficient.

Many people think Python's syntax makes sense. There are strong
feelings both ways. It must depend on a person's way of thinking,
because I find it very confusing, even after using with Python for some
time, and trying to believe the advice that I would learn to like it.
The most annoying thing is that multiple dedents are very unreadable. I
still don't understand how anybody can think significant-but-invisible
dedentation is a good thing.

Note: No need to follow up with long opinions of why indentation is
good -- they have been posted hundreds of times. It just seems that
Python developers think the whitespace thing is only an issue for
newbies. I think that many experienced users don't learn to like it,
but instead just learn to live with it.

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


Re: sorting with expensive compares?

2005-12-23 Thread Alex Martelli
Dan Stromberg <[EMAIL PROTECTED]> wrote:
   ...
> I'm wanting to sort a large number of files, like a bunch of output files
> from a large series of rsh or ssh outputs on a large series of distinct
> machines, a music collection in .ogg format (strictly redistributable and
> legally purchased music), a collection of .iso cdrom images (strictly
> redistributable and legally purchased software), and so forth.
> 
> I'm not sorting the content of each file individually.
> 
> I'm treating each file as a potentially very large string, and "sorting
> the strings".

OK, very clear.

> I've been using the following compare function, which in short checks, in
> order:
> 
> 1) device number
> 2) inode number
> 3) file length
> 4) the beginning of the file
> 5) an md5 hash of the entire file
> 6) the entire file

Makes sense, including the possibility of computing some items on
demand.  However, using a key-callable rather than a cmp-callable may
still make sense -- you just need a callable that extracts the
attributes on demand (and caches them thereafter... assuming you have
enough memory to keep all the caches, I guess [6] might be a problem).
I do see that key-callables won't necessarily work easily here, but
since the key-callable's __cmp__ will in turn be called, that might
still work better... but, on reflection, it's probably just a minor
gain.

> However, my program is still doing more #6 comparisons than seems
> strictly necessary when I could just toss all the filenames describing
> identical files into a list, and avoid re-comparing files with identical
> content over and over - I don't want to compare them to each other again
> and again), when there are a lot of identical files in the input list.

The comparison should never get called twice on the same two objects,
anyway.  So, I'm not sure what you think you could gain by optimizing
future comparisons of two objects once you've ascertained they are in
fact equal.  Still, assuming for example that self.name is a unique
identifier (i.e. the so-called name is in fact a complete path), the
optimization (memoization) is quite easy to perform.  Rename what you
currently have as __cmp__ by another name, say _real_cmp, add a
_compared dict to the class, and code the following __cmp__ ...:

_compared = {}
def __cmp__(self, other):
try: return -self._compared[other.name, self.name]
except KeyError: pass
key = self.name, other.name
if key in self._compared: return self._compared[key]
result = self_compared[key] = self._real_cmp(other)
return result

I would not expect this optimization to matter at all, because no key
should ever be already present in the self._compared dictionary (the
same two files should never, ever get compared twice anyway).

However, it might be possible to extend this idea by using the
properties you know an ordering should have -- if A and B have never
been compared, but both have been compared with C, in some cases you
don't need to compare A and B but may exploit already-known results.
For example, if A==C and B==C, you already know that A==B without any
actual comparison; if Ahttp://mail.python.org/mailman/listinfo/python-list


Re: Guido at Google

2005-12-23 Thread rbt
Luis M. González wrote:
> rbt wrote:
>> Go right ahead. Perhaps we should do one for Perl too:
>>
>> It's like having King Kong as your very own personal body guard ;)
> 
> Good analogy:
> You know, they call Perl the "eight-hundred-pound gorilla" of scripting
> languages.

Absolutely. It's big, hairy, smelly, a bit dense at times and always
difficult to communicate with, but by god it gets the job done albeit in
a messy sort of way ;)

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


Re: Indentation/whitespace

2005-12-23 Thread Larry Bates
Joe wrote:
> Is Python going to support s syntax the does not use it's infamous
> whitespace rules? I recall reading that Python might include such a
> feature. Or, maybe just a brace-to-indentation preprocessor would be
> sufficient.
> 
> Many people think Python's syntax makes sense. There are strong
> feelings both ways. It must depend on a person's way of thinking,
> because I find it very confusing, even after using with Python for some
> time, and trying to believe the advice that I would learn to like it.
> The most annoying thing is that multiple dedents are very unreadable. I
> still don't understand how anybody can think significant-but-invisible
> dedentation is a good thing.
> 
> Note: No need to follow up with long opinions of why indentation is
> good -- they have been posted hundreds of times. It just seems that
> Python developers think the whitespace thing is only an issue for
> newbies. I think that many experienced users don't learn to like it,
> but instead just learn to live with it.
> 
Characterizing indentation as "invisible" isn't really fair.
It it WAY more visible than a { character. IMHO the
indentation works very well.  I've tried to wade through PHP,
JavaScript, C code that uses those 
brace ({}) blocks until my head hurt, especially if they
didn't indent as well as using the braces.  If they indent
so I can actually read the code, why also use braces to
clutter things up?  I've solved the multiple dedent problem
by inserting a comment that shows where the indented blocks
end (sort of where the ending brace (}) would have been.
I also find that if I'm indenting more than a couple of
levels, I probably need to refactor my code into smaller
objects or rethink the process so that I process collections
of objects.  I've written in many different languages over
a span of 32+ years and it seems to work for me.

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


Re: Indentation/whitespace

2005-12-23 Thread Alex Martelli
Joe <[EMAIL PROTECTED]> wrote:

> Is Python going to support s syntax the does not use it's infamous
> whitespace rules?

No, never (even apart from the "its" vs "it's" issue here...;-).

> I recall reading that Python might include such a
> feature.

And I recall reading that Elvis is still alive and was kidnapped by
aliens, but I don't necessarily believe all that I read.

> Or, maybe just a brace-to-indentation preprocessor would be
> sufficient.

Fine, then write one -- it's not too hard (about an average interview
question for hiring a programmer, I'd say).  As for how to integrate
such a preprocessor with CPython, I would suggest you follow precedent
by allowing an arbitrary "source-code-reading hook" to be optionally
specified by setting sys.preprocessor (and/or via commandline flag,
environment variable, etc -- but, the ability to install the hook from
site-configure.py would probably be sufficient).

You could maybe get 99% of the way there by using the existing "import
hooks" mechanism (the same one that lets you import from zipfiles: it's
designed to be easily extensible), but I don't think that would help
with the "main script" (which doesn't get imported), interactive
interpreter sessions, etc; also, I'm not sure it would easily allow
seamless interoperation with other such hooks (e.g., to let you import
from zipfiles sources that need to be preprocessed).

The main reason I suggest a general-purpose mechanism for the hooking-up
of the preprocessor is that such a mechanism might stand a chance to be
accepted (via the usual PEP procedure), as long as other interesting use
cases can be found; I suspect that if the only use case was "turn braces
into indents/dedents", the PEP would stand no chance.

For example, a small but vocal minority has long campaigned for
non-ASCII characters to be allowed in identifiers; a preprocessor might
be able to do this by translating them into ASCII on the fly (though
that wouldn't necessarily work well with getattr and friends... but
then, neither do 'private' identifiers starting with two underscores;-).

> still don't understand how anybody can think significant-but-invisible
> dedentation is a good thing.

We're even, then, since I can't understand the reverse;-).

> Note: No need to follow up with long opinions of why indentation is
> good -- they have been posted hundreds of times. It just seems that

Respecting your wish, I'm not discussing the issue at all (although, by
trying to make some point AGAINST it, you really make it very hard: if
you don't want such a discussion you shouldn't start one yourself and
then try to impede your opponents from rebutting your points, that is
really an extremely unfair attempt on your part).  I'm pointing you to
ways you might get your wish, if you're willing to do some work for the
purpose. Coding the preprocessor is the easy part -- the work is mostly
in doing the PEP, including a variety of strong use cases for a general
purpose preprocessor.  (Of course, forking Python to hardcode your
preprocessor is easier, but forking always has other problems).


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


Re: sorting with expensive compares?

2005-12-23 Thread Peter Otten
Dan Stromberg wrote:

> I'm wanting to sort a large number of files, like a bunch of output files
> from a large series of rsh or ssh outputs on a large series of distinct
> machines, a music collection in .ogg format (strictly redistributable and
> legally purchased music), a collection of .iso cdrom images (strictly
> redistributable and legally purchased software), and so forth.

Are you really trying to establish an order or do want to eliminate the
duplicates?

>>> File("perfectly_legal.ogg") < File("free_of_charge.mp3")
True

doesn't make that much sense to me, regardless of what the comparison may
actually do.

Peter

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


Re: sorting with expensive compares?

2005-12-23 Thread Steve Holden
[EMAIL PROTECTED] wrote:
> Dan Stromberg wrote:
[...]
>>I've been using the following compare function, which in short checks, in
>>order:
>>
>>1) device number
>>2) inode number
>>3) file length
>>4) the beginning of the file
>>5) an md5 hash of the entire file
>>6) the entire file
[...]
> Why would #5 not enough as an indicator that the files are indentical ?
> 
Because it doesn't guarantee that the files are identical. It indicates, 
to a very high degree of probability (particularly when the file lengths 
are equal), that the two files are the same, but it doesn't guarantee it.

Technically there are in infinite number of inputs that can produce the 
same md5 hash.

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

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


Re: Providing 'default' value with raw_input()?

2005-12-23 Thread Scott David Daniels
planetthoughtful wrote:
> ...
> I had thought to build GUIs in wxPython - is Tkinter any easier to
> learn?

I certainly found Tkinter easier.  There are a couple of good tutorials
(and there is always the Grayson book) on the web to get started.  What
is easiest to learn is (in many cases) a property of the student,
however.  Were I a Linux-only GPL kind of a guy, I think Qt might be
an interesting way to go.  One thing that helps tremendously in learning
Tkinter: using Idle in single-process mode:

 C:\Python24\Python C:\Python24\Lib\idlelib\idle.pyw -n

This is obviously a WinXX example, but the "-n" parameter to idle is
the important part.  Since a single-process Idle is running the Tkinter
GUI loop, you can try operations a step at a time (letting you see what
happens).

--Scott David Daniels
[EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Indentation/whitespace

2005-12-23 Thread Dave Benjamin
Alex Martelli wrote:
> The main reason I suggest a general-purpose mechanism for the hooking-up
> of the preprocessor is that such a mechanism might stand a chance to be
> accepted (via the usual PEP procedure), as long as other interesting use
> cases can be found; I suspect that if the only use case was "turn braces
> into indents/dedents", the PEP would stand no chance.

+1 on the preprocessor idea, especially if it would allow us to hook in 
at the AST level as well. (No comment on the curlies. ;)

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


Re: Some errors when running code in diveintopython: (

2005-12-23 Thread beryan
El Fri, 23 Dec 2005 05:18:30 -0800, iclinux escribió:

> I can visit those two websites above, but when I run your code, I get
> those errors(BTW,I have closed my firewall
> ):
> 
 import socket
 socket.getaddrinfo("www.xmethods.net", 80)
> 
> Traceback (most recent call last):
>   File "", line 1, in -toplevel-
> socket.getaddrinfo("www.xmethods.net", 80)
> gaierror: (11001, 'getaddrinfo failed')
 socket.getaddrinfo("services.xmethods.net", 80)
> 
> Traceback (most recent call last):
>   File "", line 1, in -toplevel-
> socket.getaddrinfo("services.xmethods.net", 80)
> gaierror: (11001, 'getaddrinfo failed')
 
> 
> what can I do?


Have you got a Firewall ?
Take a look over firewall settings and give Python rights for accesing
port 80
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Parsing a date-time string?

2005-12-23 Thread linda.s
Hi,
I got the message of "There was an error in the DDE conversation with
Pythonwin" when I tried to run Pythonwin.
I googled and found the possible solution is:
modify the Pythonwin shortcut to pass a
"/nodde" command-line option.
I got lost how to do that.
Thanks for any help!
-- 
http://mail.python.org/mailman/listinfo/python-list


jython/wlst: How to avoid newlines in output from "cd" command (and others)

2005-12-23 Thread davidmichaelkarr
I'm using WebLogic Scripting Tool, which uses Jython, which uses Python
2.1.  In a script I'm writing, executing a "cd()" always emits a
newline to stdout.  Is there a way to make it not emit that newline on
the "cd()" command (and others like it)?

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


Re: Indentation/whitespace

2005-12-23 Thread Thomas Bartkus
"Joe" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> Is Python going to support s syntax the does not use it's infamous
> whitespace rules? I recall reading that Python might include such a
> feature. Or, maybe just a brace-to-indentation preprocessor would be
> sufficient.
>
> Many people think Python's syntax makes sense. There are strong
> feelings both ways. It must depend on a person's way of thinking,
> because I find it very confusing, even after using with Python for some
> time, and trying to believe the advice that I would learn to like it.
> The most annoying thing is that multiple dedents are very unreadable. I
> still don't understand how anybody can think significant-but-invisible
> dedentation is a good thing.
>
> Note: No need to follow up with long opinions of why indentation is
> good -- they have been posted hundreds of times. It just seems that
> Python developers think the whitespace thing is only an issue for
> newbies. I think that many experienced users don't learn to like it,
> but instead just learn to live with it.

Okay - I'll take your note and not argue about "why indentation is good"

But - why should Python
   "support s syntax the does not use it's infamous whitespace rules"
It's unique to Python. That's what Python *is*.

If one doesn't like it, one needn't waste one's time with it.  No other
other language abides by those rules except Python.

So just choose a different language to work with.
Thomas Bartkus


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


Re: Vaults of Parnassus hasn't been updated for months

2005-12-23 Thread Do Re Mi chel La Si Do
Hi!


>>> Just a poll: Who misses the Vaults of Parnassus like me?

Me   (+1)


@-salutations

Michel Claveau



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


run line or selection

2005-12-23 Thread linda.s
is there any tool like "run line or selection" in Pythonwin?
Thanks!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to call function which is in one program ...

2005-12-23 Thread Shahriar Shamil Uulu
Thank you Fredrik Lundh
for your help ...
it worked ...
the problem was in saving of file first.py
Fredrik Lundh wrote:
> "Shahriar Shamil Uulu" wrote:
>
> > i got another questions. For example i have two programs in python
> > like: first.py, second.py.
> > In first.py i have a function test() like:
> > # first.py
> > ...
> > def test(name):
> >  print name
> >
> >  so other functions
> > =
> >
> > #second.py
> >
> > Question is how i can include first.py into second.py and use function
> > test.py.
>
> # File: second.py
> import first
> first.test()
>
> tips: read a Python tutorial *before* you post your next question.  start 
> here:
> 
> http://www.python.org/doc/Intros.html
> 
> 

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


Re: Indentation/whitespace

2005-12-23 Thread Terry Hancock
On Fri, 23 Dec 2005 11:51:23 -0700
Dave Benjamin <[EMAIL PROTECTED]> wrote:
> +1 on the preprocessor idea, especially if it would allow
> us to hook in  at the AST level as well. (No comment on
> the curlies. ;)

Only +0 on it myself, but I do know of a use-case -- certain
types of web-templating frameworks can be easier to use if
the inserted code can be put on one line.

Some people have been agitating for some way to do this with
Python for some time (on Zope lists), and a preprocessor
would provide a means for them to get what they want.

OTOH, I have been able to manage with the way things are. It
encourages good separation between templates and code, which
is supposed to be a good thing according to the "Zope Zen".
;-)


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

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


pyQt for windows

2005-12-23 Thread relativity
I have downloaded and installed pyQt 3.14 educational but when I run any of 
the examples I get an error saying qt-mtedu333.dll was not found. I have 
also installed the qt4 opensource version for windows but I am not sure 
everything was set up correctly. When I run configure it complains about 
file or folder not found (mingw32-make). I installed mingw with qt. Anyway 
any help would be appreciated. All i want is to be able to use QT on windows 
with python. 


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


Re: sorting with expensive compares?

2005-12-23 Thread Steven D'Aprano
On Fri, 23 Dec 2005 09:20:55 -0800, bonono wrote:

> 
> Dan Stromberg wrote:

[snip]

>> I've been using the following compare function, which in short checks, in
>> order:
>>
>> 1) device number
>> 2) inode number
>> 3) file length
>> 4) the beginning of the file
>> 5) an md5 hash of the entire file
>> 6) the entire file
>>
>> (If #1 and #2 are identical, then the file must be a hardlink to the other
>> file.  Also, files that do not have the same length can never be
>> identical.  And of course these items are generated on demand, making it
>> frequently possible to avoid doing full-file-length compare on a lot of
>> files)
>>
>> However, my program is still doing more #6 comparisons than seems
>> strictly necessary when I could just toss all the filenames describing
>> identical files into a list, and avoid re-comparing files with identical
>> content over and over - I don't want to compare them to each other again
>> and again), when there are a lot of identical files in the input list.
>
> Why would #5 not enough as an indicator that the files are indentical ?

(1) Because the MD5 algorithm does include collisions. I was going to say
"rare collisions", but there is actually an infinite number of them. The
collisions are just distributed thinly -- because MD5 is a good hash
algorithm, *very* thinly.

(Proof of this comes from the pigeon-hole principle: there is an infinite
number of possible files of arbitrary length, and only a finite number of
possible hashes. Therefore, an infinite number of files must hash to each
possible hash.)

(2) Having said that, unless the original poster is dealing with billions
(plus) of files, it is unlikely that he is finding any of the collisions
unless there is a bug in his sort routine. Since he claims to be doing
more comparisions-by-file-contents than expected (I would suggest *one*
is more than expected), I predict a bug in his code, his algorithm, or
both.


-- 
Steven.

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


query on csv file reading and replacing

2005-12-23 Thread muttu2244
Hi everybody

Am trying to read a csv file "temp.csv", which has the below info,


compName   macAddripAddr
opSys

Chris-Dev 0003469F44CC  10.160.24.226   Microsoft Windows XP
Professional
Shivayogi-Dev  000D5234F44C 10.160.24.136   Microsoft Windows XP
Professional
John-test 000D123F44CC  10.160.24.216   Microsoft Windows XP
Professional Steve-Dev000D123F55CC  10.160.24.116   Microsoft
Windows XP Professional

am trying to read it in the following way--

>>> import csv
>>> infoFile = open ('c:\\temp.csv','r')
>>> rdr = csv.reader(infoFile)
>>> for row in rdr:
... if row[0] == infnList[0]:
... if not row[1] == infnList[1] or not row[2] == infnList[2]:

now am comparing my comp Name  with the "compName" fields, and if it
matches i ll then compare for the "mac address" and "ip address". if
they are not matching with my system, i have to modify them there
itself, i mean i have to update "mac address" and "ip address" in the
same row itself, i dont want to append the information with another row
to the "temp.csv" file. otherwise it will have two similar computer
names for two rows, which i dont want to happen.

please give me the ways how i can work on this.

thanks in advance
yogi

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


Re: Herds of cats

2005-12-23 Thread Mike Meyer
Steve Holden <[EMAIL PROTECTED]> writes:
> Alex Martelli wrote:
>> Not a bad point at all, although perhaps not entirely congruent to
>> open
>> source: hiring key developers has always been a possibility (net of
>> non-compete agreements, but I'm told California doesn't like those).

California places pretty strict limits on non-compete agreements. I
was at Ingres when their parent company - ASK - got bought by CA. CA
required people choosing to leave the company to sign an agreement
that included *their* standard non-compete clause before getting the
separation cash. Enough people left that found this clause irritating
that it got take to multiple lawyers. Every last one of them declared
it unenforceable in CA.

> The essential difference, it seems to me, is that buying the company
> gets you control over the company's proprietary technologies, whereas
> hiring the developer only gets you access to the development skills of
> the people who've been involved open source developments.

But it's not at all clear which of these is the more desirable
outcome. CA bought ASK to get control of Ingres, which their Unicenter
product used as a database. The *entire* server software development
group left, meaning CA had all the sources and technologies, but none
of the talent that created them. We called this the $300 million
source license.

CA pretty clearly got screwed on this deal. They have since
open-sourced the Ingres product.

 http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: sorting with expensive compares?

2005-12-23 Thread Steven D'Aprano
On Fri, 23 Dec 2005 19:26:11 +0100, Peter Otten wrote:

> Dan Stromberg wrote:
> 
>> I'm wanting to sort a large number of files, like a bunch of output files
>> from a large series of rsh or ssh outputs on a large series of distinct
>> machines, a music collection in .ogg format (strictly redistributable and
>> legally purchased music), a collection of .iso cdrom images (strictly
>> redistributable and legally purchased software), and so forth.
> 
> Are you really trying to establish an order or do want to eliminate the
> duplicates?
> 
 File("perfectly_legal.ogg") < File("free_of_charge.mp3")
> True
> 
> doesn't make that much sense to me, regardless of what the comparison may
> actually do.

If I have understood the poster's algorithm correctly, it gets even
weirder:


Sorted list of files ->

[parrot.ogg, redhat.iso, george.log, fred.log, rhino.ogg, cat.ogg,
debian.iso, sys_restore.iso, adrian.log, fox.ogg, ...]

It seems to this little black duck that by sorting by file contents in
this way, the effect to the human reader is virtually to randomise the
list of file names.

Even if you limit yourself to (say) a set of ogg files, and sort by the
binary contents ->

# album-track
[parrot-6.ogg, rhino-1.ogg, cat-12.ogg, fox-2.ogg, parrot-3.ogg, ...]

most people looking at the list would guess it had been shuffled, not
sorted. So I too don't know what the original poster hopes to accomplish
by sorting on the content of large binary files.



-- 
Steven.

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


Re: print UTF-8 file with BOM

2005-12-23 Thread Martin v. Löwis
John Bauman wrote:
> UTF-8 shouldn't need a BOM, as it is designed for character streams, and 
> there is only one logical ordering of the bytes. Only UTF-16 and greater 
> should output a BOM, AFAIK. 

Yes and no. Yes, UTF-8 does not need a BOM to identify endianness. No,
usage of the BOM with UTF-8 is explicitly allowed in the Unicode specs
(so output of the BOM doesn't *have* to be restricted to UTF-16 and
greater), and the BOM has a well-defined meaning for UTF-8 (namely,
as the UTF-8 signature).

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


Re: Logging: Formatter: name of the function

2005-12-23 Thread Sylvain Defresne
Le vendredi 23 décembre 2005 à 16:23 +0100, Gregor Horvath a écrit :
> Hi,
> 
> Is there a possibility to format a log message to give the function name 
> where the log appears?
> 
> Example
> 
> import logging
> 
> def aTestFunction():
>logger.debug("This is a message")
> 
> The log should read:
> 
> aTestFunction  This is a message.

You can use the currentframe of the inspect module. For example :

>>> import inspect
>>> def debug(string):
... frame = inspect.currentframe(1)
... print frame.f_code.co_name, string
>>> def a_test_function():
... debug("This is a message")
>>> a_test_function()
a_test_function This is a message

But please take note that this is not recommended. As stated in the
documentation of inspect.currentframe : "[t]his function should be used
for internal and specialized purposes only."
-- 
A: Because it messes up the order in which people normally read text.
Q: Why is it 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

Re: What is unique about Python?

2005-12-23 Thread Max
gsteff wrote:
> I'm a computer science student, and have recently been trying to
> convince the professor who teaches the programming language design
> course to consider mentioning scripting languages in the future.  Along
> those lines, I've been trying to think of features of Python, and
> scripting languages in general, that can't be found in older languages,
> and have been having a surprising amount of trouble.  Dynamic typing
> can be found in Smalltalk, the module concept can be found in Ada,
> functional parameters and the dynamic creation of functions can be
> found in Lisp.  The indentation-based syntax seems to be unique, but
> that's not really what I'm looking for.  So I'm wondering, what is
> innovative about Python, either in its design or implementation?  Or is
> its magic really just in combining many useful features of prior
> languages in an unusually pleasant way?
> 
> Greg
> 

I find that development in python is much faster than anything else. But 
one of the noticeable features, for me and presumably computer science 
students, is the pseudocode-python translation: I've been working 
through a CS textbook to train for the IOI, and noticed how much my 
python implementations look like the textbook's pseudocode (whereas the 
C++ versions look nothing like the pcode).

If anything, python is _more_ expressive - where list comprehensions and 
generators are the natural way of doing things, the textbook has to 
kludge because its target audience is C++, Java and Pascal programmers.

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


Re: sorting with expensive compares?

2005-12-23 Thread Paul Rubin
Dan Stromberg <[EMAIL PROTECTED]> writes:
> I've been using the following compare function, which in short checks, in
> order:
> 
> 1) device number
> 2) inode number
> 3) file length
> 4) the beginning of the file
> 5) an md5 hash of the entire file
> 6) the entire file
> 
> (If #1 and #2 are identical, then the file must be a hardlink to the other
> file.  Also, files that do not have the same length can never be
> identical.  And of course these items are generated on demand, making it
> frequently possible to avoid doing full-file-length compare on a lot of
> files)
> 
> However, my program is still doing more #6 comparisons than seems

Just don't do any #6 comparisons.  If the hashes are identical, the
files are identical--that's the point of a cryptographic hash.  OK, to
be pedantic:

   1) there's a microscopic chance of an accidental collision, but
   it's much lower than the chance of a hardware failure making your
   comparison function give the wrong answer.

   2) there are known cryptanalytic attacks against md5 that can let
   someone deliberately construct two distinct files with the same
   hash, with a fair amount of efort.  If you care about this, use
   sha-1 instead, or better yet, sha-256.  (sha-1 has an attack
   similar to the md5 attack, but the amount of work required is not
   really practical today, unlike the md5 attack).
-- 
http://mail.python.org/mailman/listinfo/python-list


  1   2   >