2009-12-27 5 views
0

Je convertis un seul module en utilisant 2to3.2to3 ne fonctionne pas

test_lib2to3.py est dans /Library/Frameworks/Python.framework/Versions/3.1/lib/python3.1/test/test_lib2to3.py

fichier à convertir est en /Users/Nimbuz/Documents/python31/Excercise 1/time3.py

session Terminal:

localhost:test Nimbuz$ 2to3 /Users/Nimbuz/Documents/python31/Excercise\ 1/time3.py 
RefactoringTool: No files need to be modified. 

code:

# handling date/time data 
# Python23 tested vegaseat 3/6/2005 

import time 

print "List the functions within module time:" 
for funk in dir(time): 
    print funk 

print time.time(), "seconds since 1/1/1970 00:00:00" 
print time.time()/(60*60*24), "days since 1/1/1970" 

# time.clock() gives wallclock seconds, accuracy better than 1 ms 
# time.clock() is for windows, time.time() is more portable 
print "Using time.clock() = ", time.clock(), "seconds since first call to clock()" 
print "\nTiming a 1 million loop 'for loop' ..." 
start = time.clock() 
for x in range(1000000): 
    y = x # do something 
end = time.clock() 
print "Time elapsed = ", end - start, "seconds" 

# create a tuple of local time data 
timeHere = time.localtime() 
print "\nA tuple of local date/time data using time.localtime():" 
print "(year,month,day,hour,min,sec,weekday(Monday=0),yearday,dls-flag)" 
print timeHere 

# extract a more readable date/time from the tuple 
# eg. Sat Mar 05 22:51:55 2005 
print "\nUsing time.asctime(time.localtime()):", time.asctime(time.localtime()) 
# the same results 
print "\nUsing time.ctime(time.time()):", time.ctime(time.time()) 
print "\nOr using time.ctime():", time.ctime() 

print "\nUsing strftime():" 
print "Day and Date:", time.strftime("%a %m/%d/%y", time.localtime()) 
print "Day, Date :", time.strftime("%A, %B %d, %Y", time.localtime()) 
print "Time (12hr) :", time.strftime("%I:%M:%S %p", time.localtime()) 
print "Time (24hr) :", time.strftime("%H:%M:%S", time.localtime()) 
print "DayMonthYear:",time.strftime("%d%b%Y", time.localtime()) 

print 

print "Start a line with this date-time stamp and it will sort:",\ 
    time.strftime("%Y/%m/%d %H:%M:%S", time.localtime()) 

print 

def getDayOfWeek(dateString): 
    # day of week (Monday = 0) of a given month/day/year 
    t1 = time.strptime(dateString,"%m/%d/%Y") 
    # year in time_struct t1 can not go below 1970 (start of epoch)! 
    t2 = time.mktime(t1) 
    return(time.localtime(t2)[6]) 

Weekday = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 
    'Friday', 'Saturday', 'Sunday'] 

# sorry about the limitations, stay above 01/01/1970 
# more exactly 01/01/1970 at 0 UT (midnight Greenwich, England) 
print "11/12/1970 was a", Weekday[getDayOfWeek("11/12/1970")] 

print 

print "Calculate difference between two times (12 hour format) of a day:" 
time1 = raw_input("Enter first time (format 11:25:00AM or 03:15:30PM): ") 
# pick some plausible date 
timeString1 = "03/06/05 " + time1 
# create a time tuple from this time string format eg. 03/06/05 11:22:00AM 
timeTuple1 = time.strptime(timeString1, "%m/%d/%y %I:%M:%S%p") 

#print timeTuple1 # test eg. (2005, 3, 6, 11, 22, 0, 5, 91, -1) 

time2 = raw_input("Enter second time (format 11:25:00AM or 03:15:30PM): ") 
# use same date to stay in same day 
timeString2 = "03/06/05 " + time2 
timeTuple2 = time.strptime(timeString2, "%m/%d/%y %I:%M:%S%p") 

# mktime() gives seconds since epoch 1/1/1970 00:00:00 
time_difference = time.mktime(timeTuple2) - time.mktime(timeTuple1) 
#print type(time_difference) # test <type 'float'> 
print "Time difference = %d seconds" % int(time_difference) 
print "Time difference = %0.1f minutes" % (time_difference/60.0) 
print "Time difference = %0.2f hours" % (time_difference/(60.0*60)) 

print 

print "Wait one and a half seconds!" 
time.sleep(1.5) 
print "The end!" 
+1

Il est impossible de juger si 2to3 aura un effet sans voir le code en question. –

+0

Bien sûr, Code inclus. – 3zzy

Répondre

0

Peut-être qu'il ya quelque chose de mal avec le chemin . Essayez

2to3 "/Users/Nimbuz/Documents/python31/Excercise 1/time3.py" 

Au lieu de

2to3 /Users/Nimbuz/Documents/python31/Excercise\ 1/time3.py 

ou tout simplement cd dans ce dossier et

2to3 time3.py 

Prêt diff: http://pastebay.com/78746

+0

Les deux arguments des deux premières commandes sont identiques, au moins sous bash. –

+0

Oui, mais c'est peut-être un bug sur OS X. – myfreeweb