Ruby doctest

2008-06-22 Thread Paddy
I monitor changes to the Wikipedia doctest page, and so noticed a
change in the Ruby implementation of doctest.

Scooting around their implementation I found that they have an !!!
special directive that says drop into the interpreter at this point
when testing allowing debugging in context.
http://github.com/tablatom/rubydoctest/wikis/special-directives

- Paddy.

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


Re: flock seems very unsafe, python fcntl bug?

2008-06-22 Thread Jens Henrik Leonhard Jensen

Your problem is that open(...,'w') is not locked.

Use something like:
lockf = open('aaa', 'a')
fnctl.flock(lockf,fnctl.LOCK_EX)
file = open('aaa', 'w')
file.write('asdf')
file.close()
lockf.close()

[EMAIL PROTECTED] wrote:

I ran following 2 programs (lock1, lock2) at almost same time,
to write either 123456, or 222 to file aaa at the same time.
But I often just got 222456 in aaa .

Is this a bug of python fcntl module ? See 2 programs I ran:



#!/usr/bin/env python
import fcntl, time
file = open('aaa', w)
fcntl.flock(file, fcntl.LOCK_EX)
file.write('123456')
time.sleep(10)
file.close()


#!/usr/bin/env python
import fcntl, time
file = open('aaa', w)
fcntl.flock(file, fcntl.LOCK_EX)
file.write('222')
time.sleep(10)
file.close()

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


Re: Fast and easy GUI prototyping with Python

2008-06-22 Thread Sebastian lunar Wiesner
Michael Torrie [EMAIL PROTECTED]:

 [EMAIL PROTECTED] wrote:
 2) The Qt vs. .NET API. I have no experience with Qt's API and a
 rudimentary experience with the .NET API (seems powerfull but also big
 and complex).
 
 Qt's API is very very good.  Easy to use and extremely powerful.  Note
 that in Python a number of Qt's APIs are not used in favor of Python
 native apis for things like file and socket I/O, IPC, Threads, and so
 forth.

The support for signals and slots is imho a strong reason to prefer Qt apis
over standard python apis, especially when it comes down to asynchronous
programming (for instance, large network transfers like file downloads).

  I've not used VS 2008's SWF gui designer, but of all the designers I've
  seen so far, Qt's Designer is the best I've ever used.

full ack.

-- 
Freedom is always the freedom of dissenters.
  (Rosa Luxemburg)
--
http://mail.python.org/mailman/listinfo/python-list


Storing value with limits in object

2008-06-22 Thread Josip
I'm trying to limit a value stored by object (either int or float):

class Limited(object):
def __init__(self, value, min, max):
self.min, self.max = min, max
self.n = value
def set_n(self,value):
if value  self.min: # boundary check
self.n = self.min
if value  self.max:
self.n = self.max
else:
self.n = value
n = property(lambda self : self._value, set_n)

This works, except I would like the class to behave like built-in types, so
I can use it like this:

a = Limited(7, 0, 10)
b = math.sin(a)

So that object itself returns it's value (which is stored in a.n). Is this
possible?



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


Re: Storing value with limits in object

2008-06-22 Thread David
On Sun, Jun 22, 2008 at 11:44 AM, Josip [EMAIL PROTECTED] wrote:
 I'm trying to limit a value stored by object (either int or float):

 class Limited(object):
def __init__(self, value, min, max):
self.min, self.max = min, max
self.n = value
def set_n(self,value):
if value  self.min: # boundary check
self.n = self.min
if value  self.max:
self.n = self.max
else:
self.n = value
n = property(lambda self : self._value, set_n)

 This works, except I would like the class to behave like built-in types, so
 I can use it like this:

 a = Limited(7, 0, 10)
 b = math.sin(a)

 So that object itself returns it's value (which is stored in a.n). Is this
 possible?


Not with normal vars, because = is a rebinding operator in Python,
rather than assignment.

You can do (close to) the above with object properties.

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


Re: Storing value with limits in object

2008-06-22 Thread Josip
 Not with normal vars, because = is a rebinding operator in Python,
 rather than assignment.

 You can do (close to) the above with object properties.

 David.

Yes, but it's done with built-in types like int and float. I suspect I could 
subclass from them and implement limits, but I would have to make
seperate class for each type. Can I override conversion methods like int() 
and float() within my class? 


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


Learning Python in a group

2008-06-22 Thread Jonathan Roberts
Hi all,

I'm looking to learn Python (as my first programming language) and I'm
pretty sure I'd be more successful doing this with a group of other
people.

I've currently got one other person to learn with me, and we plan to
work remotely over the net using tools such as IM/VoiP/Gobby/WIkis
etc. We'd still like a few others to work with us, with a group of
about 5 or 6 being seen as ideal. We'd also like to find somebody to
act as a mentor/guide who might be happy to meet with us once every
couple of weeks to help keep us moving in the right direction and find
solutions to problems when we get really stuck!

Wondered if there was anybody here who might be interested in working
with us in either of these roles? We both have differing goals, but
ultimately we'd just like to get more familiar so that we can provide
some simple fixes to packages we maintain/scratch a few itches of our
own. Any one is welcome, no matter what your own aim :)

Would love to hear feedback, especially from anyone who's interested
in working with us...

Best,

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


Re: Learning Python in a group

2008-06-22 Thread Henry Read
I'm a beginner, too.But python wasn't my first programming language.

On Sun, Jun 22, 2008 at 6:43 PM, Jonathan Roberts [EMAIL PROTECTED]
wrote:

 Hi all,

 I'm looking to learn Python (as my first programming language) and I'm
 pretty sure I'd be more successful doing this with a group of other
 people.

 I've currently got one other person to learn with me, and we plan to
 work remotely over the net using tools such as IM/VoiP/Gobby/WIkis
 etc. We'd still like a few others to work with us, with a group of
 about 5 or 6 being seen as ideal. We'd also like to find somebody to
 act as a mentor/guide who might be happy to meet with us once every
 couple of weeks to help keep us moving in the right direction and find
 solutions to problems when we get really stuck!

 Wondered if there was anybody here who might be interested in working
 with us in either of these roles? We both have differing goals, but
 ultimately we'd just like to get more familiar so that we can provide
 some simple fixes to packages we maintain/scratch a few itches of our
 own. Any one is welcome, no matter what your own aim :)

 Would love to hear feedback, especially from anyone who's interested
 in working with us...

 Best,

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

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

Re: Storing value with limits in object

2008-06-22 Thread David
On Sun, Jun 22, 2008 at 12:24 PM, Josip [EMAIL PROTECTED] wrote:
 Not with normal vars, because = is a rebinding operator in Python,
 rather than assignment.

 You can do (close to) the above with object properties.

 David.

 Yes, but it's done with built-in types like int and float. I suspect I could
 subclass from them and implement limits, but I would have to make
 seperate class for each type. Can I override conversion methods like int()
 and float() within my class?


I think I may have misread your original post.

ints and floats are internal , immutable types, with some class
goodness on top (so you can treat them like objects to a degree,
subclass from them, etc). Python's interpreter has built-in logic
which 'knows' how to use ints and floats variables, without calling
their special __ methods. Python would be a lot slower if it worked
this way.

To do exactly what you want, you'd need to add a new internal numeric
type to Python.

You can subclass from float, and redefine __float__ and __int__, but
those will only be called when your code actually calls the builtin
float() and int() builtins, eg:

import math

class Float(float):
def __float__(self):
raise NotImplementedError

a = Float(1)
print math.sin(a)

# Outputs 0.841470984808

a = Float(1)
print math.sin(float(a))

# Throws a NotImplementedError exception

There is no way (afaik) for an object to tell Python to call one of
it's methods to get a reference, or 'value' to the object (if there
was, it would make things really complicated). In Python you generally
need to update the logic used during a lookup to get that effect (ie,
in  a.b.c, you can customise the a.b lookup, or the a.b.c lookup, but
not the a lookup itself).

In theory you could hack Python's internal locals or globals
dictionary so that it did something unusual while looking up your
object. But in practice this doesn't work, because the returned
objects (when you call globals() or locals()) attributes are readonly.
Probably because those internal lookup dicts are implemented in
optimized C not Python, and the C implementation doesn't let you
redefine it's internals via the Python interface.

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


Re: Fast and easy GUI prototyping with Python

2008-06-22 Thread Pete Kirkham
2008/6/21 Val-Amart [EMAIL PROTECTED]:

 Use PyQt. You will gain great portability +all the functionality built
 in qt.
 You can try PyGTK also, though i wont recommend it.

Why would you not recommend it? I've been using it for a mall project, and
would like to know if there's some pit waiting for me to fall into.

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

Re: Learning Python in a group

2008-06-22 Thread David
On Sun, Jun 22, 2008 at 12:43 PM, Jonathan Roberts
[EMAIL PROTECTED] wrote:
 Hi all,

 I'm looking to learn Python (as my first programming language) and I'm
 pretty sure I'd be more successful doing this with a group of other
 people.

 I've currently got one other person to learn with me, and we plan to
 work remotely over the net using tools such as IM/VoiP/Gobby/WIkis
 etc. We'd still like a few others to work with us, with a group of
 about 5 or 6 being seen as ideal. We'd also like to find somebody to
 act as a mentor/guide who might be happy to meet with us once every
 couple of weeks to help keep us moving in the right direction and find
 solutions to problems when we get really stuck!


If you want people to meet with you (in person) as a mentor you should
probably ask on your local Python or Linux users group mailing list.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Storing value with limits in object

2008-06-22 Thread Josip
 In theory you could hack Python's internal locals or globals
 dictionary so that it did something unusual while looking up your
 object. But in practice this doesn't work, because the returned
 objects (when you call globals() or locals()) attributes are readonly.
 Probably because those internal lookup dicts are implemented in
 optimized C not Python, and the C implementation doesn't let you
 redefine it's internals via the Python interface.

 David.

I'll settle for implementing the __call__() method to return the value as I 
have
no intention to mess around with Python's internal mechanisms.

Thanks a lot for your deep insight. 


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


Re: Learning Python in a group

2008-06-22 Thread Jonathan Roberts
 If you want people to meet with you (in person) as a mentor you should
 probably ask on your local Python or Linux users group mailing list.

We're not really too worried about doing it in person - mostly because
the people doing it so far are all at least 1000 miles away from each
other :)

Best,

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

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


Re: Learning Python in a group

2008-06-22 Thread David
On Sun, Jun 22, 2008 at 1:52 PM, Jonathan Roberts
[EMAIL PROTECTED] wrote:
 If you want people to meet with you (in person) as a mentor you should
 probably ask on your local Python or Linux users group mailing list.

 We're not really too worried about doing it in person - mostly because
 the people doing it so far are all at least 1000 miles away from each
 other :)


I'm sure that many (myself included) would be happy to help out, but
due to timezone differences, working hours, etc you may only get
responses up to 24 hours (or more) later.

What needs does your (non-face-to-face) group have that would not be
met by posting questions to the Python Tutor list?

http://mail.python.org/mailman/listinfo/tutor

Perhaps you and your co-learners can sign up to that list, and
coordinate with that list's users to use your wiki, messaging
services, etc?

Personally I learned Python from the Python docs (starting with the
tutorial), practice, and Google. Dive Into Python is good too.

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


Re: Storing value with limits in object

2008-06-22 Thread George Sakkis
On Jun 22, 5:44 am, Josip [EMAIL PROTECTED] wrote:

 I'm trying to limit a value stored by object (either int or float):

 class Limited(object):
 def __init__(self, value, min, max):
 self.min, self.max = min, max
 self.n = value
 def set_n(self,value):
 if value  self.min: # boundary check
 self.n = self.min
 if value  self.max:
 self.n = self.max
 else:
 self.n = value
 n = property(lambda self : self._value, set_n)

 This works,

I bet you didn't even try this, unless your definition of works
includes a RuntimeError: maximum recursion depth exceeded. Here's a
a working version:

class Limited(object):
def __init__(self, value, min, max):
self.min, self.max = min, max
self.n = value

n = property(lambda self : self._value,
 lambda self,value:
self.__dict__.__setitem__('_value',
max(self.min, min(value,
self.max

def __int__(self): return int(self._value)
def __float__(self): return float(self._value)


a = Limited(11, 0, 9)
print float(a)
import math
print math.sqrt(a)

 except I would like the class to behave like built-in types, so
 I can use it like this:

 a = Limited(7, 0, 10)
 b = math.sin(a)

 So that object itself returns it's value (which is stored in a.n). Is this
 possible?

For (most) math.* functions it suffices to define __float__, so the
above works. For making it behave (almost) like a regular number,
you'd have to write many more special methods: 
http://docs.python.org/ref/numeric-types.html.
Here's a possible start:

import operator

class Limited(object):
def __init__(self, value, min, max):
self.min, self.max = min, max
self.n = value

n = property(lambda self : self._value,
 lambda self,value:
self.__dict__.__setitem__('_value',
max(self.min, min(value,
self.max

def __str__(self): return str(self.n)
def __repr__(self): return 'Limited(%r, min=%r, max=%r)' %
(self.n, self.min, self.max)

def __int__(self): return int(self._value)
def __float__(self): return float(self._value)

def __add__(self, other): return self._apply(operator.add, self,
other)
def __sub__(self, other): return self._apply(operator.sub, self,
other)
# a few dozens more methods follow ...

def __radd__(self, other): return self._apply(operator.add, other,
self)
def __rsub__(self, other): return self._apply(operator.sub, other,
self)
# a few dozens more methods follow ...

@classmethod
def _apply(cls, op, first, second):
minmax = None
if isinstance(first, cls):
minmax = first.min,first.max
first = first._value
if isinstance(second, cls):
if minmax is None:
minmax = second.min,second.max
second = second._value
return cls(op(first,second), *minmax)


a = Limited(11, 0, 9)
print a+1
print 1+a
print a-1
print 1-a


Needless to say, this is almost two orders of magnitude slower than
the builtin numbers, so you'd better not use it for any serious number
crunching.

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


Re: Learning Python: Code critique please

2008-06-22 Thread Saul Spatz

macoovacany wrote:

http://macoovacany.wordpress.com/
When I tried to run it, I got all kinds of syntax errors because of 
non-ASCII characters; namely, you have fancy left and right single

and double quotes.  Once I replaced these with the ASCII equivalents,
it worked fine.  I suggest you use a plain ASCII text editor, like the
one that comes with IDLE.

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


Re: Storing value with limits in object

2008-06-22 Thread Larry Bates

Josip wrote:

I'm trying to limit a value stored by object (either int or float):

class Limited(object):
def __init__(self, value, min, max):
self.min, self.max = min, max
self.n = value
def set_n(self,value):
if value  self.min: # boundary check
self.n = self.min
if value  self.max:
self.n = self.max
else:
self.n = value
n = property(lambda self : self._value, set_n)

This works, except I would like the class to behave like built-in types, so
I can use it like this:

a = Limited(7, 0, 10)
b = math.sin(a)

So that object itself returns it's value (which is stored in a.n). Is this
possible?




Why not make it a function?

function assignLimited(value, vmin, vmax):
value = max(vmin, value)
value = min(vmax, value)
return value


a = assignLimited(7, 0, 10)


Seems like it solves your problem relatively cleanly.
Note: I also removed min/max variables because they would mask the built-in 
min/max functions.


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


Trying to Learn Packages

2008-06-22 Thread Saul Spatz

Hi,

I'm making a project into my first package, mainly for organization, but 
also to learn how to do it.  I have a number of data files, both 
experimental results and PNG files.  My project is organized as a root
directory, with two subdirectories, src and data, and directory trees 
below them.  I put the root directory in my pythonpath, and I've no 
trouble accessing the modules, but for the data, I'm giving relative 
paths, that depend on the current working directory.


This has obvious drawbacks, and hard-coding a directory path is worse. 
Where the data files are numbers, I can simply incorporate them in 
python scripts that initialize data structures , but what can I do with 
the image files?


What is the usual way of dealing with this?

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


pyHook and py2exe

2008-06-22 Thread Gandalf
hi every one.
I have program which uses this pyHook lib, and when I try to compile
it using py2exe the pyhook don't work. it gives me no error. the
program works fine beside the function of this lib.
why does it append ?

is their any solution?
I would be glad to know if anyone ever experienced this problem and if
he solve it eventually


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


Re: How to convert a into a

2008-06-22 Thread dominique
On Jun 22, 6:45 am, Tim Roberts [EMAIL PROTECTED] wrote:
 dominique [EMAIL PROTECTED] wrote:
 On Jun 21, 1:37 pm, John Machin [EMAIL PROTECTED] wrote:

  Look at the operator module. In your above example:

  return {
 '': operator.gt,
 '=': operator.eq,
 '': operator.lt,
 }[variable]

 Thanks a lot John
 Dominique

 Yes, but you need to remember that what you are getting is not literally an
 operator.  That is, if you store that return value in a variable called
 op, you can't say this:

 if x op y:
 

 Instead, what you have is a function, so you'll have to write it:

 if op( x, y ):
 --
 Tim Roberts, [EMAIL PROTECTED]
 Providenza  Boekelheide, Inc.

Thanks for the tip.
Dominique
--
http://mail.python.org/mailman/listinfo/python-list


[PyQt4] QTableWidget non editable

2008-06-22 Thread Antonio Valentino
Ciao a tutti,
ho un QTableWidget che ho reso non editabile settando editTriggers a
NoEditTriggers.

Il problema è che adesso non posso selezionare una cela e copiarne il
contenuto nella clipboard.

Come posso risolvere il problema?

Grazie in anticipo

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


Re: Getting column names from a cursor using ODBC module?

2008-06-22 Thread Michael Mabin
The pyodb module doesn't implement this behavior.  You would have to create
a dictionary of column positions and column names in advance.

On Sat, Jun 21, 2008 at 3:52 PM, Chris [EMAIL PROTECTED] wrote:

 On Jun 21, 3:58 pm, [EMAIL PROTECTED] wrote:
  Is there any way to retrieve column names from a cursor using the ODBC
  module? Or must I, in advance, create a dictionary of column position
  and column names for a particular table before I can access column
  values by column names? I'd prefer sticking with the ODBC module for
  now because it comes standard in Python.
 
  I'm using Python 2.4 at the moment.
 
  Thanks.

 You should be able to do

 column_names = [d[0] for d in cursor.description]
 --
 http://mail.python.org/mailman/listinfo/python-list




-- 
| _ | * | _ |
| _ | _ | * |
| * | * | * |
--
http://mail.python.org/mailman/listinfo/python-list

Re: QTableWidget non editable

2008-06-22 Thread Antonio Valentino
On 22 Giu, 17:11, Antonio Valentino [EMAIL PROTECTED]
wrote:
 Ciao a tutti,
 ho un QTableWidget che ho reso non editabile settando editTriggers a
 NoEditTriggers.

 Il problema è che adesso non posso selezionare una cela e copiarne il
 contenuto nella clipboard.

 Come posso risolvere il problema?

 Grazie in anticipo

 antonio

Sorry,
wrong newsgroup :(

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


Re: Trying to Learn Packages

2008-06-22 Thread David
On Sun, Jun 22, 2008 at 4:07 PM, Saul Spatz [EMAIL PROTECTED] wrote:
 Hi,

 I'm making a project into my first package, mainly for organization, but
 also to learn how to do it.  I have a number of data files, both
 experimental results and PNG files.  My project is organized as a root
 directory, with two subdirectories, src and data, and directory trees below
 them.  I put the root directory in my pythonpath, and I've no trouble
 accessing the modules, but for the data, I'm giving relative paths, that
 depend on the current working directory.

 This has obvious drawbacks, and hard-coding a directory path is worse. Where
 the data files are numbers, I can simply incorporate them in python scripts
 that initialize data structures , but what can I do with the image files?

 What is the usual way of dealing with this?


The usual method (afaik) is to use relative paths, and to not change
into the script dirs before running them.

eg, instead of:

cd src/dir1/dir2/dir3
./script.py

You run it like this:
./src/dir1/dir2/dir3/script.py

And then all the scripts under src can load data files using a path
like this: './data/datafile'

Another method is to use a file-finder func which looks in various
places (using PATH, PYHONPATH, etc), and returns the first-found path
to the file.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Trying to Learn Packages

2008-06-22 Thread Cédric Lucantis
Le Sunday 22 June 2008 16:07:37 Saul Spatz, vous avez écrit :
 Hi,

 I'm making a project into my first package, mainly for organization, but
 also to learn how to do it.  I have a number of data files, both
 experimental results and PNG files.  My project is organized as a root
 directory, with two subdirectories, src and data, and directory trees
 below them.  I put the root directory in my pythonpath, and I've no
 trouble accessing the modules, but for the data, I'm giving relative
 paths, that depend on the current working directory.

 This has obvious drawbacks, and hard-coding a directory path is worse.
 Where the data files are numbers, I can simply incorporate them in
 python scripts that initialize data structures , but what can I do with
 the image files?

For a small project you can do the same with images or any kind of data, for 
instance by serializing your objects with pickle in ascii mode and putting 
the result in a string constant (well, I never did it and can't guarantee it 
will work, this is only an example of what people do in many situations)


 What is the usual way of dealing with this?


A more conventional way is to provide a configure script to run before 
compiling/installing. That script should let the user choose where to install 
datafiles with a command line option such as --datadir=/path or provide a 
reasonable default value. Then it will auto-generate some code defining this 
value as a global variable, to make it accessible to the rest of your own 
code. Ideally, your app would also provide a command line option or an 
environment variable to override this hard-coded setting at runtime.

But maybe the distutils tools have some features for this, I don't know enough 
of them to tell that.

-- 
Cédric Lucantis
--
http://mail.python.org/mailman/listinfo/python-list


Re: My n00bie brain hurts after Python setup.py install.

2008-06-22 Thread John Nagle

John Machin wrote:

On Jun 22, 9:05 am, [EMAIL PROTECTED] wrote:

I downloaded Mark Pilgrims's feedparser.py in a zipfile to my Windows
machine, unzipped it and tried to install it to no avail.



Eggs are part of a new experimental package distribution scheme. Don't
worry about it.


   Yes.  Eggs are connected to an easy install system which has
an annoying tendency to either fail or silently do the wrong thing.
They were an attempt to apply the packaging mania of Java to Python.
Fortunately, .egg files are actually .zip files, so you can
rename them, unpack them, and get at the good parts.

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


Re: Learning Python in a group

2008-06-22 Thread Jonathan Roberts
 I'm sure that many (myself included) would be happy to help out, but
 due to timezone differences, working hours, etc you may only get
 responses up to 24 hours (or more) later.

Awesome, heh I'm sure we'll have questions for the list in good time :)

 What needs does your (non-face-to-face) group have that would not be
 met by posting questions to the Python Tutor list?

 http://mail.python.org/mailman/listinfo/tutor

 Perhaps you and your co-learners can sign up to that list, and
 coordinate with that list's users to use your wiki, messaging
 services, etc?

Actually, I hadn't seen that list before but I've just signed up for
it and it sounds really interesting! The big difference really is that
I'd like to try and build something a little more personal, where we
have a group of people who can contact each other in real time and
have regular meeting times as well as being able to find each other in
between meetings too. I think this kind of consistent relationship is
probably quite conducive to learning, and I think others would
probably agree :)

 Personally I learned Python from the Python docs (starting with the
 tutorial), practice, and Google. Dive Into Python is good too.

Yeah, I think we're definitely going to be making use of these
resources, and then just using each other as support as we wade
through the material and inevitably get stuck in places!

Thanks for your help :)

Best,

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


Re: Web Crawler - Python or Perl?

2008-06-22 Thread subeen
On Jun 13, 1:26 am, Chuck Rhode [EMAIL PROTECTED] wrote:
 On Mon, 09 Jun 2008 10:48:03 -0700, disappearedng wrote:
  I knowPythonbut notPerl, and I am interested in knowing which of
  these two are a better choice.

 I'm partial to *Python*, but, the last time I looked, *urllib2* didn't
 provide a time-out mechanism that worked under all circumstances.  My
 client-side scripts would usually hang when the server quit
 responding, which happened a lot.


You can avoid the problem using the following code:
import socket

timeout = 300 # seconds
socket.setdefaulttimeout(timeout)

regards,
Subeen.
http://love-python.blogspot.com/
--
http://mail.python.org/mailman/listinfo/python-list


Re: Learning Python in a group

2008-06-22 Thread George Oliver
On Jun 22, 3:43 am, Jonathan Roberts [EMAIL PROTECTED]
wrote:
 Hi all,

 I'm looking to learn Python (as my first programming language) and I'm
 pretty sure I'd be more successful doing this with a group of other
 people.

hi Jon, I'm in the same situation as you and think a co-op method of
learning could be effective and fun. I found the Tutor list that David
mentioned a little while ago but also have been looking for a group
(without success so far). So count me in!


best, George

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


Re: Learning Python in a group

2008-06-22 Thread oesoriano
I might be interested in joining your group.  I'm trying to learn
python, too, but tend to get frustrated by the isolation.  can you
send me, or post, some details?

- O

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


Bind compiled code to name?

2008-06-22 Thread Karlo Lozovina
If string `source_code` contains Python source code, how can I execute 
that code, and bind it to some name? I tried compiling with: 

code_object = compile(source_code, 'errorfile', 'exec')

but then what to do with `code_object`?

P.S.
If my intentions aren't that clear, this is what I'm trying to do. I want 
to emulate this:

   import some_module as some_name

but with my code in `some_module` string, and not in file.


Thanks...

-- 
 ___Karlo Lozovina - Mosor
|   |   |.-.-. web: http://www.mosor.net || ICQ#: 10667163
|   ||  _  |  _  | Parce mihi domine quia Dalmata sum.
|__|_|__||_|_|
--
http://mail.python.org/mailman/listinfo/python-list


Re: Storing value with limits in object

2008-06-22 Thread Josip
 Why not make it a function?

 function assignLimited(value, vmin, vmax):
 value = max(vmin, value)
 value = min(vmax, value)
 return value


 a = assignLimited(7, 0, 10)


 Seems like it solves your problem relatively cleanly.
 Note: I also removed min/max variables because they would mask the
 built-in min/max functions.

 -Larry

Yes, the simple solution is often the best. Still, I'm going for object
oriented solution because I want the value and it's limits to be kept
together as I'll have many such values with different limits. Storing all
the limits in caller namespace is not really an option.



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


Re: Storing value with limits in object

2008-06-22 Thread Josip
 Why not make it a function?

 function assignLimited(value, vmin, vmax):
 value = max(vmin, value)
 value = min(vmax, value)
 return value


 a = assignLimited(7, 0, 10)


 Seems like it solves your problem relatively cleanly.
 Note: I also removed min/max variables because they would mask the
 built-in min/max functions.

 -Larry

Yes, the simple solution is often the best. Still, I'm going for object
oriented solution because I want the value and it's limits to be kept
together as I'll have many such values with different limits. Storing all
the limits in caller namespace is not really an option.




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


Re: install py2exe in vista

2008-06-22 Thread jim-on-linux
On Saturday 21 June 2008 13:28, Herman wrote:
  I want to install it in
 vistahttp://www.daniweb.com/forums/thread130469.htm
l#, but i get this message in the process:
 could not create... py2exe-py2.5

I forwarded your question but you may want to ask again 
at the link below.

[EMAIL PROTECTED]

jim-on-linux
http://inqvista.com


 I press 'OK', then..
 could not set key value python 2.5 py2exe-0.6.8

 I press 'OK' again, then...
 could not set key value
 c:\Python25\Removepy2exe.exe -u
 c:\python25\py2exe-wininst.log

 The installation goes on and do something, run some
 postinstall script.

 I thought it should be ok, but i fail even creating
 a simple hello word exe. I get this message after i
 run python setup.py install: running install
 running build
 running install_egg_info
 Writing
 c:\Python25\Lib\site-packages\UNKNOWN-0.0.0-py2.5-eg
g-info

 No output is created.

 Can I anyone help me with this? 
 http://www.addthis.com/bookmark.php
 http://www.daniweb.com/forums/editpost.php?do=editp
ostp=631985
--
http://mail.python.org/mailman/listinfo/python-list


-1/2

2008-06-22 Thread Serve Lau

What is the expected result of -1/2 in python?

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


Re: Bind compiled code to name?

2008-06-22 Thread Martin v. Löwis
 If string `source_code` contains Python source code, how can I execute 
 that code, and bind it to some name? I tried compiling with: 
 
 code_object = compile(source_code, 'errorfile', 'exec')
 
 but then what to do with `code_object`?
 
 P.S.
 If my intentions aren't that clear, this is what I'm trying to do. I want 
 to emulate this:
 
import some_module as some_name
 
 but with my code in `some_module` string, and not in file.
 

d = {}
exec source_code in d
some_name = d['some_name']

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


Re: pyHook and py2exe

2008-06-22 Thread jim-on-linux
On Sunday 22 June 2008 10:40, Gandalf wrote:
 hi every one.
 I have program which uses this pyHook lib, and when
 I try to compile it using py2exe the pyhook don't
 work. it gives me no error. the program works fine
 beside the function of this lib. why does it append
 ?

 is their any solution?
 I would be glad to know if anyone ever experienced
 this problem and if he solve it eventually



I forwarded your question but you may want to ask again 
at the link below.

[EMAIL PROTECTED]

jim-on-linux
http:\\inqvista.com


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


Re: Storing value with limits in object

2008-06-22 Thread Josip
 I bet you didn't even try this, unless your definition of works
 includes a RuntimeError: maximum recursion depth exceeded. Here's a
 a working version:

Actually, the version I'm using is somewhat bigger. I removed docstrings and
recklessly stripped away some methods to make it shorter concise and
incorrect.

 For (most) math.* functions it suffices to define __float__, so the
 above works. For making it behave (almost) like a regular number,
 you'd have to write many more special methods:
 http://docs.python.org/ref/numeric-types.html.
 Here's a possible start:

(...)

Yes, this is very close to what I was looking for. It implements all the
functionality except asssigning values. And speed is not an issue for my
application.
Thanks.



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


Re: Bind compiled code to name?

2008-06-22 Thread Karlo Lozovina
Martin v. Löwis [EMAIL PROTECTED] wrote in
news:[EMAIL PROTECTED]: 

 d = {}
 exec source_code in d
 some_name = d['some_name']

This works quite well! I can't believe after googling for half on hour I 
didn't notice this exec ... in ... syntax.
One more thing though, is there a way to access some_name as a 
attribute, instead as a dictionary:

some_name = d.some_name

?

Thanks...

-- 
 ___Karlo Lozovina - Mosor
|   |   |.-.-. web: http://www.mosor.net || ICQ#: 10667163
|   ||  _  |  _  | Parce mihi domine quia Dalmata sum.
|__|_|__||_|_|
--
http://mail.python.org/mailman/listinfo/python-list

Re: -1/2

2008-06-22 Thread Christian Heimes
Serve Lau wrote:
 What is the expected result of -1/2 in python?

0

Christian

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


Re: -1/2

2008-06-22 Thread Gary Herron

Serve Lau wrote:

What is the expected result of -1/2 in python?

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

From the manual:


The result is always rounded towards minus infinity: 1/2 is 0, (-1)/2 is 
-1, 1/(-2) is -1, and (-1)/(-2) is 0.



Gary Herron

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


Re: -1/2

2008-06-22 Thread Gary Herron

Christian Heimes wrote:

Serve Lau wrote:
  

What is the expected result of -1/2 in python?



0

  


No.  That's not right.  (It would be in C/C++ and many other languages.)

See my other response for the correct answer.

Gary Herron




Christian

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


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


pyTTS says, 'SAPI not supported'

2008-06-22 Thread weheh
I'm running Python 2.3 and calling pyTTS. I've had it working forever.

Today, I ran out of disk space. After deleting some of my personal files, 
for no apparent reason, pyTTS no longer runs.

For the statement

tts = pyTTS.Create()

I get the error message:

ValueError: SAPI not supported

Can anybody help me? What's going on? 


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


binary number format ? format character %b or similar.

2008-06-22 Thread Ken Starks

I'm was wanting to format a positive integer in binary,
and not finding it--to my surprise--I rolled my own version.

Is this already in python, or have I missed it somewhere?

I have Googled around a bit, and found a few threads on
the subject, but they all seem to fizzle out.

(e.g. : INPUT 35, OUTPUT 100011 )
--
http://mail.python.org/mailman/listinfo/python-list


Re: An idiom for code generation with exec

2008-06-22 Thread Scott David Daniels

[EMAIL PROTECTED] wrote:
 On 20 juin, 21:44, eliben [EMAIL PROTECTED] wrote:
...
 The generic version has to make a lot of decisions at runtime, based
 on the format specification.
 Extract the offset from the spec, extract the length.
... example with lists of operations...
 Just my 2 cents. Truth is that as long as it works and is
 maintainable, then who cares...

To chime in on non-exec operations alternatives.  The extraction
piece-by-piece looks like it might be slow.  You could figure out
where the majority of endian-ness is (typically it will be all one way),
and treat specially any others (making the string fields with an
operation applied).  The best optimizations come from understanding
the regularities in your specific case; seldom do they come from
generating code that hides the regularity and depending on a compiler
to deduce that regularity.

Have you tried something like this (a sketch of a solution)?:

import struct
from functools import partial
import operator


class Decoder(object):
def __init__(self, unpack, processors, finals):
'''Of course this might be simply take the yaml in and go'''
self.unpack = unpack
self.processors = processors
self.length = struct.calcsize(unpack)
self.finals = finals

def packet(self, data):
parts = list(struct.unpack(self.unpack, data))
for n, action, result in self.processors:
if result is None:
parts.append(action(parts[n]))
else:
parts[n] = action(parts[n])
return tuple(parts[n] for n in self.finals) # or NamedTuple ...


def _bits(from_bit, mask, v):
return (v  from_bit)  mask


Your example extended a bit:
fmt = Decoder('cBiBIi', [(1, partial(operator.mul, 2048), '-'),
  (3, partial(_bits, 5, 0x3), None),
  (3, partial(operator.iand, 0x80), None),
  (3, partial(operator.iand, 0x1F), '-'),
  (6, bool, '-')],
  [0, 1, 2, 3, 6, 7, 4, 5])
print fmt.packet(source.read(fmt.length))


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


Re: Way to unblock sys.stdin.readline() call

2008-06-22 Thread joamag
On Jun 21, 11:34 pm, Terry Reedy [EMAIL PROTECTED] wrote:
 joamag wrote:
  Is there any possible way to unblock the sys.stdin.readline() call
  from a different thread.

 If you want the thread to do something 'else' when no input is
 available, would this work?  Put readline in a thread that puts lines in
 a q=queue.Quese().  Then
 try:
      l=q.ge_nowait
      process l
 except queue.Empty
      whatever without l

Yes, that would work but still I would have a thread that would block
(the one with the readline call).
The problem with that solution is that if I try to exit the
application, while the thread is waiting in the readline call, that
thread would be blocking the exit of the application.
That behavior occurs even if the thread is configured in daemon mode.
Do you think it’s possible to solve the readline blocking problem in
any other way ?
--
http://mail.python.org/mailman/listinfo/python-list


Re: binary number format ? format character %b or similar.

2008-06-22 Thread weheh
I don't know if you found this example: 
http://www.daniweb.com/code/snippet285.html

-- 
 I'm was wanting to format a positive integer in binary,
 and not finding it--to my surprise--I rolled my own version.

 Is this already in python, or have I missed it somewhere?

 I have Googled around a bit, and found a few threads on
 the subject, but they all seem to fizzle out.

 (e.g. : INPUT 35, OUTPUT 100011 ) 


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


Re: Bind compiled code to name?

2008-06-22 Thread Martin v. Löwis
 d = {}
 exec source_code in d
 some_name = d['some_name']
 
 This works quite well! I can't believe after googling for half on hour I 
 didn't notice this exec ... in ... syntax.
 One more thing though, is there a way to access some_name as a 
 attribute, instead as a dictionary:
 
 some_name = d.some_name

Sure:

class D:pass
d = D()
exec source_code in d.__dict__
print d.some_name

Notice that this will also give you d.__builtins__, which you might
want to del afterwards.

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


Re: Learning Python in a group

2008-06-22 Thread AngelinaCarmen
I would like to be a part of this if enough people are able to join
up, I nabbed python less than two days ago, and have been trying to
absorb as much as I can out of websites and practice projects.
Learning this together would speed up the process slightly because we
could share tips and such, all in all, I'm up for it.
--
http://mail.python.org/mailman/listinfo/python-list


ImportError: cannot import name QtCore. using PyInstaller.1-3 and PyQt4 and Python 2.5

2008-06-22 Thread asoft
Please i need help with this. I just started using python and i hace
run into several issues. The on that i can't tackle is the issue of no
being able to compile the python code using PyQt4 application
It gives the error
ImportError: cannot import name QtCore.
.
I tries the trunk from the snv, but it still gives the same error.

I also would like to know. if there are any report generation tool i
can use with python similar to crystal reports. I am developing for a
windows env. And i come from a visual basic.NET background.
Thanks.
--
http://mail.python.org/mailman/listinfo/python-list


Re: binary number format ? format character %b or similar.

2008-06-22 Thread Ken Starks

weheh wrote:
I don't know if you found this example: 
http://www.daniweb.com/code/snippet285.html




Thanks for that. The offerings are very similar to the
algorithms I wrote myself.

It wasn't the solution I was after,really; that's
easy. It was whether anything had found its way into
the standard library.
--
http://mail.python.org/mailman/listinfo/python-list


Regular expression problem

2008-06-22 Thread abranches
Hello everyone.

I'm having a problem when extracting data from HTML with regular
expressions.
This is the source code:

You are ready in the nextbr /span id=counter_jt_minutes
style=display: inline;span id=counter_jt_minutes_value12/
spanM/span span id=counter_jt_seconds style=display:
inline;span id=counter_jt_seconds_value48/spanS/span

And I need to get the remaining time. Until here, isn't a problem
getting it, but if the remaining time is less than 60 seconds then the
source becomes something like this:

You are ready in the nextbr /span id=counter_jt_seconds
style=display: inline;span id=counter_jt_seconds_value36/
spanS/span

I'm using this regular expression, but the minutes are always None...
You are ready in the next.*?(?:(\d+)/spanM/span)?.*?(?:(\d+)/
spanS/span)

If I remove the ? from the first group, then it will work, but if
there are only seconds it won't work.
I could resolve this problem in a couple of python lines, but I really
would like to solve it with regular expressions.

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


Re: Getting column names from a cursor using ODBC module?

2008-06-22 Thread dananrg
Thanks Chris and John. Chris, this worked perfectly with the ODBC
module that ships with Python Win32:

 column_names = [d[0] for d in cursor.description]

John, I've never heard of pyodbc but I'll have to look into it.

Thanks again.

Dana

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


rightclick-copy in IDLE?

2008-06-22 Thread cirfu
when i rightclick in python idle i get set breakpoint or something.

n options i dont find a way to change to the normal copy/paste options.
--
http://mail.python.org/mailman/listinfo/python-list


listcomprehension, add elements?

2008-06-22 Thread cirfu
[a+b for a,b in zip(xrange(1,51), xrange(50,0,-1))]

[51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51,
51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51,
51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51]

i want to add all the elemtns a s well. can i do this all in a
listcomprehension?

i can do this ofc:
reduce(lambda x,y:x+y,[a+b for a,b in zip(xrange(1,51),
xrange(50,0,-1))])

but reduce is a functional way of doing it, what is the more pythonic
way of doing this?
--
http://mail.python.org/mailman/listinfo/python-list


Re: listcomprehension, add elements?

2008-06-22 Thread Jeff
On Jun 22, 6:32 pm, cirfu [EMAIL PROTECTED] wrote:
 [a+b for a,b in zip(xrange(1,51), xrange(50,0,-1))]

 [51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51,
 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51,
 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51]

 i want to add all the elemtns a s well. can i do this all in a
 listcomprehension?

 i can do this ofc:
 reduce(lambda x,y:x+y,[a+b for a,b in zip(xrange(1,51),
 xrange(50,0,-1))])

 but reduce is a functional way of doing it, what is the more pythonic
 way of doing this?

Nothing that would be more concise than reduce.  Anything you did with
iteration would just mimic reduce in any case.

Jeff Ober
artfulcode.net
--
http://mail.python.org/mailman/listinfo/python-list


Re: listcomprehension, add elements?

2008-06-22 Thread Paul Hankin
On Jun 23, 10:32 am, cirfu [EMAIL PROTECTED] wrote:
 [a+b for a,b in zip(xrange(1,51), xrange(50,0,-1))]

 [51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51,
 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51,
 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51]

 i want to add all the elemtns a s well. can i do this all in a
 listcomprehension?

 i can do this ofc:
 reduce(lambda x,y:x+y,[a+b for a,b in zip(xrange(1,51),
 xrange(50,0,-1))])

 but reduce is a functional way of doing it, what is the more pythonic
 way of doing this?

Use the builtin 'sum' function.

sum(a + b for a, b in zip(xrange(1, 51), xrange(50, 0, -1)))

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


Re: listcomprehension, add elements?

2008-06-22 Thread John Machin
On Jun 23, 9:23 am, Paul Hankin [EMAIL PROTECTED] wrote:
 On Jun 23, 10:32 am, cirfu [EMAIL PROTECTED] wrote:

  [a+b for a,b in zip(xrange(1,51), xrange(50,0,-1))]

  [51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51,
  51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51,
  51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51]

  i want to add all the elemtns a s well. can i do this all in a
  listcomprehension?

  i can do this ofc:
  reduce(lambda x,y:x+y,[a+b for a,b in zip(xrange(1,51),
  xrange(50,0,-1))])

  but reduce is a functional way of doing it, what is the more pythonic
  way of doing this?

 Use the builtin 'sum' function.

 sum(a + b for a, b in zip(xrange(1, 51), xrange(50, 0, -1)))


Instead of sum(a + b for a, b in zip(foo, bar))
why not use sum(foo) + sum(bar)
?


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


Re: Learning Python: Code critique please

2008-06-22 Thread William McBrine
On Sun, 22 Jun 2008 08:44:25 -0500, Saul Spatz wrote:

 macoovacany wrote:
 http://macoovacany.wordpress.com/
 When I tried to run it, I got all kinds of syntax errors because of
 non-ASCII characters; namely, you have fancy left and right single and
 double quotes.

That's probably WordPress' doing.

-- 
09 F9 11 02 9D 74 E3 5B D8 41 56 C5 63 56 88 C0 -- pass it on
--
http://mail.python.org/mailman/listinfo/python-list


Re: binary number format ? format character %b or similar.

2008-06-22 Thread Mensanator
On Jun 22, 4:07�pm, Ken Starks [EMAIL PROTECTED] wrote:
 weheh wrote:
  I don't know if you found this example:
 http://www.daniweb.com/code/snippet285.html

 Thanks for that. The offerings are very similar to the
 algorithms I wrote myself.

 It wasn't the solution I was after,really; that's
 easy. It was whether anything had found its way into
 the standard library.

Isn't that coming in Python 3.0?

You could also use gmpy, which has a lot of
other bit-functionality in addition to displaying
them.

 for i in xrange(8):
print 'i:',gmpy.digits(i,2).zfill(8),
print '# of 1-bits:',gmpy.popcount(i),
print 'find LS 1-bit:',gmpy.scan1(i),
print 'bit difference:',gmpy.hamdist(i,2**8-1)


i:  # of 1-bits: 0 find LS 1-bit: -1 bit difference: 8
i: 0001 # of 1-bits: 1 find LS 1-bit: 0 bit difference: 7
i: 0010 # of 1-bits: 1 find LS 1-bit: 1 bit difference: 7
i: 0011 # of 1-bits: 2 find LS 1-bit: 0 bit difference: 6
i: 0100 # of 1-bits: 1 find LS 1-bit: 2 bit difference: 7
i: 0101 # of 1-bits: 2 find LS 1-bit: 0 bit difference: 6
i: 0110 # of 1-bits: 2 find LS 1-bit: 1 bit difference: 6
i: 0111 # of 1-bits: 3 find LS 1-bit: 0 bit difference: 5
--
http://mail.python.org/mailman/listinfo/python-list

Re: -1/2

2008-06-22 Thread [EMAIL PROTECTED]
On Jun 22, 2:32 pm, Serve Lau [EMAIL PROTECTED] wrote:
 What is the expected result of -1/2 in python?

I would say -1, but it depends on whether the - is a unary minus.

 -1/2
-1
 3 -1/2
3
--
http://mail.python.org/mailman/listinfo/python-list


Re: Fast and easy GUI prototyping with Python

2008-06-22 Thread Michael Torrie
Pete Kirkham wrote:
 2008/6/21 Val-Amart [EMAIL PROTECTED]:
 
 Use PyQt. You will gain great portability +all the functionality built
 in qt.
 You can try PyGTK also, though i wont recommend it.

 Why would you not recommend it? I've been using it for a mall project, and
 would like to know if there's some pit waiting for me to fall into.

The only pitfall is Mac compatibility.  OS X support in GTK is still
under development, and much harder to get running than Qt.  I guess one
other minor thing is that on win32 it's not quite native-looking, but
pretty darn close.

If Gtk provides everything you need, then there's no reason not to use
it.  I personally prefer it to Qt, although Qt is quite far ahead of Gtk
in many ways (including CSS to style widgets).  GTK's licensing is more
appropriate for closed-source projects than Qt under the GPL (and
cheaper too).
--
http://mail.python.org/mailman/listinfo/python-list


Re: Tkinter canvas drag/drop obstacle

2008-06-22 Thread Peter Pearson
On Fri, 20 Jun 2008 13:41:35 -0300, Guilherme Polo [EMAIL PROTECTED] wrote:
 On Fri, Jun 20, 2008 at 1:11 PM, Peter Pearson [EMAIL PROTECTED] wrote:
 Tkinter makes it very easy to drag jpeg images around on a
 canvas, but I would like to have a target change color when
 the cursor dragging an image passes over it.  I seem to be
 blocked by the fact that the callbacks that might tell the
 target that the mouse has entered it (Enter, Any-Enter,
 even Motion) aren't called if the mouse's button is down.
 What am I missing?  Have I failed to find the right Tkinter
 document?  Is Tkinter the wrong tool for this job?  Thanks.


 I believe the only way to achieve this is binding Motion to the
 entire canvas, then checking if the x, y coords are inside the
 target.

Ugh.  OK, thanks.

-- 
To email me, substitute nowhere-spamcop, invalid-net.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Pattern Matching Over Python Lists

2008-06-22 Thread Chris
On Jun 19, 9:03 pm, John Machin [EMAIL PROTECTED] wrote:
 On Jun 20, 10:45 am, Chris [EMAIL PROTECTED] wrote:

  On Jun 17, 1:09 pm, [EMAIL PROTECTED] wrote:

   Kirk Strauser:

Hint: recursion.  Your general algorithm will be something like:

   Another solution is to use a better (different) language, that has
   built-in pattern matching, or allows to create one.

   Bye,
   bearophile

  Btw, Python's stdlib includes a regular expression library. I'm not
  sure if you're trolling or simply unaware of it, but I've found it
  quite adequate for most tasks.

 Kindly consider a third possibility: bearophile is an experienced
 Python user, has not to my knowledge exhibited any troll-like
 behaviour in the past, and given that you seem to be happy using the
 re module not on strings but on lists of integers, may have been
 wondering whether *you* were trolling or just plain confused but just
 too polite to wonder out loud :-)

Fair enough. To help you understand the method I used, I'll give you
this hint. It's true that regex on works on strings. However, is there
any way to convert arbitrarily complex data structures to string
representations? You don't need to be an experienced Python user to
answer to this ;)
--
http://mail.python.org/mailman/listinfo/python-list


Re: Pattern Matching Over Python Lists

2008-06-22 Thread eliben
 Fair enough. To help you understand the method I used, I'll give you
 this hint. It's true that regex on works on strings. However, is there
 any way to convert arbitrarily complex data structures to string
 representations? You don't need to be an experienced Python user to
 answer to this ;)

As Paddy noted before, your solution has a problem, Regexes can't
match nested parenthesis, so I think your method will have a problem
with nested lists, unless your actual inputs are much simpler than the
general case.

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


Re: Learning Python in a group

2008-06-22 Thread Satya Kiran
You can count me in too.I've been into python for sometime now.
I agree that a collaborative learning makes it fun and helps you reach
your goal faster.
--
http://mail.python.org/mailman/listinfo/python-list


Re: An idiom for code generation with exec

2008-06-22 Thread eliben
Thanks for all the replies in this post. Just to conclude, I want to
post a piece of code I wrote to encapsulate function creation in this
way:

def create_function(code):
 Create and return the function defined in code.

m = re.match('\s*def\s+([a-zA-Z_]\w*)\s*\(', code)
if m:
func_name = m.group(1)
else:
return None

d = {}
exec code.strip() in globals(), d
return d[func_name]

Although the 'def' matching in the beginning looks a bit shoddy at
first, it should work in all cases.

Eli




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


Re: Tkinter canvas drag/drop obstacle

2008-06-22 Thread Simon Forman
On Jun 22, 7:41 pm, Peter Pearson [EMAIL PROTECTED] wrote:
 On Fri, 20 Jun 2008 13:41:35 -0300, Guilherme Polo [EMAIL PROTECTED] wrote:
  On Fri, Jun 20, 2008 at 1:11 PM, Peter Pearson [EMAIL PROTECTED] wrote:
  Tkinter makes it very easy to drag jpeg images around on a
  canvas, but I would like to have a target change color when
  the cursor dragging an image passes over it.  I seem to be
  blocked by the fact that the callbacks that might tell the
  target that the mouse has entered it (Enter, Any-Enter,
  even Motion) aren't called if the mouse's button is down.
  What am I missing?  Have I failed to find the right Tkinter
  document?  Is Tkinter the wrong tool for this job?  Thanks.

  I believe the only way to achieve this is binding Motion to the
  entire canvas, then checking if the x, y coords are inside the
  target.

 Ugh.  OK, thanks.

 --
 To email me, substitute nowhere-spamcop, invalid-net.


Yep, but it's not so bad:

from Tkinter import *

c = Canvas()
c.pack()
i = c.create_oval(1, 1, 100, 100, fill='green')

def cb(e):
items = c.find_overlapping(
e.x, e.y,
e.x + 1, e.y + 1
)
if not items:
return
print items

c.bind(B1-Motion, cb)

mainloop()




The c.find_overlapping() method returns a tuple.  I believe the item
ids in the tuple (if any) will be in the same order as the items Z
order on the canvas, so items[-1] should always be the topmost
graphic item (again, if any.)
--
http://mail.python.org/mailman/listinfo/python-list


Re: Bind compiled code to name?

2008-06-22 Thread Giuseppe Ottaviano

class D:pass
d = D()
exec source_code in d.__dict__
print d.some_name

Notice that this will also give you d.__builtins__, which you might
want to del afterwards.



If you want to mimic an import you can also do this:

import types
D = types.ModuleType('D')
exec source_code in D.__dict__
print D.some_name

This way D is a module (don't know if there are real differences with  
the class approach, though)



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


Re: Learning Python in a group

2008-06-22 Thread Mensanator
On Jun 22, 5:43�am, Jonathan Roberts [EMAIL PROTECTED]
wrote:
 Hi all,

 I'm looking to learn Python (as my first programming language) and I'm
 pretty sure I'd be more successful doing this with a group of other
 people.

 I've currently got one other person to learn with me, and we plan to
 work remotely over the net using tools such as IM/VoiP/Gobby/WIkis
 etc. We'd still like a few others to work with us, with a group of
 about 5 or 6 being seen as ideal. We'd also like to find somebody to
 act as a mentor/guide who might be happy to meet with us once every
 couple of weeks to help keep us moving in the right direction and find
 solutions to problems when we get really stuck!

 Wondered if there was anybody here who might be interested in working
 with us in either of these roles? We both have differing goals, but
 ultimately we'd just like to get more familiar so that we can provide
 some simple fixes to packages we maintain/scratch a few itches of our
 own. Any one is welcome, no matter what your own aim :)

 Would love to hear feedback, especially from anyone who's interested
 in working with us...

Have you considered creating your own Google Group?


 Best,

 Jon

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

POP3_SSL Error

2008-06-22 Thread Roopesh
Hi,

While using poplib to fetch mails from my gmail account, I am getting
the following error:

Exception is POP3_SSL instance has no attribute 'sslobj'

Can anyone tell me what this error means.

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


Re: rightclick-copy in IDLE?

2008-06-22 Thread Miki
 when i rightclick in python idle i get set breakpoint or something.

 n options i dont find a way to change to the normal copy/paste options.
Under Preferences ... menu you'll find Keys tab, there you can
change the keys bindings to whatever you want.

HTH,
--
Miki [EMAIL PROTECTED]
http://pythonwise.blogspot.com

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


Re: Trying to Learn Packages

2008-06-22 Thread Saul Spatz

Cédric Lucantis wrote:

Le Sunday 22 June 2008 16:07:37 Saul Spatz, vous avez écrit :

Hi,

I'm making a project into my first package, mainly for organization, but
also to learn how to do it.  I have a number of data files, both
experimental results and PNG files.  My project is organized as a root
directory, with two subdirectories, src and data, and directory trees
below them.  I put the root directory in my pythonpath, and I've no
trouble accessing the modules, but for the data, I'm giving relative
paths, that depend on the current working directory.

This has obvious drawbacks, and hard-coding a directory path is worse.
Where the data files are numbers, I can simply incorporate them in
python scripts that initialize data structures , but what can I do with
the image files?


For a small project you can do the same with images or any kind of data, for 
instance by serializing your objects with pickle in ascii mode and putting 
the result in a string constant (well, I never did it and can't guarantee it 
will work, this is only an example of what people do in many situations)



What is the usual way of dealing with this?



A more conventional way is to provide a configure script to run before 
compiling/installing. That script should let the user choose where to install 
datafiles with a command line option such as --datadir=/path or provide a 
reasonable default value. Then it will auto-generate some code defining this 
value as a global variable, to make it accessible to the rest of your own 
code. Ideally, your app would also provide a command line option or an 
environment variable to override this hard-coded setting at runtime.


But maybe the distutils tools have some features for this, I don't know enough 
of them to tell that.



A couple of good ideas here.  Thanks.
--
http://mail.python.org/mailman/listinfo/python-list


[issue3112] implement PEP 3134 exception reporting

2008-06-22 Thread Adam Olsen

Adam Olsen [EMAIL PROTECTED] added the comment:

* cause/context cycles should be avoided.  Naive traceback printing
could become confused, and I can't think of any accidental way to
provoke it (besides the problem mentioned here.)

* I suspect PyErr_Display handled string exceptions in 2.x, and this is
an artifact of that

* No opinion on PyErr_DisplaySingle

* PyErr_Display is used by PyErr_Print, and it must end up with no
active exception.  Additionally, third party code may depend on this
semantic.  Maybe PyErr_DisplayEx?

* +1 on standardizing tracebacks

--
nosy: +Rhamphoryncus

___
Python tracker [EMAIL PROTECTED]
http://bugs.python.org/issue3112
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue3167] math test fails on Solaris 10

2008-06-22 Thread Mark Dickinson

Mark Dickinson [EMAIL PROTECTED] added the comment:

I'll take a look.

--
assignee:  - marketdickinson
nosy: +marketdickinson

___
Python tracker [EMAIL PROTECTED]
http://bugs.python.org/issue3167
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue3168] cmath test fails on Solaris 10

2008-06-22 Thread Mark Dickinson

Changes by Mark Dickinson [EMAIL PROTECTED]:


--
assignee:  - marketdickinson
nosy: +marketdickinson

___
Python tracker [EMAIL PROTECTED]
http://bugs.python.org/issue3168
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue3167] math test fails on Solaris 10

2008-06-22 Thread Mark Dickinson

Mark Dickinson [EMAIL PROTECTED] added the comment:

Could you tell me what

 import math
 math.log(float('-inf'))

gives instead of the expected ValueError?

___
Python tracker [EMAIL PROTECTED]
http://bugs.python.org/issue3167
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue2722] os.getcwd fails for long path names on linux

2008-06-22 Thread Facundo Batista

Facundo Batista [EMAIL PROTECTED] added the comment:

Went for the malloc only patch. Just fixed a small detail (weird corner
case if malloc returned NULL first time, res will be unassigned).

The test could be better (no necessity of using a recursive function, it
could be done with a while), but it works.

Commited in r64452.

--
nosy: +facundobatista
resolution:  - fixed
status: open - closed

___
Python tracker [EMAIL PROTECTED]
http://bugs.python.org/issue2722
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue2732] curses.textpad loses characters at the end of lines

2008-06-22 Thread A.M. Kuchling

A.M. Kuchling [EMAIL PROTECTED] added the comment:

This bug was fixed in 2.5 and 2.6, in rev. 60118 and 60119.  Thanks for
your bug report!

--
assignee:  - akuchling
nosy: +akuchling
resolution:  - fixed
status: open - closed

___
Python tracker [EMAIL PROTECTED]
http://bugs.python.org/issue2732
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue3112] implement PEP 3134 exception reporting

2008-06-22 Thread Antoine Pitrou

Antoine Pitrou [EMAIL PROTECTED] added the comment:

Le dimanche 22 juin 2008 à 07:04 +, Adam Olsen a écrit :
 Adam Olsen [EMAIL PROTECTED] added the comment:
 
 * cause/context cycles should be avoided.  Naive traceback printing
 could become confused, and I can't think of any accidental way to
 provoke it (besides the problem mentioned here.)

You mean they should be detected when the exception is set? I was afraid
that it may make exception raising slower. Reporting is not performance
sensitive in comparison to exception raising.

(the problem mentioned here is already avoided in the patch, but the
detection of other cycles is deferred to exception reporting for the
reason given above)

 * PyErr_Display is used by PyErr_Print, and it must end up with no
 active exception.  Additionally, third party code may depend on this
 semantic.  Maybe PyErr_DisplayEx?

I was not proposing to change the exception swallowing semantics, just
to add a return value indicating if any errors had occurred while
displaying the exception.

___
Python tracker [EMAIL PROTECTED]
http://bugs.python.org/issue3112
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue3165] cPickle recursion problem

2008-06-22 Thread Facundo Batista

Facundo Batista [EMAIL PROTECTED] added the comment:

What is this fixing? Could you please provide a test cases that fails
without this patch?

Thank you!!

--
nosy: +facundobatista

___
Python tracker [EMAIL PROTECTED]
http://bugs.python.org/issue3165
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue1974] email.MIMEText.MIMEText.as_string incorrectly folding long subject header

2008-06-22 Thread Chris Withers

Chris Withers [EMAIL PROTECTED] added the comment:

Andi, I'm in total agreement with you :-)
(so if this bug could get fixed, both issues could get closed)

___
Python tracker [EMAIL PROTECTED]
http://bugs.python.org/issue1974
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue3112] implement PEP 3134 exception reporting

2008-06-22 Thread Adam Olsen

Adam Olsen [EMAIL PROTECTED] added the comment:

On Sun, Jun 22, 2008 at 8:07 AM, Antoine Pitrou [EMAIL PROTECTED] wrote:
 You mean they should be detected when the exception is set? I was afraid
 that it may make exception raising slower. Reporting is not performance
 sensitive in comparison to exception raising.

 (the problem mentioned here is already avoided in the patch, but the
 detection of other cycles is deferred to exception reporting for the
 reason given above)

I meant only that trivial cycles should be detected.  However, I
hadn't read your patch, so I didn't realize you already knew of a way
to create a non-trivial cycle.

This has placed a niggling doubt in my mind about chaining the
exceptions, rather than the tracebacks.  Hrm.

 * PyErr_Display is used by PyErr_Print, and it must end up with no
 active exception.  Additionally, third party code may depend on this
 semantic.  Maybe PyErr_DisplayEx?

 I was not proposing to change the exception swallowing semantics, just
 to add a return value indicating if any errors had occurred while
 displaying the exception.

Ahh, harmless then, but to what benefit?  Wouldn't the traceback
module be better suited to any possible error reporting?

___
Python tracker [EMAIL PROTECTED]
http://bugs.python.org/issue3112
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue3085] chapter 17.1.3.5 'Replacing os.popen*' in the Python library reference contains an error

2008-06-22 Thread Georg Brandl

Georg Brandl [EMAIL PROTECTED] added the comment:

Fixed in r64461. Thanks!

--
resolution:  - fixed

___
Python tracker [EMAIL PROTECTED]
http://bugs.python.org/issue3085
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue3157] sqlite3 minor documentation issues

2008-06-22 Thread Georg Brandl

Georg Brandl [EMAIL PROTECTED] added the comment:

I fixed the docstring in r64463 (2.5 branch, already fixed in trunk) and
expanded the connect() docstring in r64464.

--
resolution:  - fixed
status: open - closed

___
Python tracker [EMAIL PROTECTED]
http://bugs.python.org/issue3157
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue3085] chapter 17.1.3.5 'Replacing os.popen*' in the Python library reference contains an error

2008-06-22 Thread Manuel Kaufmann

Manuel Kaufmann [EMAIL PROTECTED] added the comment:

This bug was reported on Python 2.5 version and was applied on 2.6 
branch. That's correct?

___
Python tracker [EMAIL PROTECTED]
http://bugs.python.org/issue3085
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue3146] Sphinx/LaTeX fails on Python 3.0b1 documentation

2008-06-22 Thread Georg Brandl

Georg Brandl [EMAIL PROTECTED] added the comment:

Thanks, should be fixed with Sphinx r64465.

--
resolution:  - fixed
status: open - closed

___
Python tracker [EMAIL PROTECTED]
http://bugs.python.org/issue3146
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue3085] chapter 17.1.3.5 'Replacing os.popen*' in the Python library reference contains an error

2008-06-22 Thread Georg Brandl

Georg Brandl [EMAIL PROTECTED] added the comment:

I don't maintain the 2.5 docs anymore, at least for such minor bugs.

___
Python tracker [EMAIL PROTECTED]
http://bugs.python.org/issue3085
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue3112] implement PEP 3134 exception reporting

2008-06-22 Thread Adam Olsen

Adam Olsen [EMAIL PROTECTED] added the comment:

On Sun, Jun 22, 2008 at 1:04 PM, Antoine Pitrou [EMAIL PROTECTED] wrote:

 Antoine Pitrou [EMAIL PROTECTED] added the comment:

 Le dimanche 22 juin 2008 à 17:17 +, Adam Olsen a écrit :
 I meant only that trivial cycles should be detected.  However, I
 hadn't read your patch, so I didn't realize you already knew of a way
 to create a non-trivial cycle.

 This has placed a niggling doubt in my mind about chaining the
 exceptions, rather than the tracebacks.  Hrm.

 Chaining the tracebacks rather than the exceptions loses important
 information: what is the nature of the exception which is the cause or
 context of the current exception?

I assumed each leg of the traceback would reference the relevant exception.

Although.. this is effectively the same as creating a new exception
instance when reraised, rather than modifying the old one.  Reusing
the old is done for performance I believe.

 It is improbable to create such a cycle involuntarily, it means you
 raise an old exception in replacement of a newer one caused by the
 older, which I think is quite contorted. It is also quite easy to avoid
 creating the cycle, simply by re-raising outside of any except handler.

I'm not convinced.

try:
...  # Lookup
except A as a:  # Lookup failed
try:
...  # Fallback
except B as b:  # Fallback failed
raise a  # The original exception is of the type we want

For this behaviour, this is the most natural way to write it.
Conceptually, there shouldn't be a cycle - the traceback should be the
lookup, then the fallback, then whatever code is about this - exactly
the order the code executed in.

___
Python tracker [EMAIL PROTECTED]
http://bugs.python.org/issue3112
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue1523853] 2.4.2 file.read caches EOF state

2008-06-22 Thread Facundo Batista

Facundo Batista [EMAIL PROTECTED] added the comment:

In Linux, it seems to be the behaviour of the underlying C function 'fread'.

Do you think it's ok to add the following line in the read() documentation?


As this function depends of the underlying C function :cfunc:`fread`,
inheritates its behaviour in details like caching EOF and others.


Assigning this to George, to reword that in nicer English and apply.

Regards,

--
assignee:  - georg.brandl
nosy: +facundobatista, georg.brandl

___
Python tracker [EMAIL PROTECTED]
http://bugs.python.org/issue1523853
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue3112] implement PEP 3134 exception reporting

2008-06-22 Thread Antoine Pitrou

Antoine Pitrou [EMAIL PROTECTED] added the comment:

Le dimanche 22 juin 2008 à 19:23 +, Adam Olsen a écrit :
 For this behaviour, this is the most natural way to write it.
 Conceptually, there shouldn't be a cycle

I agree your example is not far-fetched. How about avoiding cycles for
implicit chaining, and letting users shoot themselves in the foot with
explicit recursive chaining if they want? Detection would be cheap
enough, just a simple loop without any memory allocation.

 the traceback should be the
 lookup, then the fallback, then whatever code is about this - exactly
 the order the code executed in.

It would be the reverse: first the fallback, then the re-raised
exception. The last caught exception is always reported last, because
it's supposed to be the main or highest-level one.

___
Python tracker [EMAIL PROTECTED]
http://bugs.python.org/issue3112
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue3112] implement PEP 3134 exception reporting

2008-06-22 Thread Adam Olsen

Adam Olsen [EMAIL PROTECTED] added the comment:

On Sun, Jun 22, 2008 at 1:48 PM, Antoine Pitrou [EMAIL PROTECTED] wrote:

 Antoine Pitrou [EMAIL PROTECTED] added the comment:

 Le dimanche 22 juin 2008 à 19:23 +, Adam Olsen a écrit :
 For this behaviour, this is the most natural way to write it.
 Conceptually, there shouldn't be a cycle

 I agree your example is not far-fetched. How about avoiding cycles for
 implicit chaining, and letting users shoot themselves in the foot with
 explicit recursive chaining if they want? Detection would be cheap
 enough, just a simple loop without any memory allocation.

That's still O(n).  I'm not so easily convinced it's cheap enough.

And for that matter, I'm not convinced it's correct.  The inner
exception's context becomes clobbered when we modify the outer
exception's traceback.  The inner's context should reference the
traceback as it was at that point.

This would all be a lot easier if reraising always created a new
exception.  Can you think of a way to skip that only when we can be
sure its safe?  Maybe as simple as counting the references to it?

___
Python tracker [EMAIL PROTECTED]
http://bugs.python.org/issue3112
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue3112] implement PEP 3134 exception reporting

2008-06-22 Thread Antoine Pitrou

Antoine Pitrou [EMAIL PROTECTED] added the comment:

Le dimanche 22 juin 2008 à 19:57 +, Adam Olsen a écrit :
 That's still O(n).  I'm not so easily convinced it's cheap enough.

O(n) when n will almost never be greater than 5 (and very often equal to
1 or 2), and when the unit is the cost of a pointer dereference plus the
cost of a pointer comparison, still sounds cheap. We could bench it
anyway.

 And for that matter, I'm not convinced it's correct.  The inner
 exception's context becomes clobbered when we modify the outer
 exception's traceback.  The inner's context should reference the
 traceback as it was at that point.

Yes, I've just thought about that, it's a bit annoying... We have to
decide what is more annoying: that, or a reference cycle that can delay
deallocation of stuff attached to an exception (including local
variables attached to the tracebacks)?

(just a small note: it's exception objects that are chained, not
tracebacks... we never modify tracebacks at any point)

 This would all be a lot easier if reraising always created a new
 exception.

How do you duplicate an instance of an user-defined exception? Using an
equivalent of copy.deepcopy()? It will probably end up much more
expensive than the above-mentioned O(n) search.

 Can you think of a way to skip that only when we can be
 sure its safe?  Maybe as simple as counting the references to it?

I don't think so, the exception can be referenced in an unknown number
of local variables (themselves potentially referenced by tracebacks).

___
Python tracker [EMAIL PROTECTED]
http://bugs.python.org/issue3112
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue3112] implement PEP 3134 exception reporting

2008-06-22 Thread Adam Olsen

Adam Olsen [EMAIL PROTECTED] added the comment:

On Sun, Jun 22, 2008 at 2:20 PM, Antoine Pitrou [EMAIL PROTECTED] wrote:

 Antoine Pitrou [EMAIL PROTECTED] added the comment:

 Le dimanche 22 juin 2008 à 19:57 +, Adam Olsen a écrit :
 That's still O(n).  I'm not so easily convinced it's cheap enough.

 O(n) when n will almost never be greater than 5 (and very often equal to
 1 or 2), and when the unit is the cost of a pointer dereference plus the
 cost of a pointer comparison, still sounds cheap. We could bench it
 anyway.

Indeed.

 And for that matter, I'm not convinced it's correct.  The inner
 exception's context becomes clobbered when we modify the outer
 exception's traceback.  The inner's context should reference the
 traceback as it was at that point.

 Yes, I've just thought about that, it's a bit annoying... We have to
 decide what is more annoying: that, or a reference cycle that can delay
 deallocation of stuff attached to an exception (including local
 variables attached to the tracebacks)?

The cycle is only created by broken behaviour.  The more I think about
it, the more I want to fix it (by not reusing the exception).

 This would all be a lot easier if reraising always created a new
 exception.

 How do you duplicate an instance of an user-defined exception? Using an
 equivalent of copy.deepcopy()? It will probably end up much more
 expensive than the above-mentioned O(n) search.

Passing in e.args is probably sufficient.  All this would need to be
discussed on python-dev (or python-3000?) though.

 Can you think of a way to skip that only when we can be
 sure its safe?  Maybe as simple as counting the references to it?

 I don't think so, the exception can be referenced in an unknown number
 of local variables (themselves potentially referenced by tracebacks).

Can be, or will be?  Only the most common behaviour needs to be optimized.

___
Python tracker [EMAIL PROTECTED]
http://bugs.python.org/issue3112
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue3112] implement PEP 3134 exception reporting

2008-06-22 Thread Antoine Pitrou

Antoine Pitrou [EMAIL PROTECTED] added the comment:

Le dimanche 22 juin 2008 à 20:40 +, Adam Olsen a écrit :
  How do you duplicate an instance of an user-defined exception? Using
 an
  equivalent of copy.deepcopy()? It will probably end up much more
  expensive than the above-mentioned O(n) search.
 
 Passing in e.args is probably sufficient.

I think it's very optimistic :-) Some exception objects can hold dynamic
state which is simply not stored in the args tuple. See Twisted's
Failure objects for an extreme example:
http://twistedmatrix.com/trac/browser/trunk/twisted/python/failure.py

(yes, it is used an an exception: see raise self in the trap() method)

 Can be, or will be?  Only the most common behaviour needs to be optimized.

Well, the most common behaviour is a very short context chain, which
is already optimized by my reference-avoidance proposal...

___
Python tracker [EMAIL PROTECTED]
http://bugs.python.org/issue3112
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue1567948] poplib.py list interface

2008-06-22 Thread Facundo Batista

Facundo Batista [EMAIL PROTECTED] added the comment:

Hasan, are you still interested in this or wants to drop this request?
Passing almost two years without comments it's no good if you'll be the
package maintainer.

Thanks!

--
nosy: +facundobatista

___
Python tracker [EMAIL PROTECTED]
http://bugs.python.org/issue1567948
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue678464] Docs don't define sequence-ness very well

2008-06-22 Thread Facundo Batista

Facundo Batista [EMAIL PROTECTED] added the comment:

Skip, don't you think it's better to raise this kind of generic question
in the python-dev list?

This should probably lay down here for ever before a discussion raises
to decide this.

--
nosy: +facundobatista

___
Python tracker [EMAIL PROTECTED]
http://bugs.python.org/issue678464
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue701743] Reloading pseudo modules

2008-06-22 Thread Facundo Batista

Facundo Batista [EMAIL PROTECTED] added the comment:

Walter, the import mechanisms changed by a big rework from Brett Cannon
in the last months. 

Do you think still have a use case that should be fulfilled? Do you want
to update your patch?

Thank you!

--
nosy: +facundobatista

___
Python tracker [EMAIL PROTECTED]
http://bugs.python.org/issue701743
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue3051] heapq change breaking compatibility

2008-06-22 Thread Raymond Hettinger

Changes by Raymond Hettinger [EMAIL PROTECTED]:


--
status: open - closed

___
Python tracker [EMAIL PROTECTED]
http://bugs.python.org/issue3051
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue3069] Let set.union and set.intersection accept multiple arguments

2008-06-22 Thread Raymond Hettinger

Changes by Raymond Hettinger [EMAIL PROTECTED]:


--
status: open - closed

___
Python tracker [EMAIL PROTECTED]
http://bugs.python.org/issue3069
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



  1   2   >