PyCon: last day for early bird registration

2006-01-15 Thread A.M. Kuchling
Sunday, January 15th, is the last day on which you can obtain the
lower early-bird registration price. The cost of registration will be
going up on Monday; I'm quite sure that the early bird period will
*not* be extended again.

Another reminder: if you're coming to PyCon and staying in the
conference hotel, you *must* reserve your hotel rooms before February
1st in order to get the lower conference rate; if you reserve after
the 1st, you'll be stuck paying the hotel's standard room rate.  Go to
http://us.pycon.org/Addison/Hotels for hotel information and a link to
the reservation page for PyCon.


A.M. Kuchling
[EMAIL PROTECTED]
Chair, PyCon 2006
http://us.pycon.org

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

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


Re: Is 'everything' a refrence or isn't it?

2006-01-15 Thread Mike Meyer
Steven D'Aprano [EMAIL PROTECTED] writes:
 On Sat, 14 Jan 2006 23:21:14 -0500, Mike Meyer wrote:
 So those properties of object() are all identical because they're
 really properties of object. If you define an object() by those
 properties, you have to conclude that object is itself an instance of
 object().
 In this specific case, object instances get their properties from the
 class, but your conclusion doesn't follow. The easiest way to tell this is
 to ask, can we distinguish the object class (type) from an object
 instance? The answer is, yes we can:
 object
 type 'object'
 object()
 object object at 0xf705d3b8

Yes, but you're not looking at properties of the object, but rather of
the type of the object.

And for what it's worth, object is an instance of object.

 isinstance(object, object)
True


mike

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


Re: Listing partitions (on win32)

2006-01-15 Thread Bengt Richter
On 14 Jan 2006 16:52:33 -0800, Claude Henchoz [EMAIL PROTECTED] wrote:

Hi

Is there any way of listing partitions on a (win32) computer without
using WMI?

Maybe this will work (I skipped A: and B:, but you can include them if
you want to catch floppy drives with something in them). The 'xxx' is just so as
not to get a full directory's worth of useless text. If xxx happens to be 
defined
it doesn't hurt anything. It's not going to be as fast as using one of the
win32 api packages to get at GetLogicalDriveStrings, but this works on my NT4:
(error messages apparently go to stderr, so stdout gets '' which makes the if 
fail)

  def fakeGetLogicalDriveStrings():
 ... return [c+':' for c in (chr(n) for n in xrange(ord('A'), ord('Z')+1))
 ...   if os.popen('dir %s:\\xxx'%c).read()]
 ...
  fakeGetLogicalDriveStrings()
 ['C:', 'D:', 'E:', 'V:', 'W:']

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


Re: Is 'everything' a refrence or isn't it?

2006-01-15 Thread Mike Meyer
Steven D'Aprano [EMAIL PROTECTED] writes:
 On Sat, 14 Jan 2006 23:26:40 -0500, Mike Meyer wrote:
 I have no problem with that. Some objects are mutable and can change
 their value
 If the object *is* the value, how can it change to be a different value
 without also changing to be a diffent object?
 Because that's what they do.
 Think of it this way: objects are the memory location, the value is the
 particular pattern of bits at that memory location. Just because you flip
 a couple of bits at location N, changing the value, the location doesn't
 change.

Ok. So when you say the object is the value, you're *really* saying
the memory location is the pattern of bits it holds. Except that a
memory location is an address, which is a pattern of bits.  In
general, this won't be the same pattern of bits as the memory location
holds. So you're actually claiming that an object is two different
patterns of bits at the same time.

 mike
-- 
Mike Meyer [EMAIL PROTECTED]  http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Is 'everything' a refrence or isn't it?

2006-01-15 Thread Bryan Olson
Mike Meyer wrote:
 Bryan Olson [EMAIL PROTECTED] writes:
 
Mike Meyer wrote:

Bryan Olson [EMAIL PROTECTED] writes:

Mike Meyer wrote:

Bryan Olson writes:
The Python manual's claim there is solidly grounded. The logic
of 'types' is reasonably well-defined in the discipline. Each
instance of a type takes exactly one element from the type's
set of values (at least at a particular time).

References?

Are not hard to find.
 
 Well, Google didn't turn anything up. On the other hand, object and
 value are pretty poor terms to google with. Maybe you can suggest
 better ones?

Didn't I?  Type, or data type or datatype, plus abstract
data[optional-space]type.


In Niklaus Wirth's /Algorithms + Data
Structures = Programs, the first section after introduction
The concept of data type.
 
 It's been a few decades since I read that, but I don't recall anything
 that prohibited a valueless instance.

The term data type implies instances have data; is it clear
enough that a datum is a value?

Wikipedia has reasonable articles on datatype and abstract
datatype. That an instance takes a value is too obvious to state,
but clearly implied by discussion of an object's value.
 
 I obviously disagree that it's too obvious to state. Just because most
 instances of objects have a value doesn't necessarily mean that every
 instance of an object has a value.

The fact that general principles and results depend on each
object having a value implies they must.

  The discussion on these wikipedia
 pages don't say anything that would imply that an object must have a
 value.
 
 
If you're familiar with other programming
languages, you can to those. There are no values of C's 'void'
type, and consequently there are never any objects of type void.
 
 But we're not talking about C, we're talking about Python.

You seemed to disagree when I said the logic of 'types'
is reasonably well-defined in the discipline. If you're
just talking about Python, then the Python Language
Reference is right simply by status.


[...]
 Ok, so the objects identity is not it's value.

Right.

 Otherwise, the claim
 the type object has only one value would be false.

I'm still not sure that there's only one value for
objects of type 'object'.

Maybe I was wrong, and the object's identity
is part of its abstract state.

Is abstract state always part of the value?

The abstract state, sometimes called the logical state, is
the value the object represents.
 
 So are you now claiming that all instances of object have different
 values, as they all have different identities?

No, I had said I was unsure whether objects of type 'object'
know their identities, as Python defines them. (I think they
do not.)


The concept of a valueless object is inconsistent with a great deal
material.
 
 Another completely unsupported pronouncement.   *What* material? Come
 on, give me *explicit* references.

My textbooks are in storage too, but you'll find plenty if
you look. Remember learning about call by value? Did they
have to deal with objects without a value to pass?

Discussion involving an object's value would have to be rewritten
to cover the case of objects that don't have one. Is a valueless
object mutable or immutable? Let's see; the Reference says:

 Objects whose value can change are said to be mutable;
 objects whose value is unchangeable once they are created
 are called immutable.

Your valueless objects break the definitions. The Ref says
An object's mutability is determined by its type so it
must have some mutability status to determine. Want to
re-work the literature to cover your special case?

Got any references yourself? Where's the literature on typed
objects that don't have values?

  At the very least, provide or point
 to a definition of type that makes it clear that a type for which you
 can have instances *has* to have values.

Did the references make clear to you that this usage of 'type'
means 'data type'?


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


Re: Dynamically changing button text in python

2006-01-15 Thread Paul Rubin
[EMAIL PROTECTED] writes:
 The problem is once i set the textvariable property of the button,i
 cannot change the text.For example,
 
 curButton = Button(root,text=Stop Server,textvariable=this)

1. I don't think you can use text and textvariable at the same time.
2. I don't think you're using textvariable the right way.

Try something like:

tv = StringVar()
curButton = Button(root, textvariable=tv)
curButton.bind(Button-1,self.StopServer)
def StopServer(self,event):
tv.set(Start Server)

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


Re: Listing partitions (on win32)

2006-01-15 Thread Tim Golden
Claude Henchoz wrote:

 Is there any way of listing partitions on a (win32) computer without
 using WMI?

Not that this answers your question, but why _don't_ you
want to use WMI?

TJG

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


Re: Listing partitions (on win32)

2006-01-15 Thread bonono

Tim Golden wrote:
 Claude Henchoz wrote:

  Is there any way of listing partitions on a (win32) computer without
  using WMI?

 Not that this answers your question, but why _don't_ you
 want to use WMI?

 TJG

 import wmi

Traceback (most recent call last):
  File pyshell#0, line 1, in -toplevel-
import wmi
ImportError: No module named wmi


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


Python cannot print - Re: Unicode style in win32/PythonWin

2006-01-15 Thread Robert
Neil Hodgson schrieb:
 Thomas Heller:

  Hm, I don't know.  I try to avoid converting questionable characters at
  all, if possible.  Then, it seems the error-mode doesn't seem to change
  anything with mbcs encoding.  WinXP, Python 2.4.2 on the console:
 
  uabc\u034adef.encode(mbcs, ignore)
  'abc?def'
  uabc\u034adef.encode(mbcs, strict)
  'abc?def'
  uabc\u034adef.encode(mbcs, error)
  'abc?def'

yes I know, thats why 'mbcs' can also be set in site(customize).py to
solve some of the problems discussed. (site.py mechanism doesn't allow
to set the mode as in ctypes

  With latin-1, it is different:

 Yes, there are no 'ignore' or 'strict' modes for mbcs. It is a
 simple call to WideCharToMultiByte with no options set. 'ignore' may
 need two calls with different values of the default character to allow
 identification and removal of default characters as any given default
 character may also appear naturally in the output. 'strict' and 'error'
 would be easier to implement by checking both the return status and
 lpUsedDefaultChar which is set when any default character insertion is done.

But as discussed, I would not recommend this as encouragement to dig
for a real 'strict' or 'ignore' for mbcs.
('replace' also creates no invalid chars. both 'ignore' and 'replace'
change the stream and equality cannot be preserved by principle.)
Its a political discussion if the default mode should go through, or be
picky. (detailed in
[EMAIL PROTECTED])

Better change consciously to ('mbcs','replace').

The default behaviour of Python is a horror for any new Programmer and
a reason to quickly go away to mature unicode platforms like Java. It
takes many many hours to find out how everything depends in Python and
how to make simple print actions not break the application (especially,
when PythonWin is involved). This creates a lot of anger for users and
programmers. When strict converstion is really required for some
technical strings (very rare),  programmers are naturally very aware.

Be a new programmer and try:

 print '\n'.join( glob.glob(u'test/*') )
Traceback (most recent call last):
  File stdin, line 1, in ?
  File C:\PYTHON24\lib\encodings\cp850.py, line 18, in encode
return codecs.charmap_encode(input,errors,encoding_map)
UnicodeEncodeError: 'charmap' codec can't encode characters in position
146-150:
 character maps to undefined


= What is this cp850.py and has to do with my (undefined?) files? A
very cice language, which cannot print by default... go to Java ...
Bye

My recommendation is to use 'backslashreplace as default mode. Nobody
is angry when alien chars are printed in this style.

Robert

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


Re: How to get Windows system information?

2006-01-15 Thread Tim Golden
[posting through Google; not sure how it will format]

re info on WMI website: please note that the examples I
give no the WMI pages are *nowhere near* exhausting
what WMI can do. They don't even scratch the surface.
And I all too rarely add to them.

If you look around the net, you'll find absolutely loads
of recipes for doing things with WMI. And it's usually
easy to translate them into Python. So, for example,
Googling for WMI CPU load takes you straight to
this page:

http://www.robvanderwoude.com/wshexamples_0o.html

which (after some fairly intrusive boilerplate stuff)
ends up selecting from Win32_Processor. So, in
Python:

code
import wmi
c = wmi.WMI ()
for i in c.Win32_Processor ():
  print i

# gives, among other things, a LoadPercentage
# field.
/code

Now, what the different fields mean sometimes requires
a bit more research. But the Microsoft WMI pages
sometimes hit the spot, and indeed, a search for
WMI LoadPercentage

brings up this page:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnwmi/html/mngwmi.asp

with a useful snippet on using WMI events to monitor
CPU Load.

And so on. By and large, whatever you can think of doing
with WMI, someone's done before. And if someone's done
it in VBS (or Perl, or whatever), we can do it in Python.

HTH
Tim

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


Re: Listing partitions (on win32)

2006-01-15 Thread Tim Golden
[EMAIL PROTECTED] wrote:
 Tim Golden wrote:
  Claude Henchoz wrote:
 
   Is there any way of listing partitions on a (win32) computer without
   using WMI?
 
  Not that this answers your question, but why _don't_ you
  want to use WMI?
 
  TJG

  import wmi

 Traceback (most recent call last):
   File pyshell#0, line 1, in -toplevel-
 import wmi
 ImportError: No module named wmi
 

It's quite possible to do WMI in Python without using
the wmi module -- all the module does is to hide some
slightly messy plumbing. But the OP doesn't suggest
that he's unwilling to install anything, merely to *use*
WMI. (Unless you _are_ the OP under a different alias).

Just to make it plain: it's no skin off my nose at all. I
don't get offended because someone doesn't want to
use WMI. I'm merely curious as to whether it was
because the wmi module was too hard, or whether
the machines were Win9x or NT, where you have to
go out of your way to install WMI, or whether there
was some other reason.

Tim

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


Re: Is 'everything' a refrence or isn't it?

2006-01-15 Thread Steven D'Aprano
On Sun, 15 Jan 2006 03:11:27 -0500, Mike Meyer wrote:

 Steven D'Aprano [EMAIL PROTECTED] writes:
 On Sat, 14 Jan 2006 23:26:40 -0500, Mike Meyer wrote:
 I have no problem with that. Some objects are mutable and can change
 their value
 If the object *is* the value, how can it change to be a different value
 without also changing to be a diffent object?
 Because that's what they do.
 Think of it this way: objects are the memory location, the value is the
 particular pattern of bits at that memory location. Just because you flip
 a couple of bits at location N, changing the value, the location doesn't
 change.
 
 Ok. So when you say the object is the value, you're *really* saying
 the memory location is the pattern of bits it holds.

No. You seem to have trouble with analogies. My apologies for not making
it clearer: I should have said, by analogy, the relationship between
mutable objects and their value is equivalent to the relationship between
a memory location and the bit pattern at that location.


 Except that a
 memory location is an address, which is a pattern of bits.  In general,
 this won't be the same pattern of bits as the memory location holds. So
 you're actually claiming that an object is two different patterns of
 bits at the same time.

I'm not claiming that at all, but I don't have any problem with the
concept of certain objects being two or more things simultaneously.
Prince Charles, for example, is simultaneously Queen Elizabeth's son,
Diana's widower, Harry and William's father, Camilla's husband, and many
more things besides. 

It isn't common for programming data to have multiple values
simultaneously, but it does happen: a certain value can be a pointer to a
memory location and an integer, or a numeric value and a character.



-- 
Steven.

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


[FIXED] Re: urllib2.urlopen Progress bar

2006-01-15 Thread Ritesh Raj Sarraf
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

Calling urllib2.urlopen the below mentioned way fixed my problem.

try:
os.chdir (sSourceDir)
block_size = 4096
i = 0
count = 0
temp = urllib2.urlopen(sUrl)
headers = temp.info()
size = int(headers['Content-Length'])
data = open (sFile, 'wb')
while i  size:
data.write (temp.read(block_size))
i += block_size
counter += 1
progressbar.myReportHook(counter, block_size, size)
print \n
data.close()
temp.close()


Thanks,
Ritesh

Ritesh Raj Sarraf on Sunday 15 Jan 2006 12:55 wrote:

 -BEGIN PGP SIGNED MESSAGE-
 Hash: SHA1
 
 Hi,
 
 In urllib.urlretrieve I can use reporthook to implement a progress bar.
 
 But in urllib2.urlopen I can't.
 I have to use urllib2.urlopen because it throws exceptions which are
 important to be handled where as urlretrieve is dumb.
 
 Is there a way to implement urllib2.urlopen to enable reporthook ?
 
 progress.py code:
 
 #!/usr/bin/env python
 
 import time, urllib2, urllib
 
 class progressBar:
 def __init__(self, minValue = 0, maxValue = 10, totalWidth=12):
 self.progBar = []   # This holds the progress bar string
 self.min = minValue
 self.max = maxValue
 self.span = maxValue - minValue
 self.width = totalWidth
 self.amount = 0   # When amount == max, we are 100% done
 self.updateAmount(0)  # Build progress bar string
 
 def updateAmount(self, newAmount = 0):
 if newAmount  self.min: newAmount = self.min
 if newAmount  self.max: newAmount = self.max
 self.amount = newAmount
 
 # Figure out the new percent done, round to an integer
 diffFromMin = float(self.amount - self.min)
 percentDone = (diffFromMin / float(self.span)) * 100.0
 percentDone = round(percentDone)
 percentDone = int(percentDone)
 
 # Figure out how many hash bars the percentage should be
 allFull = self.width - 2
 numHashes = (percentDone / 100.0) * allFull
 numHashes = int(round(numHashes))
 
 # build a progress bar with hashes and spaces
 self.progBar = [ + '#'*numHashes + ' '*(allFull-numHashes) + ]
 
 # figure out where to put the percentage, roughly centered
 percentPlace = (len(self.progBar) / 2) - len(str(percentDone))
 percentString = str(percentDone) + %
 
 # slice the percentage into the bar
 #self.progBar = self.progBar[0:percentPlace] + percentString +
 self.progBar[percentPlace+len(percentString):]
 self.progBar = self.progBar[0:percentPlace] +
 self.progBar[percentPlace+len(percentString):] + percentString
 
 def __str__(self):
 return str(self.progBar)
 
 def myReportHook(count, blockSize, totalSize):
 import sys
 global prog
 
 if prog == :
 prog = progressBar(0,totalSize,50)
 #print count, blockSize, totalSize
 #prog = progressBar(0, totalSize, 77)
 prog.updateAmount(count*blockSize)
 sys.stdout.write (str(prog))
 sys.stdout.write (\r)
 #print count * (blockSize/1024) , kb of  , (totalSize/1024) , kb
 downloaded.\n
 prog = 
 sFile = new.rpm
 sUrl=http://localhost/new.rpm;
 urllib.urlretrieve(sUrl, sFile, reporthook=myReportHook)
 print \n\n
 #temp = urllib2.urlopen(sUrl)
 #lastval = int(temp.headers['Content-Length'])
 #prog = progressBar(0, lastval, 77)
 #
 #for x in range(101):
 #prog.updateAmount(x)
 #print prog, \r, time.sleep(0.5)
 #
 #data = open(sFile,'wb')
 #data.write(temp.read())
 #data.close()
 #temp.close()
 
 
 Regards,
 Ritesh
 - --
 Ritesh Raj Sarraf
 RESEARCHUT -- http://www.researchut.com
 Gnupg Key ID: 04F130BC
 Stealing logic from one person is plagiarism, stealing from many is
 research.
 Necessity is the mother of invention.
 -BEGIN PGP SIGNATURE-
 Version: GnuPG v1.4.2 (GNU/Linux)
 
 iD8DBQFDyfkM4Rhi6gTxMLwRAlmMAJ9yePv6DvXCcnUb0DYhWSuIonciSACgrxDj
 aKSGkfg8I1T/q3r6zWLTXmw=
 =uomB
 -END PGP SIGNATURE-
 

- -- 
Ritesh Raj Sarraf
RESEARCHUT -- http://www.researchut.com
Stealing logic from one person is plagiarism, stealing from many is
research.
Necessity is the mother of invention.
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.2 (GNU/Linux)

iD8DBQFDyicF4Rhi6gTxMLwRAldhAJ9cdnma+FerMVxe/EAG+eokL1POdQCgr5A3
ZyMQFN96Yrkp5frgHPYUnfU=
=Y9wS
-END PGP SIGNATURE-

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


Re: Dynamically changing button text in python

2006-01-15 Thread Fredrik Lundh
[EMAIL PROTECTED] wrote:

 The problem is once i set the textvariable property of the button,i
 cannot change the text.For example,

 curButton = Button(root,text=Stop Server,textvariable=this)

what made you think that setting textvariable to this would be a good
idea?

the textvariable option is used to specify a Tkinter variable that's used
to control the button text; e.g.

curVar = Tkinter.StringVar()
curButton = Button(root, textvariable=curVar)

curVar.set(new text)

also see

http://effbot.org/tkinterbook/button.htm
http://effbot.org/tkinterbook/variable.htm

/F



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


Re: Listing partitions (on win32)

2006-01-15 Thread bonono

Tim Golden wrote:
 [EMAIL PROTECTED] wrote:
  Tim Golden wrote:
   Claude Henchoz wrote:
  
Is there any way of listing partitions on a (win32) computer without
using WMI?
  
   Not that this answers your question, but why _don't_ you
   want to use WMI?
  
   TJG
 
   import wmi
 
  Traceback (most recent call last):
File pyshell#0, line 1, in -toplevel-
  import wmi
  ImportError: No module named wmi
  

 It's quite possible to do WMI in Python without using
 the wmi module -- all the module does is to hide some
 slightly messy plumbing. But the OP doesn't suggest
 that he's unwilling to install anything, merely to *use*
 WMI. (Unless you _are_ the OP under a different alias).

 Just to make it plain: it's no skin off my nose at all. I
 don't get offended because someone doesn't want to
 use WMI. I'm merely curious as to whether it was
 because the wmi module was too hard, or whether
 the machines were Win9x or NT, where you have to
 go out of your way to install WMI, or whether there
 was some other reason.

I am not him, but just another data point(possibly reason) of why one
doesn't want to use it. It is not intended to be a post of wmi suck.
In fact, when I first saw the post about wmi module, I immediate tried
to query my XP using it but once I saw the above, I gave up.

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


Re: Is 'everything' a refrence or isn't it?

2006-01-15 Thread Steven D'Aprano
On Sun, 15 Jan 2006 10:48:22 +0100, Fredrik Lundh wrote:

 an object's identity, type, and value are three different
 and distinct things.  the identity and type are not part of the value.  the
 type controls *how* to access the value, and needs to be known *before*
 you can access the value.

(Not arguing, just trying to clarify your point.)

I'm sick of arguing about object, let's use a different example:

 id(None)
135289128
 type(None)
type 'NoneType'

What's the value of None? Would you say it has no value or it's value
is None or something else?

None is a singleton, so it is meaningless to ask about two instances of
NoneType. How about this?

 class Empty:
... pass
... 
 id(Empty())
-151107636
 type(Empty())
type 'instance' 

Do two instances of Empty have the same value, or is the question
meaningless?



-- 
Steven.

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


Why/Why not WMI [was: Listing partitions (on win32)]

2006-01-15 Thread Tim Golden
[EMAIL PROTECTED] wrote:
 Tim Golden wrote:
 [EMAIL PROTECTED] wrote:
 Tim Golden wrote:
 Claude Henchoz wrote:

 Is there any way of listing partitions on a (win32) computer without
 using WMI?
 Not that this answers your question, but why _don't_ you
 want to use WMI?

 TJG
 import wmi
 Traceback (most recent call last):
   File pyshell#0, line 1, in -toplevel-
 import wmi
 ImportError: No module named wmi
 It's quite possible to do WMI in Python without using
 the wmi module -- all the module does is to hide some
 slightly messy plumbing. But the OP doesn't suggest
 that he's unwilling to install anything, merely to *use*
 WMI. (Unless you _are_ the OP under a different alias).

 I am not him, but just another data point(possibly reason) of why one
 doesn't want to use it. It is not intended to be a post of wmi suck.
 In fact, when I first saw the post about wmi module, I immediate tried
 to query my XP using it but once I saw the above, I gave up.

Fair enough. You'd need to install the pywin32 extensions
and then the wmi module on top of that. But I suppose that
because I simply install pywin32 on any Windows box as soon
as I install Python, I assumed others did the same. Not
necessarily the case, obviously. Also, I'm obviously
guaranteed to have the wmi module available since I'm
its author, but again not everyone has.

Just in case you're interested in trying it out:
http://timgolden.me.uk/python/wmi.html

I think the thing with WMI -- the mechanism, not the module --
is that you can do lots of things easily, or at least
consistently, which are painful otherwise. Sometimes
people will ask, eg How do I copy a file with WMI?
and I'm inclined to say: unless you have some very
specific requirement, you probably don't want to use
WMI to do that. But for certain things, it's just so
easy -- and there are examples and recipes for it all
over the web -- that it just makes sense.

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


Re: Listing partitions (on win32)

2006-01-15 Thread Tim Golden
Claude Henchoz wrote:
 Hi
 
 Is there any way of listing partitions on a (win32) computer without
 using WMI?

It looks as though XP has a command-line utility
called diskpart.exe which should be able to do
this kind of thing. I've no experience with it
myself, but assuming that it outputs information
to screen, it should be easy to pull that back
into Python with os.popen or the subprocess module.

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


Re: Is 'everything' a refrence or isn't it?

2006-01-15 Thread Fredrik Lundh
Steven D'Aprano wrote:

 I'm sick of arguing about object, let's use a different example:

  id(None)
 135289128
  type(None)
 type 'NoneType'

 What's the value of None? Would you say it has no value or it's value
 is None or something else?

it has no value (or if you prefer, the set of values is empty).

(unless you're talking about None-the-not-quite-but-almost-keyword, which
always evaluates to the same None object, unless you hack the __builtin__
namespace).

the None object has an identity and a type.

 None is a singleton, so it is meaningless to ask about two instances of
 NoneType. How about this?

  class Empty:
 ... pass
 ...
  id(Empty())
 -151107636
  type(Empty())
 type 'instance'

 Do two instances of Empty have the same value, or is the question
 meaningless?

Things are a bit mixed up wrt. old-style classes (because they're implemented
in terms of true objects), but if you make that

 class Empty(object):
... __slots__ = []
...

it should be clear that instances of this class have no value (or if you prefer,
the set of values is empty for all instances), and cannot have one either.

all Empty objects have an identity and a type, though.

/F



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


Re: New Python.org website ?

2006-01-15 Thread Tim Parkin
Martin Maney wrote:

Nah, it's very simple, if you can let go of the wrong-headed notion
that the web is just like print media.  Of course that means you're
unlikely to win any design awards, or even get a lot of commecnts about
how spiffy your web site looks, because all the design geeks will judge
you by the inapproriate standards of print media.  You may, however,
get pats on the back from people who actually use the site, and
appreciate a readable, logical layout far more than design school gloss
(and fonts too small to be easily read by many; no, Aahz, IMO your
solution throws out far too much along with the bath water, though I
have to agree that the font size problem vanishes if one uses a
text-mode browser grin).
  

Fortunately, what you are asking for is to be provided just the plain
text information with sufficient semantic markup to indicate logical
groupings of text such as headers, lists, etc. You've got that with the
new website, just disable your styles sheet.

From a quick look, the beta appears to commit the same error as every
design (as opposed to usability) driven web site in the world: it makes
the running text smaller than the user's default.  It's as if they care
more about how it looks than whether I can read it (as far as I can
tell, that's exactly the case, though it may just be that few are
willing to admit that the designs that they've learned to make, and
that do work well in high-resolution print, just suck on the web where
a high resolution screen is coarser than a bad fax.  bad artists, the
lot of them, who persist in ignoring the characteristics of the medium
they're working in).
  

Absolute nonsense, would you prefer we take our cue from. Just for your
information, I've never worked in print design in my life. People tend
to have a 'preferred' font size for working in. This is normally smaller
than the standard font that is delivered on the standard system running
a standard browser. For this vast majority, it aids usability for them
to have a smaller than normal body font. Possibly in an ideal world, all
websites would not set a body copy font size and it would make sense for
each user to pick the one that most suited them. Unfortunatley, if we do
that, the majority of sites break so whatever we do is a *compromise*.
I'd like to live in  the world where we don't have to do this.

As a matter of interest are you a professional design, web architect,
empassioned ameuter web designer or just an observer making casual
comments? (it's just that if you're a professional or empassioned
amateur, I'd like to know how you managed to deal with the same balance
and which group of users you would choose to cater for more)

It's otherwise nice, and I didn't see any problems with overlapping
texts (in Firefox, etc.) at any halfway reasonable window size, but
perhaps that was corrected already.  The name of the city in Sweden is
mangled in every encoding I've tried - the headline is proper UTF-8,
but the mention in the paragraph is weird.

  

Yep.. it's just a double encoding problem.. the source was iso8859-1 and
it got reprocessed as utf8.

And thanks for the feedback.. it all gets listened to. (btw, we're also
adding supplementary style sheets for different purposes - one for a
larger text size for instance - a beta of the large text style on is
available on the beta site at the moment, it still needs a couple of
tweaks with the menu)


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


Re: More than you ever wanted to know about objects [was: Is everything a refrence or isn't it]

2006-01-15 Thread Xavier Morel
Alex Martelli wrote:
 Steve Holden [EMAIL PROTECTED] wrote:
...
 3. If two objects are equal with ==, does that
   mean their values are the same?
 Almost universally, yes, although if you know enough about how the 
 interpreter works under the hood you can define the response of 
 instances of your own classes to the == operator (by defining their
 __eq__ method), and even define a class whose instances aren't equal to
 anything, even to themselves!
 
 Hmmm... now this may be just be, but I'm quite vary of saying that,
 since 1 == 1.0 == 1.0+0j, those three objects's values are the same.
 
 Are equal, sure.  But I intuitively see being the same as a stronger
 condition than being equal.
 
One could check use Common Lisp's =, eq and eql operators (which 
respectively check for being equal as in having the same set of 
values, being very equal as in having the same set of values and the 
same type and being the same as in being exactly the same object e.g. 
identity equality)

 In mathematics, 1 is not the same as 1.0 -- there exists a natural
 morphism of integers into reals that _maps_ 1 to 1.0, but they're still
 NOT the same thing.  And similarly for the real-vs-complex case.
 
I disagree here, 1 and 1.0 are the same mathematical object e.g. 1 (and 
the same as 1+0i), the difference due to notation only makes sense in 
computer science where integers, real and complex ensembles are disjoin. 
In mathematics, Z is included in IR which is included in C (note: this 
is not mathspeak, but I have no idea how to say it in english), and this 
notation -- at best -- merely determines the ensemble you're currently 
considering.

There is no natural morphism of integers into reals because there is 
no mathematical difference between integers and reals, the real ensemble 
is merely a superset of the integers one.

Or so it was last time i got a math course.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: timeout a process

2006-01-15 Thread Tim Golden
iapain wrote:
 Hello,
 I am trying to build and infinite loop handler in python 2.4 on windows
 platform. The problem is that i want to create a process and forcely
 kill/timeout after 2 sec to handle infinite loop in a gcc complied exe
 on cygwin. something like below

 os.system(mycpp.exe) # this exe is compiled with g++ and having an
 infinite loop

 I wish to terminate this after 2 sec. I've tried Watchdog and deamon
 thread.. but nothing seem to work here.

I'm not 100% sure, but I think that the following approach will work:

Use the win32process and win32event modules from the pywin32
extensions.
Use CreateProcess to run your .exe
Use WaitForSingleObject with the process handle and a timeout
Use TerminateProcess to kill your exe

Something like this (tested only casually):

code
import win32process
import win32event

TIMEOUT_SECS = 2

#
# Do as little as possible to get a
# process up and running.
#
hProcess, hThread, pid, tid = \
  win32process.CreateProcess (
None,
c:/winnt/system32/notepad.exe,
None, None, 0, 0, None, None,
win32process.STARTUPINFO ()
)
#
# Wait for it to finish, but give up after n secs
#
result = win32event.WaitForSingleObject (
  hProcess,
  1000 * TIMEOUT_SECS
)
#
# If it's timed out, kill it
#
if result == win32event.WAIT_TIMEOUT:
  win32process.TerminateProcess (hProcess, -1)
  print Killed off
else:
  print Died naturally

/code

HTH
Tim

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


Re: Getting better traceback info on exec and execfile - introspection?

2006-01-15 Thread R. Bernstein
Fernando Perez [EMAIL PROTECTED] writes:
 R. Bernstein wrote:
...
  However the frame information for exec or execfile looks like this:
File string, line 1, in ?
 
 That comes from how the code object was compiled:
...
 So any regexp-matching based approach here is likely to be fairly brittle,
 unless you restrict your tool to the standard python interpreter, and you
 get some guarantee that it will always tag interactive code with
 'string'.

Thanks for the information! Alas, that's bad news. The question then
remains as to how to accurately determine if a frame is running an
exec operation and accurately get the string associated with the exec.

Given all the introspection about python's introspection, it should be
possible.

I also tried pydb.py using IPython 0.7.0 (using an automatically
updated Fedora Core 5 RPM) and although I was expecting pydb.py breakage
from what you report, I didn't find any difference.


% ipython
Python 2.4.2 (#1, Dec 17 2005, 13:02:22)
Type copyright, credits or license for more information.

IPython 0.7.0 -- An enhanced Interactive Python.
?   - Introduction to IPython's features.
%magic  - Information about IPython's 'magic' % functions.
help- Python's own help system.
object? - Details about 'object'. ?object also works, ?? prints more.

In [1]: %run /usr/lib/python2.4/site-packages/pydb.py test1.py
 /home/rocky/python/test1.py(2)?()
- import sys
(Pydb) where
- 0  in file '/home/rocky/python/test1.py' at line 2
## 1  in exec cmd in globals, locals at line 1
## 2  run() called from file '/usr/lib/python2.4/bdb.py' at line 366
(Pydb)

Note entry ##1 is *not*
  File string, line 1, in ?

So somehow I guess ipython is not intercepting or changing how compile
was run here.


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


Re: csv format to DBase III format

2006-01-15 Thread Thomas Ganss
Hi,

I need to transfer csv format file to DBase III format file.
How do i do it in Python language?

http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/362715

I create a dbf file, it can be opened by Excel but it cannot be opened
by Access. Where is the error in my script.
...
 I have no idea too. I use Foxpro to open the file, but it is failure.
 The warning message is as follows
 Either the table record count does not match the actual records in the
 table, or the file size on the disk does not match the expected file
 size from the table header.

The error message is quite clear -
in the .dbf format the record count is written to the file header.

The filesize should be record_count*recordsize + headersize.

There are some options to fix a dbf, even via foxpro.
Comparing file size / header info should point you to your error.

Such a task (if targeted to run on a win machine) is probably
better done in foxpro or another dbase clone / file handler:
would take probably less a handful of lines and be much safer.


my 0.02 EUR

thomas

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


Re: Is 'everything' a refrence or isn't it?

2006-01-15 Thread Mike Meyer
Steven D'Aprano [EMAIL PROTECTED] writes:
 On Sun, 15 Jan 2006 03:11:27 -0500, Mike Meyer wrote:
 Steven D'Aprano [EMAIL PROTECTED] writes:
 On Sat, 14 Jan 2006 23:26:40 -0500, Mike Meyer wrote:
 I have no problem with that. Some objects are mutable and can change
 their value
 If the object *is* the value, how can it change to be a different value
 without also changing to be a diffent object?
 Because that's what they do.
 Think of it this way: objects are the memory location, the value is the
 particular pattern of bits at that memory location. Just because you flip
 a couple of bits at location N, changing the value, the location doesn't
 change.
 Ok. So when you say the object is the value, you're *really* saying
 the memory location is the pattern of bits it holds.
 No. You seem to have trouble with analogies. My apologies for not making
 it clearer: I should have said, by analogy, the relationship between
 mutable objects and their value is equivalent to the relationship between
 a memory location and the bit pattern at that location.

No, I don't have any trouble with analogies. I'm just carrying it to
make the point that *I* want to make, rather than stopping at the
point that you want to make.

 It isn't common for programming data to have multiple values
 simultaneously, but it does happen: a certain value can be a pointer to a
 memory location and an integer, or a numeric value and a character.

Yup, and they're all represented by the same bit pattern. I've got no
problem with that.   It's perfectly correct to say that that bit
pattern *is* all those things. On the other hand, it's not correct so
say that the memory location - or the object - that those bit patterns
reside in *is* those those. It isn't - it just holds them.

   mike
-- 
Mike Meyer [EMAIL PROTECTED]  http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Listing partitions (on win32)

2006-01-15 Thread Roger Upole

Claude Henchoz [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED]
 Hi

 Is there any way of listing partitions on a (win32) computer without
 using WMI?

 Cheers, Claude


Using win32file.DeviceIOControl with IOCTL_DISK_GET_DRIVE_LAYOUT
as the control code should be able to retrieve the partitions
defined on a disk.
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/fileio/fs/ioctl_disk_get_drive_layout.asp
Unpacking the output buffer may get a little messy, though.

hth
 Roger 



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


Re: Listing partitions (on win32)

2006-01-15 Thread Roger Upole

Bengt Richter [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED]
 On 14 Jan 2006 16:52:33 -0800, Claude Henchoz [EMAIL PROTECTED] wrote:

Hi

Is there any way of listing partitions on a (win32) computer without
using WMI?

 Maybe this will work (I skipped A: and B:, but you can include them if
 you want to catch floppy drives with something in them). The 'xxx' is just so 
 as
 not to get a full directory's worth of useless text. If xxx happens to be 
 defined
 it doesn't hurt anything. It's not going to be as fast as using one of the
 win32 api packages to get at GetLogicalDriveStrings, but this works on my NT4:
 (error messages apparently go to stderr, so stdout gets '' which makes the if 
 fail)

  def fakeGetLogicalDriveStrings():
 ... return [c+':' for c in (chr(n) for n in xrange(ord('A'), ord('Z')+1))
 ...   if os.popen('dir %s:\\xxx'%c).read()]
 ...
  fakeGetLogicalDriveStrings()
 ['C:', 'D:', 'E:', 'V:', 'W:']

 Regards,
 Bengt Richter

This will miss any partitions that don't have a drive letter assigned.
It will also give duplicate results for any volumes that have more
than one drive letter.  And it will return an entry for CD or DVD
drives which aren't disk partitions.

Roger



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


Re: [help] how to generate a empty .MDB file using python

2006-01-15 Thread Roger Upole
Denton [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED]
 Hi all:
 I working in MS window environment. Now I want to use a python
 script to import some data from CSV file to MDB file.
 but I have some  problems about creating MDB file in DAO.

 I am using attached code , but the last line seems invalid.
 Does anyone could help me.  Thanks!

 import win32com.client
 eng=win32com.client.Dispatch(DAO.DBEngine.36)
 eng.CreateDatabase(d:\\temp.mdb)



 Regards
Denton

It's helpful if you post the traceback.  I get
com_error: (-2147352567, 'Exception occurred.', (0, 'DAO.DbEngine', 'Invalid 
argument.', 'jeterr40.chm', 5003001, -2146825287), 
None)

Apparently the Locale parameter is required.
eng=win32com.client.gencache.EnsureDispatch(DAO.DBEngine.36)
eng.CreateDatabase(d:\\temp.mdb, win32com.client.constants.dbLangGeneral)

hth
Roger



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


Re: Is 'everything' a refrence or isn't it?

2006-01-15 Thread Mike Meyer
Bryan Olson [EMAIL PROTECTED] writes:
 Mike Meyer wrote:
 Bryan Olson [EMAIL PROTECTED] writes:
Mike Meyer wrote:
Bryan Olson [EMAIL PROTECTED] writes:
Mike Meyer wrote:
Bryan Olson writes:
The Python manual's claim there is solidly grounded. The logic
of 'types' is reasonably well-defined in the discipline. Each
instance of a type takes exactly one element from the type's
set of values (at least at a particular time).
References?
Are not hard to find.
 Well, Google didn't turn anything up. On the other hand, object and
 value are pretty poor terms to google with. Maybe you can suggest
 better ones?
 Didn't I?  Type, or data type or datatype, plus abstract
 data[optional-space]type.

You mentioned those in close connection with Wickipedia, so I only
checked there. In retrospect, those probably don't work well, as we've
already established that datatypes don't necessarily have to have
values.

In Niklaus Wirth's /Algorithms + Data
Structures = Programs, the first section after introduction
The concept of data type.
 It's been a few decades since I read that, but I don't recall
 anything
 that prohibited a valueless instance.
 The term data type implies instances have data; is it clear
 enough that a datum is a value?

Actually, what data type implies to me is that data have a type. But
skip that for now - what's the data that goes along with an instance
of object?

Wikipedia has reasonable articles on datatype and abstract
datatype. That an instance takes a value is too obvious to state,
but clearly implied by discussion of an object's value.
 I obviously disagree that it's too obvious to state. Just because
 most
 instances of objects have a value doesn't necessarily mean that every
 instance of an object has a value.
 The fact that general principles and results depend on each
 object having a value implies they must.

*What* general principles? *What* results?

   The discussion on these wikipedia
 pages don't say anything that would imply that an object must have a
 value.
If you're familiar with other programming
languages, you can to those. There are no values of C's 'void'
type, and consequently there are never any objects of type void.
 But we're not talking about C, we're talking about Python.
 You seemed to disagree when I said the logic of 'types'
 is reasonably well-defined in the discipline. If you're
 just talking about Python, then the Python Language
 Reference is right simply by status.

That my repeated requests for a definition of type (or object) have
never been answered suggest very strongly to me that the logic of
types is not well-defined.

And I'm trying to find out if there is any justification for the
statement made in the Python Programing language. If there's some good
reason that valueless objects can't (or shouldn't) exist in general,
that will do. If there's some reason they can't (or shouldn't) exist
in Python, that will do - though I'm also interested in the general
question.

What I'm *not* interested in is examples from other programming
languages. That they fail to let you have objects without values no
more proves that objects can't have values than Python not letting you
take the address of a variable provesd that variables can't have
addresses.

 [...]
 Ok, so the objects identity is not it's value.
 Right.
 Otherwise, the claim
 the type object has only one value would be false.
 I'm still not sure that there's only one value for
 objects of type 'object'.

Well, if you can identify the set the values are drawn from, that
would go a long way towards settling that issue.

The concept of a valueless object is inconsistent with a great deal
material.
 Another completely unsupported pronouncement.   *What* material? Come
 on, give me *explicit* references.
 My textbooks are in storage too, but you'll find plenty if
 you look. Remember learning about call by value? Did they
 have to deal with objects without a value to pass?

No. But in Python, call by reference has to deal with objects
without a reference to pass. So what?

 Discussion involving an object's value would have to be rewritten
 to cover the case of objects that don't have one. Is a valueless
 object mutable or immutable? Let's see; the Reference says:

  Objects whose value can change are said to be mutable;
  objects whose value is unchangeable once they are created
  are called immutable.

 Your valueless objects break the definitions. The Ref says
 An object's mutability is determined by its type so it
 must have some mutability status to determine. Want to
 re-work the literature to cover your special case?

So you're claiming that all objects have values is a convenience,
like x raised to the power 0 is 1?

 Got any references yourself? Where's the literature on typed
 objects that don't have values?

Ain't got none. On the other hand, I'm not trying to prove that such
objects exist. I'm trying to find out if there's any justification for
claiming that they don't exist.

   At the very 

Re: SPE [was: Wingide is a beautiful application]

2006-01-15 Thread Sybren Stuvel
SPE - Stani's Python Editor enlightened us with:
 This is a misinterpretation, SPE failed because of something else.
 (As would have become clear if you would have run SPE in the
 debugging mode 'python SPE.py --debug'.)

IMO displayed messages should be clear without having to resort to a
debugging mode. Debugging mode should only be for removing bugs, not
for enlightenment of the user.

Anyway, apt-getting spe now... which doesn't work:

Unpacking python-wxversion (from .../python-wxversion_2.6.1.1.1ubuntu2_all.deb)
...
dpkg: error processing
/var/cache/apt/archives/python-wxversion_2.6.1.1.1ubuntu2 _all.deb
(--unpack):
 trying to overwrite `/usr/lib/python2.4/site-packages/wxversion.py',
 which is also in package wxpython2.5.3

If it's so hard to get the requirements installed, I'd rather stick to
Vim.

 I adapted SPE such that it can ran out of the box of an archive (zip
 or tar.gz). This has the advantage that Linux (but also Mac and
 Windows) don't have to install SPE anymore but can just run it out
 of a folder or USB stick, provided the right version of wxPython
 (2.6) is installed on the system as it is always the case with
 Ubuntu boxes.

Ehm... I think I've clearly shown that, at least as far as the Ubuntu
packages go, not all requirements are always there on an Ubuntu
system.

 If it doesn't work, let me know privately.

Why? What's wrong with this newsgroup?

Sybren
-- 
The problem with the world is stupidity. Not saying there should be a
capital punishment for stupidity, but why don't we just take the
safety labels off of everything and let the problem solve itself? 
 Frank Zappa
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Listing partitions (on win32)

2006-01-15 Thread Claude Henchoz
Why I don't want to rely on WMI:
I am wanting to use this under Windows PE, and although I can include
WMI, I just wanted to find out whether there is a way to not use it.

Another thing:
I really do want to also get the partitions that do _not_ have an
associated drive letter.

All in all:
I am probably going to have to write something with tempfile that uses
diskpart.exe to use this. Although this will get ugly, it seems to be
the best way (the best way without WMI, that is).

Thanks for the help guys!

Cheers, Claude

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


Re: Is 'everything' a refrence or isn't it?

2006-01-15 Thread Bryan Olson
Fredrik Lundh wrote:
 Bryan Olson wrote:
 
 
I think the following is correct: an object's identity is not part
of its value, while its type is.
 
 
 you're wrong.  an object's identity, type, and value are three different
 and distinct things.

If I do:

  mylist = [17, 24]

are mylist and 17 different and distinct things?

Suppose I define a member attribute/property called '_class_',
that will get the save value as '__class__'. Now is that type
part of the value of an object of my class?

[...]
Python queries objects for their types; it's now a user-visible feature:

  'hello'.__class__
 type 'str'
 
 
 To get an object's type, use type(x).  This has always been a user-
 visible feature (along with id(x)).

Commanding that I get it some other way isn't going to change
that that type is now user-accessible as an attribute of the
object. The new-style classes tutorial calls it a
Python-provided attribute.

http://www.cafepy.com/article/python_attributes_and_methods/python_attributes_and_methods.html

Maybe one could to describe a consistent semantics that
distinguishes Python-provided attributes as unlike other
attributes, in that we define them not to be part of the
object's value. I don't that that would be wise.

[...]
 Nobody's saying that the identity and the type is not a property of the
 object (for a suitable definition of property, that doesn't include Python
 properties).

Sure, and whether the Interpreter queries the object for the
type is an implementation detail, and maybe a point-of-view
issue. But now the type is available as a Python-provided
attribute.

   What the documentation and I are saying is that it's not a
 part of the object's *value*.

Where does the doc say that?

 An object's identity, type, and value are three different and distinct things
 (or properties, if you prefer).  End of story.

The story continued.


-- 
--Bryan

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


Re: two questions about thread

2006-01-15 Thread Kevin
The best way to do this is by using a flag or event that the child-threads
monitor each loop (or multiple times per loop if it's a long loop).  If the
flag is set, they exit themselves.

The parent thread only has to set the flag to cause the children to die.

Kevin.


Bryan Olson [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
 iclinux wrote:
  a.  how to exit the whole process in a thread?
  b. when thread doing a infinite loops, how to terminate the process?:

 As others noted, the threading module offers Thread.setDaemon.
 As the doc says: The entire Python program exits when no active
 non-daemon threads are left.

 Python starts your program with one (non-daemon) thread which
 is sometimes called the main thread. I suggest creating all
 other threads as daemons. The process will then exit when the
 main thread exits.

 If some other thread needs to end the process, it does so by
 telling the main thread to exit. For example, we might leave
 the main thread waiting at a lock (or semaphore), and exit if
 the lock is ever released.


   it seems that the follow doesn't work, in my Windows XP:
   thread.start()
   thread.join()

 Is that part of the questions above, or another issue?


 -- 
 --Bryan


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


Re: Is 'everything' a refrence or isn't it?

2006-01-15 Thread Steven D'Aprano
On Sun, 15 Jan 2006 12:14:16 +0100, Fredrik Lundh wrote:

 Do two instances of Empty have the same value, or is the question
 meaningless?
 
 Things are a bit mixed up wrt. old-style classes (because they're
 implemented in terms of true objects), but if you make that
 
  class Empty(object):
 ... __slots__ = []
 ...
 
 it should be clear that instances of this class have no value (or if you
 prefer, the set of values is empty for all instances), and cannot have
 one either.

But that's the thing, it isn't clear to me at all that they have no value.
Does the empty string have a value? I would say yes. How about {} and []?
Again, I would say yes. So why do None and Empty() have no value?

It took mathematicians centuries to stop arguing about whether 0 is a
number or not, and then they argued whether or not 1 is a number. And
then when they settled that both 0 and 1 are numbers, they argued
whether the empty set counted as a set or not. So I'm not surprised that
we don't see eye-to-eye here.

I think part of the reason is that you are thinking at one abstract level,
where objects have a type, an identity, and everything else, and you
DEFINE that everything else as value. By that definition, if there is
nothing else, then there is no value. I can understand that, but I also
think that there is a different sense of value for which it makes sense
to include type and/or identity as part of the value. The alternative, it
seems to me, is to conclude that empty strings, dicts, lists and tuples
all are equally valueless, and I don't think that is a good idea.

The downside of my definition of value is that it is fuzzy and depends
on context. Often we want to exclude type (so that 1 and 1.0 have the
same value), we almost always want to exclude identity (so that [1,2] and
[1]+[2] have the same value), but there are enough exceptions to make
things interesting.



-- 
Steven.

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


Re: Placing graphics text on printed page - jan06call.jpg (0/1)

2006-01-15 Thread Kevin
One option is to create your page as an image file using PIL (which can
handle your text and drawing requirements, as well as any
pictures/graphics), then print it to a windows printer using my
ImagePrintWin module.

ImagePrintWin can print to any normal windows printer, and includes an
optional GUI for doing a Printer Setup type dialog (including preview).
It can even handle ICC profiles for your printer if you want color accuracy.

You can download ImagePrintWin (GPL'd) from my site at:

http://www.cazabon.com/python/downloads/ImagePrintWin.py


The pyCMS module for doing ICC is available also on my site at:

http://www.cazabon.com/pyCMS/

Kevin Cazabon.

Michael Galvin [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
 I am trying to use Python to send to the printer a calender filled
 with a mix of text and simple graphics.  I want to draw on the printed
 page something like a table with 6 rows and 7 columns to represent a
 calendar.  I want to place text precisely within those boxes on the
 printed page. I am using Python 2.4 on Windows XP

 I was  in the past able to do this within Visual Basic using its
 printer object.  Visual Basic's printer object uses a coordinate
 system to allow you to draw lines and to place text on the printed
 page precisely. I have attached a file jan06call.jpg to this message
 to illustrate what I am trying to do.

 Does Python have a module which would help me do this?

 To put it another way, can Python control the placement of text and
 graphics precisely on the printed page?

 I have scoured my Python programming texts,  python.org, and this
 usenet group without success.  Mark Lutz's wonderful book Programming
 Python  has not one reference to the word printer in its index.
 Surely, I must be overlooking something or thinking about this wrong.

 Michael Galvin
 Muskegon, MI



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


Re: Is 'everything' a refrence or isn't it?

2006-01-15 Thread Fredrik Lundh
Bryan Olson wrote:

 Python queries objects for their types; it's now a user-visible feature:
 
   'hello'.__class__
  type 'str'
 
 
  To get an object's type, use type(x).  This has always been a user-
  visible feature (along with id(x)).

 Commanding that I get it some other way isn't going to change
 that that type is now user-accessible as an attribute of the
 object.

so the object in my example has the type oops ?

 The story continued.

what story?  looks like kookery to me.  I recommend moving this thread
to comp.lang.funny.snake.farm

/F



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


Re: Spanish Translation of any python Book?

2006-01-15 Thread jean-michel bain-cornu
Olaf El Blanco wrote:
 Maybe there is someone that speak spanish. I need the best spanish book for 
 learning python.
 
 Thanks!
 
 
 
Hola,
Conoces La lista de python en castellano [EMAIL PROTECTED] ?
Si intentas preguntar a ella, se podria que haya otras respuestas que aqui.
Un saludo,
jm
-- 
http://mail.python.org/mailman/listinfo/python-list


Replacing bidirectional unicode strings/regexps

2006-01-15 Thread Ernst Elzas
Hello,

I've tried to write a sed s/original/replacement/g  -like script, but
for dealing with situations where both original and replacement contain
a mixture of left to right and right to left text (for now, English and
Hebrew) Both the texts can span multiple lines, and the replacement has
to be in files of a specific type (html) in all subdirectories. I'll
probably need to create the script (or at least the text to be replaced
and it's replacement) in some editor, since commandlines don't seem to
like bidirectional texts that much. I figured this would be easy, but
have not managed to get something working, nor have I found examples to
use. I did find some Python scripts doing related things, but they went
wrong as soon as I tried to adapt them to bidirectional text, the Perl
sed-like script also looked promising, but I did not manage to get that
working either in this situation. Please note that I had no prior
experience with the use of either language, and might easily have
overlooked the simple solution.

Thanks for your help,

Ernst

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


socket.gethostbyaddr() question

2006-01-15 Thread Harlin Seritt
I have a list of IP addresses I am testing with socket.gethostbyaddr().
For the most part, I am able to get a hostname returned to me when I
run gethostbyaddr(). I am also hoping this will allow me to tell if a
computer is up or down. However, in my environment, I am finding that I
am able to get a hostname even though I am unable to actually ping that
server (when I ping a server i like this, I get 'request timed out'
messages telling me that the server is not up).

Other times, I am able to ping a server with success but the
gethostbyaddr() request will not be able to return a hostname for me
making me think that machine is truly down when I know it's not. Can
anyone give me any pointers as to why this happens? Is there anyway I
can do a reliable ping to another server with Python? I am not
interested in doing system calls with a system Ping client (I have to
ping way too many machines and this either takes too long or causes
severe memory leakage due to MS's horrible ping client). Also, I am
unable to use Jeremy Hylton's Python ping client because it does little
more than call gethostbyaddr(). Thanks for taking a look at this.

Harlin Seritt

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


Re: PEP 309 (Partial Function Application) Idea

2006-01-15 Thread Giovanni Bajo
Ronald Mai wrote:

 Here is a reference implementation:

 _ = lambda x: x.pop(0)

 def partial(func, *args, **keywords):
 def newfunc(*fargs, **fkeywords):
 newkeywords = keywords.copy()
 newkeywords.update(fkeywords)
 newargs = (lambda seq: tuple([(a == _ and a(seq)) or a for
 a in args] + seq))(list(fargs))
 return func(*newargs, **newkeywords)
 newfunc.func = func
 newfunc.args = args
 newfunc.keywords = keywords
 return newfunc

 Here is example of use:

 def capture(*args):
 return args

 partial(capture)()
 ()
 partial(capture, _)(1)
 (1,)
 partial(capture, _, 2)(1)
 (1, 2)
 partial(capture, 1)(2)
 (1, 2)
 partial(capture, 1, _)(2)
 (1, 2)
 partial(capture, 1, _)()
 IndexError: pop from empty list
 partial(capture, 1, _, _)(2, 3)
 (1, 2, 3)

Other implementations I have seen (boost::bind comes to mind) use ordered
placeholders such as _1, _2, _3, etc to provide more flexibility in adaptation:

 partial(capture, a, _1, _2)(b, c)
(a, b, c)
 partial(capture, a, _2, _1)(b, c)
(a, c, b)

I don't see mention of this in the PEP, but it's a nice feature to have IMO.
-- 
Giovanni Bajo


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


Re: Marshal Obj is String or Binary?

2006-01-15 Thread Mike
 Even faster would be to write your code in assembly, and dump that
 ridiculously bloated database and just write everything to raw bytes on
 an unformatted disk. Of course, it might take the programmer a thousand
 times longer to actually write the program, and there will probably be
 hundreds of bugs in it, but the important thing is that you'll save three
 or four milliseconds at runtime.

 Right?

Correct. I didn't quite see the issue as assembly vs. python, having
direct translation to programming hours. The structure in mind is meant
to act as a dictionary to extend my db with a few table fields that
could vary from one record to another and won't be queried for.
Considering everytime my record is loaded, it pickle or marshal data
has to be decoded, I figured the faster alternative should be better.
With the incompatibility issue, I figured the day I upgrade my python,
I would write a python script to upgrade the data. I take my word back.

 Your database either can handle binary data, or it can't.

It can. It's my web framework that doesn't.

 If it can, then just use pickle with a binary protocol and be done with it.

That I will do.

 Either way, you have to find a way to translate your Python data
 structures into something that you can feed to the database. Your database
 can't automatically suck data structures out of Python's working memory!
 So why re-invent the wheel? marshal is not recommended, but if you can
 live with the limitations of marshal then it might do the job. But trying
 to optimise code that hasn't even been written yet is a sure way to
 trouble. 

Thanks. Will do.

Regards,
Mike

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


Re: Marshal Obj is String or Binary?

2006-01-15 Thread Mike
 Even faster would be to write your code in assembly, and dump that
 ridiculously bloated database and just write everything to raw bytes on
 an unformatted disk. Of course, it might take the programmer a thousand
 times longer to actually write the program, and there will probably be
 hundreds of bugs in it, but the important thing is that you'll save three
 or four milliseconds at runtime.

 Right?

Correct. I didn't quite see the issue as assembly vs. python, having
direct translation to programming hours. The structure in mind is meant
to act as a dictionary to extend my db with a few table fields that
could vary from one record to another and won't be queried for.
Considering everytime my record is loaded, it pickle or marshal data
has to be decoded, I figured the faster alternative should be better.
With the incompatibility issue, I figured the day I upgrade my python,
I would write a python script to upgrade the data. I take my word back.

 Your database either can handle binary data, or it can't.

It can. It's my web framework that doesn't.

 If it can, then just use pickle with a binary protocol and be done with it.

That I will do.

 Either way, you have to find a way to translate your Python data
 structures into something that you can feed to the database. Your database
 can't automatically suck data structures out of Python's working memory!
 So why re-invent the wheel? marshal is not recommended, but if you can
 live with the limitations of marshal then it might do the job. But trying
 to optimise code that hasn't even been written yet is a sure way to
 trouble. 

Thanks. Will do.

Regards,
Mike

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


Re: socket.gethostbyaddr() question

2006-01-15 Thread Roy Smith
Harlin Seritt [EMAIL PROTECTED] wrote:
 I have a list of IP addresses I am testing with socket.gethostbyaddr().
 For the most part, I am able to get a hostname returned to me when I
 run gethostbyaddr(). I am also hoping this will allow me to tell if a
 computer is up or down.

Gethostbyaddr() simply does a lookup in some sort of name resolution 
database (typically DNS, but could be YP/NIS, hostfile, etc).  The ability 
to look a name up in the database has absolutely no correlation with 
whether that node is up, down, or unreachable.

To tell if a machine is up or down, you need to probe the machine directly.  
Typically, this is done by sending it an ICMP Echo Request (commonly known 
as ping), but that's not foolproof.  A machine could be up, but unreachable 
because of network or routing problems.  A machine could be intentionally 
not answering pings.  A firewall in the way could be filtering out ping 
packets.  Or, the Echo Request or Echo Reply could have simply gotten lost 
somewhere on the network.

What, exactly, are you trying to do?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Marshal Obj is String or Binary?

2006-01-15 Thread Mike
 Well, the Cookbook isn't an exhaustive list of everything you can do
 with Python, it's just a record of some of the things people *have* done.

Considering I am a newbie, it's a good start for me...

 I presume your database has no datatype that will store binary data of
 indeterminate length? Clearly that would be the most satisfactory solution.

PostgreSQL. I think the only two thing it doesn't do is wash my car and
code my software. Well, that's up until you use it in conjunction with
Django, then the only work left is to wash my car, which I can't care
less either. We'll wait for some rain :)

Mike

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


Tomcat authentication from python

2006-01-15 Thread Michael Oliver








I need to access tomcat applications from
python, some are Axis/SOAP web services, and some are file/WebDAV operations.



But so far I cannot get python to
authenticate and access http://localhost:8080/manager/html
much less to any of the other applications.



I have found examples for httplib with a
base64 Basic Authentication header, and a urllib2 Authentication Handler, but
neither one works.



I am not an experienced python developer,
but I am an experienced Java Developer. I am using PyDev plugin for Eclipse, I
am using Python24.



I can connect to tomcat without
authentication for those pages/uris that do not require authentication
on that tomcat server, so the problem is with the authentication mechanism in
python. Obviously I can connect to the entire site and all applications with a
browser and programmatically from Java.



Any help greatly appreciated.






 
  
  
   


 
  
  
   




Highly
Cohesive and Loosely Coupled

   
  
  
  
  
  
  
 
 
  
  
   

Mike Oliver
CTO 


Alarius Systems LLC
6800 E. Lake Mead Blvd
Apt 1096
Las Vegas, NV 89156 

   
   

[EMAIL PROTECTED]
http://www.alariussystems.com/




 
  
  tel: 
  fax: 
  mobile: 
  
  
  (702)953-8949 
  (702)974-0341
  (518)378-6154 
  
 



   
  
  
  
 






   
  
  
  
 
 
  
  
   

Add me to your address book...


Want a signature like
this?

   
  
  
  
 









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

Re: socket.gethostbyaddr() question

2006-01-15 Thread Steve Holden
Harlin Seritt wrote:
 I have a list of IP addresses I am testing with socket.gethostbyaddr().
 For the most part, I am able to get a hostname returned to me when I
 run gethostbyaddr(). I am also hoping this will allow me to tell if a
 computer is up or down. However, in my environment, I am finding that I
 am able to get a hostname even though I am unable to actually ping that
 server (when I ping a server i like this, I get 'request timed out'
 messages telling me that the server is not up).
 
 Other times, I am able to ping a server with success but the
 gethostbyaddr() request will not be able to return a hostname for me
 making me think that machine is truly down when I know it's not. Can
 anyone give me any pointers as to why this happens? Is there anyway I
 can do a reliable ping to another server with Python? I am not
 interested in doing system calls with a system Ping client (I have to
 ping way too many machines and this either takes too long or causes
 severe memory leakage due to MS's horrible ping client). Also, I am
 unable to use Jeremy Hylton's Python ping client because it does little
 more than call gethostbyaddr(). Thanks for taking a look at this.
 
If  you have the ability to run code on the machines you are interested 
in you might want to consider Nicola Larosa's heartbeat recipe:

   http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/52302

You may also find something useful in

   http://pynms.sourceforge.net/ping.html

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

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


Re: Marshal Obj is String or Binary?

2006-01-15 Thread Steve Holden
Mike wrote:
Well, the Cookbook isn't an exhaustive list of everything you can do
with Python, it's just a record of some of the things people *have* done.
 
 
 Considering I am a newbie, it's a good start for me...
 
 
I presume your database has no datatype that will store binary data of
indeterminate length? Clearly that would be the most satisfactory solution.
 
 
 PostgreSQL. I think the only two thing it doesn't do is wash my car and
 code my software. Well, that's up until you use it in conjunction with
 Django, then the only work left is to wash my car, which I can't care
 less either. We'll wait for some rain :)
 
So this question was primarily theoretical, right?

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

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


Re: PEP 309 (Partial Function Application) Idea

2006-01-15 Thread bonono

Giovanni Bajo wrote:
 Ronald Mai wrote:

  Here is a reference implementation:
 
  _ = lambda x: x.pop(0)
 
  def partial(func, *args, **keywords):
  def newfunc(*fargs, **fkeywords):
  newkeywords = keywords.copy()
  newkeywords.update(fkeywords)
  newargs = (lambda seq: tuple([(a == _ and a(seq)) or a for
  a in args] + seq))(list(fargs))
  return func(*newargs, **newkeywords)
  newfunc.func = func
  newfunc.args = args
  newfunc.keywords = keywords
  return newfunc
 
  Here is example of use:
 
  def capture(*args):
  return args
 
  partial(capture)()
  ()
  partial(capture, _)(1)
  (1,)
  partial(capture, _, 2)(1)
  (1, 2)
  partial(capture, 1)(2)
  (1, 2)
  partial(capture, 1, _)(2)
  (1, 2)
  partial(capture, 1, _)()
  IndexError: pop from empty list
  partial(capture, 1, _, _)(2, 3)
  (1, 2, 3)

 Other implementations I have seen (boost::bind comes to mind) use ordered
 placeholders such as _1, _2, _3, etc to provide more flexibility in 
 adaptation:

  partial(capture, a, _1, _2)(b, c)
 (a, b, c)
  partial(capture, a, _2, _1)(b, c)
 (a, c, b)

 I don't see mention of this in the PEP, but it's a nice feature to have IMO.
 --
 Giovanni Bajo
Since python has named parameter(and I assume this PEP would support it
as well), is it really that useful to have these place holder things  ?
As when the parameter list gets long, named param should be easier to
read.

The only case I find it useful is for binary ops where I would like to
either bind the left hand side or the right hand side but that can be
handled easily with a flip function as in haskell.

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


Re: Marshal Obj is String or Binary?

2006-01-15 Thread Mike
 So this question was primarily theoretical, right?

Theoretical? not really Steve. I wanted to use django's wonderful db
framework to save a structure into my postgresql. Except there is no
direct BLOB support for it yet. There, I was trying to explore my
options with saving this structure in clear text.

Thanks,
Mike

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


[ANN] pysqlite 2.1.0 released

2006-01-15 Thread Gerhard Häring
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

pysqlite 2.1.0 released
===

I'm pleased to announce the availability of pysqlite 2.1.0. This is a
major release with many new features and some internal changes. While
the code was tested by a few people who tracked Subversion, users are
still adviced to test their applications intensively with the new
release before upgrading them to pysqlite 2.1.0.

Go to http://pysqlite.org/ for downloads, online documentation and
reporting bugs.

What is pysqlite?

pysqlite is a DB-API 2.0-compliant database interface for SQLite.

SQLite is a relational database management system contained in a
relatively small C library. It is a public domain project created
by D. Richard Hipp.  Unlike the usual client-server paradigm, the
SQLite engine is not a standalone process with which the program
communicates, but is linked in and thus becomes an integral part
of the program. The library implements most of SQL-92 standard,
including transactions, triggers and most of complex queries.

pysqlite makes this powerful embedded SQL engine available to
Python programmers. It stays compatible with the Python database
API specification 2.0 as much as possible, but also exposes most
of SQLite's native API, so that it is for example possible to
create user-defined SQL functions and aggregates in Python.

If you need a relational database for your applications, or even
small tools or helper scripts, pysqlite is often a good fit. It's
easy to use, easy to deploy, and does not depend on any other
Python libraries or platform libraries, except SQLite. SQLite
itself is ported to most platforms you'd ever care about.

It's often a good alternative to MySQL, the Microsoft JET engine
or the MSDE, without having any of their license and deployment
issues.

===
CHANGES
===

Statement caching
=

Planned since the start of the pysqlite2 development, the most
difficult to implement feature has now been implemented: transparent
statement caching.

What is statement caching?

Every SQL engine has a COMPILE and EXECUTE phase. In older pysqlite
releases, every SQL statement (except for executemany) was always
COMPILED and EXECUTED.

With statement caching, pysqlite can transparently optimize away the
COMPILE step.

The statement cache is implemented using a LRU cache with a default
capacity of 100. The cache is per connection - it's capacity can be
set when opening a connection:

con = sqlite.connect(..., cached_statements=30)

In a nutshell, this means the 100 most used SQL statements in your
application will only have to be COMPILED once by the SQLite engine.

This will of course only work well if you use the parameter-form of
the execute() method, i. e. for:

cur.execute(insert into foo(bar) values (?), (xy,))
cur.execute(insert into foo(bar) values (?), (ab,))

the SQL statement insert into foo(bar) values (?) will then only be
compiled once.

Users have seen significant performance improvements with the
statement caching in pysqlite 2.1.0:

http://lists.initd.org/pipermail/pysqlite/2005-November/000234.html

More flexibility for TEXT data
==

Until now, pysqlite would always return Unicode strings for text data,
unless you did some crazy trickery.

If you prefer to retrieve text data as Python bytestrings or a
different type, you can now set a text_factory callable per
connection:

con.text_factory = str  # ... to always return bytestrings

An optimized shortcut has been enabled to retrieve Unicode strings for
non-ASCII data, but bytestrings for non-ASCII text:

con.text_factory = sqlite.OptimizedUnicode

or something custom:

con.text_factory = lambda x: unicode(x, utf-8, ignore)

Highly optimized row_factory for column access by name
==

A new function has been implemented that allows for case-insensitive
column access by name with minimal performance and memory impact,
unlike a dictionary or db_row-based approach.

To enable it, set the row_factory attribute of your connection to
sqlite.Row:

from pysqlite2 import dbapi2 as sqlite
con = sqlite.connect(...)
con.row_factory = sqlite.Row
cur = con.cursor()
cur.execute(select name_last, age from people)
for row in cur:
print row[Name_Last], row[1]

Convenience methods
===

The execute(), executemany() and executescript() methods are now also
available in the Connection class.

This allows you to write very concise code like this:

con = sqlite.connect(...)
con.execute(insert into foo(bar) values (5))
for row in con.execute(select bar from foo):
print row


API changes
===

The row_factory attribute has been moved from the Cursor class to the
Connection class. For backwards compatibility, using it on the Cursor
class still works.

Re: Dynamically changing button text in python

2006-01-15 Thread marijuanated
Thank you very much.I had actually misinterpreted the textvariable
property for some kind of storage for each Button. I am actually
developing an app where multiple buttons have a single event handler.So
i thought the textvariable property might be used to store some info
about each of the Button so that the handler can differentiate between
the callers by examining the property.Now i achieved similar
functionality with callbacks because button command handlers dont
receive any additional arguments.

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


Re: Is 'everything' a refrence or isn't it?

2006-01-15 Thread Bryan Olson
Mike Meyer wrote:
[...]
 Actually, what data type implies to me is that data have a type.  But
 skip that for now - what's the data that goes along with an instance
 of object?

Again, I'm not an expert on 'object'. When a type has
a single value instances can take, the value is simply
defined as the single instance of the type.


[...]
The fact that general principles and results depend on each
object having a value implies they must.
 
 *What* general principles? *What* results?

Those that refer to the value of an instance without
covering the special-case of valueless objects. You've
seen some, and could not cite anything that includes
the case of valueless instances.

Mathematical methods break. In reasoning about the
correctness of implementations, we define functions
(mathematically, not in code) that map representations
to the values they represent. To allow some instances
to be valueless, we'd then need mathematical variables
that range over non-values.


 That my repeated requests for a definition of type 
  (or object) have never been answered

See the first sentence of the Wikipedia article on data
type.


[...]
 So you're claiming that all objects have values is a convenience,
 like x raised to the power 0 is 1?

All definitions are a convenience. Not special-casing
addition to define 2+2 to be five is a convenience that
makes our results cleaner.


[...]
 Ain't got none. On the other hand, I'm not trying to prove that such
 objects exist. I'm trying to find out if there's any justification for
 claiming that they don't exist.

It's the reference, it gets to decide.


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


Re: how do real python programmers work?

2006-01-15 Thread fynali
Love it.

-- 
fynali

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


Re: Is 'everything' a refrence or isn't it?

2006-01-15 Thread Donn Cave
Quoth Fredrik Lundh [EMAIL PROTECTED]:
| Steven D'Aprano wrote:
|
|  I'm sick of arguing about object, let's use a different example:
| 
|   id(None)
|  135289128
|   type(None)
|  type 'NoneType'
| 
|  What's the value of None? Would you say it has no value or it's value
|  is None or something else?
|
| it has no value (or if you prefer, the set of values is empty).

Dang, I would have said it does have a value.  For one thing, in

 if a:
 print 'more or less True'
 else:
 print 'evidently not'

None doesn't follow the default, so it seems like if has discovered
some sort of value in there.

(But of course in any case, whether this is a value or not a value, the
value of the question is certainly in question.)

Donn Cave, [EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: SPE [was: Wingide is a beautiful application]

2006-01-15 Thread SPE - Stani's Python Editor
Sybren Stuvel wrote:
 IMO displayed messages should be clear without having to resort to a
 debugging mode.
I can agree on that.

 Debugging mode should only be for removing bugs, not
 for enlightenment of the user.
Unless he doesn't follow the installation instructions.

 Anyway, apt-getting spe now... which doesn't work:

 Unpacking python-wxversion (from 
 .../python-wxversion_2.6.1.1.1ubuntu2_all.deb)
 ...
 dpkg: error processing
 /var/cache/apt/archives/python-wxversion_2.6.1.1.1ubuntu2 _all.deb
 (--unpack):
  trying to overwrite `/usr/lib/python2.4/site-packages/wxversion.py',
  which is also in package wxpython2.5.3
 If it's so hard to get the requirements installed, I'd rather stick to
 Vim.
It is so hard to contact the person who packages SPE for Ubuntu. I
contacted him but I get no answer. I am new to Ubuntu (or Linux in
general), so I would not have a clue how that works (apart from time
needed for it).

If you would have read the blog (http://pythonide.stani.be/blog), you
could clearly read this:


SPE was for the first time tested on and improved for Ubuntu (and
hopefully so for Linux in general). I adapted SPE such that it can ran
out of the box of an archive (zip or tar.gz) (...) If you want to
install SPE in this way, use the -no_setup.zip distribution:

   1. uninstall previous version of SPE (VERY IMPORTANT, otherwise SPE
won't run)
   2. download and unpack the archive
SPE-0.8.1.d-wx2.6.1.0-no_setup.zip
   3. run SPE with 'python SPE.py'


If you follow these three steps nothing more, nothing less, you are up
and running with SPE in one minute. I don't know how can I make it more
easy. Luckily other Ubuntu users had no problems and are running the
latest SPE already on Ubuntu.

  I adapted SPE such that it can ran out of the box of an archive (zip
  or tar.gz). This has the advantage that Linux (but also Mac and
  Windows) don't have to install SPE anymore but can just run it out
  of a folder or USB stick, provided the right version of wxPython
  (2.6) is installed on the system as it is always the case with
  Ubuntu boxes.

 Ehm... I think I've clearly shown that, at least as far as the Ubuntu
 packages go, not all requirements are always there on an Ubuntu
 system.

Supposing you use Ubuntu 5.10 The Breezy Badger, all the requirements
are there: wxPython 2.6 That is all SPE needs. (If you still use Hoary,
read here http://wiki.wxpython.org/index.cgi/wxPython_20with_20Ubuntu)
So you have only clearly shown that you didn't read the instructions. I
wish SPE can be retrieved by apt-get but that's beyond my control.

  If it doesn't work, let me know privately.

 Why? What's wrong with this newsgroup?
Nothing, just thought it might be off topic, SPE has forums or
newsgroups for that.

So follow this recipee:

- apt-get wxPython 2.6 (in case you don't have)

- uninstall your previous SPE attempts (no '_spe' or 'sm' folder may be
present in site-packages)
- get
http://download.berlios.de/python/SPE-0.8.1.d-wx2.6.1.0-no_setup.zip
and unpack it
- run SPE (python SPE.py)

Still not working?

Stani
--
http://pythonide.stani.be
http://pythonide.stani.be/screenshots
http://pythonide.stani.be/manual/html/manual.html

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


Re: Marshal Obj is String or Binary?

2006-01-15 Thread Steve Holden
Mike wrote:
So this question was primarily theoretical, right?
 
 
 Theoretical? not really Steve. I wanted to use django's wonderful db
 framework to save a structure into my postgresql. Except there is no
 direct BLOB support for it yet. There, I was trying to explore my
 options with saving this structure in clear text.
 
Right, NOW I understand.

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

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


Re: Getting better traceback info on exec and execfile - introspection?

2006-01-15 Thread Fernando Perez
R. Bernstein wrote:

 Fernando Perez [EMAIL PROTECTED] writes:
 R. Bernstein wrote:
 ...
  However the frame information for exec or execfile looks like this:
File string, line 1, in ?
 
 That comes from how the code object was compiled:
 ...
 So any regexp-matching based approach here is likely to be fairly
 brittle, unless you restrict your tool to the standard python
 interpreter, and you get some guarantee that it will always tag
 interactive code with 'string'.
 
 Thanks for the information! Alas, that's bad news. The question then
 remains as to how to accurately determine if a frame is running an
 exec operation and accurately get the string associated with the exec.
 
 Given all the introspection about python's introspection, it should be
 possible.

I thought a little about this.  One possibility would be to check whether
the argument given in the string exists as a file; if not, assume it's a
string.  I can't think of another way, since the string given is completely
arbitrary.  But someone who knows more about the internal structure of code
objects may give you better tips.

 I also tried pydb.py using IPython 0.7.0 (using an automatically
 updated Fedora Core 5 RPM) and although I was expecting pydb.py breakage
 from what you report, I didn't find any difference.
 
 
 % ipython
 Python 2.4.2 (#1, Dec 17 2005, 13:02:22)
 Type copyright, credits or license for more information.
 
 IPython 0.7.0 -- An enhanced Interactive Python.
 ?   - Introduction to IPython's features.
 %magic  - Information about IPython's 'magic' % functions.
 help- Python's own help system.
 object? - Details about 'object'. ?object also works, ?? prints more.
 
 In [1]: %run /usr/lib/python2.4/site-packages/pydb.py test1.py
 /home/rocky/python/test1.py(2)?()
 - import sys
 (Pydb) where
 - 0  in file '/home/rocky/python/test1.py' at line 2
 ## 1  in exec cmd in globals, locals at line 1
 ## 2  run() called from file '/usr/lib/python2.4/bdb.py' at line 366
 (Pydb)
 
 Note entry ##1 is *not*
   File string, line 1, in ?
 
 So somehow I guess ipython is not intercepting or changing how compile
 was run here.

Oh, that's because you're using %run, so your code is in complete control. 
What I meant about a restriction was thiking about using your pydb as the
debugger called by ipython when exceptions occur.

Try

%pdb

and then %run any script with an error in it, to be dropped in post-mortem
mode inside the stack.  That uses an ipython-enhanced pdb, but not your
pydb.  As your code matures and improves, it would be nice to, for example,
make it possible to plug it into ipython as a 'better debugger'.  But
there, you'll see 'ipython console' as the filename markers.

Anyway, good luck with this.  If you are interested in ipython integration,
I suggest the ipython-dev list as a better place for discussion: I only
monitor c.l.py on occasion, so I may well miss things here.

Regards,

f

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


Clear Thinking Power for Comp Developers

2006-01-15 Thread PeaceFest 05 Campaign HQ
Aloha,

It's been 32 years that I've been blessed to be in this industry, and
as you all know, mental clarity is always a challenge, especially when
working on deadline or when the perfect code arrives(the zone). Well,
at 50, i'm finding out that sometimes the old noggin ain't firing on
all cylinders, and been searching for a mental edge. Found it. have a
looksie here and then make your own decisions.

http://health.groups.yahoo.com/group/healing4ourworld/files/Personal%20Profiles%20of%20Our%20Team/A%20Clear%20Thinker%20Gets%20Even%20More%20Clear/

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


Re: Is 'everything' a refrence or isn't it?

2006-01-15 Thread Fredrik Lundh
Donn Cave wrote:

 |  What's the value of None? Would you say it has no value or it's value
 |  is None or something else?
 |
 | it has no value (or if you prefer, the set of values is empty).

 Dang, I would have said it does have a value.

 For one thing, in

  if a:
  print 'more or less True'
  else:
  print 'evidently not'

 None doesn't follow the default, so it seems like if has discovered
 some sort of value in there.

the if statement happens to use object identity to determine truth values
for certain special objects, including None:

int
PyObject_IsTrue(PyObject *v)
{
int res;
if (v == Py_True)
return 1;
if (v == Py_False)
return 0;
if (v == Py_None)
return 0;
/... query object .../
}

in the more general case, it's up to the object's type implementation to deter-
mine its truth value, in response to a __nonzero__ or __len__ query.

maybe we need a new word for virtual values that are not really part of an
object's internal state ?

/F



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


Re: Is 'everything' a refrence or isn't it?

2006-01-15 Thread Paul Rubin
Mike Meyer [EMAIL PROTECTED] writes:
  I'd say a==b doesn't necessarily mean a and b have the same value.
 Care to say what it does mean (as opposed to what it doesn't mean), then?

a==b simply means that a.__eq__(b) returns True.  
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: On Numbers

2006-01-15 Thread Paul Rubin
Mike Meyer [EMAIL PROTECTED] writes:
 I'd like to work on that. The idea would be that all the numeric types
 are representations of reals with different properties that make them
 appropriate for different uses. 

2+3j?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Marshal Obj is String or Binary?

2006-01-15 Thread Paul Rubin
Mike [EMAIL PROTECTED] writes:
 Correct. I didn't quite see the issue as assembly vs. python, having
 direct translation to programming hours I figured the day I
 upgrade my python, I would write a python script to upgrade the
 data. I take my word back.

Writing that script sounds potentially capable of consuming some
programming hours.  If the marshal format changes, it might not be
easy to have the old and new marshal modules in the same Python
instance.  You might need two separate interpreters (old and new), to
demarshal your objects in the old interpreter and communicate them
somehow to the new interpreter (e.g. through pickle and sockets) for
re-marshalling.  Migrating a database is a big pain in the neck
already without such extra complication.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: New Python.org website ?

2006-01-15 Thread Tim Parkin
[EMAIL PROTECTED] wrote:
 JW wrote:
 
On Fri, 13 Jan 2006 11:00:05 -0600, Tim Chase wrote:


http://tim.thechases.com/pythonbeta/pythonbeta.html


Very strange.  With FF 1.0.7, I can just get the buttons to violate the
next column if I ViewPage StyleLarge Text, but I wouldn't have noticed
it unless Tim had pointed it out.  Tim's gifs are much worse than what
I see. WIth ViewPage StyleBasic Page Style, it looks really good.
 
 
 Mine looks like Tim's gifs, with Basic Page Style.
 

Hi,

I've got an old copy of the html and tried to fix the general problem.
It's currently on another website

http://pyyaml.org/downloads/masterhtml/

Feedback appreciated (it's just the left hand nav width I'm concerned
about, all the other html and some styles are probably old). I've tried
this with 'min font size' adjustments and it doesn't seem to break. If I
don't get any bad feedback I'll roll the changes out.

Many thanks

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


Re: Just want to walk a single directory

2006-01-15 Thread Tim Roberts
SB [EMAIL PROTECTED] wrote:

Hi,

I have a super-simple need to just walk the files in a single directory.

I thought this would do it, but permanentFilelist ends up containing 
all folders in all subdirectories.

Could someone spot the problem? I've scoured some threads using XNews reg 
expressions involving os.walk, but couldn't extrapolate the answer for my 
need.

===

thebasedir = E:\\temp

permanentFilelist= []

for thepath,thedirnames,thefilenames in os.walk(thebasedir):
   if thepath != thebasedir:
   thedirnames[:] = []
   for names in thefilenames:
   permanentFilelist.append(names)

Um, excuse me for butting in, but couldn't you accomplish the same thing
more simply by using os.listdir and os.path.isfile?  In my brain, os.walk
is the solution to RECURSIVE search needs.
-- 
- Tim Roberts, [EMAIL PROTECTED]
  Providenza  Boekelheide, Inc.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Getting better traceback info on exec and execfile - introspection?

2006-01-15 Thread Ziga Seilnacht
R. Bernstein wrote:
.
.
.
 which is perhaps is a little more honest since one is not really in a
 file called string. However the way the debugger gets this *is*
 still a little hoaky in that it looks for something in the frame's
 f_code.co_filename *called* string. And from that it *assumes* this
 is an exec, so it can't really tell the difference between an exec
 command an execfile command, or a file called string. But I suppose
 a little more hoakiness *could* be added to look at the outer frame
 and parse the source line for exec or execfile.

You should check the getFrameInfo function in zope.interface package:
http://svn.zope.org/Zope3/trunk/src/zope/interface/advice.py?rev=25177view=markup

 And suppose instead of 'string' I'd like to give the value or the
 leading prefix of the value instead of the unhelpful word 'string'?
 How would one do that? Again, one way is to go into the outer frame
 get the source line (if that exists), parse that and interpolate
 argument to exec(file). Is there are better way?

Py library (http://codespeak.net/py/current/doc/index.html) has some
similar functionality in the code subpackage.

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


Re: SPE [was: Wingide is a beautiful application]

2006-01-15 Thread Sybren Stuvel
SPE - Stani's Python Editor enlightened us with:
 If you would have read the blog (http://pythonide.stani.be/blog),
 you could clearly read this:

I haven't.

2. download and unpack the archive
SPE-0.8.1.d-wx2.6.1.0-no_setup.zip

 If you follow these three steps nothing more, nothing less, you are
 up and running with SPE in one minute. I don't know how can I make
 it more easy.

You could start by adding the zip file to the download page. Even the
blog entry you mention doesn't contain the URL to that file.

 Supposing you use Ubuntu 5.10 The Breezy Badger, all the
 requirements are there: wxPython 2.6 That is all SPE needs.

Well, in that case the SPE package that's contained in the Universe
respository is broken. Besides, it was wxPython 2.5.3 that was
insalled on my Breezy box, after I upgraded from Hoary, and not 2.6.

 So you have only clearly shown that you didn't read the
 instructions. I wish SPE can be retrieved by apt-get but that's
 beyond my control.

No it isn't. All you need to do is publish proper packages, and set up
a Debian repository. Then all people need is to add one line to their
sources.list, and they can use apt-get.

 - apt-get wxPython 2.6 (in case you don't have)

That would be apt-get install python-wxgtk2.6. wxpython2.6 is
mentioned, but python-wxgtk2.6 is actually installable. At least, it
would be if it didn't conflict with the version of wxPython I have
currently installed. I had to uninstall 2.5.3 first, because a simple
upgrade didn't work.

 - get
 http://download.berlios.de/python/SPE-0.8.1.d-wx2.6.1.0-no_setup.zip
 and unpack it

Finally, an URL.

 Still not working?

It runs now, but some things aren't working. When I open a file and
click on the browse tab, I see the current directory. If I then
double-click on a Python file, I'd expect SPE to open it, but nothing
happens. Hmmm... and now SPE has crashed. No errors on the terminal,
but the GUI simply doesn't repaint anymore.

Sorry mate, it looks like a promising project, but it just doesn't do
it for me. Way too much hassle for something that crashes on the first
try.

Sybren
-- 
The problem with the world is stupidity. Not saying there should be a
capital punishment for stupidity, but why don't we just take the
safety labels off of everything and let the problem solve itself? 
 Frank Zappa
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Pythonic wrappers for SQL?

2006-01-15 Thread BartlebyScrivener
Just to chime in with Steve Holden on taking the why-not-learn-SQL
route. Chris Fehily's new book, SQL, A Visual QuickStart Guide (2nd Ed)
is a masterpiece and goes well on the bookshelf with his equally lucid
Python QuickStart Guide.

Cheap, too, for what you get.

http://www.amazon.com/exec/obidos/asin/0321334175/richarddooling/

rpd

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


instance attributes not inherited?

2006-01-15 Thread John M. Gabriele
The following short program fails:


--- code 
#!/usr/bin/python

class Parent( object ):
 def __init__( self ):
 self.x = 9
 print Inside Parent.__init__()


class Child( Parent ):
 def __init__( self ):
 print Inside Child.__init__()


p1 = Parent()
p2 = Parent()
c1 = Child()
foo = [p1,p2,c1]

for i in foo:
 print x =, i.x
- /code --



yielding the following output:

 output --
Inside Parent.__init__()
Inside Parent.__init__()
Inside Child.__init__()
x = 9
x = 9
x =
Traceback (most recent call last):
   File ./foo.py, line 21, in ?
 print x =, i.x
AttributeError: 'Child' object has no attribute 'x'
 /output -


Why isn't the instance attribute x getting inherited?

My experience with OOP has been with C++ and (more
recently) Java. If I create an instance of a Child object,
I expect it to *be* a Parent object (just as, if I subclass
a Car class to create a VW class, I expect all VW's to *be*
Cars).

That is to say, if there's something a Parent can do, shouldn't
the Child be able to do it too? Consider a similar program:

--- code 
#!/usr/bin/python


class Parent( object ):
 def __init__( self ):
 self.x = 9
 print Inside Parent.__init__()

 def wash_dishes( self ):
 print Just washed, self.x, dishes.


class Child( Parent ):
 def __init__( self ):
 print Inside Child.__init__()


p1 = Parent()
p2 = Parent()
c1 = Child()
foo = [p1,p2,c1]

for i in foo:
 i.wash_dishes()
--- /code ---

But that fails with:

--- output --
Inside Parent.__init__()
Inside Parent.__init__()
Inside Child.__init__()
Just washed 9 dishes.
Just washed 9 dishes.
Just washed
Traceback (most recent call last):
   File ./foo.py, line 24, in ?
 i.wash_dishes()
   File ./foo.py, line 10, in wash_dishes
 print Just washed, self.x, dishes.
AttributeError: 'Child' object has no attribute 'x'
--- /output -

Why isn't this inherited method call working right?
Is this a problem with Python's notion of how OO works?

Thanks,
---J

-- 
(remove zeez if demunging email address)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: instance attributes not inherited?

2006-01-15 Thread David Hirschfield
Nothing's wrong with python's oop inheritance, you just need to know 
that the parent class' __init__ is not automatically called from a 
subclass' __init__. Just change your code to do that step, and you'll be 
fine:

class Parent( object ):
 def __init__( self ):
 self.x = 9


class Child( Parent ):
 def __init__( self ):
super(Child,self).__init__()
print Inside Child.__init__()

-David

John M. Gabriele wrote:

The following short program fails:


--- code 
#!/usr/bin/python

class Parent( object ):
 def __init__( self ):
 self.x = 9
 print Inside Parent.__init__()


class Child( Parent ):
 def __init__( self ):
 print Inside Child.__init__()


p1 = Parent()
p2 = Parent()
c1 = Child()
foo = [p1,p2,c1]

for i in foo:
 print x =, i.x
- /code --



yielding the following output:

 output --
Inside Parent.__init__()
Inside Parent.__init__()
Inside Child.__init__()
x = 9
x = 9
x =
Traceback (most recent call last):
   File ./foo.py, line 21, in ?
 print x =, i.x
AttributeError: 'Child' object has no attribute 'x'
 /output -


Why isn't the instance attribute x getting inherited?

My experience with OOP has been with C++ and (more
recently) Java. If I create an instance of a Child object,
I expect it to *be* a Parent object (just as, if I subclass
a Car class to create a VW class, I expect all VW's to *be*
Cars).

That is to say, if there's something a Parent can do, shouldn't
the Child be able to do it too? Consider a similar program:

--- code 
#!/usr/bin/python


class Parent( object ):
 def __init__( self ):
 self.x = 9
 print Inside Parent.__init__()

 def wash_dishes( self ):
 print Just washed, self.x, dishes.


class Child( Parent ):
 def __init__( self ):
 print Inside Child.__init__()


p1 = Parent()
p2 = Parent()
c1 = Child()
foo = [p1,p2,c1]

for i in foo:
 i.wash_dishes()
--- /code ---

But that fails with:

--- output --
Inside Parent.__init__()
Inside Parent.__init__()
Inside Child.__init__()
Just washed 9 dishes.
Just washed 9 dishes.
Just washed
Traceback (most recent call last):
   File ./foo.py, line 24, in ?
 i.wash_dishes()
   File ./foo.py, line 10, in wash_dishes
 print Just washed, self.x, dishes.
AttributeError: 'Child' object has no attribute 'x'
--- /output -

Why isn't this inherited method call working right?
Is this a problem with Python's notion of how OO works?

Thanks,
---J

  


-- 
Presenting:
mediocre nebula.

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


Re: Listing partitions (on win32)

2006-01-15 Thread Bengt Richter
On Sun, 15 Jan 2006 08:08:16 -0500, Roger Upole [EMAIL PROTECTED] wrote:


Bengt Richter [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED]
 On 14 Jan 2006 16:52:33 -0800, Claude Henchoz [EMAIL PROTECTED] wrote:

Hi

Is there any way of listing partitions on a (win32) computer without
using WMI?

 Maybe this will work (I skipped A: and B:, but you can include them if
 you want to catch floppy drives with something in them). The 'xxx' is just 
 so as
 not to get a full directory's worth of useless text. If xxx happens to be 
 defined
 it doesn't hurt anything. It's not going to be as fast as using one of the
 win32 api packages to get at GetLogicalDriveStrings, but this works on my 
 NT4:
 (error messages apparently go to stderr, so stdout gets '' which makes the 
 if fail)

  def fakeGetLogicalDriveStrings():
 ... return [c+':' for c in (chr(n) for n in xrange(ord('A'), ord('Z')+1))
 ...   if os.popen('dir %s:\\xxx'%c).read()]
 ...
  fakeGetLogicalDriveStrings()
 ['C:', 'D:', 'E:', 'V:', 'W:']

 Regards,
 Bengt Richter

This will miss any partitions that don't have a drive letter assigned.
It will also give duplicate results for any volumes that have more
than one drive letter.  And it will return an entry for CD or DVD
drives which aren't disk partitions.

Yes, I guess I wasn't paying attention to the focus on partitions.
I wonder if you could try opening the physical disks (there is a weird
path prefix syntax IIRC) and read and interpret MBRs etc. for yourself.
Of course, you would need privilege to open raw disk reading, and you
definitely wouldn't want to make a mistake about read vs write ;-)

If ctypes becomes standard amongst the batteries included, this kind of
stuff should get easier, since I suppose you could use it to get to the
APIs you suggest (DeviceIoControl with IOCTL_DISK_GET_DRIVE_LAYOUT).

Kind of scary the damage you could do as administrator though, given that
on windows people tend to wind up running as administrator by default if they 
own
the machine ;-/

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


Re: pdb.py - why is this debugger different from all other debuggers?

2006-01-15 Thread Andreas Kostyrka
Am Donnerstag, den 05.01.2006, 15:03 -0800 schrieb [EMAIL PROTECTED]:

I know this sounds like brutal, but I've been developing Python code for
a decade now, and I've almost never used pdb.py. OTOH I also use gdb
only for bt from a core file.

Sorry to sound harsh, I do not consider manually stepping through a
program a costeffective way of debugging. Writting asserts,
instrumentisation, automatic debuggers and tracers are usually much
better spent money.

Consider how complicated it is to apply gdb or pdb say to a CGI program,
running in an embedded chroot environment?

Actually, for many things, python -i is more then enough to test and
debug code interactivly. Consider writing a settrace function, that
catches any data and control flow you might be interested.

Andreas
 
 I was disappointed not to see any replies to this.
 I use pdb a lot because most of my debugging needs
 are simple, and I don't need/want the overhead or
 complications of a heavy duty gui debugger.
 
 I used ddd only little many many years ago, but
 compatibility with existing tools I think is a big plus.
 I would certainly consider using such a combination,
 and even without ddd I think being behaving similarly
 to existing tools is a good thing.
 
 I hope some of the other problems with it get
 addressed some day:
 - There is no way (I know of) to start a python script
   from the command line with the debugger active;
   I always have to modify the source to insert a
   pdb.set_trace().  I would like something like Perl's
   -d option.
 - Exceptions often don't stop debugger in routine
   where they occurred; instead you are dumped
   into a higher (lower?) stack frame and have to
   navigate back to the frame the exception
   occurred in.
 - It needs something like the Perl debugger's
   X command to display full information about
   an object (value and attributes).
 - The help command is lame giving just a list
   of commands (which are often a single character)
   with no hint of what they do.
 


signature.asc
Description: Dies ist ein digital signierter Nachrichtenteil
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: PEP 309 (Partial Function Application) Idea

2006-01-15 Thread Giovanni Bajo
[EMAIL PROTECTED] wrote:

 Since python has named parameter(and I assume this PEP would support
 it as well), is it really that useful to have these place holder things
 ?

Probably not so much, you're right.

 As when the parameter list gets long, named param should be easier to
 read.

 The only case I find it useful is for binary ops where I would like to
 either bind the left hand side or the right hand side but that can be
 handled easily with a flip function as in haskell.

I'm not sure I'd like a specialized flip function, compared to the numbered
placeholders solution.
-- 
Giovanni Bajo


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


Re: pdb.py - why is this debugger different from all other debuggers?

2006-01-15 Thread Andreas Kostyrka
Am Donnerstag, den 05.01.2006, 21:34 -0800 schrieb [EMAIL PROTECTED]:
 [EMAIL PROTECTED] wrote:
  Mike I don't use pdb a lot either - and I write a *lot* of Python.
 
  Ditto.  I frequently just insert prints or enable cgitb.  Sometimes I enable
  line tracing for a specific function and the functions it calls using a
  tracing decorator.  There are lots of things that are easier than breaking
  down and learning how to use pdb. ;-)
 
 I think the degree of familiarity you and Mike have with
 Python makes using the intrinsic (for lack of a better
 word) tools easier.  For me, having a tool like pdb is a
 big help because I am not yet familiar with the all other
 options.  (For example, I never heard of cgitb until just
 now.)  I am also pretty sure both of you can draw more
 conclusions, more reliably, and from less data, then me
 so one or two added print statement for you would for
 me be 10 or 20.
 
 pdb is light-weight enough that (I hope) it does not
Well, actually it uses the internal tracing mechanism of Python to do
the debugging so to say. As such it is nowhere even near the term
light-weight. Actually, when it comes to execution time it's quite
heavy-weight so to say.

 obscure, or change what Python is doing -- something
 I worry about with heavier-duty debuggers.  It also
 comes with Python which gives it some kind of credibilty
 in my mind.

 For me, it is mostly useful for understanding flow of
 control and how objects change as that happens.  I
 find it easier than constantly modifying the source code.

One question that is often needed is How did we get to this place?.
The easiest solution is, putting this code in the place you are curious
about:

import traceback ; traceback.print_stack()

Andreas


 


signature.asc
Description: Dies ist ein digital signierter Nachrichtenteil
-- 
http://mail.python.org/mailman/listinfo/python-list

proposal: another file iterator

2006-01-15 Thread Paul Rubin
I find pretty often that I want to loop through characters in a file:

  while True:
 c = f.read(1)
 if not c: break
 ... 

or sometimes of some other blocksize instead of 1.  It would sure
be easier to say something like:

   for c in f.iterbytes(): ...

or 

   for c in f.iterbytes(blocksize): ...

this isn't anything terribly advanced but just seems like a matter of
having the built-in types keep up with language features.  The current
built-in iterator (for line in file: ...) is useful for text files but
can potentially read strings of unbounded size, so it's inadvisable for
arbitrary files.

Does anyone else like this idea?  
-- 
http://mail.python.org/mailman/listinfo/python-list


oss mixer usage

2006-01-15 Thread klappnase
Hi,

I am trying to write a mixer program using the ossaudiodev module.
I could hardly find any documentation or example code, so I try and ask
here.
There are two things that seem to work already, however I am not sure
if the solutions I found are the way it is supposed to be.

First, when on initialization of my MixerController class I query the
properties of the mixer device in use, I tried the following:

self._mixer = ossaudiodev.openmixer()
self.names, self.controls, self.stereocontrols,
self.reccontrols = [], [], [], []
clabels = ossaudiodev.control_labels
for label in clabels:
control = clabels.index(label)
if self._mixer.controls()  (1  control):
# channel is available
self.names.append(label.strip())
self.controls.append(control)
# now see if it's a stereo channel
if self._mixer.stereocontrols()  (1  control):
self.stereocontrols.append(control)
# finally see if it is an input device
if self._mixer.reccontrols()   (1  control):
self.reccontrols.append(control)

This works, at least on my box, however the ossaudiodev.control_label
attribute is not mentioned in the library reference, so I am  not sure
if this is the canonical way  that will always work.

Second, when I want to change the currently used recording source, I am
not sure if I have to  provide different code for sound cards that
support multiple active recording source channels and sound cards that
support only one active recording source channel; the code I wrote
works with my card (which allows multiple channels being active), but I
don't have a card that supports only one active recording channel at
hand so I cannot test if the same code will work.
Finally, if it *is* neccessary to provide different code, how can I
find out which type of card is currently in use?

Any pointers are much appreciated.

Thanks in advance

Michael

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


Re: How to get Windows system information?

2006-01-15 Thread dpickles
Thank you all! These tips answer my question. I am glad I discovered
this group.

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


Re: More than you ever wanted to know about objects [was: Is everything a refrence or isn't it]

2006-01-15 Thread Tim Peters
[Alex Martelli]
...
 In mathematics, 1 is not the same as 1.0 -- there exists a natural
 morphism of integers into reals that _maps_ 1 to 1.0, but they're still
 NOT the same thing.  And similarly for the real-vs-complex case.

[Xavier Morel]
 I disagree here, 1 and 1.0 are the same mathematical object e.g. 1 (and
 the same as 1+0i), the difference due to notation only makes sense in
 computer science where integers, real and complex ensembles are disjoin.
 In mathematics, Z is included in IR which is included in C (note: this
 is not mathspeak, but I have no idea how to say it in english), and this
 notation -- at best -- merely determines the ensemble you're currently
 considering.

 There is no natural morphism of integers into reals because there is
 no mathematical difference between integers and reals, the real ensemble
 is merely a superset of the integers one.

 Or so it was last time i got a math course.

This all depends on which math course you last took ;-)  You have more
a physicist's view here.  The simplest case is real versus complex,
where even a physicist wink can accept that a complex number,
formally, is an ordered pair of real numbers.  From that view, it's
almost obviously not possible that a complex number could be the same
object as a real number.  For example, 1+0i is formally the ordered
pair 1.0, 0.0, but the real 1.0 is just the real 1.0.  If you'll
grant that a real number is never itself an ordered pair of real
numbers, then the intersection between the complex and real numbers is
necessarily empty.

At lower levels of the numeric tower you have in mind, the formal
difference is more extreme, not less.  The natural numbers
(non-negative integers) are often defined in terms of von Neumann
ordinals, so that natural number N is the set of all natural numbers
less than N (0 is the empty set, 1 is the set containing the empty
set, 2 is the set containing the empty set and the set containing
the empty set, ...), while defining reals as either Dedekind cuts or
Cauchy sequences requires elaborate formal machinery.

Does it matter?  To foundational mathematicians, certainly.  Luckily,
in a computer all numerics suck, so who cares ;-).
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: instance attributes not inherited?

2006-01-15 Thread John M. Gabriele
David Hirschfield wrote:
 Nothing's wrong with python's oop inheritance, you just need to know 
 that the parent class' __init__ is not automatically called from a 
 subclass' __init__. Just change your code to do that step, and you'll be 
 fine:
 
 class Parent( object ):
 def __init__( self ):
 self.x = 9
 
 
 class Child( Parent ):
 def __init__( self ):
 super(Child,self).__init__()
print Inside Child.__init__()
 
 -David
 

How does it help that Parent.__init__ gets called? That call simply
would create a temporary Parent object, right? I don't see how it
should help (even though it *does* indeed work).

Why do we need to pass self along in that call to super()? Shouldn't
the class name be enough for super() to find the right superclass object?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: New Python.org website ?

2006-01-15 Thread JW
On Sun, 15 Jan 2006 22:19:37 +, Tim Parkin wrote:

 http://pyyaml.org/downloads/masterhtml/
 
 Feedback appreciated ... Many thanks

Again, with FF 1.0.7 (on FC4 Linux BTW), the left column no longer
violates the right.  However, ViewPage Stylelarge text makes the
button annotation smaller than ViewPage StyleBasic Page Style.

Please understand, web programming is not my main axe.  I'm in no way
asserting my observations are meaningful ;).

Jim Wilson
Gainesville, FL
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: instance attributes not inherited?

2006-01-15 Thread John M. Gabriele
John M. Gabriele wrote:
 David Hirschfield wrote:
 
 Nothing's wrong with python's oop inheritance, you just need to know 
 that the parent class' __init__ is not automatically called from a 
 subclass' __init__. Just change your code to do that step, and you'll 
 be fine:

 class Parent( object ):
 def __init__( self ):
 self.x = 9


 class Child( Parent ):
 def __init__( self ):
 super(Child,self).__init__()
print Inside Child.__init__()

 -David

 
 How does it help that Parent.__init__ gets called? That call simply
 would create a temporary Parent object, right? I don't see how it
 should help (even though it *does* indeed work).

Sorry -- that question I wrote looks a little incomplete: what I meant
to ask was, how does it help this code to work:

 code 
#!/usr/bin/python

class Parent( object ):
 def __init__( self ):
 self.x = 9
 print Inside Parent.__init__()

 def wash_dishes( self ):
 print Inside Parent.wash_dishes(), washing, self.x, dishes.


class Child( Parent ):
 def __init__( self ):
 super( Child, self ).__init__()
 print Inside Child.__init__()


c = Child()
c.wash_dishes()
 /code 

since the x instance attribute created during the
super( Child, self ).__init__() call is just part of what looks to be
a temporary Parent instance.




-- 
(remove zeez if demunging email address)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to get Windows system information?

2006-01-15 Thread dpickles
For the memory, which of these fields tells you the total amount of
RAM? Thanks!

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


Re: instance attributes not inherited?

2006-01-15 Thread Bengt Richter
On Sun, 15 Jan 2006 18:44:50 -0500, John M. Gabriele [EMAIL PROTECTED] 
wrote:

The following short program fails:
to do what you intended, but it does not fail to do what you programmed ;-)


--- code 
#!/usr/bin/python

class Parent( object ):
 def __init__( self ):
 self.x = 9
 print Inside Parent.__init__()


class Child( Parent ):
 def __init__( self ):
 print Inside Child.__init__()


p1 = Parent()
p2 = Parent()
c1 = Child()
foo = [p1,p2,c1]

for i in foo:
 print x =, i.x
- /code --



yielding the following output:

 output --
Inside Parent.__init__()
Inside Parent.__init__()
Inside Child.__init__()
x = 9
x = 9
x =
Traceback (most recent call last):
   File ./foo.py, line 21, in ?
 print x =, i.x
AttributeError: 'Child' object has no attribute 'x'
 /output -


Why isn't the instance attribute x getting inherited?
It would be if it existed, but your Child defines __init__
and that overrides the Parent __init__, so since you do not
call Parent.__init__ (directly or by way of super), x does not get set,
and there is nothing to inherit.

BTW, inherit is not really what makes x visible as an attribute of the
instance in this case. The x attribute happens to be assigned in 
Parent.__init__,
but that does not make it an inherited attribute of Parent. IOW, Parent.__init__
is a function that becomes bound to the instance and then operates on the 
instance
to set the instance's x attribute, but any function could do that. Or any 
statement
with access to the instance in some way could do it. Inheritance would be if 
there were
e.g. a Parent.x class variable or property. Then Child().x would find that by 
inheritance.

BTW, if you did _not_ define Child.__init__ at all, Child would inherit 
Parent.__init__
and it would be called, and would set the x attribute on the child instance.


My experience with OOP has been with C++ and (more
recently) Java. If I create an instance of a Child object,
I expect it to *be* a Parent object (just as, if I subclass
a Car class to create a VW class, I expect all VW's to *be*
Cars).

That is to say, if there's something a Parent can do, shouldn't
the Child be able to do it too? Consider a similar program:

--- code 
#!/usr/bin/python


class Parent( object ):
 def __init__( self ):
 self.x = 9
 print Inside Parent.__init__()

 def wash_dishes( self ):
 print Just washed, self.x, dishes.


class Child( Parent ):
 def __init__( self ):
 print Inside Child.__init__()


p1 = Parent()
p2 = Parent()
c1 = Child()
foo = [p1,p2,c1]

for i in foo:
 i.wash_dishes()
--- /code ---

But that fails with:

--- output --
Inside Parent.__init__()
Inside Parent.__init__()
Inside Child.__init__()
Just washed 9 dishes.
Just washed 9 dishes.
Just washed
Traceback (most recent call last):
   File ./foo.py, line 24, in ?
 i.wash_dishes()
   File ./foo.py, line 10, in wash_dishes
 print Just washed, self.x, dishes.
AttributeError: 'Child' object has no attribute 'x'
--- /output -

Why isn't this inherited method call working right?
The method call is working fine. It's just that as before
Child.__init__ overrides Parent.__init__ without calling
Parent.__init__ or setting the x attribute itself, so
AttributeError: 'Child' object has no attribute 'x'
is telling the truth. And it's telling that was discovered
at File ./foo.py, line 10, in wash_dishes -- in other
words _inside_ wash_dishes, meaning the call worked, but
you hadn't provided for the initialization of the x attribute
it depended on.

There are various ways to fix this besides calling Parent.__init__
from Child.__init__, depending on desired semantics.

Is this a problem with Python's notion of how OO works?
Nope ;-)

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


Re: proposal: another file iterator

2006-01-15 Thread Jean-Paul Calderone
On 15 Jan 2006 16:44:24 -0800, Paul Rubin http://phr.cx@nospam.invalid 
wrote:
I find pretty often that I want to loop through characters in a file:

  while True:
 c = f.read(1)
 if not c: break
 ...

or sometimes of some other blocksize instead of 1.  It would sure
be easier to say something like:

   for c in f.iterbytes(): ...

or

   for c in f.iterbytes(blocksize): ...

this isn't anything terribly advanced but just seems like a matter of
having the built-in types keep up with language features.  The current
built-in iterator (for line in file: ...) is useful for text files but
can potentially read strings of unbounded size, so it's inadvisable for
arbitrary files.

Does anyone else like this idea?

It's a pretty useful thing to do, but the edge-cases are somewhat complex.  
When I just want the dumb version, I tend to write this:

for chunk in iter(lambda: f.read(blocksize), ''):
...

Which is only very slightly longer than your version.  I would like it even 
more if iter() had been written with the impending doom of lambda in mind, so 
that this would work:

for chunk in iter('', f.read, blocksize):
...

But it's a bit late now.  Anyhow, here are some questions about your 
iterbytes():

  * Would it guarantee the chunks returned were read using a single read?  If 
blocksize were a multiple of the filesystem block size, would it guarantee 
reads on block-boundaries (where possible)?

  * How would it handle EOF?  Would it stop iterating immediately after the 
first short read or would it wait for an empty return?

  * What would the buffering behavior be?  Could one interleave calls to 
.next() on whatever iterbytes() returns with calls to .read() on the file?

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


Re: proposal: another file iterator

2006-01-15 Thread Raymond Hettinger
Paul Rubin wrote:
 I find pretty often that I want to loop through characters in a file:

   while True:
  c = f.read(1)
  if not c: break
  ...

 or sometimes of some other blocksize instead of 1.  It would sure
 be easier to say something like:

for c in f.iterbytes(): ...

 or

for c in f.iterbytes(blocksize): ...

 this isn't anything terribly advanced but just seems like a matter of
 having the built-in types keep up with language features.  The current
 built-in iterator (for line in file: ...) is useful for text files but
 can potentially read strings of unbounded size, so it's inadvisable for
 arbitrary files.

 Does anyone else like this idea?

+1   It would be nice to see this replace the old API where you had to
test for an empty return value.


FWIW, I've seen it expressed using other tools:

   for c in iter(partial(somefile.read, blocksize), ''):
 . . .

Raymond

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


Preventing class methods from being defined

2006-01-15 Thread David Hirschfield
Here's a strange concept that I don't really know how to implement, but 
I suspect can be implemented via descriptors or metaclasses somehow:

I want a class that, when instantiated, only defines certain methods if 
a global indicates it is okay to have those methods. So I want something 
like:

global allow
allow = [foo,bar]

class A:
def foo():
...

def bar():
...

def baz():
...

any instance of A will only have a.foo() and a.bar() but no a.baz() 
because it wasn't in the allow list.

I hope that makes sense.
Don't ask why I would need such a strange animal, I just do. I'm just 
not sure how to approach it.

Should class A have some special metaclass that prevents those methods 
from existing? Should I override __new__ or something? Should those 
methods be wrapped with special property subclasses that prevent access 
if they're not in the list? What's a low-overhead approach that will 
work simply?

Thanks in advance,
-David

-- 
Presenting:
mediocre nebula.

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


Re: proposal: another file iterator

2006-01-15 Thread Benji York
Jean-Paul Calderone wrote:
   When I just want the dumb version, I tend to write this:
 
  for chunk in iter(lambda: f.read(blocksize), ''): ...
 
  Which is only very slightly longer than your version.  I would like it
  even more if iter() had been written with the impending doom of lambda
  in mind, so that this would work:
 
  for chunk in iter('', f.read, blocksize): ...
 
  But it's a bit late now.

How about this instead (will work in 2.5):

 for chunk in iter(partial(f.read, blocksize), ''): ...

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


Can one class have multiple metaclasses?

2006-01-15 Thread David Hirschfield
Is it possible for one class definition to have multiple metaclasses?

I don't think it is, but I'm just checking to make sure.
 From what I know, you can only define __metaclass__ to set the 
metaclass for a class, and that's it, is that correct?

-David

-- 
Presenting:
mediocre nebula.

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


Re: proposal: another file iterator

2006-01-15 Thread Paul Rubin
Jean-Paul Calderone [EMAIL PROTECTED] writes:
 Which is only very slightly longer than your version.  I would like
 it even more if iter() had been written with the impending doom of
 lambda in mind, so that this would work:
 
 for chunk in iter('', f.read, blocksize):
 ...
 
 But it's a bit late now.

Well, iter could be extended to take *args and **kwargs parameters, so
you'd say

for chunk in iter(f.read, '', (blocksize,)): ...

That leaves the params in a clumsy order for backwards compatibility,
but it's not unbearable.

 Anyhow, here are some questions about your iterbytes():
 
   * Would it guarantee the chunks returned were read using a single
 read?  If blocksize were a multiple of the filesystem block size,
 would it guarantee reads on block-boundaries (where possible)?

I expect that the iterator's .next() would just get the result
of f.read(blocksize), which makes no such guarantees.

   * How would it handle EOF?  Would it stop iterating immediately
after the first short read or would it wait for an empty return?

Wait for empty return.

   * What would the buffering behavior be?  Could one interleave
 calls to .next() on whatever iterbytes() returns with calls to
 .read() on the file?

I don't see why not.  Iterbytes would just call read() and yield the
result.  You could even have multiple iterators going at once.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: instance attributes not inherited?

2006-01-15 Thread Dan Sommers
On Sun, 15 Jan 2006 20:37:36 -0500,
John M. Gabriele [EMAIL PROTECTED] wrote:

 David Hirschfield wrote:

 Nothing's wrong with python's oop inheritance, you just need to know
 that the parent class' __init__ is not automatically called from a
 subclass' __init__. Just change your code to do that step, and you'll
 be fine:

[example snipped]

 How does it help that Parent.__init__ gets called? That call simply
 would create a temporary Parent object, right? I don't see how it
 should help (even though it *does* indeed work).

The __init__ method is an *initializer*, *not* a constructor.  By the
time __init__ runs, the object has already been constructed; __init__
just does extra initialization.

Regards,
Dan

-- 
Dan Sommers
http://www.tombstonezero.net/dan/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Preventing class methods from being defined

2006-01-15 Thread Dan Sommers
On Sun, 15 Jan 2006 18:41:02 -0800,
David Hirschfield [EMAIL PROTECTED] wrote:

 I want a class that, when instantiated, only defines certain methods
 if a global indicates it is okay to have those methods. So I want
 something like:

 global allow
 allow = [foo,bar]

 class A:
 def foo():
 ...

 def bar():
 ...

 def baz():
 ...

 any instance of A will only have a.foo() and a.bar() but no a.baz()
 because it wasn't in the allow list.

 I hope that makes sense.

I think so, at least in the I can implement that idea sense, although
not the why would you need such a strange animal sense.  Since class
is an executable statement in Python, this ought to do it:

allow = [foo, bar]

class A:

  if foo in allow:
def foo( ):
  ...

  if bar in allow:
def bar( ):
  ...

 Don't ask why I would need such a strange animal ...

Consider yourself not asked.

HTH,
Dan

-- 
Dan Sommers
http://www.tombstonezero.net/dan/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Preventing class methods from being defined

2006-01-15 Thread David Hirschfield
I should have explicitly mentioned that I didn't want this particular 
solution, for a number of silly reasons.
Is there another way to make this work, without needing to place an 
explicit if allowed around each method definition?

Thanks again,
-David

Dan Sommers wrote:

On Sun, 15 Jan 2006 18:41:02 -0800,
David Hirschfield [EMAIL PROTECTED] wrote:

  

I want a class that, when instantiated, only defines certain methods
if a global indicates it is okay to have those methods. So I want
something like:



  

global allow
allow = [foo,bar]



  

class A:
def foo():
...



  

def bar():
...



  

def baz():
...



  

any instance of A will only have a.foo() and a.bar() but no a.baz()
because it wasn't in the allow list.



  

I hope that makes sense.



I think so, at least in the I can implement that idea sense, although
not the why would you need such a strange animal sense.  Since class
is an executable statement in Python, this ought to do it:

allow = [foo, bar]

class A:

  if foo in allow:
def foo( ):
  ...

  if bar in allow:
def bar( ):
  ...

  

Don't ask why I would need such a strange animal ...



Consider yourself not asked.

HTH,
Dan

  


-- 
Presenting:
mediocre nebula.

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


Re: Can one class have multiple metaclasses?

2006-01-15 Thread Alex Martelli
David Hirschfield [EMAIL PROTECTED] wrote:

 Is it possible for one class definition to have multiple metaclasses?
 
 I don't think it is, but I'm just checking to make sure.

You're right, it isn't.

  From what I know, you can only define __metaclass__ to set the 
 metaclass for a class, and that's it, is that correct?

Yes, it's correct.  Just as an instance is an instance of one (leafmost)
class, so a class is an instance of one (leafmost) metaclass -- if you
want multiple classes or metaclasses, you must inherit.

The last recipe in the 2nd ed of Python Cookbook shows how to design an
automatic metaclass conflict reconciler to do the inheritance on your
behalf, btw.


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


Re: Preventing class methods from being defined

2006-01-15 Thread Alex Martelli
David Hirschfield [EMAIL PROTECTED] wrote:

 Here's a strange concept that I don't really know how to implement, but
 I suspect can be implemented via descriptors or metaclasses somehow:

Yeah, a custom metaclass will do it, easily.

 I want a class that, when instantiated, only defines certain methods if
 a global indicates it is okay to have those methods. So I want something
 like:
 
 global allow
 allow = [foo,bar]
 
 class A:
 def foo():
 ...
 
 def bar():
 ...
 
 def baz():
 ...
 
 any instance of A will only have a.foo() and a.bar() but no a.baz() 
 because it wasn't in the allow list.
 
 I hope that makes sense.

Sure.  If you don't need to worry about inheritance, and want to
'snapshot' the set of methods and other class attributes based on the
value of 'allow' at the time the class statement executes:

class meta_only_allowed(type):
def __new__(mcl, name, bases, cdict):
for k in cdict.keys():
if k not in allow:
del cdict[k]
return super(mcl, meta_only_allowed).__new__(
 mcl, name, bases, cdict)

[[untested, but I hope the concept is clear]].

If you want the value of 'allow' at class-*instantiation* time to be in
control, then what you need to override is __call__ rather than __new__.
You'll need to make a special class on the fly for the purpose (make
sure you memoize it to avoid needless duplication).

If you do need to worry about inheritance, and want to disallow
inherited methods as well, then you need to loop over all methods in
base classes (use standard library module inspect for that) and
construct an artificial dict, then drop the 'bases' and use an empty
tuple of bases for the supercall (real inheritance doesn't let you
hide methods, or other superclass attributes, ever).

Etc, etc -- it's most surely possible to do what you want, whatever what
you DO want is exactly!-)


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


Re: On Numbers

2006-01-15 Thread Alex Martelli
Paul Rubin http://[EMAIL PROTECTED] wrote:

 Mike Meyer [EMAIL PROTECTED] writes:
  I'd like to work on that. The idea would be that all the numeric types
  are representations of reals with different properties that make them
  appropriate for different uses. 
 
 2+3j?

Good point, so s/reals/complex numbers/ -- except for this detail,
Mike's idea do seem well founded.

What *I* would also like would be a basenumber abstract class, like the
existing basestring, such that alternate numerics (like those I supply
in gmpy) could inherit from it in order to assert yes, I *AM* a
number! and allow isinstance-based checks rather than ones based on
try to sum 0 and see if that gives an exception.  A very small,
localized, and potentially useful change, IMHO.


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


Re: how do real python programmers work?

2006-01-15 Thread Alex Martelli
Scott David Daniels [EMAIL PROTECTED] wrote:

 bblais wrote:
  How do experienced python programmers usually do it?  Is there a
  usually about it, or is it up to personal taste?  Are there any
  convenient ways of doing these things?
 There are a lot of us who use a test-first process:

Yep, I'm one of those (TDD, test-driven development, is the acronym
-- I think concept and monicker are both due to Kent Beck).  I also
strive to convince anybody else to do that if I have any stake in the
success of their programming -- if they're emacsers, bully for them, but
I'm a vi'er myself (I keep telling myself I should learn emacs, but
then, I also tell myself I should stop smoking, and I don't actually DO
anything about that, either;-), and TDD can be used with any editor or
IDE, anyway.


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


Re: [ANN] pysqlite 2.1.0 released

2006-01-15 Thread Alex Martelli
Gerhard Häring [EMAIL PROTECTED] wrote:
   ...
 An optimized shortcut has been enabled to retrieve Unicode strings for
 non-ASCII data, but bytestrings for non-ASCII text:
 
 con.text_factory = sqlite.OptimizedUnicode

I assume you mean ASCII text rather than non-ASCII text here?

At any rate, my compliments for a new release (which looks great!) of a
most excellent module!


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


Re: Getting better traceback info on exec and execfile - introspection?

2006-01-15 Thread R. Bernstein
Ziga Seilnacht [EMAIL PROTECTED] writes:
 You should check the getFrameInfo function in zope.interface package:
 http://svn.zope.org/Zope3/trunk/src/zope/interface/advice.py?rev=25177view=markup

Thanks! Just looked at that. The logic in the relevant part (if I've extracted
this correctly):

f_globals = frame.f_globals
hasName = '__name__' in f_globals
module = hasName and sys.modules.get(f_globals['__name__']) or None
namespaceIsModule = module and module.__dict__ is f_globals
if not namespaceIsModule:
# some kind of funky exec
kind = exec

is definitely not obvious to me. exec's don't have module namespace
(or something or other)?  Okay. And that the way to determine the
module-namespace thingy is whatever that logic is? Are the assumptions
here be likely to be valid in the future? 

Another problem I have with that code is that it uses the Zope Public
License. But the code is adapted from the Python Enterprise
Application Kit (PEAK) which doesn't seem to use the Zope Public
License. I'm not sure it's right to adopt a Zope Public License just
for this.

So instead, I followed the other avenue I suggested which is
dissembling the statement around the frame. Talk about the kettle
calling the pot black! Yes, I don't know if the assumptions in this
method are likely to be valid in the future either.

But I can use op-code examination to also help me determine if we are
stopped at a def statement which I want to skip over. So here's the
code I've currently settled on:

from opcode import opname
def op_at_frame(frame):
code = frame.f_code.co_code
pos  = frame.f_lasti
op = ord(code[pos])
return opname[op]

def is_exec_stmt(frame):
Return True if we are looking at an exec statement
return frame.f_back is not None and op_at_frame(frame.f_back)=='EXEC_STMT'

re_def = re.compile(r'^\s*def\s+')
def is_def_stmt(line, frame):
Return True if we are looking at a def statement
# Should really also check that the operand is a code object
return re_def.match(line) and op_at_frame(frame)=='LOAD_CONST'

But it may just be because I wrote it that I find it easier to
understand and more straightforward to fathom.

  And suppose instead of 'string' I'd like to give the value or the
  leading prefix of the value instead of the unhelpful word 'string'?
  How would one do that? Again, one way is to go into the outer frame
  get the source line (if that exists), parse that and interpolate
  argument to exec(file). Is there are better way?
 
 Py library (http://codespeak.net/py/current/doc/index.html) has some
 similar functionality in the code subpackage.

Again, many thanks. I'll have to study this further. It may be that
exec and so on are wrapped so that it's possible to squirrel away the
string before calling exec. Again, dunno. But thanks for the pointer.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Getting better traceback info on exec and execfile - introspection?

2006-01-15 Thread R. Bernstein
Fernando Perez [EMAIL PROTECTED] writes:
 I thought a little about this.  One possibility ...

Thanks. A sibling thread has the code I'm currently using. 

 Oh, that's because you're using %run, so your code is in complete control. 
 What I meant about a restriction ...
Okay.

 If you are interested in ipython integration,

Yes I am.

 I suggest the ipython-dev list as a better place for discussion: I only
 monitor c.l.py on occasion, so I may well miss things here.

Okay now subscribed. But interestingly I looked in the IPython PDF and
didn't see mention of it when looking for contact info. I do however
see it (now) listed on http://ipython.scipy.org/. Thanks again.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: On Numbers

2006-01-15 Thread Dan Bishop
Alex Martelli wrote:
 Paul Rubin http://[EMAIL PROTECTED] wrote:

  Mike Meyer [EMAIL PROTECTED] writes:
   I'd like to work on that. The idea would be that all the numeric types
   are representations of reals with different properties that make them
   appropriate for different uses.
 
  2+3j?

 Good point, so s/reals/complex numbers/ -- except for this detail,
 Mike's idea do seem well founded.

 What *I* would also like would be a basenumber abstract class, like the
 existing basestring, such that alternate numerics (like those I supply
 in gmpy) could inherit from it in order to assert yes, I *AM* a
 number! and allow isinstance-based checks rather than ones based on
 try to sum 0 and see if that gives an exception.  A very small,
 localized, and potentially useful change, IMHO.

+1

although I personally would prefer

   (number)
   /   \
(realnumber)   complex
  |   |   |
int float |
  |
Decimal

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


Re: Display of JPEG images from Python

2006-01-15 Thread David
Svien and Michel,

Thanks for your help.  Much appreciated.

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


  1   2   >