Re: Explicit variable declaration

2008-04-25 Thread Filip Gruszczyński
> In Python the standard patten for "declaring" variables is just to assign to > them as they are needed. If you want the effect of a declaration as you > would do in C, you can just define the variable and initialize it to 0 or > None. (Or {} for a new dictionary, or [] for a new list.) Yep

Re: Explicit variable declaration

2008-04-24 Thread Jason Stokes
"Filip Gruszczynski" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] >> If you want to just declare that name exist, but doesn't want to >> declare the type, why don't you just do this: >> >> def somefunc(): >> nonlocal = nonlocal >> local = 0 # or None or [] or an initial

Re: Explicit variable declaration

2008-04-24 Thread Terry Reedy
"Filip Gruszczynski" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] |> If you want to just declare that name exist, but doesn't want to | > declare the type, why don't you just do this: Names do not 'exist' in Python, nor do they have types. They are bound to objects that have t

Re: Explicit variable declaration

2008-04-23 Thread Filip Gruszczyński
> If you want to just declare that name exist, but doesn't want to > declare the type, why don't you just do this: > > def somefunc(): > nonlocal = nonlocal > local = 0 # or None or [] or an initial value > # > return nonlocal * local Err.. I don't quite get. How it may help me?

Re: Explicit variable declaration

2008-04-23 Thread Lie
On Apr 23, 4:52 pm, "Filip Gruszczyński" <[EMAIL PROTECTED]> wrote: > > You mean the type? Not in 2.x, but in 3.x, there are function > > annotations: > > > def a_function(arg1: int, arg2: str) -> None: pass > > Nope, I don't like types ;-) 3.x seems pretty revolutionary, and this > typing can b

Re: Explicit variable declaration

2008-04-23 Thread Filip Gruszczyński
Wow! This is extremely easy and seems to do exactly what I need. Those decorators are pretty powerful then. Thanks for your help, I'll try to use this. > def uses(names): > def decorator(f): > used = set(f.func_code.co_varnames) > declared = set(names.split()) > undecl

Re: Explicit variable declaration

2008-04-23 Thread Duncan Booth
Steve Holden <[EMAIL PROTECTED]> wrote: > Filip Gruszczy"ski wrote: >> Just declaring, that they exist. Saying, that in certain function >> there would appear only specified variables. Like in smalltalk, if I >> remember correctly. >> > Icon has (had?) the same feature: if the "local" statement

Re: Explicit variable declaration

2008-04-23 Thread Steve Holden
Filip Gruszczyński wrote: You mean the type? Not in 2.x, but in 3.x, there are function annotations: def a_function(arg1: int, arg2: str) -> None: pass Nope, I don't like types ;-) 3.x seems pretty revolutionary, and this typing can be appreciated by some people. Declaring what about them

Re: Explicit variable declaration

2008-04-23 Thread Filip Gruszczyński
> You mean the type? Not in 2.x, but in 3.x, there are function > annotations: > > def a_function(arg1: int, arg2: str) -> None: pass Nope, I don't like types ;-) 3.x seems pretty revolutionary, and this typing can be appreciated by some people. > Declaring what about them? If you mean declari

Re: Explicit variable declaration

2008-04-22 Thread Gabriel Genellina
En Tue, 22 Apr 2008 21:39:41 -0300, Filip Gruszczyński <[EMAIL PROTECTED]> escribió: Hello everyone! It is my first message on this list, therefore I would like to say hello to everyone. I am fourth year student of CS on the Univeristy of Warsaw and recently I have become very interested in d

Re: Explicit variable declaration

2008-04-22 Thread Ben Finney
"Filip Gruszczyński" <[EMAIL PROTECTED]> writes: > I have become very interested in dynamically typed languages, > especially Python. Good to know. Welcome to the group. > I would like to ask, whether there is any way of explicitly > declaring variables used in a function? Declaring what about

Re: Explicit variable declaration

2008-04-22 Thread Benjamin
On Apr 22, 7:39 pm, "Filip Gruszczyński" <[EMAIL PROTECTED]> wrote: > Hello everyone! > > It is my first message on this list, therefore I would like to say > hello to everyone. I am fourth year student of CS on the Univeristy of > Warsaw and recently I have become very interested in dynamically ty

Re: Explicit variable declaration

2008-04-22 Thread Dan Bishop
On Apr 22, 7:39 pm, "Filip Gruszczyński" <[EMAIL PROTECTED]> wrote: > Hello everyone! > > It is my first message on this list, therefore I would like to say > hello to everyone. I am fourth year student of CS on the Univeristy of > Warsaw and recently I have become very interested in dynamically ty

Explicit variable declaration

2008-04-22 Thread Filip Gruszczyński
Hello everyone! It is my first message on this list, therefore I would like to say hello to everyone. I am fourth year student of CS on the Univeristy of Warsaw and recently I have become very interested in dynamically typed languages, especially Python. I would like to ask, whether there is any

Re: Can I use a conditional in a variable declaration?

2006-03-21 Thread Sion Arrowsmith
Ron Adam <[EMAIL PROTECTED]> wrote: >[EMAIL PROTECTED] wrote: >> I want the equivalent of this: >> >> if a == "yes": >>answer = "go ahead" >> else: >>answer = "stop" >> >> in [a] more compact form: >I sometimes find it useful to do: > > answers = {True: "go ahead", False: "stop"} >

Re: Can I use a conditional in a variable declaration?

2006-03-19 Thread Jeffrey Schwab
Georg Brandl wrote: > Jeffrey Schwab wrote: >> [EMAIL PROTECTED] wrote: >> >>> I want the equivalent of this: >>> >>> if a == "yes": >>>answer = "go ahead" >>> else: >>>answer = "stop" >>> >> def mux(s, t, f): >> if s: >> return t >> return f > > But be aware that this i

Re: Can I use a conditional in a variable declaration?

2006-03-19 Thread andy
[EMAIL PROTECTED] wrote: >I've done this in Scheme, but I'm not sure I can in Python. > >I want the equivalent of this: > >if a == "yes": > answer = "go ahead" >else: > answer = "stop" > >in this more compact form: > > >a = (if a == "yes": "go ahead": "stop") > > >is there such a form in Pytho

Re: Can I use a conditional in a variable declaration?

2006-03-19 Thread Georg Brandl
Jeffrey Schwab wrote: > [EMAIL PROTECTED] wrote: > >> I want the equivalent of this: >> >> if a == "yes": >>answer = "go ahead" >> else: >>answer = "stop" >> >> in this more compact form: >> >> a = (if a == "yes": "go ahead": "stop") >> >> is there such a form in Python? I tried playin

Re: Can I use a conditional in a variable declaration?

2006-03-19 Thread Ron Adam
[EMAIL PROTECTED] wrote: > I've done this in Scheme, but I'm not sure I can in Python. > > I want the equivalent of this: > > if a == "yes": >answer = "go ahead" > else: >answer = "stop" > > in this more compact form: > > > a = (if a == "yes": "go ahead": "stop") > > > is there such

Re: Can I use a conditional in a variable declaration?

2006-03-18 Thread Jeffrey Schwab
[EMAIL PROTECTED] wrote: > I want the equivalent of this: > > if a == "yes": >answer = "go ahead" > else: >answer = "stop" > > in this more compact form: > > a = (if a == "yes": "go ahead": "stop") > > is there such a form in Python? I tried playing around with lambda > expressions, bu

Re: Can I use a conditional in a variable declaration?

2006-03-18 Thread Grant Edwards
On 2006-03-19, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: > I want the equivalent of this: > > if a == "yes": >answer = "go ahead" > else: >answer = "stop" If that's what you want, then write that. ;) -- [EMAIL PROTECTED] Grant Edwards -- http://mail.python.org/mailman/listinfo/pytho

Re: Can I use a conditional in a variable declaration?

2006-03-18 Thread Paul Rubin
[EMAIL PROTECTED] writes: > a = (if a == "yes": "go ahead": "stop") > > is there such a form in Python? I tried playing around with lambda > expressions, but I couldn't quite get it to work right. This has been the subject of huge debate over the years. The answer is Python doesn't currently hav

Re: Can I use a conditional in a variable declaration?

2006-03-18 Thread volcs0
Kent - Thanks for the quick reply. I tried the and/or trick - it does work. But you're right - more trouble than its worth So for now, I did it "the long way". It looks like (see below), this functionality will be added in soon. Thanks for the quick help. -sam -- http://mail.python.org/mail

Re: Can I use a conditional in a variable declaration?

2006-03-18 Thread Ben Cartwright
[EMAIL PROTECTED] wrote: > I've done this in Scheme, but I'm not sure I can in Python. > > I want the equivalent of this: > > if a == "yes": >answer = "go ahead" > else: >answer = "stop" > > in this more compact form: > > > a = (if a == "yes": "go ahead": "stop") > > > is there such a form

Re: Can I use a conditional in a variable declaration?

2006-03-18 Thread Kent Johnson
[EMAIL PROTECTED] wrote: > I want the equivalent of this: > > if a == "yes": >answer = "go ahead" > else: >answer = "stop" > > in this more compact form: > > > a = (if a == "yes": "go ahead": "stop") If the value for the 'true' case can never have a boolean value of False, you can use

Can I use a conditional in a variable declaration?

2006-03-18 Thread volcs0
I've done this in Scheme, but I'm not sure I can in Python. I want the equivalent of this: if a == "yes": answer = "go ahead" else: answer = "stop" in this more compact form: a = (if a == "yes": "go ahead": "stop") is there such a form in Python? I tried playing around with lambda expr

Re: implicit variable declaration and access

2005-06-16 Thread Cameron Laird
In article <[EMAIL PROTECTED]>, Christopher Subich <[EMAIL PROTECTED]> wrote: . . . >Out of curiosity, where would you classify interpreters for secondary >app-specific programming languages? Specifically, mud-client stored

Re: implicit variable declaration and access

2005-06-15 Thread Tom Anderson
On Tue, 14 Jun 2005, Scott David Daniels wrote: > Tom Anderson wrote: >> ... If it's not, try: >> x = "myVarName" >> y = "myVarValue" >> locals()[x] = y > > Sorry, this works with globals(), but not with locals(). Oh, weird. It works when i tried it. Aaaah, i only tried it at the interactive pro

Re: implicit variable declaration and access

2005-06-14 Thread Ali Razavi
Steven D'Aprano wrote: > On Mon, 13 Jun 2005 12:18:31 -0400, Ali Razavi wrote: > > >>Is there any reflective facility in python >>that I can use to define a variable with a >>name stored in another variable ? >>like I have : >>x = "myVarName" >> >>what can I do to declare a new variable with the

Re: implicit variable declaration and access

2005-06-14 Thread Scott David Daniels
Tom Anderson wrote: > ... If it's not, try: > x = "myVarName" > y = "myVarValue" > locals()[x] = y Sorry, this works with globals(), but not with locals(). There isn't a simple way to fiddle the locals (the number is determined when the function is built). I do, however, agree with you about what

Re: implicit variable declaration and access

2005-06-14 Thread Tom Anderson
On Mon, 13 Jun 2005, Ali Razavi wrote: > Tom Anderson wrote: >> On Mon, 13 Jun 2005, Ali Razavi wrote: >> >>> Is there any reflective facility in python that I can use to define a >>> variable with a name stored in another variable ? >>> >>> like I have : >>> x = "myVarName" >>> >>> what can I

Re: implicit variable declaration and access

2005-06-13 Thread Christopher Subich
Cameron Laird wrote: > cleaner algorithm somewhere in the neighborhood. In general, > "application-level" programming doesn't need exec() and such. > > PyPy and debugger writers and you other "systems" programmers > already know who you are. Out of curiosity, where would you classify interprete

Re: implicit variable declaration and access

2005-06-13 Thread Cameron Laird
In article <[EMAIL PROTECTED]>, Ali Razavi <[EMAIL PROTECTED]> wrote: >Tom Anderson wrote: >> On Mon, 13 Jun 2005, Ali Razavi wrote: >> >>> Is there any reflective facility in python that I can use to define a >>> variable with a name stored in another variable ? .

Re: implicit variable declaration and access

2005-06-13 Thread Cameron Laird
In article <[EMAIL PROTECTED]>, Peter Dembinski <[EMAIL PROTECTED]> wrote: >Benji York <[EMAIL PROTECTED]> writes: > >[snap] > >>> code = x + '= 0' >>> exec(code) >> >> You should generally stay away from exec for lots of reasons. > >Code 'refactorizability' is one of them. There's an affirmative

Re: implicit variable declaration and access

2005-06-13 Thread Steven D'Aprano
On Mon, 13 Jun 2005 12:18:31 -0400, Ali Razavi wrote: > Is there any reflective facility in python > that I can use to define a variable with a > name stored in another variable ? > like I have : > x = "myVarName" > > what can I do to declare a new variable with the name of the string > stored in

Re: implicit variable declaration and access

2005-06-13 Thread Tom Anderson
On Mon, 13 Jun 2005, Peter Dembinski wrote: > Tom Anderson <[EMAIL PROTECTED]> writes: > > [snap] > >> The MAtrix had evarything in it: guns, a juimping off teh walls, flying >> guns, a bullet tiem, evil computar machenes, numbers that flew, flying >> gun bullets in slowar motian, juimping into

Re: implicit variable declaration and access

2005-06-13 Thread Ali Razavi
Tom Anderson wrote: > On Mon, 13 Jun 2005, Ali Razavi wrote: > >> Is there any reflective facility in python that I can use to define a >> variable with a name stored in another variable ? >> >> like I have : >> x = "myVarName" >> >> what can I do to declare a new variable with the name of the st

Re: implicit variable declaration and access

2005-06-13 Thread Peter Dembinski
Tom Anderson <[EMAIL PROTECTED]> writes: [snap] > The MAtrix had evarything in it: guns, a juimping off teh walls, > flying guns, a bullet tiem, evil computar machenes, numbers that > flew, flying gun bullets in slowar motian, juimping into a gun, dead > police men, computar hackeing, Kevin Mitni

Re: implicit variable declaration and access

2005-06-13 Thread Tom Anderson
On Mon, 13 Jun 2005, Ali Razavi wrote: > Is there any reflective facility in python that I can use to define a > variable with a name stored in another variable ? > > like I have : > x = "myVarName" > > what can I do to declare a new variable with the name of the string > stored in x. And how ca

Re: implicit variable declaration and access

2005-06-13 Thread Peter Dembinski
Benji York <[EMAIL PROTECTED]> writes: [snap] >> code = x + '= 0' >> exec(code) > > You should generally stay away from exec for lots of reasons. Code 'refactorizability' is one of them. -- http://mail.python.org/mailman/listinfo/python-list

Re: implicit variable declaration and access

2005-06-13 Thread Benji York
Ali Razavi wrote: > Ali Razavi wrote: > >>Is there any reflective facility in python >>that I can use to define a variable with a >>name stored in another variable ? > Got it! use higher order functions like Lisp! No, you use higher order functions like Python. :) > code = x + '= 0' > exec(cod

Re: implicit variable declaration and access

2005-06-13 Thread Ali Razavi
Ali Razavi wrote: > Is there any reflective facility in python > that I can use to define a variable with a > name stored in another variable ? > like I have : > x = "myVarName" > > what can I do to declare a new variable with the name of the string > stored in x. And how can I access that implici

implicit variable declaration and access

2005-06-13 Thread Ali Razavi
Is there any reflective facility in python that I can use to define a variable with a name stored in another variable ? like I have : x = "myVarName" what can I do to declare a new variable with the name of the string stored in x. And how can I access that implicitly later ? -- http://mail.python

Re: variable declaration

2005-02-25 Thread Serge Orlov
Alexander Zatvornitskiy wrote: > Hello All! > > I'am novice in python, and I find one very bad thing (from my point > of view) in language. There is no keyword or syntax to declare > variable, like 'var' in > Pascal, or special syntax in C. It can > cause very ugly errors,like this: > > epsilon=0 >

Re: variable declaration

2005-02-10 Thread Nick Coghlan
Antoon Pardon wrote: I don't think that would be a big issue. Python uses '=' also differently from a number of languages. My preference would currently be for ':=' because I have the impression that if you don't leave spaces the period in '.=' tends to be obscured. x.=42 vsx:=42 seems a cl

Re: variable declaration

2005-02-10 Thread Antoon Pardon
Op 2005-02-10, Nick Coghlan schreef <[EMAIL PROTECTED]>: > Antoon Pardon wrote: >> Well it seems you have some fair points. I'll just stop here stating >> that I would like to have it, even if it proved to be slower. Speed >> is not that big a factor in the things I write. > > Oh, certainly. I wasn

Re: variable declaration

2005-02-10 Thread Nick Coghlan
Antoon Pardon wrote: Well it seems you have some fair points. I'll just stop here stating that I would like to have it, even if it proved to be slower. Speed is not that big a factor in the things I write. Oh, certainly. I wasn't suggesting the speed hit was enough to kill the idea - I was just po

Re: variable declaration

2005-02-10 Thread Antoon Pardon
Op 2005-02-09, Nick Coghlan schreef <[EMAIL PROTECTED]>: > Antoon Pardon wrote: >> Op 2005-02-08, Nick Coghlan schreef <[EMAIL PROTECTED]>: >>>The CPython *_FAST opcodes relate to functions' local variables. Behind the >>>scenes they are implemented as integer indexing operations into a pre-sized

Re: variable declaration

2005-02-10 Thread Antoon Pardon
Op 2005-02-08, Fredrik Lundh schreef <[EMAIL PROTECTED]>: > Peter Otten wrote: > >>> executed. the compiler handles "global" and "from __future__", everything >>> else is done at runtime. >> >> and __debug__, too, it seems: > > you left out the "python -O" line. > > __debug__ >> False > def

variable declaration

2005-02-09 Thread Alexander Zatvornitskiy
:) SH> If, as you suggest, def were a declaration, then it should either not SH> be possible to write SH> if __debug__: SH> def func(x): SH> print x, "is bollocks" if __debug__: ~S=0 S=5 #error in non-debug mode. print S That&

variable declaration

2005-02-09 Thread Alexander Zatvornitskiy
gram) tested separately and in whole. But tests are not a silver bullet. static checking is also very usefull. What's why I feel variable declaration (or explicit variable definition) may help. Alexander, [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list

Re: variable declaration

2005-02-09 Thread Nick Coghlan
Antoon Pardon wrote: Op 2005-02-08, Nick Coghlan schreef <[EMAIL PROTECTED]>: The CPython *_FAST opcodes relate to functions' local variables. Behind the scenes they are implemented as integer indexing operations into a pre-sized C array. Operations don't come much faster than that :) I don't fo

Re: variable declaration

2005-02-08 Thread Eric Pederson
Arthur artfully argued: > What if: > > There was a well conducted market survey conclusive to the effect that > adding optional strict variable declaration would, in the longer run, > increase Python's market share dramatically. It's always good to examine one's

Re: variable declaration

2005-02-08 Thread Elspeth Thorne
Alexander Zatvornitskiy wrote: > You may say: give better names for your variables! Ha, I'am often don't > understand that they mean! They are written for me by an engineer! Hang on, though - if you don't understand what you are programming, then how can you check if it's correct? Regardless of va

Re: variable declaration

2005-02-08 Thread Arthur
that Python's design is essentially correct as it is. > > >> You wrote about "substantial cost" of var declarations. Yes, you are >> write. But think about the cost of lack of var declarations. Compare time >> that programmer will waste on search for the r

Re: variable declaration

2005-02-08 Thread Caleb Hattingh
Jeff I fully agree. As I stated in a message to alexander, it is quick and easy even to write a simple project-specific tool for checking that only allowed variable names exist in all the project files. Compared to having to work with tons of effectively useless variable declarations foreve

Re: variable declaration

2005-02-08 Thread Caleb Hattingh
Alexander PowerOfGenerator=TakeFromSensor() if PowerOfGenerator>xxx: RecalcPower(PowerOfGenerator) PutToTheDatabase(PowerOfGenerator) Here, python will not help you. The worst thing is that in such calculations you often receive plausible results. (I think PyChecker has co

Re: variable declaration

2005-02-08 Thread Jeff Shannon
Alexander Zatvornitskiy wrote: Another example. Let say you have variable PowerOfGenerator in your program. But, it is only active power, so you have to (1)rename PowerOfGenerator to ActivePowerOfGenerator, (2)calculate ReactivePowerOfGenerator, and (3)calculate new PowerOfGenerator by formula Po

Re: variable declaration

2005-02-08 Thread Thomas Bartkus
"Alexander Zatvornitskiy" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > The worst thing is that in such calculations you often receive plausible results. Exactly so! An ordinary spelling error gets promoted to a logic error that is damn difficult to detect, let alone trace! Bef

Re: variable declaration

2005-02-08 Thread Alex Martelli
top <[EMAIL PROTECTED]> wrote: > Alex Martelli wrote: > [snip] > > I disagree: compile time is when the compiler is running (for > example, > > the compiler is the component which diagnoses syntax errors, while > other > > errors are diagnosed ``at runtime''). > [snip] > > That thing about syntax

Re: variable declaration

2005-02-08 Thread Fredrik Lundh
"top" <[EMAIL PROTECTED]> wrote: > That thing about syntax errors is news to me. I thought they were > caught at runtime, since you can catch them as exceptions, as in: > > try: prijnt projnt > except SyntaxError: print "See, it gets caught" > > If this happens at compile-time, I'd like to know ho

Re: variable declaration

2005-02-08 Thread top
Alex Martelli wrote: [snip] > I disagree: compile time is when the compiler is running (for example, > the compiler is the component which diagnoses syntax errors, while other > errors are diagnosed ``at runtime''). [snip] That thing about syntax errors is news to me. I thought they were caught at

Re: variable declaration

2005-02-08 Thread Brian van den Broek
Brian van den Broek said unto the world upon 2005-02-07 20:36: Steve Holden said unto the world upon 2005-02-07 17:51: The reason global is a wart can clearly be seen in the following example: >>> x = 3 >>> def f(tf, v): ... if tf: ... global x ... x = v ... >>> f(0, 5) >>> x 5 >>

Re: variable declaration

2005-02-08 Thread Antoon Pardon
Op 2005-02-08, Nick Coghlan schreef <[EMAIL PROTECTED]>: > Antoon Pardon wrote: >> I have the impression you are looking at this too much from the view >> of the current implementation where putting a an entry in >> a directory is seen as an atomic operation. > > Yes and no. I *am* looking at it fr

variable declaration

2005-02-08 Thread Alexander Zatvornitskiy
Hi, Peter! 05 feb 2005 at 15:28, Peter Otten wrote: >> variable names. You have to move the code into a function, though: $ >> cat epsilon.py ...skipped... $ pychecker epsilon.py epsilon.py:6: >> Local variable (epselon) not used Well, I can change it a little to >> pass this check. Just add

Re: variable declaration

2005-02-08 Thread Fredrik Lundh
Peter Otten wrote: >> executed. the compiler handles "global" and "from __future__", everything >> else is done at runtime. > > and __debug__, too, it seems: you left out the "python -O" line. __debug__ > False def f(): > ... if __debug__: > ... global x > ... x = 4

Re: variable declaration

2005-02-08 Thread Nick Coghlan
Antoon Pardon wrote: I have the impression you are looking at this too much from the view of the current implementation where putting a an entry in a directory is seen as an atomic operation. Yes and no. I *am* looking at it from an implementation point of view, but dictionaries have nothing to do

Re: variable declaration

2005-02-08 Thread Nick Coghlan
Just wrote: In article <[EMAIL PROTECTED]>, Nick Coghlan <[EMAIL PROTECTED]> wrote: Antoon Pardon wrote:ons already existing. The compilor might generate a RESTORE instruction. Whether it is done as a LOAD/STORE or a RESTORE, it has to perform the same work - check the name exists in the local

Re: variable declaration

2005-02-08 Thread Antoon Pardon
Op 2005-02-08, Nick Coghlan schreef <[EMAIL PROTECTED]>: > Antoon Pardon wrote:ons already existing. >> The compilor might generate a RESTORE instruction. > > Whether it is done as a LOAD/STORE or a RESTORE, it has to perform the same > work > - check the name exists in the local namespace, and t

Re: variable declaration

2005-02-08 Thread Duncan Booth
Brian van den Broek wrote: > Can it then be further (truly :-) ) said that > > if False: > # thousands of lines of code here > > would effect the structure of the function object's bytecode, but not > its behaviour when run? Or, at most, would cause a performance effect > due to the bytec

Re: variable declaration

2005-02-08 Thread Peter Otten
Fredrik Lundh wrote: > executed. the compiler handles "global" and "from __future__", everything > else is done at runtime. and __debug__, too, it seems: >>> __debug__ False >>> def f(): ... if __debug__: ... global x ... x = 42 ... >>> f() >>> x Traceback (most recent call l

Re: variable declaration

2005-02-08 Thread Just
In article <[EMAIL PROTECTED]>, Nick Coghlan <[EMAIL PROTECTED]> wrote: > Antoon Pardon wrote:ons already existing. > > The compilor might generate a RESTORE instruction. > > Whether it is done as a LOAD/STORE or a RESTORE, it has to perform the same > work > - check the name exists in the loc

Re: variable declaration

2005-02-08 Thread Nick Coghlan
Antoon Pardon wrote:ons already existing. The compilor might generate a RESTORE instruction. Whether it is done as a LOAD/STORE or a RESTORE, it has to perform the same work - check the name exists in the local namespace, and throw an exception if it doesn't. If it the name does exist, perform a

Re: variable declaration

2005-02-08 Thread Fredrik Lundh
Terry Reedy wrote: >>At compile time (by which I mean when the Python bytecode is built) > > Compile time is when the def statement is executed no, that's run time. "def" is an executable statement, just like "print", "for", assignments, "import", etc. the entire module is compiled (to bytecod

Re: variable declaration

2005-02-08 Thread Alex Martelli
Terry Reedy <[EMAIL PROTECTED]> wrote: > "Brian van den Broek" <[EMAIL PROTECTED]> wrote in message > news:[EMAIL PROTECTED] > > Is the right way to understand it in this vicinity: > > In the vicinity, but not quite exact > > >At compile time (by which I mean when the Python bytecode is built)

Re: variable declaration

2005-02-07 Thread Terry Reedy
"Brian van den Broek" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > Is the right way to understand it in this vicinity: In the vicinity, but not quite exact >At compile time (by which I mean when the Python bytecode is built) Compile time is when the def statement is executed

Re: variable declaration

2005-02-07 Thread Brian van den Broek
Steve Holden said unto the world upon 2005-02-07 17:51: Alexander Zatvornitskiy wrote: Привет Alex! 05 февраля 2005 в 17:00, Alex Martelli в своем письме к All писал: AM> to all intents and purposes working "as if" AM> it was a declaration. If I had to vote about the one worst formal AM> defec

Re: variable declaration

2005-02-07 Thread Steve Holden
Alexander Zatvornitskiy wrote: Привет Alex! 05 февраля 2005 в 17:00, Alex Martelli в своем письме к All писал: >> AM> The fact that in Python there are ONLY statements, NO >> AM> declarations, >> What is "global"? Statement? Ok, I fill lack of "var" statement:) AM> 'global' is an ugly wart, O

Re: variable declaration

2005-02-07 Thread Alex Martelli
Alexander Zatvornitskiy <[EMAIL PROTECTED]> wrote: > ?? Alex! > > 05 ??? 2005 ? 17:00, Alex Martelli ? ? ?? ? All ?: > >> AM> The fact that in Python there are ONLY statements, NO > >> AM> declarations, > >> What is "global"? Statement? Ok, I fill lack of "var" statement:

variable declaration

2005-02-07 Thread Alexander Zatvornitskiy
Привет Nick! 06 февраля 2005 в 02:54, Nick Coghlan в своем письме к Python List писал: NC> An alternate proposal, where the decision to request rebinding NC> semantics is made at the point of assignment: NC> epsilon = 0 NC> S = 0 NC> while epsilon < 10: NC>S .= S + epsilon NC>epsel

variable declaration

2005-02-07 Thread Alexander Zatvornitskiy
e that programmer will waste on search for the reason of bug >> caused by such typo, plus time what programmer will waste while >> remembering exact variable name. AM> I've been programming essentially full-time in Python for about three AM> years, plus a few more years

Re: variable declaration

2005-02-07 Thread Antoon Pardon
Op 2005-02-07, Nick Coghlan schreef <[EMAIL PROTECTED]>: > Antoon Pardon wrote: >> Op 2005-02-05, Nick Coghlan schreef <[EMAIL PROTECTED]>: >> >> >>>[ ... ] >>> >>>With a rebinding operator, the intent of the last line can be made explicit: >>> >>>def collapse(iterable): >>> it = iter(iterabl

Re: variable declaration

2005-02-07 Thread Nick Coghlan
Antoon Pardon wrote: Op 2005-02-05, Nick Coghlan schreef <[EMAIL PROTECTED]>: [ ... ] With a rebinding operator, the intent of the last line can be made explicit: def collapse(iterable): it = iter(iterable) lastitem = it.next() yield lastitem for item in it: if item != last

Re: variable declaration

2005-02-07 Thread Antoon Pardon
Op 2005-02-05, Roy Smith schreef <[EMAIL PROTECTED]>: > In article <[EMAIL PROTECTED]>, > [EMAIL PROTECTED] (Alexander > Zatvornitskiy) wrote: > >> And, one more question: do you think code like this: >> >> var S=0 >> var eps >> >> for eps in xrange(10): >> S=S+ups >> >> is very bad? Please

Re: variable declaration

2005-02-07 Thread Antoon Pardon
Op 2005-02-05, Nick Coghlan schreef <[EMAIL PROTECTED]>: > [ ... ] > > With a rebinding operator, the intent of the last line can be made explicit: > > def collapse(iterable): > it = iter(iterable) > lastitem = it.next() > yield lastitem > for item in it: > if item !=

Re: variable declaration

2005-02-07 Thread Nick Coghlan
Roy Smith wrote: I'm not sure what that last sentence is supposed to mean, but I have visions (nightmares?) of someday having ANSI, ISO, IEEE, or some other such organization notice that something useful exists which they haven't yet standardized/broken and decide to form a committee to do it. S

Re: variable declaration

2005-02-06 Thread Arthur
On Sun, 06 Feb 2005 08:20:29 -0500, Jeremy Bowers <[EMAIL PROTECTED]> wrote: >On Sun, 06 Feb 2005 07:30:33 -0500, Arthur wrote: >> What if: >> >> There was a well conducted market survey conclusive to the effect that >> adding optional strict variable dec

Re: variable declaration

2005-02-06 Thread Jeremy Bowers
On Sun, 06 Feb 2005 07:30:33 -0500, Arthur wrote: > What if: > > There was a well conducted market survey conclusive to the effect that > adding optional strict variable declaration would, in the longer run, > increase Python's market share dramatically. > > It jus

Re: variable declaration

2005-02-06 Thread Alex Martelli
Roy Smith <[EMAIL PROTECTED]> wrote: > > which is good news for sellers of books, tools, training, consultancy > > services, and for Python programmers everywhere -- more demand always > > helps. *BUT* the price is eternal vigilance... > > I'm not sure what that last sentence is supposed to mean

Re: variable declaration

2005-02-06 Thread Roy Smith
In article <[EMAIL PROTECTED]>, [EMAIL PROTECTED] (Alex Martelli) wrote: > This is a good development, overall. Against stupidity, the gods > themselves contend in vain; Python's entrance into stupid firms broadens > its potential appeal from less than 10% to around 100% of the market, > which i

Re: variable declaration

2005-02-06 Thread Arthur
a well conducted market survey conclusive to the effect that adding optional strict variable declaration would, in the longer run, increase Python's market share dramatically. It just would. More books. more jobs, etc. Why would it? My sense of how the real world works is that there is goin

Re: variable declaration

2005-02-05 Thread Alex Martelli
Arthur <[EMAIL PROTECTED]> wrote: > Do the STUPID firms use Python as well. Yes, they're definitely starting to do so. > Why? The single most frequent reason is that some techie sneaked it in, for example "just for testing" or "to do a prototype" or even without any actual permission. Firms

Re: variable declaration

2005-02-05 Thread Alex Martelli
Nick Coghlan <[EMAIL PROTECTED]> wrote: ... > > _temp = x.y > > x.y = type(temp).__irebind__(temp, z) ... > I was thinking of something simpler: > >x.y >x.y = z > > That is, before the assignment attempt, x.y has to resolve to *something*, but > the interpreter isn't particu

Re: variable declaration

2005-02-05 Thread Nick Coghlan
Alex Martelli wrote: It's not clear to me what semantics, exactly, x.y := z would be defined to have (assuming := is the syntax sugar for ``rebinding''). Perhaps, by analogy with every other augmented operator, it should be equivalent to: _temp = x.y x.y = type(temp).__irebind__(temp, z) T

Re: variable declaration

2005-02-05 Thread Arthur
On Sat, 5 Feb 2005 20:02:44 +0100, [EMAIL PROTECTED] (Alex Martelli) wrote: >Arthur <[EMAIL PROTECTED]> wrote: > >> On Sat, 5 Feb 2005 17:00:15 +0100, [EMAIL PROTECTED] (Alex Martelli) >> wrote: >> > >> >I consider this one of the worst ideas to have been proposed on this >> >newsgroup over the ye

Re: variable declaration

2005-02-05 Thread Alex Martelli
Arthur <[EMAIL PROTECTED]> wrote: > On Sat, 5 Feb 2005 17:00:15 +0100, [EMAIL PROTECTED] (Alex Martelli) > wrote: > > > >I consider this one of the worst ideas to have been proposed on this > >newsgroup over the years, which _IS_ saying something. \ > > I would disagree, but only to the extent th

Re: variable declaration

2005-02-05 Thread Arthur
On Sat, 5 Feb 2005 17:00:15 +0100, [EMAIL PROTECTED] (Alex Martelli) wrote: > >I consider this one of the worst ideas to have been proposed on this >newsgroup over the years, which _IS_ saying something. \ I would disagree, but only to the extent that nothing that is only a request for an option t

Re: variable declaration

2005-02-05 Thread Alex Martelli
Nick Coghlan <[EMAIL PROTECTED]> wrote: > Alex Martelli wrote: > > 'global' is an ugly wart, to all intents and purposes working "as if" it > > was a declaration. If I had to vote about the one worst formal defect > > of Python, it would surely be 'global'. > > > > Fortunately, it's reasonably e

Re: variable declaration

2005-02-05 Thread Nick Coghlan
Alexander Zatvornitskiy wrote: var epsilon=0 var S S=0 while epsilon<10: S=S+epsilon epselon=epsilon+1#interpreter should show error here,if it's in "strict mode" print S It is easy, and clean-looking. Alexander, [EMAIL PROTECTED] An alternate proposal, where the decision to request rebinding s

Re: variable declaration

2005-02-05 Thread Nick Coghlan
Alex Martelli wrote: 'global' is an ugly wart, to all intents and purposes working "as if" it was a declaration. If I had to vote about the one worst formal defect of Python, it would surely be 'global'. Fortunately, it's reasonably easy to avoid the ugliness, by avoiding rebinding (within functio

  1   2   >