Re: Declaring variables
On May 16, 6:48 pm, Matimus [EMAIL PROTECTED] wrote: On May 16, 9:57 am, HMS Surprise [EMAIL PROTECTED] wrote: I looked in the language but did not find a switch for requiring variables to be declared before use. Is such an option available? Thanks, jvh You do have to declare a variable before use. You do so by assigning it a value. You can't use a variable before it has been assigned. Yes this is where the problem arises. This is a gross oversimplification , but is where I typically find problems. jh #~~ createdIncidentId = 0 . . . #attempt to change varialbe createdIncidentID = 1 . . . if createdIncidentId == 1: ... -- http://mail.python.org/mailman/listinfo/python-list
Re: Declaring variables
HMS Surprise schrieb: #~~ createdIncidentId = 0 . . . #attempt to change varialbe createdIncidentID = 1 . . . if createdIncidentId == 1: ... test.py is your code above $ pychecker -v test.py Processing test... Warnings... test.py:7: Variable (createdIncidentID) not used Gregor -- http://mail.python.org/mailman/listinfo/python-list
Re: Declaring variables
On 2007-05-16, HMS Surprise [EMAIL PROTECTED] wrote: No haven't had to endure Pascal. Mostly C/C++, Tcl, and assembler. I must have you mixed up with somebody else who recently mentioned having Pascal as their first real language. -- Grant Edwards grante Yow! It's OKAY -- I'm an at INTELLECTUAL, too. visi.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Declaring variables
On May 17, 9:34 am, Grant Edwards [EMAIL PROTECTED] wrote: On 2007-05-16, HMS Surprise [EMAIL PROTECTED] wrote: No haven't had to endure Pascal. Mostly C/C++, Tcl, and assembler. I must have you mixed up with somebody else who recently mentioned having Pascal as their first real language. -- Grant Edwards grante Yow! It's OKAY -- I'm an at INTELLECTUAL, too. visi.com That's OK. I am easily mixed up. -- http://mail.python.org/mailman/listinfo/python-list
Re: Declaring variables
On 2007-05-16, HMS Surprise [EMAIL PROTECTED] wrote: I looked in the language but did not find a switch for requiring variables to be declared before use. Still trying to write Pascal, eh? ;) Is such an option available? No. However, there are utilities to proofread your code should you have a desire for that: http://www.logilab.org/pylint http://pychecker.sourceforge.net/ -- Grant Edwards grante Yow! What I need is a at MATURE RELATIONSHIP with a visi.comFLOPPY DISK ... -- http://mail.python.org/mailman/listinfo/python-list
Re: Declaring variables
No haven't had to endure Pascal. Mostly C/C++, Tcl, and assembler. Oh yeah, and a (thankfully) short stint of Ada. But I glad to hear of the proofing tools. Working a lot of data parsed from web pages and the developer there a different naming convention from what I am accustomed so sometimes I introduce a new variable unintentionally. Thanks, jvh -- http://mail.python.org/mailman/listinfo/python-list
Re: Declaring variables
On May 16, 9:57 am, HMS Surprise [EMAIL PROTECTED] wrote: I looked in the language but did not find a switch for requiring variables to be declared before use. Is such an option available? Thanks, jvh You do have to declare a variable before use. You do so by assigning it a value. You can't use a variable before it has been assigned. In some ways this is less ambiguous than even C where you can declare a variable without assigning a value. Also note that this caries the type information, since the variable is of whatever type was assigned to it. The only thing it doesn't do is give a unique flag that says hey this is where I'm declared, although I suppose you could do that with a comment. Matt -- http://mail.python.org/mailman/listinfo/python-list
Re: Declaring variables
Matimus wrote: On May 16, 9:57 am, HMS Surprise [EMAIL PROTECTED] wrote: I looked in the language but did not find a switch for requiring variables to be declared before use. Is such an option available? Thanks, jvh You do have to declare a variable before use. You do so by assigning it a value. You can't use a variable before it has been assigned. In some ways this is less ambiguous than even C where you can declare a variable without assigning a value. Also note that this caries the type information, since the variable is of whatever type was assigned to it. The only thing it doesn't do is give a unique flag that says hey this is where I'm declared, although I suppose you could do that with a comment. Strictly, the variable has no type at all (and strictly your variables are actually names bound to values in a namespace, and it's the values that are typed). We shouldn't ignore the fact that declarations unambiguously say the programmer intends to use such-and-such a name for a value of a specific type. Contrast this with a Python program where one path makes an assignment (binding) to a name while another path doesn't, resulting in a later NameError. regards Steve -- Steve Holden+1 571 484 6266 +1 800 494 3119 Holden Web LLC/Ltd http://www.holdenweb.com Skype: holdenweb http://del.icio.us/steve.holden -- Asciimercial - Get on the web: Blog, lens and tag your way to fame!! holdenweb.blogspot.comsquidoo.com/pythonology tagged items: del.icio.us/steve.holden/python All these services currently offer free registration! -- Thank You for Reading -- http://mail.python.org/mailman/listinfo/python-list
Re: Declaring variables from a list
You can use the built-in statement exec (http://www.python.org/doc/2.4.1/ref/exec.html) : # Blob = ['Var1', 'Var2', 'vAR3'] # i = 5 # for listitems in Blob: # i += 1 # exec('%s = i' %listitems) # # print Var1, Var2, vAR3 Regards, Pierre -- http://mail.python.org/mailman/listinfo/python-list
Re: Declaring variables from a list
Fredrik Lundh [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED]... Cactus wrote: If I got a list is it possible to declare a variable from the items in that list? Code Sample: Blob = ['Var1', 'Var2', 'vAR3'] i = 5 for listitems in Blob: i += 1 listitems = i print Var1 6 print Var2 7 print vAR3 8 Something like that? This doesn't work (obviously) but is there a way to do this? why? if you want a dictionary, use a dictionary (see the tutorial for details). /F Thanks, I'll look in to that. Seems like that will work Cacti -- http://mail.python.org/mailman/listinfo/python-list
Re: Declaring variables from a list
Cactus wrote: If I got a list is it possible to declare a variable from the items in that list? Code Sample: Blob = ['Var1', 'Var2', 'vAR3'] i = 5 for listitems in Blob: i += 1 listitems = i print Var1 6 print Var2 7 print vAR3 8 Something like that? This doesn't work (obviously) but is there a way to do this? why? if you want a dictionary, use a dictionary (see the tutorial for details). /F -- http://mail.python.org/mailman/listinfo/python-list
Re: Declaring variables from a list
Python has a builtin function called locals which returns the local context as a dictionary locals = locals() locals[a] = 5 a 5 locals[a] = changed a 'changed' On 8 Apr 2005 13:55:39 -0700, Cactus [EMAIL PROTECTED] wrote: Hi, If I got a list is it possible to declare a variable from the items in that list? Code Sample: Blob = ['Var1', 'Var2', 'vAR3'] i = 5 for listitems in Blob: i += 1 listitems = i print Var1 6 print Var2 7 print vAR3 8 Something like that? This doesn't work (obviously) but is there a way to do this? TIA, Cacti -- http://mail.python.org/mailman/listinfo/python-list -- http://blogs.applibase.net/sidharth -- http://mail.python.org/mailman/listinfo/python-list
Re: Declaring variables from a list
On Sat, Apr 09, 2005 at 03:15:01AM +0530, Sidharth Kuruvila wrote: Python has a builtin function called locals which returns the local context as a dictionary locals = locals() locals[a] = 5 a 5 locals[a] = changed a 'changed' From Python lib reference: locals() ... Warning: The contents of this dictionary should not be modified; changes may not affect the values of local variables used by the interpreter. -- http://mail.python.org/mailman/listinfo/python-list
Re: Declaring variables from a list
What I gave was a bad solution. Something that works right now, but probably shouldn't be done. On Apr 9, 2005 3:37 AM, Inyeol Lee [EMAIL PROTECTED] wrote: On Sat, Apr 09, 2005 at 03:15:01AM +0530, Sidharth Kuruvila wrote: Python has a builtin function called locals which returns the local context as a dictionary locals = locals() locals[a] = 5 a 5 locals[a] = changed a 'changed' From Python lib reference: locals() ... Warning: The contents of this dictionary should not be modified; changes may not affect the values of local variables used by the interpreter. -- http://mail.python.org/mailman/listinfo/python-list -- http://blogs.applibase.net/sidharth -- http://mail.python.org/mailman/listinfo/python-list