Question about locals()

Gökhan SEVER gokhansever at gmail.com
Fri May 22 10:27:12 EDT 2009


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 than using locals() to construct variable-like
identities in my program.

Gökhan


On Fri, May 22, 2009 at 3:34 AM, Gabriel Genellina
<gagsl-py2 at yahoo.com.ar>wrote:

> En Tue, 19 May 2009 14:06:04 -0300, Gökhan SEVER <gokhansever at 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
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20090522/7b442f86/attachment.html>


More information about the Python-list mailing list