Re: numbers to string

2006-10-25 Thread David Isaac
Robert Kern wrote: >>> from numpy import * >>> y = [116, 114, 121, 32, 116, 104, 105, 115] >>> a = array(y, dtype=uint8) >>> z = a.tostring() >>> z 'try this' Very nice! Thanks also to Paul and Travis! Alan Isaac -- http://mail.python.org/mailman/listinfo/python-list

numbers to string

2006-10-24 Thread David Isaac
>>> y [116, 114, 121, 32, 116, 104, 105, 115] >>> z=''.join(chr(yi) for yi in y) >>> z 'try this' What is an efficient way to do this if y is much longer? (A numpy solution is fine.) Thanks, Alan Isaac -- http://mail.python.org/mailman/listinfo/python-list

Re: return same type of object

2006-10-24 Thread David Isaac
Bruno wrote: > This is usually known as a 'factory method'. You do realise that both solutions are *not* strictky equilavent, do you? Your point I believe is that after inheritance the factory method in the subclass will still return MyClass() but will return an instance of the subclass if I retu

return same type of object

2006-10-24 Thread David Isaac
Instances of MyClass have a method that returns another instance. Ignoring the details of why I might wish to do this, I could return MyClass() or return self.__class__() I like that latter better. Should I? Should I do something else altogether? Thanks, Alan Isaac -- http://mail.python.org/

yet another "groupsofn" function (newbie entertainment)

2006-10-04 Thread David Isaac
I have not seen this posted and I kind of like it. Shared for entertainment value only. Alan Isaac PS Easily adapted if the residual group is not desired. def groupsofsize(iterable,size): itr = iter(iterable) c=count() for k,it in groupby(itr,lambda x:c.next()//size): yield tup

Re: item access time: sets v. lists

2006-10-04 Thread David Isaac
Paul M. wrote: > Random access to item in list/set when item exists > set -> 0.000241650824337 > list -> 0.0245168031132 > > Random access to item in list/set when item does not exist > set -> 0.000187733357172 > list -> 0.522086186932 OK, that's a much better set of answers including to questi

Re: loop beats generator expr creating large dict!?

2006-10-04 Thread David Isaac
> Alan Isaac wrote: > > The current situation is: use a loop because the obvious generator > > approach is not efficient. "Fredrik Lundh" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > "not efficient" compared to what ? I already guess that I've missed your point, but to prove it

item access time: sets v. lists

2006-10-04 Thread David Isaac
Is it expected for access to set elements to be much slower than access to list elements? Explanation? Thanks, Alan Isaac >>> t1=timeit.Timer("for i in set(xrange(1)):pass","") >>> t2=timeit.Timer("for i in list(xrange(1)):pass","") >>> t1.timeit(1000) 9.806250235714316 >>> t2.timeit(1000

Re: loop beats generator expr creating large dict!?

2006-10-03 Thread David Isaac
Does George's example raise the question: why do dictionaries not implement efficient creation for two common cases? - Making a dict from two sequences of the same length. - Making a dict from a sequence and a function (as in George's example in this thread). The current situation is: use a loo

SimpleParse installer available for 2.5

2006-10-02 Thread David Isaac
This is important for my move to Python 2.5, so I thought others might want to know... Alan Isaac -- http://mail.python.org/mailman/listinfo/python-list

Re: "what's new" missing

2006-09-23 Thread David Isaac
"Alan Isaac" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > Where does one get the > "What's New" document for Python 2.5? > http://docs.python.org/dev/whatsnew/whatsnew25.html > pretends to hold it, but the links are corrupt. OK, here it is: http://docs.python.org/whatsnew/whatsn

"what's new" missing

2006-09-23 Thread David Isaac
Where does one get the "What's New" document for Python 2.5? http://docs.python.org/dev/whatsnew/whatsnew25.html pretends to hold it, but the links are corrupt. Thanks, Alan Isaac -- http://mail.python.org/mailman/listinfo/python-list

Re: newbie division question

2006-09-18 Thread David Isaac
> Alan Isaac wrote: > > Suppose x and y are ints in moduleA. > > > > If I put > > from __future__ import division > > in moduleA then x/y will produce the truediv result. > > > > If I put > > from __future__ import division > > in moduleB > > and > > from moduleB import * > > in module A > > then x

newbie division question

2006-09-18 Thread David Isaac
Suppose x and y are ints in moduleA. If I put from __future__ import division in moduleA then x/y will produce the truediv result. If I put from __future__ import division in moduleB and from moduleB import * in module A then x/y will NOT produce the truediv result (in moduleA). Why? And is ther

Re: best small database?

2006-09-12 Thread David Isaac
Thanks to all for the suggestions and much else to think about. Summarizing: Those who were willing to consider a database suggested: anydbm Gadfly SQLite (included with Python 2.5) Schevo Some preferred using the file system. The core suggestion was to choose a directory structure along with sp

best small database?

2006-09-11 Thread David Isaac
I have no experience with database applications. This database will likely hold only a few hundred items, including both textfiles and binary files. I would like a pure Python solution to the extent reasonable. Suggestions? Thank you, Alan Isaac -- http://mail.python.org/mailman/listinfo/pyth

Re: change property after inheritance

2006-09-06 Thread David Isaac
Le mercredi 06 septembre 2006 16:33, Alan Isaac a écrit : >> Suppose a class has properties and I want to change the >> setter in a derived class. If the base class is mine, I can do this: >> http://www.kylev.com/2004/10/13/fun-with-python-properties/ >> Should I? (I.e., is that a good solution?)

change property after inheritance

2006-09-06 Thread David Isaac
Suppose a class has properties and I want to change the setter in a derived class. If the base class is mine, I can do this: http://www.kylev.com/2004/10/13/fun-with-python-properties/ Should I? (I.e., is that a good solution?) And what if I cannot change the base class? How to proceed then? Than

Re: methods and functions, instances and classes

2006-09-04 Thread David Isaac
> Alan Isaac wrote: > > are method calls actually calls of the class's functions? "Bruno Desthuilliers" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > Depends on how the method was associated to the instance (you can set > methods on a per-instance property), but in the general case

Re: replace deepest level of nested list

2006-09-04 Thread David Isaac
Thanks to both Roberto and George. I had considered the recursive solution but was worried about its efficiency. I had not seen how to implement the numpy solution, which looks pretty nice. Thanks! Alan -- http://mail.python.org/mailman/listinfo/python-list

Re: methods and functions, instances and classes

2006-09-04 Thread David Isaac
> Alan Isaac wrote: > > When I create an instance of a class, > > are the class's functions *copied* to create the methods? > > Or are method calls actually calls of the class's functions? "Diez B. Roggisch" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > On the class functions. You

replace deepest level of nested list

2006-09-04 Thread David Isaac
I have a list of lists, N+1 deep. Like this (for N=2): [[['r00','g00','b00'],['r01','g01','b01']],[['r10','g10','b10'],['r11','g11' ,'b11']]] I want to efficiently produce the same structure except that the utlimate lists are replaced by a chosen (by index) item. E.g., [['r00','r01'],['r10','r11']

methods and functions, instances and classes

2006-09-04 Thread David Isaac
When I create an instance of a class, are the class's functions *copied* to create the methods? Or are method calls actually calls of the class's functions? I am sure this is both obvious and FAQ, but I did not find a clear answer (e.g. here http://docs.python.org/tut/node11.html#SECTION001134

TNEF decoder

2006-08-28 Thread David Isaac
I'm aware of http://cheeseshop.python.org/pypi/pytnef/ but it uses the tnef utility, and I'd like a pure Python solution (along the lines of http://www.freeutils.net/source/jtnef/ ). Is there one? Thanks, Alan Isaac -- http://mail.python.org/mailman/listinfo/python-list

Re: Don't use __slots__ (was Re: performance of dictionary lookup vs. object attributes)

2006-08-27 Thread David Isaac
"Jacob Hallen" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > Unfortunately there is a side effect to slots. They change the behaviour of > the objects that have slots in a way that can be abused by control freaks > and static typing weenies. This is bad, because the contol freaks s

Mahogany mail

2006-08-27 Thread David Isaac
Somewhat OT: Just wondering if anyone is doing something cool with the Python support in Mahogany mail. If so, please describe it or post some code. Thanks, Alan Isaac -- http://mail.python.org/mailman/listinfo/python-list

Re: text editor suggestion?

2006-08-18 Thread David Isaac
http://www.american.edu/econ/notes/soft.htm#EDITORS has some relevant discussion and suggestions. Cheers, Alan Isaac -- http://mail.python.org/mailman/listinfo/python-list

Re: How to draw line on Image?

2006-08-18 Thread David Isaac
"Daniel Mark" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > I want to draw some shapes, such as lines, circles on an image. http://www.pythonware.com/library/pil/handbook/psdraw.htm hth, Alan Isaac -- http://mail.python.org/mailman/listinfo/python-list

Re: __contains__ vs. __getitem__

2006-08-09 Thread David Isaac
> Alan Isaac wrote: > > I have a subclass of dict where __getitem__ returns None rather than > > raising KeyError for missing keys. (The why of that is not important for > > this question.) "Bruno Desthuilliers" <[EMAIL PROTECTED]> wrote: > Well, actually it may be important... What's so wrong wi

__contains__ vs. __getitem__

2006-08-09 Thread David Isaac
I have a subclass of dict where __getitem__ returns None rather than raising KeyError for missing keys. (The why of that is not important for this question.) I was delighted to find that __contains__ still works as before after overriding __getitem__.So even though instance['key'] does not ra

Re: using names before they're defined

2006-07-26 Thread David Isaac
Suppose I have inherited the structure PackageFolder/ __init__.py mod1.py SubPackageFolder/ __init__.py mod2.py mod3.py When mod1 is run as a script, I desire to import either mod2 or mod3 but not both conditional on an option detected b

Re: import from containing folder

2006-07-26 Thread David Isaac
Alan wrote: > I do not want to make any assumptions about > this particular package being on sys.path. > (I want a relative import, but cannot assume 2.5.) I should mention that to get around this I have been using sys.path.append(os.path.split(sys.argv[0])[0]) in the script I care most about. I

Re: import from containing folder

2006-07-26 Thread David Isaac
Simon Forman wrote: > I would assume (but I haven't checked) that this should work as long as > delmepy (in your case PackageFolder) was somewhere on sys.path. Sorry that was not clear: I do not want to make any assumptions about this particular package being on sys.path. (I want a relative import

import from containing folder

2006-07-26 Thread David Isaac
Suppose I have inherited the structure PackageFolder/ __init__.py mod1.py mod2.py SubPackageFolder/ __init__.py mod3.py and mod3.py should really use a function in mod2.py. *Prior* to Python 2.5, what is the best way to access that? (Please assu

property __doc__

2006-06-30 Thread David Isaac
To access the doc string of a property, I have to use the class not an instance. Why? Thanks, Alan Isaac -- http://mail.python.org/mailman/listinfo/python-list

Re: Legitimate use of the "is" comparison operator?

2006-06-19 Thread David Isaac
> > (I was using *small* integers). "Fredrik Lundh" <[EMAIL PROTECTED]> wrote: > "small integers" is what the phrase "small integers" in the "small > integers" and "small integers" parts of my reply referred too, of course. But aren't "*small* integers" likely to be smaller than "small integers

Re: Most elegant way to generate 3-char sequence

2006-06-09 Thread David Isaac
alpha = string.lowercase x=(a+b+c for a in alpha for b in alpha for c in alpha) -- http://mail.python.org/mailman/listinfo/python-list

Re: Most elegant way to generate 3-char sequence

2006-06-09 Thread David Isaac
"Rob Cowie" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > alpha = ['a','b','c','d'] #shortened for brevity > alpha2 = ['a','b','c','d'] > alpha3 = ['a','b','c','d'] > > def generator(): > for char in alpha: > for char2 in alpha2: > for char3 in alpha3: > yield c

Re: Writing PNG with pure Python

2006-06-09 Thread David Isaac
"Johann C. Rocholl" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > What license would you suggest? I recommend that you choose the license that will best achieve your long run goals for the code. As I understand them, and as I understand your application and software development,

Re: Writing PNG with pure Python

2006-06-09 Thread David Isaac
> Em Sex, 2006-06-09 às 12:30 -0400, Alan Isaac escreveu: > > It's your code, so you get to license it. > > But if you wish to solicit patches, > > a more Pythonic license is IMHO more likely > > to prove fruitful. "Felipe Almeida Lessa" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED

Re: Request new feature suggestions for my PDF conversion toolkit - xtopdf

2006-06-08 Thread David Isaac
"vasudevram" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > http://sourceforge.net/projects/xtopdf Serendipity: I was just looking for this functionality. Thanks! So here is an idea for a great enhancement: rst -> PDF The good news: the project is all Python, so you will only have

FreeImagePy and PIL

2006-06-03 Thread David Isaac
I am just starting to think about image processing. What are the overlaps and differences in intended functionality between FreeImagePy and PIL? Thanks, Alan Isaac -- http://mail.python.org/mailman/listinfo/python-list

Re: numpy bug

2006-06-03 Thread David Isaac
"Boris Borcic" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > after a while trying to find the legal manner to file numpy bug reports, > since it's a simple one, I thought maybe a first step is to describe the bug > here. Then maybe someone will direct me to the right channel. > > So

Re: argmax

2006-06-01 Thread David Isaac
Thanks for all the replies. A couple of comments. 1. I think the usefulness of an argmax built-in can be assessed by looking at other languages (and e.g. at numpy). So I do not buy the "not needed" argument as presented. More like "haven't got around to it," I'm thinking. 2. The particular use

argmax

2006-06-01 Thread David Isaac
1. Why is there no argmax built-in? (This would return the index of the largest element in a sequence.) 2. Is this a good argmax (as long as I know the iterable is finite)? def argmax(iterable): return max(izip( iterable, count() ))[1] 3. If this is the only place in a module where I need count a

Re: Tabs are *MISUNDERSTOOD*, end of discussion. (Re: Tabs versus Spaces in Source Code)

2006-05-17 Thread David Isaac
> Andy Sy wrote: > >Don't be evil - always configure your editor to > >convert tabs to true spaces. "achates" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > Yet another space-indenter demonstrates that problem actually lies with > people who think that tab == some spaces. Exactl

Re: simultaneous assignment

2006-05-02 Thread David Isaac
"John Salerno" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > Is there a way to assign multiple variables to the same value, but so > that an identity test still evaluates to False? Make sure the value is not a singleton. Assign them one at a time. >>> w=1000 >>> x=1000 >>> w==x Tr

Re: list*list

2006-05-01 Thread David Isaac
"Diez B. Roggisch" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > it's considered bad style to use range if all you want is a > enumeration of indices, as it will actually create a list of the size you > specified. Use xrange in such cases. I'm pretty sure this distinction goes away

Re: Numeric, vectorization

2006-05-01 Thread David Isaac
"RonnyM" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > e.g. y = [ 1, 2, 3, 4, 5, 6 ,7 ,8, 9 ] > ybar = [ 1, (1 + 3)*.5,(2 + 4)*.5,(3 + 5)*.5,..., (n-1 + n+1)*.5 ], n = > 1,...len(y) -1 > How do I make a vectorized version of this, I will prefer not to > utilize Map or similar funct

Re: HELP PLEASE: What is wrong with this?

2006-04-14 Thread David Isaac
"Ralph H. Stoos Jr." <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > HELP PLEASE: What is wrong with this?File "autotp.py", line 21 > ready = raw_input("Ready to proceed ? TYPE (y)es or (n)o: ") > ^ Probably the parenthesis you forgot to close on the preceding line ... C

Re: access mbx files?

2006-03-27 Thread David Isaac
Donn Cave, [EMAIL PROTECTED] > I suppose it isn't supported by the mailbox module basically because > it isn't all that commonly encountered. It may be more common on mail > servers, but there it's email net protocol data, POP or IMAP. If > Mahogany has been using this format for `local' folders

Re: access mbx files?

2006-03-26 Thread David Isaac
"Alan Isaac" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > Should I be able to access mail messages in Mahogany mail's mbx > format using the Python mailbox module? If so, can someone > please post a working example? If not, can you please > point me to documentation of the file for

access mbx files?

2006-03-26 Thread David Isaac
Should I be able to access mail messages in Mahogany mail's mbx format using the Python mailbox module? If so, can someone please post a working example? If not, can you please point me to documentation of the file format or better yet Python code to parse it? Thanks, Alan Isaac -- http://

Re: Comparisons and singletons

2006-03-26 Thread David Isaac
Alan asked: > > 2. If I really want a value True will I ever go astray with the test: > > if a is True: > > >>> a = True > > >>> b = 1. > > >>> c = 1 > > >>> a is True, b is True, c is True > > (True, False, False) "Ziga Seilnacht" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > I th

Re: Comparisons and singletons

2006-03-25 Thread David Isaac
"Ziga Seilnacht" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > >>> a = 1 > >>> b = 1 > >>> a == b > True > >>> a is b > False Two follow up questions: 1. I wondered about your example, and noticed >>> a = 10 >>> b = 10 >>> a is b True Why the difference? 2. If I really w

Re: __slots__

2006-03-25 Thread David Isaac
"Aahz" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > Because __slots__ breaks with inheritance. I believe that was the point of Ziga's example, which I acknowledged as a good one in my reply. So there still appears to be this single reason, which applies if your class may be subcla

Re: __slots__

2006-03-23 Thread David Isaac
"Ziga Seilnacht" <[EMAIL PROTECTED]> wrote: > If you want to restrict attribute asignment, you should use the > __setattr__ special method, see: > http://docs.python.org/ref/attribute-access.html That "should" is what I am asking about. If I understand, in the simplest case, you want me to say so

__slots__

2006-03-22 Thread David Isaac
1. "Without a __dict__ variable, instances cannot be assigned new variables not listed in the __slots__ definition." So this seemed an interesting restriction to impose in some instances, but I've noticed that this behavior is being called by some a side effect the reliance on which is considered

Re: Numerical solver

2006-03-01 Thread David Isaac
"Laszlo Zsolt Nagy" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > I would like to use a numerical solver for a specific problem. Another possibility: http://nlpy.sourceforge.net/ Alan Isaac -- http://mail.python.org/mailman/listinfo/python-list

Re: define loop statement?

2006-02-19 Thread David Isaac
"Benji York" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > Here's a flagrant hack: Admiration wins out over revulsion. ;-) Thanks, Alan Isaac PS Here's the motivation. Python closely resembles pseudocode. With a very little LaTeX hacking, it is often possible to write algorith

Re: define loop statement?

2006-02-18 Thread David Isaac
> Alan Isaac wrote: > > I would like to be able to define a loop statement > > (nevermind why) so that I can write something like > > > > loop 10: > > do_something > > > > instead of > > > > for i in range(10): > > do_something > > > > Possible? If so, how? "Jeffrey Schwab" <[EMAIL PROT

define loop statement?

2006-02-17 Thread David Isaac
I would like to be able to define a loop statement (nevermind why) so that I can write something like loop 10: do_something instead of for i in range(10): do_something Possible? If so, how? Thanks, Alan Isaac -- http://mail.python.org/mailman/listinfo/python-list

Re: lambda (and reduce) are valuable

2005-12-11 Thread David Isaac
"Chris Mellon" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > As someone who does a tremendous amount of event-driven GUI > programming, I'd like to take a moment to speak out against people > using us as a testament to the virtues of lamda. Event handlers are > the most important

Re: lambda (and reduce) are valuable

2005-12-11 Thread David Isaac
> Alan Isaac wrote: > >>> #evaluate polynomial (coefs) at x using Horner's rule > >>> def horner(coefs,x): return reduce(lambda a1,a2: a1*x+a2,coefs) > > It just cannot get simpler or more expressive. "Peter Otten" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > But is it correct?

Re: lambda (and reduce) are valuable

2005-12-09 Thread David Isaac
>>> Jibes against the lambda-clingers lead eventually to serious >>> questions of style in regard to variable namespacing, >>> lifespan, cleanup, and so on: >>> http://groups.google.com/group/comp.lang.python/browse_thread/thread/ad0e15cb6b8f2c32/ Alan Isaac <[EMAIL PROTECTED]> wrote:

Re: Dr. Dobb's Python-URL! - weekly Python news and links (Dec 7)

2005-12-08 Thread David Isaac
"Cameron Laird" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > Jibes against the lambda-clingers lead eventually to serious > questions of style in regard to variable namespacing, > lifespan, cleanup, and so on: > http://groups.google.com/group/comp.lang.python/browse_th

Re: best cumulative sum

2005-11-28 Thread David Isaac
"Peter Otten" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > sufficiently similar I think I understand your points now. But I wanted to match these cases: >>> import operator >>> reduce(operator.add,[],42) 42 >>> reduce(operator.add,[1],42) 43 The idea is that the i-th yield of i

Re: best cumulative sum

2005-11-27 Thread David Isaac
"Peter Otten" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > I think that the test for an empty iterator makes ireduce() unintuitive. OK. I misunderstood you point. But that is needed to match the behavior of reduce. >>> reduce(operator.add,[],42) 42 Thanks, Alan -- http://mail.

Re: FTP over TLS

2005-11-25 Thread David Isaac
"Carl Waldbieser" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > Does anyone know of any good examples for writing client side code to upload > files over a secure FTP connection? http://trevp.net/tlslite/ Alan Isaac -- http://mail.python.org/mailman/listinfo/python-list

Re: best cumulative sum

2005-11-24 Thread David Isaac
"Peter Otten" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > I'd rather have a second look whether the test is really needed. That's too obscure of a hint. Can you be a bit more explicit? Here's an example (below). You're saying I think that most of it is unnecessary. Thanks, Alan

Re: best cumulative sum

2005-11-23 Thread David Isaac
"Peter Otten" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > You are in for a surprise here: You got that right! > >>> def empty(): > ... for item in []: > ... yield item > ... > >>> bool(empty()) > True Ouch. > >>> bool(iter([])) > True # python 2.3 and probably

Re: best cumulative sum

2005-11-23 Thread David Isaac
"Peter Otten" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > Of course nothing can beat a plain old for loop in terms of readability and > -- most likely -- speed. Here are two versions, meant to be comparable. Thanks, Alan Isaac def cumreduce(func, seq, init = None): cr = seq

Re: best cumulative sum

2005-11-23 Thread David Isaac
"Peter Otten" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > - allows arbitrary iterables, not sequences only > - smaller memory footprint if sequential access to the items is sufficient Sure; I meant aside from that. > - fewer special cases, therefore > - less error prone, e. g.

Re: best cumulative sum

2005-11-23 Thread David Isaac
"Michael Spencer" <[EMAIL PROTECTED]> wrote in message news:mailman.1054.1132707811.18701.python-> This can be written more concisely as a generator: > > >>> import operator > >>> def ireduce(func, iterable, init): > ... for i in iterable: > ... init = func(init, i) > ...

Re: best cumulative sum

2005-11-23 Thread David Isaac
> Michael Spencer wrote: > > This can be written more concisely as a generator: <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > If iterable has no elements, I believe the behaviour should be [init], > there is also the case of init=None that needs to be handled. Right. So it is "

Re: Converting a flat list to a list of tuples

2005-11-22 Thread David Isaac
"Duncan Booth" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > >>> aList = ['a', 1, 'b', 2, 'c', 3] > >>> it = iter(aList) > >>> zip(it, it) > [('a', 1), ('b', 2), ('c', 3)] That behavior is currently an accident. http://sourceforge.net/tracker/?group_id=5470&atid=105470&func=detail

Re: best cumulative sum

2005-11-21 Thread David Isaac
> Alan Isaac wrote: >> Like SciPy's cumsum. "Colin J. Williams" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > Doesn't numarray handle this? Sure. One might say that numarray is in the process of becoming scipy. But I was looking for a solution when these are available. Something

Re: best cumulative sum

2005-11-21 Thread David Isaac
<[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > He seems to want scanl Yes. But it's not in Python, right? (I know about Keller's version.) Robert Kern wrote: > Define better. More accurate? Less code? Good point. As Bonono (?) suggested: I'd most like a solution that relies on a

best cumulative sum

2005-11-20 Thread David Isaac
What's the good way to produce a cumulative sum? E.g., given the list x, cumx = x[:] for i in range(1,len(x)): cumx[i] = cumx[i]+cumx[i-1] What's the better way? Thanks, Alan Isaac -- http://mail.python.org/mailman/listinfo/python-list

Re: grep

2005-10-25 Thread David Isaac
"Fredrik Lundh" <[EMAIL PROTECTED]> wrote:: def grep(pattern, *files): search = re.compile(pattern).search for file in files: for index, line in enumerate(open(file)): if search(line): print ":".join((file, str(index+1), line[:-1])

Re: calling matlab

2005-10-24 Thread David Isaac
"hrh1818" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > There is a module named pymat avvailable from > http://sourceforge.net/projects/pymat that provides a limited set of > functions for intertfacing Python to Matlab. I think that pymat was superceded by mlabwrap http://mlabwrap

grep

2005-10-24 Thread David Isaac
What's the standard replacement for the obsolete grep module? Thanks, Alan Isaac -- http://mail.python.org/mailman/listinfo/python-list

extract PDF pages

2005-10-13 Thread David Isaac
While pdftk is awesome http://www.accesspdf.com/pdftk/ I am looking for a Python solution. Just for PDF page extraction. Any hope? Thanks, Alan Isaac -- http://mail.python.org/mailman/listinfo/python-list

Re: FTP over SSL (explicit encryption)

2005-08-14 Thread David Isaac
> > http://www.lag.net/paramiko/ "Alan Isaac" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) > sock.settimeout(20) > sock.connect((hostname, port)) > my_t = paramiko.Transport(sock) > my_t.connect(hostkey=None ,username=userna

Re: FTP over SSL (explicit encryption)

2005-08-14 Thread David Isaac
"Eric Nieuwland" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > I'm having a look at FTP/S right now. That's a little > more complicated, but it seems doable. > If I succeed, I guess I'll donate the stuff as an extension to ftplib. Just found this: http://trevp.net/tlslite/ I haven

Re: Permutation Generator

2005-08-14 Thread David Isaac
"Casey Hawthorne" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > It's hard to make "complete" permutation generators, Knuth has a whole > fascicle on it - "The Art of Computer Programming - Volume 4 Fascicle > 2 - Generating All Tuples and Permutations" - 2005 Can you elaborate a

Re: Permutation Generator

2005-08-13 Thread David Isaac
"Talin" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > I wanted to share > this: a generator which returns all permutations of a list: Try this instead: def permuteg(lst): return ([lst[i]]+x for i in range(len(lst)) for x in permute(lst[:i]+lst[i+1:])) \ or [[]

Re: FTP over SSL (explicit encryption)

2005-08-12 Thread David Isaac
"Alan Isaac" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > http://www.lag.net/paramiko/ > However it requires the PyCrypto module. > http://www.amk.ca/python/code/crypto > > Can you briefly outline how to use this as a client > to upload and down files from a server using SFTP? OK

Re: FTP over SSL (explicit encryption)

2005-08-11 Thread David Isaac
> David Isaac wrote: > > I am looking for a pure Python secure ftp solution. > > Does it exist? "Andrew MacIntyre" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > I recall coming across an extension package (pretty sure it wasn't pure > Pyt

Re: FTP over SSL (explicit encryption)

2005-08-10 Thread David Isaac
"Eric Nieuwland" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > Do you want SFTP or FTP/S? The latter. > I'm having a look at FTP/S right now. That's a little > more complicated, but it seems doable. > If I succeed, I guess I'll donate the stuff as an extension to ftplib. Great!

FTP over SSL (explicit encryption)

2005-08-10 Thread David Isaac
I am looking for a pure Python secure ftp solution. Does it exist? I would have thought that the existence of OpenSSL would imply "yes" but I cannot find anything. ftplib does not seem to provide any secure services. I know about fptutil http://codespeak.net/mailman/listinfo/ftputil but that doe

MultiFile object does not iterate

2005-08-09 Thread David Isaac
Why is a MultiFile object not an iterator? For example if mfp = multifile.MultiFile(fp)I cannot dofor line in mfp: do_somethingRelated:MultiFile.next seems badly named.(Something like next_section would be better.)Is this just historical accident or am I missing the point?Thanks,Alan Isaac -- ht

can list comprehensions replace map?

2005-07-27 Thread David Isaac
Newbie question: I have been generally open to the proposal that list comprehensions should replace 'map', but I ran into a need for something like map(None,x,y) when len(x)>len(y). I cannot it seems use 'zip' because I'll lose info from x. How do I do this as a list comprehension? (Or, more gen

Re: Software needed

2005-07-22 Thread David Isaac
"niXin" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > Can anyone direct me to where I can find free software to do the following: > Document Management Software > --- > 1. Written in PHP or Python > 2. scanning feature - where I can scan a document http://

Re: Returning histogram-like data for items in a list

2005-07-22 Thread David Isaac
"Ric Deez" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > I have a list: > L1 = [1,1,1,2,2,3] > How can I easily turn this into a list of tuples where the first element > is the list element and the second is the number of times it occurs in > the list (I think that this is referred

tuple.index(item)

2005-07-11 Thread David Isaac
Why don't tuples support an index method? It seems natural enough ... Thanks, Alan Isaac -- http://mail.python.org/mailman/listinfo/python-list

default values of function parameters

2005-06-05 Thread David Isaac
Alan Isaac wrote: > Default parameter values are > evaluated once when the function definition is > executed. Where are they stored? ... Where is this documented? Forgive any poor phrasing: I'm not a computer science type. At http://www.network-theory.co.uk/docs/pytut/tut_26.html we read: "The exe

Re: evaluated function defaults: stored where?

2005-05-27 Thread David Isaac
Alan Isaac wrote: > Default parameter values are evaluated once when the function definition is > executed. Where are they stored? ... Where is this documented? Forgive any poor phrasing: I'm not a computer science type. At http://www.network-theory.co.uk/docs/pytut/tut_26.html we read: "The execu

evaluated function defaults: stored where?

2005-05-25 Thread David Isaac
Default parameter values are evaluated once when the function definition is executed. Where are they stored? (A guess: in a dictionary local to the function.) Where is this documented? As a Python newbie I found this behavior quite surprising. Is it common in many other languages? Is it unsurpris

mbx repair script: Python vs perl

2005-04-30 Thread David Isaac
I'm looking for the Python equivalent of the perl script and module described at http://comments.gmane.org/gmane.mail.imap.uw.c-client/707 Any hope? Thanks, Alan Isaac -- http://mail.python.org/mailman/listinfo/python-list

  1   2   >