Re: on slices, negative indices, which are the equivalent procedures?

2021-08-06 Thread Boris Dorestand
Jach Feng writes: >> > s = "Jack Brandom" >> > s[3 : -13 : -1] >> >> 'kcaJ' >> >> I have no idea how to replace that -13 with a positive index. Is it >> >> possible at all? > That's not possible because a positive index is relative to the leftmost item > 0 And the middle index is al

how to plot the FFT of a list of values

2020-12-05 Thread Boris Dorestand
I have 16 values of the period sequence 1, 2, 4, 8, 1, 2, 4, 8, ... I compute its fourier transform using >>> from scipy import fft, ifft >>> x = [1,2,4,8,1,2,4,8] >>> fft(x) array([ 30. +0.j, 0. +0.j, -6.+12.j, 0. +0.j, -10. +0.j, 0. +0.j, -6.-12.j, 0. +0.j]) Now how can I plot

Re: on generating combinations among a variable list of lists

2020-06-28 Thread Boris Dorestand
Peter Otten <__pete...@web.de> writes: > Boris Dorestand wrote: > >> Say we have [1,3,5,7], [2,3], [1,10]. I'd like to generate >> >> [1,2,1] >> [1,2,10] >> [1,3,1] >> [1,3,10] >> [3,2,1] >> [3,2,10] >> [3,3,

on generating combinations among a variable list of lists

2020-06-28 Thread Boris Dorestand
Say we have [1,3,5,7], [2,3], [1,10]. I'd like to generate [1,2,1] [1,2,10] [1,3,1] [1,3,10] [3,2,1] [3,2,10] [3,3,1] [3,3,10] [5, ...] ... [7,3,10] The number of input lists is variable. The example shows three lists, but there could be only one or ten lists or any other

Re: how to let argument be optional falling back to certain integer

2020-06-22 Thread Boris Dorestand
David Raymond writes: >> This is true. I have written 0 as false in C so many times. But >> clearly for me times have changed... I now look at numbers as a thing >> in their own special class not to be confused as truth-values. (So much >> so that I fell for this.) But I confess I still thin

Re: how to let argument be optional falling back to certain integer

2020-06-21 Thread Boris Dorestand
Chris Angelico writes: [...] >> Anyway, I kind of replied just to thank you all for the great group this >> is. ChrisA, I don't know how can keep up with this newsgroup, but you >> do. This is crazy. Years go by and when I come back, there you are >> still. You're priceless. > > You're most

Re: how to let argument be optional falling back to certain integer

2020-06-20 Thread Boris Dorestand
Chris Angelico writes: > On Sun, Jun 21, 2020 at 2:02 AM Boris Dorestand > wrote: >> >> I just wrote >> >> def f(y, N, k = None): >> k = k or (N - 1) >> return k >> >> I was surprised to find out that 0 == False, so f(7, 31, 0) pr

how to let argument be optional falling back to certain integer

2020-06-20 Thread Boris Dorestand
I just wrote def f(y, N, k = None): k = k or (N - 1) return k I was surprised to find out that 0 == False, so f(7, 31, 0) produces 31. I'd like 0 to be a valid choice for k. How do you guys let k be an optional argument such that it defaults to N - 1? Thank you. -- https://mail.pytho

Re: how to make ["a","b",["c","d"],"e"] into ['a', 'b', 'c', 'd', 'e'] ?

2014-04-10 Thread Boris Borcic
Boris Borcic wrote: Rustom Mody wrote: def fl1(l): return [y for x in l for y in x] # recursive flatten def fr(l): ... if not isinstance(l,list): return [l] ... return fl1([fr(x) for x in l]) For a short non-recursive procedure - not a function, modifies L in-place but none of its

Re: how to make ["a","b",["c","d"],"e"] into ['a', 'b', 'c', 'd', 'e'] ?

2014-04-10 Thread Boris Borcic
Rustom Mody wrote: def fl1(l): return [y for x in l for y in x] # recursive flatten def fr(l): ... if not isinstance(l,list): return [l] ... return fl1([fr(x) for x in l]) For a short non-recursive procedure - not a function, modifies L in-place but none of its sublists. >>> def flat

Re: How can i create a random array of floats from 0 to 5 in python

2013-03-12 Thread Boris FELD
You can use [random.random() * 5 for x in range(100)] but works only on range [0, 5). If you want to include 5, you will need more code. Cheers, FELD Boris 2013/3/12 Norah Jones : > I want to create a random float array of size 100, with the values in the > array ranging from 0 to 5.

Re: For Loop in List

2013-01-13 Thread Boris FELD
2013/1/13 Tim Chase : > On 01/13/13 06:45, subhabangal...@gmail.com wrote: > SIZE = 3 for i in range(len(list1)//SICE): > ... print list1[i*SIZE:i*SIZE+SIZE] > ... > [1, 2, 3] > [4, 5, 6] > [7, 8, 9] > [10, 11, 12] > A little shorter and simpler version: >>> x = x[1:] >>> for i in ra

Re: Help with unittest2

2012-12-13 Thread Boris FELD
How are you importing unittest2, do you have something like this ? try: import unittest2 as unittest except ImportError: import unittest If it's the case, you are maybe using default unittest while you think you are using unittest2. 2012/12/13 Daniel Laird : > On Thursday, December 13, 2012

Re: open URL in the current tab

2012-12-10 Thread Boris FELD
Don't think that it's possible with webbrowser, you should try with Selenium. For example with sst (Simple Selenium Test), it open url in current tab or create a new one if no one exists: from sst.actions import * go_to('http://www.ubuntu.com/') 2012/12/10 Jabba Laci : > Hi, > > With the webbrow

Re: Testing against multiple versions of Python

2012-10-19 Thread Boris FELD
Did you take a look at https://www.shiningpanda-ci.com/? 2012/10/19 andrea crotti : > 2012/10/19 Michele Simionato : >> Yesterday I released a new version of the decorator module. It should run >> under Python 2.4, 2.5, 2.6, 2.7, 3.0, 3.1, 3.2, 3.3. I did not have the will >> to install on my ma

Re: Writing Android application using GPS data with Python

2012-04-15 Thread Boris FELD
You can try appaccelerator, it seems to support python and you should be able to access geolocalisation (according to wikipedia: https://en.wikipedia.org/wiki/Appcelerator_Titanium) Le 15 avril 2012 16:44, Noam Peled a écrit : > I want to write an Android application using Python. I've found 2 o

PDF 508 Compliance with Python?

2011-12-27 Thread Yanovsky, Boris, VHACIN
Hello, I am new to Python and I hope my question makes sense. We are trying to make PDFs 508 Compliant, meaning that the objects within them have to be tagged. The problem is that we have hundreds, and potentially thousands of PDFs, since they are automated reports that we create on a regular b

Re: (*args **kwargs) how do I use' em?

2011-06-11 Thread FELD Boris
A good tutorial will surely help : http://www.saltycrane.com/blog/2008/01/how-to-use-args-and-kwargs-in-python/ The idea between *args and *kwargs is to create function (callables) which accepts an arbitrary number of anonymous and/or keyword arguments. It's useful when you want to create a fu

Re: learnpython.org - an online interactive Python tutorial

2011-04-20 Thread FELD Boris
's an excellent idea and, when the tutorials were expanded enough, i should be good to integrate it with python.org website (but it's more a dream than something else...) One question, if i want to write a tutorial about import mechanism, how can i manage the file system ? Nice work ! --

Re: Python benefits over Cobra

2011-04-05 Thread Boris FELD
Cobra seems interessant, open-source, but the dependance on Mono and .Net annoy me a bit. Otherwise, cobra have good ideas, a syntax similar to python. One thing i really love is the "How-To" and the "Samples" pages on it's website, i think it's a very good thing fo

Re: Dump interpreter history?

2011-03-25 Thread FELD Boris
Take a look at : http://ipython.scipy.org/doc/manual/html/interactive/tutorial.html#use-your-input-history Cheers, FELD Boris -- FELD Boris Sent with Sparrow On vendredi 25 mars 2011 at 22:03, Ken D'Ambrosio wrote: > Hey, all. A co-worker asked me a question, and I've got no idea

Re: Validating Command Line Options

2011-03-23 Thread Boris FELD
If you're using argparse, you have a method for that named "add_mutually_exclusive_group". Tutorial : http://www.doughellmann.com/PyMOTW/argparse/#mutually-exclusive-options Cheers, Feld Boris 2011/3/23 T : > For a Python script with multiple command line options, what is th

Re: Threading with Socket Server

2011-03-23 Thread Boris FELD
n.org/library/socketserver.html). I'm not sure about how shelve manage concurrency, but in my opinion, you'll need to create a single process or thread which manage read and write operation in order to avoiding race conditions. Cheers, Feld Boris 2011/3/23 T : > Hello all, I am writing

Re: side by side python

2011-03-21 Thread FELD Boris
Yes, i did not mention this solution, using virtualenv is a very good practice, but before create a virtualenv with a specific version of python, you must have installed it globally, isn't it ? Regards, -- FELD Boris Sent with Sparrow On lundi 21 mars 2011 at 14:45, macm wrote: > On M

Re: [OSX] side by side python

2011-03-21 Thread FELD Boris
lation. No specific problem, i use these Python versions without any problem on mac os x : 2.5, 2.6, 2.7, 3.0, 3.1, 3.2. -- FELD Boris Sent with Sparrow On lundi 21 mars 2011 at 13:31, Robert wrote: > Can I install Python 2.7 and 3.2 (from python.org) side by side on OSX > without them st

Re: A and B but not C in list

2011-01-24 Thread Boris Borcic
Terry Reedy wrote: The straightforward code if a in L and b in L and c not in L and d not in L scans the list 4 times. of course for a single scan one can setify the list and write S=set(L) if a in S and b in S and c not in S and d not in S or even, I guess, something like {a,b} <= S and

Re: Printing from Web Page

2010-11-21 Thread FELD Boris
I think the best way to do this is using css with specific media type.Take a look at : http://martybugs.net/articles/print.cgi -- FELD BorisSent with Sparrow On dimanche 21 novembre 2010 at 03:35, Hidura wrote:

Re: How convert list to nested dictionary?

2010-11-05 Thread Boris Borcic
Arnaud Delobelle wrote: macm writes: Hi Folks How convert list to nested dictionary? l ['k1', 'k2', 'k3', 'k4', 'k5'] result {'k1': {'k2': {'k3': {'k4': {'k5': {}} Regards macm reduce(lambda x,y: {y:x}, reversed(l), {}) d={} while L : d={L.pop():d} -- http://mail.python.org/

Re: Python Macros's Not the Power in OOo they should be ?

2010-09-23 Thread Boris Borcic
Lawrence D'Oliveiro wrote: flebber wrote: Has anyone had much success with python macro's. Or developing powerful macro's in an language? I did an application for my own use recently, involving automatically generating invoices in editable OOWriter format from my billing database. I gave up o

Re: List of lists surprising behaviour

2010-06-17 Thread Boris Borcic
candide wrote: So what is the right way to initialize to 0 a 2D array ? Is that way correct : >>> t=[[0 for _ in range(2)] for _ in range(3)] That's overkill :) You can skip the inner loop by using a list display, eg t=[[0,0] for _ in range(3)] It seems there is no more trouble now :

Re: pythonize this!

2010-06-16 Thread Boris Borcic
Ignacio Mondino wrote: On Tue, Jun 15, 2010 at 8:49 AM, superpollo wrote: goal (from e.c.m.): evaluate 1^2+2^2+3^2-4^2-5^2+6^2+7^2+8^2-9^2-10^2+...-2010^2, where each three consecutive + must be followed by two - (^ meaning ** in this context) my solution: s = 0 for i in range(1, 2011): ...

python 2.x and running shell command

2009-12-24 Thread Boris Arloff
>On Dec 23, 5:22 pm, Sean DiZazzo wrote: > On Dec 23, 1:57 pm, tekion wrote: > > > > > All, > > some of the servers I have run python 2.2, which is a drag because I > > can't use subprocess module.  My options that I know of is popen2 > > module.  However, it seems it does not have io blocking >

PYO versus PYC Behavior

2009-12-24 Thread Boris Arloff
with a -OO compile.   Anyone can comment, please?   Thanks, Boris     -- http://mail.python.org/mailman/listinfo/python-list

Beginner question: binary data and socket.send

2009-12-21 Thread Boris Epel
eed string ... Suggestions are appreciated! boris -- http://mail.python.org/mailman/listinfo/python-list

SocketServer

2009-10-12 Thread Boris Arloff
kill for defunct children after a time.sleep(0.5); allow dependent processes to complete their job before totally closing down the request. 4. Report os errors as exceptions; but not errno.ECHILD, which means trying to kill none existing child; keep this as a warning. This is more suscinct code a

Re: The rap against "while True:" loops

2009-10-10 Thread Boris Arloff
I agree there is no rap against "while True"-loops.  As an example these are very useful especially when receiving continuous data over a queue, pipe socket, or over any other connection.  You set to block, receive data, then process data and finally loop around to wait for next data segment.  O

Re: An iteration idiom (Was: Re: [Guppy-pe-list] loading files containing multiple dumps)

2009-09-02 Thread Boris Borcic
Sverker Nilsson wrote: Sverker Nilsson wrote: It reads one Stat object at a time and wants to report something when there is no more to be read from the file. Hmm, am I right in thinking the above can more nicely be written as: >>> from guppy import hpy >>> h = hpy() >>> f = open(r'your.hp

Trying to get ABC to work

2009-08-03 Thread Boris Arloff
y I could define an abstract method within a metaclass and have it behave with abstraction when the class is created off the metaclass?   I other words, I want to force an implementation of cls_abc() method when MyKlass(object): __metaclass__ = MetaExample is declared, or else get NotImplement

Re: Making the case for repeat

2009-06-12 Thread Boris Borcic
Raymond Hettinger wrote: There is a natural inclination to do the opposite. We factor code to eliminate redundancy, but that is not always a good idea with an API. The goal for code factoring is to minimize redundancy. The goal for API design is having simple parts that are easily learned and c

Metaclasses Demystified

2009-06-10 Thread Boris Arloff
reby I will try to create class objects on the fly at runtime out of nothing; or almost nothing. I can attach my code if necessary, but as indicated it is identical to LaCour's in the article with the necessary syntax changes for python 3.0. Thanks Boris -- http://mail.python.org/mailman/listinfo/python-list

Re: list comprehension question

2009-05-06 Thread Boris Borcic
Ross wrote: If I have a list of tuples a = [(1,2), (3,4), (5,6)], and I want to return a new list of each individual element in these tuples, I can do it with a nested for loop but when I try to do it using the list comprehension b = [j for j in i for i in a], my output is b = [5,5,5,6,6,6] inste

Re: Python to Perl transalators

2009-03-18 Thread Boris Borcic
Armin wrote: Why on earth would you want to? That'd be like translating Shakespeare into a bad rap song! lol, actually I would prefer a rap song over Shakespeare, so your analogy doesn't work there ;) Why, some people do prefer Perl over Python, so what's wrong with the analogy ? -- http

Re: Ban Xah Lee

2009-03-08 Thread Boris Borcic
seconded. -- http://mail.python.org/mailman/listinfo/python-list

Re: Themed TK (tk Tile) at last?!

2009-03-08 Thread Boris Borcic
Python Nutter wrote: Looks like we finally get tkinter GUI based programs according to Issue# 2983 in Python 3.1a so our programs don't look like something out of early 1980's Please don't confuse History gratuitously. Make that mid 90's. Cheers, BB -- http://mail.python.org/mailman/listinfo/

Re: Delete all items in the list

2009-02-26 Thread Boris Borcic
Chris Rebert wrote: On Thu, Feb 26, 2009 at 3:05 AM, Clarendon wrote: ... L=['a', 'b', 'c', 'a'] I want to delete all 'a's from the list. But if L.remove('a') only deletes the first 'a'. How do you delete all 'a's? There are several ways. I'd go with a list comprehension: and for a coupl

Re: lazy evaluation is sometimes too lazy... help please.

2009-01-16 Thread Boris Borcic
itlist[i] = (x+(i*10) for i,s in (i,count()) for x in s) oops, that would be itlist[i] = (x+(i*10) for i,s in [(i,count())] for x in s) or equivalent, kind of ugly anyway. -- http://mail.python.org/mailman/listinfo/python-list

Re: lazy evaluation is sometimes too lazy... help please.

2009-01-16 Thread Boris Borcic
The minimal correction, I guess, is to write itlist[i] = (x+(i*10) for i in [i] for x in count()) instead of itlist[i] = (x+(i*10) for x in count()) although itlist[i] = (x+(i*10) for i,s in (i,count()) for x in s) will better mimic generalizations in the sense that the "minimal cor

Re: More elegant way to try running a function X times?

2008-11-20 Thread Boris Borcic
Tim Chase wrote: success = None for i in range(5): #Try to fetch public IP success = CheckIP() if success: break if not success: print "Exiting." sys.exit() Though a bit of an abuse, you can use if not any(CheckIP() for _ in range(5)): print "Exiting" sys.e

Re: More elegant way to try running a function X times?

2008-11-20 Thread Boris Borcic
Tim Chase wrote: success = None for i in range(5): #Try to fetch public IP success = CheckIP() if success: break if not success: print "Exiting." sys.exit() Though a bit of an abuse, you can use if not any(CheckIP() for _ in range(5)): print "Exiting" sys

Re: Function to Add List Elements?

2008-10-23 Thread Boris Borcic
Chris Rebert wrote: On Wed, Oct 22, 2008 at 12:59 PM, Henry Chang <[EMAIL PROTECTED]> wrote: This seems like a simple problem, but I can't find a simple solution. Suppose I have two lists of integers. List A = [A1, A2, A3] List B = [B1, B2, B3] I just simply want a new list, such as: List C

Re: Append a new value to dict

2008-10-16 Thread Boris Borcic
Kirk Strauser wrote: While we're on the subject, use keyword arguments to dict like: foo.update(dict(quux='blah', baz='bearophile', jdd='dict')) was *much* slower, at 11.8s. Presumably you would save half of that time by writing simply foo.update(quux='blah', baz='bearophile', jdd

Re: ABCs -> infix syntax for isinstance() ?

2008-10-09 Thread Boris Borcic
Terry Reedy wrote: Boris Borcic wrote: ... - allowing containment tests, ie "x in Number" to invoke isinstance() in the background when the container is of type . My brain is too muddled by flu at the moment, to see whether Guido's fabled time machine allowed him to already

Re: ABCs -> infix syntax for isinstance() ?

2008-10-08 Thread Boris Borcic
Bruno Desthuilliers wrote: [EMAIL PROTECTED] a écrit : ... A intriguing wider proposition would be to transpose Ruby's notion of "Open Classes" to Python built-in metaclasses (or just to type itself ?). No, thanks. Even the Ruby guys start to think making evrything open may not be such a goo

Re: ABCs -> infix syntax for isinstance() ?

2008-10-07 Thread Boris Borcic
Bruno Desthuilliers wrote: Boris Borcic a écrit : Given the ABC innovation, maybe an infix syntax for isinstance() would be good. Possibilities : - stealing "is" away from object identity. As a motivation, true use cases for testing object identity are rare; "x is None"

ABCs -> infix syntax for isinstance() ?

2008-10-03 Thread Boris Borcic
Given the ABC innovation, maybe an infix syntax for isinstance() would be good. Possibilities : - stealing "is" away from object identity. As a motivation, true use cases for testing object identity are rare; forcing the usage of a function or method to test it, would dissuade abuse. - allow

Re: What is not objects in Python?

2008-10-01 Thread Boris Borcic
42, for instance. Proof : >>> 42 is not object True QED -- http://mail.python.org/mailman/listinfo/python-list

Re: dict generator question

2008-09-19 Thread Boris Borcic
Gerard flanagan wrote: George Sakkis wrote: .. Note that this works correctly only if the versions are already sorted by major version. Yes, I should have mentioned it. Here's a fuller example below. There's maybe better ways of sorting version numbers, but this is what I do. Indeed, you

Re: recursion gotcha?

2008-09-14 Thread Boris Borcic
cnb wrote: this recursive definition of sum thrumped me, is this some sort of gotcha or am I just braindead today? and yes i know this is easy a a for x in xs acc += x or just using the builtin. def suma(xs, acc=0): if len(xs) == 0: acc else: suma(

Re: Injecting new names into the above frame

2008-09-13 Thread Boris Borcic
Why don't you use import and __import__() ? - They seem designed for such an application. I mean, I am not against vicious hacks for the fun of them, but not if they serve the illusion that what they do can't (easily) be achieved other ways. Cheers, BB Peter Waller wrote: Dear Pythoners, I

''.join woes - Re: max(), sum(), next()

2008-09-13 Thread Boris Borcic
I wrote: Tino Wildenhain wrote: [...] sum(['a','b'],'') : sum() can't sum strings [use ''.join(seq) instead] Yes which is a bit bad anyway. I don't think hard wiring it is such a nice idea. You know, walks like a duck, smells like a duck... If it makes sense to handle things differently

Re: max(), sum(), next()

2008-09-13 Thread Boris Borcic
Tino Wildenhain wrote: Hi, Luis Zarrabeitia wrote: Quoting Laszlo Nagy <[EMAIL PROTECTED]>: ... Even better: help(sum) shows === sum(...) sum(sequence, start=0) -> value Returns the sum of a sequence of numbers (NOT strings) plus the value of parameter 'start'. When the

Re: max(), sum(), next()

2008-09-09 Thread Boris Borcic
castironpi wrote: On Sep 8, 8:54 am, Boris Borcic <[EMAIL PROTECTED]> wrote: David C. Ullrich wrote: (ii) If A is a subset of B then we should have max(A) <= max(B). This requires that max(empty set) be something that's smaller than everything else. So we give up on that.

Re: max(), sum(), next()

2008-09-08 Thread Boris Borcic
David C. Ullrich wrote: (ii) If A is a subset of B then we should have max(A) <= max(B). This requires that max(empty set) be something that's smaller than everything else. So we give up on that. Er, what about instances of variations/elaborations on class Smaller(object) : __cmp__ = lambda

Re: Lining Up and PaddingTwo Similar Lists

2008-08-29 Thread Boris Borcic
D,T=[dict((x.split('.')[0],x) for x in X) for X in (dat,txt)] for k in sorted(set(D).union(T)) : for S in D,T : print '%-8s' % S.get(k,'None'), print HTH W. eWatson wrote: Maybe there's some function like zip or map that does this. If not, it's probably fairly easy to do with pu

Re: like a "for loop" for a string

2008-08-18 Thread Boris Borcic
Alexnb wrote: Uhm, "string" and "non-string" are just that, words within the string. Here shall I dumb it down for you? string = "yes text1 yes text2 yes text3 no text4 yes text5+more Text yes text6 no text7 yes text8" It doesn't matter what is in the string, I want to be able to know exactly

Re: Is there a faster way to do this?

2008-08-06 Thread Boris Borcic
Is your product ID always the 3rd and last item on the line ? Else your output won't separate IDs. And how does output = open(output_file,'w') for x in set(line.split(',')[2] for line in open(input_file)) : output.write(x) output.close() behave ? [EMAIL PROTECTED] wrote: I have a csv fil

Re: 2d graphics - what module to use?

2008-07-25 Thread Boris Borcic
Pierre Dagenais wrote: What is the easiest way to draw to a window? I'd like to draw something like sine waves from a mathematical equation. Newbie to python. -- http://mail.python.org/mailman/listinfo/python-list For very simple things, the standard module turtle might be your best bet. BB

Re: listcomprehension, add elements?

2008-06-23 Thread Boris Borcic
John Machin wrote: Instead of sum(a + b for a, b in zip(foo, bar)) why not use sum(foo) + sum(bar) ? or even sum(foo+bar) as may apply. Cheers, BB -- http://mail.python.org/mailman/listinfo/python-list

Re: slicing lists

2008-05-08 Thread Boris Borcic
Yves Dorfsman wrote: So would it be a worthy addition to python, to add it right in the core of the language, and hopefully in an efficient manner ? Note that the s[0,2:6] syntax is currently allowed because of the distinct semantics that the Numeric module and its successors numarray and

Re: parameters to lambda's executed at run time.

2008-05-06 Thread Boris Borcic
One way : >>> from functools import partial >>> def func(item) : print item >>> llist = [partial(func,item) for item in range(5)] >>> for thing in llist : thing() 0 1 2 3 4 wyleu wrote: I'm trying to supply parameters to a function that is called at a later time as in the code below: llist

Re: computing with characters

2008-05-06 Thread Boris Borcic
Duncan Booth wrote: Torsten Bronger <[EMAIL PROTECTED]> wrote: The biggest ugliness though is ",".join(). No idea why this should be better than join(list, separator=" "). Besides, ",".join(u"x") yields an unicode object. This is confusing (but will probably go away with Python 3). It is o

Re: get number that is raised to the power of

2008-05-02 Thread Boris Borcic
Marc 'BlackJack' Rintsch wrote: On Fri, 02 May 2008 19:19:07 +1000, Astan Chee wrote: Hi, Im not sure if this is more of a math question or a python question. I have a variable in python: >>> v = 10.0**n is there a way to find the value of n if i know only v aside from str(v).split('+')[1]

Re: __iter__ yield

2008-03-10 Thread Boris Borcic
Paul Hankin wrote: > On Mar 10, 3:12 am, George Sakkis <[EMAIL PROTECTED]> wrote: >> On Mar 9, 7:37 pm, Paul Hankin <[EMAIL PROTECTED]> wrote: >> >> >> >>> On Mar 9, 8:58 pm, duccio <[EMAIL PROTECTED]> wrote: Someone knows if it's possible to make this __iter__ function with just one 'yie

Re: Making string-formatting smarter by handling generators?

2008-02-27 Thread Boris Borcic
D'Arcy J.M. Cain wrote: >> I find I hit it mostly with calls to map() where I want to apply >> some transform (as above) to all the items in a list of >> parameters such as >> >>"%s=%s&%s=%s" % map(urllib.quote, params) > > Isn't map() deprecated? The above can be done with; > > "%s=%s

Re: Is crawling the stack "bad"? Why?

2008-02-25 Thread Boris Borcic
Paul Rubin wrote: > Russell Warren <[EMAIL PROTECTED]> writes: >> That is exactly where I started (creating my own request handler, >> snagging the IP address and stashing it), but I couldn't come up with >> a stash location that would work for a threaded server. > > How about a dictionary indexed

Re: Simple - looking for a way to do an element exists check..

2008-02-23 Thread Boris Ozegovic
TeroV wrote: > It isn't list comprehension, it is generator expression > http://en.wikipedia.org/wiki/Python_syntax_and_semantics#Generator_expressions Nice. :) -- http://mail.python.org/mailman/listinfo/python-list

Re: Simple - looking for a way to do an element exists check..

2008-02-23 Thread Boris Ozegovic
Paul Rubin wrote: > if any(x[0]==element[0] for x in a): How come this list comprehension isn't in [] brackets? -- http://mail.python.org/mailman/listinfo/python-list

Re: Pydev, Eclipse

2008-02-22 Thread Boris Ozegovic
Preston Landers wrote: > Shift-Tab does it for me. It can also dedent whole blocks if you have > them selected. Excellent. Thank you. -- http://mail.python.org/mailman/listinfo/python-list

Pydev, Eclipse

2008-02-22 Thread Boris Ozegovic
Hi Suppose I have three blocks: if 1: if 2: if 3: # here I want my cursor go back to second block (if 2:) What is the standard shortcut for this? ctrl+arrow keys aren't, arrow keys alone aren't either. -- http://mail.python.org/mailman/listinfo/python-li

Re: Seemingly odd 'is' comparison.

2008-02-19 Thread Boris Borcic
Duncan Booth wrote: > Boris Borcic <[EMAIL PROTECTED]> wrote: >> Arnaud Delobelle wrote: >>> Whereas when "3.0*1.0 is 3.0" is evaluated, *two* different float >>> objects are put on the stack and compared (LOAD_CONST 3 / LOAD_CONST >>> 1 / COM

Re: Seemingly odd 'is' comparison.

2008-02-19 Thread Boris Borcic
Arnaud Delobelle wrote: > On Feb 13, 10:19 pm, Tobiah <[EMAIL PROTECTED]> wrote: > print float(3.0) is float(3.0) >> True > print float(3.0 * 1.0) is float(3.0) >> False > > [You don't need to wrap your floats in float()] > def f(): > ... return 3.0 is 3.0, 3.0*1.0 is 3.0 > ... >

Re: flattening a dict

2008-02-19 Thread Boris Borcic
Duncan Booth wrote: > In this particular case I think the lambda does contribute to the > obfuscation. Yes, they are single expressions, but only because that > have been contorted to become single expressions. The first two return > generators, so if you don't force them into a lambda you can wr

Re: flattening a dict

2008-02-18 Thread Boris Borcic
Duncan Booth wrote: > Boris Borcic <[EMAIL PROTECTED]> wrote: > >> It is more elementary in the mathematician's sense, and therefore >> preferable all other things being equal, imo. I've tried to split >> 'gen' but I can't say the result is s

Re: flattening a dict

2008-02-18 Thread Boris Borcic
Arnaud Delobelle wrote: > On Feb 17, 4:03 pm, Boris Borcic <[EMAIL PROTECTED]> wrote: >> George Sakkis wrote: >>> On Feb 17, 7:51 am, Arnaud Delobelle <[EMAIL PROTECTED]> wrote: >>>> BTW, I keep using the idiom itertools.chain(*iterable). I guess that

Re: flattening a dict

2008-02-17 Thread Boris Borcic
George Sakkis wrote: > On Feb 17, 7:51 am, Arnaud Delobelle <[EMAIL PROTECTED]> wrote: > >> BTW, I keep using the idiom itertools.chain(*iterable). I guess that >> during function calls *iterable gets expanded to a tuple. Wouldn't it >> be nice to have an equivalent one-argument function that ta

Re: flattening a dict

2008-02-17 Thread Boris Borcic
Arnaud Delobelle wrote: > > In Python you can do anything, even ...pass the Turing test with a one-liner. Back after 9/11, when US patriotism was the rage, Python knew how to answer correctly the query filter(lambda W : W not in 'ILLITERATE','BULLSHIT') And Python 3.0 slated for next August o

Re: An idea for fast function composition

2008-02-16 Thread Boris Borcic
[EMAIL PROTECTED] wrote: > On Feb 16, 3:47 pm, Arnaud Delobelle <[EMAIL PROTECTED]> wrote: >> Hi all, >> >> Recently there was a thread about function composition in Python (and >> this was probably not the first). The fast way to create a >> (anonymous) composite function >> >> f1 o f2 o ...

Re: ways to declare empty set variable

2008-02-16 Thread Boris Borcic
Steve Holden wrote: > Boris Borcic wrote: >> [EMAIL PROTECTED] wrote: >>> ...Missing that, I think dict() and set() and >>> tuple() and list() look better than using {} for the empty dict and >>> {/} for the empty set and () for empty tuple (or {} for the empty

Re: ways to declare empty set variable

2008-02-16 Thread Boris Borcic
[EMAIL PROTECTED] wrote: > > ...Missing that, I think dict() and set() and > tuple() and list() look better than using {} for the empty dict and > {/} for the empty set and () for empty tuple (or {} for the empty dict > and set() for the empty set). The problem I have with them is in no way the l

Re: How to identify which numbers in a list are within each others' range

2008-02-08 Thread Boris Borcic
Boris Borcic wrote: > Arnaud Delobelle wrote: > (...) >> >> from itertools import chain >> >> def overlaps(lst): >> bounds = chain(*(((x[1],i), (x[2], i)) for i,x in enumerate(lst))) > > imho, this is a uselessly painful equivalent of > >

Re: How to identify which numbers in a list are within each others' range

2008-02-08 Thread Boris Borcic
Arnaud Delobelle wrote: (...) > > from itertools import chain > > def overlaps(lst): > bounds = chain(*(((x[1],i), (x[2], i)) for i,x in enumerate(lst))) imho, this is a uselessly painful equivalent of bounds = ((x[k],i) for i,x in enumerate(lst) for k in (1,2)) Cheers, BB -- http:

Re: future multi-threading for-loops

2008-02-05 Thread Boris Borcic
[EMAIL PROTECTED] wrote: > On Feb 5, 12:26 am, Gabriel Genellina <[EMAIL PROTECTED]> wrote: >> On 5 feb, 03:46, [EMAIL PROTECTED] wrote: >> >>> Some timing stats: On Windows XP, Python 3.0a2. (...) >>> Are threads an OS bottleneck? >> I don't understand your threading issues, but I would not use 3.

Re: find nearest time in datetime list

2008-01-30 Thread Boris Borcic
washakie wrote: > Hello, > > I have a list of datetime objects: DTlist, I have another single datetime > object: dt, ... I need to find the nearest DTlist[i] to the dt is > there a simple way to do this? There isn't necessarily an exact match... > > Thanks! > .john > min(DTlist,key=lambd

Re: optional static typing for Python

2008-01-28 Thread Boris Borcic
Wish you'd opted out of typing all that static. BB Russ P. wrote: (...) > > What is that supposed to mean? > > Oh, I almost forgot. I'm supposed to sit here and be polite while > clueless dolts make wise cracks. Sorry, but I haven't yet mastered > that level of self-control. > > I would just l

Re: Python self-evaluating strings

2008-01-27 Thread Boris Borcic
Now there's always that style : >>> print x Traceback (most recent call last): File "", line 1, in eval(x) File "", line 2 Traceback (most recent call last): ^ SyntaxError: invalid syntax >>> eval(x) Traceback (most recent call last): File "", lin

Re: sudoku solver in Python ...

2008-01-25 Thread Boris Borcic
er for unknowns. Returns same with values filled in. > > Beware that although in practice it solved all well-formed > human-solvable problems I could find, it is not guaranteed to deal > properly (or even terminate?) for underdetermined problems or determined > problems that wou

Re: sudoku solver in Python ...

2008-01-24 Thread Boris Borcic
for unknowns. Returns same with values filled in. Beware that although in practice it solved all well-formed human-solvable problems I could find, it is not guaranteed to deal properly (or even terminate?) for underdetermined problems or determined problems that would require exploring choicepoin

Re: Why not 'foo = not f' instead of 'foo = (not f or 1) and 0'?

2008-01-23 Thread Boris Borcic
I am surprised nobody pointed out explicitely that True==1 and False==0 so that for instance 5*(True+True)==10 and even (but implementation-dependent) : 5*(True+True) is 10 BB -- http://mail.python.org/mailman/listinfo/python-list

Using utidylib, empty string returned in some cases

2008-01-22 Thread Boris
Hello I'm using debian linux, Python 2.4.4, and utidylib (http:// utidylib.berlios.de/). I wrote simple functions to get a web page, convert it from windows-1251 to utf8 and then I'd like to clean html with it. Here is two pages I use to check my program: http://www.ya.ru/ (in this case everythin

Re: convert pdf to png

2007-12-26 Thread Boris Borcic
Carl K wrote: > Rob Wolfe wrote: >> Carl K <[EMAIL PROTECTED]> writes: >> >>> I need to take the take the pdf output from reportlab and create a >>> preview image for a web page. so png or something. I am sure >>> ghostscript will be involved. I am guessing PIL or ImageMagic ? >>> >>> all sugesti

  1   2   3   >