Re: Problem with slow httplib connections on Windows (and maybe other platforms)

2009-02-01 Thread Christoph Zwerschke
Steve Holden schrieb: Search for the subject line "socket.create_connection slow" - this was discovered by Kristjan Valur Jonsson. It certainly seems like a Microsoft weirdness. Thanks for the pointer, Steve. I hadn't seen that yet. I agree that's actually the real problem here. The solution s

Re: Problem with slow httplib connections on Windows (and maybe other platforms)

2009-02-01 Thread Christoph Zwerschke
rdmur...@bitdance.com schrieb: Quoth Christoph Zwerschke : With Py 2.3 (without IPv6 support) this is only the IPv4 address, but with Py 2.4-2.6 the order is (on my Win XP host) the IPv6 address first, then the IPv4 address. Since the IPv6 address is checked first, this gives a

Problem with slow httplib connections on Windows (and maybe other platforms)

2009-02-01 Thread Christoph Zwerschke
It cost me a while to analyze the cause of the following problem. The symptom was that testing a local web app with twill was fast on Python 2.3, but very slow on Python 2.4-2.6 on a Win XP box. This boiled down to the problem that if you run a SimpleHTTPServer for localhost like this, BaseHT

Re: Missing exceptions in PEP 3107

2008-08-17 Thread Christoph Zwerschke
Carl Banks wrote: If it bothers you that much, go file a bug report. Someone might even change it. But it's nothing but needless pedantry. Has my "de" domain inspired you to rant about "pedantry"? No, it does not bother me that much. I just thought the PEP could be clearer here and explicit

Re: Missing exceptions in PEP 3107

2008-08-17 Thread Christoph Zwerschke
Terry Reedy wrote: > I would agree... but... > The problem is that code that uses a function hardly cares whether an > exception that replaces the normal return is raised explicitly, by a > syntax operation (and these are not yet completely documented, though > perhaps they should be), or by a fun

Re: Missing exceptions in PEP 3107

2008-08-17 Thread Christoph Zwerschke
Carl Banks schrieb: You are free to use it for other things. For example, the following usage is obvious and sensible (insofar as listing exceptions is sensible): def f(x : int) -> int, raises(TypeError) Think of the return value annotation as more of a function outcome annotation. That's fi

Re: Missing exceptions in PEP 3107

2008-08-15 Thread Christoph Zwerschke
Carl Banks wrote: > I think you're missing the point here. PEP 3017 is policy-neutral: > it describes a mechanism to annotate functions and arguments, > and that's it. That's not quite true: PEP 3017 describes a mechanism for annotating function parameters *and return values*, and my point was w

Re: Missing exceptions in PEP 3107

2008-08-15 Thread Christoph Zwerschke
Matimus wrote: > Christoph wrote: >> Maybe the following syntax would be even more intuitive: >> >> def foo(a: "a info", b: "b info") return "ret info" raise "exc info": >> return "hello world" > > That seems much more intuitive and extensible. The "->" syntax has > always bothered me. The

Re: Missing exceptions in PEP 3107

2008-08-10 Thread Christoph Zwerschke
Duncan Booth schrieb: There is no currently recommended way to make such annotations, so how could the PEP mention it? Then it could mention the fact that there is currently no recommended way (and maybe make some suggestions, like those given by you). -- http://mail.python.org/mailman/listin

Re: Missing exceptions in PEP 3107

2008-08-10 Thread Christoph Zwerschke
Duncan Booth wrote: If you really want this then you can use a decorator to insert a 'raise' key into the annotations: Well, yes, but wasn't the whole point of PEP 3107 to get rid of such decorators and provide a single standard way of specifying this kind of info instead? I don't know how

Re: Missing exceptions in PEP 3107

2008-08-10 Thread Christoph Zwerschke
Matimus schrieb: The expr in that "raises" clause should be a list of Exceptions. You are clearly confusing the annotation feature with a possible application of the annotation feature. Annotation could be used for many different applications besides type safety. Sorry, I wanted to say "*coul

Missing exceptions in PEP 3107

2008-08-09 Thread Christoph Zwerschke
I'm just reading PEP 3107 (function annotations) and wonder why exceptions are not mentioned there. I think it would be helpful if one could specify which exceptions can be raised by a function, similarly to how it is possible in C++ using the "throw" clause. The syntax would be something like

Re: strip() using strings instead of chars

2008-07-12 Thread Christoph Zwerschke
Duncan Booth schrieb: if url.startswith('http://'): url = url[7:] If I came across this code I'd want to know why they weren't using urlparse.urlsplit()... Right, such code can have a smell since in the case of urls, file names, config options etc. there are specialized functions avail

Re: strip() using strings instead of chars

2008-07-11 Thread Christoph Zwerschke
Bruno Desthuilliers schrieb: DRY/SPOT violation. Should be written as : prefix = 'http://' if url.startswith(prefix): url = url[len(prefix):] That was exactly my point. This formulation is a bit better, but it still violates DRY, because you need to type "prefix" two times. It is exac

strip() using strings instead of chars

2008-07-11 Thread Christoph Zwerschke
In Python programs, you will quite frequently find code like the following for removing a certain prefix from a string: if url.startswith('http://'): url = url[7:] Similarly for stripping suffixes: if filename.endswith('.html'): filename = filename[:-5] My problem with this is that it'

Re: First post from a Python newbiw

2008-03-03 Thread Christoph Zwerschke
Arnaud Delobelle schrieb: > It's a FAQ: > http://www.python.org/doc/faq/programming/#how-do-i-create-a-multidimensional-list Somewhere on my todo list I have "read through the whole Python FAQ", but so far never got round doing it. Should probably set it to prio A. -- Christoph -- http://mail.p

Re: tuples, index method, Python's design

2008-03-02 Thread Christoph Zwerschke
Paul Boddie schrieb: > On 2 Mar, 19:06, Alan Isaac <[EMAIL PROTECTED]> wrote: >> On April 12th, 2007 at 10:05 PM Alan Isaac wrote: >> >>> The avoidance of tuples, so carefully defended in other >>> terms, is often rooted (I claim) in habits formed from >>> need for list methods like ``index`` and `

Re: First post from a Python newbiw

2008-03-02 Thread Christoph Zwerschke
Marc 'BlackJack' Rintsch schrieb: > On Sun, 02 Mar 2008 14:15:09 +, Steve Turner wrote: > >> Apart from doing something like >> a=[0,0,0] >> b=[0,0,0] >> c=[0,0,0] >> d=[a,b,c] >> >> is there a better way of creating d?? > > a = [[0] * 3 for dummy in xrange(3)] Why not simply [[0]*3]*3 ? --

Re: Re-raising exceptions with modified message

2007-07-15 Thread Christoph Zwerschke
Christoph Zwerschke wrote: > Here is a simple solution, but it depends on the existence of the args > attribute that "will eventually be deprecated" according to the docs: Just found another amazingly simple solution that does neither use teh .args (docs: "will eve

Re: Re-raising exceptions with modified message

2007-07-15 Thread Christoph Zwerschke
Christoph Zwerschke wrote: > Here is a simple solution, but it depends on the existence of the args > attribute that "will eventually be deprecated" according to the docs: Ok, here is another solution that does not depend on args: def PoliteException(e): E = e.__cl

Re: Re-raising exceptions with modified message

2007-07-15 Thread Christoph Zwerschke
Christoph Zwerschke wrote: > But my __getattr__ solution does not work either, since the attributes > are set to None when initialized, so __getattr__ is never called. Here is a simple solution, but it depends on the existence of the args attribute that "will eventually be deprecated

Re: Re-raising exceptions with modified message

2007-07-15 Thread Christoph Zwerschke
samwyse wrote: > NewStyle.__name__ = old.__class__.__name__ Simple, but that does the trick! > new.__dict__ = old.__dict__.copy() Unfortunately, that does not work, since the attributes are not writeable and thus do not appear in __dict__. But my __getattr__ solution does not work either, si

Re: Re-raising exceptions with modified message

2007-07-12 Thread Christoph Zwerschke
samwyse wrote: > TypeError: __class__ must be set to a class > > Excpt ceratinly appears to be a class. Does anyone smarter than me > know what's going on here? Not that I want to appear smarter, but I think the problem here is that exceptions are new-style classes now, whereas Empty is an old-

Re: Re-raising exceptions with modified message

2007-07-08 Thread Christoph Zwerschke
samwyse wrote: > def test(code): > try: > code() > except Exception, e: > try: > raise e.__class__, str(e) + ", sorry!" > except TypeError: > raise SorryFactory(e)() Ok, you're suggestig the naive approach if it works and the factory approach I came up with last as a f

Re: Re-raising exceptions with modified message

2007-07-08 Thread Christoph Zwerschke
Did you run this? With Py < 2.5 I get a syntax error, and with Py 2.5 I get: new.__class__ = old.__class__ TypeError: __class__ must be set to a class -- Chris -- http://mail.python.org/mailman/listinfo/python-list

Re: Re-raising exceptions with modified message

2007-07-07 Thread Christoph Zwerschke
Gerard Flanagan wrote: > Would a decorator work here? Depends on how you want to use that functionality. In my use case I only need to catch the excpetion once. Note that in your code the exception has not the right type which is what I targeted in my last posting. I.e. the following will raise

Re: Re-raising exceptions with modified message

2007-07-05 Thread Christoph Zwerschke
Alex Popescu wrote: > Probably the simplest solution would be to create a new exception and > wrapping the old one and the additional info. Unfortunately, this > may have a huge impact on 3rd party code that was catching the > original exception. So, I think you should create an utility > factor

Re: Re-raising exceptions with modified message

2007-07-05 Thread Christoph Zwerschke
Sorry for the soliloquy, but what I am really using is the following so that the re-raised excpetion has the same type: def PoliteException(e): class PoliteException(e.__class__): def __init__(self, e): self._e = e def __getattr__(self, name): retu

Re: Re-raising exceptions with modified message

2007-07-05 Thread Christoph Zwerschke
Seems that no simple solution exists, so for now, I will be using something like this: class PoliteException(Exception): def __init__(self, e): self._e = e def __getattr__(self, name): return getattr(self._e, name) def __str__(self): if isinstance(self._e,

Re: Re-raising exceptions with modified message

2007-07-05 Thread Christoph Zwerschke
Kay Schluehr wrote: > If you are sure that the exception isn't caught on another level just > use the following showtraceback() function, manipulate it's output > slightly and terminate your program with sys.exit() That's what I want to avoid. In my case the error is displayed and evaluated in a

Re: Re-raising exceptions with modified message

2007-07-05 Thread Christoph Zwerschke
Neil Cerutti wrote: > You may need the traceback module to get at the error message, if > trying to read e.message can fail. > > Something like this mess here: ;) > >... >except Exception, e: > etype, evalue, etb = sys.exc_info() > ex = traceback.format_exception_only(etype, eva

Re: Proposal: s1.intersects(s2)

2007-07-05 Thread Christoph Zwerschke
Steven D'Aprano wrote: > I'm not a professional set theorist, but in 15-odd years of studying and > teaching maths I've never come across mathematicians using intersect as a > verb except as informal short-hand. I often say "North Street and South > Street don't intersect", but "the intersection of

Re: Proposal: s1.intersects(s2)

2007-07-05 Thread Christoph Zwerschke
Nis Jørgensen wrote: > The problem is, these functions can be read as "X is [consisting only > of] digit[s]", "X is lower [case]" etc, where the bits in brackets have > been removed for brewity. In the case of "s1 is intersect s2" there is > no way I can see of adding words to get a correct sentenc

Re: Re-raising exceptions with modified message

2007-07-05 Thread Christoph Zwerschke
Neil Cerutti wrote: > The documentation for BaseException contains something that might > be relevant: > >[...] If more data needs to be attached to the exception, >attach it through arbitrary attributes on the instance. All > > Users could get at the extra info you attached, but it wouldn

Re: Re-raising exceptions with modified message

2007-07-05 Thread Christoph Zwerschke
Thomas Heller wrote: > I have the impression that you do NOT want to change the exceptions, > instead you want to print the traceback in a customized way. But I may be > wrong... No, I really want to modify the exception, supplementing its message with additional information about the state of

Re-raising exceptions with modified message

2007-07-05 Thread Christoph Zwerschke
What is the best way to re-raise any exception with a message supplemented with additional information (e.g. line number in a template)? Let's say for simplicity I just want to add "sorry" to every exception message. My naive solution was this: try: ... except Exception, e: raise e.__

Re: Problem with reimporting modules

2007-02-11 Thread Christoph Zwerschke
Thanks for the detailed explanations, Gabriel. > At that time, all values in the module namespace are set to > None (for breaking possible cycles, I presume). print_hello now has a > func_globals with all names set to None. (Perhaps the names could have > been deleted instead, so print_hello()

Re: Problem with reimporting modules

2007-02-11 Thread Christoph Zwerschke
Yes I know about reload(), but TurboGears (TurboKid) does not use it and the docs say that removing modules from sys.module is possible to force reloading of modules. I don't want to rewrite everything since it's a pretty complex thing with modules which are compiled from templates which can de

Problem with reimporting modules

2007-02-11 Thread Christoph Zwerschke
I'm currently investigating a problem that can hit you in TurboGears when Kid template modules are reloaded in the background, because in certain situations, global variables suddenly are set to None values. I tracked it down to the following behavior of Python. Assume you have a module hello.p

Re: No latin9 in Python?

2006-12-17 Thread Christoph Zwerschke
Martin v. Löwis schrieb: > Christoph Zwerschke schrieb: >> Shall I proceed writing such a patch? Shall I also add latin0 and l0 >> which are other inofficial aliases? > > Sure, go ahead. I see no need for the latin0/l0 aliases, though: they > predate the formal adoption of

Re: tuple.index()

2006-12-16 Thread Christoph Zwerschke
James Stroud wrote: > Christoph Zwerschke wrote: >> Maybe there would be less dispute if this dogma/convention(?) "Tuples >> are for heterogeneous data, list are for homogeneous data" would be >> written down somewhere in the tutorial, reference or in PEP8, so

Re: tuple.index()

2006-12-16 Thread Christoph Zwerschke
Hendrik van Rooyen wrote: > From a practical point of view, the only reason to use a tuple instead > of a list for anything seems to be that you want to use it as a key in a > dict... > > Otherwise, why bother with these recalcitrant things that you can't > change or index, or append to or anythi

Re: tuple.index()

2006-12-15 Thread Christoph Zwerschke
Tim Golden wrote: > Christoph Zwerschke wrote: >> And can somebody explain what is exactly meant with >> "homogenous data"? > > This seems to have been explained a few times > recently :) Basically, if you have a "list of xs" > and remove one item

Re: No latin9 in Python?

2006-12-15 Thread Christoph Zwerschke
Martin v. Löwis wrote: > While you are at it, you'll notice that the current version of the > character-sets database lists > > Name: ISO-8859-15 > MIBenum: 111 > Source: ISO > Please see: > > Alias: ISO_8859-15 > Alias: Latin-9 >

Re: tuple.index()

2006-12-15 Thread Christoph Zwerschke
Maybe there would be less dispute if this dogma/convention(?) "Tuples are for heterogeneous data, list are for homogeneous data" would be written down somewhere in the tutorial, reference or in PEP8, so people would be aware of it. And can somebody explain what is exactly meant with "homogenous

No latin9 in Python?

2006-12-06 Thread Christoph Zwerschke
I noticed that Python does not understand the codec alias names latin7 = iso8859-13, latin9 = iso8859-15 (see http://docs.python.org/lib/standard-encodings.html). Particularly latin9 is pretty popular here in Western Europe since it contains the Euro symbol (contrary to latin1). According to the

Re: Protecting against SQL injection

2006-11-22 Thread Christoph Zwerschke
Tor Erik Soenvisen wrote: > How safe is the following code against SQL injection: > > # Get user privilege > digest = sha.new(pw).hexdigest() > # Protect against SQL injection by escaping quotes > uname = uname.replace("'", "''") > sql = 'SELECT privilege FR

Re: Bug in urllib?

2006-10-14 Thread Christoph Zwerschke
goyatlah wrote: > urllib.url2pathname("http://127.0.0.1:1030/js.cgi?pca&r=12181";) > gives IOError : Bad Url, only coz of the :1030 which should be > accurate portnumber. Is it something I did wrong, or a bug. And what > to do to avoid this (except rewriting url2pathname)? >>> help(urllib.url2pat

Re: finding file

2006-06-05 Thread Christoph Zwerschke
su wrote: > could someone help me on how can i restrict > my code to search the file in the current dir only Use os.listdir(). -- Christoph -- http://mail.python.org/mailman/listinfo/python-list

Re: How to search for substrings of a string in a list?

2006-06-05 Thread Christoph Zwerschke
Girish Sahani schrieb: > Given a length k string,i want to search for 2 substrings (overlap > possible) in a list consisting of length k-1 strings. These 2 substrings > when 'united' give the original string. > e.g given 'abc' i want to search in the list of 2-length strings > ['ab',ac','cd','bc','

Re: Python less error-prone than Java

2006-06-05 Thread Christoph Zwerschke
Ilpo Nyyssönen wrote: > It is not different. Your crash can tell you that it was a null > pointer. Your crash can tell you that you stomped over memory. You > just get the information about the error in different way. Not all stomping over memory must result in a crash. You might just get wrong r

Re: Python less error-prone than Java

2006-06-05 Thread Christoph Zwerschke
Martin v. Löwis wrote: > In Python 2.4 and later, you could write > > def Distance(t1, t0, maxint=(1<<32)-1): > return (t1-t0) & maxint No, this function behaves differently. It never returns a negative value. The only difference in Python 2.4 is that 1<<32 was 0 before. -- Christoph -- http

Re: Python less error-prone than Java

2006-06-04 Thread Christoph Zwerschke
nikie wrote: > Hm, then I probably didn't get your original point: I thought your > argument was that a dynamically typed language was "safer" because it > would choose the "right" type (in your example, an arbitrary-pecision > integer) automatically. No, my point was not to make a general sta

Re: Python less error-prone than Java

2006-06-04 Thread Christoph Zwerschke
nikie wrote: > Let's look at two different examples: Consider the following C# code: > > static decimal test() { >decimal x = 10001; >x /= 100; >x -= 100; >return x; > > It returns "0.01", as you would expect it. Yes, I would expect that because I have defined x as decimal

Re: Python less error-prone than Java

2006-06-04 Thread Christoph Zwerschke
Kaz Kylheku wrote: > You can have statically typed languages with inadequate type safety, > and you can have dynamically typed languages with inadequate type > safety. But the point in this example was that the Java program ironically had the bug *because* Java handles ints in a type-safe way,

Re: Python less error-prone than Java

2006-06-04 Thread Christoph Zwerschke
>> Simon Percivall wrote: >>> First: It's perfectly simple in Java to create a binary sort that >>> sorts all arrays that contain objects; so wrong there. >> My point was that the *same* Java source example, directly converted to >> Python would *automatically* accept all kinds of arrays. > > And

Re: reordering elements of a list

2006-06-03 Thread Christoph Zwerschke
greenflame wrote: > Suppose the main list is: mainlist = list('qwertyuiop') > Suppose the ordering list is: orderinglist = [3, 4, 2, 1] > > Then I am looking for a function that will take mainlist and > orderinglist as arguments and return the following list: > > ['e', 'r', 'w', 'q', 't', 'y', 'u

Re: Python less error-prone than Java

2006-06-03 Thread Christoph Zwerschke
Cameron Laird wrote: > So, here's my summary: Python's a nice language--a very nice one. > It's safer to use than Java in many ways. Python's typing is > STRICTER than Java's, but it's also dynamic, so people get to argue > for decades about which is a better model. Anyone who thinks typing > i

Re: Python less error-prone than Java

2006-06-03 Thread Christoph Zwerschke
Simon Percivall wrote: > First: It's perfectly simple in Java to create a binary sort that > sorts all arrays that contain objects; so wrong there. My point was that the *same* Java source example, directly converted to Python would *automatically* accept all kinds of arrays. No need to make a

Python less error-prone than Java

2006-06-03 Thread Christoph Zwerschke
You will often hear that for reasons of fault minimization, you should use a programming language with strict typing: http://turing.une.edu.au/~comp284/Lectures/Lecture_18/lecture/node1.html I just came across a funny example in which the opposite is the case. The following is a binary search al

State of the "Vaults of Parnassus"

2006-05-12 Thread Christoph Zwerschke
Does anybody know what happened to the "Vaults of Parnassus" site at http://www.vex.net/~x/parnassus/? "Dr Dobb's weekly Python news" still claims that it "ambitiously collects references to all sorts of Python resources." But I have the impression that it does not do this any more since April

Re: pygresql - bytea

2006-05-07 Thread Christoph Zwerschke
Jan Danielsson wrote: >I'm trying to use pygresql to insert binary data (type: bytea) into a > column (using postgresql, obviously). > ... >Does _anyone_ have a working example? A simple insertion, and a > simple select is all I'm looking for. You should better ask such questions on the P

Integrate docs of site-packages with Python doc index?

2006-05-07 Thread Christoph Zwerschke
I just thought it would be nice to have a standardized place to put the accompanying documentation for Python site packages, and something like a hook to register documentation so that all installed site packages can install links to their documentation in the Python Documentation Index. Are th

Re: Python Debugger / IDE ??

2006-03-29 Thread Christoph Zwerschke
Don Taylor wrote: > Is there a free or low-cost version of Delphi for Windows available > anywhere? I don't know (never used Delphi actually). Anyway, you don't need to have Delphi to use PyScripter, and PyScripter is completely free. However, it will only run on Windows because it is developed

Re: Command line option -Q (floor division)

2006-03-28 Thread Christoph Zwerschke
Just for the records, Anthony Baxter explained that this is by intent, because it would be still too disruptive a change. The testsuite does not even run completely with -Qnew yet. So it will be probably only changed with Python 3.0. -- Christoph -- http://mail.python.org/mailman/listinfo/pyth

Re: doctest, unittest, or if __name__='__main__'

2006-03-28 Thread Christoph Zwerschke
[EMAIL PROTECTED] wrote: > Hi there Christopher, I was wondering if you (or anyone reading this ) > could quickly summarize the ways in which unittest is unpythonic, or > point me to somewhere which discusses this. > Is this 'consensus opinion' or mainly your own opinion? It is just a consequence

Re: Multiplying sequences with floats

2006-03-25 Thread Christoph Zwerschke
Caleb Hattingh wrote: > 4.0//2 doesn't return an integer, but the equality against an integer > still holds. I agree that integer division should return an integer, > because using the operator at all means you expect one. There are actually two conflicting expectations here: You're right, the

Re: What's The Best Editor for python

2006-03-24 Thread Christoph Zwerschke
Just because nobody has mentioned them so far: - SciTe is a perfect editor for Pyhton on Win and Linx - PyScripter is a wonderful IDE (but only on Win) - DrPython is a nice platform independent editor/mini-IDE There is no one editor that could be called the best one, but there are many which are

Re: Multiplying sequences with floats

2006-03-24 Thread Christoph Zwerschke
Andrew Koenig wrote: > Christoph Zwerschke wrote: > >> Anyway this would be an argument only against the variant of typecasting a >> float with a fractional part. But what about the other variant which >> raises an error if there is a fractional part, but works if the

Re: Strings and % sign fails - Help Please

2006-03-23 Thread Christoph Zwerschke
Erik Max Francis wrote: > His problem is that cursor.execute does format expansion with %, so a > single % is not legal. Yes, I think psycopg uses paramstyle='pyformat', i.e. it expands parameters in your sql in the usual Python way where % has a special meaning. If you really mean the % sign o

Re: Multiplying sequences with floats

2006-03-23 Thread Christoph Zwerschke
Dan Sommers wrote: > Christoph Zwerschke wrote: >> I was wondering whether this should be allowed, i.e. multiplication of >> a sequence with a float. There could be either an implicit typecast to >> int (i.e. rounding) ... > > Explicit is better than implicit. I

Multiplying sequences with floats

2006-03-23 Thread Christoph Zwerschke
Currently, if you write 3*'*', you will get '***', but if you write 3.0*'*', you will get an error (can't multiply sequence by non-int). I was wondering whether this should be allowed, i.e. multiplication of a sequence with a float. There could be either an implicit typecast to int (i.e. roun

Command line option -Q (floor division)

2006-03-23 Thread Christoph Zwerschke
I noticed that contrary to what is said in http://www.python.org/doc/2.2.3/whatsnew/node7.html, namely that integer divison should print deprecation warnings beginning with Python 2.3, even Python 2.4 is still quiet about it, i.e. you still need to explicitely set the -Q warn option to see the warn

Re: encoding problems (é and è)

2006-03-23 Thread Christoph Zwerschke
bussiere bussiere wrote: > hi i'am making a program for formatting string, > i've added : > #!/usr/bin/python > # -*- coding: utf-8 -*- > > in the begining of my script but > > str = str.replace('Ç', 'C') > ... > doesn't work it put me " and , instead of remplacing é by E Are your sure your scr

Re: multiple assignment

2006-03-22 Thread Christoph Zwerschke
Anand schrieb: > Suppose i have a big list and i want to take tke the first one and rest > of the list like car/cdr in lisp. > is there any easy way to do this in python? > > Only way i know is > > a = range(10) > x, y = a[0], a[1:] You have so many higher-level ways to access and iterate throug

Re: ** Operator

2006-03-22 Thread Christoph Zwerschke
Georg Brandl wrote: > Had I seen the tracker item and/or read this thread to the end before I made > that checkin, I probably wouldn't have made it... ;) But then we would have never known that the Python gods are only people ;-) -- http://mail.python.org/mailman/listinfo/python-list

Re: Console UI library for Python

2006-03-21 Thread Christoph Zwerschke
Sean Hammond schrieb: > > Anyone know of a good library for building text-mode user-interfaces in > Python, like if I wanted to make an email program like Pine or Mutt? > > A quick Google reveals Urwid: > > http://excess.org/urwid/ > > which looks pretty good. Urwid is probably a more sophist

Re: doctest, unittest, or if __name__='__main__'

2006-03-21 Thread Christoph Zwerschke
[EMAIL PROTECTED] wrote: > By that, do you mean you can write your tests and your > docstrings in one shot with doctest? Right. The tests serve also as usage examples. -- http://mail.python.org/mailman/listinfo/python-list

Re: doctest, unittest, or if __name__='__main__'

2006-03-21 Thread Christoph Zwerschke
[EMAIL PROTECTED] schrieb: > Anyhow, I'm not attacking doctest, but rather, just trying > to understand why there seems to be two very similar ways > of testing your code built into the system (considering that > one motto around here is "There should be one -- and > preferably only one -- obvious

Re: doctest, unittest, or if __name__='__main__'

2006-03-21 Thread Christoph Zwerschke
[EMAIL PROTECTED] wrote: > If unittest is the standard way to write test code, why do we still > have doctest? (I notice there's no mention in PEP 3000 of deprecating > the doctest module). Because both have their pros and cons and their right to exist. Doctest is really easy to use and you can k

Re: ** Operator

2006-03-21 Thread Christoph Zwerschke
Christoph Zwerschke wrote: > Christoph Zwerschke wrote: >> Kent Johnson wrote: >>> The way to make this change happen is to submit a bug report with >>> your suggested change. See the link at the bottom of the above page >>> to find out how. >> >>

Re: ** Operator

2006-03-21 Thread Christoph Zwerschke
Ron Adam wrote: > I agree and think the "for language lawyers" should be changed to > something that encourages people to read it instead of encouraging them > to avoid it. Maybe: > > "The Python language structure for everyone". > > If it's hard to read and understand, then that can and s

Re: ** Operator

2006-03-21 Thread Christoph Zwerschke
Christoph Zwerschke wrote: > Kent Johnson wrote: >> The way to make this change happen is to submit a bug report with your >> suggested change. See the link at the bottom of the above page to find >> out how. > > I know, but I wanted to see at least one person a

Re: ** Operator

2006-03-20 Thread Christoph Zwerschke
Kent Johnson wrote: > The way to make this change happen is to submit a bug report with your > suggested change. See the link at the bottom of the above page to find > out how. I know, but I wanted to see at least one person assenting before doing so. Anyway, I took your words as assent and fil

Re: ** Operator

2006-03-20 Thread Christoph Zwerschke
Ziga Seilnacht wrote: > Christoph Zwerschke wrote: >> In the explanation about pow() at >> http://docs.python.org/lib/built-in-funcs.html, the notation 10**2 is >> suddenly used, without explaining that it is equivalent to pow(10,2). I >> think this could be improved in

Re: cmp() on integers - is there guarantee of returning only +-1 or 0?

2006-03-20 Thread Christoph Zwerschke
Alex Martelli wrote: > <[EMAIL PROTECTED]> wrote: >> Why not >> >> def sign(n): >> return n and n/abs(n) or 0 > > If you assume n is a number, the 'or 0' appears redundant (if you don't > so assume, then the abs(n) and the division are doubtful;-). Without the 'or 0' it is also more c

Re: ** Operator

2006-03-20 Thread Christoph Zwerschke
Alex Martelli wrote: > Sathyaish wrote: > >> I tried it on the interpreter and it looks like it is the "to the power >> of" operator symbol/function. Can you please point me to the formal >> definition of this operator in the docs? > > http://docs.python.org/ref/power.html I think this should be

Re: Python Debugger / IDE ??

2006-03-15 Thread Christoph Zwerschke
[EMAIL PROTECTED] wrote: > I like the Pyscripter, is there any Linux version or something of it. Sorry, I forgot to mention that there is a snag in it. Since PyScripter is based on Python for Delphi, it is available for Windows only. -- Christoph -- http://mail.python.org/mailman/listinfo/pytho

Re: Python Debugger / IDE ??

2006-03-15 Thread Christoph Zwerschke
[EMAIL PROTECTED] schrieb: > Is there any editor or IDE in Python (either Windows or Linux) which > has very good debugging facilites like MS VisualStudio has or something > like that. > > I like SPE but couldn't easily use winPDP. I need tips to debug my code > easily. You can try out PyScripter

Re: Proper class initialization

2006-03-03 Thread Christoph Zwerschke
gry@ll.mit.edu schrieb: > Hmm, the meta-class hacks mentioned are cool, but for this simple a > case how about just: > > class A: >def __init__(self): > self.__class__.sum = self.calculate_sum() >def calculate_sum(self): > do_stuff > return sum_value If you do it like th

Re: Proper class initialization

2006-03-02 Thread Christoph Zwerschke
Steven Bethard wrote: > I don't run into this often, but when I do, I usually go Jack > Diederich's route:: > > class A(object): > class __metaclass__(type): > def __init__(cls, name, bases, classdict): > cls.sum = sum(xrange(10)) Good idea, that is really

Re: Proper class initialization

2006-03-02 Thread Christoph Zwerschke
Steven Bethard wrote: > I assume the intention was to indicate that the initialization required > multiple statements. I just couldn't bring myself to write that > horrible for-loop when the sum() function is builtin. ;) Yes, this was just dummy code standing for something that really requires

Re: Proper class initialization

2006-03-01 Thread Christoph Zwerschke
Jack Diederich wrote: > ... __metaclass__ = MyMeta Thanks. I was not aware of the __metaclass__ attribute. Still a bit complicated and as you said, difficult to read, as the other workarounds already proposed. Anyway, this is probably not needed so often. -- Christoph -- http://mail.python.o

Proper class initialization

2006-03-01 Thread Christoph Zwerschke
Usually, you initialize class variables like that: class A: sum = 45 But what is the proper way to initialize class variables if they are the result of some computation or processing as in the following silly example (representative for more: class A: sum = 0 for i in range(10):

ihooks and Python eggs

2006-03-01 Thread Christoph Zwerschke
Is it a known problem that ihooks is incompatible with Python eggs? When I do the following: import ihooks ihooks.install(ihooks.ModuleImporter()) then I cannot import any Python egg afterwards. Can there be anything done about this? -- Christoph -- http://mail.python.org/mailman/listinfo/pyt

Re: embedding python in HTML

2006-02-18 Thread Christoph Zwerschke
Rene Pijlman wrote: > There's also PSP: > http://www.ciobriefings.com/psp/ Another incarnation of PSP can be used as part of Webware for Python (http://www.w4py.org). And one of the more modern solutions that should be mentioned is Kid (http://kid.lesscode.org). -- Christoph -- http://mail.py

Re: Pythonic gui format?

2006-02-14 Thread Christoph Zwerschke
bruno at modulix schrieb: > And finally, you could write your own ordered mapping type - but then > you loose the builtin syntax... I still don't understand why so many objected there are no "use cases" for ordered dicts when I tried to discuss these in a recent thread... Actually I see them eve

Re: [OT] Pythonic gui format?

2006-02-14 Thread Christoph Zwerschke
bruno at modulix schrieb: > Christoph Zwerschke wrote: >> Bruno Desthuilliers schrieb: >> >>> Gregory Petrosyan a écrit : >>> >>>> I am currently seeking for pythonic alternative for XML. >> Bruno, before writing another simple GUI, > >

Re: how do you pronounce 'tuple'?

2006-02-14 Thread Christoph Zwerschke
[EMAIL PROTECTED] schrieb: > Then we went to hear Guido speak about Python 2.2 at a ZPUG meeting in > Washington, DC. When he said toople I almost fell out of my chair > laughing, particularly because the people who taught me to say it the > "right" way were with me. When I looked over, they just

Re: Pythonic gui format?

2006-02-14 Thread Christoph Zwerschke
Bruno Desthuilliers schrieb: > Gregory Petrosyan a écrit : >> I am currently seeking for pythonic alternative for XML. > > A pretty obvious one is dicts and lists. What about (Q&D): > > window = { > 'title' : 'Hello World!' > 'image' : {'text' :"nice picture here", > ... I think this is pret

  1   2   3   >