Re: Question about locals()

2009-05-22 Thread Gabriel Genellina
En Tue, 19 May 2009 14:06:04 -0300, Gökhan SEVER gokhanse...@gmail.com escribió: I will make double sure myself while using locals() to end up with valid identifiers. I would ask myself why I'm using locals() in the first place. -- Gabriel Genellina --

Re: Question about locals()

2009-05-22 Thread Gökhan SEVER
Hello, I use local() because I read a file which has many consecutive variables in it. Like shown below: (I use numpy's txt reading function) serialc = np.loadtxt(sys.argv[1], skiprows=skiprows).T for i in range(20): locals()['serialc_bin' + str(i+1)] = serialc[i+4] I don't know easier way

Re: Question about locals()

2009-05-22 Thread David Robinow
On Fri, May 22, 2009 at 10:27 AM, Gökhan SEVER gokhanse...@gmail.com wrote: ... serialc = np.loadtxt(sys.argv[1], skiprows=skiprows).T for i in range(20):     locals()['serialc_bin' + str(i+1)] = serialc[i+4] I don't know easier way than using locals() to construct variable-like identities

Re: Question about locals()

2009-05-22 Thread Gökhan SEVER
Because in this case serialc is an numpy array. Since loadtxt returns a numpy-array. Furthermore locals()['serialc_bin' + str(i+1)] creates a dictionary key (that's what I use the term variable-like) serialc_bin1, serialc_bin2, ... not serialc_bin[0] with indexes. Gökhan On Fri, May 22, 2009

Re: Question about locals()

2009-05-22 Thread J. Cliff Dyer
Top-posting corrected. On Fri, 2009-05-22 at 10:00 -0500, Gökhan SEVER wrote: On Fri, May 22, 2009 at 9:43 AM, David Robinow drobi...@gmail.com wrote: On Fri, May 22, 2009 at 10:27 AM, Gökhan SEVER gokhanse...@gmail.com wrote: ... serialc =

Re: Question about locals()

2009-05-22 Thread David Robinow
On Fri, May 22, 2009 at 11:00 AM, Gökhan SEVER gokhanse...@gmail.com wrote: Because in this case serialc is an numpy array. Since loadtxt returns a numpy-array. Furthermore locals()['serialc_bin' + str(i+1)]  creates a dictionary key (that's what I use the term variable-like) serialc_bin1,

Re: Question about locals()

2009-05-19 Thread Steven D'Aprano
Sorry for breaking threading, the original post is not being carried by my ISP. On Tue, 19 May 2009, Gökhan SEVER wrote: Hello, Could you please explain why locals() allow me to create variables that are not legal in Python syntax. Example: locals()['1abc'] = 55. Calling of 1abc results

Re: Question about locals()

2009-05-19 Thread Gökhan SEVER
Thank you all for great explanation on this subject. Maybe a few sentences from these conversations could be added to locals() documentation. I will make double sure myself while using locals() to end up with valid identifiers. Gökhan On Tue, May 19, 2009 at 1:06 AM, Steven D'Aprano

Question about locals()

2009-05-18 Thread Gökhan SEVER
Hello, Could you please explain why locals() allow me to create variables that are not legal in Python syntax. Example: locals()['1abc'] = 55. Calling of 1abc results with a syntax error. Shouldn't it be better to raise an error during the variable creation time? Thank you Gökhan --

Re: Question about locals()

2009-05-18 Thread John O'Hagan
On Tue, 19 May 2009, Gökhan SEVER wrote: Hello, Could you please explain why locals() allow me to create variables that are not legal in Python syntax. Example: locals()['1abc'] = 55. Calling of 1abc results with a syntax error. Shouldn't it be better to raise an error during the variable

Re: Question about locals()

2009-05-18 Thread Terry Reedy
Gökhan SEVER wrote: Hello, Could you please explain why locals() allow me to create variables that are not legal in Python syntax. It doesn't. Example: locals()['1abc'] = 55. Calling of 1abc results with a syntax error. Within a function, locals() is a persistemt dictionary copy of the