Python - in aysnc function, global variables appear to be unassigned I have looked extensively on stack exchange for a solution to this, but I can't seem to find one. I'm writing a discord bot that essentially just counts how many times someone replies &quot;lmao&quot; or &quot;lol&quot; to your message. I'm keeping track of who sent the previous message in a variable named priorMessageAuthorId defined and assigned in the global scope. Yet when I call it in a function, it returns the error local variable 'priorMessageAuthorId' referenced before assignment. I've tried all sorts of different ways of declaring this variable but I can't get it to work. It seems like I'm missing something really obvious here but nothing I do seems to work. All of the answers to similar questions here where case-specific and I don't think applied to me. Anyway here is the code (I've removed the ID for privacy reasons but in the actual code it is initialized as a valid id int). Data is a dictionary containing the count keyed with the user's ids. priorMessageAuthorId = ''  @client.event async def on_message(message):     if message.author == client.user:         return      words = ['lol', 'Lol', 'LOL', 'lmao', 'LMAO', 'Lmao']     for word in words:         if word in message.content:             data[priorMessageAuthorId] = data[priorMessageAuthorId] + 1              #processes some data              break         elif word == words[-1]:             print(&quot;newAuthor&quot;, message.author.id)             priorMessageAuthorId = message.author.id  Any help would be greatly appreciated edit: removed a typo
Using global variables in a function How can I create or use a global variable in a function?  If I create a global variable in one function, how can I use that global variable in another function? Do I need to store the global variable in a local variable of the function which needs its access?
Why high voltage transmission lines? Why is it “a defeated Napoleon, not “the defeated Napoleon” who rode off the battlefield and into exile? I noticed an infinite article; ‘a’ was used before ‘defeated Napoleon’ in the following sentence of Jeffery Archer’s novel, "Fales Impression" :  “General Sir Harry Wentworth sat at the right hand of the Iron Duke that night, and was commanding his left flank when a defeated Napoleon rode off the battlefield and into exile."  I’m curious to know why it should be “a defeated Napoleon,” not “the defeated Napoleon” or simply “defeated Napoleon.” Isn’t it only one Napoleon who was defeated the battle and exiled (to St. Helena). It looks like as though there were many (defeated) Napoleons who were exiled.  It’s always headache for me to handle articles as we Japanese (I think Chinese too) don’t have article as the basic part of speeches in our language system. I’ve studied it on English grammar text books at school, but have never reached full understanding of the usage of articles, because we don’t have that practice. Is there any special knack to master how to use articles? I'm toying with the jQuery plugin  to implement a branching wizard for a web application. The problem I'm struggling with right now is how to deal with user choices that affect the subsequent workflow and the content and re-ordering of the progress meter of the wizard.  As for now I can think of 3 alternatives.   Static solution: Lay out all possible steps in advance. Though some steps will only be activated if the user makes the appropriate choice. Otherwise, the wizard continues with the next valid step. As an example: If someone doesn't need the "flight transfer option" the wizard simply leaves out all steps concerned with that choice. Fluid solution: Lay out only the default or required steps (happy path scenario). If for instance at some point the user chooses to branch away from the visible path (I need the transfer option) the wizard gets a visual update and also its progress meter. Now, showing all the additional steps. (I'm not sure though if this is visually appealing.) A combination of 1 and 2: This is meant as an extension to 1) and 2) where all the choices are made up-front like in a short enquiry (1st step). Based upon these choices the wizard gets a visual update with the corresponding workflow. If the user wants to change the choice she made she has to re-visit the first step (which creates the potential complexity of not loosing already entered data) I'm using classicthesis to write my document. I don't use the option drafting but I can see on the bottom of the page the date (there is a part of the date that is not readable, but when I copy and paste this part I obtain [ December 1, 2011 at 20:50 ]). This is my code:  \documentclass[a4paper]{scrreprt}   % classe report di KOMA-Script  \usepackage[english]{babel}     % Per scrivere in inglese \usepackage[T1]{fontenc}        % Imposta la codifica dei font \usepackage[utf8]{inputenc}     % Lettere accentate da tastiera \usepackage{classicthesis-preamble} % Preambolo classicthesis \usepackage{classicthesis}      % Classicthesis  \begin{document}  \input{Chapters/0_Introduction} [...]  \end{document}   I would like to avoid this little issue.  I use TeXworks in Windows7 x64. Measures: Atom Definitions Let $\Omega$ be a measure space with measure $\mu$. (Here, a measure is only meant to be countable additive!)  Consider a subset $A\in\Sigma$.  Then according to the  it is an atom if: $$(1)\quad\forall E\subseteq A:\quad\mu(E)&lt;\mu(A)\implies\mu(E)=0\quad(\mu(A)&gt;0)$$ and according to the  it is an atom if: $$(2)\quad\forall E\in\Sigma:\quad\mu(E\cap A)=0\lor\mu(E^c\cap A)=0\quad(\mu(A)&gt;0)$$  Now, these definitions agree for the really trivial cases: $$\mu\equiv0$$ $$\mu\equiv\infty$$ but they differ for the less trivial case: $$\quad\mu(E\neq\varnothing):=\infty,\,\mu(\varnothing):=0$$ namely the atoms are w.r.t. (1) all nonempty subsets whereas w.r.t. (2) only the singletons.  Excluding this pathological case, are the definitions equivalent? (More precisely, assume there exists a measurable subset $0&lt;\mu(F)&lt;\infty$.)  So far I checked that: $$(2)\implies(1):\quad\mu(E)&lt;\mu(A)\implies\mu(A\setminus E)&gt;0\implies\mu(E)=0$$ but what about the other direction? How to replace a video on YouTube I need to make a small correction in a video I uploaded to YouTube. Googling shows that this is not possible. However, I remember seeing it done before. I posted a comment on a video saying that a certain part of the video was missing. I got a reply back that it was fixed, and when I went to see the video again, it was changed. How was this done? Hello,    This question is about the Command Line Developer Tools that are usually installed with xcode-select --install and updated via a software update from the Mac App Store (at least until macOS 10.13). I use the developer toolchain on a daily basis and it has always worked and updated without issues.    Today I've updated my mac from High Sierra 10.13.6 to Mojave 10.14.1, and I've lost the ability to update the Developer Tools.    After the update I've executed a terminal command that relies on the developer tools being installed. It was a command to update , although I don't think that the specifics matter, as I believe that any task that tried to access the developer tools would have triggered the same error message.    The error was:   xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools), missing xcrun at: /Library/Developer/CommandLineTools/usr/bin/xcrun       The phrasing was new (maybe), but I thought that it was caused by the usual need to re-install the Developer Tools after some macOS updates.    Later I tried to dig a bit deeper into the failure, and found out that:  $ ls -l /Library/Developer/CommandLineTools/usr/total 0drwxr-xr-x  3 root  admin  96  4 Nov 19:32 share$ which xcrun/usr/bin/xcrun$ xcode-select -p/Library/Developer/CommandLineTools    Still, as I normally do, I entered the command to install and update the Developer Tools in the terminal:  xcode-select --install    This started the usual procedure: modal window to confirm, then request to accept the license agreement, followed by a progress bar. Except that it failed very quickly with an unexpected error:     Can&rsquo;t install the software because it is not currently available from the Software Update server.     I've tried several times, to no avail. It gets always stuck.    Sometimes, however, the failure causes the System Preferences to report a pending update:      If I open that preference panel it starts searching for updates, and it always finds nothing except the first time that it happened. The first time, it found this:          It literally suggested me to install the updates for macOS 10.11 and 10.13. I have no idea why.  I closed the preference without installing, and as I said it hasn't shown them again. There is also no update available in new Mac App Store.   Is this a known issue? Is there any way to resolve the problem?     Update  Of course I can download the Dev Tools for macOS 10.14 installer from .  Before installing them manually, though, I'm wondering if there is anything that's broken with the system. Prove that the equation: $c_0+c_1x+\ldots+c_nx^n=0$ has a real solution between 0 and 1. Let $c_0,c_1,c_2,\ldots ,c_n$ be constants such that :  $$c_0+\frac{c_1}{2}+\ldots+\frac{c_{n-1}}{n}+\frac{c_n}{n+1}=0$$  I have to prove that the equation: $$c_0+c_1x+\ldots+c_nx^n=0$$  Has a real solution between 0 and 1.  Didn't know how to start...I thought that maybe I could use something about derivative...But I'm lost... Any help,much appreciated!!! Probability of two uniform random numbers being more than $\frac{1}{2}$ apart Two numbers are chosen randomly and independently from the unit interval $(0,1)$.  What is the probability that they differ by more than $\frac{1}{2}$? Hint: Think of the $2$ numbers chosen as coordinates in the Cartesian plane. Draw a square with vertices at $(0,0)$,$(1,0)$,$(1,1)$, and $(0,1)$. Allowable choices for the $2$ points lie below the line $y=x-\frac{1}{2}$ or the above $y=x+\frac{1}{2}$. Find the combined area of these regions.  I need help on this. I know what $y=x-\frac{1}{2}$ and $y=x+\frac{1}{2}$ looks like but I am not understanding the problem as a whole Can somebody help me with the execute commands in Minecraft? Recently, Minecraft had removed the /testfor command, which broke these sets of commands that I was trying to execute today.  /testfor @p[r=10] {SelectedItem:{id:"minecraft:feather",tag:{display:{Name:"Roc's Feather",Lore:[Jump higher using this feather.]}}}}`   Now normally, from Minecraft 1.13 onwards, the new /execute command would've been the replacement for the /testfor command, but as I soon found out, the command failed to detect my Roc's Feather and thus could not execute an /effect command that gave me a Jump Boost, for 1 second, at level 3.  I tried remaking my feather from scratch with this command here:  /give @p minecraft:feather{display:{Name:"{\"text\":\"Roc's Feather\",\"color\":\"light_purple\",\"bold\":true,\"italic\":true,\"underlined\":false,\"strikethrough\":false,\"obfuscated\":false}",Lore:["{\"text\":\"Jump higher using this feather.\",\"bold\":false,\"italic\":true,\"underlined\":false,\"strikethrough\":false,\"obfuscated\":false}"]}} 1   But the execute command I placed did not detect this type of uniqueness.  /execute if entity @p[distance=10,nbt={SelectedItem:{id:"minecraft:feather",Count:1b,tag:{display:{Name:"{\"text\":\"Roc's Feather\",\"color\":\"light_purple\",\"bold\":true,\"italic\":true,\"underlined\":false,\"strikethrough\":false,\"obfuscated\":false}",Lore:["{\"text\":\"Jump higher using this feather.\",\"bold\":false,\"italic\":true,\"underlined\":false,\"strikethrough\":false,\"obfuscated\":false}"]}}}}] run effect give @s minecraft:jump_boost 1 3 true   Can somebody tell me what I'm doing wrong here because I cannot even tell what's the issue. After writing the FreeNAS IMG to a 16 GB USB flash drive, I can now only use 938 MB. I used the Win32 Disk Imager tool to write the IMG to the device. Then later, when I inserted the the USB drive into my Windows 7 computer it said that it had to be formatted, because it couldn't read it. I believe this is normal. So I formatted it inside Windows using the format option when prompted. So in Windows Explorer now, 938 MB is reported as capacity of this device.    Also, when i check the properties dialog box I can see the same numbers.    And when I check with diskmgmt.msc I can see there are several volumes I don't recognize and unallocated space of 12.79 GB.    Now, I have another 2 GB USB flash drive with the same problem. It too was used for FreeNAS, and it too has a reported capacity of only 938 MB. I thought it was broken there for a while, until I saw the same problem with this 16 GB model.  I tried using diskpart on the 2 GB model, and I saw that there were several partitions there (list partitions) just like on this one. So I used the clean option to try to wipe it, but that wiped off everything so it's totally useless now. I'm not sure how to rebuild it.  Is this a standard routine, like part of the whole "user experience", that whenever you make a bootable USB falsh drive with FreeNAS, it messes up your device? I am new to FreeNAS, so i wouldn't know. But it sure looks like it. Maybe it is in fact the format operation in Windows that messes things up... I don't know. It's not very nice.  How do I restore the capacity back to 16 GB-ish (14.9 GiB)? Creating point features with exact coordinates in QGIS? Error 404 : While using flag Recently on Stack Overflow I got privilege to flag a post. So when I try to flag a post as duplicate. The diaglog box is not properly loading.         However I am easily able to use other flag option like "other","spam" or "offensive".   "other"        "spam"        "offensive"        I am using Google Chrome Version 28.0.1500.71 and Win XP Operating System. I have tried in firefox as well but it is showing me same problem. referring to Eqn. 1a) and 1b) in a sentence as eqn. (1) $\int_0^\infty \frac{\sin(x^2+ax)}{x}\,dx$ converges I want to show that the following converges for $a\ge 0$ $$\int_0^\infty \frac{\sin(x^2+ax)}{x}\,dx$$  We can show that $\lim_{x\to 0} \frac{\sin(x^2+ax)}{x} = a$, and with that fact it's straightforward to prove that $$\left|\int_0^\delta\frac{\sin(x^2+ax)}{x}\,dx \right|&lt; \infty$$ where $\delta &gt;0$ is a constant.  However I'm having trouble showing that the function decays quickly enough as $x$ goes to infinity. I know how to prove this when taking the integral of $\sin(ax)/x$, but that $x^2$ is causing me problems.  Any ideas? Thanks. FIELD_INTEGRITY_EXCEPTION: field integrity exception: unknown (invalid user or group: 005XXXXXXXXXXXX) I've a object called myobject__c. This object is private in OWD Setting.  Now when admin create a new record of this object then I want to share this record with a user(community user). For this I've written a code in trigger to create a sharing record of this object (myobject__Share).  But I am getting a problem of :-      FIELD_INTEGRITY_EXCEPTION: field integrity exception: unknown (invalid   user or group: 005XXXXXXXXXXXXX).   how can I solve this problem and second doubt is can we create share record for community user or not. Characterization of short exact sequences The following is the first part of Proposition 2.9 in "Introduction to Commutative Algebra" by Atiyah &amp; Macdonald.     Let $A$ be a commutative ring with $1$. Let $$M' \overset{u}{\longrightarrow}M\overset{v}{\longrightarrow}M''\longrightarrow  0\tag{1} $$ be sequence of $A$-modules and homomorphisms. Then the sequence (1) is exact if and only if for all $A$-modules $N$, the   sequence  $$0\longrightarrow \operatorname{Hom}(M'', N)  \overset{\overline{v}}{\longrightarrow}\operatorname{Hom}(M,  N)\overset{\overline{u}}{\longrightarrow}\operatorname{Hom}(M', N)  \tag{2} $$ is exact.   Here, $\overline{v}$ is the map defined by $\overline{v}(f)=f\circ v$ for every $f\in\operatorname{Hom}(M'', N)$ and $\overline{u}$ is defined likewise.   The proof one of direction, namely $(2)\Rightarrow (1)$ is given in the book, which I am having some trouble understanding. So assuming (2) is exact sequence, the authors remark that "since $\overline{v}$ is injective for all $N$, it follows that $v$ is surjective". Could someone explain why this follows?  Given that $\overline{v}$ is injective, we know that whenever $f(v(x))=g(v(x))$ for all $x\in M$, we have $f=g$. I am not sure how we conclude from this surjectivity of $v$.  Thanks! Nature of gravity: gravitons, curvature of space-time or both? General relativity tells us that what we perceive as gravity is curvature of space-time.   On the other hand (as I understand it) gravity can be understood as a force between objects which are exchanging (hypothetical) virtual particles called gravitons, similar to the way electromagnetic forces are due to objects exchanging virtual photons?  At least at first glance, the two concepts seem mutually exclusive. Is there a description of gravity which includes both, or is this contradiction one of the problems in combining GR with quantum mechanics? How many named characters died in Avengers: Infinity War? How many named characters have died       and/or disintegrated      by the end of Avengers: Infinity War. It is difficult to speculate who died on         Xandar and the Asgardian ship.       So restrict it to on-screen deaths only. Check ping statistics without stopping Is there a way to tell ping to show its usual termination statistics without stopping the execution?  For instance, I'd like to quickly view:  --- 8.8.8.8 ping statistics --- 2410 packets transmitted, 2274 received, +27 errors, 5% packet loss, time 2412839ms rtt min/avg/max/mdev = 26.103/48.917/639.493/52.093 ms, pipe 3   without having to stop the program, thus losing the accumulated data.