pyspread 0.0.12a released

2009-11-22 Thread Martin Manns
Pyspread is getting close to the first Beta. This new release should
work with Windows as well as with Linux.


About
-

Pyspread is a cross-platform Python spreadsheet application. It is
based on and written in the programming language Python.

Instead of spreadsheet formulas, Python expressions are entered into
the spreadsheet cells. Each expression returns a Python object that can
be accessed from other cells. These objects can represent anything
including lists or matrices.

Pyspread runs on Linux, Windows and *nix platforms with GTK+ support. 
I have reports that it works with MacOS X as well.


Homepage


http://pyspread.sf.net


New features in 0.0.12a
---

* pys file support more secure
* ODF file support removed
* Left and right alignment to cell attributes added
* Custom grid  cell drawing on refresh added
* Save functionality for row and column size added
* Problem with update of cells that contain strings, lists solved
* Frozen cells toolbar update fixed
* Windows missing cell background bug removed



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

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


Python Ireland's Christmas meetup

2009-11-22 Thread Vicky Lee
Hi All,

When: Wed 9th Dec, 18:30
Where: Bull and Castle, Christchurch, D2

What:
- Food will be provided, please
RSVPhttps://spreadsheets.google.com/viewform?formkey=dDlHTk9WcGhpWFZPekFhdTRWb1EwakE6MAby
6th Dec so we can ensure that we have enough platters.
- Raffle with prizes thanks to O'Reilly and Apress. Proceeds will go to
Python Software Foundation

More detail -
http://www.python.ie/meetup/2009/python_ireland_christmas_meetup/

Cheers,

/// Vicky

~~
~~ http://irishbornchinese.com   ~~
~~   http://www.python.ie   ~~
~~
-- 
http://mail.python.org/mailman/listinfo/python-announce-list

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


yappi v0.3

2009-11-22 Thread k3xji
Hi,
yappi(yet another python profiler) is a Python Profiler with
multithreading support. This is the last beta version with some major
changes and bugfixes:

v0.3 Changes
-
[+] yappi did not compile out of box on VS2008. Fix the compile
issues. (Thanks to Kevin Watters)
[+] tidy up stat formatting code. that's previously messy.
[+] BUGFIX:application total time is calculated wrong.
[+] BUGFIX:change some int's to long long's to prevent simple integer
overflows.
[+] show profiler status.
[+] show memory usage of the yappi itself.
[+] show thread class name in the thread stats.
[+] make thread/profiler stats column separated.
[+] big endian support for core hash function.
[+] BUGFIX: CURRENTCTX macro can return NULL on rare occassions,
handle that.
[+] BUGFIX: Shows wrong thread class name as we call it in the
profile_thread.
[+] OPTIMIZATION:some hashtable enhancements are done.


For documentation and download see:
http://code.google.com/p/yappi/


--
twitter.com/sumercip
Sumer Cip
-- 
http://mail.python.org/mailman/listinfo/python-announce-list

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


Re: ANN: PyGUI Mailing List

2009-11-22 Thread Gregory Ewing

Terry Reedy wrote:
Having it mirrored to news.gmane,org, if you have not yet, like other 
python.org lists, would make it easier to follow or join. Perhaps it 
will happen automatically, I do not know.


I don't think it's automatic. I've submitted a request to
gmane to have it added and I'm waiting to see what happens.

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


Re: Imitating tail -f

2009-11-22 Thread Wolodja Wentland
On Sun, Nov 22, 2009 at 03:43 +0100, Ivan Voras wrote:
 I'm trying to simply imitate what tail -f does, i.e. read a file, wait
 until it's appended to and process the new data, but apparently I'm
 missing something.
[..]
 Any advice?

Have a look at [1], which mimics tail -f perfectly. It comes from a
talk by David Beazley on generators which you can find at [2] and
[3].

Enjoy!

[1] http://www.dabeaz.com/generators/follow.py
[2] http://www.dabeaz.com/generators-uk/
[3] http://www.dabeaz.com/coroutines/

-- 
  .''`. Wolodja Wentlandwentl...@cl.uni-heidelberg.de 
 : :'  :
 `. `'` 4096R/CAF14EFC 
   `-   081C B7CD FF04 2BA9 94EA  36B2 8B7F 7D30 CAF1 4EFC


signature.asc
Description: Digital signature
-- 
http://mail.python.org/mailman/listinfo/python-list


Sorting: too different times. Why?

2009-11-22 Thread n00m
Any comment:

class Vector:
def __init__(self, x, y):
self.x = x
self.y = y
def __cmp__(self, v):
if self.x  v.x and self.y  v.y:
return -1
return 0

def v_cmp(v1, v2):
if v1.x  v2.x and v1.y  v2.y:
return -1
return 0

from random import randint
from time import time

a = []
for i in range(20):
a += [Vector(randint(0, 50), randint(0, 50))]
b = a[:]
c = a[:]

print 'Sorting...'

t = time()
b.sort(cmp=v_cmp)
print time() - t

t = time()
c.sort()
print time() - t

print b == c



 = RESTART ==

Sorting...
0.906000137329
6.57799983025
True

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


Re: parallel class structures for AST-based objects

2009-11-22 Thread Diez B. Roggisch

Steve Howell schrieb:

On Nov 21, 4:07 pm, MRAB pyt...@mrabarnett.plus.com wrote:

I don't see the point of EvalNode and PrettyPrintNode. Why don't you
just give Integer, Sum and Product 'eval' and 'pprint' methods?


That's a good question, and it's the crux of my design dilemma.  If
ALL I ever wanted to to with Integer/Sum/Product was to eval() and
pprint(), then I would just add those methods to Integer, Sum, and
Product, and be done with it, as you suggest.  But what happens when
somebody wants to extend capability?  Should every future software
developer that wants to use Integer/Sum/Product extend those classes
to get work done?  What if they want to store additional state for
nodes?



What's usually done is to create visitors/matchers. Those traverse the 
AST, and either only visit, or return transformed versions of it (think 
e.g. algebraic optimization)


A visitor will roughly look like this:


class ASTVisitor(object):



   def visit(self, node):
   name = node.__class__.__name__.lower()
   if hasattr(self, visit_%s % name):
   getattr(self, visit_%s % name)(node)
   for child in node:
   self.visit(child)



You can of course chose another type of dispatch, using e.g. a generic 
method.


Then you create Visitors for specific tasks - pretty-printing, 
evaluation, rewriting. Those don't have the overhead of your current 
design with all those factory-mapping stuff, and yet you aren't forced 
to put logic into AST you don't want there.



Diez

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


Re: How do I create a vanilla object in C?

2009-11-22 Thread sturlamolden
On 22 Nov, 04:05, Carl Banks pavlovevide...@gmail.com wrote:

 name = PyString_FromString(vanilla);
 bases = PyTuple_New(0);
 dict = PyDict_New();
 vanilla_type = PyObject_CallObject(
         PyType_Type,name,bases,dict,0);

 Then call the vanilla type (however you create it) to get a vanilla
 object:

 vanilla_object = PyObject_CallObject(vanilla_type,0);

 Definitely not the most straightforward thing to do from C.


It is much easier to do this from Cython.

cdef class foo:
# fields stored in C struct
pass

class foo:
# fields stored in Python dict
pass

The let the Cython compiler generate the C code you need.

http://docs.cython.org/src/tutorial/cdef_classes.html


















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


Re: Writing a Carriage Return in Unicode

2009-11-22 Thread Steve Howell
On Nov 21, 11:33 pm, Gregory Ewing greg.ew...@canterbury.ac.nz
wrote:
 Steve Howell wrote:
  If you are
  going to couple character sets to their legacy physical
  implementations, you should also have a special extra character to dot
  your i's and cross your t's.

 No, no, no. For that device you need to output a series
 of motion vectors for the scribing point. Plus control
 characters for dip nib and apply blotter, and
 possibly also pluck goose for when the print head
 becomes worn.


Greg, at the first reading of your response, it sounded overly
complicated for me to have to dip nib and  pluck goose every time
I just want to semantically indicate the ninth letter of the English
alphabet, but that's easily solved with a wizard interface, I guess.
Maybe every time I am trying to decide which letter to type in Word,
there could be some kind of animated persona that helps me choose the
character.  There could be a visual icon of an eye that reminds me
of the letter that I am trying to type, and I could configure the
depth to which I dib the nib with some kind of slider interface.  It
actually sounds quite simple and elegant, the more that I think about
it.

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


yappi v0.3

2009-11-22 Thread k3xji
Hi,
yappi(yet another python profiler) is a Python Profiler with
multithreading support. This is the last beta version with some major
changes and bugfixes:

v0.3 Changes
-
[+] yappi did not compile out of box on VS2008. Fix the compile
issues. (Thanks to Kevin Watters)
[+] tidy up stat formatting code. that's previously messy.
[+] BUGFIX:application total time is calculated wrong.
[+] BUGFIX:change some int's to long long's to prevent simple integer
overflows.
[+] show profiler status.
[+] show memory usage of the yappi itself.
[+] show thread class name in the thread stats.
[+] make thread/profiler stats column separated.
[+] big endian support for core hash function.
[+] BUGFIX: CURRENTCTX macro can return NULL on rare occassions,
handle that.
[+] BUGFIX: Shows wrong thread class name as we call it in the
profile_thread.
[+] OPTIMIZATION:some hashtable enhancements are done.


For documentation and download see:
http://code.google.com/p/yappi/


--
twitter.com/sumercip
Sumer Cip
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Sorting: too different times. Why?

2009-11-22 Thread Ben Finney
n00m n...@narod.ru writes:

 Any comment:

I get similar output. What were you expecting to happen? Did you have
any questions?

-- 
 \“The right to search for truth implies also a duty; one must |
  `\  not conceal any part of what one has recognized to be true.” |
_o__) —Albert Einstein |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Sorting: too different times. Why?

2009-11-22 Thread n00m

I was expecting the 1st method would be *slower* than the 2nd one :-)
Or at least equal... Just random (intuitive) expectations
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Sorting: too different times. Why?

2009-11-22 Thread Steven D'Aprano
In the subject line, you write too different times. You actually want 
two, the number, not too as in too many, too much. Lots of native 
English speakers get this wrong too :)

On Sun, 22 Nov 2009 01:21:42 -0800, n00m wrote:

 Any comment:
 
 class Vector:
 def __init__(self, x, y):
 self.x = x
 self.y = y
 def __cmp__(self, v):
 if self.x  v.x and self.y  v.y:
 return -1
 return 0


Modern versions of Python (since 2.2 I think?) use __lt__ or __gt__ for 
sorting. If the class doesn't have a __lt__ method, Python falls back on 
__cmp__.

 b.sort(cmp=v_cmp)

This is relatively fast, because you pass a comparison function directly, 
so Python doesn't need to look for a __lt__ method then fall back to 
__cmp__. It just uses v_cmp, every time.


 c.sort()

This is slower, because every comparison looks up the __lt__ and fails, 
then tries the __cmp__.

If you change the definition of Vector to include rich comparison methods 
as detailed here:

http://docs.python.org/reference/datamodel.html#object.__lt__

sorting will probably be significantly faster still.



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


Re: Sorting: too different times. Why?

2009-11-22 Thread Chris Rebert
On Sun, Nov 22, 2009 at 2:56 AM, n00m n...@narod.ru wrote:
 I was expecting the 1st method would be *slower* than the 2nd one :-)
 Or at least equal... Just random (intuitive) expectations

The second method repeatedly looks up left_item.__class__.__cmp__
(i.e. Vector.__cmp__) when doing the necessary comparisons between the
list items; while these lookups are optimized and are fast, they are
not free and cannot be skipped because Python doesn't know the list
contains only Vectors.
The first method uses the single provided comparison function and thus
does no such lookups; hence, it's faster.

That's my guess anyway.

Cheers,
Chris
--
http://blog.rebertia.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Sorting: too different times. Why?

2009-11-22 Thread Diez B. Roggisch

n00m schrieb:

Any comment:

class Vector:
def __init__(self, x, y):
self.x = x
self.y = y
def __cmp__(self, v):
if self.x  v.x and self.y  v.y:
return -1
return 0

def v_cmp(v1, v2):
if v1.x  v2.x and v1.y  v2.y:
return -1
return 0

from random import randint
from time import time

a = []
for i in range(20):


Use xrange instead (unless you are under python3), because for loops you 
don't need the full list range creates - xrange is just a generator.



a += [Vector(randint(0, 50), randint(0, 50))]


Better use .append here, looks nicer and should also be a bit faster.


b = a[:]
c = a[:]

print 'Sorting...'

t = time()
b.sort(cmp=v_cmp)
print time() - t

t = time()
c.sort()
print time() - t

print b == c




= RESTART ==


Sorting...
0.906000137329
6.57799983025


I think the main reason is that method-dispatch is more expensive than 
function-dispatch. The former must create a bound method before calling, 
the latter just works out of the box.


Things get better if you do this:

t = time()
c.sort(cmp=Vector.__cmp__)
print time() - t


Although not the exact same performance - I get

Sorting...
0.677843093872
1.4283311367
True

Diez

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


Re: Sorting: too different times. Why?

2009-11-22 Thread Duncan Booth
n00m n...@narod.ru wrote:

 Any comment:
 
 class Vector:
 def __init__(self, x, y):
 self.x = x
 self.y = y
 def __cmp__(self, v):
 if self.x  v.x and self.y  v.y:
 return -1
 return 0
 
 def v_cmp(v1, v2):
 if v1.x  v2.x and v1.y  v2.y:
 return -1
 return 0

What's that comparison function supposed to be doing?

 print Vector(1, 1)  Vector(2, 0)
True
 print Vector(2, 0) == Vector(1, 1)
True

If you use a broken comparison function then you must expect strange 
results, and your list of vectors isn't going to end up in any particular 
order (try adding c.reverse() before the call to c.sort() and the two 
'sorted' lists won't match any more).

In this case though the time difference may simply be down to creating in 
excess of 1 million bound methods.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Sorting: too different times. Why?

2009-11-22 Thread Mark Dickinson
On Nov 22, 9:21 am, n00m n...@narod.ru wrote:
 Any comment:

 class Vector:
     def __init__(self, x, y):
         self.x = x
         self.y = y
     def __cmp__(self, v):
         if self.x  v.x and self.y  v.y:
             return -1
         return 0

 def v_cmp(v1, v2):
     if v1.x  v2.x and v1.y  v2.y:
         return -1
     return 0

 from random import randint
 from time import time

 a = []
 for i in range(20):
     a += [Vector(randint(0, 50), randint(0, 50))]
 b = a[:]
 c = a[:]

 print 'Sorting...'

 t = time()
 b.sort(cmp=v_cmp)
 print time() - t

 t = time()
 c.sort()
 print time() - t

 print b == c

  = RESTART ==

 Sorting...
 0.906000137329
 6.57799983025
 True

Do you get the same magnitude difference if you make Vector a new-
style
class?  (I.e., use class Vector(object) instead of class Vector
().)

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


Why Python allows comparison of a callable and a number?

2009-11-22 Thread 一首诗
I used python to write an assignment last week, here is a code snippet

#

def departTime():
'''
Calculate the time to depart a packet.
'''
if(random.random  0.8):
t = random.expovariate(1.0 / 2.5)
else:
t = random.expovariate(1.0 / 10.5)
return t

#

Can you see the problem?  I compare random.random with 0.8,  which
should be random.random().

Of course this because of my careless, but I don't get it.  In my
opinion, this kind of comparison should invoke a least a warning in
any programming language.

So why does python just ignore it?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Why Python allows comparison of a callable and a number?

2009-11-22 Thread Chris Rebert
On Sun, Nov 22, 2009 at 4:03 AM, 一首诗 newpt...@gmail.com wrote:
 I used python to write an assignment last week, here is a code snippet

 #

 def departTime():
    '''
    Calculate the time to depart a packet.
    '''
    if(random.random  0.8):
        t = random.expovariate(1.0 / 2.5)
    else:
        t = random.expovariate(1.0 / 10.5)
    return t

 #

 Can you see the problem?  I compare random.random with 0.8,  which
 should be random.random().

 Of course this because of my careless, but I don't get it.  In my
 opinion, this kind of comparison should invoke a least a warning in
 any programming language.

 So why does python just ignore it?

It's an historical anomaly that's been rectified in Python 3, where
such non-equality comparisons between unrelated types *do* now raise
an error.

Cheers,
Chris
--
http://blog.rebertia.com
-- 
http://mail.python.org/mailman/listinfo/python-list


No-syntax Web-programming-IDE (was: Does turtle graphics have the wrong associations?)

2009-11-22 Thread Robert Maas, http://tinyurl.com/uh3t
  My proposed no-syntax
  IDE *also* gets rid of the need to bother with any programming-language
  syntax. I've been proposing it for years, but nobody has shown any
  interest
 From: Terry Reedy tjre...@udel.edu
 What you describe below is similar to various systems that have
 been proposed and even implemented, including visual programming
 systems.

Are any of them integrated with tutorial material and available
over the Web, as mine will be? If so, will you tell me the URLs so
that I can play with them?

 And there has been some success with non-programmers.

The purpose of *my* system will be to start with mostly
non-programmers and *teach* them algorithm design from examples of
tasks they get paid (labor-credits, not $money$) to perform,
without needing to simultaneously bother them with
programming-language syntax. They learn how to take one step at a
time towards a long journey (Chinese proverb) without needing to
first learn a language for stating with ultra-precision *how*
exactly to take each one step. Thus they learn algorithm design
with maximal efficiency, because nearly their whole attention is on
*that* without distraction of syntax too.

 But for most people, it is simply easier to say/write what one
 means rather than point and click.

That works only after you already know to say/write what you mean
for the computer *precisely*exactly*analRetentively* what you want
the computer to do. If you don't already know *how* to say
precisely what you mean for the computer to do, it's impossible.
For example, show somebody this data:
   [12 15 19 26 43 62 92 71 78 85 93]
Point to this item ...^^
Ask that person, who has *never* even seen a computer program much
less written one him/herself, and also who has never studied formal
mathematics such as set theory, and ask that person to say in
precise terms how a computer should find that indicated item among
the data. Look at the data. You see what's special about that one
item among the data, right? So how to express to a computer how to
find it? Answer: It's the item that's out-of-sequence relative to
its neighbors.

How many non-computer non-math beginners would even notice what's
special about that item? (my guess: about half)

How many would be able to express either the mathematical
definition of the desired result, or an algorithm for finding it,
clearly enough that even a human seeing the expression but *not*
seeing the sample would be able to write a computer program per
that spec to solve the problem? (my guess: less than 1%)

Example of a valid informal mathematical expression: There's a
sequence of numbers. Mostly they are in correct sequence. But
exactly one of them is in the wrong place relative to the others
around it. Find that one that's out of place.

Example of a valid semi-formal mathematical expression:
Given an index set [0..N], and a function F from that index set
into the integers;
Such that the predicate lambda (i) F(i-1)  F(i)  F(i+1)
is true for all but one member of the interval [1..N-1];
Find the element of [1..N-1] for which the predicate is not true.

Formal mathematical expression depends on the notation conventions,
so I won't bother to even attempt to concoct such here for example.

Computer algorithms are several in overall algorithm, depending on
which primitives are available from declarative or imperative
programming, from functional or prodedural etc. programming, and
within each choice of *that*, the actual syntax can be any of
several per programming language such as Lisp or APL or Forth etc.
(Yeah, I deliberately avoided mentionning C or Fortran or Java etc.)

If my guess is correct that less than 1% of absolute beginners can
even state what is desired, so that a human can understand it
unambiguously, much less how to obtain it, likewise, expecting that
such an absolute beginner would simply say/write what one means
is IMO unreasonable.

Hence my idea is a sort of friendly wizard to take as much of a
crude ambiguous statment as the student is capable of and willing
to key in, use that to narrow and/or prioritize the number of
possible data-processing steps that are reasonably possible given
the data we have to work from, and then show the prioritized
options to the student, clearly expressed moderately verbosely, and
let the student either pick one of them or clarify what had been
keyed in just before. At the start, before the student has
said *anything* about what the next D/P step will be, *all*
possible operations on existing data are available, organized in
some meaningful way that would support a fully menu-driven method
as you presume. But a hybrid of vague statement what to do (such as
my first answer above which said nothing about there being any
sequence or that the numbers were ascending except for that one out
of place) and limited set of known options available a priori,
would be available whenever the student *can* at least partially
express what to do with the data.

Now in the example given 

Re: Imitating tail -f

2009-11-22 Thread Paul Rudin
Matt Nordhoff mnordh...@mattnordhoff.com writes:

 Jason Sewall wrote:
 FWIW, GNU tail on Linux uses inotify for tail -f:
 
 http://git.savannah.gnu.org/cgit/coreutils.git/tree/src/tail.c
 
 The wikipedia page for inotify lists several python bindings:
 
 http://en.wikipedia.org/wiki/Inotify
 
 Not much help for non-Linux users, but there it is. Too bad, because
 inotify is pretty cool.
 
 Jason

 Some other operating systems have similar facilities, e.g. FSEvents on OS X.

Yeah, and there's a similar kind of thing in the windows api.

A nice python project would be a cross-platform solution that presented
a uniform api and just did the right thing behind the scenes on each OS.

(Incidentally on linux you need to watch out for the value of
/proc/sys/fs/inotify/max_user_watches - if you're using inotify in anger
it's easy to exceed the default set by a lot of distributions.)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Sorting: too different times. Why?

2009-11-22 Thread Dave Angel

n00m wrote:

Any comment:

snip
def v_cmp(v1, v2):
if v1.x  v2.x and v1.y  v2.y:
return -1
return 0

  

The second part of the compound if is backwards.  So if this is headed 
for production code, it better get fixed.


DaveA

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


Re: plotting arrow in python

2009-11-22 Thread rudra
On Nov 22, 6:58 am, Gregory Ewing greg.ew...@canterbury.ac.nz wrote:
  rudra wrote:

  0.0 0.0 0.1
  0.0 0.1 0.1
  0.1 0.0 0.5

  like that! the first two column are coordinate and 3rd one is
  magnitude of moment (say: x y,m)!! so what i want to do is draw an
  arrow of magnitude(m) in the position (x,y).

 There seems to be some information missing there.
 How do you know what direction to draw the arrow in?

 --
 Greg

Greg,
you are right direction is also needed. But as a beginner, I am trying
to make it simple and all arrows are collinear along x axis!!
then i have to  try non collinear as well.
thank you
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Sorting: too different times. Why?

2009-11-22 Thread n00m
 Do you get the same magnitude difference
 if you make Vector a new-style class?

Yes (I mean No): new-style's much faster

And now it's elephants instead of vectors.
Def: an elephant is smarter than another one IIF
its size is strictly less but its IQ is strictly
greater

I.e. you can't compare (2, 8) to (20, 50)
or let count them as equally smart elephants.


class Elephant(object):
def __init__(self, size, iq):
self.size = size
self.iq = iq
def __cmp__(self, e):
if self.size  e.size and self.iq  e.iq:
return -1
if self.size  e.size and self.iq  e.iq:
return 1
return 0

def e_cmp(e1, e2):
if e1.size  e2.size and e1.iq  e2.iq:
return -1
if e1.size  e2.size and e1.iq  e2.iq:
return 1
return 0

from random import randint
from time import time

a = []
for i in xrange(20):
a.append(Elephant(randint(1, 5), randint(1, 5)))
b = a[:]
c = a[:]

print 'Sorting...'

t = time()
b.sort(cmp=e_cmp)
print time() - t

t = time()
c.sort()
print time() - t

print b == c



 = RESTART =

Sorting...
1.5626376
1.9536866
True
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Sorting: too different times. Why?

2009-11-22 Thread n00m

 The second part of the compound if is backwards.  So if this is headed
 for production code, it better get fixed.

 DaveA

Not sure I'm understanding your remark.
-- 
http://mail.python.org/mailman/listinfo/python-list


python regex negative lookahead assertions problems

2009-11-22 Thread Jelle Smet
Hi List,

I'm trying to match lines in python using the re module.
The end goal is to have a regex which enables me to skip lines which have ok 
and warning in it.
But for some reason I can't get negative lookaheads working, the way it's 
explained in http://docs.python.org/library/re.html;.

Consider this example:

Python 2.6.4 (r264:75706, Nov  2 2009, 14:38:03) 
[GCC 4.4.1] on linux2
Type help, copyright, credits or license for more information.
 import re
 line='2009-11-22 12:15:441  lmqkjsfmlqshvquhsudfhqf qlsfh qsduidfhqlsiufh 
 qlsiuf qldsfhqlsifhqlius dfh warning qlsfj lqshf lqsuhf lqksjfhqisudfh 
 qiusdfhq iusfh'
 re.match('.*(?!warning)',line)
_sre.SRE_Match object at 0xb75b1598

I would expect that this would NOT match as it's a negative lookahead and 
warning is in the string.


Thanks,


-- 
Jelle Smet
http://www.smetj.net
-- 
http://mail.python.org/mailman/listinfo/python-list


MySQLdb

2009-11-22 Thread Kill Joy
Hi all.

I have a mod_python script with two query:

cursor = db.cursor()

sql = 'SELECT * FROM users where username=\'' + username +'\''
cursor.execute(sql)
result = cursor.fetchall()
num =  int(cursor.rowcount)

if num == 0 :
sql2 = 'insert into users values (null, \'' + username + '\', 
\'' +
password +'\', \'no\',\'fdfdf\')'
cursor.execute(sql2)
warning = Registration ok
else :
warning = EXIST!

The first query is executed... but not the second. It doesn't insert.
Why?
I'm a newbie... sorry.

Many thanks.


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


pyspread 0.0.12a released

2009-11-22 Thread Martin Manns
Pyspread is getting close to the first Beta. This new release should
work with Windows as well as with Linux.


About
-

Pyspread is a cross-platform Python spreadsheet application. It is
based on and written in the programming language Python.

Instead of spreadsheet formulas, Python expressions are entered into
the spreadsheet cells. Each expression returns a Python object that can
be accessed from other cells. These objects can represent anything
including lists or matrices.

Pyspread runs on Linux, Windows and *nix platforms with GTK+ support. 
I have reports that it works with MacOS X as well.


Homepage


http://pyspread.sf.net


New features in 0.0.12a
---

* pys file support more secure
* ODF file support removed
* Left and right alignment to cell attributes added
* Custom grid  cell drawing on refresh added
* Save functionality for row and column size added
* Problem with update of cells that contain strings, lists solved
* Frozen cells toolbar update fixed
* Windows missing cell background bug removed



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


Re: python regex negative lookahead assertions problems

2009-11-22 Thread Tim Chase

import re
line='2009-11-22 12:15:441  lmqkjsfmlqshvquhsudfhqf qlsfh qsduidfhqlsiufh 
qlsiuf qldsfhqlsifhqlius dfh warning qlsfj lqshf lqsuhf lqksjfhqisudfh qiusdfhq 
iusfh'
re.match('.*(?!warning)',line)

_sre.SRE_Match object at 0xb75b1598

I would expect that this would NOT match as it's a negative lookahead and 
warning is in the string.


This first finds everything (.*) and then asserts that 
warning doesn't follow it, which is correct in your example. 
You may have to assert that warning doesn't exist at every 
point along the way:


  re.match(r'(?:(?!warning).)*',line)

which will match up-to-but-not-including the warning text.  If 
you don't want it at all, you'd have to also anchor the far end


  re.match(r'^(?:(?!warning).)*$',line)

but in the 2nd case I'd just as soon invert the test:

  if 'warning' not in line:
do_stuff()

-tkc




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


Re: MySQLdb

2009-11-22 Thread Gerald Walker
Kill Joy wrote:
 Hi all.
 
 I have a mod_python script with two query:
 
   cursor = db.cursor()
 
   sql = 'SELECT * FROM users where username=\'' + username +'\''
   cursor.execute(sql)
   result = cursor.fetchall()
   num =  int(cursor.rowcount)
 
   if num == 0 :
   sql2 = 'insert into users values (null, \'' + username + '\', 
 \'' +
 password +'\', \'no\',\'fdfdf\')'
   cursor.execute(sql2)
db.commit()
   warning = Registration ok

   else :
   warning = EXIST!
 
 The first query is executed... but not the second. It doesn't insert.
 Why?
 I'm a newbie... sorry.
 
 Many thanks.
 

I added db.commit() after cursor.execute(sql2).

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


Re: MySQLdb

2009-11-22 Thread Kill Joy
On 22 Nov, 16:00, Gerald Walker geraldwalk...@gmail.com wrote:
 Kill Joy wrote:
  Hi all.

  I have a mod_python script with two query:

     cursor = db.cursor()

     sql = 'SELECT * FROM users where username=\'' + username +'\''
     cursor.execute(sql)
     result = cursor.fetchall()
     num =  int(cursor.rowcount)

     if num == 0 :
             sql2 = 'insert into users values (null, \'' + username + '\', 
  \'' +
  password +'\', \'no\',\'fdfdf\')'
             cursor.execute(sql2)

                 db.commit()

             warning = Registration ok

     else :
             warning = EXIST!

  The first query is executed... but not the second. It doesn't insert.
  Why?
  I'm a newbie... sorry.

  Many thanks.

 I added db.commit() after cursor.execute(sql2).

ohhh... many thanks many thanks.

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


Re: python regex negative lookahead assertions problems

2009-11-22 Thread Helmut Jarausch

On 11/22/09 14:58, Jelle Smet wrote:

Hi List,

I'm trying to match lines in python using the re module.
The end goal is to have a regex which enables me to skip lines which have ok 
and warning in it.
But for some reason I can't get negative lookaheads working, the way it's explained in 
http://docs.python.org/library/re.html;.

Consider this example:

Python 2.6.4 (r264:75706, Nov  2 2009, 14:38:03)
[GCC 4.4.1] on linux2
Type help, copyright, credits or license for more information.

import re
line='2009-11-22 12:15:441  lmqkjsfmlqshvquhsudfhqf qlsfh qsduidfhqlsiufh 
qlsiuf qldsfhqlsifhqlius dfh warning qlsfj lqshf lqsuhf lqksjfhqisudfh qiusdfhq 
iusfh'
re.match('.*(?!warning)',line)

_sre.SRE_Match object at 0xb75b1598

I would expect that this would NOT match as it's a negative lookahead and 
warning is in the string.



'.*' eats all of line. Now, when at end of line, there is no 'warning' anymore, 
so it matches.
What are you trying to achieve?

If you just want to single out lines with 'ok' or warning in it, why not just
if re.search('(ok|warning)') : call_skip

Helmut.

--
Helmut Jarausch

Lehrstuhl fuer Numerische Mathematik
RWTH - Aachen University
D 52056 Aachen, Germany
--
http://mail.python.org/mailman/listinfo/python-list


Re: Sorting: too different times. Why?

2009-11-22 Thread Duncan Booth
n00m n...@narod.ru wrote:

 And now it's elephants instead of vectors.
 Def: an elephant is smarter than another one IIF
 its size is strictly less but its IQ is strictly
 greater
 
 I.e. you can't compare (2, 8) to (20, 50)
 or let count them as equally smart elephants.

and that still isn't a relationship where you can get any meaningful order 
out of sorting them:

 Elephant(1, 20)  Elephant(2, 10)
True
 Elephant(1, 20) == Elephant(2, 20) == Elephant(2, 10)
True
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: parallel class structures for AST-based objects

2009-11-22 Thread Simon Forman
On Sun, Nov 22, 2009 at 4:50 AM, Diez B. Roggisch de...@nospam.web.de wrote:
 Steve Howell schrieb:

 On Nov 21, 4:07 pm, MRAB pyt...@mrabarnett.plus.com wrote:

 I don't see the point of EvalNode and PrettyPrintNode. Why don't you
 just give Integer, Sum and Product 'eval' and 'pprint' methods?

 That's a good question, and it's the crux of my design dilemma.  If
 ALL I ever wanted to to with Integer/Sum/Product was to eval() and
 pprint(), then I would just add those methods to Integer, Sum, and
 Product, and be done with it, as you suggest.  But what happens when
 somebody wants to extend capability?  Should every future software
 developer that wants to use Integer/Sum/Product extend those classes
 to get work done?  What if they want to store additional state for
 nodes?


 What's usually done is to create visitors/matchers. Those traverse the AST,
 and either only visit, or return transformed versions of it (think e.g.
 algebraic optimization)

 A visitor will roughly look like this:


 class ASTVisitor(object):



   def visit(self, node):
       name = node.__class__.__name__.lower()
       if hasattr(self, visit_%s % name):
           getattr(self, visit_%s % name)(node)
       for child in node:
           self.visit(child)



 You can of course chose another type of dispatch, using e.g. a generic
 method.

 Then you create Visitors for specific tasks - pretty-printing, evaluation,
 rewriting. Those don't have the overhead of your current design with all
 those factory-mapping stuff, and yet you aren't forced to put logic into AST
 you don't want there.



FWIW I often use John Aycock's SPARK (Scanning, Parsing, and Rewriting
Kit) for this sort of thing.  It has a GenericASTTraversal which is a
Visitor pattern according to Design Patterns.

http://pages.cpsc.ucalgary.ca/~aycock/spark/

It's apparently distributed with the python source, but it's not in
the standard library, more's the pity IMO.

There's a bit of a learning curve but it's well worth it.

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


Re: Sorting: too different times. Why?

2009-11-22 Thread MRAB

Steven D'Aprano wrote:
In the subject line, you write too different times. You actually want 
two, the number, not too as in too many, too much. Lots of native 
English speakers get this wrong too :)



[snip]
It could mean that the times are not just different, they're _too_
different, ie a lot more than they are expected to be.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Why Python allows comparison of a callable and a number?

2009-11-22 Thread MRAB

一首诗 wrote:

I used python to write an assignment last week, here is a code snippet

#

def departTime():
'''
Calculate the time to depart a packet.
'''
if(random.random  0.8):
t = random.expovariate(1.0 / 2.5)
else:
t = random.expovariate(1.0 / 10.5)
return t

#

Can you see the problem?  I compare random.random with 0.8,  which
should be random.random().

Of course this because of my careless, but I don't get it.  In my
opinion, this kind of comparison should invoke a least a warning in
any programming language.

So why does python just ignore it?


In Python 2 you can compare any 2 objects, for example an int with a
string. The result is arbitrary but consistent.

In Python 3 if the 2 objects aren't 'compatible' you'll get a TypeError
at runtime.

BTW, you don't need to put parentheses around the conditions in 'if' and
'while' statements. Python isn't C, etc. :-)
--
http://mail.python.org/mailman/listinfo/python-list


Re: Sorting: too different times. Why?

2009-11-22 Thread n00m
Here meaningful order is:
if
elephant a[i] is smarter than elephant a[j]
then i must be strictly less than j

Of course, to the same effect we could sort them simply
by sizes, but then time of sorting would increase by ~
2 times -- due to decreasing of number of equally smart
things.

But here it does not matter -- for my initial question.
I like all above explanations. Especially that by Chris Rebert.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Sorting: too different times. Why?

2009-11-22 Thread n00m
:-) Of course, by too I meant too, as in to much
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python regex negative lookahead assertions problems

2009-11-22 Thread MRAB

Tim Chase wrote:

import re
line='2009-11-22 12:15:441  lmqkjsfmlqshvquhsudfhqf qlsfh 
qsduidfhqlsiufh qlsiuf qldsfhqlsifhqlius dfh warning qlsfj lqshf 
lqsuhf lqksjfhqisudfh qiusdfhq iusfh'

re.match('.*(?!warning)',line)

_sre.SRE_Match object at 0xb75b1598

I would expect that this would NOT match as it's a negative lookahead 
and warning is in the string.


This first finds everything (.*) and then asserts that warning 
doesn't follow it, which is correct in your example. You may have to 
assert that warning doesn't exist at every point along the way:


  re.match(r'(?:(?!warning).)*',line)

which will match up-to-but-not-including the warning text.  If you 
don't want it at all, you'd have to also anchor the far end


  re.match(r'^(?:(?!warning).)*$',line)

but in the 2nd case I'd just as soon invert the test:

  if 'warning' not in line:
do_stuff()


The trick is to think what positive lookahead you'd need if you wanted
check whether 'warning' is present:

'(?=.*warning)'

and then negate it:

'(?!.*warning)'

giving you:

re.match(r'(?!.*warning)', line)
--
http://mail.python.org/mailman/listinfo/python-list


Re: Sorting: too different times. Why?

2009-11-22 Thread MRAB

n00m wrote:

:-) Of course, by too I meant too, as in to much


Although it's OK in English to say too much x or too many x, it's
somewhat unnatural to say too different xs; it would have to be the
xs are too different. Nobody said English was logical! :-)
--
http://mail.python.org/mailman/listinfo/python-list


Re: Sorting: too different times. Why?

2009-11-22 Thread n00m
 it's somewhat unnatural to say too different xs

Aha. Thanks.
PS
For years I thought that song's title No Woman No Cry by Bob Marley
means No Woman -- No Cry. As if a man got rid of his woman and
stopped
crying, out of her bad behaviour etc.
It turned out to mean No, woman,.. no cry...

Or take Drips by Eminem. What on earth do the drips mean?

Album:  The Eminem Show
Song:   Drips

[Eminem] Obie.. yo
 [Trice] {*coughing*} I'm sick
[Eminem] Damn, you straight dog?

[Chorus]
That's why I ain't got no time
for these games and stupid tricks
or these bitches on my dick
That's how dudes be gettin sick
That's how dicks be gettin drips
Fallin victims to this shit...
...
...
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: parallel class structures for AST-based objects

2009-11-22 Thread Steve Howell
On Nov 22, 7:55 am, Simon Forman sajmik...@gmail.com wrote:
 On Sun, Nov 22, 2009 at 4:50 AM, Diez B. Roggisch de...@nospam.web.de wrote:



  Steve Howell schrieb:

  On Nov 21, 4:07 pm, MRAB pyt...@mrabarnett.plus.com wrote:

  I don't see the point of EvalNode and PrettyPrintNode. Why don't you
  just give Integer, Sum and Product 'eval' and 'pprint' methods?

  That's a good question, and it's the crux of my design dilemma.  If
  ALL I ever wanted to to with Integer/Sum/Product was to eval() and
  pprint(), then I would just add those methods to Integer, Sum, and
  Product, and be done with it, as you suggest.  But what happens when
  somebody wants to extend capability?  Should every future software
  developer that wants to use Integer/Sum/Product extend those classes
  to get work done?  What if they want to store additional state for
  nodes?

  What's usually done is to create visitors/matchers. Those traverse the AST,
  and either only visit, or return transformed versions of it (think e.g.
  algebraic optimization)

  A visitor will roughly look like this:

  class ASTVisitor(object):

    def visit(self, node):
        name = node.__class__.__name__.lower()
        if hasattr(self, visit_%s % name):
            getattr(self, visit_%s % name)(node)
        for child in node:
            self.visit(child)

  You can of course chose another type of dispatch, using e.g. a generic
  method.

  Then you create Visitors for specific tasks - pretty-printing, evaluation,
  rewriting. Those don't have the overhead of your current design with all
  those factory-mapping stuff, and yet you aren't forced to put logic into AST
  you don't want there.

 FWIW I often use John Aycock's SPARK (Scanning, Parsing, and Rewriting
 Kit) for this sort of thing.  It has a GenericASTTraversal which is a
 Visitor pattern according to Design Patterns.

 http://pages.cpsc.ucalgary.ca/~aycock/spark/

 It's apparently distributed with the python source, but it's not in
 the standard library, more's the pity IMO.

 There's a bit of a learning curve but it's well worth it.


Thanks, Simon, I think something like GenericASTTraversal should work
for me in most cases.

A couple of folks have suggested an idea that is in his paper, which
is to use a single class for something PrettyPrinter, and then use
reflection to find methods on PrettyPrinter to pretty-print sums,
products, integers, etc.


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


scanning under windows WIA with custom settings (dpi / etc )

2009-11-22 Thread News123
Hi,

I'm trying to scan a document from a python 2.6 script without user
interaction.

I found  a code snippet, that allows me to scan under Vista, but that
doesn't allow me to select the dpi / color mode / etc.

The snippet uses win32com.client

# # script start
import win32com.client,os

WIA_IMG_FORMAT_PNG   = {B96B3CAF-0728-11D3-9D7B-F81EF32E}
WIA_COMMAND_TAKE_PICTURE = {AF933CAC-ACAD-11D2-A093-00C04F72DC3C}

os.chdir('c:/temp')
wia = win32com.client.Dispatch(WIA.CommonDialog)
dev = wia.ShowSelectDevice()
for command in dev.Commands:
if command.CommandID==WIA_COMMAND_TAKE_PICTURE:
foo=dev.ExecuteCommand(WIA_COMMAND_TAKE_PICTURE)
i=1
for item in dev.Items:
if i==dev.Items.Count:
image=item.Transfer(WIA_IMG_FORMAT_PNG)
break
i=i+1

image.SaveFile(test.png)
# script end


My problems are:

- This script works fine for me under Windows 7, however I'm
  unable to   specify additional parameters, like dpi and
  color mode.

- The script doesn't work under windows XP, though the scanner driver is
installed. (Gimp finds the scanner (as WIA scanner)).
Perhaps 'WIA.CommonDialig' has another name or I need to install some DLL.
The error message is:

Traceback (most recent call last):
  File C:\work\python\minidemos\wia_get_simple.py, line 7, in module
wia = win32com.client.Dispatch(WIA.CommonDialog)
  File C:\Python26\lib\site-packages\win32com\client\__init__.py, line
95, in Dispatch
dispatch, userName =
dynamic._GetGoodDispatchAndUserName(dispatch,userName,clsctx)
  File C:\Python26\lib\site-packages\win32com\client\dynamic.py, line
104, in _GetGoodDispatchAndUserName
return (_GetGoodDispatch(IDispatch, clsctx), userName)
  File C:\Python26\lib\site-packages\win32com\client\dynamic.py, line
84, in _GetGoodDispatch
IDispatch = pythoncom.CoCreateInstance(IDispatch, None, clsctx,
pythoncom.IID_IDispatch)
com_error: (-2147221005, 'Invalid class string', None, None)
-


As I have no knowledge of Win32com and WIA I would appreciate some help
or good documentation about wincom32 / WIA with python



thanks for your help and bye


N






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


Scripts Only Run In Root

2009-11-22 Thread Victor Subervi
Hi;
I can only run my python scripts on my server if they are owned by root. How
do I change that?
TIA,
Victor
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Sorting: too different times. Why?

2009-11-22 Thread Lie Ryan

n00m wrote:

The second part of the compound if is backwards.  So if this is headed
for production code, it better get fixed.

DaveA


Not sure I'm understanding your remark.


Maybe he meant, that this:
if v1.x  v2.x and v1.y  v2.y
should be:
if v1.x  v2.x and v1.y  v2.y
?
--
http://mail.python.org/mailman/listinfo/python-list


TypeError: an integer is required

2009-11-22 Thread Lutfi Oduncuoglu
Hello,

I am a newbie on oython and I am taking the error at subject my code is
below, I am trying to develop a qgis plugin and lines begin with # is the
thing that I tried. Thus sys.stdout gives the type error. When I comment
that line it turns an error like below. What may be the problem? thanks for
help:)

...\ReadData.py, line 128, in run
print %d %s %(k, attr.toString())
IOError: [Errno 9] Bad file descriptor




# Import the PyQt and QGIS libraries
from PyQt4 import QtCore, QtGui

from PyQt4.QtCore import *
from PyQt4.QtGui import *
from qgis.core import *
from os import *
from qgis.gui import *
import sys
import pdb
# Initialize Qt resources from file resources.py
import resources
# Import the code for the dialog
from ReadDataDialog import ReadDataDialog

class ReadData:

  def __init__(self, iface):
# Save reference to the QGIS interface
self.iface = iface

  def initGui(self):
# Create action that will start plugin configuration
self.action = QAction(QIcon(:/plugins/readdata/icon.png), \
Read shp for calculations, self.iface.mainWindow())
# connect the action to the run method
QObject.connect(self.action, SIGNAL(triggered()), self.run)

# Add toolbar button and menu item
self.iface.addToolBarIcon(self.action)
self.iface.addPluginToMenu(Read shp for calculations, self.action)

  def unload(self):
# Remove the plugin menu item and icon
self.iface.removePluginMenu(Read shp for calculations,self.action)
self.iface.removeToolBarIcon(self.action)

  # run method that performs all the real work
  def run(self):

#fileName =
QFileDialog.getOpenFileName(None,QString.fromLocal8Bit(Select a file:),,
*.shp *.gml)

#if fileName.isNull():

#  QMessageBox.information(None, Cancel, File selection canceled)




#else:

#  print fileName


vlayer =
QgsVectorLayer(C:\\Users\\lutfi\\Documents\\te\\deneme2\\ownership.shp,
hebe, ogr)
print vlayer.source()
print vlayer.featureCount()
QgsMapLayerRegistry.instance().addMapLayer(vlayer)
QMessageBox.information(self.iface.mainWindow(), info, file:
+str(vlayer.source())+ is added.)





if not vlayer.isValid():
  print Couldn't open the layer
  pdb.set_trace()

else:

#QMessageBox.information(None, Cancel, File selection canceled)

  provider = vlayer.dataProvider()
  feat = QgsFeature()
  allAttrs = provider.attributeIndexes()
  provider.select(allAttrs)

  while provider.nextFeature(feat):
geom = feat.geometry()
import sys
import os
#
win32api.SetFileAttributes('C://Users//lutfi//Documents//te//log.txt',
win32con.FILE_ATTRIBUTE_NORMAL)
#sys.stdout = open('C://Users//lutfi//Documents//te//log.txt',
777 )
print geom
#QMessageBox.information(None, Cancel, File selection canceled)
print Feature ID %d:  % feat.id()
if geom.type() == QGis.Point:
  x = geom.asPoint()
  print Point:  + str(x)

elif geom.type() == QGis.Line:
  x = geom.asPolyline()
  print Line: %d points % len(x)

elif geom.type() == QGis.Polygon:
  x = geom.asPolygon()
  numPts = 0
  for ring in x:
numPts += len(ring)
print Polygon: %d rings with %d points % (len(x), numPts)
else:
  print Unknown

attrs = feat.attributeMap()

for (k,attr) in attrs.iteritems():
  sys.stdout =
os.open(C://Users//lutfi//Documents//te//log.txt , a )
  print %d %s %(k, attr.toString())
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Sorting: too different times. Why?

2009-11-22 Thread Dave Angel

n00m wrote:

The second part of the compound if is backwards.  So if this is headed
for production code, it better get fixed.

DaveA



Not sure I'm understanding your remark.

  
Well, others in the thread have observed the same thing, so maybe it 
doesn't matter.  But the quoted code had only one if statement:


def v_cmp(v1, v2):
if v1.x  v2.x and v1.y  v2.y:
return -1
return 0


And the first part of the compound if is a  comparison, while the 
second part is a  comparison


This produces a different sort order than the default tuple comparison.  
So it needs fixing.


DaveA


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


Re: TypeError: an integer is required

2009-11-22 Thread MRAB

Lutfi Oduncuoglu wrote:

Hello,

I am a newbie on oython and I am taking the error at subject my code is 
below, I am trying to develop a qgis plugin and lines begin with # is 
the thing that I tried. Thus sys.stdout gives the type error. When I 
comment that line it turns an error like below. What may be the problem? 
thanks for help:)


...\ReadData.py, line 128, in run
print %d %s %(k, attr.toString())
IOError: [Errno 9] Bad file descriptor



[snip]


for (k,attr) in attrs.iteritems():
  sys.stdout = 
os.open(C://Users//lutfi//Documents//te//log.txt , a )

  print %d %s %(k, attr.toString())
 

I think the problem is that you're binding a low-level file id to
sys.stdout instead of a file object. Try:

   sys.stdout = 
open(C://Users//lutfi//Documents//te//log.txt , a )


Actually, changing sys.stdout just to use print a single string is a bad
idea. Try this instead:

  log_file = 
open(C://Users//lutfi//Documents//te//log.txt , a )

  print  log_file, %d %s %(k, attr.toString())
  log_file.close()
--
http://mail.python.org/mailman/listinfo/python-list


Re: Scripts Only Run In Root

2009-11-22 Thread geremy condra
On Sun, Nov 22, 2009 at 12:39 PM, Victor Subervi
victorsube...@gmail.com wrote:
 Hi;
 I can only run my python scripts on my server if they are owned by root. How
 do I change that?
 TIA,
 Victor

Almost certainly going to need more information. On that note, you are
probably going to get better help with less explaining from the appropriate
OS support channels.

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


Re: Split class across multiple files

2009-11-22 Thread Lie Ryan

eric.frederich wrote:

I have a class which holds a connection to a server and a bunch of
services.
In this class I have methods that need to work with that connection
and services.

Right now there are about 50 methods some of which can be quite long.
From an organizational standpoint, I'd like to have method
implementations in their own files.

Is this possible?  It is recommended?  Should I just stop worrying
about it and have a 5,000 line class?


If you're not joking about the 5000 lines estimation, then with 50 
methods, each method would be ~100 lines? That stinks of huge refactoring.

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


Re: Go versus Brand X

2009-11-22 Thread Aahz
In article 7ms7ctf3k2a7...@mid.individual.net,
Gregory Ewing  greg.ew...@canterbury.ac.nz wrote:

However, Go's designers seem to favour using the absolute minimum
number of characters they can get away with.

Although if they *really* wanted that, they would have dropped most of
the semicolons and used indentation-based block structure instead of
curly braces. I would have forgiven them several other sins if they'd
done that. :-)

That's essentially my issue with Go based on the code samples I've seen:
no over-arching design sensibility at the syntax level.  It looks like an
aggolomeration of semi-random C-like syntax.  There's nothing that
shouts out, This is a Go program, unlike Python, C, and even Perl.
-- 
Aahz (a...@pythoncraft.com)   * http://www.pythoncraft.com/

The best way to get information on Usenet is not to ask a question, but
to post the wrong information.  
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: What is the naming convention for accessor of a 'private' variable?

2009-11-22 Thread Lie Ryan

Peng Yu wrote:

On Wed, Nov 18, 2009 at 8:47 PM, Chris Rebert c...@rebertia.com wrote:

On Wed, Nov 18, 2009 at 6:27 PM, Peng Yu pengyu...@gmail.com wrote:

http://www.python.org/dev/peps/pep-0008/

The above webpage states the following naming convention. Such a
variable can be an internal variable in a class. I'm wondering what is
the naming convention for the method that access such variable.

   - _single_leading_underscore: weak internal use indicator.  E..g. from M
 import * does not import objects whose name starts with an underscore.

If there's a method to access the variable, then it's not all that
private, is it?
Accessor methods are not Pythonic. Just make the attribute public by
not prefixing it with an underscore.

See also Python is Not Java:
http://dirtsimple.org/2004/12/python-is-not-java.html


I don't quite understand the following paragraph from the above
webpage. Would you please give me an example to help me understand it?

Here's what you do. You write a function that contains a function.
The inner function is a template for the functions that you're writing
over and over again, but with variables in it for all the things that
vary from one case of the function to the next. The outer function
takes parameters that have the same names as those variables, and
returns the inner function. Then, every place where you'd otherwise be
writing yet another function, simply call the outer function, and
assign the return value to the name you want the duplicated function
to appear. Now, if you need to change how the pattern works, you only
have to change it in one place: the template.


Basically it sums to (pun not intended):

def adder(by):
def _adder(num):
return num + by
return _adder

add4 = adder(4)
add10 = adder(10)
add35 = adder(35)
add1 = adder(1)

in java, you'll need to manually duplicate the code, equivalent to doing:

def add4(num):
return num + 4
def add10(num):
return num + 10
def add35(num):
return num + 35
def add1(num):
return num + 1

or passes two arguments (which completely misses the point).
--
http://mail.python.org/mailman/listinfo/python-list


Re: Sorting: too different times. Why?

2009-11-22 Thread Mel
MRAB wrote:

 n00m wrote:
 :-) Of course, by too I meant too, as in to much
 
 Although it's OK in English to say too much x or too many x, it's
 somewhat unnatural to say too different xs; it would have to be the
 xs are too different. Nobody said English was logical! :-)

Now that James Joyce has written _Finnegans Wake_ there are no grammar 
errors and there are no spelling errors.  There are only unexpected 
meanings.

Mel.


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


Re: scanning under windows WIA with custom settings (dpi / etc )

2009-11-22 Thread r
On Nov 22, 11:32 am, News123 news...@free.fr wrote:
 Hi,

 I'm trying to scan a document from a python 2.6 script without user
 interaction.

 I found  a code snippet, that allows me to scan under Vista, but that
 doesn't allow me to select the dpi / color mode / etc.

 The snippet uses win32com.client


Hello,
I would also like to know the answer for which i am investigating now,
although like yourself i don't know much about the windows API and the
MSDN docs aren't helping much :(. All i can understand is that doing
anything in windows is a real PITA!

I am sure someone (or many) have climbed this mountain before but all
of them seemed to have forgotten to leave us the map that shows the
easy way up... bummer! The PyWin32extensions are great but lacking
detailed information of how to use the thing. And i know some GUI kits
like wxPython have Printer support but thats not really what i am
talking about here. I want the functionality directly from Python with
only win32extentions needed! We need to extend on the great work of
PyWin32 *OR* create a new module that will be an abstraction of the
Win32 module.

The problem with Windows scripting is all the crap you need to do
before you can even set parameters. Get a device context or find some
cryptic dispatch code, then mull over some even more cryptic options
and such. By now your eyeballs are about to pop out of there sockets
and your head is ponding from a massive hemorrhage and yet you still
have nothing to show for all this jumping through MS hoops!!!

There needs to be a drive to make some docs and post them somewhere.
This knowledge must be shared! The best place would be in the PyWin32
docs, but i don't expect the creator will do this, he has given us the
vehicle now we must forge the path.

I am willing to help create this if someone with even a small amount
of win32 knowledge could lend their expertise (any takers? send me an
email!). I would write all the Python code to implement these actions
very easily. (of course i'm not promising ground breaking code here
just something that works, but a hack is better than nothing!

I think a good start would be two classes for dealing with Printers
and Scanners in a very pythonic way (no device contexts!!!), from
there the sky is the limit!


##PRINTING RAW STRING##
import win32printer
printer = win32printer.get_default()
if not printer.online():
showerror('', 'Turn it on first you idiot!')
sys.exit(1)
printer.options.update({
'orientation':'landscape',
'font':('Times New', 12),
'header':time.ctime(),
})
printer.print_raw_string('hello printer, i have have arrived!')

##SCANNING##
import win32scanner
scanner = win32scanner.get_default()
if not scanner.online():
showerror('', 'Turn it on first you idiot!')
sys.exit(1)
scanner.options['imagetype'] = '.jpg'
scanner.scan(file=C:\\tmp\\image1)

##MORE??##

All the device context and cryptic mumbo-gumbo are nicly hidden from
the user. Of course there will also be option to show dialogs for user
input because that will be needed. With this proposed module the
bumbling confusion can be avoided. Joe-Scripter can study the source
later to learn Win32 more in depth. Yes people i hate windows too, but
for now we all have to deal with Windows like it or not!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Imitating tail -f

2009-11-22 Thread Nobody
On Sun, 22 Nov 2009 03:43:31 +0100, Ivan Voras wrote:

 The problem is: poll() always returns that the fd is ready (without
 waiting), but read() always returns an empty string. Actually, it
 doesn't matter if I turn O_NDELAY on or off. select() does the same.

Regular files are always ready for read/write. read() might return EOF,
but it will never block (or fail with EAGAIN or EWOULDBLOCK).

 Any advice?

The Linux version of tail uses the Linux-specific inotify_add_watch()
mechanism to block waiting for file-modification events.

If you don't have access to inotify_add_watch(), you'll just have to keep
trying to read from the file, sleep()ing whenever you hit EOF so that you
don't tie up the system with a busy-wait.

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


xmlrpc idea for getting around the GIL

2009-11-22 Thread Patrick Stinson
Has anyone every tried wrapping the CPython lib into a daemon with an
RPC mechanism in order to move the GIL out of the process? I have
multiple audio threads, each of which use the python interpreter but
don't have to interact with each other and can might as well use a
separate interpreter handled by a daemon with libpython linked in.

I've never used a C xmlrpc lib before and would probably need to set
up some shared memory to get it to work. Can anyone suggest a library
out there that would at do that sort of thing, maybe with some
cross-platform process management?

I imagine this is how the multiprocessing module works.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: TypeError: an integer is required

2009-11-22 Thread Dave Angel



Lutfi Oduncuoglu wrote:

Hello,

I am a newbie on oython and I am taking the error at subject my code is
below, I am trying to develop a qgis plugin and lines begin with # is the
thing that I tried. Thus sys.stdout gives the type error. When I comment
that line it turns an error like below. What may be the problem? thanks for
help:)

...\ReadData.py, line 128, in run
print %d %s %(k, attr.toString())
IOError: [Errno 9] Bad file descriptor

  
(Comment #2 is critical, but I didn't notice it right away.  Remove that 
line   from os import *  and use import os  instead.  )


This error is caused by binding the wrong kind of open to stdout.  
os.open() returns a file descriptor (integer), while stdout is expected 
to be a file object.


As for your previous error an integer is required it'd certainly be 
nice if you showed us the error message.  You say it was on a line 
beginning with # but there are many of those, none of them near the 
present error.


Taking a wild guess, I see another open for sys.stdout:

sys.stdout = open('C://Users//lutfi//Documents//te//log.txt', 777 )

But that line causes a file() argument 2 must be string, not int  
error.  You want w or a or something like that, rather than a 
mysterious 777 for that.


Just randomly jumping around in your code, consider what happens if you 
have the following line:


print %d %s %(k, attr)

and k is a string.  Then you'd get:   %d format: a number is required, 
not str


Well, enough guessing.  You need to give a complete traceback, as you 
did for the bad file descriptor


And you'd also need to specify Python version, as the messages might be 
different between your version and the 2.6 that I'm trying it with.


Other comments:

1) Are you coming from a java background?  In Python you do not need to 
put everything in a class definition.


2) the   from  import *   form is discouraged, and you use it 
several times.  I know some GUI packages specify it, and there you're 
best off by following their conventions.  But for modules like os, 
you're asking for trouble.  In this case, the built-in open() function 
that you need is being hidden by the os.open() call, which is not the 
one you wanted.  So you'll get syntax errors and funny runtime errors, 
just because you're calling different functions that what you think you are.


3) You have import within other defs.  This is unnecessary if the module 
has already been imported (such as sys), and is considered bad form in 
almost all cases.
There are only two common cases where an import might not appear right 
at the top of the module:
  A) when you want to conditionally import a module, based on some 
runtime choice.  Example would be to import a Unix version or a Windows 
version of some module.
   B) When a module will only be used in some unlikely case, such as in 
error handling.
   C) when a module is very slow to import, and you need to speed up 
startup time.


4) Simplified example code would do two things:   
   A) easier for us to follow, especially those of us that don't happen 
to use the same libraries that you do.
   B) by simplifying it, you can frequently find the problem yourself, 
which is a great way to learn


5) If you have two different error messages, but only have one version 
of the code, make both tracebacks complete, and make sure we know what's 
changed between the two versions.



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


Re: xmlrpc idea for getting around the GIL

2009-11-22 Thread Daniel Fetchinson
 Has anyone every tried wrapping the CPython lib into a daemon with an
 RPC mechanism in order to move the GIL out of the process? I have
 multiple audio threads, each of which use the python interpreter but
 don't have to interact with each other and can might as well use a
 separate interpreter handled by a daemon with libpython linked in.

 I've never used a C xmlrpc lib before and would probably need to set
 up some shared memory to get it to work. Can anyone suggest a library
 out there that would at do that sort of thing, maybe with some
 cross-platform process management?

 I imagine this is how the multiprocessing module works.

Yes, it does seem you need multiprocessing. That would take advantage
of multiple cores and the GIL wouldn't bother you at all. Take a look
at

http://docs.python.org/library/multiprocessing.html

For what you describe (separate tasks running concurrently without
communicating) the multiprocessing module would be ideal.

Cheers,
Daniel



-- 
Psss, psss, put it down! - http://www.cafepress.com/putitdown
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Sorting: too different times. Why?

2009-11-22 Thread Steven D'Aprano
On Sun, 22 Nov 2009 15:08:28 +, Duncan Booth wrote:

 n00m n...@narod.ru wrote:
 
 And now it's elephants instead of vectors. Def: an elephant is smarter
 than another one IIF its size is strictly less but its IQ is strictly
 greater
 
 I.e. you can't compare (2, 8) to (20, 50) or let count them as equally
 smart elephants.
 
 and that still isn't a relationship where you can get any meaningful
 order out of sorting them:

Not everything has, or need have, a total order. There are relationships 
which are only partial (i.e. not all the items are comparable), or 
missing transitivity.

A real-world example is pecking order in chickens, or social hierarchies 
in general. Using the  operator to mean higher ranking, you often get 
non-transitive hierarchies like the following:

A  B, C, D, E
B  C, E
C  D, E
D  B, E

That is, A  B  C  D  E except that D  B also.

Economic preference is also non-transitive: people may prefer X to Y, and 
prefer Y to Z, but prefer Z to X.

It is perfectly legitimate to sort a non-total ordered list, provided you 
understand the limitations, including that the order you get will depend 
on the order you started with.


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


Re: xmlrpc idea for getting around the GIL

2009-11-22 Thread Diez B. Roggisch

Daniel Fetchinson schrieb:

Has anyone every tried wrapping the CPython lib into a daemon with an
RPC mechanism in order to move the GIL out of the process? I have
multiple audio threads, each of which use the python interpreter but
don't have to interact with each other and can might as well use a
separate interpreter handled by a daemon with libpython linked in.

I've never used a C xmlrpc lib before and would probably need to set
up some shared memory to get it to work. Can anyone suggest a library
out there that would at do that sort of thing, maybe with some
cross-platform process management?

I imagine this is how the multiprocessing module works.


Yes, it does seem you need multiprocessing. That would take advantage
of multiple cores and the GIL wouldn't bother you at all. Take a look
at

http://docs.python.org/library/multiprocessing.html

For what you describe (separate tasks running concurrently without
communicating) the multiprocessing module would be ideal.


The problem is that the OP has a embedded application running threads. 
multiprocssing doesn't help there.


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


creating pipelines in python

2009-11-22 Thread per
hi all,

i am looking for a python package to make it easier to create a
pipeline of scripts (all in python). what i do right now is have a
set of scripts that produce certain files as output, and i simply have
a master script that checks at each stage whether the output of the
previous script exists, using functions from the os module. this has
several flaws and i am sure someone has thought of nice abstractions
for making these kind of wrappers easier to write.

does anyone have any recommendations for python packages that can do
this?

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


problem manipulating a list belonging to a class

2009-11-22 Thread Marc Leconte
Dear all,

I have a problem with the following code (ubuntu 8.04, Python 2.5.2):

class Toto(object):
def __init__(self, number, mylist=[]):
self.number=number
self.mylist=mylist
pass
pass

listA=Toto(number=1)
listB=Toto(number=2)

listA.mylist.append(5)
print 1) , listA.mylist
print 2) , listB.mylist

 1) [5]
 2) [5]

I would have expected
 1) [5]
 2) []

Thanks in advance for advice,
Marc.

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


problem with pyqt.. help please...

2009-11-22 Thread Threader Slash
-- Forwarded message --
From: Jebagnana Das jebagnana...@gmail.com
To: python-list@python.org
Date: Sat, 21 Nov 2009 19:17:56 +0530
Subject: problem with pyqt.. help please...
Hi friends,
 I've recently changed to ubuntu 9.04.. I've not had any problem
with the installation of pyqt as it is available from the ubuntu
repositories with umpteen number of packages.. Anyhow i've to download
tarball file for python 3.1 and installed it.. I found that PyQt4 supports
python 3.1(Am i right?)..

I wanted to check the pyqt installation with a sample program..

import sys
from PyQt4 import QtGui
app=QtGui.QApplication(sys.argv)
widget=QtGui.QWidget()
widget.resize(250,150)
widget.setWindowTitle('Simple')
widget.show()
sys.exit(app.exec_())

when i issued the command
$python simple.py
it worked perfectly since it's executed with 2.6 installation..
But when i tried to execute it with
$python3 simple.py
it showed the error like
ImportError: No module named PyQt4
So i searched the sys.path for 2.6 and included
/usr/lib/python2.6/dist-packages
in python3 sys.path...
Now when i tried to run this with python3  the error is like..
ImportError: /usr/lib/python2.6/dist-packages/PyQt4/QtGui.so: undefined
symbol: PyString_FromString
I got the same error when i tried to execute another program... So can u
please tell me how to solve this problem?? Am i heading in the right
direction???...

Thanks  Regards...

Jebagnanadas,
Python Learner..

...
it just looks like your problem is on setting your installation paths. Have
a look here:
http://www.linux.org/docs/ldp/howto/Nvidia-OpenGL-Configuration/instqt.html
http://www.linuxforums.org/forum/debian-linux-help/108948-setting-path-qt.html

Check and follow the steps. It should fix your problem.
- ThreaderSlash.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: problem manipulating a list belonging to a class

2009-11-22 Thread Diez B. Roggisch

Marc Leconte schrieb:


Dear all,

I have a problem with the following code (ubuntu 8.04, Python 2.5.2):

class Toto(object):
def __init__(self, number, mylist=[]):
self.number=number
self.mylist=mylist
pass
pass

listA=Toto(number=1)
listB=Toto(number=2)

listA.mylist.append(5)
print 1) , listA.mylist
print 2) , listB.mylist


1) [5]
2) [5]


I would have expected

1) [5]
2) []


http://effbot.org/zone/default-values.htm

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


Re: problem manipulating a list belonging to a class

2009-11-22 Thread Steve Howell
On Nov 22, 2:50 pm, Marc Leconte marcg...@free.fr wrote:
 Dear all,

 I have a problem with the following code (ubuntu 8.04, Python 2.5.2):

 class Toto(object):
         def __init__(self, number, mylist=[])
                 self.number=number
                 self.mylist=mylist
                 pass
         pass


Change your code to do this:

def __init__(self, number, mylist=None):
if mylist is None:
 self.mylist = []
else:
 self.mylist = mylist

Explanations of why you need to write it that will follow...
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: problem manipulating a list belonging to a class

2009-11-22 Thread Steve Howell
On Nov 22, 3:14 pm, Steve Howell showel...@yahoo.com wrote:

 Explanations of why you need to write it that will follow...

I knew this had to be written up somewhere...

http://www.ferg.org/projects/python_gotchas.html#contents_item_6
-- 
http://mail.python.org/mailman/listinfo/python-list


Implementation of Book Organization tool (Python2.[x])

2009-11-22 Thread ~km
Hi together,

I'm a python-proficient newbie and want to tackle a program with
Python 2.x, which basically organizes all my digital books (*.pdf,
*.chm, etc..) and to give them specific labels, such as:

Author - string
Read - boolean
Last Opened: - string
and so on..

Now my question is:

Is it a better method to use a /database/, a /static File/, with some
Markup (e.g.: YAML, XML), a Python dictionary or are there better ways
I
don't know of.., for organizing my books collection? I'm sure you can
do
it in any way above, but I'm apelling to /your/ personal experience
and
preference. Please give me at least one reason, why.
---
I think we are in Rats' Alley where the dead men lost their bones.
-- T.S. Eliot
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: creating pipelines in python

2009-11-22 Thread Lie Ryan

per wrote:

hi all,

i am looking for a python package to make it easier to create a
pipeline of scripts (all in python). what i do right now is have a
set of scripts that produce certain files as output, and i simply have
a master script that checks at each stage whether the output of the
previous script exists, using functions from the os module. this has
several flaws and i am sure someone has thought of nice abstractions
for making these kind of wrappers easier to write.

does anyone have any recommendations for python packages that can do
this?

thanks.


You're currently implementing a pseudo-pipeline: 
http://en.wikipedia.org/wiki/Pipeline_%28software%29#Pseudo-pipelines


If you want to create a unix-style, byte-stream-oriented pipeline, have 
all scripts write output to stdout and read from stdin (i.e. read with 
raw_input and write with print). Since unix pipeline's is byte-oriented 
you will require parsing the input and formatting the output from/to an 
agreed format between each scripts. A more general approach could use 
more than two streams, you can use file-like objects to represent stream.


For a more pythonic pipeline, you can rewrite your scripts into 
generators and use generator/list comprehension that reads objects from 
a FIFO queue and write objects to another FIFO queue (queue can be 
implemented using list, but take a look at Queue.Queue in standard 
modules). Basically an Object Pipeline: 
http://en.wikipedia.org/wiki/Pipeline_%28software%29#Object_pipelines


For unix-style pipeline, you shell/batch scripts is the best tool, 
though you can also use subprocess module and redirect the process's 
stdin's and stdout's. For object pipeline, it can't be simpler than 
simply passing an input and output queue to each scripts.


For in-script pipelines (c.f. inter-script pipeline), you can use 
generator/list comprehension and iterators. There are indeed several 
modules intended for providing slightly neater syntax than 
comprehension: http://code.google.com/p/python-pipeline/ though I 
personally prefer comprehension.

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


Re: Trying to understand += better

2009-11-22 Thread Lie Ryan

Roy Smith wrote:

If I've got an object foo, and I execute:

foo.bar += baz

exactly what happens if foo does not have a 'bar' attribute?  It's
pretty clear that foo.__getattr__('bar') gets called first, but it's a
little murky after that.  Assume for the moment that foo.__getattr__
('bar') returns an object x.  I think the complete sequence of calls
is:

foo.__getattr__('bar')  == x
x.__add__(baz)  == y
foo.__setattr__('bar', y)

but I'm not 100% sure.  It would be nice if it was, because that would
let me do some very neat magic in a system I'm working on :-)

How would things change if X defined __iadd__()?



The semantic of the in-place operator is something like:
x += y
becomes
x = x.__iadd__(y)

thus
foo.bar += baz
becomes
foo.bar = foo.bar.__iadd__(baz)

So the call sequence is,
foo.__getattr__('bar') == x
x.__iadd__(baz) == y
foo.__setattr__('bar', y)

the default definition of object.__iadd__ is something like this:
def __iadd__(self, other):
# this calls self.__add__ or other.__radd__ according to the
# operator call rule, may call __coerce__ or any other magics
# in operator calling
return self + other

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


Re: Implementation of Book Organization tool (Python2.[x])

2009-11-22 Thread Lie Ryan

~km wrote:

Hi together,

I'm a python-proficient newbie and want to tackle a program with
Python 2.x, which basically organizes all my digital books (*.pdf,
*.chm, etc..) and to give them specific labels, such as:

Author - string
Read - boolean
Last Opened: - string
and so on..

Now my question is:

Is it a better method to use a /database/, a /static File/, with some
Markup (e.g.: YAML, XML), a Python dictionary or are there better ways


In high-volume systems, it is almost always better to use a database. 
Database solves many issues with concurrent access and persistent memory.


Though many would disagree, I consider XML as a form of database though 
it is only suitable for data exchange. XML is suitable for low- to 
medium-volume purpose and when compatibility with various systems is 
extremely important (nearly any OS and any programming language has XML 
parsers; porting a DBMS system may not be as easy as that).


Python dictionary is stored in memory and closing the program == 
deleting the database. You can pickle dictionary; and this might be 
sufficient for quick and dirty, low-volume purpose. Pickled dictionary 
is the least portable solution; only python program can open a pickled 
dictionary and even different versions of python may have incompatibilities.



I
don't know of.., for organizing my books collection? I'm sure you can
do
it in any way above, but I'm apelling to /your/ personal experience
and
preference. Please give me at least one reason, why.


For a personal book collection where the number of books is around ~300 
books and you don't care about porting to another system, pickled 
dictionary may be just good enough.

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


Re: problem manipulating a list belonging to a class

2009-11-22 Thread Lie Ryan

Marc Leconte wrote:

class Toto(object):
def __init__(self, number, mylist=[]):
self.number=number
self.mylist=mylist
pass
pass


Why are you using pass to end your blocks?
--
http://mail.python.org/mailman/listinfo/python-list


Re: Trying to understand += better

2009-11-22 Thread Steve Howell
On Nov 22, 7:28 pm, Lie Ryan lie.1...@gmail.com wrote:
 Roy Smith wrote:
  If I've got an object foo, and I execute:

  foo.bar += baz

  exactly what happens if foo does not have a 'bar' attribute?  It's
  pretty clear that foo.__getattr__('bar') gets called first, but it's a
  little murky after that.  Assume for the moment that foo.__getattr__
  ('bar') returns an object x.  I think the complete sequence of calls
  is:

  foo.__getattr__('bar')  == x
  x.__add__(baz)  == y
  foo.__setattr__('bar', y)

  but I'm not 100% sure.  It would be nice if it was, because that would
  let me do some very neat magic in a system I'm working on :-)

  How would things change if X defined __iadd__()?

 The semantic of the in-place operator is something like:
 x += y
 becomes
 x = x.__iadd__(y)

 thus
 foo.bar += baz
 becomes
 foo.bar = foo.bar.__iadd__(baz)

 So the call sequence is,
 foo.__getattr__('bar') == x
 x.__iadd__(baz) == y
 foo.__setattr__('bar', y)

 the default definition of object.__iadd__ is something like this:
 def __iadd__(self, other):
      # this calls self.__add__ or other.__radd__ according to the
      # operator call rule, may call __coerce__ or any other magics
      # in operator calling
      return self + other

The __iadd__ method will often return self for mutable types.  So, for
example, these two statements are NOT identical where lst is a list:

lst = lst + [3]
lst += [3]

The first statement is creating a whole new list; the second one
isn't.


http://docs.python.org/reference/datamodel.html
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Implementation of Book Organization tool (Python2.[x])

2009-11-22 Thread Steve Howell
On Nov 22, 6:06 pm, ~km knny.m...@gmail.com wrote:
 Hi together,

 I'm a python-proficient newbie and want to tackle a program with
 Python 2.x, which basically organizes all my digital books (*.pdf,
 *.chm, etc..) and to give them specific labels, such as:

 Author - string
 Read - boolean
 Last Opened: - string
 and so on..

 Now my question is:

 Is it a better method to use a /database/, a /static File/, with some
 Markup (e.g.: YAML, XML), a Python dictionary or are there better ways
 I
 don't know of.., for organizing my books collection? I'm sure you can
 do
 it in any way above, but I'm apelling to /your/ personal experience
 and
 preference. Please give me at least one reason, why.

If your data structure is just a list of dictionaries and you do not
have any performance/security issues to consider yet, then you can use
pure Python for your input, since it is pretty easy to hand-edit, and
then occasionally you could use the PrettyPrinter module to format
your data.  YAML is another option, as it can offer a slightly cleaner
syntax, but I do not think it buys you a whole lot more than that for
your use case.  Same for JSON--I like JSON but you do not need it
right away.

PrettyPrinter is batteries included.

I would avoid XML and pickle.
-- 
http://mail.python.org/mailman/listinfo/python-list


Amoeba OS and Python

2009-11-22 Thread Александр Бежашвили
As I know, Python has been started for Amoeba OS.
Did anybody try Python with it? What about speed?

Python is so slow for big projects and I try to find a way to accelerate it.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Trying to understand += better

2009-11-22 Thread Steve Howell
On Nov 22, 9:11 pm, n00m n...@narod.ru wrote:
  The first statement is creating a whole new list;

 Yes but *imo* not quite exactly so.
 We can't think of 2 lists as of absolutely independent
 things.
 [...]

You are correct that two lists can both have the same mutable object
as items, and if you mutate that object, both lists will see that
mutation.  Changing the innards of an item doesn't change the list, if
you think of the list as just a collection of ids, but your point is
well taken.  It is probably easiest to understand all this with a more
elaborate example.

 mutable = {'foo': 'bar'}
 list1 = [mutable, 'bla']
 list2 = list1 + ['another element']
 list1
[{'foo': 'bar'}, 'bla']
 list2
[{'foo': 'bar'}, 'bla', 'another element']

So list2 and list1 are no longer the same list, but...

 mutable['foo'] = 'new value for mutable'
 list1
[{'foo': 'new value for mutable'}, 'bla']
 list2
[{'foo': 'new value for mutable'}, 'bla', 'another element']

They do still share a common element, as shown above.

But you can reassign the first element of list2 without affecting
list1:

 list2[0] = 'only list 2'
 list1
[{'foo': 'new value for mutable'}, 'bla']
 list2
['only list 2', 'bla', 'another element']

Now look at fred_list and barney_list below.  Since you use +=,
fred_list and barney_list stay tied together even when you *think* you
are only assigning a new value to barney_list[0].

 fred_list = [0]
 barney_list = fred_list
 barney_list += [1]
 barney_list
[0, 1]
 fred_list
[0, 1]
 barney_list[0] = 'barney'
 barney_list
['barney', 1]
 fred_list
['barney', 1]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: xmlrpc idea for getting around the GIL

2009-11-22 Thread Patrick Stinson
that's right. I cannot make CPython calls from my original C-based threads.

On Sun, Nov 22, 2009 at 3:15 PM, Diez B. Roggisch de...@nospam.web.de wrote:
 Daniel Fetchinson schrieb:

 Has anyone every tried wrapping the CPython lib into a daemon with an
 RPC mechanism in order to move the GIL out of the process? I have
 multiple audio threads, each of which use the python interpreter but
 don't have to interact with each other and can might as well use a
 separate interpreter handled by a daemon with libpython linked in.

 I've never used a C xmlrpc lib before and would probably need to set
 up some shared memory to get it to work. Can anyone suggest a library
 out there that would at do that sort of thing, maybe with some
 cross-platform process management?

 I imagine this is how the multiprocessing module works.

 Yes, it does seem you need multiprocessing. That would take advantage
 of multiple cores and the GIL wouldn't bother you at all. Take a look
 at

 http://docs.python.org/library/multiprocessing.html

 For what you describe (separate tasks running concurrently without
 communicating) the multiprocessing module would be ideal.

 The problem is that the OP has a embedded application running threads.
 multiprocssing doesn't help there.

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

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


Re: Trying to understand += better

2009-11-22 Thread Lie Ryan

Roy Smith wrote:
In article 4b0a01a...@dnews.tpgi.com.au, Lie Ryan lie.1...@gmail.com 
wrote:



The semantic of the in-place operator is something like:
x += y
becomes
x = x.__iadd__(y)

thus
foo.bar += baz
becomes
foo.bar = foo.bar.__iadd__(baz)

So the call sequence is,
foo.__getattr__('bar') == x
x.__iadd__(baz) == y
foo.__setattr__('bar', y)


I don't get where the __setattr__() call comes from in this situation.  I 
thought the whole idea of __iadd__(self, other) is that it's supposed to 
mutate self.  So, why is there another assignment happening after the 
__iadd__() call?


The formal name of the __iop__ is agumented assignment. The name 
doesn't talk about in-place; but it does talk about assignment. The 
semantic defines that augmented assignment operation is done in-place 
*when the left-hand side object supports it* (i.e. it does not require 
in-place mutation).



 The __iadd__ hook should behave similar to __add__, returning the 
result of the operation (which *could* be `self') which is to be 
assigned to the variable `x'.



For a more complete description, see: 
http://www.python.org/dev/peps/pep-0203/

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


[issue7374] Property accessor/getter called twice

2009-11-22 Thread Michal Liddle

New submission from Michal Liddle mich...@liddle.net.nz:

The following snippet demonstrates the problem:

-
class Test(object):
def get(self):
print get
def set(self, v):
print set
test = property(get, set)

t = Test()
t.test
t.test = 3
---

get is printed twice (expected once?), set is printed only once (as
expected)

--
messages: 95595
nosy: mliddle
severity: normal
status: open
title: Property accessor/getter called twice
type: behavior
versions: Python 2.5

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue7374
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue7374] Property accessor/getter called twice

2009-11-22 Thread Raymond Hettinger

Raymond Hettinger rhettin...@users.sourceforge.net added the comment:

Tried your snippet with both py2.5 and py2.6.  It works as expected (one
get and one set).

--
nosy: +rhettinger
resolution:  - works for me
status: open - closed

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue7374
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue7173] Cython compiler run crashes CPython 3.1.1 and 3.2

2009-11-22 Thread Amaury Forgeot d'Arc

Amaury Forgeot d'Arc amaur...@gmail.com added the comment:

I don't reproduce the problem on Windows. But the class NodeTypeWriter is 
not even used at all; did I miss something? The test builds a python 
extension and runs it, successfully it seems.

--
nosy: +amaury.forgeotdarc

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue7173
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue7374] Property accessor/getter called twice

2009-11-22 Thread Michal Liddle

Michal Liddle mich...@liddle.net.nz added the comment:

Right you are. Looks like its actually an IPython specific behaviour
here (didn't think to check that in the first place, sorry).

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue7374
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue7173] Cython compiler run crashes CPython 3.1.1 and 3.2

2009-11-22 Thread Stefan Behnel

Stefan Behnel sco...@users.sourceforge.net added the comment:

The patch is supposed to apply near the end of the class
TreeAssertVisitor at the end of the file Cython/TestUtils.py, not in the
class NodeTypeWriter.

And the test doesn't run (or even import) the extension, it just builds it.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue7173
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue6454] Add example keyword argument to optparse constructor

2009-11-22 Thread Greg Ward

Greg Ward g...@gerg.ca added the comment:

 but I feel there is a better and more general
 solution - just provide some minimal formatting for description: treat
 empty line as paragraph separator. Then I would be able to add example
 or anything else to the description formatting it as necessary

Agreed.  I have also been bitten by optparse munging paragraphs together
in the description, and it's annoying.  I *think* we could get away with
two simple rules:

  * blank lines separate paragraphs
  * indented lines don't get wrapped

Obviously no one wants to reinvent reStructuredText, but I think that
should do the trick.

If that works, I think the suggested 'examples' arg becomes unnecessary.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue6454
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue5007] urllib2 HTTPS connection failure (BadStatusLine Exception)

2009-11-22 Thread Senthil Kumaran

Senthil Kumaran orsent...@gmail.com added the comment:

This bug is not reproducible in trunk, py3k and is not reproducible in
py26 releases too. I tried to hunt down if any changes in the code-line
from py2.5 to py2.6 had effect on the behavior mention (BadStatusLine) ,
but don't see any. 

I am closing this as works for me.

--
resolution:  - works for me
status: open - closed

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue5007
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue7375] 2to3 - does not translate urllib2 to urllib.request correctly for function/method argument

2009-11-22 Thread Senthil Kumaran

New submission from Senthil Kumaran orsent...@gmail.com:

2.x code:

import urllib2
opener = urllib2.build_opener(urllib2.HTTPHandler(debuglevel=1))

2to3 on this would result in:

import urllib.request, urllib.error, urllib.parse
opener = urllib.request.build_opener(urllib2.HTTPHandler(debuglevel=1))

which is wrong. It did not translate the urllib2 in argument.

--
assignee: benjamin.peterson
messages: 95602
nosy: benjamin.peterson, orsenthil
priority: normal
severity: normal
status: open
title: 2to3 - does not translate urllib2 to urllib.request correctly for 
function/method argument
type: behavior

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue7375
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue7375] 2to3 - does not translate urllib2 to urllib.request correctly for function/method argument

2009-11-22 Thread Senthil Kumaran

Changes by Senthil Kumaran orsent...@gmail.com:


--
components: +2to3 (2.x to 3.0 conversion tool)

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue7375
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue7173] Cython compiler run crashes CPython 3.1.1 and 3.2

2009-11-22 Thread Amaury Forgeot d'Arc

Amaury Forgeot d'Arc amaur...@gmail.com added the comment:

Sorry, my mistake. Now the prints are there, but the test run without 
error:

Running tests against Cython 0.12.rc1
Python 3.2a0 (py3k, Nov 22 2009, 12:04:23) [MSC v.1500 32 bit (Intel)]
HERE1
(None, None, None)
HERE2
HERE1
(None, None, None)
HERE2
HERE1
(None, None, None)
HERE2
building 'first_assignment' extension
[...More output...]

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue7173
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue7369] Fibonacci example does not include 0; section 4.6

2009-11-22 Thread Senthil Kumaran

Senthil Kumaran orsent...@gmail.com added the comment:

tjreedy: The reporter's suggestion seems fine. Prepending a 0 does not
seem to be a good idea.

--
nosy: +orsenthil

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue7369
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue7376] FAIL: Doctest: __main__.DebugRunner

2009-11-22 Thread flox

New submission from flox la...@yahoo.fr:

Running on Debian Lenny, with Python 3.1.
The Python 2.5 version is OK.

~ $ python3 --version
Python 3.1.1+
~ $ python3 -m doctest
F..
==
FAIL: Doctest: __main__.DebugRunner
--
Traceback (most recent call last):
  File /usr/lib/python3.1/doctest.py, line 2096, in runTest
raise self.failureException(self.format_failure(new.getvalue()))
AssertionError: Failed doctest test for __main__.DebugRunner
  File /usr/lib/python3.1/doctest.py, line 1644, in DebugRunner

--
File /usr/lib/python3.1/doctest.py, line 1712, in __main__.DebugRunner
Failed example:
runner.run(test)
Expected:
Traceback (most recent call last):
...
doctest.UnexpectedException: DocTest foo from foo.py:0 (2 examples)
Got:
Traceback (most recent call last):
  File /usr/lib/python3.1/doctest.py, line 1243, in __run
compileflags, 1), test.globs)
  File doctest __main__.DebugRunner[15], line 1, in module
runner.run(test)
  File /usr/lib/python3.1/doctest.py, line 1736, in run
r = DocTestRunner.run(self, test, compileflags, out, False)
  File /usr/lib/python3.1/doctest.py, line 1375, in run
return self.__run(test, compileflags, out)
  File /usr/lib/python3.1/doctest.py, line 1296, in __run
exception)
  File /usr/lib/python3.1/doctest.py, line 1742, in
report_unexpected_exception
raise UnexpectedException(test, example, exc_info)
UnexpectedException: DocTest foo from foo.py:0 (2 examples)


--
Ran 15 tests in 0.015s

FAILED (failures=1)
~ $

--
components: Library (Lib), Tests
messages: 95605
nosy: flox
severity: normal
status: open
title: FAIL: Doctest: __main__.DebugRunner
versions: Python 3.1, Python 3.2

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue7376
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue7377] Slight difference: math.floor returns an Integral

2009-11-22 Thread flox

New submission from flox la...@yahoo.fr:

The last code snippet on section 25.2.3.2 How are Docstring Examples
Recognized? does not output the expected result.
http://docs.python.org/dev/py3k/library/doctest.html#how-are-docstring-examples-recognized


Documentation example:

 assert Easy!
   import math
   math.floor(1.9)
  1.0

Real life (Python 3.1):
 math.floor(1.9)
1

--
assignee: georg.brandl
components: Documentation
messages: 95606
nosy: flox, georg.brandl
severity: normal
status: open
title: Slight difference: math.floor returns an Integral
versions: Python 3.1, Python 3.2

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue7377
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue6123] tarfile: opening an empty tar file fails

2009-11-22 Thread Lars Gustäbel

Lars Gustäbel l...@gustaebel.de added the comment:

I have checked in a fix for this problem: trunk (r76443) and py3k (r76444).

Thank you very much for your report. Sorry that it took that long to get
it fixed.

--
resolution:  - accepted
status: open - closed

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue6123
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue7173] Cython compiler run crashes CPython 3.1.1 and 3.2

2009-11-22 Thread Amaury Forgeot d'Arc

Amaury Forgeot d'Arc amaur...@gmail.com added the comment:

I reproduce the crash on Linux. Some debug prints showed that the failing 
exception object is tp_clear'ed, because it belongs to a reference 
cycle. Now if it is cleared it should not be reachable...

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue7173
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue7369] Fibonacci example does not include 0; section 4.6

2009-11-22 Thread Terry J. Reedy

Terry J. Reedy tjre...@udel.edu added the comment:

Senthil: look again. The OP's suggestion *is* to prepend a 0 to the current
1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 1597
I just specified the delta between current and suggested, should someone
decide to make the change.

That said, def fib2(n), a little further on in 4.6, should get the same
edit as def fib(n) does.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue7369
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue7375] 2to3 - does not translate urllib2 to urllib.request correctly for function/method argument

2009-11-22 Thread Benjamin Peterson

Benjamin Peterson benja...@python.org added the comment:

Fixed in r76447.

--
resolution:  - fixed
status: open - closed

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue7375
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue7369] Fibonacci example does not include 0; section 4.6

2009-11-22 Thread Senthil Kumaran

Senthil Kumaran orsent...@gmail.com added the comment:

Terry: Oh, sorry. Now I get what you meant by Prepend O to output
line. That is, Output line from the fib, as part of the patch.  The
changes need to be done at 3 places. Section 3.2, twice in Section 4.6.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue7369
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue7373] Use PyModule_AddIntMacro() in Modules/gcmodule.c

2009-11-22 Thread Benjamin Peterson

Changes by Benjamin Peterson benja...@python.org:


--
resolution:  - works for me
status: open - closed

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue7373
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue1169193] Handle ungzipped man pages in rpm builds correctly

2009-11-22 Thread Dave Malcolm

Changes by Dave Malcolm dmalc...@redhat.com:


--
nosy: +dmalcolm

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue1169193
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue7376] FAIL: Doctest: __main__.DebugRunner

2009-11-22 Thread Alexander Belopolsky

Alexander Belopolsky belopol...@users.sourceforge.net added the comment:

Apparently this was introduced with r51625 :

r51625 | guido.van.rossum | 2006-08-26 16:37:44 -0400 (Sat, 26 Aug 2006) 
| 4 lines

Inspired by SF patch #860326, make the exception formatting by
traceback.py be closer to the built-in formatting.
A few unittests had to be fixed, too.




When doctest is imported as __main__, traceback does not prepend 
UnexpectedException with doctest. prefix.  Attached patch fixes the 
issue by explicitly reimporting doctest in the 'if __name__ == 
__main__:' clause.

This is rather inelegant and a better solution would probably be to use 
python -m doctest for something other than self test.  For example, 
running doctest.testfile on command line arguments would be a reasonable  
use, but python -m doctest Lib/doctest.py may still have a problem.

--
keywords: +patch
nosy: +belopolsky
Added file: http://bugs.python.org/file15380/issue7376.diff

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue7376
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue444582] Finding programs in PATH, addition to os

2009-11-22 Thread Brian Curtin

Brian Curtin cur...@acm.org added the comment:

Here is a patch against r76432 which implements a which generator
function in shutil that yields full file paths where the searched file
exists on the PATH. Includes doc change and a test. It is pretty similar
to what edemaine had suggested.

This could just as easily return a list, so if that would be more
preferable I'll change the patch.

--
nosy: +brian.curtin
Added file: http://bugs.python.org/file15381/shutil_which.patch

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue444582
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com