newbie to python: code doesn't see global variable of one type but it does of another I am new to python, so this may be a silly question...  Why does the function fetchsamples not see the variable smilies? Strangely, the variable frownyDict and smileyDict are accessible, while smilies is not.  The error I get is:  Traceback (most recent call last):   File "simple.py", line 41, in &lt;module&gt;     fetchsamples()   File "simple.py", line 18, in fetchsamples     print smilies UnboundLocalError: local variable 'smilies' referenced before assignment   Below is the python code:  ##my global vars  frownyDict={} smileyDict={} frownyDict['_counter_']=0 smileyDict['_counter_']=0 frownies = 0 smilies = 0    def fetchsamples():     print frownyDict;     response = [":) happy",":( sad","sad","dunno"]     counter=0     print smilies     for tweet in response:         if (tweet):             tweet=tweet.encode("iso-8859-1", "ignore")             if ":)" in tweet:                 parse(smileyDict,tweet)                 counter+=1                 smilies+=1             if ":(" in tweet:                 parse(frownyDict,tweet)                 counter+=1                 #frownies+=1                 frownyDict['_counter_']+=1;             if ":)" in tweet or ":)" in tweet:                 guess(tweet)                 # let's predict!              if (counter % 50==10):                 print frownyDict;                 print smileyDict   if __name__ == '__main__':   fetchsamples()
UnboundLocalError on local variable when reassigned after first use The following code works as expected in both Python 2.5 and 3.0:  a, b, c = (1, 2, 3)  print(a, b, c)  def test():     print(a)     print(b)     print(c)    # (A)     #c+=1       # (B) test()   However, when I uncomment line (B), I get an UnboundLocalError: 'c' not assigned at line (A). The values of a and b are printed correctly. This has me completely baffled for two reasons:   Why is there a runtime error thrown at line (A) because of a later statement on line (B)? Why are variables a and b printed as expected, while c raises an error?   The only explanation I can come up with is that a local variable c is created by the assignment c+=1, which takes precedent over the "global" variable c even before the local variable is created. Of course, it doesn't make sense for a variable to "steal" scope before it exists.  Could someone please explain this behavior?
Print floating point values without leading zero Property of Entire Functions Suppose $f$ and $g$ are entire functions with $|f(z)|\leq|g(z)|$ for all $z$.  How can we show that $f=cg$ for some complex constant $c$?  Thanks for any help :) I am using ring modulator for DSB-SC  am modulation in a transmitter circuit. Can anyone please tell me about more DSB SC modulator for am modulation? I want to know which one to use where? "Overclocking" an AVR In AVR datasheets under the Electrical Characteristics section you will typically find a graph like this (this one is from the ATMega328):    I've seen designs that seem to "work" but operate outside the shaded envelope. Specifically, I've seen 3.3V (Arduino) designs that run the clock from an external 16MHz crystal. Clearly, this is out of spec. What are the practical negative consequences of running outside this envelope? Wrong Sentence:     Never before in the history of the world such a thing has happened, I don't think that will ever happen again.   Right sentence:     Never Before in the history of the world has such a thing happened, I don't think that will ever happen again.   Why “has such a thing happened” is the right form, and why can't I use such a thing has happened? What is the best way to convert an array to a hash in Ruby In Ruby, given an array in one of the following forms...  [apple, 1, banana, 2] [[apple, 1], [banana, 2]]   ...what is the best way to convert this into a hash in the form of...  {apple =&gt; 1, banana =&gt; 2} Show $\lim_{n \to \infty} n^{-1} E \left( \frac{1}{X}1_{[X>n^{-1}]} \right) =0$ Suppose $X$ is a non-negative random variable satisfying  \begin{align*} P[0 \le X &lt; \infty ]=1. \end{align*} Show   a)  \begin{align*} \lim_{n \to \infty} n E \left( \frac{1}{X}1_{[X&gt;n]} \right) =0 \end{align*} b)  \begin{align*} \lim_{n \to \infty} n^{-1} E \left( \frac{1}{X}1_{[X&gt;n^{-1}]} \right) =0 \end{align*}  What I did  I showed part a) already here is the proof:  \begin{align*} n E \left( \frac{1}{X}1_{[X&gt;n]} \right) \le n E \left( \frac{1}{n}1_{[X&gt;n]} \right)=n\cdot\frac{1}{n}P[X&gt;n]=P[X&gt;n] \end{align*} So $\lim_{n \to \infty} n E \left( \frac{1}{X}1_{[X&gt;n]} \right) \le \lim_{n \to \infty} P[X&gt;n]=0$.  What about part b)? The same techniques no longer works.  I was thinking that  \begin{align*} \lim_{n \to \infty} n E \left( \frac{1}{X}1_{[X&gt;n]} \right) \le \lim_{n \to \infty} n E \left( \frac{1}{X} \right) \le 0 \end{align*} but I am not sure that $E \left( \frac{1}{X} \right) &lt; \infty$ There is an image in the Wikipedia about the :    I have a rough understanding of the stress tensor: you imagine cutting out a tiny cube from the fluid and form a matrix out of the forces on each side of it: it's not hard to see that the forces that push the faces outwards so the x direction of the force on the x side, the y direction of the force on the y side, etc. is the pressure, while other forces directions are the shear stress (these can be non-zero is some jelly-like substance).  Now the first question: Why is the lower half of the spatial part is the momentum flux, while only the upper one is the shear stress on the image? Is the image wrong? Isn't the spatial part describe the classical stress tensor?   The second question is: what's the intuition behind the temporal part?  So if I have a Minkowski spacetime and cut out a cube of it, then it's quite hard to see why "pressure" on the temporal face means density, also why "shear stresses" on the temporal face translate to momentum density, not speaking of the "temporal force components" the spatial faces...  Also stresses are measured in Pascals, mass density is measured in $kg/m^3$ while momentum density is in the units of $Ns/m^3$. These units doesn't seem to be compatible, but still they are in the same matrix, why?  EDIT: It has been pointed out that momentum flux refer to the entire blue part, it indeed have a lighter frame I didn't notice. Then yet another subquestion: what's the difference between the momentum density and momentum flux? Book covering differential geometry and topology for physics I'm interested in learning how to use geometry and topology in physics. Could anyone recommend a book that covers these topics, preferably with some proofs, physical applications, and emphasis on geometrical intuition? I've taken an introductory course in real analysis but no other higher math. Closed form for $\int_0^\infty\frac{1}{(1+x^2)^s}\,dx$ when $s\in (0.5,\infty)\setminus\mathbb{N}$ edges with thickness and color Is there a way to vary the thickness and color of lines created by just edges and vertices? I realize that a face can be defined and then color and material applied, but is there any way to apply a color to the edges? Let $G$, $H$, and $K$ be abelian groups. Assume $G \oplus H \cong G \oplus K$. If each are finitely generated, then the structure theorem easily gives us that $H \cong K$. However, there are counterexamples in the general case, namely $H=\mathbb{Z}$, $K=\mathbb{Z} \oplus \mathbb{Z}$, and $G=\bigoplus_{i=1}^\infty\mathbb{Z}$.   I am wondering what goes wrong with the following argument:   Form the split short exact sequence  $$0 \to G \xrightarrow{i} G \oplus H \xrightarrow{\pi} H \to 0$$  where $i$ and $\pi$ are the inclusion and projection, respectively. Then don't we immediately get from the first isomorphism theorem that $H \cong (G \oplus H)/G$, which would contradict the counterexample above?   If we run this for the counterexample given, we get the sequence   $$0 \to \bigoplus_{i=1}^\infty\mathbb{Z} \to \bigoplus_{i=1}^\infty\mathbb{Z} \to \mathbb{Z} \to 0$$  which seems to still be short exact, even though here $G \cong G \oplus H$. But of course here we can see directly that $(G \oplus H)/G \cong G/G$, which is trivial. So what went wrong?   It seems to me to be something along these lines: In this case, the kernel of the projection is not the same as the original group, it is just, say, $0 \oplus \mathbb{Z} \oplus \mathbb{Z} \oplus \dots$, i.e. nontrivial from the second coordinate on, which just happens to be isomorphic to the original group. So if we form the other short exact sequence with $K$ in place of $H$, then the difference seems to be that we have two different projection maps with different (but isomorphic) kernels.   But I'm not really sure how to explain this in the general case, if my reasoning is correct to begin with.   Thanks in advance for any help! How does a phonon cause two electrons to attract each other and form a cooper pair? We know that like charges repel each other. But my professor claimed that two electrons can attract each other as well. What he said was that due to screening an electron travelling at some speed won't repel another electron, but that they will, in some cases, attract each other due to weak phonon exchange. What does that mean? What is phonon exchange? Do two electrons really attract each other? Use grep to find content in files and move them if they match According to Theorem 8.8 in Time Series A.W. van der Vaart an ARMA process $$\phi (L)X_t=\theta(L)\epsilon_t$$ has a  unique stationary solution $X_t=\psi(L)\epsilon_t$ with $\psi=\theta/\phi$ if $\phi$ has no roots on the complex unit circle. This would imply that the explosive process, with $\rho&gt;1$, is a stationary process $$X_t=\rho X_{t-1}+\epsilon_t$$ with stationary solution $X_t=\sum_{i=1}^\infty \rho^{-i}\epsilon_{t+i}$.  Now indeed $\sum_{i=1}^{\infty} \rho^{-i} &lt; \infty$ so that weak stationarity can be proved by using this representation.   However, here on stackexchange I see a lot of question/answers that suggest that the process above is not stationary (see for example , ). In particular, the accepted answer of the latter question claims that the process is non-stationary by simulating a series and showing it displays explosive trending behaviour.  I think the only way to reconcile the theorem I mention above and the plots in the accepted answer of () is the following: the explosive process is indeed stationary but non-ergodic, that is, we cannot find the statistical properties of $X_t$ such as $\mathbb{E}(X_t)=\mu$ by observing a single infinitely long sample path of the explosive process, mathematically: $$\lim_{t \to \infty}\frac{1}{t}\sum_{t=1}X_t \neq\mathbb{E}X_t$$  Is this reading correct? What can interfere with glossaries to prevent printing? I have the strange experience that from the combination      \glossarystyle{altlisthypergroup}     \clearpage     Printing acronyms     \printglossary[type=acronym]   only the debug message is printed, the glossaries not.  Even, the \printglossary leads to hanging. At the same time, in the text commands like \gls{} work as expected.  Any advice, what other package can interfere with glossaries? (It is part of a bigger project, the MWE works as expected.)    I changed to command line version from TeXstudio. I receive the output  makeglossaries DSc2 makeglossaries version 2.12 (2014-01-20) added glossary type 'main' (glg,gls,glo) added glossary type 'acronym' (alg,acr,acn) makeindex  -s "DSc2.ist" -t "DSc2.alg" -o "DSc2.acr" "DSc2.acn" This is makeindex, version 2.15 [TeX Live 2013] (kpathsea + Thai support). Scanning style file ./DSc2.ist.............................done (29 attributes redefined, 0 ignored). Scanning input file DSc2.acn....done (9 entries accepted, 0 rejected). Sorting entries....done (36 comparisons). Generating output file DSc2.acr....done (15 lines written, 0 warnings). Output written in DSc2.acr. Transcript written in DSc2.alg. Warning: File 'DSc2.glo' is empty. Have you used any entries defined in glossary 'main'? Remember to use package option 'nomain' if you don't want to use the main glossary.   What I do not understand, that if there are entries accepted, and sorted, why do I receive the warning about empty .glo file? And also, why the pdflatex hangs if I try to continue with using pdflatex again? Export Windows 7 search results to a text file Is the genderless pronoun "they" appropriate and grammatical for a non-binary gender? I recently had somebody tell me that a mutual friend of ours who is  prefers that people refer to him/her using the gender-indefinite pronoun they.   In some cases, this almost seems okay:   Kris left their umbrella at our house.  On the other hand, if Kris is sitting right next to you, it feels very odd to say       They (meaning just Kris) would like more cake.   Or even odder,      Kris would like some more cake, can you please pass it to they/them?"   Are these usages grammatically correct? Are they in the process of becoming grammatically correct? Are there more correct alternatives? My question is, if you create a new domain user account for each of the SQL Server processes, what permissions should be set for each account? Or does the SQL configuration manager actually take care of this, and I just had an unforeseen issue?  I quite often have to setup Microsoft SQL Server and wondered if anyone can provide advice on configuring the accounts the services should run as. IMO this has been vaguely documented by Microsoft, while they point you in the right direction I have never been able to find any concrete examples.  To summarize what I've seen so far:  For simple deployments\development environments it is OK to use the virtual account defaults the installer uses: e.g. NT SERVICE\MSSQLSERVER  Avoid using the SYSTEM account, this is not secure.  For production and in domain environments it's recommended to use either a Managed Service Account, or create a domain user account (not an admin) for each service. Allegedly if you use a domain account at installation time the installer will set any required permissions for you.  If changing the service account on an existing install from a virtual account to a domain account the recommendation is to use the SQL Server configuration manager to set the new service accounts. Allegedly this will set any required permissions for you.  I just tried changing the service account in an existing install to a domain account and it would give me a logon failure until I granted the account log on as service permission, which contradicts the part where the SQL Server configuration manager will set any required permissions. (Although I'm not sure if a GPO may have interfered with setting this local security policy)  Microsoft does provide a list of the permissions that the SQL Server Setup grants .  But it's not clear to me if that is something I should be doing manually for the user I create to run the service as, or whether using the SQL config manager should automatically set these permissions.  SQL Server 2014, Domain Controller is on Windows Server 2008 R2. I am writing a small matrix library in C++ for matrix operations. However my compiler complains, where before it did not. This code was left on a shelf for 6 months and in between I upgraded my computer from debian etch to lenny (g++ (Debian 4.3.2-1.1) 4.3.2 ) however I have the same problem on a Ubuntu system with the same g++.  Here is the relevant part of my matrix class:  namespace Math {     class Matrix     {     public:          [...]          friend std::ostream&amp; operator&lt;&lt; (std::ostream&amp; stream, const Matrix&amp; matrix);     } }   And the "implementation":  using namespace Math;  std::ostream&amp; Matrix::operator &lt;&lt;(std::ostream&amp; stream, const Matrix&amp; matrix) {      [...]  }   This is the error given by the compiler:     matrix.cpp:459: error: 'std::ostream&amp;   Math::Matrix::operator&lt;&lt;(std::ostream&amp;,   const Math::Matrix&amp;)' must take   exactly one argument   I'm a bit confused by this error, but then again my C++ has gotten a bit rusty after doing lots of Java those 6 months. :-)