Re: SECURITY ADVISORY [PSF-2006-001] Buffer overrun in repr() for UCS-4 encoded unicode strings

2006-10-12 Thread Anthony Baxter
On Thursday 12 October 2006 17:31, Anthony Baxter wrote:
SECURITY ADVISORY [PSF-2006-001]
  Buffer overrun in repr() for UCS-4 encoded unicode strings

  http://www.python.org/news/security/PSF-2006-001/

As a few people noted in email to me - the patch directory was not _quite_ 
correct on the website. You have my complete apologies for this - I've 
updated the website, and it should be all good now.

Thanks!
Anthony.


pgpUajph05CUP.pgp
Description: PGP signature
-- 
http://mail.python.org/mailman/listinfo/python-announce-list

Support the Python Software Foundation:
http://www.python.org/psf/donations.html


ANN: BayPIGgies, Oct 12, 7:30pm, Google, Mtn View

2006-10-12 Thread wesley chun
Final REMINDER:

Tonight, the Silicon Valley/San Francisco Bay Area Python users group
meets at Google in Mountain View from 7:30-9p.

the featured speaker is Alex Martelli, author of O'Reilly's Python in
a Nutshell and editor of the Python Cookbook(s).  the topic is Python
2.5.

for more info and directions, see http://baypiggies.net

for information on meeting for dinner before the meeting (6pm):
http://mail.python.org/pipermail/baypiggies/2006-October/001228.html

hope to see you there!
-- wesley
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Core Python Programming, Prentice Hall, (c)2007,2001
http://corepython.com

wesley.j.chun :: wescpy-at-gmail.com
python training and technical consulting
cyberweb.consulting : silicon valley, ca
http://cyberwebconsulting.com
-- 
http://mail.python.org/mailman/listinfo/python-announce-list

Support the Python Software Foundation:
http://www.python.org/psf/donations.html


Guppy-PE 0.1.5 released

2006-10-12 Thread Sverker Nilsson
I would like to announce Guppy-PE 0.1.5

Guppy-PE is a library and programming environment for Python,
currently providing in particular the Heapy subsystem, which supports
object and heap memory sizing, profiling and debugging. It also
includes a prototypical specification language, the Guppy Specificaion
Language (GSL), which can be used to formally specify aspects of
Python programs and generate tests and documentation from a common
source.

The current version is updated to work with Python 2.5 (and can still
be used with 2.3 and 2.4). It also has some feature improvements, such
as some shorthand attributes, and a clearer representation of shortest
paths. Bugs have been fixed wrt especially remote monitoring and
making the HTML generated by GSL more standards-compliant. For update
details, see the changelog included with the source code.

License: MIT

For more information and to download the Guppy-PE source code, see:

http://guppy-pe.sourceforge.net

My master thesis, Heapy: A Memory Profiler and Debugger for Python
has now been approved and is available here:

http://guppy-pe.sourceforge.net/heapy-thesis.pdf

Best regards,

Sverker Nilsson

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

Support the Python Software Foundation:
http://www.python.org/psf/donations.html


Re: hundreds of seconds?

2006-10-12 Thread neoedmund

python's time is as old as glibc's time(). A more clear interface as
Java should be implements! though i'm not has the ability to do this.
maybe some volenties could do out the favor.


On Oct 11, 10:38 pm, [EMAIL PROTECTED] wrote:
 Hi all

 How can I access partial seconds on the system clock?

 I measure air speed and water flow in a heat-exchanger test stand and
 count pulses from both water meter and air speed meter. I divide the
 amount of these counts over a certain interval with the time of that
 interval. Since I only have seconds, I need to wait 100 seconds for may
 calculation is I want a precision of 1%.

 The radiator fan that I use can't stand these long intervals, 'cause I
 run it with 24V and 50 Amps to get decent airflow (10m/s) through my
 heat exchanger.

 Again: how do I get the hundreds of seconds from the system clock?

 In Pascal it was:  GetTime( Hr1, Min1, Sec1, cSec1);  (yes, I'm that
 old).

 ---
 ir EE van Andel [EMAIL PROTECTED]
 Fiwihex B.V. Wierdensestraat 74, NL7604BK Almelo, Netherlands
 tel+31-546-491106 fax+31-546-491107

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


Re: Experiences with Py2Exe

2006-10-12 Thread Fredrik Lundh
Isaac Rodriguez wrote:

 I am asking this because I have a lot of experience using the Windows
 Installer service, and I also have all the productivity tools available
 to create an installer for my tools if I needed to

just go ahead and use it.

py2exe generates an EXE and (usually) a bunch of related files:

 http://www.py2exe.org/index.cgi/FAQ

any tool that can wrap that up and install it on another machine works 
just fine.

/F

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


Re: Standard Forth versus Python: a case study

2006-10-12 Thread bearophileHUGS
[EMAIL PROTECTED] wrote:

 no sort() is needed to calculate the median of a list.
 you just need one temp var.

Can you show some actual code?

(There is the median of 5 algorithm too).

Bye,
bearophile

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


Re: Python component model

2006-10-12 Thread Erik Max Francis
Ilias Lazaridis wrote:

 http://dabodev.com
 http://case.lazaridis.com/wiki/DaboAudit

Who.  Cares.  What.  You.  Think?

-- 
Erik Max Francis  [EMAIL PROTECTED]  http://www.alcyone.com/max/
  San Jose, CA, USA  37 20 N 121 53 W  AIM, Y!M erikmaxfrancis
   Love is, above all, the gift of oneself.
-- Jean Anouilh
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to write Smart Python programs?

2006-10-12 Thread Antoine De Groote
Antoine De Groote wrote:

 class C(object):
 def __init__(self): self.__x = None
 def getx(self): return self._x
 def setx(self, value): self._x = value
 def delx(self): del self._x
 x = property(getx, setx, delx, I'm the 'x' property.)
 

Altough I'm not the OP, thanks a lot to everyone, I've learned much in 
this thread. But there's still something that puzzles me, I just realized.

In the snippet above (taken from the Python doc 
http://docs.python.org/lib/built-in-funcs.html), self.__x is 
initialized, but never used. I would appreciate any explanation for this.

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


Re: How to write Smart Python programs?

2006-10-12 Thread Paul Rubin
Antoine De Groote [EMAIL PROTECTED] writes:
 In the snippet above (taken from the Python doc
 http://docs.python.org/lib/built-in-funcs.html), self.__x is
 initialized, but never used. I would appreciate any explanation for
 this.

Looks like a typo, should say self._x .
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to write Smart Python programs?

2006-10-12 Thread Fredrik Lundh
Antoine De Groote wrote:

 In the snippet above (taken from the Python doc 
 http://docs.python.org/lib/built-in-funcs.html), self.__x is 
 initialized, but never used. I would appreciate any explanation for this.

looks like a typo.

/F

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


Re: News on versions modules for Python-2.5?

2006-10-12 Thread MC
Hi!

Ok.
Downloaded.
Thanks

-- 
@-salutations

Michel Claveau


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


Re: How to write Smart Python programs?

2006-10-12 Thread Antoine De Groote
Paul Rubin wrote:
 Antoine De Groote [EMAIL PROTECTED] writes:
 In the snippet above (taken from the Python doc
 http://docs.python.org/lib/built-in-funcs.html), self.__x is
 initialized, but never used. I would appreciate any explanation for
 this.
 
 Looks like a typo, should say self._x .

Ok, thanks, that's just what I was thinking..
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python component model

2006-10-12 Thread Kay Schluehr

Peter Maas wrote:
 Paul Boddie wrote:
  People who bring up stuff about self and indentation are just showing
  their ignorance, in my opinion, since Python isn't the first language
  to use self in such a way, and many C++ and Java programs use this
  pervasively in order to make attribute scope explicit, whereas the
  indentation matter is only troublesome with bad editing practices. I
  don't think the community should spend any more time on these
  criticisms.

 How many programmers don't use Python because of the self issue?

The only reason I know why self shall not be inforced is reducing the
number of troll postings.

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


Re: Standard Forth versus Python: a case study

2006-10-12 Thread Fredrik Lundh
Paul Rubin wrote:

 Ok, I'll bite.  How do you compute the median of a list using just a single 
 temp var?
 
 Well there's an obvious quadratic-time method...

that does it without modifying the list?

if you can modify the list, there are plenty of algorithms that does it 
in expected O(n) or better, but I cannot think of a one that doesn't use 
at least a few variables (e.g. two list indexes and a pivot).

but I haven't had enough coffee yet, so I'm probably missing something 
simple here.

/F

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


Re: Standard Forth versus Python: a case study

2006-10-12 Thread Paul Rubin
Fredrik Lundh [EMAIL PROTECTED] writes:
  Ok, I'll bite.  How do you compute the median of a list using just
  a single temp var?
  Well there's an obvious quadratic-time method...
 
 that does it without modifying the list?
 
 if you can modify the list, there are plenty of algorithms that does
 it in expected O(n) or better, but I cannot think of a one that
 doesn't use at least a few variables (e.g. two list indexes and a pivot).

Hmm, whoops, I didn't count the list index for the quadratic time
version (but that version shouldn't need to modify the list).

If you can modify the list, let's see, you can swap two elements with
no temp vars:

   a[i] ^= a[i+1]
   a[i+1] ^= a[i]
   a[i] ^= a[i+1]

This assumes an indexed addressing mode so finding a[i+1] doesn't
require using a temp var to hold (i+1).  Let's say the list length is
n, which is not a variable, and constant expressions like n-1 are also
not variables.  I'm still envisioning some reasonable type of assembly
code.  So now we can straightforwardly sort the list with one index
var and one flag bit:

   flag = True
   while flag:
  flag = False
  for i in 0..(n-2):
 if a[i]  a[i+1]:
 swap a[i], a[i+1] as above
 flag = True

and then pick the median out of the middle.

 but I haven't had enough coffee yet, so I'm probably missing something
 simple here.

Yeah, it's night here, maybe after I get some sleep I'll look for a
way to get rid of the flag bit above.
-- 
http://mail.python.org/mailman/listinfo/python-list


SECURITY ADVISORY [PSF-2006-001] Buffer overrun in repr() for UCS-4 encoded unicode strings

2006-10-12 Thread Anthony Baxter
   SECURITY ADVISORY [PSF-2006-001] 
 Buffer overrun in repr() for UCS-4 encoded unicode strings

 http://www.python.org/news/security/PSF-2006-001/

Advisory ID:  PSF-2006-001
Issue Date:   October 12, 2006
Product:  Python
Versions: 2.2, 2.3, 2.4 prior to 2.4.4, wide unicode (UCS-4) builds only
CVE Names:CAN-2006-4980

Python is an interpreted, interactive, object-oriented programming language. 
It is often compared to Tcl, Perl, Scheme or Java.

The Python development team has discovered a flaw in the repr() implementation 
of Unicode string objects which can lead to execution of arbitrary code due 
to an overflow in a buffer allocated with insufficient size.

The flaw only manifests itself in Python builds configured to support UCS-4 
Unicode strings (using the --enable-unicode=ucs4 configure flag). This is 
still not the default, which is why the vulnerability should not be present 
in most Python builds out there, especially not the builds for the Windows or 
Mac OS X platform provided by www.python.org.

You can find out whether you are running a UCS-4 enabled build by looking at 
the sys.maxunicode attribute: it is 65535 in a UCS-2 build and 1114111 in a 
UCS-4 build.

More information can be found in this posting to the python-dev mailing list: 
http://mail.python.org/pipermail/python-dev/2006-October/069260.html

The Common Vulnerabilities and Exposures project (cve.mitre.org) has assigned 
the name CAN-2006-4980 to this issue.

Python 2.4.4 will be released from www.python.org next week containing a fix 
for this issue. A release candidate of 2.4.4 is already available containing 
the fix. Python 2.5 also already contains the fix and is not vulnerable.

Patches for Python 2.2, 2.3 and 2.4 are also immediately available:

 * http://python.org/files/news/security/PSF-2006-001/patch-2.3.txt
 (Python 2.2, 2.3)
 * http://python.org/files/news/security/PSF-2006-001/patch-2.4.txt 
 (Python 2.4) 

Acknowledgement: thanks to Benjamin C. Wiley Sittler for discovering this 
issue.

The official URL for this security advisory is
http://www.python.org/news/security/PSF-2006-001/


pgpYsTZQ0YbSg.pgp
Description: PGP signature
-- 
http://mail.python.org/mailman/listinfo/python-list

RELEASED Python 2.4.4, release candidate 1

2006-10-12 Thread Anthony Baxter
On behalf of the Python development team and the Python community, 
I'm happy to announce the release of Python 2.4.4 (release candidate 1).

Python 2.4.4 is a bug-fix release. While Python 2.5 is the latest 
version of Python, we're making this release for people who are 
still running Python 2.4.

See the release notes at the website (also available as Misc/NEWS in
the source distribution) for details of the more than 80 bugs squished
in this release, including a number found by the Coverity and Klocwork
static analysis tools. We'd like to offer our thanks to both these 
companies for making this available for open source projects.

 *  Python 2.4.4 contains a fix for PSF-2006-001, a buffer overrun   *
 *  in repr() of unicode strings in wide unicode (UCS-4) builds. *
 *  See http://www.python.org/news/security/PSF-2006-001/ for more.  *

Assuming no major problems crop up, a final release of Python 2.4.4 will
follow in about a week's time. This will be the last planned release in
the Python 2.4 series - future maintenance releases will be in the 2.5 
line.

For more information on Python 2.4.4, including download links for
various platforms, release notes, and known issues, please see:

http://www.python.org/2.4.4/

Highlights of this new release include:

  - Bug fixes. According to the release notes, at least 80 have been
fixed.
  - A fix for PSF-2006-001, a bug in repr() for unicode strings 
on UCS-4 (wide unicode) builds.

Highlights of the previous major Python release (2.4) are available
from the Python 2.4 page, at

http://www.python.org/2.4/highlights.html

Enjoy this release,
Anthony

Anthony Baxter
[EMAIL PROTECTED]
Python Release Manager
(on behalf of the entire python-dev team)


pgpY6GGofDny5.pgp
Description: PGP signature
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: sufficiently pythonic code for testing type of function

2006-10-12 Thread A.T.Hofkamp
On 2006-10-11, Bruno Desthuilliers [EMAIL PROTECTED] wrote:
 A.T.Hofkamp wrote:
 On 2006-10-11, Bruno Desthuilliers [EMAIL PROTECTED] wrote:
 Now the real question : what if the object is not an instance of any of
 the types, but still support the expected interface ?

 
 one possible answer: Use ZopeInterfaces
 (and ask objects 'do you implement interface X' rather than 'are you type Y')
 
 Not sure what options you have when dealing with builtin data types however.

 This was mostly a rethorical question...

And even for rethorical questions, Python already provides a solution.. :-)

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


pygtk dynamic table

2006-10-12 Thread JyotiC
hi,

i am making a gui, which looks like excel sheets.
i want to give the user the facility of adding rows/columns at the run
time.
there is some initial size, but that can be increased any time during
the executation of the code.

what i have tried, is that i am using table.
so when ever user increase the size, i destroy the original table and
make a new one with the increased size.

is there a better way to do this ?

thanx in advance

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


Re: Python component model

2006-10-12 Thread Fredrik Lundh
Erik Max Francis wrote:

 http://dabodev.com
 http://case.lazaridis.com/wiki/DaboAudit

 Who.  Cares.  What.  You.  Think?

his mom?

/F 



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


Enum

2006-10-12 Thread Massi
Hi Everyone! Does anybody know how to implemet Enumeration in python
for Ctypes? Thank you!
Massi

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


Dll files and Python2.5

2006-10-12 Thread roee88 shlomo
Hi,
I would like to know a few things about the dll files usually included in Python windowsapplications:

1. in the Pythonwin Home Page (http://www.python.net/crew/skippy/win32/) I can see that mfc42.dll is required for python2.3 and mfc71.dll is required for python2.4
 . 
Ismfc71.dll still requiredin python2.5 asin 2.4 ?
I'm asking it because I deleted all the mfc71.dll files from my computer and functions that uses win32com are still working.
Perhaps mfc71 is included in the python25 package?

2. What package requires msvcr71.dll ?

3. What package requires msvcp71.dll ?

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

Re: Dll files and Python2.5

2006-10-12 Thread roee88 shlomo
Ignore the first question, it is required.
On 10/12/06, roee88 shlomo [EMAIL PROTECTED] wrote:

Hi,
I would like to know a few things about the dll files usually included in Python windowsapplications:

1. in the Pythonwin Home Page (http://www.python.net/crew/skippy/win32/) I can see that mfc42.dll
 is required for python2.3 and mfc71.dll is required for python2.4 . 
Ismfc71.dll still requiredin python2.5 asin 2.4 ?
I'm asking it because I deleted all the mfc71.dll files from my computer and functions that uses win32com are still working.
Perhaps mfc71 is included in the python25 package?

2. What package requires msvcr71.dll ?

3. What package requires msvcp71.dll ?

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

Re: Motions.

2006-10-12 Thread dug
Hi,

I think that the science discipline you will be working with is called
'computer vision' (CV). It will be worthwhile also posting your
question in a CV group.

Best wishes

Douglas

Dr. Pastor wrote:
 Hi:
 I would like to track the motions of
 small birds in short (20-30sec) .avi films.
 What tool-set/programs would be wise to use?
 Thanks for any guidance.

 == Posted via Newsfeeds.Com - Unlimited-Unrestricted-Secure Usenet 
 News==
 http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ 
 Newsgroups
 = East and West-Coast Server Farms - Total Privacy via Encryption =

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


prefix search on a large file

2006-10-12 Thread js
 Hello, list.

 I have a list of sentence in text files that I use to filter-out some data.
I managed the list so badly that now it's become literally a mess.

Let's say the list has a sentence below

1. Python has been an important part of Google since the beginning,
and remains so as the system grows and evolves. 

2. Python has been an important part of Google

3. important part of Google

As you see sentence 2 is a subset of sentence 1
so I don't need to have sentence 1 on the list.
(For some reason, it's no problem to have sentence 3.
Only sentence that has the same prefix part is the one I want to remove)

So I decided to clean up the list.

I tried to do this simple brute-force manner,  like

---
sorted_list = sorted(file('thelist'), key=len)
for line in sorted_list[:]
  unneeded = [ line2 for line2 in sorted_list[:] if line2.startswith(line) ]
  sorted_list = list(set(sorted_list) - (unneeded))

---

This is so slow and not so helpful because the list is
so big(more than 100M bytes and has about 3 million lines)
and I have more than 100 lists.

I'm not familiar with algorithms/data structure and large-scale data processing,
so any advice, suggestions and recommendations will be appreciated.

Thank you in advance.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: operator overloading + - / * = etc...

2006-10-12 Thread Bruno Desthuilliers
Georg Brandl wrote:
 Bruno Desthuilliers wrote:
 Steven D'Aprano wrote:
 On Sat, 07 Oct 2006 17:21:55 -0500, Tim Chase wrote:

 With the caveat of the = mentioned in the subject-line (being
 different from ==)...I haven't found any way to override
 assignment in the general case.
 Why would you want to do that?
 For the same reason one would use property() to create getter/setter
 functions for a particular variable--to intercept attempts to set a
 variable.

 (snip)

 Suppose we bind the name x to the object 1, and then rebind the
 name x
 to the object []. Which object's hypothetical __assign__ method
 should get
 called? 

 The current namespace object, of course.
 
 Which is?

Depends on the context... Can be actually the module (global) namespace,
a function local namespace or a class namespace.


-- 
bruno desthuilliers
python -c print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in '[EMAIL PROTECTED]'.split('@')])
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: operator overloading + - / * = etc...

2006-10-12 Thread Bruno Desthuilliers
Terry Reedy wrote:
 Bruno Desthuilliers [EMAIL PROTECTED] wrote in message 
 news:[EMAIL PROTECTED]
 The current namespace object, of course.
 
 Implementing a namespace as a Python object (ie, dict) is completely 
 optional and implementation dependent.  For CPython, the local namespace of 
 a function is generally *not* done that way.

I know this, and that's not the point here. The op's question seemed to
imply that the hypothetical __assign__ method should belong to the rhs
object, which is obviously not the case - it must of course belongs to
the lhs 'object'.


-- 
bruno desthuilliers
python -c print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in '[EMAIL PROTECTED]'.split('@')])
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: thread lock question

2006-10-12 Thread Ritesh Raj Sarraf
I'm sorry. My example code wasn't clear enough.
Please see the following:

exit_status = copy_first_match(foo, bar)

if exit_status == False:
if download_file(foo, bar) == True:
 if zip_bool:
 ziplock.acquire()
 try:
 compress_the_file(zip_type_file, foo,
bar)
 os.unlink(foo) # Unlink it once it has
been zipped
 finally:
 ziplock.release()
else:
if zip_bool:
 ziplock.acquire()
 try:
 compress_the_file(zip_type_file, foo, bar)
 os.unlink(foo)
 finally:
 ziplock.release()

I think this code should be clear enough.
The program, before trying to download from the web, checks into its
cache repository to see if the file is available or not. If available,
it copies it from the local cache repository and adds to the archive,
else it downloads from the web and archives it.

Now in this scenario, with threads, say a file of 100 mb got downloaded
and then being zipped. It might take a couple of seconds for the zip to
complete. During those couple of seconds, if another thread's file (a
couple kb) gets downloaded/copied, will it wait for the lock to be
released or will it create another lock ?

Thanks,
Ritesh


Dennis Lee Bieber wrote:
 On Wed, 11 Oct 2006 18:39:32 +0530, Ritesh Raj Sarraf
 [EMAIL PROTECTED] declaimed the following in comp.lang.python:

 
  if download_file(foo, bar) == True:
  if some condition:
  do_something()
  if zip_bool:
   snip
  if zip_bool:
   snip

  Basically, I'm testing for some condition, if that is True, do something and
  then do the zipping. I'm also doing the zipping even if that's not true.
 
   Actually, given the code you show, if some condition is true, you
 are /attempting/ to zip the file twice; the second one likely fails due
 to the first one deleting the file -- a condition masked by the finally:
 clause.

   All you really need there is

   if download_file(foo, bar):
   if some condition:
   do_something()
   if zip_bool:
   


  My question is, in a code example like this which is threaded, does the 
  locking
  mechanism work correctly ?
  Or are two different locks being acquired ?

   Is the lock object itself defined globally (shared by the threads)?
 --
   WulfraedDennis Lee Bieber   KD6MOG
   [EMAIL PROTECTED]   [EMAIL PROTECTED]
   HTTP://wlfraed.home.netcom.com/
   (Bestiaria Support Staff:   [EMAIL PROTECTED])
   HTTP://www.bestiaria.com/

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


Re: is there an easy way to create a database on the fly and let the user input values

2006-10-12 Thread Bruno Desthuilliers
[EMAIL PROTECTED] wrote:
  I don't realy care what database I use wx.grid or whatever.  I
 wan't it to look at a line
 
 128 9023 23428 exc and create the database or pick something out of the
 file as  some sort of a descrition line and then display and allow the
 user to change and add new lines.  What is the easiest set of database
 routines to use for such a project???

I'd go for something like SQLite or Gadfly - or even the standard CSV
module if there are no need for a relational model.

 http://www.dexrow.com
 


-- 
bruno desthuilliers
python -c print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in '[EMAIL PROTECTED]'.split('@')])
-- 
http://mail.python.org/mailman/listinfo/python-list


Code generator

2006-10-12 Thread Massi
Hello NG! Can anybody explain me how to install the code generator fo
ctypes on my pc? I use windows...
for example I found this line command on the overview:

python h2xml.py windows.h -o windows.xml -q -c

Where do I have to type? and where do I have to put the file that I got
from the repository?
Thank you for the help!

Massi

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


Re: Standard Forth versus Python: a case study

2006-10-12 Thread Ian McConnell
[EMAIL PROTECTED] writes:

 John Doty:
 Yes. The efficient exact algorithms for this problem use *partial*
 sorts. The Forth one from the FSL is of this class (although I know of
 two better ones for big arrays). But it's tough to beat the efficiency
 of the approximate histogram-based method the Python stats module
 implements.

 The usual way to compute a true median with Python may be:

 def median(inlist):
 newlist = sorted(inlist)
 index = len(newlist) // 2
 if len(newlist) % 2:
 return newlist[index]
 else:
 return (newlist[index] + newlist[index-1]) / 2.0

 If you can use Psyco and your FITS lines are really long (well, maybe
 too much, the treshold if about ~3000 in my PC) you can use something
 like this instead the builtin timsort:
 http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/466330
 (To compute the median on a image line the median that uses sort is
 probably better in most cases, expecially if you use the built in sort
 of numerical libraries.)

sort() sorts all of the data, but you're only after one or two numbers, so
the MODFIND method may be faster for the median:

 http://www.geocities.com/SiliconValley/Garage/3323/algor.html

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


python's newbie question

2006-10-12 Thread tpochep
Hi. I have some strange problem (this is usual for newbies :) ):

#!/usr/bin/python
#sample.py

class Base1:
def __init__(self):
print Base1.__init__, self
def __del__(self):
print Base1.__del__, self

class Base2:
def __init__(self):
print Base2.__init__, self
def __del__(self):
print Base2.__del__, self

class Derived(Base1, Base2):
def __init__(self):
print Derived.__init__:
Base1.__init__(self)
Base2.__init__(self)
def __del__(self):
print Derived.__del__:
Base1.__del__(self)
Base2.__del__(self)

print begin...
d = Derived()
b = d
print end...

The output of this script:

begin...
Derived.__init__:
Base1.__init__ __main__.Derived instance at 0x1869adcc
Base2.__init__ __main__.Derived instance at 0x1869adcc
end...
Derived.__del__:
Base1.__del__ __main__.Derived instance at 0x1869adcc
Base2.__del__ __main__.Derived instance at 0x1869adcc

If I change this program a little:

#!/usr/bin/python
#skipped

print begin...
d = Derived()
b1 = d #Here
print end...

The output is:

begin...
Derived.__init__:
Base1.__init__ __main__.Derived instance at 0x1869adcc
Base2.__init__ __main__.Derived instance at 0x1869adcc
end...
Derived.__del__:
Exception exceptions.AttributeError: 'NoneType' object has no
attribute '__del__' in bound method
Derived.__del__ of __main__.Derived instance at 0x1869adcc ignored

I tried different names instead of b1, sometimes programm works,
sometimes I have an exception. So it's clear, that I've done some
stupid mistake, but it's not clear for me, python's newbie, where :)

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


Re: python's newbie question

2006-10-12 Thread js
http://mail.python.org/pipermail/python-list/2004-May/221591.html

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


Re: python's newbie question

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

 begin...
 Derived.__init__:
 Base1.__init__ __main__.Derived instance at 0x1869adcc
 Base2.__init__ __main__.Derived instance at 0x1869adcc
 end...
 Derived.__del__:
 Exception exceptions.AttributeError: 'NoneType' object has no
 attribute '__del__' in bound method
 Derived.__del__ of __main__.Derived instance at 0x1869adcc ignored

 I tried different names instead of b1, sometimes programm works,
 sometimes I have an exception. So it's clear, that I've done some
 stupid mistake, but it's not clear for me, python's newbie, where :)

The real mistake here is to use __del__ in your program; don't do that, unless
you have really good reasons (and they are few and not very common).  In most
cases, you can just rely on Python's garbage collector; it'll clean up after 
you all
by itself, most of the time.

The error you're seeing is due to the fact that Python attempts to destroy 
every-
thing during shutdown, and this process includes clearing out the contents of 
all
modules in the program.  Your object is simply destroyed *after* the module it's
defined in is cleared.  To work around this, you need to keep references to all
objects you might end up needing in your object.  (Or just drop the __del__
methods.  Chances are that you don't really need them.)  For more on module
cleanup, see this old Guido essay:

http://www.python.org/doc/essays/cleanup/

/F 



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


Re: python's newbie question

2006-10-12 Thread tpochep

js  писал(а):

 http://mail.python.org/pipermail/python-list/2004-May/221591.html
 
 HTH

Thank you!!!

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

Re: python's newbie question

2006-10-12 Thread tpochep

Fredrik Lundh писал(а):

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

Re: Experiences with Py2Exe

2006-10-12 Thread MaR
We use py2exe on regular basis for most of our app's, both for internal
and external distribution.
We then pack it to an installer using NSIS
(http://nsis.sourceforge.net/Main_Page) which is also free :o)

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


Re: python's newbie question

2006-10-12 Thread Duncan Booth
[EMAIL PROTECTED] wrote:

 I tried different names instead of b1, sometimes programm works,
 sometimes I have an exception. So it's clear, that I've done some
 stupid mistake, but it's not clear for me, python's newbie, where :)

Not a stupid mistake, although as you come to use Python more you will 
learn that you need __del__ methods very rarely if at all. This is just as 
well as writing reliable __del__ methods can be non-trivial.

The problem you have is that your __del__ method is being called as Python 
tidies up before exiting. It does this by going systematically through all 
the modules and deleting all of their global variables. If you are using 
__del__ you have to be aware that by the time it gets called not all global 
variables still exist.

The order in which the globals are deleted isn't defined, in this case it 
looks like Base1 has been deleted before Derived, but that won't always be 
the case.

One option is to use new-style classes and use super() to pass the call up 
to the base classes (super is a builtin, and builtins should still be 
around when your code is being cleaned up). Another option would be to 
access the base classes through Derived.__bases__.

Probably the best solution is to remove any objects which required cleanup 
from your class hierarchy. e..g if Derived has a __del__ method because it 
needs to close a database, have a separate object representing the database 
which does its own cleanup. Then Derived doesn't need to call 
self.database.close() because that will happen automatically when 
self.database is destroyed, so Derived won't need a __del__.

Here's your code pushing the __del__ method out of the class hierarchy. But 
watch out: if you pass self as an argument to printer then nothing gets 
destroyed at all as the program exits, and of course the order in which the 
__del__ prints appear is now undefined.

class printer(object):
def __init__(self, *args):
self.msg = args
def __del__(self):
print ' '.join(self.msg)

class Base1:
def __init__(self):
print Base1.__init__, self
self.__del = printer(Base1.__del__)

class Base2:
def __init__(self):
print Base2.__init__, self
self.__del = printer(Base2.__del__)

class Derived(Base1, Base2):
def __init__(self):
print Derived.__init__:
Base1.__init__(self)
Base2.__init__(self)
self.__del = printer(Derived.__del__:)

print begin...
d = Derived()
b = d
print end...
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: What value should be passed to make a function use the default argument value?

2006-10-12 Thread Magnus Lycka
Antoon Pardon wrote:
 Well maybe he didn't intend that, but how is the reader of the
 documentation to know that? The reader can only go by how
 things are documented. If those are not entirely consistent
 with the intend of the programmer, that is not the readers
 fault.

I don't think I ever assumed that it was right to call functions
with keyword arguments if they weren't defined with keyword
parameters, but when I read 4.7.2 of the tutorial, I can see that
it's stated through an example that this is a correct thing to do.
I suppose the tutorial (and maybe the language reference) should
be corrected if this isn't supposed to be guaranteed behavior.

It seems like a bad idea to have different calling semantics
depending on whether a callable is implemented in C or Python.
Even if non-keyword parameters in Python implemented callables,
*can* be called with keyword arguments, it seems like a bad
idea to encourage that use. Perhaps it would be a good idea
to deprecate that possibility and remove it in Python 3.0?

I think it's better to force some calls into using f(*a, **kw)
instead of f(**kw) if it decreases the risk that reimplementing
functions in C in an API will break client code. Sure, it's
simple to make a Python wrapper, but if you're after raw speed,
you might not want to do that.

The main downside to removing the possibility of calling non
keyword parameters with keyword arguments might be that using
keyword arguments could fill a documentation purpose in the
code, e.g. x=get(host=arg[0], port=arg[1], path=arg[2]) would
be clearer than x=get(arg[0], arg[1], arg[2]). Of course,
host, port, path = arg; x=get(host, port, path) is even better
(if s/;/\n) but in some cases, it's better to be able to
inline things.
-- 
http://mail.python.org/mailman/listinfo/python-list


XML ElementTree Parse.

2006-10-12 Thread marc . wyburn
I'm playing with XML and elementtree and am missing something but I'm
not sure what...? I've create an XML file with Elementtree with a root
of backup.xml.  Attached to the root is a dirob and the dirobj has a
fileobj.  fileobj has filename and filesize tags.  I can open the file
in excel and it sets out the columns as I would expect.  The problem
I'm having is parsing the file. Using..

 file = open('c:\\scripts\\backup.xml', r)
 tree = parse(file)
 elem = tree.getroot()
 elem.findtext('filesize')

Doesn't return anything, infact I can't seem to find anything
regardless of what I search for.
Here is the XML.  I've got a list of files and their containing
directories and I want my python script to append to the XML file each
day.  I could have done it with SQL but fancied banging my head on the
wall instead.  Thanks, MW.


- backup.xml
- dirob
  dirnameC:\sysprep/dirname
- fileob
  filenametest.txt/filename
  filesize10/filesize 
  /fileob
  /dirob
  /backup.xml

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


Re: prefix search on a large file

2006-10-12 Thread John Machin

js  wrote:
 Hello, list.

  I have a list of sentence in text files that I use to filter-out some data.
 I managed the list so badly that now it's become literally a mess.

 Let's say the list has a sentence below

 1. Python has been an important part of Google since the beginning,
 and remains so as the system grows and evolves. 

 2. Python has been an important part of Google

 3. important part of Google

 As you see sentence 2 is a subset of sentence 1
 so I don't need to have sentence 1 on the list.

Are you 100% sure that you wnat to throw away the *longer* sentence?

 (For some reason, it's no problem to have sentence 3.
 Only sentence that has the same prefix part is the one I want to remove)

 So I decided to clean up the list.

 I tried to do this simple brute-force manner,  like

Please don't waste time and bandwith with like; post the exact code
that you executed.


 ---
 sorted_list = sorted(file('thelist'), key=len)
 for line in sorted_list[:]
# won't compile, missing a colon at end
   unneeded = [ line2 for line2 in sorted_list[:] if line2.startswith(line) ]
   sorted_list = list(set(sorted_list) - (unneeded))
#  can't do set - list
# Presuming you mean - set(unneeded), but then produces an empty list
(see later).
# Naming the output sorted_list is misleading advertising.
# With sorted_list[:] in an inner loop, it's no wonder that it runs
slowly.
# Test your code on small samples of data and ensure that it is working
correctly before you run it on huge amounts of data.
# Be careful of end cases; note that in my solutions below, the first
or last item needs special handling.

 
 ---

 This is so slow and not so helpful because the list is
 so big(more than 100M bytes and has about 3 million lines)
 and I have more than 100 lists.

Here's one way of doing it, tested to the extent shown:

C:\junktype prefixdel.py
from pprint import pprint as pp
data = [
'foo bar baz',
'foo bar',
'foo',
'food',
'food', # duplicate
'xyzzy',
'plugh',
'xyzzy and plugh are magic',
'',
]


 sorted_list = sorted(file('thelist'), key=len)
 for line in sorted_list[:]
   unneeded = [ line2 for line2 in sorted_list[:] if line2.startswith(line) ]
   sorted_list = list(set(sorted_list) - set(unneeded))

slist = sorted(data, key=len)
print OP trial 1 input; pp(slist)
for line in slist[:]:
unneeded = [line2 for line2 in slist[:] if line2.startswith(line)]
slist = list(set(slist) - set(unneeded))
print OP trial 1 output; pp(slist)

ilist = sorted(data)
print sorted input; pp(ilist)

olist = []
for i in xrange(len(ilist)-1, 0, -1):
if ilist[i].startswith(ilist[i-1]):
continue
olist.append(ilist[i])
olist.append(ilist[0])
print output (keeping shorter); pp(olist)

olist = []
for i in xrange(len(ilist)-1):
if ilist[i+1].startswith(ilist[i]):
continue
olist.append(ilist[i])
olist.append(ilist[-1])
print output (keeping longer); pp(olist)


C:\junkprefixdel.py
OP trial 1 input
['foo',
 'food',
 'food',
 '',
 'xyzzy',
 'plugh',
 'foo bar',
 'foo bar baz',
 'xyzzy and plugh are magic']
OP trial 1 output
[]
sorted input
['foo',
 'foo bar',
 'foo bar baz',
 'food',
 'food',
 'plugh',
 'xyzzy',
 'xyzzy and plugh are magic',
 '']
output (keeping shorter)
['', 'xyzzy', 'plugh', 'food', 'foo']
output (keeping longer)
['foo bar baz', 'food', 'plugh', 'xyzzy and plugh are magic', '']

HTH,
John

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


Re: XML ElementTree Parse.

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

 I'm playing with XML and elementtree and am missing something but I'm
 not sure what...? I've create an XML file with Elementtree with a root
 of backup.xml.  Attached to the root is a dirob and the dirobj has a
 fileobj.  fileobj has filename and filesize tags.  I can open the file
 in excel and it sets out the columns as I would expect.  The problem
 I'm having is parsing the file. Using..

 file = open('c:\\scripts\\backup.xml', r)
 tree = parse(file)
 elem = tree.getroot()
 elem.findtext('filesize')

 Doesn't return anything, infact I can't seem to find anything
 regardless of what I search for.

find/findtext/findall only look at direct subelements, unless you use xpath-
style syntax.  in this case,

elem.findtext(dirob/fileob/filesize)

should do the trick.  or you could do something like

for dir_elem in tree.findall(dirob):
for file_elem in dirob.findall(fileob):
print file_elem.findtext(filesize)

to loop over all directory objects at the top level, and print the sizes for
all files in those directories.

to get the first filesize in the tree, no matter where it is, use

elem.findtext(.//filesize)

/F

 - backup.xml
 -  dirob
 dirnameC:\sysprep/dirname
 -  fileob
  filenametest.txt/filename
  filesize10/filesize
 /fileob
/dirob
  /backup.xml



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


Re: Python component model

2006-10-12 Thread Terry Reedy

Ilias Lazaridis [EMAIL PROTECTED] wrote in message 
news:[EMAIL PROTECTED]
 I share the infrastructure which I use:

 http://dev.lazaridis.com/base

But not quite yet, it appears. A public release is planned shortly 



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


Re: Where is Python in the scheme of things?

2006-10-12 Thread Magnus Lycka
Bruno Desthuilliers wrote:
 gord wrote:
 As a complete novice in the study of Python, I am asking myself where this 
 language is superior or better suited than others. For example, all I see in 
 the tutorials are lots of examples of list processing, arithmetic 
 calculations - all in a DOS-like environment.
 
 s/DOS-like/command line/
 
 The command line interface is widely used on unix-like systems, and is
 very handy for a lot of things.

In general, I think using the keyboard more and the mouse less is
typically a win, both in power of expression and in speed. I don't
think it's a coincidence that most of us use the keyboard and plain
text to communicate in this forum. Writing text by pointing, dragging
and clicking instead of by typing, would probably slow us down quite
a bit.

I feel much more productive in bash than in most Windows apps.
(I still like to have several terminal windows though.)

My seven year old son did play a bit with magnetic letters we have
on the fridge door in the kitchen (when he was small, he'd say now)
but he's dropped that entirely in favor of pencil and paper. His
two year old brother can play with that fridge-based GUI...

When we reach a certain level of expertize, we often find it easier
to pick the things we put together from our memory and imagination,
rather than from some kind of menu in our field of vision.

Ok, the keyboard is a kind of menu too, but that's not the point.
The important thing is that text is an extremely powerful way of
conveying information that we've used for thousands of years. It's
far more sophisticated than pointing at visible objects.

Also, a tool like Python isn't bound to keyboards, like VB is
bound to the Windows GUI. Almost everything, from network traffic,
to GUI interaction, to hardware manipulations can be effectively
translated to and from text formats. Not that Python can't handle
binary data, but going via textual representations usually makes
testing, debugging and understanding much easier.

I'd suggest that the OP look at the Wikipedia page in Unix
Philosophy. Read about Gancarz tenets, and replace shell scripts
with Python. (Of course, Python offers more elaborate communication
than pipes.) I'd also the link to Joel Spolsky's Biculturalism
article, and read that.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: XML ElementTree Parse.

2006-10-12 Thread marc . wyburn
Thanks Fredrik, thats got me started but just incase anyone looks there
is a slight mistype in your code...

 or you could do something like

 for dir_elem in tree.findall(dirob):
 for file_elem in dirob.findall(fileob):
 print file_elem.findtext(filesize)

 to loop over all directory objects at the top level, and print the sizes for
 all files in those directories.

should read

 for delem in tree.findall(dirob):
... for felem in delem.findall(fileob):
... print felem.findtext(filesize)
... 
933888
9365

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


Re: Alternative constructors naming convention

2006-10-12 Thread Will McGugan
Steven Bethard wrote:

 Are you really using staticmethod and calling __new__?  It's often much 
 easier to use classmethod, e.g.::
 
 class Color(object):
 ...
 @classmethod
 def from_html(cls, r, g, b):
 ...
 # convert r, g, b to normal constructor args
 ...
 # call normal constructor
 return cls(...)
 

I could use that for some things, but often I can avoid an intermediate 
step by bypassing the class constructor altogether...

 And FWIW, I use lower_with_underscores for alternate constructors, not 
 CamelCase.

Seems to be the consensus. I think I'll stick_to_it!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Standard Forth versus Python: a case study

2006-10-12 Thread [EMAIL PROTECTED]
Paul McGuire wrote:
 [EMAIL PROTECTED] wrote in message
 news:[EMAIL PROTECTED]
  [snip]
 
  no sort() is needed to calculate the median of a list.
 
  you just need one temp var.
 

 Ok, I'll bite.  How do you compute the median of a list using just a single
 temp var?

 -- Paul

hi Paul; well when this was a stats-class assignment (back when pascal
was popular :) i just stepped through the vector and compared it

(pseudo-code)

ptr p = [with values].

fun median {
 var x = 0.
  while( *p++) {
if( (*p)  x) x = *p.
  }
  return x.
}

of course, pascal is more verbose but that's median()

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


Re: Standard Forth versus Python: a case study

2006-10-12 Thread Paul Rubin
[EMAIL PROTECTED] [EMAIL PROTECTED] writes:
 fun median {
  var x = 0.
   while( *p++) {
 if( (*p)  x) x = *p.
   }
   return x.
 }

I count two variables, p and x.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Standard Forth versus Python: a case study

2006-10-12 Thread Paul Rubin
Paul Rubin http://[EMAIL PROTECTED] writes:
  fun median {
   var x = 0.
while( *p++) {
  if( (*p)  x) x = *p.
}
return x.
  }
 
 I count two variables, p and x.

Also, that finds the maximum, not the median.  I had stopped examining
it after seeing it used more than one variable.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Standard Forth versus Python: a case study

2006-10-12 Thread Andrew Haley
In comp.lang.forth Paul Rubin http://[EMAIL PROTECTED] wrote:
 [EMAIL PROTECTED] [EMAIL PROTECTED] writes:
 fun median {
  var x = 0.
   while( *p++) {
 if( (*p)  x) x = *p.
   }
   return x.
 }

 I count two variables, p and x.

Isn't this the maximum?

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


Re: error handling

2006-10-12 Thread Bernard
lol you are so right! I didn't even notice this was the 1.5.2 version!


Gabriel Genellina wrote:
 At Wednesday 11/10/2006 16:16, Bernard wrote:

 I just found this webpage showing the most common exceptions:
 http://pydoc.org/1.5.2/exceptions.html

 Why not refer to the *current* documentation?
 http://docs.python.org/lib/module-exceptions.html
 (You already have it installed with Python)

 1.5.2 is way too old!


 --
 Gabriel Genellina
 Softlab SRL





 __
 Preguntá. Respondé. Descubrí.
 Todo lo que querías saber, y lo que ni imaginabas,
 está en Yahoo! Respuestas (Beta).
 ¡Probalo ya! 
 http://www.yahoo.com.ar/respuestas

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


Re: How to share session with IE

2006-10-12 Thread zdp
I found some similar topics in the newsgroup and get some ideas from
them.
http://groups.google.com/group/comp.lang.python/browse_thread/thread/2fe0be6c386adce4
http://groups.google.com/group/comp.lang.python/browse_thread/thread/a51cec8747f64619

According to all you suggestions, there are at least two ways to get my
result.

1. Use the cookie of IE, so I don't need to code to logon. That means I
must use ClientCookie. I found some example in the docs and the
newsgroup. Below is some code based on the docs of ClientCookie. But
the page I get is still the page told me must login ( I CAN get the
right page in IE).

import ClientCookie, urllib2

url_string=http://www.targetsite.com/bbs/viewthread.php?tid=12345;
   #the page I want to get

cj = ClientCookie.MSIECookieJar(delayload=True)
cj.load_from_registry()
print cj  #I want to know what I get

opener =
ClientCookie.build_opener(ClientCookie.HTTPCookieProcessor(cj))
ClientCookie.install_opener(opener)
f = ClientCookie.urlopen(url_string)
print f.read()  # NOT the right page html


2. Logon myself by python. First, I access the login page and submit
the form of username and password. The form has many fields other than
username and passwd, so the dict data has all the fields even if it's
hide. Then, if the login succeed, I can get my page use the opener with
CookieJar.

import urllib2, cookielib

url_string=http://www.targetsite.com/bbs/viewthread.php?tid=12345;
   #the page I want to get
url_login=http://www.targetsite.com/bbs/logging.php?action=login;
 #the login page

headers =  {'User-agent' : 'Mozilla/4.0 (compatible; MSIE 5.5;
Windows NT)'}
cj = cookielib.CookieJar()
opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj))

urllib2.install_opener(opener)
data = {
'formhash': '3bd8bc0a',
referer : index.php,
loginfield: username,
'username': 'myname',
'password': 'mypass',
questionid: 0,
answer:,
cookietime : 31536,
loginmode:,
styleid:
}
req=urllib2.Request(url_login, urllib.urlencode(data), headers)
f = opener.open(req)
print req.get_data()
print req.header_items()
print f.info()
print f.read()

## if login succeed, I can get my page
f=opener.open( url_string)


However, both ways didn't work for me. I don't know what's wrong. If
it's because the server page check the header or the submit of the form
is wrong?

I didn't study Mechanize module yet. I want a solution as simple as
possible for distribution reason.

John J. Lee 写道:

 Bernard [EMAIL PROTECTED] writes:
  zdp wrote:
 [...]
   However, now I need to process some pages by a python program. When I
   use urllib.urlopen(theurl), I can only get a page which told me I need
   login. I think It's reasonable, becuase I wasn't in a loggined session
   which as IE did.
  
   So how can I do my job? I want to get the right webpage by the url. I
   have search answers from the groups but didn't get clear answer. Should
   I use win32com or urllib? Any reply or information is appreciate. Hope
   I put it clear.

  You can do the same thing as IE on your forum using urllib2 and
  cookielib. In short you need to code a small webcrawler. I can give you
  my browser module if necessary.
  You might not have the time to fiddle with the coding part or my
  browser module so you can also use this particularly useful module :
  http://wwwsearch.sourceforge.net/mechanize/
  The documentation is pretty clear for an initiated python programmer.
  If it's not your case, I'd recommend to read some ebooks on the python
  language first to get use to it.

 In particular, if you're following the approach Bernard suggests, you
 can either:

 1. Log in every time your program runs, by going through the sequence
of clicks, pages, etc. that you would use in a browser to log in.

 2. Once only (or once a month, or whatever), log in by hand using IE
with a Remember me-style feature (if the website offers that) --
where the webapp asks the browser to save the cookie rather than
just keeping it in memory until you close your browser.  Then your
program can load the cookies from your real browser's cookie store
using this:

 http://wwwsearch.sourceforge.net/mechanize/doc.html#browsers


 There are other alternatives too, but they depend on knowing a little
 bit more about how cookies and web apps work, and may or may not work
 depending on what exactly the server does.  I'm thinking specifically
 here of saving *session* cookies (the kind that usually go away when
 you close your browser) in a file -- but the server may not like them
 when you send them back the next time, depending how much time has
 elapsed since the last run.  Of course, you can always detect the
 need to login condition, and react accordingly.
 
 
 John

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

Re: Standard Forth versus Python: a case study

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

 hi Paul; well when this was a stats-class assignment (back when pascal
 was popular :) i just stepped through the vector and compared it

 (pseudo-code)

 ptr p = [with values].

 fun median {
 var x = 0.
  while( *p++) {
if( (*p)  x) x = *p.
  }
  return x.
 }

 of course, pascal is more verbose but that's median()

that's a rather unusual definition of median, though.

/F 



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


httplib/DAV: How to respond to WWW-Authenticate: NTLM ?

2006-10-12 Thread robert
In a DAV scheme with PROPFIND or GET (PROPFIND /test/ HTTP/1.1)  and 
Basic AUTH to a MS SharePoint over https server (AUTH required), he 
responds 'WWW-Authenticate: NTLM' only:

reply: 'HTTP/1.1 401 Unauthorized\r\n'
header: Content-Length: 1656
header: Content-Type: text/html
header: Server: Microsoft-IIS/6.0
header: WWW-Authenticate: NTLM
header: X-Powered-By: ASP.NET
header: MicrosoftSharePointTeamServices: 6.0.2.6568
header: Date: Thu, 12 Oct 2006 12:27:42 GMT


I simply try repeatedly the same request with Basic Auth header again = 
The same response requesting 'header: WWW-Authenticate: NTLM' again.

But then after an unsuccessful test on a really new connection (.close() 
, .request()) he accepts the Basic AUTH immediately.

* What is this?
* Is this a legal/known way to respond to a NTLM AUTH request by 
.close() and reconnect with Basic Auth?
* Is there a Python function out there to do real NTLM authentication?.. 
and is this recommended to dig into Microsofty HTTP protocols ?


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


Re: Standard Forth versus Python: a case study

2006-10-12 Thread Peter Decker
On 12 Oct 2006 04:40:32 -0700, Paul Rubin
http://phr.cx@nospam.invalid wrote:
 Paul Rubin http://[EMAIL PROTECTED] writes:
   fun median {
var x = 0.
 while( *p++) {
   if( (*p)  x) x = *p.
 }
 return x.
   }
 
  I count two variables, p and x.

 Also, that finds the maximum, not the median.  I had stopped examining
 it after seeing it used more than one variable.

Um... isn't 'p' the list in question? There is only one variable used
for the calculation of the return value (yes, it's a maximum), and
that's 'x'.
-- 

# p.d.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: does raw_input() return unicode?

2006-10-12 Thread Neil Cerutti
On 2006-10-11, Martin v. Löwis [EMAIL PROTECTED] wrote:
 Neil Cerutti schrieb:
 I'm all mindboggley. Just when I thought I was starting to
 understand how this character encoding stuff works. Are
 PythonWin's stdout and stdin implementations is incomplete?

 Simple and easy: yes, they are.

Oh, phew!

-- 
Neil Cerutti
Any time I've taken the mound, it's always been the old
Samson-and-Goliath story written about me. --Randy Johnson
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Standard Forth versus Python: a case study

2006-10-12 Thread Fredrik Lundh
Peter Decker wrote:

 Also, that finds the maximum, not the median.  I had stopped examining
 it after seeing it used more than one variable.

 Um... isn't 'p' the list in question?

no, it's a pointer to the current item in the list.

/F 



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


Re: Standard Forth versus Python: a case study

2006-10-12 Thread bearophileHUGS
Ian McConnell wrote:
  If you can use Psyco and your FITS lines are really long (well, maybe
  too much, the treshold if about ~3000 in my PC) you can use something
  like this instead the builtin timsort:
  http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/466330
  (To compute the median on a image line the median that uses sort is
  probably better in most cases, expecially if you use the built in sort
  of numerical libraries.)

 sort() sorts all of the data, but you're only after one or two numbers, so
 the MODFIND method may be faster for the median:

The modified quicksort I have shown in the cookbook (466330) is O(n)
too, and it modifies the list in place, so you can apply it twice for
lists of even len.

Bye,
bearophile

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


Re: operator overloading + - / * = etc...

2006-10-12 Thread Terry Reedy

Bruno Desthuilliers [EMAIL PROTECTED] wrote in message 
news:[EMAIL PROTECTED]
 Terry Reedy wrote:
 Bruno Desthuilliers [EMAIL PROTECTED] wrote in message
 news:[EMAIL PROTECTED]
 The current namespace object, of course.

 Implementing a namespace as a Python object (ie, dict) is completely
 optional and implementation dependent.  For CPython, the local namespace 
 of
 a function is generally *not* done that way.

 I know this, and that's not the point here. The op's question seemed to
 imply that the hypothetical __assign__ method should belong to the rhs
 object, which is obviously not the case - it must of course belongs to
 the lhs 'object'.

And my point is that in general there is no lhs object for the method to 
belong to.




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


Assigning different Exception message

2006-10-12 Thread Tor Erik Soenvisen
try:
self.cursor.execute(sql)
except AttributeError, e:
if e.message == oracleDB instance has no attribute 'cursor':
e.message = 'oracleDB.open() must be called before' + \
' oracleDB.query()'
raise AttributeError, e

This code does not re-assign e's message when the conditional is satisfied. 
Why not?

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


Re: How to be a good programmers?

2006-10-12 Thread Gasikara

I have already started to learn the language (python) since  4 months,
I love this language program! I have read some of example of zope and I
see that it look like with html programming , so I don't need to learn
again this things.

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


Re: Assigning different Exception message

2006-10-12 Thread Peter Otten
Tor Erik Soenvisen wrote:

 try:
 self.cursor.execute(sql)
 except AttributeError, e:
 if e.message == oracleDB instance has no attribute 'cursor':
 e.message = 'oracleDB.open() must be called before' + \
 ' oracleDB.query()'
 raise AttributeError, e
 
 This code does not re-assign e's message when the conditional is
 satisfied. Why not?

It does, but e.args is used to generate the message shown:

 try:
... None.not_there
... except AttributeError, e:
... e.args = (whatever,)
... raise e
...
Traceback (most recent call last):
  File stdin, line 5, in module
AttributeError: whatever

However, I would prefer to rewrite your snippet along the lines:

try:
cursor = self.cursor
except AttributeError:
raise EriksCustomError(oracleDB.open()...)
else:
cursor.execute(sql)

Peter

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


Re: How to be a good programmers?

2006-10-12 Thread Gasikara

[EMAIL PROTECTED] wrote:
 [EMAIL PROTECTED] wrote:
  I just started to learn python programming because I need to be in the
  group when google come in Madagascar, So I want to know, what kind of
  python programming I have to start to learn? Zope?...?
  Sorry for My english! You can writ me on [EMAIL PROTECTED]
  thanks!

 Let me know and I can get you some expierence using some of pythons
 functions that you can build your resume with.  My goal is to be
 featured in csound journal or at least www.csounds.com

 https://sourceforge.net/project/showfiles.php?group_id=156455
 http://www.dexrow.com

 He is either a satinist or some kind of programmer with that snake
 book quote (C) 2006

OKAY, I will look this

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


Click and Drag Functionality in Web Apps with Python

2006-10-12 Thread Wijaya Edward

Hi,
 
Some recent webapps like Kiko http://www.kiko.com/ , Google's gadget 
http://www.google.com/ig/directory?hl=en , and spreadsheets 
http://spreadsheets.google.com  to name a few, 
have this functionality. 

I wonder how can this funcitonalities be implemented in Python. 
Do you guys have any experience with it?
Any Python module that support that?
 
Regards,
Edward WIJAYA
SINGAPOE

 Institute For Infocomm Research - Disclaimer -
This email is confidential and may be privileged.  If you are not the intended 
recipient, please delete it and notify us immediately. Please do not copy or 
use it for any purpose, or disclose its contents to any other person. Thank you.

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


Re: Standard Forth versus Python: a case study

2006-10-12 Thread Paul McGuire
[EMAIL PROTECTED] wrote in message 
news:[EMAIL PROTECTED]
 Paul McGuire wrote:
 [EMAIL PROTECTED] wrote in message
 news:[EMAIL PROTECTED]
  [snip]
 
  no sort() is needed to calculate the median of a list.
 
  you just need one temp var.
 

 Ok, I'll bite.  How do you compute the median of a list using just a 
 single
 temp var?

 -- Paul

 hi Paul; well when this was a stats-class assignment (back when pascal
 was popular :) i just stepped through the vector and compared it

 (pseudo-code)

 ptr p = [with values].

 fun median {
 var x = 0.
  while( *p++) {
if( (*p)  x) x = *p.
  }
  return x.
 }

 of course, pascal is more verbose but that's median()


No, that's the maximum.  The median value is the value that is in the middle 
of the list when the list is sorted.  Many analyses prefer median to mean 
(also known as average) because the median is less sensitive to wild 
outlier points.

My original question was in response to your post, that sort() wasn't 
required but only a temp variable.  I am very interested in seeing your 
solution that does not require the data to be sorted.  (This is not just an 
academic exercise - given a large historical data set, sorting the data is 
one of the costliest parts of computing the median, and I would greatly 
appreciate seeing an alternative algorithm.)

-- Paul 


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


Re: httplib/DAV: How to respond to WWW-Authenticate: NTLM ?

2006-10-12 Thread Steve Holden
robert wrote:
 In a DAV scheme with PROPFIND or GET (PROPFIND /test/ HTTP/1.1)  and 
 Basic AUTH to a MS SharePoint over https server (AUTH required), he 
 responds 'WWW-Authenticate: NTLM' only:
 
 reply: 'HTTP/1.1 401 Unauthorized\r\n'
 header: Content-Length: 1656
 header: Content-Type: text/html
 header: Server: Microsoft-IIS/6.0
 header: WWW-Authenticate: NTLM
 header: X-Powered-By: ASP.NET
 header: MicrosoftSharePointTeamServices: 6.0.2.6568
 header: Date: Thu, 12 Oct 2006 12:27:42 GMT
 
 
 I simply try repeatedly the same request with Basic Auth header again = 
 The same response requesting 'header: WWW-Authenticate: NTLM' again.
 
 But then after an unsuccessful test on a really new connection (.close() 
 , .request()) he accepts the Basic AUTH immediately.
 
 * What is this?
 * Is this a legal/known way to respond to a NTLM AUTH request by 
 ..close() and reconnect with Basic Auth?
 * Is there a Python function out there to do real NTLM authentication?.. 
 and is this recommended to dig into Microsofty HTTP protocols ?
 
 
 -robert

The protocol is described in

   http://www.innovation.ch/personal/ronald/ntlm.html

though you may need to consult other documents to get the full details. 
It seems there may be a Python implementation at

   http://ntlmaps.sourceforge.net/

At a pinch you could just use the proxy.

regards
  Steve
-- 
Steve Holden   +44 150 684 7255  +1 800 494 3119
Holden Web LLC/Ltd  http://www.holdenweb.com
Skype: holdenweb   http://holdenweb.blogspot.com
Recent Ramblings http://del.icio.us/steve.holden

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


Pickling an instance of a class containing a dict doesn't work

2006-10-12 Thread Marco Lierfeld
Hello there,

I want to save an instance of a class containing a dictionary with the
pickle-module.

The class looks like this:
class subproject:
configuration   = {}
build_steps = []
# some functions
# ...

Now I create an instance of this class, e.g.
test = subproject()
and try to save it with pickle.dump(test, file('test.pickle','wb')) or with
pickle.Pickler(file('test.pickle','wb')).save(test) it looks like
everything has worked well, but in the saved file 'test.pickle' only the
list 'build_steps' is saved - the dictionary 'configuration' is missing.
There is wether an error-message nor an exception.

When I try to save only the dictionary, there is no problem at all - the
dict is saved to the file.

I also tried the 3 different protocols (0, 1, 2), but none of them worked
for me.

I hope somebody knows what to do ;)

Thanks for reading

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


Re: Click and Drag Functionality in Web Apps with Python

2006-10-12 Thread Steve Holden
Wijaya Edward wrote:
 Hi,
  
 Some recent webapps like Kiko http://www.kiko.com/ , Google's gadget 
 http://www.google.com/ig/directory?hl=en , and spreadsheets 
 http://spreadsheets.google.com  to name a few, 
 have this functionality. 
 
 I wonder how can this funcitonalities be implemented in Python. 
 Do you guys have any experience with it?
 Any Python module that support that?
  
 Regards,
 Edward WIJAYA
 SINGAPOE
 

In order for your request to make sense Python would have to be 
available as a browser programming language. This has been done (by Mark 
Hammond as part of the win32all extensions), but for security reasons it 
is no longer installed by default, and it's not sufficiently widespread 
to make such solutions really worthwhile.

If you are talking about web servers *delivering* such interactive code, 
then there is no inherent difference between Python and other web 
servers - they just deliver the interactive code to the browser. Bob 
Ippolito's MochiKit is quite Pythonic in nature.

regards
  Steve
-- 
Steve Holden   +44 150 684 7255  +1 800 494 3119
Holden Web LLC/Ltd  http://www.holdenweb.com
Skype: holdenweb   http://holdenweb.blogspot.com
Recent Ramblings http://del.icio.us/steve.holden

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


Re: Standard Forth versus Python: a case study

2006-10-12 Thread Fredrik Lundh
Paul McGuire wrote:

 My original question was in response to your post, that sort() wasn't 
 required but only a temp 
 variable.  I am very interested in seeing your solution that does not require 
 the data to be 
 sorted.  (This is not just an academic exercise - given a large historical 
 data set, sorting the 
 data is one of the costliest parts of computing the median, and I would 
 greatly appreciate seeing 
 an alternative algorithm.)

if you absolutely definitely cannot afford to modify or copy the input data 
set, but can
read the data sequentially multiple times reasonably fast, you can do what's 
basically a
binary search for the median, by counting how many values you have that's above 
or
below the current guess, and repeating until you find the right value.  see e.g.

http://ndevilla.free.fr/median/median/src/torben.c

/F 



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


Re: error handling

2006-10-12 Thread Fulvio
On Thursday 12 October 2006 04:47, Gabriel Genellina wrote:
 |Why not refer to the *current* documentation?

Gabriel,

Thank you, some time I (we) forget to look at the most obvious place ;)
Meanwhile yesterday I found some useful info on the web, which an *except* 
statement needs a string object or class for a named exception.
Now I got the meaning and  sys.exc_info()[0] Bernard's idea is useful to 
fish out more clues.

F

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


Re: prefix search on a large file

2006-10-12 Thread js
Thank you for the quick reply.

Here're the exact code I executed. (including your code)

#!/usr/bin/env python
from pprint import pprint as pp

data = [
   'foo bar baz',
   'foo bar',
   'foo',
   'food',
   'food', # duplicate
   'xyzzy',
   'plugh',
   'xyzzy and plugh are magic',
   '',
   ]

data_sorted_by_len = sorted(data, key=len)
data_sorted_by_asc = sorted(data)
print OP trial 1 input; pp(data)

def prefixdel_stupidly(alist):
for line in alist[:]:
unneeded = [no for no, line2 in enumerate(alist[1:]) if
line2.startswith(line) and line != line2]
adjust=1
for i in unneeded:
del alist[i+adjust]
adjust -= 1
return alist

def prefixdel_recursively(alist):
if len(alist)  2:
return alist

unneeded = [no for no, line in enumerate(alist[1:]) if
line.startswith(alist[0])]
adjust=1
for i in unneeded:
del alist[i+adjust]
adjust -= 1

return [alist[0]] + prefixdel_recursively(alist[1:])

def prefixdel_by_john(alist):
olist = []
for i in xrange(len(alist)-1, 0, -1):
if alist[i].startswith(alist[i-1]):
continue
olist.append(alist[i])
olist.append(alist[0])
return olist

if __name__ == '__main__':
from timeit import Timer
print sorted(prefixdel_stupidly(data_sorted_by_len[:]))
print sorted(prefixdel_recursively(data_sorted_by_len[:]))
print sorted(prefixdel_by_john(data_sorted_by_asc[:]))

t = Timer(prefixdel_stupidly(data_sorted_by_len), from __main__
import prefixdel_stupidly, data_sorted_by_len)
print t.timeit(number=10)
t = Timer(prefixdel_recursively(data_sorted_by_len), from
__main__ import prefixdel_recursively, data_sorted_by_len)
print t.timeit(number=10)
t = Timer(prefixdel_by_john(data_sorted_by_asc), from __main__
import prefixdel_by_john, data_sorted_by_asc)
print t.timeit(number=10)

The output is the following:

$ python2.5 myprefixdel.py
OP trial 1 input
['foo bar baz',
 'foo bar',
 'foo',
 'food',
 'food',
 'xyzzy',
 'plugh',
 'xyzzy and plugh are magic',
 '']
['foo', 'plugh', 'xyzzy', '']
['foo', 'plugh', 'xyzzy', '']
['foo', 'food', 'plugh', 'xyzzy', '']
1.17837095261
1.21182584763
0.737352132797

Your code is much faster than ones I wrote
but the result is a little bit different.('food' shoud be removed
because 'foo' is in the list)

As you pointed out, list[:] must be a big evil but without duplicating the list,
the problem become much harder to solve to me.

Any practical solution, anyone?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Standard Forth versus Python: a case study

2006-10-12 Thread Paul Rubin
Paul McGuire [EMAIL PROTECTED] writes:
 My original question was in response to your post, that sort() wasn't 
 required but only a temp variable.  I am very interested in seeing your 
 solution that does not require the data to be sorted.  (This is not just an 
 academic exercise - given a large historical data set, sorting the data is 
 one of the costliest parts of computing the median, and I would greatly 
 appreciate seeing an alternative algorithm.)

There are well known algorithms for finding the median in expected
O(n) time, the most straightforward of which is a modified quicksort.
You do the traditional quicksort pivot step, figure out which
partition the median is in, and recurse on just that partition instead
of on both of them.  Expected running time is n + n/2 + n/4 + ...
which is approx 2n.

Tarjan discovered a guaranteed O(n) algorithm in the 1970's(?) whose
operation is much different and quite complex.  But all of these need
more than one temp var.  See an algorithms book like CLRS or Knuth
for more info.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Pickling an instance of a class containing a dict doesn't work

2006-10-12 Thread Jon Clements

Marco Lierfeld wrote:

 The class looks like this:
 class subproject:
 configuration   = {}
 build_steps = []
 # some functions
 # ...

 Now I create an instance of this class, e.g.
 test = subproject()
 and try to save it with pickle.dump(test, file('test.pickle','wb')) or with
 pickle.Pickler(file('test.pickle','wb')).save(test) it looks like
 everything has worked well, but in the saved file 'test.pickle' only the
 list 'build_steps' is saved - the dictionary 'configuration' is missing.
 There is wether an error-message nor an exception.

 When I try to save only the dictionary, there is no problem at all - the
 dict is saved to the file.

 I also tried the 3 different protocols (0, 1, 2), but none of them worked
 for me.

At a wild guess. Since pickle descends the objects hierarchy, and since
configuration and build_steps aren't local to an instance of a class,
it stores only a reference to them (so you won't see values). However,
if you change the above to:

class subproject:
def __init__(self):
configuration = { }
build_steps = [ ]

That'll probably be what you expect...

Jon.

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


Re: Pickling an instance of a class containing a dict doesn't work

2006-10-12 Thread Jon Clements

Jon Clements wrote:

 if you change the above to:

 class subproject:
 def __init__(self):
 configuration = { }
 build_steps = [ ]

Of course, I actually meant to write self.configuration and
self.build_steps; d0h!

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


Re: Pickling an instance of a class containing a dict doesn't work

2006-10-12 Thread Paul McGuire
Marco Lierfeld [EMAIL PROTECTED] wrote in message 
news:[EMAIL PROTECTED]
 Hello there,

 I want to save an instance of a class containing a dictionary with the
 pickle-module.

 The class looks like this:
class subproject:
configuration   = {}
build_steps = []
# some functions
# ...

 Now I create an instance of this class, e.g.
test = subproject()
 and try to save it with pickle.dump(test, file('test.pickle','wb')) or 
 with
 pickle.Pickler(file('test.pickle','wb')).save(test)

I'm guessing that configuration and build_steps are supposed to be instance 
variables, not class-level variables.  It would be interesting to see what 
your __init__ method looks like.  I'm guessing you assign something the 
self.build_steps in __init__, but self.configuration is omitted.

Try moving these initializers into the __init__ method, as:
class subproject:
def __init__(self):
self.configuration   = {}
self.build_steps = []

and see if pickle starts behaving better.

-- Paul



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


Re: Click and Drag Functionality in Web Apps with Python

2006-10-12 Thread Bernard
I'd say they use javascript to make a click and drag function.
Like this jquery interface example:
http://interface.eyecon.ro/demos/drag.html

So basically, you could use a python web framework like
Turbogears(http://www.turbogears.org/) or
Django(http://www.djangoproject.com/) with javascript to create such
effects.

Bernard

Wijaya Edward wrote:
 Hi,

 Some recent webapps like Kiko http://www.kiko.com/ , Google's gadget 
 http://www.google.com/ig/directory?hl=en , and spreadsheets 
 http://spreadsheets.google.com  to name a few,
 have this functionality.

 I wonder how can this funcitonalities be implemented in Python.
 Do you guys have any experience with it?
 Any Python module that support that?

 Regards,
 Edward WIJAYA
 SINGAPOE

  Institute For Infocomm Research - Disclaimer -
 This email is confidential and may be privileged.  If you are not the 
 intended recipient, please delete it and notify us immediately. Please do not 
 copy or use it for any purpose, or disclose its contents to any other person. 
 Thank you.
 

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


Re: Standard Forth versus Python: a case study

2006-10-12 Thread Paul Rubin
Paul Rubin http://[EMAIL PROTECTED] writes:
 Tarjan discovered a guaranteed O(n) algorithm in the 1970's(?) whose
 operation is much different and quite complex.  But all of these need
 more than one temp var.  See an algorithms book like CLRS or Knuth
 for more info.

Ehh, make that Blum, Floyd, Pratt, Rivest, and Tarjan, and the main
different part is selecting the pivot, plus the complexity analysis.

http://www.cs.cmu.edu/afs/cs.cmu.edu/academic/class/15451-f06/www/lectures/lect0907.pdf

http://en.wikipedia.org/wiki/Selection_algorithm (see median of
medians algorithm)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Standard Forth versus Python: a case study

2006-10-12 Thread Paul McGuire

Fredrik Lundh [EMAIL PROTECTED] wrote in message 
news:[EMAIL PROTECTED]
 Paul McGuire wrote:

 My original question was in response to your post, that sort() wasn't 
 required but only a temp variable.  I am very interested in seeing your 
 solution that does not require the data to be sorted.  (This is not just 
 an academic exercise - given a large historical data set, sorting the 
 data is one of the costliest parts of computing the median, and I would 
 greatly appreciate seeing an alternative algorithm.)

 if you absolutely definitely cannot afford to modify or copy the input 
 data set, but can
 read the data sequentially multiple times reasonably fast, you can do 
 what's basically a
 binary search for the median, by counting how many values you have that's 
 above or
 below the current guess, and repeating until you find the right value. 
 see e.g.

http://ndevilla.free.fr/median/median/src/torben.c

 /F

Thanks!

-- Paul


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


Re: People's names

2006-10-12 Thread Antoon Pardon
On 2006-10-11, Theerasak Photha [EMAIL PROTECTED] wrote:
 On 10/10/06, Piet van Oostrum [EMAIL PROTECTED] wrote:
  Roel Schroeven [EMAIL PROTECTED] (RS) wrote:

 RS It's the same here in Belgium. Except that our Van is with a capital V 
 in
 RS most cases; if it's a lower v it either indicates nobility or a Dutch 
 name.

 RS I don't see it as a problem. I prefer having Van Straeten and Van 
 Stralen
 RS next to each other than having them mixed up with names without Van like
 RS this:
 RS Straeten, Van
 RS Straetmans
 RS Stralen, Van

 In Holland it is sorted without the 'van' 'de' etc.

 Which was my original point in mentioning similar Portuguese names. :)

But in Belgium (That includes the flemisch region) names are sorted
with the 'van' 'de' etc. De reason is rather simple. If you hear
someone's name as Van den Hautte, you have no idea how it is spelled

  Van Den Haute
  Vandenhaute
  Vanden Haute

These are all possible. Now I think you can hardly sort Vandenhaute
next to haute because then you would need to know al kind of
prefixes that may be also written seperately. So by putting all these
names together it makes for easier searching in case you have doubts
on how the name is actually written.

 BTW, do Dutch/Flemish family names now follow the trend of dropping
 declension, as seen in both languages (dialects?) in general: e.g.,
 'de' instead of 'der'?

Yes but not in names (at least in Flemish families)

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


Re: Standard Forth versus Python: a case study

2006-10-12 Thread Neil Cerutti
On 2006-10-12, Paul Rubin http wrote:
 Tarjan discovered a guaranteed O(n) algorithm in the 1970's(?)

Huhn!  I thought Tarjan was just the big bad evil guy in Bard's
Tale 2 who was creating eternal winter.  I'm glad he also
contributed to our stock of *useful* algorithms.

-- 
Neil Cerutti
We will not have an all volunteer army.  We *will* have an all
volunteer army. --George W. Bush
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: is there an easy way to create a database on the fly and let the user input values

2006-10-12 Thread Chris Lambacher
I've heard good things about Dabo: http://dabodev.com/
On Wed, Oct 11, 2006 at 09:44:37PM -0700, [EMAIL PROTECTED] wrote:
  I don't realy care what database I use wx.grid or whatever.  I
 wan't it to look at a line
 
 128 9023 23428 exc and create the database or pick something out of the
 file as  some sort of a descrition line and then display and allow the
 user to change and add new lines.  What is the easiest set of database
 routines to use for such a project???
 
 http://www.dexrow.com
 
 -- 
 http://mail.python.org/mailman/listinfo/python-list
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Pickling an instance of a class containing a dict doesn't work

2006-10-12 Thread Marco Lierfeld
Jon Clements wrote:

 if you change the above to:

 class subproject:
 def __init__(self):
 configuration = { }
 build_steps = [ ]
 
 Of course, I actually meant to write self.configuration and
 self.build_steps; d0h!

Thank you Jon and Paul, you both were 100% right :) 

But I still don't understand, why the list was saved and the dict was not...
confusing ;)

Bye,
Marco
-- 
http://mail.python.org/mailman/listinfo/python-list


Compile python on Solaris 64bit

2006-10-12 Thread Martijn de Munnik
Hi,

I want to compile python on my solaris 10 system (amd 64 bit).

I did the following:

./configure --prefix=/opt/64/python
make

which resulted in this error:
Include/pyport.h, line 730: #error: LONG_BIT definition appears wrong
for platform (bad gcc/glibc config?).

so I edited the file and removed the error line and did a configure and
make again after a make distclean.

after a new make I get this error complaining about 32 and 64 bit.

ld: fatal: file Parser/acceler.o: wrong ELF class: ELFCLASS32

when I look to the cc statements none of my CFLAGS are passed while these
are in my environment;

CC=cc
CFLAGS=-xO3 -mt -fsimple=1 -ftrap=%none -nofstore -xbuiltin=%all -xlibmil
-xlibmopt -xtarget=opteron -xarch=amd64 -xregs=no%frameptr
CXX=CC
CXXFLAGS=-xO3 -mt -fsimple=1 -ftrap=%none -nofstore -xbuiltin=%all
-xlibmil -xlibmopt -xtarget=opteron -xarch=amd64 -xregs=no%frameptr
LDFLAGS=-xtarget=opteron -xarch=amd64


anybody succesfully compiled python on solaris?

thanks,
martijn

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


Re: Compile python on Solaris 64bit

2006-10-12 Thread casevh

Martijn de Munnik wrote:
 Hi,

 I want to compile python on my solaris 10 system (amd 64 bit).

 I did the following:

 ./configure --prefix=/opt/64/python
 make

 which resulted in this error:
 Include/pyport.h, line 730: #error: LONG_BIT definition appears wrong
 for platform (bad gcc/glibc config?).

 so I edited the file and removed the error line and did a configure and
 make again after a make distclean.

 after a new make I get this error complaining about 32 and 64 bit.

 ld: fatal: file Parser/acceler.o: wrong ELF class: ELFCLASS32

 when I look to the cc statements none of my CFLAGS are passed while these
 are in my environment;

 CC=cc
 CFLAGS=-xO3 -mt -fsimple=1 -ftrap=%none -nofstore -xbuiltin=%all -xlibmil
 -xlibmopt -xtarget=opteron -xarch=amd64 -xregs=no%frameptr
 CXX=CC
 CXXFLAGS=-xO3 -mt -fsimple=1 -ftrap=%none -nofstore -xbuiltin=%all
 -xlibmil -xlibmopt -xtarget=opteron -xarch=amd64 -xregs=no%frameptr
 LDFLAGS=-xtarget=opteron -xarch=amd64


 anybody succesfully compiled python on solaris?

I have compiled Python 2.5 successfully on 32-bit Intel platform. After
running configure, I had to manually edit the generated Makefile to add
the contents of CFLAGS.

I've had difficulties with ctypes, too. To get a successful compile, I
had to edit ffitarget.h (I think) and also use the Sun Studio Express 2
compiler suite. Or use gcc.

 
 thanks,
 martijn

casevh

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


What is python(abi)?

2006-10-12 Thread Mandy.Lialie
Hi,
I have search it for quite a long time. But I still can't get it.
When I attempt to install yum and others, it always embarrasses me.
It says python(abi) = 2.4 is need.
I have version 2.4 at first. But have a try version 2.5, remove 2.4.
Both work well, and do well with wx.

OS: FC5
THX.
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Standard Forth versus Python: a case study

2006-10-12 Thread John Doty
Paul McGuire wrote:
 [EMAIL PROTECTED] wrote in message 
 news:[EMAIL PROTECTED]
 Paul McGuire wrote:
 [EMAIL PROTECTED] wrote in message
 news:[EMAIL PROTECTED]
 [snip]

 no sort() is needed to calculate the median of a list.

 you just need one temp var.

 Ok, I'll bite.  How do you compute the median of a list using just a 
 single
 temp var?

 -- Paul
 hi Paul; well when this was a stats-class assignment (back when pascal
 was popular :) i just stepped through the vector and compared it

 (pseudo-code)

 ptr p = [with values].

 fun median {
 var x = 0.
  while( *p++) {
if( (*p)  x) x = *p.
  }
  return x.
 }

 of course, pascal is more verbose but that's median()

 
 No, that's the maximum.  The median value is the value that is in the middle 
 of the list when the list is sorted.  Many analyses prefer median to mean 
 (also known as average) because the median is less sensitive to wild 
 outlier points.
 
 My original question was in response to your post, that sort() wasn't 
 required but only a temp variable.  I am very interested in seeing your 
 solution that does not require the data to be sorted.  (This is not just an 
 academic exercise - given a large historical data set, sorting the data is 
 one of the costliest parts of computing the median, and I would greatly 
 appreciate seeing an alternative algorithm.)

Here's a KR C function I wrote almost 20 years ago. It's a general 
purpose quantile. The essential idea is to choose an element at random 
(thus mostly avoiding perverse behavior with already sorted data) and 
divide the set into two pieces around it. Then you figure out which 
piece contains the quantile you want, and what quantile it is within 
that piece, and recurse. When you see enough identical elements in the 
piece you're processing, it's done. In the extreme case you'll get down 
to one element.

ixrand(n) generates a random integer in the range 0..n-1. I think that's 
the only nonstandard function used.

The style is torqued by what Unisoft C could and couldn't optimize: I 
wouldn't write it quite like that today. One of my students pointed out 
that all of the recursion is tail recursion so it should be easy to 
flatten. Left as an exercise to the reader...

Somewhere, in Knuth I think, I saw a somewhat similar algorithm that 
promised a little better performance by estimating the median from a 
sample of the data, breaking the data up there, and then looking for a 
quantile (statistically guaranteed to be) close to the min or max of one 
of the subsets.

It shouldn't be hard to recode in Python, Forth, or whatever. That 
wasn't my purpose in the exercise that started the thread though: I 
wanted to see if I could import modules good enough to do the job from 
public sources. In Python I could, and the entire image processing 
program is 15 lines. In Forth I couldn't.

Anyway, here it is:

/* Find the nth from the minimum value in an array */
/* Monte Carlo method intended for finding medians */
/* 2/13/85 jpd */

/* For random data, this routine takes about */
/* 2.6*numdata + O( log( numdata )) comparisons */
/* If the data is tightly clustered about the mean, */
/* there is a speedup; it may take as few as
/* 0.5*numdata comparisons. */
/* There is a slight penalty if the array is completely */
/* or partially sorted; it is at most 25%. */

/* NTH will be nthi, nths, etc., depending on DATATYPE */

NTH( data, numdata, n )
DATATYPE data[];/* Data array (will be scrambled on return) */
int numdata;/* lemgth of data array */
int n;  /* index if item to find:
   1 = n = numdata */
{
register DATATYPE boundary, thisdata;
register DATATYPE *lowp, *highp;
DATATYPE v1, v2;
int nlowbin;

lowp = data;/* Init data pointer */

v1 = data[ ixrand( numdata )];
{
register DATATYPE v1r = v1;
int nc = 1 + numdata - n;   /* Complement of n */

if( nc  n )
highp = lowp + nc;
else
highp = lowp + n;   /* Limit to test for done */

/* Scan for the first point which
   doesn't match the boundary point.
   If we encounter enough
   matching points,
   the boundary is the answer */
while( *lowp++ == v1r ) {
if( lowp = highp ) return( v1r );
}
v2 = *--lowp;   /* Back up to get point */
}

boundary = ( v1  1 ) + ( v2  1 );   /* Beware overflows */

highp = data + numdata; /* Now process the whole thing */
thisdata = *lowp;   /* Prime the pump */

if( v2  v1 ) { /* Bin 2 is low bin */
  

Re: What is python(abi)?

2006-10-12 Thread Fredrik Lundh
Mandy.Lialie wrote:

 I have search it for quite a long time. But I still can't get it.
 When I attempt to install yum and others, it always embarrasses me.
 It says python(abi) = 2.4 is need.

afaik, python(api) is a psuedo-package that's used for dependency manage-
ment in Red Hat and Fedora distributions.  installing the corresponding Python
package should make sure that python(abi) is also available.

 I have version 2.4 at first. But have a try version 2.5, remove 2.4.
 Both work well, and do well with wx.

not sure what you're saying here.

/F 



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


Re: Standard Forth versus Python: a case study

2006-10-12 Thread Neal Bridges
John Doty [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
[snip]
 Here's a KR C function I wrote almost 20 years ago.
[code snipped]

John, 'man indent' right away!

-- 
Neal Bridges
http://quartus.net  Home of Quartus Forth for the Palm OS!


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


Re: prefix search on a large file

2006-10-12 Thread js
By eliminating list cloning, my function got much faster than before.
I really appreciate you, John.

def prefixdel_recursively2(alist):
if len(alist)  2:
return alist

first = alist.pop(0)
unneeded = [no for no, line in enumerate(alist) if line.startswith(first)]
adjust=0
for i in unneeded:
del alist[i+adjust]
adjust -= 1

return [first] + prefixdel_recursively(alist)


process stime
prefixdel_stupidly : 11.9247150421
prefixdel_recursively   : 14.6975700855
prefixdel_recursively2 : 0.408113956451
prefixdel_by_john: 7.60227012634
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python 2.5 sqlite3

2006-10-12 Thread John Salerno
Fredrik Lundh wrote:

 I still think the get the official build (and add win32all if you're 
 doing native windows stuff) advice is sound, though.

Agreed. It seems silly to use anything other than the official release.

But anyway, I think the OP was confused about having to install the 
sqlite libraries manually, because I believe you have to do this on 
Linux distros, but a Windows binary of Python already includes all you 
need to work with sqlite3.

Now, if the ActiveState distro *doesn't* include the libraries, then I 
would probably call it broken too. :)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Compile python on Solaris 64bit

2006-10-12 Thread Alan Franzoni
Il Thu, 12 Oct 2006 16:46:19 +0200 (CEST), Martijn de Munnik ha scritto:

 Hi,
 
 I want to compile python on my solaris 10 system (amd 64 bit).

Just a question... AFAIK, Solaris 10 64 bit includes binaries  kernels for
both 64 bit and 32 bit machines. Which binaries are you actually using? I
think there could be some configuration mismatch between running binaries
and environment variables that could confuse the compiler.

-- 
Alan Franzoni [EMAIL PROTECTED]
-
Togli .xyz dalla mia email per contattarmi.
Rremove .xyz from my address in order to contact me.
-
GPG Key Fingerprint:
5C77 9DC3 BD5B 3A28 E7BC 921A 0255 42AA FE06 8F3E 
-
Blog: http://laterradeglieroi.verdiperronchi.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: operator overloading + - / * = etc...

2006-10-12 Thread OKB (not okblacke)
Terry Reedy wrote:

 Implementing a namespace as a Python object (ie, dict) is
 completely optional and implementation dependent.  For CPython, the
 local namespace of a function is generally *not* done that way.

Sure, but this is all just theoretical talk anyway, right?  I would 
like to see more control over the name-binding operation, and exposing 
the namespace as an object sounds like an interesting way to do this.

-- 
--OKB (not okblacke)
Brendan Barnwell
Do not follow where the path may lead.  Go, instead, where there is
no path, and leave a trail.
--author unknown
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python 2.5 sqlite3

2006-10-12 Thread Fredrik Lundh
John Salerno wrote:

 Now, if the ActiveState distro *doesn't* include the libraries, then I 
 would probably call it broken too. :)

if it doesn't, it wouldn't be the first time they'd (by accident or on 
purpose) left things out.  trust me, it'd cause a lot less confusion if 
ActivePython was a true superset of the python.org distribution.

/F

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


Wing IDE 2.1.3 released

2006-10-12 Thread Wingware Announce
Hi,

We're happy to announce version 2.1.3 of Wing IDE, an advanced
development environment for the Python programming language.

This is a bug fix release that fixes debugger support for 
Python 2.5 final, improves VI mode and multi-file replace,
and adds support for Subversion 1.4, among other things.

The release can be downloaded from:

http://wingware.com/downloads

A detailed list of changes is available here:

http://wingware.com/pub/wingide/2.1.3/CHANGELOG.txt

Wing IDE provides powerful debugging, editing, code intelligence,
and search capabilities that reduce development and debugging
time, cut down on coding errors, and make it easier to understand
and navigate Python code.

Highlights of Wing IDE 2.1:

* Professional quality code editor
* Visual Studio, VI/Vim, Emacs, and Brief key bindings
* Auto-completion, call tips, and source browser
* Graphical debugger for Python, Zope, and Plone
* Subversion, CVS, and Perforce integration
* Powerful search interface
* User-extensible with Python scripts
* Templates (code snippets), bookmarks, folding, macros, and more

Some features are available in Wing IDE Pro only -- for details
see http://wingware.com/wingide/features

This release is available for Windows (2000+), Linux, and Mac OS X
(10.3+ with X11 installed) and can be compiled from sources on *BSD,
Solaris, and other Posix operating systems.

For more information see:

Product Info:   http://wingware.com/products
Sales:  http://wingware.com/store/purchase

Sincerely,

The Wingware Team 


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


Re: Click and Drag Functionality in Web Apps with Python

2006-10-12 Thread Bruno Desthuilliers
Wijaya Edward wrote:
 Hi,
  
 Some recent webapps like Kiko http://www.kiko.com/ , Google's gadget 
 http://www.google.com/ig/directory?hl=en , and spreadsheets 
 http://spreadsheets.google.com  to name a few, 
 have this functionality. 
 
 I wonder how can this funcitonalities be implemented in Python. 

I wonder too !-)

Seriously: this is done with Javascript, not Python. But if you're
looking for a Python web framework making such things easy, then Pylons
is for you:
http://pylonshq.com/docs/0.9.2/quick_wiki.html#delete
http://pylonshq.com/project/pylonshq/wiki/AjaxGettingStarted

HTH

-- 
bruno desthuilliers
python -c print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in '[EMAIL PROTECTED]'.split('@')])
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to be a good programmers?

2006-10-12 Thread Bruno Desthuilliers
Gasikara wrote:
 I have already started to learn the language (python) since  4 months,
 I love this language program! I have read some of example of zope and I
 see that it look like with html programming, 

Well... Zope being a web app server, this may not be that surprising.
Now there's much more to Zope and web programming than just html.

 so I don't need to learn
 again this things.
 


-- 
bruno desthuilliers
python -c print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in '[EMAIL PROTECTED]'.split('@')])
-- 
http://mail.python.org/mailman/listinfo/python-list


numpy slice: create view, not copy

2006-10-12 Thread K. Jansma
Hi,

given an array:

import numpy
a = numpy.arange(100).reshape((10,10))
print a

[[ 0  1  2  3  4  5  6  7  8  9]
 [10 11 12 13 14 15 16 17 18 19]
 [20 21 22 23 24 25 26 27 28 29]
 [30 31 32 33 34 35 36 37 38 39]
 [40 41 42 43 44 45 46 47 48 49]
 [50 51 52 53 54 55 56 57 58 59]
 [60 61 62 63 64 65 66 67 68 69]
 [70 71 72 73 74 75 76 77 78 79]
 [80 81 82 83 84 85 86 87 88 89]
 [90 91 92 93 94 95 96 97 98 99]]


I'd like to create a new array that is a view of a, i.e. it shares data. If
a is updated, this new array should be automatically 'updated'.

e.g. the array west should be a view of a that gives the element at the left
of location i,j in a.
a[i,j] = west[i,j+1]

west can be created using:

a[:,range(-1,a.shape[1]-1)]

As you can see, this also defines periodic boundaries (i.e. west[0,0] = 9)
but it seems that this returns a copy of a, not a view.
How can I change the slice definition in such a way it returns a view?

Thanks in advance,
Karel




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


Re: Pickling an instance of a class containing a dict doesn't work

2006-10-12 Thread Peter Otten
Marco Lierfeld wrote:

 Jon Clements wrote:
 
 if you change the above to:

 class subproject:
 def __init__(self):
 configuration = { }
 build_steps = [ ]
 
 Of course, I actually meant to write self.configuration and
 self.build_steps; d0h!
 
 Thank you Jon and Paul, you both were 100% right :)
 
 But I still don't understand, why the list was saved and the dict was
 not... confusing ;)

Chances are you have inadvertently created an /instance/ attribute
build_steps which was then saved:

s = subproject()
# ...
s.configuration[name] = my dinner # modifies the class attribute
s.build_steps = [hunt, kill, cook] # creates an instance attribute

Peter


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


Python 2.4 online certification - new items available for Beta testing

2006-10-12 Thread Randy Kraemer
There is a free Beta test of a Python 2.4 Certification test available
at Brainbench.com. They are a provider of skills-based certification
exams.
Go to the link below to find the test. It is free to take the test.

http://www.brainbench.com/xml/bb/common/testcenter/betatests.xml

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


problem including tests in unittest

2006-10-12 Thread Chris Fonnesbeck
I have a module for which I am trying to code a unit test. However,
when I run unittest.main(), I get:

In [1]: import PyMC

In [2]: PyMC.unittest.main()

--
Ran 0 tests in 0.000s

OK


This is confusing, because I have set up a class called MCMCTest that
is a sublcass of unttest.TestCase, which in turn contains a test
method. Yet, unittest seems not to be aware of it. Is there anything I
am forgetting?

Thanks,
Chris

-- 
Chris Fonnesbeck + Atlanta, GA + http://trichech.us
-- 
http://mail.python.org/mailman/listinfo/python-list


  1   2   3   >