Python - short syntax and list comprehension and iterations -


I'm a big fan of understanding Python's list and I think it's really easy to read from running regularly .

I am writing a constructor which has an alternative code that can be used to set ** kwargs square etters, and I understand it as a list I want to write, but it seems there is no list which does not actually do anything to consider:

  class book (object): attrs = ('id', 'title ',' Authors', ...) def __init __ (self, * args, ** kwargs): [orator (self, atri, etter) If kwargs.get (attr)]   

however the syntax looks good, I think it is bad coding because you have

  [none , None, no one ...]   

, they are just sitting there and yes I know it is collected after the constructor is run, but I Still do not like it. If I have read someone's code, then I will be uncompressed.

Is there a better way to do such a recursive list as clear as a list but do not make useless objects

Edit: < P> To use loop

  class book (object): Attrs = ('id', 'title', 'writer', ...) def __init __ (self, * Args, ** kwargs): For attr in attrs: if kwargs.get (set): setattr (self, attr, kwargs.get (attr)   

Is it that you guys What are you saying? If not, a better way to write Instead of understanding the list, you can use direct generator expression:

  class book (object): attrs = ('id', 'title', 'authors', ...) def __init __ (self, * args, ** kwargs): self. In the Python 3, it also uses the update for k (एtr, quoraj [k]) and   

in __ dictra, Kwargs.viewkeys () Simply use kwargs.viewkeys () instead of kwargs.keys () . A dictionary acts as a visual set; & amp; Self.attrs creates intersection between the keys and your list of properties of the expression .

The generator expression produces (key, value) is one of two acceptable inputs for pair.

Updating

OK ; The Python 2.7 standard library uses this technique in 7 different places, as well as some 30 other cases of mutation. Keep in mind that if you are using the descriptor ( @property and / or other custom descriptor), then bypassing those who reach self.decc_____ .

To understand the list for side effects: just not. You are actually wasting the cycles that make such inventory objects that are immediately abandoned, there is a list of misleading expectations in terms of .

Viewkeys () & amp; Self. Etter: sateterer (self, atri, quarrel [atri])

Comments

Popular posts from this blog

ios - Adding an SKSpriteNode to SKScene from a child SKSpriteNode -

Matlab transpose a table vector -

c# - Textbox not clickable but editable -