Re: Clever hack or code abomination?

2011-12-01 Thread Vito 'ZeD' De Tullio
i in xrange(-1, -20, -1)]: >> > > It's a little obfuscated ;) I would go for the simple: > > for i in xrange(21): > suffix = "-%s" % i if i else "" > > obfuscated for obfuscated, you can merge the two ideas: for suffix in ('-%s' % i if i else '' for i in xrange(21)): ... -- By ZeD -- http://mail.python.org/mailman/listinfo/python-list

FYI

2011-09-09 Thread Vito 'ZeD' De Tullio
http://scummos.blogspot.com/2011/09/kdev-python-argument-type-guessing.html I'm not used to big ide/rad for python... but I think this work is excellent! Are there alternatives (pydev? others?) capable of this sort of thinks (I mean "guessing the type" and method autocomple

Re: allow line break at operators

2011-08-11 Thread Vito 'ZeD' De Tullio
uch any other serious "programmer editor" program try to do its best to deal with line wrap: the minimal I found is the wrapped line is "indented" at the same level of the flow, but I found editors where you can specify what to do (generally something like "indent the wra

Re: how to separate a list into two lists?

2011-08-06 Thread Vito 'ZeD' De Tullio
David Robinow wrote: > On Sat, Aug 6, 2011 at 1:23 PM, Kabie wrote: >> No. >> L1, L2 = zip(*L) > > Not quite. That makes L1 & L2 tuples. > > L1, L2 = zip(*L) > L1 = list(L1) > L2 = list(L2) > ??? L1, L2 = map(list, zip(*L)) -- By ZeD -- http://mail.python.org/mailman/listinfo/python-list

Re: What is this syntax ?

2011-06-19 Thread Vito 'ZeD' De Tullio
efined scheme, host, port, route and fragment? or you think also this is "code smell"? 2) I'm in no way modifying the dict, just accessing in read only. 3) I'm restricting to locals() :D btw I never used dict to format strings, so I learned how old this feature is :D -- By ZeD -- http://mail.python.org/mailman/listinfo/python-list

Re: What is this syntax ?

2011-06-19 Thread Vito 'ZeD' De Tullio
to line up the nth format specifier with the nth > data item. well, in python3 you can use dict to format strings >>> print("%(a)s" % {'a':'b'}) b and you can achieve php interpolation via locals() >>> a = 'b' >>> print("%(a)s" % locals()) b -- By ZeD -- http://mail.python.org/mailman/listinfo/python-list

Re: announcing: dmangame: an ai game. maybe.

2011-06-06 Thread okay zed
could be the ACM queue challenge and google's ai challenge, they've had games in the past with somewhat similar mechanics On Jun 5, 11:10 pm, James Mills wrote: > On Mon, Jun 6, 2011 at 3:50 PM, okay zed wrote: > > the link:http://okayzed.github.com/dmangame/introduction.

announcing: dmangame: an ai game. maybe.

2011-06-05 Thread okay zed
the link: http://okayzed.github.com/dmangame/introduction.html dmangame is a game about writing AI for a simple strategy game. an example game: http://okayzed.github.com/dmangame/circleblaster_vs_expand.html there are some example / more advanced AI in the dmanai repository (http://github.com/ok

Re: Lambda question

2011-06-04 Thread Vito 'ZeD' De Tullio
jyoun...@kc.rr.com wrote: > I was surfing around looking for a way to split a list into equal > sections. non-recursive, same-unreadeable (worse?) one liner alternative: def chunks(s, j): return [''.join(filter(None,c))for c in map(None,*(s[i::j]for i in range(j)))] --

Re: True lists in python?

2010-12-19 Thread Vito 'ZeD' De Tullio
;reversed' ll.reversed = True n = n_previous while n is not None: print n.value n = n.nextNode() if __name__ == '__main__': main() -- By ZeD -- http://mail.python.org/mailman/listinfo/python-list

Re: True lists in python?

2010-12-18 Thread Vito 'ZeD' De Tullio
ake a look at the deque[0] module. If you want "true lists" (um... "linked list"?) there are is this recipe[1] you might look. [0] http://docs.python.org/library/collections.html#collections.deque [1] http://code.activestate.com/recipes/577355-python-27-linked-list-vs- l

Re: How on Factorial

2010-11-01 Thread Vito 'ZeD' De Tullio
Lawrence D'Oliveiro wrote: > You know what, I think I actually prefer the trick to Python’s > backwards-if syntax... fact = lambda x: x*fact(x-1) if x>1 else 1 naa, it's not too bad... -- By ZeD -- http://mail.python.org/mailman/listinfo/python-list

Request For Comments: Learn Python The Hard Way

2010-09-28 Thread Zed Shaw
about the approach I took with the book and what you think. Thanks for your time. Zed P.S. The book is totally free so long as you don't charge for it and you don't change it or break it up. Thanks. -- http://mail.python.org/mailman/listinfo/python-list

Re: bug in python documentation?

2010-09-11 Thread Vito 'ZeD' De Tullio
Benjamin Kaplan wrote: > You're looking at the 2.7 documentation. Are you using 2.7? whoops, no: 2.6.5 :\ (but the "new in python X.Y.Z" disclaimer does not apply to the example snippets?) -- By ZeD -- http://mail.python.org/mailman/listinfo/python-list

bug in python documentation?

2010-09-11 Thread Vito 'ZeD' De Tullio
Traceback (most recent call last): File "./test_data_manip.py", line 23, in test_sample with self.assertRaises(ValueError): TypeError: failUnlessRaises() takes at least 3 arguments (2 given) --------

Beyond the moratorium

2010-08-11 Thread Vito 'ZeD' De Tullio
n erlang-style "bang" (!) process message passing? -- By ZeD -- http://mail.python.org/mailman/listinfo/python-list

Re: Python "why" questions

2010-08-06 Thread Vito 'ZeD' De Tullio
ne --obvious way to do it." > 3) In Python 3, why does 2.0 / 3.0 display as 0., but 8 * > 3.57 displays as 28.56 (rounded off to 2 decimal places)? And yet, in > Python 2.6, 8 * 3.57 displays as 28.559? http://mail.python.org/pipermail/python-dev/200

Re: easy question on parsing python: "is not None"

2010-08-06 Thread Vito 'ZeD' De Tullio
tion" of python: one for each release of CPython (2.0, 2.1.2, 2.6.1, 3.x.y...), multiplied for each OS multiplied for IronPython, Jython, Pypy... etc... (obviously the "implementation details" between, say, CPython 2.6.1 and 2.6.2 are really minor vs Pypy X.Y.Z and IronPython A.B

Re: python command line manual

2010-05-24 Thread Vito 'ZeD' De Tullio
Peng Yu wrote: > I mainly check online python manual. But I feel that it would be nice > if there is command line manual available (just like perl command line > manual). Could you please let me know if such command line manual > available? pydoc? -- By ZeD -- http://mail.python

Re: condition and True or False

2010-05-02 Thread Vito 'ZeD' De Tullio
n bool(big_beast)? -- By ZeD -- http://mail.python.org/mailman/listinfo/python-list

Re: subtraction is giving me a syntax error

2010-03-16 Thread Vito 'ZeD' De Tullio
etween (say) ??? ??? and -. > > My point is that if it's an ASCII file, source files aren't (necessary) ASCII files -- By ZeD -- http://mail.python.org/mailman/listinfo/python-list

Re: detect interactivity

2009-12-30 Thread Vito 'ZeD' De Tullio
Steven D'Aprano wrote: >> if I run 'python <<< "import sys; print(sys.ps1)"', I get an error. > > Of course you do, because you're not running interactively Excuse me, why do you say that? -- By ZeD -- http://mail.python.org/mailman/listinfo/python-list

]ANN[ Vellum 0.16: Lots Of Documentation and Watching

2008-04-29 Thread Zed A. Shaw
ed to release the commands. However, I'm curious to get other people's thoughts. Thanks a bunch folks. -- Zed A. Shaw - Hate: http://savingtheinternetwithhate.com/ - Good: http://www.zedshaw.com/ - Evil: http://yearofevil.com/ -- http://mail.python.org/mailman/listinfo/python-list

[ANN] Vellum 0.13: Simple Python Build Tool (usable now)

2008-04-16 Thread Zed A. Shaw
DBACK Let me know if you run into anything, and if you like it or hate it. Otherwise, enjoy the gear. -- Zed A. Shaw - Hate: http://savingtheinternetwithhate.com/ - Good: http://www.zedshaw.com/ - Evil: http://yearofevil.com/ -- http://mail.python.org/mailman/listinfo/python-list

[ANN] Vellum 0.8: No More YAML, Some Python

2008-04-05 Thread Zed A. Shaw
nts are welcome, especially about the actual safety of the code in vellum/parser.g and vellum/parser.py (generated by Zapps). Have fun. -- Zed A. Shaw - Hate: http://savingtheinternetwithhate.com/ - Good: http://www.zedshaw.com/ - Evil: http://yearofevil.com/ -- http://mail.python.org/mailman/

[ANN] Vellum 0.7: Simple Python Can Build Many Things

2008-04-01 Thread Zed A. Shaw
or send me patches. Suggested features that don't involve major changes are more than welcome. == NEXT FEATURES * A few recipes to make building common stuff easy, like generating setup.py and so on. * A way to load modules from trusted locations. * Documentation, built with Vellum and Id

[ANN] Vellum 0.4 (it builds things, mostly books)

2008-03-31 Thread Zed A. Shaw
the core of the project are on the above page. Since I'm a total Python newbie, I'd love any advice about my code I can get. Thanks much. -- Zed A. Shaw - Hate: http://savingtheinternetwithhate.com/ - Good: http://www.zedshaw.com/ - Evil: http://yearofevil.com/ -- http://mail.python.org/mailman/listinfo/python-list

Re: Cheat sheet

2007-12-29 Thread ZeD
Michele Simionato wrote: > Python 2.4.4 (#2, Oct 4 2007, 22:02:31) file is open > True > > Python 2.5.1 (r251:54863, Oct 5 2007, 13:36:32) file is open > False > > Nowadays file is no more an alias for open. curious... maybe it's me, but I can't find a "What's New in Python" where t

Re: Loops and things

2007-12-15 Thread ZeD
Jair Trejo wrote: > I was wondering how and if it's possible to write a > loop in python > which updates two or more variables at a time. For > instance, something > like this in C: > > for (i = 0, j = 10; i < 10 && j < 20; i++, j++) { > printf("i = %d, j = %d\n", i, j); > } >>> for i,j in z

Re: eof

2007-11-26 Thread ZeD
Grant Edwards wrote: > The user-defined xor is operates on "logical" boolean values. > The one in the operator module is a bitwise operator. def xor(a, b): return bool(a) ^ bool(b) seems more explicit to me. maybe, to make "more" explicit (too much, onestly...) from operator import xor as b

Re: sorting a list numbers stored as strings

2007-09-25 Thread ZeD
thebjorn wrote: >> >>> int("020") >> 20 >> >>> 020 >> 16 > > You can get the latter behavior using eval: why using eval when int has the "base" optional parameter? >>> int("020") 20 >>> int("020", 8) 16 >>> int("09", 8) Traceback (most recent call last): File "", line 1, in ValueError: inval

Re: generate list of partially accumulated values

2007-09-16 Thread ZeD
cesco wrote: > The list is composed of objects: > l = [obj1, obj2, obj3, obj4] > and I need to call a method (say method1) on each object as follow: > l1 = [obj1.method1(obj2), obj2.method1(obj3), obj3.method1(obj4), > obj4] to me it sounds a bit different from the original request, but... > Is

Re: List Comprehension Question: One to Many Mapping?

2007-08-24 Thread ZeD
Boris Borcic wrote: >>> For example, if I have x=[ [1,2], [3,4] ] >>> What I want is a new list of list that has four sub-lists: >>> [[1,2], [f(1), f(2)], [3,4], [f(3), f(4)]] >> [[a, map(f,a)] for a in x] > [map(g,a) for a in x for g in [None,f]] > will do it. > > ...a bit too cleverly, but ther

Re: alternative to eclipse [ python ide AND cvs ]

2007-05-17 Thread ZeD
yomgui wrote: > I use eclipse for python and cvs, what is "the" good alternative ? "the" good alternative, I dont know. But a good solution is eric3 (http://www.die-offenbachs.de/detlev/eric.html) -- Under construction -- http://mail.python.org/mailman/listinfo/python-list

Re: PEP 3131: Supporting Non-ASCII Identifiers

2007-05-14 Thread ZeD
Neil Hodgson wrote: > Ada 2005 allows Unicode identifiers and even includes the constant > '?' in Ada.Numerics. this. is. cool. (oh, and +1 for the pep) -- Under construction -- http://mail.python.org/mailman/listinfo/python-list

Re: track cpu usage of linux application

2007-05-14 Thread Zed A. Shaw
Using this you can find out anything you need with just basic file operations. Use: man proc to find our more. -- Zed A. Shaw - Hate: http://savingtheinternetwithhate.com/ - Good: http://www.zedshaw.com/ - Evil: http://yearofevil.com/ -- http://mail.python.org/mailman/listinfo/python-list

Re: Standardizing XML

2007-04-15 Thread ZeD
ZeeGeek wrote: > in the code returned by Live Space, they use instead of so > that Blogger will complain that this tag is not valid because it > doesn't have a closing tag. Another example is that the contents of a > lot of the tag attributes like "color" and "size" are not surrounded > by quot

Re: How to find all the same words in a text?

2007-02-10 Thread ZeD
Johny wrote: >> >Let suppose I want to find a number 324 in the text >> >> >'45 324 45324' >> >> >there is only one occurrence of 324 word but string.find() finds 2 >> >occurrences ( in 45324 too) >> >> >>> '45 324 45324'.split().count('324') >> 1 >> >>> >> >> ciao > Marco, > Th

Re: Splitting lines from a database query

2006-12-26 Thread ZeD
Peter Machell wrote: > I have an application where I need to take a query from an existing > database and send it to a web api. [...] > There are always 5 values, but some are blank and some are 'None'. > I'd like to split the lines so I get something resembling XML, like this: > Frank > Spencer

Re: problem about list indexing

2006-11-26 Thread ZeD
hollowspook wrote: > how about indexing 1-7, 10 > [range(1:8),10] will generate [[1, 2, 3, 4, 5, 6, 7], 10], instead of > [1, 2, 3, 4, 5, 6, 7, 10] >>> range(1,8)+[10] [1, 2, 3, 4, 5, 6, 7, 10] -- Under construction -- http://mail.python.org/mailman/listinfo/python-list

Re: tab compleation input

2006-11-13 Thread ZeD
Eli Criffield wrote: > Here is what i want to do. I have a question in my program, and i want > to do tab completion for the valid answers. I think you may "play" width curses library: readline() read... while you input a "newline", but you need to catch single keys (the "TAB" key, foremost) --

Re: Sorting by item_in_another_list

2006-10-24 Thread ZeD
Paul Rubin wrote: >> A = [0,1,2,3,4,5,6,7,8,9,10] >> B = [2,3,7,8] >> >> desired_result = [2,3,7,8,0,1,4,5,6,9,10] > > How about: > > desired_result = B + sorted(x for x in A if x not in B) this. is. cool. -- Under construction -- http://mail.python.org/mailman/listinfo/python-list

Re: Input from the same file as the script

2006-08-21 Thread ZeD
Dennis Lee Bieber wrote: >> Can the input to the python script be given from the same file as the >> script itself. e.g., when we execute a python script with the command >> 'python > > Redirecting? Ugh... > > Off-hand, I'd say NO > > There is no way to tell the python interpreter where the pro

Re: #!/usr/bin/python or #!/usr/bin/env python?

2006-08-09 Thread ZeD
Erik Max Francis wrote: > The file _is_ a /bin/sh executable. You're just having that /bin/sh > executable run something else -- how could `file` figure that out > without a ridiculously complicated set of rules that rise to the level > of a sh interpreter -- thereby, defeating the purpose? but.

Re: #!/usr/bin/python or #!/usr/bin/env python?

2006-08-09 Thread ZeD
Stephan Kuhagen wrote: >> #!/bin/sh >> """exec" python "$0" "$@""" > > Wow, cool... I like that! yeah, but... $ cat test.py #!/bin/sh """exec" python "$0" "$@""" print "Hello, world" $ file test.py test.py: Bourne shell script text executable -- Under construction -- http://mail.python.org/

Re: Accessors in Python (getters and setters)

2006-07-10 Thread ZeD
Bruno Desthuilliers wrote: >> I decided to change the name of an attribute. Problem is I've used the >> attribute in several places spanning thousands of lines of code. If I >> had encapsulated the attribute via an accessor, I wouldn't need to do >> an unreliable and tedious search and replace > f

Re: Initializing a list of lists

2006-03-19 Thread ZeD
Ciao, [EMAIL PROTECTED] Che stavi dicendo? > Is there a simple way to create a list of independent lists? N=3 x=[[0] for e in range(N)] -- Up da 1 giorno, 3 ore, 43 minuti e 10 secondi -- http://mail.python.org/mailman/listinfo/python-list

Re: how to write a C-style for loop?

2006-02-15 Thread ZeD
Ciao, John Salerno! Che stavi dicendo? > for (int i = 0; i < 50; i += 5) > > How would that go in Python, in the simplest and most efficient way? i=0 while i<50: #... i+=5 about range()/xrange(): what if you want to traslate this c-loop? for (int i=1; i<50; i*=2) -- Evangelion e' la s

Re: line wrapping problem

2006-02-09 Thread ZeD
Ciao, Juho Schultz! Che stavi dicendo? > should work. IMO file.write() is self-explanatory but "print >> file" is > a bit obscure. is obscure only if you have never used a shell :) -- Evangelion e' la storia yaoi di un angelo che vuole portarsi a letto un ragazzo che si intreccia con la storia

Re: zip unzip?

2005-12-28 Thread ZeD
Ciao, KraftDiner! Che stavi dicendo? > I have two lists... > > a=[1,2,3] > b=[4,5,6] > > n=0 > for i in a: >print i, b[n] >n=n+1 > > how can i have two iterators on my for loop? for i,j in zip(a,b): print i,j -- Quante sono le persone che sanno leggere il codice esadecim

Re: python coding contest

2005-12-27 Thread ZeD
Ciao, Shane Hathaway! Che stavi dicendo? > I'm down to 133 characters (counted according to 'wc -c') on a single > line. It contains about 11 whitespace characters (depending on what you > consider whitespace.) $ wc -c seven_seg.py 137 seven_seg.py $ sed 's/ //g' seven_seg.py|wc -c 120 (yeah, to