Title: Signature.html
In some code I'm writing, I ran into a problem with the variable updown. I want it to be global. I cut down the code to near the essentials. I set a variable abc, and it seems to be happy with an almost identical use of updown. Where's this going wrong? Although there's an implication of a yyyy/mm/dd date, I omitted any check, so just enter a number.
import os, os.path, sys
# The following import is necessary for Python to use the datetime
# strftime method. See comments with use of that method below.
from datetime import datetime, timedelta
import re
import time

def morris():
    print abc, "in morris", updown
   
def sync_high2low_files():
    # put last date first to avoid collisons when actually rewrite
    print "hiho"
    morris(); print "OK"
    return

abc = 200
updown = +1 # natural order

# keyboard operation/command input loop
keyop = 999

while keyop <> 0:
    print
    keyin = raw_input("Enter operation number (h for help): ")

    keyop = int(keyin)

    # Perform commands
    if (keyop == 1): # shift starting dates of files to new date
        print
        start_date = raw_input( "Enter new start date (yyyy/mm/dd): ")
       
        # Date OK. Assemble date for file name
        print "updown",updown
        print "abc", abc
        morris()
        sync_low2high_files()

print "bottomed out"
Results:
Enter operation number (h for help): 1

Enter new start date (yyyy/mm/dd): 111
updown 1
abc 200
200 in morris 1
Traceback (most recent call last):
  File "C:\Sandia_Meteors\Improved_Sentinel\Sentinel_Playground\Utility_Dev\debug.py", line 39, in ?
    sync_low2high_files()
  File "C:\Sandia_Meteors\Improved_Sentinel\Sentinel_Playground\Utility_Dev\SU_DateTimeAdjust.py", line 35, in sync_low2high_files
    print updown
UnboundLocalError: local variable 'updown' referenced before assignment

--
           Wayne Watson (Watson Adventures, Prop., Nevada City, CA)

             (121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time)
              Obz Site:  39° 15' 7" N, 121° 2' 32" W, 2700 feet
            
            "Though no one can go back and make a brand new start, 
	     ANYONE can start from now and make a brand new end." 
		                    -- Anonymous
            
                    Web Page: <www.speckledwithstars.net/>
_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

Reply via email to