what python function replace functionaly for php operator $$
hi in php im able to create variable like this
$param = array('product', 'brand');
foreach ($param as $item) {
$$item = $item;
}
so the result will be
$product = 'product';
how can i achieve 开发者_如何学JAVAthis in python?
param = ['product', 'brand']
for item in param:
??? = item
You can't, sanely. Use a dict instead.
items = {}
for item in param:
items[item] = item
param = ['product', 'brand']
for item in param:
globals()[item] = item
But it's not a good idea to do so.
精彩评论