So i was making an alarm clock with python using tkinter I set up my layout for i wanted it to look, then i decided to implement the plus button in order to increase the number of minutes or hours by which i wanted to set the alarm  For some reason, it says that the 'demo_hour' variable has been refered to before the assignment Is there something wrong with the logic in my code? The needed code:     demo_hour = 0     demo_minute = 0     demo_am_pm = &quot;AM&quot;      hour = time.strftime(&quot;%I&quot;)     minute = time.strftime(&quot;%M&quot;)     am_pm = time.strftime(&quot;%p&quot;)      mytime.config(text=f&quot;|{demo_hour}| : |{demo_minute}| |{demo_am_pm}|&quot;)      # Up/Down commands     def u_hr():         demo_hour += 1         mytime.config(text=f&quot;|{demo_hour}| : |{demo_minute}| |{demo_am_pm}|&quot;)     def u_m():         demo_minute += 1         mytime.config(text=f&quot;|{demo_hour}| : |{demo_minute}| |{demo_am_pm}|&quot;)     def u_ap():         demo_am_pm = &quot;PM&quot;         up_hr.config(state=DISABLED)         mytime.config(text=f&quot;|{demo_hour}| : |{demo_minute}| |{demo_am_pm}|&quot;)      def d_hr():         demo_hour -= 1         mytime.config(text=f&quot;|{demo_hour}| : |{demo_minute}| |{demo_am_pm}|&quot;)     def d_m():         demo_minute -= 1         mytime.config(text=f&quot;|{demo_hour}| : |{demo_minute}| |{demo_am_pm}|&quot;)     def d_ap():         demo_am_pm = &quot;AM&quot;         dw_hr.config(state=DISABLED)         mytime.config(text=f&quot;|{demo_hour}| : |{demo_minute}| |{demo_am_pm}|&quot;)  The needed error: Traceback (most recent call last):   File &quot;/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/tkinter/__init__.py&quot;, line 1883, in __call__     return self.func(*args)   File &quot;/Users/veresh/Desktop/Python Projects/alarm.py&quot;, line 112, in u_hr     demo_hour += 1 UnboundLocalError: local variable 'demo_hour' referenced before assignment
1022
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?
86440
I can't seem to figure out the difference between + and ++ relative coordinates in TikZ.   I understand ++. ++ specifies delta coordinates that are added to the last current point, the current point is then set to the new absolute current point (correct?):  \draw (0,0) -- ++(1,0) -- ++(0,1) means:  set Current Point to (0,0) add (1,0) to Current Point = (1,0) set Current Point to (1,0) add Current Point (1,0) to (0,1) = (1,1) set Current Point to (1,1)   I can't seem to figure out that + does, when I try it out it looks like the coordinates in the +(x,y) are absolute coordinates rather than delta coordinates, but the manual says otherwise
116717
If i switch between solid and wireframe mode, i can see in the info window that these commands are invoked :  bpy.data.screens["Layout"].shading.type = 'WIREFRAME' bpy.data.screens["Layout"].shading.type = 'SOLID'   Now i want to execute this command using python console. So i cut and paste the codes into python console but i got this error :   &gt;&gt;&gt; bpy.data.screens["Layout"].shading.type = 'WIREFRAME' Traceback (most recent call last):   File "&lt;blender_console&gt;", line 1, in &lt;module&gt; AttributeError: 'Screen' object has no attribute 'shading'  &gt;&gt;&gt; bpy.data.screens["Layout"].shading.type = 'SOLID' Traceback (most recent call last):   File "&lt;blender_console&gt;", line 1, in &lt;module&gt; AttributeError: 'Screen' object has no attribute 'shading'   Does anyone know why ? and what the correct script should i use in python console ?  Thanks
2178
Why doesn't the following work (Python 2.5.2)?  &gt;&gt;&gt; import datetime &gt;&gt;&gt; class D(datetime.date):         def __init__(self, year):             datetime.date.__init__(self, year, 1, 1) &gt;&gt;&gt; D(2008) Traceback (most recent call last):   File "&lt;stdin&gt;", line 1, in &lt;module&gt; TypeError: function takes exactly 3 arguments (1 given)   I wanted to create a class that was just like datetime.date, but with a different __init__ function.  Apparently my function never gets called.  Instead the original datetime.date.__init__ is called and fails because that expects 3 arguments and I am passing in one.  What's going on here?  And is this a clue?  &gt;&gt;&gt; datetime.date.__init__ &lt;slot wrapper '__init__' of 'object' objects&gt;   Thanks!
102637
I am reading the book 'Practical Common Lisp' by Peter Seibel. In Chapter 6, &quot;Variables&quot; sections &quot;Lexical Variables and Closures&quot; and &quot;Dynamic, a.k.a. Special, Variables&quot;.  My problem is that the examples in both sections show how (let ...) can shadow global variables and doesn't really tell the difference between the Dynamic and Lexical vars. I understand how closures work but I don't really get whats so special about let in this example: (defvar *x* 10)  (defun foo ()   (format t &quot;Before assignment~18tX: ~d~%&quot; *x*)   (setf *x* (+ 1 *x*))   (format t &quot;After assignment~18tX: ~d~%&quot; *x*))   (defun bar ()   (foo)   (let ((*x* 20)) (foo))   (foo))   CL-USER&gt; (foo) Before assignment X: 10 After assignment  X: 11 NIL   CL-USER&gt; (bar) Before assignment X: 11 After assignment  X: 12 Before assignment X: 20 After assignment  X: 21 Before assignment X: 12 After assignment  X: 13 NIL  I feel like there is nothing special is going on here. The outer foo in bar increments the global x, and foo surrounded by let in bar increments the shadowed x. What's the big deal? I don't see how is this supposed to explain the difference between lexical and dynamic variables. Yet the book continues like this:  So how does this work? How does LET know that when it binds x it's supposed to create a dynamic binding rather than a normal lexical binding? It knows because the name has been declared special.12 The name of every variable defined with DEFVAR and DEFPARAMETER is automatically declared globally special.  What would happen if let would bind x using &quot;normal lexical binding&quot;? All in all, what are the differences between dynamic and lexical binding and how is this example special regarding dynamic binding?
88152
I have been using this command successfully, which changes a variable in a config file and then executes a Python script within a loop: for((i=114;i&lt;=255;i+=1)); do echo $i &gt; numbers.txt; python DoMyScript.py; done  As each DoMyScript.py instance takes about 30 seconds to run before terminating, I'd like to relegate them to the background while the next one can be spawned. I have tried what I am familiar with, by adding in an ampersand as below: for((i=114;i&lt;=255;i+=1)); do echo $i &gt; numbers.txt; python DoMyScript.py &amp;; done  However, this results in the below error: -bash: syntax error near unexpected token `;'
1704
This has always confused me. It seems like this would be nicer:  my_list = ["Hello", "world"] print(my_list.join("-")) # Produce: "Hello-world"   Than this:  my_list = ["Hello", "world"] print("-".join(my_list)) # Produce: "Hello-world"   Is there a specific reason it is like this?
83136
The best I can come up with for now is this monstrosity:  &gt;&gt;&gt; datetime.utcnow() \ ...   .replace(tzinfo=pytz.UTC) \ ...   .astimezone(pytz.timezone("Australia/Melbourne")) \ ...   .replace(hour=0,minute=0,second=0,microsecond=0) \ ...   .astimezone(pytz.UTC) \ ...   .replace(tzinfo=None) datetime.datetime(2008, 12, 16, 13, 0)   I.e., in English, get the current time (in UTC), convert it to some other timezone, set the time to midnight, then convert back to UTC.  I'm not just using now() or localtime() as that would use the server's timezone, not the user's timezone.  I can't help feeling I'm missing something, any ideas?
73955
I am having a little trouble figuring out how to make this work properly, I am trying to put a small countdown clock in the left column and one in the right column, which will show a countdown to two separate dates. I was able to create a single countdown clock using the below code and was hoping to be able to be able to tweak the code enough to allow it to run on a second CEWP with a different date. Is it possible to run two Javascript files on the page without them interferring with eachother? Thank you anyone that can lend a quick hand.      &lt;style type="text/css"&gt; .container{     text-align: center;     background: #f63536;   font-family: sans-serif;   font-weight: 100;   height:115px;   width:215px; }  h3{   color: #FFFFFF;   font-weight: 100;   font-size: 16px;   margin: 0px 0px 5px;   padding-top:3px; }  #clockdiv{     font-family: sans-serif;     color: #fff;     display: inline-block;     font-weight: 100;     text-align: center;     font-size: 20px; }  #clockdiv &gt; div{     padding: 5px;     border-radius: 3px;     background: #ff5b5b;     display: inline-block; }  #clockdiv div &gt; span{     padding: 5px;     border-radius: 3px;     background: #ab0202;     display: inline-block; }  .smalltext{     padding-top: 5px;     font-size: 13px; }  &lt;/style&gt;  &lt;div class="container"&gt;  &lt;h3&gt;Countdown Clock Left&lt;/h3&gt; &lt;div id="clockdiv"&gt;   &lt;div&gt;     &lt;span class="days"&gt;&lt;/span&gt;     &lt;div class="smalltext"&gt;Days&lt;/div&gt;   &lt;/div&gt;   &lt;div&gt;     &lt;span class="hours"&gt;&lt;/span&gt;     &lt;div class="smalltext"&gt;Hrs.&lt;/div&gt;   &lt;/div&gt;   &lt;div&gt;     &lt;span class="minutes"&gt;&lt;/span&gt;     &lt;div class="smalltext"&gt;Min.&lt;/div&gt;   &lt;/div&gt;   &lt;div&gt;     &lt;span class="seconds"&gt;&lt;/span&gt;     &lt;div class="smalltext"&gt;Sec.&lt;/div&gt;   &lt;/div&gt; &lt;/div&gt;&lt;/div&gt;  &lt;script&gt; function getTimeRemaining(endtime){   var t = Date.parse(endtime) - Date.parse(new Date());   var seconds = Math.floor( (t/1000) % 60 );   var minutes = Math.floor( (t/1000/60) % 60 );   var hours = Math.floor( (t/(1000*60*60)) % 24 );   var days = Math.floor( t/(1000*60*60*24) );   return {     'total': t,     'days': days,     'hours': hours,     'minutes': minutes,     'seconds': seconds   }; }  function initializeClock(id, endtime){   var clock = document.getElementById(id);   var daysSpan = clock.querySelector('.days');   var hoursSpan = clock.querySelector('.hours');   var minutesSpan = clock.querySelector('.minutes');   var secondsSpan = clock.querySelector('.seconds');    function updateClock(){     var t = getTimeRemaining(endtime);      daysSpan.innerHTML = t.days;     hoursSpan.innerHTML = ('0' + t.hours).slice(-2);     minutesSpan.innerHTML = ('0' + t.minutes).slice(-2);     secondsSpan.innerHTML = ('0' + t.seconds).slice(-2);      if(t.total&lt;=0){       clearInterval(timeinterval);     }   }    updateClock();   var timeinterval = setInterval(updateClock,1000); }  var deadline = 'October 31 2015 00:00:50'; initializeClock('clockdiv', deadline); &lt;/script&gt;
80656
I want do something like this:  Button btn1 = new Button(); btn1.Click += new EventHandler(btn1_Click); Button btn2 = new Button(); // Take whatever event got assigned to btn1 and assign it to btn2. btn2.Click += btn1.Click; // The compiler says no...   Where btn1_Click is already defined in the class:  void btn1_Click(object sender, EventArgs e) {     // }   This won't compile, of course ("The event 'System.Windows.Forms.Control.Click' can only appear on the left hand side of += or -="). Is there a way to take the event handler from one control and assign it to another at runtime? If that's not possible, is duplicating the event handler and assigning it to another control at runtime doable?  A couple of points: I have googled the heck out of this one for awhile and found no way of doing it yet. Most of the attempted approaches involve reflection, so if you read my question and think the answer is incredibly obvious, please try to compile the code in Visual Studio first. Or if the answer really is incredibly obvious, please feel free to slap me with it. Thanks, I'm really looking forward to seeing if this is possible.  I know I could just do this:  btn2.Click += new EventHandler(btn1_Click);   That's not what I'm looking for here.  This is also not what I'm looking for:  EventHandler handy = new EventHandler(btn1_Click); Button btn1 = new Button(); btn1.Click += handy; Button btn2 = new Button(); btn2.Click += handy;
58025
I simply want one command block to test for the time of day or night (e.g. time = 18000) and output a message in the chat to everyone if that time returns true.  I was trying a simple set-up with two command blocks and a comparator in the middle, but I'm a beginner and am obviously missing the correct syntax (especially to test for a particular time of day, and if true, then trigger the say "message" block).  ETA: Kudos to @Ben for the Daylight Sensor/Redstone idea, but I'd really prefer a Command Block solution for the above, since my plan is to output several messages during the day and night cycle at very specific times in the world. Thanks.
18594
What is the module/method used to get the current time?
98262
Why won't this work?  I'm trying to make an instance of a class delete itself.  &gt;&gt;&gt; class A():     def kill(self):         del self   &gt;&gt;&gt; a = A() &gt;&gt;&gt; a.kill() &gt;&gt;&gt; a &lt;__main__.A instance at 0x01F23170&gt;
96218
I came across this code and wanted others to provide their point of view... is it good or bad ? ;)  Class ReportClass {  public string ReportName {get; set;} }   Then it was used as follows in code:  displayReport(ReportClass.ReportName = cmbReportName.SelectedValue.ToString())   That is about the simplest form example I can give you. Quetion is... why can't I find examples ? What would this be called? Is this just asking for trouble?  EDIT: I'm referring to the inplace assignment. Which I wasn't aware of until today
107670
Why is it bad to name a variable id in Python?
12929
Could someone please tell me what I'm doing wrong with this code? It is just printing 'count' anyway.  I just want a very simple prime generator (nothing fancy).   import math  def main():     count = 3     one = 1     while one == 1:         for x in range(2, int(math.sqrt(count) + 1)):             if count % x == 0:                  continue             if count % x != 0:                 print count          count += 1
122421
There are a lot of articles around the web concerning python performance, the first thing you read: concatenating strings should not be done using '+': avoid s1+s2+s3, instead use str.join  I tried the following: concatenating two strings as part of a directory path: three approaches:   '+' which i should not do str.join os.path.join   Here is my code:  import os,time  s1='/part/one/of/dir' s2='part/two/of/dir' N=10000  t=time.clock() for i in xrange(N):     s=s1+os.sep+s2 print time.clock()-t  t=time.clock() for i in xrange(N):     s=os.sep.join((s1,s2)) print time.clock()-t  t=time.clock() for i in xrange(N):     s=os.path.join(s1,s2) print time.clock()-t   Here the results (python 2.5 WinXP)  0.0182201927899 0.0262544541275 0.120238186697   Shouldn't it be exactly the other way round ?