Re: Can't do a multiline assignment!

2008-04-18 Thread Bruno Desthuilliers
[EMAIL PROTECTED] a écrit : > On Apr 17, 12:34 pm, Michael Torrie <[EMAIL PROTECTED]> wrote: >> Another thing to consider is that referencing a member of a class or >> instance already *is* a dictionary lookup. It's how python works. Thus >> dictionaries are optimized to be fast. Since strings a

Re: Can't do a multiline assignment!

2008-04-18 Thread Diez B. Roggisch
Michael Torrie schrieb: > [EMAIL PROTECTED] wrote: >> You didn't really write that at the Python's interpreter, did you? >> It's wrong. The way that would really go at the interpreter is like > > I did actually run it through the interpreter, but I didn't copy and > past it to the e-mail. Thought

Re: Can't do a multiline assignment!

2008-04-17 Thread Steve Holden
[EMAIL PROTECTED] wrote: > On Apr 17, 11:46 am, Arnaud Delobelle <[EMAIL PROTECTED]> wrote: >> Why not do something like: >> >> class RequestHeadersManager: >> >> def __init__(self, string): >> self._fields = {} >> # Populate self.fields with fields defined in 'string' >> >>

Re: Can't do a multiline assignment!

2008-04-17 Thread J. Cliff Dyer
On Thu, 2008-04-17 at 13:53 -0400, Steve Holden wrote: > Gary Herron wrote: > > [EMAIL PROTECTED] wrote: > >> On Apr 17, 10:54 am, [EMAIL PROTECTED] wrote: > >> > >>> On 17 avr, 17:40, [EMAIL PROTECTED] wrote: > >>> > >>> Out of sheer curiosity, why do you need thirty (hand-specified and > >>> d

Re: Can't do a multiline assignment!

2008-04-17 Thread Paul Hankin
On Apr 17, 5:56 pm, [EMAIL PROTECTED] wrote: > class RequestHeadersManager: > ... >     def __init__(self, headers, linesep): >         headersDict = parse_headers(headers, linesep) > >         for header in headersDict.keys(): > ...[lots of code] Your code is pretty much equivalent to

Re: Can't do a multiline assignment!

2008-04-17 Thread Michael Torrie
[EMAIL PROTECTED] wrote: > You didn't really write that at the Python's interpreter, did you? > It's wrong. The way that would really go at the interpreter is like I did actually run it through the interpreter, but I didn't copy and past it to the e-mail. Thought that I saw this behavior, but cle

Re: Can't do a multiline assignment!

2008-04-17 Thread s0suk3
On Apr 17, 12:34 pm, Michael Torrie <[EMAIL PROTECTED]> wrote: > > Another thing to consider is that referencing a member of a class or > instance already *is* a dictionary lookup. It's how python works. Thus > dictionaries are optimized to be fast. Since strings are immutable, > python hashes t

Re: Can't do a multiline assignment!

2008-04-17 Thread Steve Holden
Gary Herron wrote: > [EMAIL PROTECTED] wrote: >> On Apr 17, 10:54 am, [EMAIL PROTECTED] wrote: >> >>> On 17 avr, 17:40, [EMAIL PROTECTED] wrote: >>> >>> Out of sheer curiosity, why do you need thirty (hand-specified and >>> dutifully commented) names to the same constant object if you know >>> t

Re: Can't do a multiline assignment!

2008-04-17 Thread s0suk3
On Apr 17, 12:24 pm, Michael Torrie <[EMAIL PROTECTED]> wrote: > [EMAIL PROTECTED] wrote: > > > > There! That's the whole code. I guess the way you suggest is simpler > > and a bit more intuitive, but I was figuring that the way I suggested > > it is more stylish. > > Umm, doesn't defining all tho

Re: Can't do a multiline assignment!

2008-04-17 Thread Steve Holden
Marco Mariani wrote: > [EMAIL PROTECTED] wrote: > >> Yes, it makes it more readable. And yes, it does make it (a lot) more >> maintainable. Mainly because I don't have those four variables, I have >> about thirty. And I think I won't need to one or two of them, but >> maybe all of them at once. >

Please don't fake interpreter sessions, was Re: Can't do a multiline assignment!

2008-04-17 Thread Peter Otten
Michael Torrie wrote: That's not how Python actually works: > >>> a=myclass(3) > >>> b=myclass(6) > >>> a.classvar1=9 > >>> a.classvar1 > 9 > >>> b.classvar1 > 9 What actually happens is that the a.classvar1 = 9 assignment creates an instance variable that shades the classvar: >>> class A(objec

Re: Can't do a multiline assignment!

2008-04-17 Thread Arnaud Delobelle
On Apr 17, 6:02 pm, [EMAIL PROTECTED] wrote: [...] > I do it with all the separate variables mainly for performance. If I > had the headers in a dict, I'd be looking up a string in a list of > strings (the keys of the dict) everytime I check for a header. Not > that that's going to take more that 0

Re: Can't do a multiline assignment!

2008-04-17 Thread Michael Torrie
[EMAIL PROTECTED] wrote: > I do it with all the separate variables mainly for performance. If I > had the headers in a dict, I'd be looking up a string in a list of > strings (the keys of the dict) everytime I check for a header. Not > that that's going to take more that 0.1 seconds, but the progra

Re: Can't do a multiline assignment!

2008-04-17 Thread s0suk3
On Apr 17, 12:07 pm, Sion Arrowsmith <[EMAIL PROTECTED]> wrote: > <[EMAIL PROTECTED]> wrote: > >In Python, you usually can use parentheses to split something over > >several lines. But you can't use parentheses for an assignment of > >several lines. > > Yes you can, you just need an iterable of th

Re: Can't do a multiline assignment!

2008-04-17 Thread Michael Torrie
[EMAIL PROTECTED] wrote: > > There! That's the whole code. I guess the way you suggest is simpler > and a bit more intuitive, but I was figuring that the way I suggested > it is more stylish. Umm, doesn't defining all those members in the class lead to class variables, not instance variables? I

Re: Can't do a multiline assignment!

2008-04-17 Thread Sion Arrowsmith
<[EMAIL PROTECTED]> wrote: >In Python, you usually can use parentheses to split something over >several lines. But you can't use parentheses for an assignment of >several lines. Yes you can, you just need an iterable of the right length on the other side for the tuple unpacking to work: >>> (CON

Re: Can't do a multiline assignment!

2008-04-17 Thread s0suk3
On Apr 17, 11:46 am, Arnaud Delobelle <[EMAIL PROTECTED]> wrote: > > Why not do something like: > > class RequestHeadersManager: > > def __init__(self, string): > self._fields = {} > # Populate self.fields with fields defined in 'string' > > def __getitem__(self, fieldname):

Re: Can't do a multiline assignment!

2008-04-17 Thread s0suk3
On Apr 17, 11:44 am, Gary Herron <[EMAIL PROTECTED]> wrote: > But. *What's the point* of doing it this way.I see 14 variables > being assigned a value, but I don't see the value, they are getting. > Reading this bit if code provides no useful information unless I'm > willing to scan down the

Re: Can't do a multiline assignment!

2008-04-17 Thread Arnaud Delobelle
On Apr 17, 5:19 pm, [EMAIL PROTECTED] wrote: > On Apr 17, 10:54 am, [EMAIL PROTECTED] wrote: > > > On 17 avr, 17:40, [EMAIL PROTECTED] wrote: > > > Out of sheer curiosity, why do you need thirty (hand-specified and > > dutifully commented) names to the same constant object if you know > > there wil

Re: Can't do a multiline assignment!

2008-04-17 Thread Gary Herron
[EMAIL PROTECTED] wrote: > On Apr 17, 10:54 am, [EMAIL PROTECTED] wrote: > >> On 17 avr, 17:40, [EMAIL PROTECTED] wrote: >> >> Out of sheer curiosity, why do you need thirty (hand-specified and >> dutifully commented) names to the same constant object if you know >> there will always be only one

Re: Can't do a multiline assignment!

2008-04-17 Thread colas . francis
On 17 avr, 18:19, [EMAIL PROTECTED] wrote: > On Apr 17, 10:54 am, [EMAIL PROTECTED] wrote: > > > On 17 avr, 17:40, [EMAIL PROTECTED] wrote: > > > Out of sheer curiosity, why do you need thirty (hand-specified and > > dutifully commented) names to the same constant object if you know > > there will

Re: Can't do a multiline assignment!

2008-04-17 Thread D'Arcy J.M. Cain
On Thu, 17 Apr 2008 09:19:32 -0700 (PDT) [EMAIL PROTECTED] wrote: > I'm building a web server. The many variables are names of header > fields. One part of the code looks like this (or at least I'd like it > to): > > class RequestHeadersManager: > > # General header fields > Cache_Control

Re: Can't do a multiline assignment!

2008-04-17 Thread s0suk3
On Apr 17, 10:54 am, [EMAIL PROTECTED] wrote: > On 17 avr, 17:40, [EMAIL PROTECTED] wrote: > > Out of sheer curiosity, why do you need thirty (hand-specified and > dutifully commented) names to the same constant object if you know > there will always be only one object? I'm building a web server.

Re: Can't do a multiline assignment!

2008-04-17 Thread Grant Edwards
On 2008-04-17, Gary Herron <[EMAIL PROTECTED]> wrote: >> For example, let's say I want to assign a bunch of variables to an >> initial, single value. In C or a similar language you would do: >> >> CONSTANT1= >> /* This is some constant */ >> CONSTANT2= >> CONSTANT3= >> >> /*This is yet

Re: Can't do a multiline assignment!

2008-04-17 Thread colas . francis
On 17 avr, 17:40, [EMAIL PROTECTED] wrote: > > Yuck! No way!! If you *want* to make your code that hard to read, I'm > > sure you can find lots of ways to do so, even in Python, but don't > > expect Python to change to help you toward such a dubious goal. > > Well, my actual code doesn't look lik

Re: Can't do a multiline assignment!

2008-04-17 Thread Marco Mariani
[EMAIL PROTECTED] wrote: > Yes, it makes it more readable. And yes, it does make it (a lot) more > maintainable. Mainly because I don't have those four variables, I have > about thirty. And I think I won't need to one or two of them, but > maybe all of them at once. have fun with locals(), then (

Re: Can't do a multiline assignment!

2008-04-17 Thread Andrew Lee
[EMAIL PROTECTED] wrote: >> Yuck! No way!! If you *want* to make your code that hard to read, I'm >> sure you can find lots of ways to do so, even in Python, but don't >> expect Python to change to help you toward such a dubious goal. >> > > Well, my actual code doesn't look like that. Trust me,

Re: Can't do a multiline assignment!

2008-04-17 Thread s0suk3
> Yuck! No way!! If you *want* to make your code that hard to read, I'm > sure you can find lots of ways to do so, even in Python, but don't > expect Python to change to help you toward such a dubious goal. > Well, my actual code doesn't look like that. Trust me, I like clean code. > Seriously,

Re: Can't do a multiline assignment!

2008-04-17 Thread Gary Herron
[EMAIL PROTECTED] wrote: > I was shocked a while ago when a discovered that in Python you can't > do a multiline assignment > with comments between the lines. > > For example, let's say I want to assign a bunch of variables to an > initial, single value. In C or a s

Can't do a multiline assignment!

2008-04-17 Thread s0suk3
I was shocked a while ago when a discovered that in Python you can't do a multiline assignment with comments between the lines. For example, let's say I want to assign a bunch of variables to an initial, single value. In C or a similar language you would do: CONSTANT1= /* Th