Is it possible to do something like this in Python?  class MyClass():     def __init__(self):         someValue = 42          str = 'a'         # self.a = someValue         str = 'xyz'         # self.xyz = someValue          Essentially what I want to achieve is by reading the value of str (say the value of str resolves to 'myValue'), the code adds an additional attribute (self.myValue) into the class.
Suppose I have a python object x and a string s, how do I set the attribute s on x? So:  &gt;&gt;&gt; x = SomeObject() &gt;&gt;&gt; attr = 'myAttr' &gt;&gt;&gt; # magic goes here &gt;&gt;&gt; x.myAttr 'magic'   What's the magic? The goal of this, incidentally, is to cache calls to x.__getattr__().
Best way to deal with questions answered by the OP in the question instead of in an answer I saw this question:   I don't know what the best option is for dealing with such a question, because I've seen questions like this several times already.  So, what should we do with questions that are:   poorly asked finally answered by the OP as an update to the question itself, not as an answer. Is it possible to mark the same tag as "Interesting" and "Ignored"? Can you mark the same tag as both interesting and ignored? If you can, what is the resulting appearance of a question with that tag? Changing default width of blocks in beamer What is a smart pointer and when should I use one? Invite people who liked my first page to like another one in Facebook Suppose we have $x^2+4x+3=0$  We differentiate both sides to get $2x+4=0$.  So $x=-2$  But $(-2)^2+4(-2)+3=0$   $4-8+3=-1$ is not equal to $0$.  Which tells that we cannot differentiate equalities. But in many proofs, like in integral calculus, differentiating both sides occurs. So, where is the fallacy? System.FinalException: Record is read-only: Trigger.updateCompetitors: line 24 I am writing a trigger to get all the Opportunity competitors into a field on Opportunity, however, getting an error while testing it.  Error: updateCompetitors: execution of AfterUpdate caused by: System.FinalException: Record is read-only: Trigger.updateCompetitors: line 24  Can you please check the below code and suggest me what's wrong with this?  trigger updateCompetitors on Opportunity(after insert, after update){    List&lt;Opportunity&gt; OppIds = new List&lt;Opportunity&gt;();     for (Opportunity opp: trigger.new){         OppIds.add(opp);     }  List&lt;OpportunityCompetitor&gt; oppComps = new List&lt;OpportunityCompetitor&gt;();  oppComps= [select id, CompetitorName, Strengths, Weaknesses from OpportunityCompetitor where OpportunityId in: Trigger.newMap.keySet()];  List&lt;Opportunity&gt; OppstoUpdate = new List&lt;Opportunity&gt;();   for (Opportunity opp: OppIds){     String allcomps = null;      if( oppComps.size()&gt;0 ) {       for (integer i = 0; i &lt; oppComps.size(); i++){          allcomps = allcomps + oppComps[i].CompetitorName+',';       }     }    opp.OpportunityCompetitors__c = allcomps;    OppstoUpdate.add(opp);  }    update OppstoUpdate; } Why can rm remove read-only files? What would be the best way to calculate someone's age in years, months, and days in T-SQL (SQL Server 2000)?  The datediff function doesn't handle year boundaries well, plus getting the months and days separate will be a bear.  I know I can do it on the client side relatively easily, but I'd like to have it done in my . What does recursive cosine sequence converge to? I have a sequence defined as follow:  $a_0 = 1, a_n=\cos\left(a_{n-1}\right)$.  I want to count $\lim_{n\rightarrow\infty} a_n$ - it definitely does have limit by looking at the graph, the first few numbers of the limit are 0.7390851, but I have no idea, if that number is related to some other real number ($\pi$ or something like that).  The sequence is from , but they don't provide actual result for their own sequence. Guaranteed lifetime of temporary in C++? Motivation for Napier's Logarithms In the wikipedia article on logarithms, I am clueless about the approach and motivation for the following computations done by Napier (and the mysterious appearance of Euler's number) in this . Please help me understand:       By repeated subtractions Napier   calculated $10^7(1 − 10^{−7})^L$ for L   ranging from 1 to 100. The result for   $L=100$ is approximately $0.99999 = 1  − 10^{-5}$. Napier then calculated the   products of these numbers with $10^7(1  − 10^{−5})^L$ for L from 1 to 50, and   did similarly with $0.9995 ≈ (1 −  10^{−5})^{20}$ and $0.99 ≈ 0.995^{20}$.   These computations, which occupied 20   years, allowed him to give, for any   number ''N'' from 5 to 10 million, the   number ''L'' that solves the equation      $$N=10^7 {(1-10^{-7})}^L$$      In modern notation, the relation to   natural logarithms is:      $$L = \log_{(1-10^{-7})} \!\left(  \frac{N}{10^7} \right) \approx 10^7  \log_{ \frac{1}{e}} \!\left(  \frac{N}{10^7} \right) = -10^7 \log_e  \!\left( \frac{N}{10^7} \right)$$      where the very close approximation   corresponds to the observation that      $${(1-10^{-7})}^{10^7} \approx  \frac{1}{e}. $$   I understand the computations, but I don't know what's going on. How closely can we estimate $\sum_{i=0}^n \sqrt{i}$ By looking at an integral and bounding the error? Property of the conjugate transpose matrix with inner product Recovering broken or deleted NTFS partitions How can I comment out a block of text in texmaker? I use texmaker and some time ago I found, by chance, a way to comment many lines at once, but I can't remember it now. Can somebody remind me of that? Acces VBA code combination not working, issue with exit sub? I'm very new at VBA and I can't seem to solve this problem. It seems like it should be an easy problem to fix, I just don't know how.   So what the code does: In the main form is a record. This record will be copied to another table bij pressing a button on the form. Before the copying begins, the code checks first if the 'OMnummer' has been filled in in the subform.  If not, a message box appears saying that the user should fill in the subform and the code stops running.   Secondly the code checks if the record is allready present in the other table. If so, a messagebox appears and the record will not be copied. If not, the record will be copied to the other table.   Both pieces of code work ok seperately. However, when I try to include both pieces in the same private sub, only the first one works. It may be something with the 'Exit Sub' code or I am not using the If - Then right.   Hope you can help me!  Monika   Private Sub KnopProjectVersturen_Click() On Error GoTo ErrProc  If IsNull(Me!Subform_OMnummers.Form!Omnr) Then  If MsgBox("Vul het OMnummer in. Je kan het project niet exporteren zonder OMnummer.")     Then       Exit Sub      DoCmd.OpenQuery "Qry_Depo_ControleAanwezig"  If DCount("Deponering.projectnummer", "Qry_Depo_ControleAanwezig") = 0 Then         DoCmd.SetWarnings False         DoCmd.OpenQuery "Qry_projectnaarDepot"          DoCmd.OpenQuery "Qry_ToevoegProjectDepot"         DoCmd.OpenForm "Depot_uitvoer", , , "[Projectnummer] = '" &amp; Me![Projectnummer] &amp; "' And [subID]=[subID]"     Me.Status = 8     DoCmd.Close acQuery, ("Qry_Depo_ControleAanwezig")     DoCmd.SetWarnings True  Else         MsgBox "Dit project bestaat al in de Depot_Uitvoer, verander de status in het projectformulier", vbInformation, "Example"         DoCmd.Close acQuery, ("Qry_Depo_ControleAanwezig")     End If  End If  End If    'Als er fouten zijn laat deze code een messagebox zien met het nummer en de melding.  ExitProc:  Exit Sub  ErrProc:     Select Case Err.Number     Case Else         MsgBox Err.Number &amp; "--" &amp; Err.Description         Resume ExitProc         End Select End Sub How to render an animation as video in Blender? Yesterday I was working on a simple animation, an animated logo.   Here is an image of the progress:    I already have the animation working and everything is okay with the project, but I can't figure out how I can render the animation and turn it into an AVI format video.  How do I render an animation in Blender? What is so special about Prime? Getting full JS autocompletion under Sublime Text