ANN: Zenoss-0.21.1

2006-07-22 Thread Erik A. Dahl
Version 0.21.1 of Zenoss is available for download.

Major feature enhancements of this version include remote process  
monitoring using the HOST-RESOURCES-MIB, SNMP trap reception and MIB  
compilation (using libsmi).

This release also fixes zenoss bugs: #176, #177 and #185 and zenwin  
bug #189.

To download:
http://www.zenoss.org/download

Release Notes:
http://dev.zenoss.org/trac/wiki/zenoss-0.21/

Project Home:
http://www.zenoss.org/

Project Blurb:
Zenoss is a GPL licensed enterprise grade monitoring system that
provides Inventory/Configuration, Event, Performance and Availability
management in a single integrated package. It is written in Python
using the Zope web application framework and Twisted network
programming environment.  Zenoss is designed to be easy to use for a
beginner yet flexible and powerful enough for the advanced user.

Enjoy,

-EAD

Erik Dahl
CTO  Co-Founder
Zenoss, Inc.
-- 
http://mail.python.org/mailman/listinfo/python-announce-list

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


cx_Oracle 4.2

2006-07-22 Thread Anthony Tuininga
What is cx_Oracle?

cx_Oracle is a Python extension module that allows access to Oracle and
conforms to the Python database API 2.0 specifications with a few
exceptions.


Where do I get it?

http://starship.python.net/crew/atuining


What's new?

 1) Added support for parsing an Oracle statement as requested by Patrick
Blackwill.
 2) Added support for BFILEs at the request of Matthew Cahn.
 3) Added support for binding decimal.Decimal objects to cursors.
 4) Added support for reading from NCLOBs as requested by Chris Dunscombe.
 5) Added connection attributes encoding and nencoding which return the IANA
character set name for the character set and national character set in use
by the client.
 6) Rework module initialization to use the techniques recommended by the
Python documentation as one user was experiencing random segfaults due
to the use of the module dictionary after the initialization was complete.
 7) Removed support for the OPT_Threading attribute. Use the threaded keyword
when creating connections and session pools instead.
 8) Removed support for the OPT_NumbersAsStrings attribute. Use the
numbersAsStrings attribute on cursors instead.
 9) Use type long rather than type int in order to support long integers on
64-bit machines as reported by Uwe Hoffmann.
10) Add cursor attribute bindarraysize which is defaulted to 1 and is used
to determine the size of the arrays created for bind variables.
11) Added repr() methods to provide something a little more useful than the
standard type name and memory address.
12) Added keyword argument support to the functions that imply such in the
documentation as requested by Harald Armin Massa.
13) Treat an empty dictionary passed through to cursor.execute() as keyword
arguments the same as if no keyword arguments were specified at all, as
requested by Fabien Grumelard.
14) Fixed memory leak when a LOB read would fail.
15) Set the LDFLAGS value in the environment rather than directly in the
setup.py file in order to satisfy those who wish to enable the use of
debugging symbols.
16) Use __DATE__ and __TIME__ to determine the date and time of the build
rather than passing it through directly.
17) Use Oracle types and add casts to reduce warnings as requested by Amaury
Forgeot d'Arc.
18) Fixed typo in error message.
-- 
http://mail.python.org/mailman/listinfo/python-announce-list

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


ctypes 0.9.9.9 released

2006-07-22 Thread Thomas Heller

ctypes 0.9.9.9 released - July 21, 2006
===

Overview

ctypes is an advanced ffi (Foreign Function Interface) package for
Python 2.3 and higher.

ctypes allows to call functions exposed from dlls/shared libraries
and has extensive facilities to create, access and manipulate
simple and complicated C data types in Python - in other words:
wrap libraries in pure Python.  It is even possible to implement C
callback functions in pure Python.

ctypes runs on Windows, Windows CE, MacOS X, Linux, Solaris,
FreeBSD, OpenBSD. It may also run on other systems, provided that
libffi supports this platform.


Changes in 0.9.9.9

Index checking on 1-sized arrays was reintroduced, so they can no
longer be used as variable sized data.

Assigning None to pointer type structure fields possible overwrote
wrong fields.

Fixed a segfault when ctypes.wintypes were imported on non-Windows
machines.

Accept any integer or long value in the ctypes.c_void_p
constructor.

It is now possible to use custom objects in the ctypes foreign
function argtypes sequence as long as they provide a from_param
method, no longer is it required that the object is a ctypes type.

ctypes can now be built with MingW on Windows, but it will not
catch access violations then since MingW does no structured
exception handling.

Sync the darwin/x86 port libffi with the copy in PyObjC. This
fixes a number of bugs in that port. The most annoying ones were
due to some subtle differences between the document ABI and the
actual implementation :-(

Release the GIL during COM method calls, to avoid deadlocks in
Python coded COM objects.

Changes in 0.9.9.7

Fixes for 64-bit big endian machines.

It is now possible to read and write any index of pointer
instances (up to 0.9.9.6, reading was allowed for any index, but
writing only for index zero).

Support for unnamed (anonymous) structure fields has been added,
the field names must be listed in the '_anonymous_' class
variable.  Fields of unnamed structure fields can be accessed
directly from the parent structure.

Enabled darwin/x86 support for libffi (Bob Ippolito and Ronald
Oussuren).

Added support for variable sized data structures: array
types with exactly 1  element don't do  bounds checking any  more,
and  a resize  function can resize  the internal  memory buffer of
ctypes instances.

Fixed a bug with certain array or structure types that contained
more than 256 elements.

Changes in 0.9.9.6

The most important change is that the old way to load libraries
has been restored: cdll.LoadLibrary(path), and CDLL(path) work
again.  For details see the changelog in CVS and in the source
distribution.

It was a mistake to change that in the 0.9.9.3 release - I
apologize for any confusion and additional work this has caused or
will cause.

New module ctypes.util which contains a cross-platform
find_library function.

Sized integer types (c_int8, c_int16, and so on) have been added
by integrating a patch from Joe Wreschnig.  Also c_size_t, which
corresonds to the 'size_t' C type has been added.

Two long standing bugs with pointers have been fixed.  Thanks to
Axel Seibert for pushing me to the first, and thanks to Armin Rigo
for finding the second one.

The ctypes.decorator module has been removed completely, so the
'cdecl' and 'stdcall' symbols are no longer available.
The code generator has been removed completely.  It will probably
be made available as a separate project later.

The samples directory has been removed because it was completely
out-of-date.

The .zip and .tar.gz source distributions no longer contain
different file sets.

The development in CVS now takes place in the HEAD again, the
'branch_1_0' branch is no longer used.


Changes in 0.9.9.3

Windows

The ctypes.com package is no longer included and supported.
It is replaced by the comtypes package which will be released
separately.

ctypes has been ported to Windows CE by Luke Dunstan.

Other platforms

Hye-Shik Chang has written a new build system for libffi
which should remove possible licensing issues.

All platforms

The library loading code has been rewritten by Andreas Degert,
there are now sophisticated methods to find shared libraries.
On OS X, this uses files from Bob Ippolito's macholib.
See the manual for details.

Finally I started to write the manual, it is available online:

http://tinyurl.com/7bpg4

New 'errcheck' protocol to check the return values of foreign
functions, suggested by Mike Fletcher.

Lots of bug fixes, especially for 64-bit platforms. Improved
performance when 

cx_Freeze 3.0.3

2006-07-22 Thread Anthony Tuininga
What is cx_Freeze?

cx_Freeze is a set of utilities for freezing Python scripts into
executables using many of the techniques found in Thomas Heller's
py2exe, Gordon McMillan's Installer and the Freeze utility that ships
with Python itself.


Where do I get it?

http://starship.python.net/crew/atuining

What's new?

1) In Common.c, used MAXPATHLEN defined in the Python OS independent
include file rather than the PATH_MAX define which is OS dependent and
is notavailable on IRIX as noted by Andrew Jones.
2) In the initscript ConsoleSetLibPath.py, added lines from initscript
Console.py that should have been there since the only difference
between that script and this one is the automatic re-execution of the
executable.
3) Added an explicit import encodings to the initscripts in order to
handle Unicode encodings a little better. Thanks to Ralf Schmitt for
pointing out the problem and its solution.
4) Generated a meaningful name for the extension loader script so that
it is clear which particular extension module is being loaded when an
exception is being raised.
5) In MakeFrozenBases.py, use distutils to figure out a few more
platform-dependent linker flags as suggested by Ralf Schmitt.
-- 
http://mail.python.org/mailman/listinfo/python-announce-list

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


Ann: Crunchy Frog 0.6

2006-07-22 Thread andre . roberge
Crunchy Frog (version 0.6) has been released.

Crunchy Frog is an application that transforms an html-based Python
tutorial into an interactive session within a browser window.  The
interactive embedded objects include:
* a Python interpreter;
* a simple code editor, whose input can be executed by Python;
* a special doctest mode for the code editor;
* a graphics canvas which can be drawn upon using a simple api.
* simple sounds can be generated and played with all of the above.

A comprehensive set of examples are included in the package, as well
as two standard Python tutorials (mini-sorting HowTo, and regular
expression HowTo) which have been adapted for use with Crunchy Frog.

Requirements:
Python 2.4+ (it might work, but has not been tested with earlier
versions)
Elementtree; (a link is provided in the included docs)
Firefox 1.5+

The website address is http://crunchy.sourceforge.net
The files can be downloaded from
http://sourceforge.net/project/showfiles.php?group_id=169458

André and Johannes

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

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


Ophelia 0.1

2006-07-22 Thread Thomas Lotze
The first release of Ophelia, 0.1, has just been tagged. From README.txt:

=

Ophelia creates XHTML pages from templates written in TAL, the Zope Template
Attribute Language. It is designed to reduce code repetition to zero.

At present, Ophelia contains a request handler for the Apache2 web server.

Static content
--

Consider Ophelia as SSI on drugs. It's not fundamentally different, just a
lot friendlier and more capable.

Use Ophelia for sites where you basically write your HTML yourself, except
that you need write the recurring stuff only once. Reducing repetition to zero
comes at a price: your site must follow a pattern for Ophelia to combine your
templates the right way.

Consider your site's layout to be hierarchical: there's a common look to all
your pages, sections have certain characteristics, and each page has unique
content. It's crucial to Ophelia that this hierarchy reflects in the file
system organization of your documents; how templates are nested is deduced
from their places in the hierarchy of directories.

Dynamic content
---

Ophelia makes the Python language available for including dynamic content.
Each template file may include a Python script. Python scripts and templates
contributing to a page share a common set of variables to modify and use.

Ophelia's content model is very simple and works best if each content object
you publish is its own view: the page it is represented on. If you get content
from external resources anyway (e.g. a database or a version control
repository), it's still OK to use Ophelia even with multiple views per content
object as long as an object's views doesn't depend on the object's type or
even the object itself.

Trying to use Ophelia on a more complex site will lead to an ugly entanglement
of logic and presentation. Don't use Ophelia for sites that are actually web
interfaces to applications, content management systems and the like.

=

To use Ophelia, you need

- Apache2
- Python 2.3 or better
- mod_python 3.1 or better
- the zope package from Zope3

Ophelia is released under the Zope Public License, version 2.1. You can
access the source code repository at

https://svn.thomas-lotze.de/repos/public/Ophelia/,

browse it using ViewCVS at

http://svn.thomas-lotze.de/svn-public/Ophelia/,

and download the 0.1 release from

http://svn.thomas-lotze.de/svn-public/Ophelia/tags/Ophelia-0.1.tar.gz.

Ophelia is currently used to deliver its author's private web site.

-- 
Thomas

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

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


Re: Python newbie needs constructive suggestions

2006-07-22 Thread Peter Otten
[EMAIL PROTECTED] wrote:

 What is the idiomatically appropriate Python way to pass, as a
 function-type parameter, code that is most clearly written with a local
 variable?
 
 For example, map takes a function-type parameter:
 
 map(lambda x: x+1, [5, 17, 49.5])
 
 What if, instead of just having x+1, I want an expression that is most
 clearly coded with a variable that is needed only inside the lambda, e.g.
 if I wanted to use the name one instead of 1:
 
 map(lambda x: (one = 1  x+one), [5, 17, 49.5])
 
For a simple constant expression, your example is how it's done most
frequently. When it gets more complicated the classic trick is to use a
default argument:

 map(lambda x, delta=2**10: x+delta, [5, 17, 49.5])
[1029, 1041, 1073.5]

A closure works equally well:

 def make_adder(delta):
... def add(x):
... return x + delta
... return add
...
 map(make_adder(42), [5, 17, 49.5])
[47, 59, 91.5]

So does a callable class...

 class Adder(object):
... def __init__(self, delta):
... self.delta = delta
... def __call__(self, x):
... return x + self.delta
...
 map(Adder(321), [5, 17, 49.5])
[326, 338, 370.5]

which has the advantage that it can maintain state between calls (e. g. if
you were to build an accumulator it would be your only clean option).

In the real world the first two are most common, but they are only used when
the variable is not for immediate consumption:

# wrong
 adders = [lambda x: x + delta for delta in range(3)]
 [a(0) for a in adders]
[2, 2, 2]

# fixed
 adders = [lambda x, delta=delta: x + delta for delta in range(3)]
 [a(0) for a in adders]
[0, 1, 2]

 Do I
 
   d) give up on using Python and go back to Scheme, or

If you stick with Python your students can soon start to experiment with
concepts and algorithms, and at the same time you provide them with a tool
that may be useful in their daily work (think scipy).

Peter

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


Re: Has anyone used davlib by Greg Stein?

2006-07-22 Thread Guido Goldstein

Hi!

On Tue, 18 Jul 2006 15:06:55 +0200
  Joel Hedlund [EMAIL PROTECTED] wrote:
 Hi!

 I want to PUT files to a authenticated https WebDAV server from within
 a python script. Therefore I put python dav into google, and the
 davlib module by Greg Stein (and Guido?) came up. It seems to be soild
 but has very little docs. Has anyone worked with this? Is it any good? 
 Where can I find some good docs for it?

I don't know any documentation for it.
But I know that there is another DAV lib around at
  http://www.infrae.com/download/pydavclient

It is also not fully documented but might fit your needs.

Cheers
  Guido G.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: New to threads. How do they work?

2006-07-22 Thread Lawrence D'Oliveiro
In message [EMAIL PROTECTED], Dennis Lee Bieber
wrote:

 On Sat, 22 Jul 2006 17:19:22 +1200, Lawrence D'Oliveiro
 [EMAIL PROTECTED] declaimed the following in
 comp.lang.python:
 
 
 Perhaps because with threads, data is shared by default. Whereas with
 processes, it is private by default, and needs to be explicitly shared if
 you want that.
 
 Or just that the name thread was a late-comer for some of us...
 
 The Amiga had tasks at the lowest level (these were what the core
 OS library managed -- that core handled task switching, memory
 allocation, and IPC [event flags, message ports]). Processes were
 scheduled by the executive, but had additional data -- like stdin/stdout
 and environment variables... all the stuff one could access from a
 command line. Or, confusing for many... Processes were DOS level,
 Tasks were OS level.

Or for a more up-to-date example, how about the Linux way, where processes
and threads are just two points on a spectrum of possibilities, all
controlled by options to the clone(2) system call.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Isn't there a better way?

2006-07-22 Thread Lawrence D'Oliveiro
In message [EMAIL PROTECTED], T wrote:

 
 I am using an optparse to get command line options, and then pass them
 to an instance of another class:
 
 
 
 # Class that uses optparse.OptionParser
 foo = Parse_Option()
 
 # Class that does the real work
 bar = Processor()
 
 bar.index = foo.options.index
 bar.output  = foo.options.output
 bar.run()
 
 
 
 This works, but it feels hokey or unnatural to pass data from one
 class to another.  Isn't there a better way???

I don't see the problem. If you're calling a number of different routines in
the Processor class, all accessing the same data, then it makes perfect
sense to only pass it once.
-- 
http://mail.python.org/mailman/listinfo/python-list


Is it possible to get image size before/without downloading?

2006-07-22 Thread aldonnelley
Hi there: a bit of a left-field question, I think.
I'm writing a program that analyses image files downloaded with a basic
crawler, and it's slow, mainly because I only want to analyse files
within a certain size range, and I'm having to download all the files
on the page, open them, get their size, and then only analyse the ones
that are in that size range.
Is there a way (in python, of course!) to get the size of images before
or without downloading them? I've checked around, and I can't seem to
find anything promising...

Anybody got any clues?

Cheers, Al.

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


Re: Is it possible to get image size before/without downloading?

2006-07-22 Thread Josiah Manson
In the head of an HTTP response, most servers will specify a
Content-Length that is the number of bytes in the body of the response.
Normally, when using the GET method, the header is returned with the
body following. It is possible to make a HEAD request to the server
that will only return header information that will hopefully tell you
the file size.

If you want to know the actual dimensions of the image, I don't know of
anything in HTTP that will tell you. You will probably just have to
download the image to find that out. Relevant HTTP specs below if you
care.

http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html
http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html

The above is true regardless of language. In python it appears there an
httplib module. I would call request using the method head.

http://docs.python.org/lib/httpconnection-objects.html

[EMAIL PROTECTED] wrote:
 Hi there: a bit of a left-field question, I think.
 I'm writing a program that analyses image files downloaded with a basic
 crawler, and it's slow, mainly because I only want to analyse files
 within a certain size range, and I'm having to download all the files
 on the page, open them, get their size, and then only analyse the ones
 that are in that size range.
 Is there a way (in python, of course!) to get the size of images before
 or without downloading them? I've checked around, and I can't seem to
 find anything promising...
 
 Anybody got any clues?
 
 Cheers, Al.

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


Re: random shuffles

2006-07-22 Thread danielx
Boris Borcic wrote:
 does

 x.sort(cmp = lambda x,y : cmp(random.random(),0.5))

 pick a random shuffle of x with uniform distribution ?

 Intuitively, assuming list.sort() does a minimal number of comparisons to
 achieve the sort, I'd say the answer is yes. But I don't feel quite 
 confortable
 with the intuition... can anyone think of a more solid argumentation ?

 - BB
 --
 On naît tous les mètres du même monde

Someone has already said this, but I'm not sure we can ignore exactly
what algorithm we are using. With that in mind, I'll just arbitrarily
choose an algorithm to use for analysis. I know you want something that
works in N*log(N) where N is the length of the list, but I'm going to
ignore that and consider selection sort for the sake of a more solid
argument.

In that case, you would NOT achieve a uniform distribution. I quote
that because I'm going to make up a definition, which I hope
corresponds to the official one ;). To me, uniform will mean if we look
at any position in the list, element e has 1/N chance of being there.

Let e be the element which was in the first position to begin with.
What are its chances of being there after being sorted? Well, in
order for it to still be there, it would have to survive N rounds of
selection. In each selection, it has 1/2 chance of surviving. That
means its total chance of survival is 1/(2**N), which is much less than
1/N. QED!

***

After writting that down, I thought of an argument for an N*log(N)
algorithm, which would cause the resulting list to be uniformly random:
tournament sort (I think this is also called binary tree sort). How
many rounds does an element have to win in order to come out on top? A
number which approaches log2(N). This is like before, except this
element doesn't have to survive as many rounds; therefore, it's total
chance of coming out on top is 1/(2**log2(N)) ==  1/N. Hoorah!

***

After considering that, I realized that even if your idea to shuffle a
list did work (can't tell because I don't know how Python's sort
works), it would not be an optimal way to shuffle a list even though
Python uses an N*log(N) sort (at least I hope so :P). This is because
you can shuffle in time proportional the the length of the list.

You can accomplish this by doing what I will call random selection.
It would be like linear selection, except you wouldn't bother checking
the head against every other element. When you want to figure out what
to put at the head, just pick at random! I suspect this is what Python
does in random.shuffle, since it is rather an easy to see it would
result in something uniform (I swear I haven't looked at the source
code for random.shuffle :P).

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


Re: Is it possible to get image size before/without downloading?

2006-07-22 Thread aldonnelley
Thanks Josiah

I thought as much... Still, it'll help me immensely to cut the
downloads from a page to only those that are within a file-size range,
even if this gets me some images that are out-of-spec dimensionally.

Cheers, Al.

(Oh, and if anyone still has a bright idea about how to get image
dimensions without downloading, it'd be great to hear!)

Josiah Manson wrote:
 In the head of an HTTP response, most servers will specify a
 Content-Length that is the number of bytes in the body of the response.
 Normally, when using the GET method, the header is returned with the
 body following. It is possible to make a HEAD request to the server
 that will only return header information that will hopefully tell you
 the file size.

 If you want to know the actual dimensions of the image, I don't know of
 anything in HTTP that will tell you. You will probably just have to
 download the image to find that out. Relevant HTTP specs below if you
 care.

 http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html
 http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html

 The above is true regardless of language. In python it appears there an
 httplib module. I would call request using the method head.

 http://docs.python.org/lib/httpconnection-objects.html

 [EMAIL PROTECTED] wrote:
  Hi there: a bit of a left-field question, I think.
  I'm writing a program that analyses image files downloaded with a basic
  crawler, and it's slow, mainly because I only want to analyse files
  within a certain size range, and I'm having to download all the files
  on the page, open them, get their size, and then only analyse the ones
  that are in that size range.
  Is there a way (in python, of course!) to get the size of images before
  or without downloading them? I've checked around, and I can't seem to
  find anything promising...
  
  Anybody got any clues?
  
  Cheers, Al.

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


Re: Is it possible to get image size before/without downloading?

2006-07-22 Thread Peter Otten
[EMAIL PROTECTED] wrote:

 Hi there: a bit of a left-field question, I think.
 I'm writing a program that analyses image files downloaded with a basic
 crawler, and it's slow, mainly because I only want to analyse files
 within a certain size range, and I'm having to download all the files
 on the page, open them, get their size, and then only analyse the ones
 that are in that size range.
 Is there a way (in python, of course!) to get the size of images before
 or without downloading them? I've checked around, and I can't seem to
 find anything promising...
 
 Anybody got any clues?

The PIL can determine the size of an image from some large enough chunk at
the beginning of the image, e. g:

import Image
import urllib
from StringIO import StringIO

f = urllib.urlopen(http://www.python.org/images/success/nasa.jpg;)
s = StringIO(f.read(512))
print Image.open(s).size

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


Re: Is it possible to get image size before/without downloading?

2006-07-22 Thread Marc 'BlackJack' Rintsch
In [EMAIL PROTECTED], aldonnelley
wrote:

 (Oh, and if anyone still has a bright idea about how to get image
 dimensions without downloading, it'd be great to hear!)

Most image formats have some sort of header with the dimensions
information so it's enough to download this header.  Depends on the image
format how much of the file has to be read and how the information is
encoded.

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


Re: using array as execute parameter in dbapi

2006-07-22 Thread gglegrp112
This is a really neat trick.

Thank you very much.

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


Wxpython, using more than 1 timer?

2006-07-22 Thread janama
Hi all,

Using wx
When adding a second timer as i have the first,  the second timer
adding  stops the first timer (updating or stops?) . In this example im
updating a uptime and localtime label. It works fine for displaying the
last self.startTimer2() called. But prevents the previous
self.startTimer1() from running . Im doing something fundamentally
wrong i guess?

def __init__(self, parent):
self._init_ctrls(parent)

#Start timers
self.startTimer1()
self.startTimer2()

def startTimer1(self):
self.t1 = wx.Timer(self)
self.t1.Start(360) # 36 ms = 1/10 hour
self.Bind(wx.EVT_TIMER, self.OnUpTime)

def startTimer2(self):
self.t2 = wx.Timer(self)
self.t2.Start(1000) # run every second
self.Bind(wx.EVT_TIMER, self.OnTime)

def OnTime(self,evt):
self.lblTime.SetLabel(str(time.localtime()))

def OnUpTime(self, evt):
self.lblUptime.SetLabel('Running ' + (str(myTimerText[0])) + '
hours') # 1/10  hour count
myTimerText[0] = myTimerText[0] + .1

Any help appreciated, ta

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


Re: Python newbie needs constructive suggestions

2006-07-22 Thread David G. Wonnacott
Many thanks to those of you who responded to my question about
anonymous functions with local variables, filling me in on

  e) do something else clever and Pythonic that I don't know about yet?

by pointing out that I can use (among other good things) lambda with
default arguments. That should suit my immediate needs well, since I
don't need to maintain state (or avoid maintaning state); I may also
look into closures (possibly anonymous ones?) and callable classes if
I need to go beyond this. And, of course, if the code is complex
enough, then one should give up the anonymous function and name it.

Rest assured that I will _not_ be attempting to write let in Python
and use it.

It looks like Python may be every much as big an improvement over C++
as I had hoped.

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


Re: Wxpython, using more than 1 timer?

2006-07-22 Thread nikie
janama wrote:

 Hi all,

 Using wx
 When adding a second timer as i have the first,  the second timer
 adding  stops the first timer (updating or stops?) . In this example im
 updating a uptime and localtime label. It works fine for displaying the
 last self.startTimer2() called. But prevents the previous
 self.startTimer1() from running . Im doing something fundamentally
 wrong i guess?

 def __init__(self, parent):
 self._init_ctrls(parent)

 #Start timers
 self.startTimer1()
 self.startTimer2()

 def startTimer1(self):
 self.t1 = wx.Timer(self)
 self.t1.Start(360) # 36 ms = 1/10 hour
 self.Bind(wx.EVT_TIMER, self.OnUpTime)

 def startTimer2(self):
 self.t2 = wx.Timer(self)
 self.t2.Start(1000) # run every second
 self.Bind(wx.EVT_TIMER, self.OnTime)

 def OnTime(self,evt):
 self.lblTime.SetLabel(str(time.localtime()))

 def OnUpTime(self, evt):
 self.lblUptime.SetLabel('Running ' + (str(myTimerText[0])) + '
 hours') # 1/10  hour count
 myTimerText[0] = myTimerText[0] + .1

 Any help appreciated, ta

The problem is not that the first timer ist stopped, the problem is
that both timers happen to call the same method in the end.

Think of the Bind method as an assignment: it assigns a handler
function to an event source. If you call it twice for the same event
source, the second call will overwrite the first event handler. That's
what happens in your code.

The easiest way to change this is by using different ids for the
timers:

def startTimer1(self):
self.t1 = wx.Timer(self, id=1)
self.t1.Start(2000)
self.Bind(wx.EVT_TIMER, self.OnUpTime, id=1)

def startTimer2(self):
self.t2 = wx.Timer(self, id=2)
self.t2.Start(1000)
self.Bind(wx.EVT_TIMER, self.OnTime, id=2)

This way, the timers launch two different events, which are bound to
two different methods.

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


How to force a thread to stop

2006-07-22 Thread Hans
Hi all,

Is there a way that the program that created and started a thread also stops 
it.
(My usage is a time-out).

E.g.

thread = threading.Thread(target=Loop.testLoop)
thread.start() # This thread is expected to finish within a second
thread.join(2)# Or time.sleep(2) ?

if thread.isAlive():
# thread has probably encountered a problem and hangs
# What should be here to stop thread  ??

Note that I don't want to change the target (too much), as many possible 
targets exist,
together thousands of lines of code.

Thanks,
Hans 


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


Re: Wxpython, using more than 1 timer?

2006-07-22 Thread janama
Thanks for that, cheers

Regards


nikie wrote:
 janama wrote:

  Hi all,
 
  Using wx
  When adding a second timer as i have the first,  the second timer
  adding  stops the first timer (updating or stops?) . In this example im
  updating a uptime and localtime label. It works fine for displaying the
  last self.startTimer2() called. But prevents the previous
  self.startTimer1() from running . Im doing something fundamentally
  wrong i guess?
 
  def __init__(self, parent):
  self._init_ctrls(parent)
 
  #Start timers
  self.startTimer1()
  self.startTimer2()
 
  def startTimer1(self):
  self.t1 = wx.Timer(self)
  self.t1.Start(360) # 36 ms = 1/10 hour
  self.Bind(wx.EVT_TIMER, self.OnUpTime)
 
  def startTimer2(self):
  self.t2 = wx.Timer(self)
  self.t2.Start(1000) # run every second
  self.Bind(wx.EVT_TIMER, self.OnTime)
 
  def OnTime(self,evt):
  self.lblTime.SetLabel(str(time.localtime()))
 
  def OnUpTime(self, evt):
  self.lblUptime.SetLabel('Running ' + (str(myTimerText[0])) + '
  hours') # 1/10  hour count
  myTimerText[0] = myTimerText[0] + .1
 
  Any help appreciated, ta

 The problem is not that the first timer ist stopped, the problem is
 that both timers happen to call the same method in the end.

 Think of the Bind method as an assignment: it assigns a handler
 function to an event source. If you call it twice for the same event
 source, the second call will overwrite the first event handler. That's
 what happens in your code.

 The easiest way to change this is by using different ids for the
 timers:

 def startTimer1(self):
 self.t1 = wx.Timer(self, id=1)
 self.t1.Start(2000)
 self.Bind(wx.EVT_TIMER, self.OnUpTime, id=1)

 def startTimer2(self):
 self.t2 = wx.Timer(self, id=2)
 self.t2.Start(1000)
 self.Bind(wx.EVT_TIMER, self.OnTime, id=2)

 This way, the timers launch two different events, which are bound to
 two different methods.

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


Converting argv to variable

2006-07-22 Thread tgiles
(now that I've posted in the wrong flipping newsgroup the first thing,
here's my question to the lovely python folks)

I've taken a year off (or so) using Python and the first thing I run
into utterly stumped me. Been too long and none of the searches I've
done seems to have helped any.
Basically, I'm trying to create a little script which will make a new
directory, using the argument passed to it to give the directory a
name:

#!/usr/bin/python

import sys, os

newDirectory = str(sys.argv[1:])

currentPath =  str(os.getcwd())

create =  currentPath + '/' + newDirectory

print create

# os.mkdir(create)

Now, in a perfect universe I would get an output something like the
following (if I run the script with the argument 'python':

/Volumes/Home/myuser/python

However, Python still hangs on to all the fluff and prints out
something else:

/Volumes/Home/myuser/['python']

I know there must be some way to convert the argument to a 'normal'
variable, but it escapes me how to do so. Any pointers? 

Thanks! 

tom

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


Re: Converting argv to variable

2006-07-22 Thread Tim Chase
  newDirectory = str(sys.argv[1:])
[cut]
  Now, in a perfect universe I would get an output something
  like the following (if I run the script with the argument
  'python':
 
  /Volumes/Home/myuser/python
 
  However, Python still hangs on to all the fluff and prints
  out something else:
 
  /Volumes/Home/myuser/['python']

Your newDirectory = ... line is asking for a slice of a
list, which returns a list.  Python then dutifully converts
that list to a string representation and tacks that onto
your string/path.

What you want is sys.argv[1] (the first argument) not
sys.argv[1:] (a list of all but the first argv--namely, all
the arguments as [0] is the name of your python script)

-tkc





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


Re: Converting argv to variable

2006-07-22 Thread Klaus Alexander Seistrup
Tom skrev:

 newDirectory = str(sys.argv[1:])

Try

newDir = '/'.join(sys.argv[1:])
or
newDir = sys.argv[1]
or
for newDir in sys.argv[1:]:
:

or something along those lines, depending on how you wish to 
interpret the commandline.

Cheers, 

-- 
Klaus Alexander Seistrup
Copenhagen, Denmark
http://surdej.dk/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: New to threads. How do they work?

2006-07-22 Thread Grant Edwards
On 2006-07-22, Lawrence D'Oliveiro [EMAIL PROTECTED] wrote:

 I've never understood the aversion people seem to have to
 threads.

 Perhaps because with threads, data is shared by default.
 Whereas with processes, it is private by default, and needs to
 be explicitly shared if you want that.

Only global data is shared.  I guess if you use a lot of global
data that's an issue.  I tend not to.  The problem with
processes is that sharing data is hard.

-- 
Grant Edwards   grante Yow!  Are you mentally here
  at   at Pizza Hut??
   visi.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Application Generators

2006-07-22 Thread walterbyrd

Steve Hannah wrote:
 I know that this is an older thread, but I came across it on Nabble.com.
 Just wanted add some updated info on Walter's observations about Dataface
 (http://fas.sfu.ca/dataface) .  It is much further along in development now
 and it does support authentication now.


Thanks, for the particular project that I was working on, I went with
AppGeni, and added my own authentication.

I do have other projects in mind. Dataface seems almost like a free
version of codecharge. One thing I don't much like about codecharge, is
that it's windows only.

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


Re: random shuffles

2006-07-22 Thread David G. Wonnacott
   From: danielx [EMAIL PROTECTED]
   Date: 22 Jul 2006 01:43:30 -0700

   Boris Borcic wrote:
does
   
x.sort(cmp = lambda x,y : cmp(random.random(),0.5))
   
pick a random shuffle of x with uniform distribution ?

...

   Let e be the element which was in the first position to begin with.
   What are its chances of being there after being sorted? Well, in
   order for it to still be there, it would have to survive N rounds of
   selection. In each selection, it has 1/2 chance of surviving. That
   means its total chance of survival is 1/(2**N), which is much less than
   1/N. QED!


This proof makes sense to me if the sorting algorithm makes a random
decision every time it swaps.

Couldn't we easily get an n*log(n) shuffle by performing a _single_
mapping of each element in the collection to a pair made up of a
random key and its value, and then sorting based on the keys and
stripping them out? i.e., in O(n) time, turn

   2 clubs, 2 diamonds, 2 hearts, 2 spades, 3 clubs

into something like

   [0.395, 2 clubs], [0.158, 2 diamonds], [0.432, 2 hearts], [0.192, 2 
spades], [0.266, 3 clubs]

and then in O(n*log(n)) time, sort it into

   [0.158, 2 diamonds], [0.192, 2 spades], [0.266, 3 clubs], [0.395, 2 
clubs], [0.432, 2 hearts]

and then strip out the keys again in O(n) time?

Or perhaps this has been discussed already and I missed that part? I
just joined the list... apologies if this is a repeat.



   You can accomplish this by doing what I will call random selection.
   It would be like linear selection, except you wouldn't bother checking
   the head against every other element. When you want to figure out what
   to put at the head, just pick at random! I suspect this is what Python
   does in random.shuffle, since it is rather an easy to see it would
   result in something uniform (I swear I haven't looked at the source
   code for random.shuffle :P).


But, after making the linear selection, don't you still need to use
O(log(n)) time to find and remove the item from the collection? I
don't know much about Python's internal data structures, but if
there's an array in there, you need O(n) time to move up everything
after the deleted item; if there's a list, you need O(n) time to find
the element you picked at random; if there's a balanced tree, you
could find it and delete it in O(log(n)) time...

Help me review my undergraduate data structures here -- is there some
way to pick each item _exactly_once_ in O(n) time?

Dave Wonnacott

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


Re: IronPython and scipy/pyExcelerator

2006-07-22 Thread Fuzzyman

[EMAIL PROTECTED] wrote:
 I'm looking forward to the release IronPython, primarily for its IDE. I
 currently use scipy and pyExcelerator to crunch numbers and write them
 to Excel: does can these packages be used with IronPython as well?

 Thanks in advance

You could try Python for .NET. This is a version of cPython with
support for .NET built in.

You may have to amend the code that Visual Studio produces to work with
Python for .NET rather than for IronPython  (necessary changes may be
restricted to the import syntax).

SciPy makes extensive use of C extensions which aren't currently
supoorted by IronPython. There has been some preliminary work done dy
Seo Sanghyeon on a 'reflector' that uses ctypes to allow IronPython to
access cPython C extensions. My understanding is that it works (at
least partially) but that the exceptions it returns are (currently)
confusing.

See
http://groups.google.com/group/comp.lang.python/browse_frm/thread/842a8011a1a2a26c/9d7e157124943e9f

and also search the IronPython mailing lists. Alternatively you could
use interprocess communication between cPython and IronPython ;-)

All the best,


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

 
 Thomas Philips

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


Re: How to force a thread to stop

2006-07-22 Thread bryanjugglercryptographer

Hans wrote:
 Hi all,

 Is there a way that the program that created and started a thread also stops
 it.
 (My usage is a time-out).

 E.g.

 thread = threading.Thread(target=Loop.testLoop)
 thread.start() # This thread is expected to finish within a second
 thread.join(2)# Or time.sleep(2) ?

No, Python has no threadicide method, and its absence is not an
oversight. Threads often have important business left to do, such
as releasing locks on shared data; killing them at arbitrary times
tends to leave the system in an inconsistent state.

 if thread.isAlive():
 # thread has probably encountered a problem and hangs
 # What should be here to stop thread  ??

At this point, it's too late. Try to code so your threads don't hang.

Python does let you arrange for threads to die when you want to
terminate the program, with threading's Thread.setDaemon().


-- 
--Bryan

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


Re: What is a type error?

2006-07-22 Thread Benjamin Franksen
Darren New wrote:
 Chris Smith wrote:
 Specialized
 language already exist that reliably (as in, all the time) move array
 bounds checking to compile time;
 
 It sounds like this means the programmer has to code up what it means to
 index off an array, yes? Otherwise, I can't imagine how it would work.
 
 x := read_integer_from_stdin();
 write_to_stdout(myarray[x]);
 
 What does the programmer have to do to implement this semantic in the
 sort of language you're talking about? Surely something somewhere along
 the line has to  fail (for some meaning of failure) at run-time, yes?

You should really take a look at Epigram. One of its main features is that
it makes it possible not only to statically /check/ invariants, but also
to /establish/ them.

In your example, of course the program has to check the integer at runtime.
However, in a dependent type system, the type of the value returned from
the check-function can very well indicate whether it passed the test (i.e.
being a valid index for myarray) or not.

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


httplib, threading, wx app freezing after 4 hours

2006-07-22 Thread Mark rainess
The program displays images from a motion jpeg webcam.
(Motion jpeg is a bastardization of multi-part mime.)
http://wp.netscape.com/assist/net_sites/pushpull.html

It runs perfectly for about 4 hours, then freezes.
I'm stuck. How do I debug this?

(Using: Python 2.4.3, wxPython 2.6.3.2, Windows 2000 and XP)

There are no tracebacks, the gui continues to run,
isAlive() and activeCount() indicate that the thread is OK,
print I'm alive stops. CPU % usage is 0

I figure it is hanging in r.readline() or f.read()

Can anyone suggest techniques to help me learn what is going on.

I'm using httplib.HTTP instead of httplib.HTTPConnection because
I don't find that HTTPConnection has readline().


Mark Rainess


=
class mjpeg_get(threading.Thread):
 def run(self):
 while 1:
 while 1:
 # print I'm connecting
 h = httplib.HTTP(self.url)
 h.putrequest('GET','VIDEO.CGI')
 h.putheader('Accept','text/html')
 h.endheaders()
 if errcode == 200:
 f = h.getfile()
 break
 # cleanup and try again

 s = cStringIO()
 while 1:
 # print I'm alive
 try:
 # do f.readline() to get headers
 # get count from 'Content-length:'
 s.reset()
 s.write(f.read(count))
 s.truncate()
 wx.CallAfter(self.window.onUpdateImg, s)
 continue
 except:
 # print error
 # cleanup and try again
 break

class Frame(wx.Frame):
 def OnIdle(self, event):
 # for debugging display result of
 # Thread.isAlive()
 # threading.activeCount()
 if self.gotImage is True:
 # do display self.sImage
 self.gotImage = False
 def onUpdateImg(self, parm):
 if self.gotImage is False:
 self.sImage.reset()
 self.sImage.write(parm.getvalue())
 self.sImage.truncate()
 self.sImage.reset()
 self.gotImage = True
=
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Nested function scope problem

2006-07-22 Thread Justin Azoff
Josiah Manson wrote:
 I just did some timings, and found that using a list instead of a
 string for tok is significantly slower (it takes 1.5x longer). Using a
 regex is slightly faster for long strings, and slightly slower for
 short ones. So, regex wins in both berevity and speed!

I think the list.append method of building strings may only give you
speed improvements when you are adding bigger chunks of strings
together instead of 1 character at a time. also:

http://docs.python.org/whatsnew/node12.html#SECTION000121

String concatenations in statements of the form s = s + abc and s
+= abc are now performed more efficiently in certain circumstances.
This optimization won't be present in other Python implementations such
as Jython, so you shouldn't rely on it; using the join() method of
strings is still recommended when you want to efficiently glue a large
number of strings together. (Contributed by Armin Rigo.)

I tested both, and these are my results for fairly large strings:

[EMAIL PROTECTED]:/tmp$ python /usr/lib/python2.4/timeit.py -s'import
foo' 'foo.test(foo.breakLine)'
10 loops, best of 3: 914 msec per loop

[EMAIL PROTECTED]:/tmp$ python /usr/lib/python2.4/timeit.py -s'import
foo' 'foo.test(foo.breakLineRE)'
10 loops, best of 3: 289 msec per loop

-- 
- Justin

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


GUIDE: Using xtopdf to create PDF from text and DBF files (including creating simple PDF e-books)

2006-07-22 Thread vasudevram

Hi,

I'm giving below, steps to install and use my xtopdf PDF
creation/conversion toolkit.

This post is for end-users. xtopdf is both a set of end-user tools and
a library for use by developers, to create PDF from various input
formats.
I'll post another message here about how developers can use it in
various ways, sometime later.

The steps are for the Windows platform. Will do another post for Linux.

1. Get Python v2.4.3 here:
http://www.python.org/ftp/python/2.4.3/python-2.4.3.msi
Size is not more than 10 MB. Install it - its an MSI, so just
double-click.

(Any Python version = 2.2 will work for xtopdf).

2. Get Reportlab open source version 1.21 here:
http://www.reportlab.org/ftp/ReportLab_1_21.tgz

Size is not more than 3 MB.

(Don't use ReportLab 2.0 although it is available. I've not yet tested
xtopdf with it. ReportLab 1.21 is the latest stable version in the
version 1 series.)

Install it following the instructions in the README file.
It should be straightforward. The main points to take care of are:

2.1 First, before installing ReportLab, run Python once (you may have
to add the dir. where Python got installed, say C:\Python24, to your
PATH variable first). Once that dir. is added to your PATH (preferably
via Control Panel), open a DOS prompt.
At this prompt, type:

python

This should start the Python interpreter. You will get a one or two
line message with the Python version, and then the Python interpreter
prompt.

2.2. At this prompt, type the following two lines:

import sys
print sys.path

This should display a list of all the dirs. that are in the Python PATH
- an internal Python variable that gets set automatically, upon startup
of the interpreter, to a set of default dirs. This variable is
analogous to the DOS PATH variable. In this list of dirs., look for
C:\Python24\lib\site-packages as one of the dirs. It should be there
by default.

If it is there, then exit the Python interpreter by typing Ctrl-Z and
Enter.

3. Now install Reportlab:

Unzip the ReportLab_1_21.tgz file with WinZip, into some folder, say
c:\reportlab.
This will create a folder called either:
a) reportlab_1.21 with a folder called reportlab under it
or
b) just a folder called reportlab.

If a), then move the reportlab folder (which is under reportlab_1.21)
to under C:\Python24\Lib\site-packages .
If b), then move the reportlab folder to under
C:\Python24\Lib\site-packages.

The above steps should make ReportLab work.

An alternative way is to just unzip the reportlab  .tgz file into some
folder, say, C:\RL, and then create a file called, say, reportlab.pth,
which contains just one line - the path to this folder where the
extracted contents get stored.e.g. C:\RL\reportlab . Please check that
step out (in the ReportLab .tgz file's  README file for the exact
details).

4. After the above steps, to check that Reportlab works, go to a DOS
prompt again, run python again as before, and then at the Python
prompt, enter either or both of the following commands (on separate
lines):

import reportlab

from reportlab import pdfgen

If either or both of these above commands work (and if there is no
error message), it means that Reportlab is properly installed.

5. Now you can install xtopdf.

Get xtopdf here: http://sourceforge.net/projects/xtopdf (click on the
green rectangle which says Download Conversion of other formats to
PDF.
After downloading the file, unzip it into a folder, say c:\temp. This
will create a folder called xtopdf-1.0 under C:\temp.
Go to that folder.

There are many Python programs here with extension .py.

To run, e.g., WritePDF.py, do this:

python WritePDF.py some_file.txt

This will run it and the output will be a file called some_file.pdf.
Try opening it in Adobe Reader.

Similarly try running some more programs:

python DBFReader.py test1.dbf (or test2.dbf or test3.dbf or test4.dbf -
all of which are in the package)

This should read the DBF file and display its metadata (file header and
field headers) and data records to standard output - the screen.

python DBFToPDF.py test1.dbf  test1.pdf

This should do the same as the above (DBFReader.py), except that
instead of the output going to the screen, it will go to a file called
test1.pdf.

And so on, try out a few others. Most of all of the programs can be run
as python prog_name.py. Some require one or
more command-line arguments (all of them require at least one
command-line argument, at least an input file).
Some of them give usage messages if you run them without any
command-line arguments, but this is not necessarily the case for
all of them, nor are the messages always user-friendly enough - I'm
working on fixing that in the next release. (Developers who have at
least
a working knowledge of Python should be easily able to figure out the
usage, though, just by reading the start of the main() function for
each program -
the part where the code checks the command-line arguments.)

But you should be able to run at least a few of them like this.

Be 

Python website problem?

2006-07-22 Thread Tim N. van der Leeuw
Hi,

Does the Python.org website have a problem? I only get a directory
index, and clicking on any of the HTML files in there shows a page
without any CSS makeup.

Anyone noticed this too?

--Tim

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


How to test if object is sequence, or iterable?

2006-07-22 Thread Tim N. van der Leeuw
Hi,

I'd like to know if there's a way to check if an object is a sequence,
or an iterable. Something like issequence() or isiterable().

Does something like that exist? (Something which, in case of iterable,
doesn't consume the first element of the iterable)

Regards,

--Tim

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


Re: Python website problem?

2006-07-22 Thread Tim N. van der Leeuw

Tim N. van der Leeuw wrote:
 Hi,

 Does the Python.org website have a problem? I only get a directory
 index, and clicking on any of the HTML files in there shows a page
 without any CSS makeup.

 Anyone noticed this too?
 
 --Tim

Well, it seems fixed again...

--Tim

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


Sansung YH-920 + Linux + yh-925-db-0.1.py = AttributeError: 'module' object has no attribute 'decode'

2006-07-22 Thread rsd
Hi,

I'm trying get Samsung YH-920 mp3 player to work with Debian GNU/Linux. 
To do that I need to run
   http://www.paul.sladen.org/toys/samsung-yh-925/yh-925-db-0.1.py 
script, the idea behind the script is described at
   http://www.paul.sladen.org/toys/samsung-yh-925/

I'm getting errors and hoping someone could give me some hints, for I 
have no python background.

This is what I've done:
1. mounted YH-920 as /mnt/usb and transfered my MP3s to 
/mnt/usb/System/music/mp3 folder. That was easy.

2. Now, I need to run yh-925-db-0.1.py to update the database.

test:/mnt/usb# ls -l
total 64
drwxr-xr-x 3 root root 16384 2006-07-22 10:31 backup
drwxr-xr-x 8 root root 16384 2006-07-22 10:33 System
drwxr-xr-x 2 root root 16384 2002-01-01 11:00 tmp


test:/mnt/usb/System# ls -l
total 2480
drwxr-xr-x 2 root root 16384 2006-06-26 16:31 audible
drwxr-xr-x 2 root root 16384 2006-06-26 16:31 data
drwxr-xr-x 6 root root 16384 2006-06-26 16:31 music
drwxr-xr-x 2 root root 16384 2006-06-26 16:31 Parms
drwxr-xr-x 2 root root 16384 2006-06-26 16:31 playlist
-rwxr-xr-x 1 root root 2424832 2004-07-31 10:47 pp5020.mi4
drwxr-xr-x 2 root root 16384 2006-06-26 16:31 Recordings
-rwxr-xr-x 1 root root 7305 2006-07-22 10:34 yh-925-db-0.1.py


test:/mnt/usb/System# ./yh-925-db-0.1.py
Traceback (most recent call last):
File ./yh-925-db-0.1.py, line 195, in ?
de.add_from_dict(e.unpack3(f))
File ./yh-925-db-0.1.py, line 53, in unpack3
u = utf_16_le.decode(fp.read(size))
AttributeError: 'module' object has no attribute 'decode'

Any ideas? Thanks
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Isn't there a better way?

2006-07-22 Thread Bruno Desthuilliers
Lawrence D'Oliveiro a écrit :
 In message [EMAIL PROTECTED], T wrote:
 
 
I am using an optparse to get command line options, and then pass them
to an instance of another class:



# Class that uses optparse.OptionParser
foo = Parse_Option()

# Class that does the real work
bar = Processor()

bar.index = foo.options.index
bar.output  = foo.options.output
bar.run()



This works, but it feels hokey or unnatural to pass data from one
class to another.  Isn't there a better way???
 
 
 I don't see the problem. 

The problem is setting bar attributes from the outside IMHO. Which is 
easily solved by passing the relevant stuff either at instanciation time 
or at call time.

 If you're calling a number of different routines in
 the Processor class, all accessing the same data, then it makes perfect
 sense to only pass it once.

Actually they are not passed.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to test if object is sequence, or iterable?

2006-07-22 Thread Bruno Desthuilliers
Tim N. van der Leeuw a écrit :
 Hi,
 
 I'd like to know if there's a way to check if an object is a sequence,
 or an iterable. Something like issequence() or isiterable().
 
 Does something like that exist? (Something which, in case of iterable,
 doesn't consume the first element of the iterable)

isiterable = lambda obj: isinstance(obj, basestring) \
  or getattr(obj, '__iter__', False)


Should cover most cases.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python newbie needs constructive suggestions

2006-07-22 Thread Bruno Desthuilliers
[EMAIL PROTECTED] a écrit :
 What is the idiomatically appropriate Python way to pass, as a
 function-type parameter, code that is most clearly written with a
 local variable?

def functionWithLocal(andArg):
   localVar = 42
   return andArg+localVar

map(functionWithLocal, range(42))


 For example, map takes a function-type parameter:
 
 map(lambda x: x+1, [5, 17, 49.5])
 
 What if, instead of just having x+1, I want an expression that is
 most clearly coded with a variable that is needed _only_ inside the
 lambda, e.g. if I wanted to use the name one instead of 1:
 
 map(lambda x: (one = 1  x+one), [5, 17, 49.5])

map(lambda x, one=42 : x + one, [5, 17, 49.5])

 This sort of thing is of course straightforward in many other
 languages with anonymous functions (Scheme, Haskell, Smalltalk, etc),
 and I saw in the archives the discussion from 2003 about How do I
 get Scheme-like let bindings in Python. Many of the answers seem to
 boil down to You should not write Scheme programs in Python, you
 should write Python programs in Python.

A very sensible advice IMHO. Python - while having some support for FP - 
is still statement-based and mostly on the OO/procedural side.

(snip)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: random shuffles

2006-07-22 Thread danielx
David G. Wonnacott wrote:
 From: danielx [EMAIL PROTECTED]
Date: 22 Jul 2006 01:43:30 -0700

Boris Borcic wrote:
 does

 x.sort(cmp = lambda x,y : cmp(random.random(),0.5))

 pick a random shuffle of x with uniform distribution ?

 ...

Let e be the element which was in the first position to begin with.
What are its chances of being there after being sorted? Well, in
order for it to still be there, it would have to survive N rounds of
selection. In each selection, it has 1/2 chance of surviving. That
means its total chance of survival is 1/(2**N), which is much less than
1/N. QED!


 This proof makes sense to me if the sorting algorithm makes a random
 decision every time it swaps.

 Couldn't we easily get an n*log(n) shuffle by performing a _single_
 mapping of each element in the collection to a pair made up of a
 random key and its value, and then sorting based on the keys and
 stripping them out? i.e., in O(n) time, turn

2 clubs, 2 diamonds, 2 hearts, 2 spades, 3 clubs

 into something like

[0.395, 2 clubs], [0.158, 2 diamonds], [0.432, 2 hearts], [0.192, 2 
 spades], [0.266, 3 clubs]

 and then in O(n*log(n)) time, sort it into

[0.158, 2 diamonds], [0.192, 2 spades], [0.266, 3 clubs], [0.395, 2 
 clubs], [0.432, 2 hearts]

 and then strip out the keys again in O(n) time?

 Or perhaps this has been discussed already and I missed that part? I
 just joined the list... apologies if this is a repeat.


Yes, that would work beautifully. You could use the key argument of
list.sort. What we are talking about though, is using the cmp argument.
I.e. will list.sort(cmp=lambda:???) be able to give you a shuffle? I
think most of us think this depends on what sort algorithm Python uses.



You can accomplish this by doing what I will call random selection.
It would be like linear selection, except you wouldn't bother checking
the head against every other element. When you want to figure out what
to put at the head, just pick at random! I suspect this is what Python
does in random.shuffle, since it is rather an easy to see it would
result in something uniform (I swear I haven't looked at the source
code for random.shuffle :P).


 But, after making the linear selection, don't you still need to use
 O(log(n)) time to find and remove the item from the collection? I
 don't know much about Python's internal data structures, but if
 there's an array in there, you need O(n) time to move up everything
 after the deleted item; if there's a list, you need O(n) time to find
 the element you picked at random; if there's a balanced tree, you
 could find it and delete it in O(log(n)) time...

I'm almost sure there's a C array back there as well (well, not
techinically an array, but something from malloc), because indexing a
Python list is supposed to be fast. It would take constant time to
put something at the head. Just swap with the thing that's already
there. Since you have to do this swap for each position, it takes time
proportional to N.

When I originally came up with this idea, I was thinking you would not
choose a new head among previously chosen heads. But if you do allow
that, I think it will still be uniform. So my original idea was
something like this:

  1  2  3  4
# ^ head pos
stage 0: we need to choose something to put in pos 0. We can choose
anything to go there.

(swap)
  3  2  1  4
#^ head pos
stage 1: we need to choose something to put in pos 1. We can choose
among things in positions greater than or equal to 1 ie, we may choose
among 2 1 4.

etc.

This is what I meant when I said this would be like linear selection,
because once something is in its correct position, it doesn't get
moved. But you might also be able to achieve a uniform sort if in
stages 1 and up, you are still allowed to choose anything you want to
be the head. I'll let someone else figure it out :P.


 Help me review my undergraduate data structures here -- is there some
 way to pick each item _exactly_once_ in O(n) time?

I think I answered this in the first segment of this post. Let me know
if I don't seem clear.

 
 Dave Wonnacott

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


Re: How to test if object is sequence, or iterable?

2006-07-22 Thread Tim N. van der Leeuw

Bruno Desthuilliers wrote:
 Tim N. van der Leeuw a écrit :
  Hi,
 
  I'd like to know if there's a way to check if an object is a sequence,
  or an iterable. Something like issequence() or isiterable().
 
  Does something like that exist? (Something which, in case of iterable,
  doesn't consume the first element of the iterable)

 isiterable = lambda obj: isinstance(obj, basestring) \
   or getattr(obj, '__iter__', False)


 Should cover most cases.

Yes, that seems to cover all cases I can think of, indeed. Funny
though, that string objects do not have an '__iter__' method, but are
still iterable... But it will make most of my use-cases easier: Often I
want to iterate over something, if it's an iterable, except when it's a
string.


Thanks,

--Tim

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


Re: Converting argv to variable

2006-07-22 Thread Terry Reedy

tgiles [EMAIL PROTECTED] wrote in message 
news:[EMAIL PROTECTED]
 (now that I've posted in the wrong flipping newsgroup the first thing,
 here's my question to the lovely python folks)

 I've taken a year off (or so) using Python and the first thing I run
 into utterly stumped me. Been too long and none of the searches I've
 done seems to have helped any.
 Basically, I'm trying to create a little script which will make a new
 directory, using the argument passed to it to give the directory a
 name:

 #!/usr/bin/python
 import sys, os
 newDirectory = str(sys.argv[1:])

If you are only going to make one dir at a time, newDir = sys.argv[1]

 currentPath =  str(os.getcwd())
 create =  currentPath + '/' + newDirectory

os.path has platform-independent function to do this

tjr



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


Re: How to automate user input at the command prompt?

2006-07-22 Thread M�ta-MCI
Hi!


 There are typically only two output streams from a command line program. 
 stdout and stderr... Some of the OS triggered error messages
(abort, retry, fail) might be going to stderr -- so if you were looking at 
stdout, you won't see them.

- when you use  RD TOTO/S , win show the text Are-you sure (Y/N)? on 
stdout, and no stderr
- when the text is send, by win, on stdout, there are no RC ; consequently, 
subprocess (or popen) don't see anything
- it's possible, with popen4, with subprocess, to merge stdout  stderr in 
the same pipe


The problem remain entire.


@-salutations
-- 
Michel Claveau



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


Re: How to test if object is sequence, or iterable?

2006-07-22 Thread Terry Reedy

Tim N. van der Leeuw [EMAIL PROTECTED] wrote in message 
news:[EMAIL PROTECTED]
 Hi,

 I'd like to know if there's a way to check if an object is a sequence,
 or an iterable. Something like issequence() or isiterable().

How about
try: it = iter(possible_iterable)
except TypeError: bail()

Terry Jan Reedy



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


Re: Nested function scope problem

2006-07-22 Thread Bruno Desthuilliers
Josiah Manson a écrit :
 I found that I was repeating the same couple of lines over and over in
 a function and decided to split those lines into a nested function
 after copying one too many minor changes all over. The only problem is
 that my little helper function doesn't work! It claims that a variable
 doesn't exist. If I move the variable declaration, it finds the
 variable, but can't change it. Declaring the variable global in the
 nested function doesn't work either.
 
 But, changing the variable in the containing scope is the whole purpose
 of this helper function.
 
 I'm new to python, so there is probably some solution I haven't
 encountered yet. Could you please suggest a nice clean solution? The
 offending code is below. Thanks.
 
 def breakLine(s):
   Break a string into a list of words and symbols.
   
   def addTok():
   if len(tok)  0:

 if tok:

An empty sequence evals to False in a boolean context.

   ls.append(tok)
   tok = ''
 

First point: the nested function only have access to names that exists 
in the enclosing namespace at the time it's defined.

Second point: a nested function cannot rebind names from the enclosing 
namespace. Note that in Python, rebinding a name and modifying the 
object bound to a name are very distinct operations.

Third point : functions modifying their environment this way are usually 
considered bad form.

Here's a possible solution - but note that there are probably much 
better ways to get the same result...

def breakline(line):
   Break a string into a list of words and symbols.
   class TokenList(list):
 def append(self, token):
   if token:
 list.append(self, token)
   return ''

   tokens = TokenList()
   token = ''
   splitters = '?()|:~,'
   whitespace = ' \t\n\r'
   specials = splitters + whitespace

   for char in line:
 if char in specials:
token = tokens.append(token)
 if char in splitters:
   tokens.append(char)
 else:
   token += char

   tokens.append(token)
   return list(tokens)

(snip)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Nested function scope problem

2006-07-22 Thread Bruno Desthuilliers
Justin Azoff a écrit :
 Simon Forman wrote:
 
That third option seems to work fine.
 
 
 Well it does, but there are still many things wrong with it
 
(snip)

 tok = ''
 tok = toc + c
 should be written as
 tok = []
 tok.append(c)
 and later
 ''.join(toc)

IIRC, string concatenation slowness has been fixed a few versions ago - 
at least in CPython - , so there's  no more reason to use this idiom.

(snip)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Nested function scope problem

2006-07-22 Thread Bruno Desthuilliers
Justin Azoff a écrit :
 Simon Forman wrote:
 
That third option seems to work fine.
 
 
 Well it does, but there are still many things wrong with it
 
 if len(tok)  0:
 should be written as
 if(tok):
 

actually, the parenthesis are useless.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Nested function scope problem

2006-07-22 Thread Bruno Desthuilliers
Lawrence D'Oliveiro a écrit :
 In message [EMAIL PROTECTED], Justin 
 Azoff wrote:
 
 
Simon Forman wrote:

That third option seems to work fine.

Well it does, but there are still many things wrong with it

if len(tok)  0:
should be written as
if(tok):
 
 
 I prefer the first way.

This is your right, but it's not the python idiom.

 Besides, your way is sub-optimal.

Care to explain ?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python newbie needs constructive suggestions

2006-07-22 Thread Bruno Desthuilliers
Lawrence D'Oliveiro a écrit :
 In message [EMAIL PROTECTED],
 [EMAIL PROTECTED] wrote:
 
 
  b) give up on using an anonymous function and create a named successor
  function with def,
 
 
 This is what you have to do.

Not necessarily.

map(lambda x, one=1: one + x, range(42))

 For some reason mr van Rossum has this aversion
 to anonymous functions, and tries to cripple them as much as possible.

For some reasons, including the fact that Python is statement based and 
have significative indentation, it's actually not trivial to come with a 
better syntax for lambdas. The horse has been beaten to hell and back, 
and no one managed to propose anything worth implementing so far. But if 
you have the solution to this problem, please share...
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: function v. method

2006-07-22 Thread danielx
Bruno Desthuilliers wrote:
 danielx wrote:
  Bruno Desthuilliers wrote:
 
 danielx wrote:
 
 (snip)
 
 Obviously, such things would be omitted from your docs, but users also
 learn by interacting with Python, which is really one of Python's great
 virtues. When supporting documents aren't sufficient to learn an api
 (I'm sure this never happens, so just humor me), you can always turn to
 interactive Python.
 
 ...and source code...
 
 
  *shudders* What happened to all the goodness of abstraction?

 Compared to machine language, Python source code is really abstration.


And machine language is an abstraction of pushing electrons around
circuits. I'm not sure I see your point, unless it is simply that
Python is easier than asm.

 --
 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: Nested function scope problem

2006-07-22 Thread Justin Azoff
Bruno Desthuilliers wrote:
 Justin Azoff a écrit :
  if len(tok)  0:
  should be written as
  if(tok):
 

 actually, the parenthesis are useless.

yes, that's what happens when you edit something instead of typing it
over from scratch :-)

-- 
- Justin

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


Re: New to threads. How do they work?

2006-07-22 Thread Edmond Dantes
Dennis Lee Bieber wrote:

 On Sat, 22 Jul 2006 17:19:22 +1200, Lawrence D'Oliveiro
 [EMAIL PROTECTED] declaimed the following in
 comp.lang.python:
 
 
 Perhaps because with threads, data is shared by default. Whereas with
 processes, it is private by default, and needs to be explicitly shared if
 you want that.
 
 Or just that the name thread was a late-comer for some of us...
 
 The Amiga had tasks at the lowest level (these were what the core
 OS library managed -- that core handled task switching, memory
 allocation, and IPC [event flags, message ports]). Processes were
 scheduled by the executive, but had additional data -- like stdin/stdout
 and environment variables... all the stuff one could access from a
 command line. Or, confusing for many... Processes were DOS level,
 Tasks were OS level.

On the Amiga, everything was essentially a thread. There was *no* memory
protection whatsoever, which made for a wickedly fast -- and unstable --
OS.

Now, before Commordore went the way of the Dodo Bird, there was some
discussion about adding memory protection to the OS, but that was a very
difficult proposition since most if not all of the OS control structures
were just that -- basically c structs, with live memory pointers handed
around from application to kernel and back.

I think we could've done it eventually, but that ship sank. All because of
the idiots there that was upper management. But I digress.
 
-- 
-- Edmond Dantes, CMC
And Now for something Completely Different:
  http://baskets.giftsantiquescollectables.com
  http://vacation-packages.YouDeserveItNow.com
  http://cold-remedy.WomenLite.com
  http://investments.BankOrLoan.com
  http://coils.IndustrialMetalz.com
  http://brackets.Auto1Parts.com
  http://windmill.industrialtips.com


 Posted Via Usenet.com Premium Usenet Newsgroup Services
--
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
--
http://www.usenet.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: function v. method

2006-07-22 Thread danielx

Gerhard Fiedler wrote:
 On 2006-07-20 18:10:21, danielx wrote:

  When supporting documents aren't sufficient to learn an api (I'm sure
  this never happens, so just humor me), you can always turn to
  interactive Python.
 
  ...and source code...
 
  *shudders* What happened to all the goodness of abstraction?

 Abstraction as you seem to use it requires complete docs of the interface.
 Which is what you said you don't have... So the original abstractor broke
 the abstraction when publishing insufficient docs, not the one who looks
 into the sources to find out what actually happens.

Absolutely. I didn't mean the user was breaking abstraction (let's not
blame the victim). I was saying that we should really have more
sympathy for him.

 
 (This independently of the merits of abstraction.)
 
 Gerhard

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


Re: function v. method

2006-07-22 Thread Bruno Desthuilliers
danielx a écrit :
 Bruno Desthuilliers wrote:
 
danielx wrote:

Bruno Desthuilliers wrote:


danielx wrote:


(snip)

Obviously, such things would be omitted from your docs, but users also
learn by interacting with Python, which is really one of Python's great
virtues. When supporting documents aren't sufficient to learn an api
(I'm sure this never happens, so just humor me), you can always turn to
interactive Python.

...and source code...


*shudders* What happened to all the goodness of abstraction?

Compared to machine language, Python source code is really abstration.

 And machine language is an abstraction of pushing electrons around
 circuits. I'm not sure I see your point, unless it is simply that
 Python is easier than asm.

Python is very hi-level, and very often well-written Python code is it's 
own better documentation.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: function v. method

2006-07-22 Thread danielx
fuzzylollipop wrote:
 danielx wrote:
  Bruno Desthuilliers wrote:
   danielx wrote:
At first I was going to post the following:
   
!-- beginning of my original post --
   
   (snip)
   
!-- end of my original post, with ending censored --
   
but then I tried this:
   
   
   res = Foo.__dict__['func']
   res is dan
   
True
   
And it all started to make sense. The surprising thing turned out to be
not so surprising: When the expression Foo.func gets evaluated, we get
a method which is just a wrapper around dan. Therefore, f is not dan!
This is still a little bit of magic,
  
   FWIW, the function class implements the descriptor protocol... Here's
   the magic.
  
which gets me thinking again about
the stuff I self-censored. Since the dot syntax does something special
and unexpected in my case,
  
   unexpected ? Did you ever wondered how the instance or class was
   passed as first arg when doing method calls ?
 
  Not knowing what's going on during method calls is exactly what
  motivated me to post.
 
  
why not use some more dot-magic to implement
privates?
  
   What for ? What makes you think we need language-inforced access
   restriction ?
 
  I knew someone would bring this up. The motivation would not be to
  provide restriction, but to help maintain clean api's. If you intended
  for users to use only a subset of the methods in your class, why not
  help them learn your api by presenting the stuff they can use not along
  side the stuff they should not?
 
  Obviously, such things would be omitted from your docs, but users also
  learn by interacting with Python, which is really one of Python's great
  virtues. When supporting documents aren't sufficient to learn an api
  (I'm sure this never happens, so just humor me), you can always turn to
  interactive Python. This is exactly what it's there for. If nothing is
  hidden, a user could be easily mislead to believe he can use a method
  when he really shouldn't.
 


 if you prefix with a single underscore, that tells the user, DON'T MESS
 WITH ME FROM OUTSIDE! I AM AN IMPLEMENTATION DETAIL!

 and it gets ommited from all the doc generation

 if you prefix with a double underscore, then they have to go even
 FARTHER out of their way to shoot themselves in the foot.

 Python takes the stance of personal responsiblity when it comes to
 access control. Which in NO WAY dimishes its robustness or anything
 else.

 just read the DailyWTF.com, incompentent people will abuse any language
 features in any language, and will figure out how to break programatic
 access control no matter how it is implemented. Matter of fact, Java
 which in another thread someone was ADAMANT that did not expose private
 anything from reflection ( and was wrong ) specifically allows you to
 access all the private members, functions, everything. You just need to
 tell it to turn all the safeties off.

 From the api:

 public void setAccessible(boolean flag)
 throws SecurityException

 Set the accessible flag for this object to the indicated boolean value.
 A value of true indicates that the reflected object should suppress
 Java language access checking when it is used. A value of false
 indicates that the reflected object should enforce Java language access
 checks.

 Setting the accessible flag in a reflected object permits sophisticated
 applications with sufficient privilege, such as Java Object
 Serialization or other persistence mechanisms, to manipulate objects in
 a manner that would normally be prohibited.

 so anything added to Python to enforce access control would
 immediately be forced to provide some means to over-ride the checks for
 pickle and the like. Not to even mention the argument that it would
 break crap loads of existing code base.

Sigh. I TOTALLY realize that Python works by politeness and not
enforcement. I think you are misinterpreting why I think this would be
a good idea. My concern is not with control, but with convenience. My
suggestion was that privates would only be invisible if you use the dot
syntax (ie if you are an external user); they would not be invisible
altogether (they would still be in __dict__ with no name games).

One problem which was brought up about this was that self.meth and
outsider.meth would have to be interpretted differently. I suspect (but
I haven't finished my reading assignment :P) that you could find a good
way around this.

With respect to breaking stuff. I'm not sure why that would be
necessary. If current code does not say any member is private,
everything that was visible before (ie everything) would still be
visible after.

Last thing. You mentioned that auto doc generation omits
underscore-prefixed and name mangled members. dir on the other hand
does not. Maybe this suggests only a minor future improvement.

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


Re: Isn't there a better way?

2006-07-22 Thread Dave Hansen
On 21 Jul 2006 07:51:15 -0700 in comp.lang.python, T
[EMAIL PROTECTED] wrote:


I am using an optparse to get command line options, and then pass them
to an instance of another class:



# Class that uses optparse.OptionParser
foo = Parse_Option()

# Class that does the real work
bar = Processor()

bar.index = foo.options.index
bar.output  = foo.options.output
bar.run()


How about

   class Processor(whatever):
  ...
  def __init__(self,whatever_else):
  ...
  self.op = Parse_Option()

   ...
   bar = Processor()
   bar.run()

This would even let you do some preliminary option processing during
object initialization.

Regards,

   
-=Dave

-- 
Change is inevitable, progress is not.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: function v. method

2006-07-22 Thread danielx
Bruno Desthuilliers wrote:
 danielx a écrit :
  Bruno Desthuilliers wrote:
 
 danielx wrote:
 
 Bruno Desthuilliers wrote:
 
 
 danielx wrote:
 
 
 (snip)
 
 Obviously, such things would be omitted from your docs, but users also
 learn by interacting with Python, which is really one of Python's great
 virtues. When supporting documents aren't sufficient to learn an api
 (I'm sure this never happens, so just humor me), you can always turn to
 interactive Python.
 
 ...and source code...
 
 
 *shudders* What happened to all the goodness of abstraction?
 
 Compared to machine language, Python source code is really abstration.
 
  And machine language is an abstraction of pushing electrons around
  circuits. I'm not sure I see your point, unless it is simply that
  Python is easier than asm.

 Python is very hi-level, and very often well-written Python code is it's
 own better documentation.

Yes, Python is very easy to read, but who's supposed to be reading it?
Maintainers or users? I'm really against code acting as its own
documentation. Of course the code is authoritative, but should we
really EXPECT it to serve as a reference to users??

Appearantly, this view puts me in the minority...

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


Re: function v. method

2006-07-22 Thread Bruno Desthuilliers
danielx a écrit :
 
(snip)
 Sigh. I TOTALLY realize that Python works by politeness and not
 enforcement. I think you are misinterpreting why I think this would be
 a good idea. My concern is not with control, but with convenience.

Having free access to implementation is convenient IMHO.

 My
 suggestion was that privates would only be invisible if you use the dot
 syntax (ie if you are an external user); they would not be invisible
 altogether (they would still be in __dict__ with no name games).

How would this work for class attributes ? (implementation methods, 
implementation descriptors etc...)

Also, it would impact lookup perfs, which is already a somewhat weak 
point in Python.




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


Re: function v. method

2006-07-22 Thread danielx
Bruno Desthuilliers wrote:
 Antoon Pardon wrote:
  On 2006-07-21, fuzzylollipop [EMAIL PROTECTED] wrote:
 
 danielx wrote:
 
 (snip)
 
 
 if you prefix with a single underscore, that tells the user, DON'T MESS
 WITH ME FROM OUTSIDE! I AM AN IMPLEMENTATION DETAIL!
 
 
  Personnaly I don't like this convention.

 To bad for you.

  It isn't clear enough.

 Oh yes ?

  Suppose I am writing my own module, I use an underscore, to
  mark variables which are an implementation detail for my
  module.
 
  Now I need to import an other module in my module and need access
  to an implementation variable from that module.
 
  So now I have
  variables with an underscore which have two different meanings:
 
1) This is an implemantation detail of this module, It is the
   users of my module who have to be extra carefull using it.
 
2) This is an implemantation detail of the other module,
   I should be extra carefull using it.

 Either you imported with the from othermodule import * form (which you
 shouldn't do), and you *don't* have the implementation of othermodule,
 or your used the import othermodule form, in which case it's pretty
 obvious which names belongs to othermodule.

 Have any other, possibly valid, reason ?

  And I find variable starting or ending with an underscore ugly. :-)

 Too bad for you. Choose another language then... PHP, Perl, Ruby ?-)


Too bad for you: While you have a valid point that this contention is
really just arbitrary (just like all conventions), could we be a little
gentler?

Personally, I don't think it looks very good either, but you just have
to deal with it if you're going to use the language properly.

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


Re: How to test if object is sequence, or iterable?

2006-07-22 Thread Marc 'BlackJack' Rintsch
In [EMAIL PROTECTED], Bruno Desthuilliers wrote:

 Tim N. van der Leeuw a écrit :
 Hi,
 
 I'd like to know if there's a way to check if an object is a sequence,
 or an iterable. Something like issequence() or isiterable().
 
 Does something like that exist? (Something which, in case of iterable,
 doesn't consume the first element of the iterable)
 
 isiterable = lambda obj: isinstance(obj, basestring) \
   or getattr(obj, '__iter__', False)
 
 
 Should cover most cases.

What about objects that just implement an apropriate `__getitem__()`
method?

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

Re: function v. method

2006-07-22 Thread Bruno Desthuilliers
danielx a écrit :
 Bruno Desthuilliers wrote:
 
danielx a écrit :

Bruno Desthuilliers wrote:


danielx wrote:


Bruno Desthuilliers wrote:



danielx wrote:


(snip)


Obviously, such things would be omitted from your docs, but users also
learn by interacting with Python, which is really one of Python's great
virtues. When supporting documents aren't sufficient to learn an api
(I'm sure this never happens, so just humor me), you can always turn to
interactive Python.

...and source code...


*shudders* What happened to all the goodness of abstraction?

Compared to machine language, Python source code is really abstration.


And machine language is an abstraction of pushing electrons around
circuits. I'm not sure I see your point, unless it is simply that
Python is easier than asm.

Python is very hi-level, and very often well-written Python code is it's
own better documentation.
 
 
 Yes, Python is very easy to read, but who's supposed to be reading it?
 Maintainers or users?

In an ideal world, nobody !-)

 I'm really against code acting as its own
 documentation. 

I'm really for it, because :

 Of course the code is authoritative,

indeed.

 but should we
 really EXPECT it to serve as a reference to users??

Unless you're able to maintain a good, accurate and always up to date 
documentation, you can be sure users (ie other programmers) will turn to 
the code. Also, there are cases where even a pretty good doc is not 
enough, and you really have to turn to the code to know for sure how to 
best implement something.

FWIW, reading source code can be very instructive...

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


Re: How to test if object is sequence, or iterable?

2006-07-22 Thread Bruno Desthuilliers
Marc 'BlackJack' Rintsch a écrit :
 In [EMAIL PROTECTED], Bruno Desthuilliers wrote:
 
 
Tim N. van der Leeuw a écrit :

Hi,

I'd like to know if there's a way to check if an object is a sequence,
or an iterable. Something like issequence() or isiterable().

Does something like that exist? (Something which, in case of iterable,
doesn't consume the first element of the iterable)

isiterable = lambda obj: isinstance(obj, basestring) \
  or getattr(obj, '__iter__', False)


Should cover most cases.
 
 
 What about objects that just implement an apropriate `__getitem__()`
 method?

Hmmm... (quick test)

Good point.

FWIW, Terry's solution might be far better.
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Python website problem?

2006-07-22 Thread Aahz
In article [EMAIL PROTECTED],
Tim N. van der Leeuw [EMAIL PROTECTED] wrote:

Does the Python.org website have a problem? I only get a directory
index, and clicking on any of the HTML files in there shows a page
without any CSS makeup.

Anyone noticed this too?

Yes, we're having problems with the build system.  Nothing to see here,
move along.
-- 
Aahz ([EMAIL PROTECTED])   * http://www.pythoncraft.com/

Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are, by
definition, not smart enough to debug it.  --Brian W. Kernighan
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: random shuffles

2006-07-22 Thread Ross Ridge
David G. Wonnacott wrote:
 Couldn't we easily get an n*log(n) shuffle...

Why are you trying to get an O(n*log(n)) shuffle when an O(n) shuffle
algorithim is well known and implemented in Python as random.shuffle()?

 Ross Ridge

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


Re: using names before they're defined

2006-07-22 Thread Nick Vatamaniuc
Dave,

Sometimes generating classes from .ini or XML files is not the best
way. You are just translating one language into another and are making
bigger headaches for your self. It is certainly cool and bragable to
say that my classes get generated on the fly from XML but  Python is
terse and reasonable enough to just write it in Python. In other words
instead of saying turbine power2MW/power/turbine just write
some Python code that instantiates a turbine  with a 2MW power based on
your class. Then you can evaluate Python code in Python and you even
got your on-the-fly generation.
As a general rule, I would say to think 3 times before touching XML in
Python unless you are absolutely forced to. Config .ini files can be
more acceptable but Python is still best. Why write
;;My turbine class
[turbine]
power=2MW
speed=800rpm
...
when you can just say:
#my turbine class
t=Turbine( power=2MW, \
   speed=800rpm, \
   ...
First case is a little shorter but then you have to use a parser for it
while in the second case you just execute the file, and besides, you
can edit it with any Python editor.

Hope this helps,
Nick V.


[EMAIL PROTECTED] wrote:
 Hi

  Also, I gave the example using Python code as 'config' format, but any
  structured enough text format could do, ie JSON, XML, or even ini-like:
 
  # schema.ini
  objects = turbine1, frobnicator2
 
  [turbine1]
  class=Turbine
  upstream=frobnicator2
  downstream=
 

 yes, I like the idea of using .ini type file format or XML, very much.
 There are parser available which will automatically building python
 objects from this, won't they (like configparser)? I'll have to get
 reading over the weekend...

  def get_class_by_name(name):
return globals()[name]
  
 
  QD way to retrieve the class object (Python's classes are themselves
  objects) known by it's name (as a string).

 ok, so it actually returns the class object itself.
 One thing that confuses me is that objects have a name (self.name) but
 object instances also have a name (e.g. myspecialturbine = turbine(...)
  how do I discover the name 'myspecialturbine' ?). And object
 instances have a class name too ('turbine'). Aaargh, too many names!
 what if just want to know what the name of the instance is (in this
 case 'myspecialturbine'?)

 Right. I'll have a go at pulling all this together over the weekend
 hopefully. Hurrah! Thanks for all the help, to everyone.
 Dave

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


Re: subprocess module

2006-07-22 Thread Tim Roberts
placid [EMAIL PROTECTED] wrote:

Hi all,

If someone could give me an example of creating a subprocess (on
Windows) using the subprocess module and Popen class and connecting to
its stdout/stdin file handles. I googled for a bit but the only example
i found was here ;

Use the source, Luke.  The best examples of the use of subprocess are
contained in the introductory comments in the module itself.
-- 
- Tim Roberts, [EMAIL PROTECTED]
  Providenza  Boekelheide, Inc.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to test if object is sequence, or iterable?

2006-07-22 Thread Nick Vatamaniuc
Tim,

An object is iterable if it implements the iterator protocol. A good
enough check to see if it does is to check for the presense of the
__iter__() method. The way to do it is:
hasattr(object,'__iter__')

You are correct in the fact that you check if an object is iterable
rather than using isinstance to check if it is of a partucular type.
You are doing things 'the pythonic way' ;)

Nick Vatamaniuc


Tim N. van der Leeuw wrote:
 Hi,

 I'd like to know if there's a way to check if an object is a sequence,
 or an iterable. Something like issequence() or isiterable().

 Does something like that exist? (Something which, in case of iterable,
 doesn't consume the first element of the iterable)
 
 Regards,
 
 --Tim

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


Type signature

2006-07-22 Thread Yacao Wang
Hi, I'm a newbie to Python. I've recently read some books about this language and none of them have answered my question. As a dynamically-typed language Python doesn't need any form of type signature which makes the syntax very clean and concise. However, type signatures are not only a kind of information provided for the compiler, but also for the programmer, or more important, for the programmer. Without it, we have to infer the return type or required agument types of a function, and this can't be done without seeing the implementation of it, and sometimes it is still difficult to extract the above information even if the implementation is available. Haskell can also determine type information dynamically, but it still supports and recommends the programming style with type signatures, which makes the code very readable and maitainable. As I understand, Python relies too much on run-time type-checking, that is, whenever you give the wrong type, you just end up with an exception, which is logically correct, but not that useful as type signatures.
Any ideas on this issue? -- Alex
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: httplib, threading, wx app freezing after 4 hours

2006-07-22 Thread Nick Vatamaniuc
Mark,

httplib will block waiting for a server connection. I am not sure if
that is your problem but you could try a quick and dirty workaround of
recording a timestamp of the last data transfer and then have a timer
in a separate thread and if too much time passed, restart the retrieval
thread and issue a warning.  Also check the memory on your machine in
case some buffer fills the memory up and the machine gets stuck.
To understand what's really happening try to debug the program. Try
Winpdb debugger you can find it here:
http://www.digitalpeers.com/pythondebugger/
Nick Vatamaniuc

Mark rainess wrote:
 The program displays images from a motion jpeg webcam.
 (Motion jpeg is a bastardization of multi-part mime.)
 http://wp.netscape.com/assist/net_sites/pushpull.html

 It runs perfectly for about 4 hours, then freezes.
 I'm stuck. How do I debug this?

 (Using: Python 2.4.3, wxPython 2.6.3.2, Windows 2000 and XP)

 There are no tracebacks, the gui continues to run,
 isAlive() and activeCount() indicate that the thread is OK,
 print I'm alive stops. CPU % usage is 0

 I figure it is hanging in r.readline() or f.read()

 Can anyone suggest techniques to help me learn what is going on.

 I'm using httplib.HTTP instead of httplib.HTTPConnection because
 I don't find that HTTPConnection has readline().


 Mark Rainess


 =
 class mjpeg_get(threading.Thread):
  def run(self):
  while 1:
  while 1:
  # print I'm connecting
  h = httplib.HTTP(self.url)
  h.putrequest('GET','VIDEO.CGI')
  h.putheader('Accept','text/html')
  h.endheaders()
  if errcode == 200:
  f = h.getfile()
  break
  # cleanup and try again

  s = cStringIO()
  while 1:
  # print I'm alive
  try:
  # do f.readline() to get headers
  # get count from 'Content-length:'
  s.reset()
  s.write(f.read(count))
  s.truncate()
  wx.CallAfter(self.window.onUpdateImg, s)
  continue
  except:
  # print error
  # cleanup and try again
  break

 class Frame(wx.Frame):
  def OnIdle(self, event):
  # for debugging display result of
  # Thread.isAlive()
  # threading.activeCount()
  if self.gotImage is True:
  # do display self.sImage
  self.gotImage = False
  def onUpdateImg(self, parm):
  if self.gotImage is False:
  self.sImage.reset()
  self.sImage.write(parm.getvalue())
  self.sImage.truncate()
  self.sImage.reset()
  self.gotImage = True
 =

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


Re: Type signature

2006-07-22 Thread Marc 'BlackJack' Rintsch
In [EMAIL PROTECTED], Yacao Wang
wrote:

 However, type signatures are not only a kind of information provided for
 the compiler, but also for the programmer, or more important, for the
 programmer. Without it, we have to infer the return type or required
 agument types of a function, and this can't be done without seeing the
 implementation of it,

That's what documentation is meant for.  If you are forced to look at the
implementation, the documentation is bad.

 Haskell can also determine type information dynamically, but it still
 supports and recommends the programming style with type signatures,

Does Haskell really determine the type information dynamically!?  AFAIK
it's done at compile time.

 which makes the code very readable and maitainable. As I understand,
 Python relies too much on run-time type-checking, that is, whenever you
 give the wrong type, you just end up with an exception, which is
 logically correct, but not that useful as type signatures. Any ideas on
 this issue?

Which issue?  ;-)

Just stop thinking in terms of types.  Python is about *behavior*.  If
the docs say `this functions takes an iterable as input` then `iterable`
isn't a specific type but an object that implements the behavior of an
iterable.  You can't check that reliable without actually trying to
iterate over it.  Search for duck typing.

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


Re: Type signature

2006-07-22 Thread hanumizzle

Yacao Wang wrote:
 Hi, I'm a newbie to Python. I've recently read some books about this
 language and none of them have answered my question.
 As a dynamically-typed language Python doesn't need any form of type
 signature which makes the syntax very clean and concise.

OK...

 However, type
 signatures are not only a kind of information provided for the compiler

Statically-typed code tends (generally) to be faster than
dynamically-typed code, obviously. Often, it doesn't really matter,
though. (This is an old argument.)

Lush is an interesting Lisp-like language that supports admixture of
dynamic and static typing, and uses type signatures to support it. It
can produce high performance machine code because of this.

 Python relies too much on run-time type-checking, that is,
 whenever you give the wrong type, you just end up with an exception, which
 is logically correct, but not that useful as type signatures.

As said before, polymorphism plays an important role. In addition to
looking up 'duck typing' (c.f. Programming Ruby), it might also be
useful to look for Damian Conway's observations on 'interface
polymorphism' (standard practice in Perl, Python, Ruby, etc.) vs.
'inheritance polymorphism' (what you get with C++ and IIRC Java).

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


Dive Into Python -- Still Being Updated?

2006-07-22 Thread hanumizzle
I find Dive Into Python generally an excellent text, and I am not
surprised to see people recommending it...but I have noticed a few
errors already:

http://diveintopython.org/getting_to_know_python/indenting_code.html

The function called fib (presumably short for Fibonacci) appears to
produce factorials. Anyway, 'fib' should really be called 'hem'. :)

http://diveintopython.org/native_data_types/tuples.html#odbchelper.tuplemethods

I think tuples have methods, na?

[EMAIL PROTECTED]:~$ python
Python 2.4.3 (#1, Jun 20 2006, 11:52:59)
[GCC 3.3.5 (Debian 1:3.3.5-13)] on linux2
Type help, copyright, credits or license for more information.
 print \n.join(dir(tuple))
__add__
__class__
__contains__
__delattr__
__doc__
__eq__
__ge__
__getattribute__
__getitem__
__getnewargs__
__getslice__
__gt__
__hash__
__init__
__iter__
__le__
__len__
__lt__
__mul__
__ne__
__new__
__reduce__
__reduce_ex__
__repr__
__rmul__
__setattr__
__str__


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


Re: Sansung YH-920 + Linux + yh-925-db-0.1.py = AttributeError: 'module' object has no attribute 'decode'

2006-07-22 Thread John Machin
rsd wrote:
 Hi,

 I'm trying get Samsung YH-920 mp3 player to work with Debian GNU/Linux.
 To do that I need to run
http://www.paul.sladen.org/toys/samsung-yh-925/yh-925-db-0.1.py
 script, the idea behind the script is described at
http://www.paul.sladen.org/toys/samsung-yh-925/

 I'm getting errors and hoping someone could give me some hints, for I
 have no python background.

 This is what I've done:
 1. mounted YH-920 as /mnt/usb and transfered my MP3s to
 /mnt/usb/System/music/mp3 folder. That was easy.

 2. Now, I need to run yh-925-db-0.1.py to update the database.

[snip]



 test:/mnt/usb/System# ./yh-925-db-0.1.py
 Traceback (most recent call last):
 File ./yh-925-db-0.1.py, line 195, in ?
 de.add_from_dict(e.unpack3(f))
 File ./yh-925-db-0.1.py, line 53, in unpack3
 u = utf_16_le.decode(fp.read(size))
 AttributeError: 'module' object has no attribute 'decode'

 Any ideas? Thanks

You don't say which version of Python you are running ... but my guess
is that it's 2.3 or earlier.

What the author is doing appears to be undocumented in Python 2.4 and
not supported in 2.3  earlier.


Option (1): Upgrade your Python to 2.4 (visit www.python.org).
Option (2): Pass this problem description on to the author:

C:\junkpython
Python 2.4.3 (#69, Mar 29 2006, 17:35:34) [MSC v.1310 32 bit (Intel)]
on win32
Type help, copyright, credits or license for more information.

| from encodings import utf_16_le
# The above is not documented.

# get some sample data in utf-16-le encoding:
| u = u'abcdef'
| u
u'abcdef'
| le16 = u.encode('utf-16-le')
| le16
'a\x00b\x00c\x00d\x00e\x00f\x00'

| utf_16_le.decode(le16)
(u'abcdef', 12)
# Doesn't work on Python 2.3 and earlier -- the decode() and encode()
functions are not exposed.
# Note: returns a tuple containing (unicode_object, length_in_bytes).
In the Python script for the music player,  the length is not used and
the unicode object has to be extracted by doing the_tuple[0]

# One documented way of decoding a string strg using encoding enc is
strg.decode(enc)
| le16.decode('utf-16-le')
u'abcdef'
# ... but this was introduced in 2.2. The builtin unicode(strg, enc)
function (also documented) does the same thing  works all the way back
to Python 2.1 at least (I didn't keep copies of 1.6  2.0) . I've heard
of Linux users stuck on 2.1 for whatever reason but not on earlier
versions.

C:\junkc:\python21\python
Python 2.1.3 (#35, Apr  8 2002, 17:47:50) [MSC 32 bit (Intel)] on win32
Type copyright, credits or license for more information.
| from encodings import utf_16_le
| u = u'abcdef'
| u
u'abcdef'
| le16 = u.encode('utf-16-le')
| le16
'a\x00b\x00c\x00d\x00e\x00f\x00'
| utf_16_le.decode(le16)
Traceback (most recent call last):
  File stdin, line 1, in ?
AttributeError: 'encodings.utf_16_le' module has no attribute 'decode'
| unicode(le16, 'utf-16-le')
u'abcdef'
|

Option (3): hack the source code along the above lines ...
Option (4): hope somebody will hack it for you 

HTH,
John

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


Compiler for external modules for python

2006-07-22 Thread pretoriano_2001
Hello:
I have interesting external modules that I want to incorporate to
python 2.4.3 and python 2.5b2 also. Some of them requires C/C++
compiler. I work with Win XP Sp2 and have installed VC2005 express (I
do not know if the compiler is the one with optimizing
characterisitics), when trying to install some module using distutils
program, it asks for C/C++ VC7 that is part of VS2003, it seems
distutils is not configured for VC8 that is part of VC2005.
Under this circumstances I tried to find the VC7 compiler from
microsoft sites, however it deflect to the new version of VS2005, so I
lost the cord and the goat .
I do not know what to do. Does anybody has some guidelines about this
matter?
Thanks!!!

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


Re: How to use pdb?

2006-07-22 Thread R. Bernstein
[EMAIL PROTECTED] writes:

 R. Bernstein wrote:
  Perhaps what you are looking for is:
python /usr/lib/python2.4/pdb.py Myprogram.py
 
 I tried this and it did not work.  pdb did not load the file so it
 could be debugged.

lol. Yes, if you are not in the same directory as Myprogram.py you may
have to add be more explicit about where Myprogram.py is. 

Reminds me of the story of the guy who was so lazy that when he got an
award for laziest person alive he said, roll me over and put it in
my back pocket. :-)

Glad you were able to solve your problem though.

For other similarly confused folks I have updated pydb's
documentation (in CVS):

  In contrast to running a program from a shell (or gdb), no path
  searching is performed on the python-script. Therefore python-script
  should be explicit enough (include relative or absolute file paths)
  so that the debugger can read it as a file name. Similarly, the
  location of the Python interpeter used for the script will not
  necessarily be the one specified in the magic field (the first line
  of the file), but will be the Python interpreter that the debugger
  specifies. (In most cases they'll be the same and/or it won't
  matter.)

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


Which Pyton Book For Newbies?

2006-07-22 Thread W. D. Allen
I want to write a retirement financial estimating program. Python was 
suggested as the easiest language to use on Linux. I have some experience 
programming in Basic but not in Python.

I have two questions:
 1. What do I need to be able to make user GUIs for the program, and
 2. Which book would be easiest to use to learn Python programming?

Thanks,

WDA
[EMAIL PROTECTED]

end
 


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


Re: Which Pyton Book For Newbies?

2006-07-22 Thread pretoriano_2001

W. D. Allen wrote:
 I want to write a retirement financial estimating program. Python was
 suggested as the easiest language to use on Linux. I have some experience
 programming in Basic but not in Python.

 I have two questions:
  1. What do I need to be able to make user GUIs for the program, and

Try in: www.wxpython.org
or in
http://www.codeplex.com/Wiki/View.aspx?ProjectName=IronPythontitle=More%20Information

  2. Which book would be easiest to use to learn Python programming?

Try in: http://docs.python.org/tut/tut.html
I nice Book I has is in:
http://www.amazon.com/gp/product/159059519X/sr=8-1/qid=1153612000/ref=pd_bbs_1/104-182-3979942?ie=UTF8

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


Re: Which Pyton Book For Newbies?

2006-07-22 Thread pretoriano_2001

W. D. Allen wrote:
 I want to write a retirement financial estimating program. Python was
 suggested as the easiest language to use on Linux. I have some experience
 programming in Basic but not in Python.

 I have two questions:
  1. What do I need to be able to make user GUIs for the program, and

Try in: www.wxpython.org
or in
http://www.codeplex.com/Wiki/View.aspx?ProjectName=IronPythontitle=More%20Information

  2. Which book would be easiest to use to learn Python programming?

Try in: http://docs.python.org/tut/tut.html
I nice Book I has is in:
http://www.amazon.com/gp/product/159059519X/sr=8-1/qid=1153612000/ref=pd_bbs_1/104-182-3979942?ie=UTF8

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


Re: using names before they're defined

2006-07-22 Thread Patrick Maupin

[EMAIL PROTECTED] wrote:
 I have a problem. I'm writing a simulation program with a number of
 mechanical components represented as objects. When I create instances
 of objects, I need to reference (link) each object to the objects
 upstream and downstream of it, i.e.

 supply = supply()
 compressor = compressor(downstream=combustor, upstream=supply)
 combuster = combuster(downstream=turbine, upstream=compressor)
 etc.

 the problem with this is that I reference 'combustor' before is it
 created. If I swap the 2nd and 3rd lines I get the same problem
 (compressor is referenced before creation).


 aargh!!! any ideas on getting around this?

 Dave

I have done similar things in the past.  One useful trick is to define
a special class for connections, create a single instance of this
class, and make all your connections as attributes of this instance.
For example:

world = Simulation()

world.supply = Supply()
world.compressor = Compressor(downstream=world.cumbustor,
upstream=world.supply)
world.cumbuster = Combuster(downstream=world.turbine,
upstream=world.compressor)

Because Python lets you control attribute access to your simulation
world object, it is relatively easy to make proxy objects for
attributes which don't yet exist via __getattr__, and then to insert
the real object into the proxy via __setattr__.

Alternatively, the script (using the same syntax as shown above!) can
simply collect all the connection information when it is run, then make
a real structure later.  This works best if your simulation objects
(Supply, Compressor, Cumbuster) allow setting of the connection
attributes after instantiation.

Regards,
Pat

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


Re: Python proficiency test

2006-07-22 Thread Richard Jones
Kent Johnson wrote:
 I recently helped create an on-line Python proficiency test. The
 publisher of the test is looking for beta testers to try the test and
 give feedback. If you are interested, here is an announcement from the
 publisher:

Had a look. In between my browser blocking a popup on every page and the
registration asking far more details that I felt necessary, I stopped
before looking at the actual test.


Richard

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


Re: Which Pyton Book For Newbies?

2006-07-22 Thread hanumizzle

W. D. Allen wrote:
 I want to write a retirement financial estimating program. Python was
 suggested as the easiest language to use on Linux. I have some experience
 programming in Basic but not in Python.

 I have two questions:
  1. What do I need to be able to make user GUIs for the program, and
  2. Which book would be easiest to use to learn Python programming?

I am a fairly experienced programmer and I have been reading Dive Into
Python. If you have prior experience, you may find it very
satisfactory. (But see a recent thread I started which points out a few
small mistakes...nothing too bad over all.) If you have less
programming experience, you may wish to look at Byte of Python. The
great thing about Python is that there is a ton of online material to
peruse...

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


DRUG EMPIRE - INVEST IN QUANTUM COMPTERS GODS WEPON

2006-07-22 Thread switzerland qunatium computer
DRUG EMPIRE - INVEST IN QUANTUM COMPTERS GODS WEPON

http://www.beyond-science.com RUN THIS WITH A QUNATIUM COMPUTER

THE GREATEST PROTECTION AND RIVAL'S ANY INTELLGENCE AGNECY'S

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


Re: How to test if object is sequence, or iterable?

2006-07-22 Thread Terry Reedy

Nick Vatamaniuc [EMAIL PROTECTED] wrote in message 
news:[EMAIL PROTECTED]
 Tim,

 An object is iterable if it implements the iterator protocol

There are presently two iterator protocols.  The old one will be likely be 
dropped in 3.0 (currently being discussed).

. A good
 enough check to see if it does is to check for the presense of the
 __iter__() method. The way to do it is:
 hasattr(object,'__iter__')

Sorry, this check for the newer and nicer protocol but not the older one.

 hasattr('abc', '__iter__')
False

This may change in 2.6.  The defacto *version-independent* way to determine 
iterability is to call iter(ob).  If it returns an iterator, you can 
iterate; if it raises TypeError, you cannot.  Any it should be patched as 
necessary by the developers to continue doing the right thing in future 
versions.

Terry Jan Reedy



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


Re: Sansung YH-920 + Linux + yh-925-db-0.1.py = AttributeError: 'module' object has no attribute 'decode'

2006-07-22 Thread rsd
 
 You don't say which version of Python you are running ... but my guess
 is that it's 2.3 or earlier.

Yes, you're right. I was using version 2.3.5

I'll see if I can get it working with 2.4

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


Re: getaddrinfo not found on SCO OpenServer 5.0.5

2006-07-22 Thread Martin v. Löwis
[EMAIL PROTECTED] wrote:
 1) I've seen mention of native vs. Python getaddrinfo implementations.
 If that's true, how can I force the program to use the Python one?
 
 2) Is there an option to not use the BSD Library function?
 
 3) Finally, is there a trick to searching for shared libaries?

There is an autoconf test to determine whether getaddrinfo is
available on the system. You should study that test to find out
why it thinks the function is available when it is actually not.
If you can't do that, you can manually edit pyconfig.h to
change the outcome of configure.

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


Re: Compiler for external modules for python

2006-07-22 Thread Martin v. Löwis
[EMAIL PROTECTED] wrote:
 Under this circumstances I tried to find the VC7 compiler from
 microsoft sites, however it deflect to the new version of VS2005, so I
 lost the cord and the goat .
 I do not know what to do. Does anybody has some guidelines about this
 matter?

You need to use VS 2003 to build Python extensions; VS 2005 does not
work. As Microsoft has stopped shipping VS 2003, you could try to get
a copy on ebay.

Alternatively, you can use GNU MingW to build Python extensions.

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


[ python-Bugs-1526585 ] Concatenation on a long string breaks

2006-07-22 Thread SourceForge.net
Bugs item #1526585, was opened at 2006-07-21 18:18
Message generated for change (Comment added) made by mwh
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detailatid=105470aid=1526585group_id=5470

Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: Python Interpreter Core
Group: Python 2.5
Status: Open
Resolution: None
Priority: 5
Submitted By: Jp Calderone (kuran)
Assigned to: Nobody/Anonymous (nobody)
Summary: Concatenation on a long string breaks

Initial Comment:
Consider this transcript:

[EMAIL PROTECTED]:~/Projects/python/trunk$ ./python
Python 2.5b2 (trunk:50698, Jul 18 2006, 10:08:36)
[GCC 4.0.3 (Ubuntu 4.0.3-1ubuntu5)] on linux2
Type help, copyright, credits or license for
more information.
 x = 'x' * (2 ** 31 - 1)
 x = x + 'x'
Traceback (most recent call last):
  File stdin, line 1, in module
SystemError: Objects/stringobject.c:4103: bad argument
to internal function
 len(x)
Traceback (most recent call last):
  File stdin, line 1, in module
NameError: name 'x' is not defined
 


I would expect some exception other than SystemError
and for the locals namespace to not become corrupted.


--

Comment By: Michael Hudson (mwh)
Date: 2006-07-22 10:00

Message:
Logged In: YES 
user_id=6656

Confirmed with 2.4.  Ouch.

--

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detailatid=105470aid=1526585group_id=5470
___
Python-bugs-list mailing list 
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[ python-Bugs-1526585 ] Concatenation on a long string breaks

2006-07-22 Thread SourceForge.net
Bugs item #1526585, was opened at 2006-07-21 13:18
Message generated for change (Comment added) made by tim_one
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detailatid=105470aid=1526585group_id=5470

Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: Python Interpreter Core
Group: Python 2.5
Status: Open
Resolution: None
Priority: 5
Submitted By: Jp Calderone (kuran)
Assigned to: Nobody/Anonymous (nobody)
Summary: Concatenation on a long string breaks

Initial Comment:
Consider this transcript:

[EMAIL PROTECTED]:~/Projects/python/trunk$ ./python
Python 2.5b2 (trunk:50698, Jul 18 2006, 10:08:36)
[GCC 4.0.3 (Ubuntu 4.0.3-1ubuntu5)] on linux2
Type help, copyright, credits or license for
more information.
 x = 'x' * (2 ** 31 - 1)
 x = x + 'x'
Traceback (most recent call last):
  File stdin, line 1, in module
SystemError: Objects/stringobject.c:4103: bad argument
to internal function
 len(x)
Traceback (most recent call last):
  File stdin, line 1, in module
NameError: name 'x' is not defined
 


I would expect some exception other than SystemError
and for the locals namespace to not become corrupted.


--

Comment By: Tim Peters (tim_one)
Date: 2006-07-22 10:11

Message:
Logged In: YES 
user_id=31435

Part of the problem appears to be that ceval.c's
string_concatenate() doesn't check for overflow in the
second argument here:

if (_PyString_Resize(v, v_len + w_len) != 0)

The Windows malloc on my box returns NULL (and so Python
raises MemoryError) on the initial:

x = 'x' * (2 ** 31 - 1)

attempt, so I never get that far.  I'm afraid this is
muddier in strange ways on Linux because the Linux malloc()
is pathologically optimistic (can return a non-NULL value
pointing at memory that can't actually be used for anything).

--

Comment By: Michael Hudson (mwh)
Date: 2006-07-22 05:00

Message:
Logged In: YES 
user_id=6656

Confirmed with 2.4.  Ouch.

--

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detailatid=105470aid=1526585group_id=5470
___
Python-bugs-list mailing list 
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[ python-Bugs-1472251 ] pdb 'run' crashes when the it's first argument is non-string

2006-07-22 Thread SourceForge.net
Bugs item #1472251, was opened at 2006-04-18 05:16
Message generated for change (Comment added) made by isandler
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detailatid=105470aid=1472251group_id=5470

Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: Python Library
Group: Python 2.5
Status: Open
Resolution: None
Priority: 3
Submitted By: Kuba Kończyk (jakamkon)
Assigned to: Nobody/Anonymous (nobody)
Summary: pdb 'run' crashes when the it's first argument is non-string

Initial Comment:
Pdb 'run/runeval' commands fails to check the type of
given argument.When argument to 'run/runeval' is
non-string the functions crashes with further
impilications on (correctly)invoking this functions: 

Python 2.5a1 (trunk:45527, Apr 18 2006, 11:12:31)

 def x(): pass
 import pdb
 pdb.run(x())
Traceback (most recent call last):
  File stdin, line 1, in module
  File /home/jkk/python/python-svn/Lib/pdb.py, line
1113, in run
Pdb().run(statement, globals, locals)
  File /home/jkk/python/python-svn/Lib/bdb.py, line
363, in run
cmd = cmd+'\n'
TypeError: unsupported operand type(s) for +:
'NoneType' and 'str'
 pdb.run('x()')
 /home/jkk/python/python-svn/Lib/pdb.py(1113)run()
- Pdb().run(statement, globals, locals)
(Pdb)
# CTRL-D pressed
Traceback (most recent call last):
  File stdin, line 1, in module
  File /home/jkk/python/python-svn/Lib/pdb.py, line
1113, in run
Pdb().run(statement, globals, locals)
  File /home/jkk/python/python-svn/Lib/pdb.py, line
1113, in run
Pdb().run(statement, globals, locals)
  File /home/jkk/python/python-svn/Lib/bdb.py, line
48, in trace_dispatch
return self.dispatch_line(frame)
  File /home/jkk/python/python-svn/Lib/bdb.py, line
67, in dispatch_line
if self.quitting: raise BdbQuit
bdb.BdbQuit

The solution is to simply ensure that the first
argument passed to the 'run/runeval' functions is string.

--

Comment By: Ilya Sandler (isandler)
Date: 2006-07-22 10:46

Message:
Logged In: YES 
user_id=971153

 Is your comment directly related to this bug?

Yes, my suggestion was to call settrace() after 

  cmd = cmd+'\n'

which should solve the original (bdb leaving tracing on)
problem.. Your latest suggestion would do the same thing by
different means..

However, I think there an even better way: can we simply remove

-if not isinstance(cmd, types.CodeType):
-cmd = cmd+'\n'

from bdb.py???

This would both solve the original problem and make error
message more meaningful IMO..

  exec: arg 1 must be a string, file, or code object

Rather than:

 Unsupported operand type(s) for +: 'NoneType' and 'str'

This seems to work for me, would you be interested in
testing and submitting a patch for this?


A bit more information: it appears that older versions of
python in some cases required string passed to exec to end
with '\n', this was even mentioned in python FAQ.. E.g if I
feed  
  
 exec 'for i in range(4):\nx=i'

into python2.1, I get a Syntax error..

However, this does work in python2.3.3, 2.4,2.5...

So was this + '\n' indeed a workaround for a deficiency in exec?





apparently older versions of python required the string
passed to exec to end with '\n'. It was even mentioned in
older FAQs... However, latest versions of python seem to
accept strings without new line... Eg. even

--

Comment By: Kuba Kończyk (jakamkon)
Date: 2006-07-11 08:02

Message:
Logged In: YES 
user_id=1491175

Simple solution is to catch TypeError in bdb's run function:
 try:
if not isinstance(cmd, types.CodeType):
cmd = cmd+'\n'
 except TypeError:
pass

Now it seems that handling nonstring arguments is better:

 import pdb
 def x():pass
...
 pdb.run(x())
Traceback (most recent call last):
  File stdin, line 1, in module
  File /home/jkk/python-svn/Lib/pdb.py, line 1122, in run
Pdb().run(statement, globals, locals)
  File /home/jkk/python-svn/Lib/bdb.py, line 369, in run
exec cmd in globals, locals
TypeError: exec: arg 1 must be a string, file, or code object
 pdb.run('x()')
 string(1)module()
(Pdb) x
function x at 0x4024a9cc
(Pdb) pdb.run('x()')
(Pdb)




--

Comment By: Kuba Kończyk (jakamkon)
Date: 2006-07-11 07:02

Message:
Logged In: YES 
user_id=1491175

Is your comment directly related to this bug?
Maybe you should create separete bug tracker item to discuss
problem presented in your comment?

--

Comment By: Ilya Sandler (isandler)
Date: 2006-06-25 11:54

Message:
Logged In: YES 
user_id=971153

I have looked at what's happening in a bit more detail and
now I agree that the current behaviour 

[ python-Bugs-1517996 ] IDLE (macosx): Class and Path browsers show Tk menu

2006-07-22 Thread SourceForge.net
Bugs item #1517996, was opened at 2006-07-06 04:34
Message generated for change (Comment added) made by kbk
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detailatid=105470aid=1517996group_id=5470

Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: IDLE
Group: Python 2.5
Status: Open
Resolution: None
Priority: 5
Submitted By: Ronald Oussoren (ronaldoussoren)
Assigned to: Ronald Oussoren (ronaldoussoren)
Summary: IDLE (macosx): Class and Path browsers show Tk menu

Initial Comment:
I've done some work on fixing the menus for IDLE before 2.5b1, but 
recently found more toplevel windows that don't have their own menu.

Both the Path Browser and Class Browser don't have a menubar of their 
own. The Tk implementation on MacOSX won't accept an empty menubar, 
but will replace that by a generic Tk menubar.

--

Comment By: Kurt B. Kaiser (kbk)
Date: 2006-07-22 17:23

Message:
Logged In: YES 
user_id=149084

 Tk uses the per-window menu for the currently
 selected window

I assume you mean AquaTk uses the per-window...

Please put in a bug request on AquaTk to get it
to conform to how Tk handles this menu on Linux
and Windows.  Then downgrade the priority of this
bug or close it.

Does the debugger have the same problem?

--

Comment By: Ronald Oussoren (ronaldoussoren)
Date: 2006-07-18 08:20

Message:
Logged In: YES 
user_id=580910

These menu problems are at the very root caused by differences in the way 
menus work on OSX (one application wide menu at the top of the screen) and 
most other systems (optional menus for every window).  Applications on OSX 
must have some kind of menu (or be full-screen, but we don't want that for 
IDLE), Tk uses the per-window menu for the currently selected window for 
that. If a window doesn't have a menu it makes up one and I haven't found a 
way yet to override that menu (which would solve that problem once and for 
all).

I do believe that my other changes really are good, they make IDLE perform 
more like a true OSX application. This is important because IDLE is the default 
IDE, and hence probably the first thing naive OSX users will see of python.

BTW. AquaTk really sucks, which makes it annoyingly hard to create a really 
good OSX citizen of IDLE and I have given up on getting there. If I understand 
the lazyweb correctly you're supposed to port your appliations to some other 
GUI library (Tile?) to get a native LF for lots of widgets and standard 
dialogs.

--

Comment By: Kurt B. Kaiser (kbk)
Date: 2006-07-15 15:51

Message:
Logged In: YES 
user_id=149084

I suppose this is also true for the debugger?

I'd consider this a bug in OSX Tk, it should be
reported there.

Without a specific need for a menubar, all it does
is take up valuable vertical space.  And continuing
to add OSX special casing clutters up the IDLE code;
IMO it should be limited to situations where
functionality is compromised.

--

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detailatid=105470aid=1517996group_id=5470
___
Python-bugs-list mailing list 
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[ python-Bugs-768481 ] Column Number is not visible in MacOSX

2006-07-22 Thread SourceForge.net
Bugs item #768481, was opened at 2003-07-09 10:11
Message generated for change (Comment added) made by kbk
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detailatid=105470aid=768481group_id=5470

Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: IDLE
Group: Python 2.3
Status: Closed
Resolution: Fixed
Priority: 3
Submitted By: Tiago Castro Henriques (tiagoh)
Assigned to: Ronald Oussoren (ronaldoussoren)
Summary: Column Number is not visible in MacOSX

Initial Comment:
I'm running IDLE under MacOSX 10.2.6 using Python 2.3b2.

Using Apple's X11 beta 3 version, the column number,
which should appear in the lower right-hand corner, is
not visible. It is obscured by the Aqua resize widget
which is always anchored to the lower right-hand corner.

The column number becomes briefly visible when the IDLE
window is resized, only to be obscured again when the
final redraw is performed.

--

Comment By: Kurt B. Kaiser (kbk)
Date: 2006-07-22 17:50

Message:
Logged In: YES 
user_id=149084

Rev 46859, Ronald Oussoren

--

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detailatid=105470aid=768481group_id=5470
___
Python-bugs-list mailing list 
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[ python-Bugs-775535 ] Tooltip-window doesn't vanish if...

2006-07-22 Thread SourceForge.net
Bugs item #775535, was opened at 2003-07-22 05:14
Message generated for change (Comment added) made by kbk
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detailatid=105470aid=775535group_id=5470

Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: IDLE
Group: Python 2.4
Status: Closed
Resolution: Fixed
Priority: 5
Submitted By: Gregor Lingl (glingl)
Assigned to: Kurt B. Kaiser (kbk)
Summary: Tooltip-window doesn't vanish if...

Initial Comment:
When entering in the shell window of IDLE:

gt;gt;gt; len(

a tooltip-window appears with content
   
len(object) -gt; integer

Now, when deleting these four characters (or at least
the opening parentheses) the tooltip-window remains open.

I can enter other expressions, writing even behind this
tooltip-window and it vanishes only

- when clicking the shell-window with the mouse
- when minimizing and remaximizing the shell-window
- wehn using another function call and typing a new
opening parentheses.

It should vanish immediately, when the opening parentheses 
is deleted.

Regards, Gregor

--

Comment By: Kurt B. Kaiser (kbk)
Date: 2006-07-22 17:52

Message:
Logged In: YES 
user_id=149084

Fixed by 'syntax' patch, Rev 41480

--

Comment By: Kurt B. Kaiser (kbk)
Date: 2003-07-23 01:20

Message:
Logged In: YES 
user_id=149084

Related to IDLEfork Bug 683123: ESC doesn't
close the call tip.

--

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detailatid=105470aid=775535group_id=5470
___
Python-bugs-list mailing list 
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[ python-Bugs-791968 ] Arguments tooltip wrong if def contains tuple

2006-07-22 Thread SourceForge.net
Bugs item #791968, was opened at 2003-08-20 11:16
Message generated for change (Comment added) made by kbk
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detailatid=105470aid=791968group_id=5470

Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: IDLE
Group: Python 2.3
Status: Open
Resolution: None
Priority: 5
Submitted By: Christos Georgiou (tzot)
Assigned to: Kurt B. Kaiser (kbk)
Summary: Arguments tooltip wrong if def contains tuple

Initial Comment:
This happens in IDLE on Windows 2000, from 2.3 EXE 
installer.  Type the following:

gt;gt;gt; def f((a,b), c):
print a, b, c

gt;gt;gt; f(

The tooltip shows up containing the following exact 
string (but the triple quotes):
quot;quot;quot;(.0, c)quot;quot;quot;


--

Comment By: Kurt B. Kaiser (kbk)
Date: 2006-07-22 17:56

Message:
Logged In: YES 
user_id=149084

Problem still exists in 2.5 as of Rev 50739.

--

Comment By: Christos Georgiou (tzot)
Date: 2003-08-20 12:02

Message:
Logged In: YES 
user_id=539787

I tried this:

def f((a,b), c, (d,e)): pass

and f.func_code.co_varnames is

('.0', 'c', '.4', 'a', 'b', 'd', 'e')

That means .0 and .4 are dummy placeholders for the 
argument tuples.  I couldn't find a direct way to know the 
length of each tuple, though --unless one analyzes the first 
UNPACK_SEQUENCE bytecodes of fob.func_code.co_code, 
and then uses the tuple fob.func_code.co_varnames
[fob.func_code.co_argcount:] to recreate the tuples; should 
we get into this trouble, or just do a regular expression 
replace a la:

argText = quot;(%s)quot; % re.sub(quot;\.\d+quot;, 
quot;lt;tuplegt;quot;, argText)

at line 144?

--

Comment By: Christos Georgiou (tzot)
Date: 2003-08-20 11:44

Message:
Logged In: YES 
user_id=539787

Quite fast, Neal! :)
It seems it's not exactly an IDLE bug; check ToolTip.py, line 
134 (vanilla 2.3); it's the f.func_code.co_varnames that 
returns this tuple:
('.0', 'c', 'a', 'b')

--

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detailatid=105470aid=791968group_id=5470
___
Python-bugs-list mailing list 
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[ python-Bugs-1501330 ] failure of test_ossaudiodev; elapsed time .1 sec faster

2006-07-22 Thread SourceForge.net
Bugs item #1501330, was opened at 2006-06-05 20:23
Message generated for change (Comment added) made by gward
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detailatid=105470aid=1501330group_id=5470

Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: Python Library
Group: Python 2.5
Status: Closed
Resolution: Fixed
Priority: 5
Submitted By: Brett Cannon (bcannon)
Assigned to: Greg Ward (gward)
Summary: failure of test_ossaudiodev; elapsed time .1 sec faster

Initial Comment:
I am getting a consistent failure of test_ossaudiodev
on Ubuntu Hoary on an HP xw4300 Workstation.  The
failure is that the test is printing out elapsed time:
3.0 sec while the test expects 3.1 sec.

I don't know anything about sound recordings so I don't
know if there is any way to calculate the expected
length of the test sound file and thus know that this
is a true error or the test is just working faster than
normally expected.

--

Comment By: Greg Ward (gward)
Date: 2006-07-22 22:27

Message:
Logged In: YES 
user_id=14422

Fixed in r50775 using the patch I attached earlier.


--

Comment By: Brett Cannon (bcannon)
Date: 2006-06-12 14:09

Message:
Logged In: YES 
user_id=357491

Output with the patch:

playing test sound file (expected running time: 2.93 sec)
actual running time was 3.09 sec (5.5% difference)

--

Comment By: Greg Ward (gward)
Date: 2006-06-11 12:54

Message:
Logged In: YES 
user_id=14422

Brett -- I'm not sure why I put 3.1 sec in there.  It's
probably just what popped out the first time I ran this test
on my machine.  Anyways, simple math reveals that the
theoretical running time of the test file is ~2.93 sec:

  (23493 bytes) / (1 byte/sample) / (8000 samples/sec) =
2.93 sec

which of course ignores the overhead of the file header, but
that seems to pretty small.  sox agrees:

$ time /usr/bin/play Lib/test/audiotest.au

Input Filename : Lib/test/audiotest.au
Sample Size: 8-bits
Sample Encoding: u-law
Channels   : 1
Sample Rate: 8000

Time: 00:02.93 [00:00.00] of 00:02.93 ( 100.0%) Output
Buffer:  23.46K

Done.
/usr/bin/play Lib/test/audiotest.au  0.03s user 0.02s system
1% cpu 3.127 total

Can you try that on your machine and put the output here?

Anyways, the likely culprits are 1) faster hardware (less
overhead opening audio device, reading file, etc) and 2)
variations in sound chip frequency (8000 Hz is not always
exactly 8000 Hz).  I'll try to fix the test so it's a little
fuzzier.


--

Comment By: A.M. Kuchling (akuchling)
Date: 2006-06-07 09:04

Message:
Logged In: YES 
user_id=11375

Yes, the length is calculable -- you have N bytes in the
file, with so many bits per sample and so many samples per
second.  Perhaps the driver now buffers more and the write()
returns earlier?  Or you could try printing the exact
duration without rounding; maybe it's 3.099 or something
and the print is just truncating.


Assigning to Greg Ward, in case he gets around to looking at it.


--

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detailatid=105470aid=1501330group_id=5470
___
Python-bugs-list mailing list 
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[ python-Bugs-1027566 ] Argument missing from calltip for new-style class init

2006-07-22 Thread SourceForge.net
Bugs item #1027566, was opened at 2004-09-13 18:17
Message generated for change (Comment added) made by kbk
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detailatid=105470aid=1027566group_id=5470

Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: IDLE
Group: None
Status: Closed
Resolution: Accepted
Priority: 5
Submitted By: Loren Guthrie (lguthrie)
Assigned to: Kurt B. Kaiser (kbk)
Summary: Argument missing from calltip for new-style class init

Initial Comment:
The calltip for __init__ on new-style classes doesn't
show the arguments like it does for old-style classes.

 import idlelib.CallTips
 class OldClass:
... Old-style class
... def __init__(self, x):
... self.x = x
... 
 idlelib.CallTips.get_arg_text(OldClass)
'(x)\nOld-style class'
 class NewClass(object):
... New-style class
... def __init__(self, x):
... self.x = x
... 
 idlelib.CallTips.get_arg_text(NewClass)
'New-style class'

Changing CallTips.py line 134 (in get_arg_text) from
if type(ob)==types.ClassType:
to
if type(ob) in [types.ClassType, types.TypeType]:

SEEMS to fix the problem, but I have no idea what
side-effects this might have.

--

Comment By: Kurt B. Kaiser (kbk)
Date: 2006-07-23 00:20

Message:
Logged In: YES 
user_id=149084

Rev 50776.  Thanks for the patch!

--

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detailatid=105470aid=1027566group_id=5470
___
Python-bugs-list mailing list 
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[ python-Bugs-1482122 ] Shift+Backspace exhibits odd behavior

2006-07-22 Thread SourceForge.net
Bugs item #1482122, was opened at 2006-05-04 16:48
Message generated for change (Comment added) made by kbk
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detailatid=105470aid=1482122group_id=5470

Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: Tkinter
Group: None
Status: Open
Resolution: None
Priority: 5
Submitted By: NothingCanFulfill (ncf)
Assigned to: Nobody/Anonymous (nobody)
Summary: Shift+Backspace exhibits odd behavior

Initial Comment:
On Windows, pressing Shift+Backspace while in an editor
window will act just like a regular Backspace will,
however under Linux (Gentoo 2006.0 and
Slackware-current), instead of deleting the caracter
before the cursor, it inserts ^B.

Correct me if I'm wrong, but I don't think it'd be too
hard to fix this little annoyance.

(I would do it myself, but I'm not at all familiar with
IDLE's source layout)

--

Comment By: Kurt B. Kaiser (kbk)
Date: 2006-07-23 01:07

Message:
Logged In: YES 
user_id=149084

Can't fix in IDLE by binding Shift-Key-BackSpace.

Using Python interpreter:

 import Tkinter
 root = Tkinter.Tk()
 text = Tkinter.Text()
 text.pack()

and try typing some char followed by
backspace and shift-backspace.

In Tcl shift-backspace works correctly.

Not an IDLE issue, appparently a Tkinter issue.

--

Comment By: Neal Norwitz (nnorwitz)
Date: 2006-05-05 03:03

Message:
Logged In: YES 
user_id=33168

Right now there aren't a lot of IDLE developers.  It would
be great if you could work on a patch.

--

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detailatid=105470aid=1482122group_id=5470
___
Python-bugs-list mailing list 
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com