Message158026
| Author |
billje |
| Recipients |
billje, eric.smith |
| Date |
2012年04月11日.12:02:28 |
| SpamBayes Score |
-1.0 |
| Marked as misclassified |
Yes |
| Message-id |
<1334145746.35931.YahooMailNeo@web161904.mail.bf1.yahoo.com> |
| In-reply-to |
<1334094348.56.0.434494052694.issue14542@psf.upfronthosting.co.za> |
| Content |
Eric.....
Thanks for answering, but I don't understand the difference between "reversing a list" and "reversing it's current values". If I have a list containing elements: A, B, C, D and reverse the list's current values, I get: D, C, B, A, which is the same as reversing the list. Please explain in more detail. Perhaps you can recommend good reference material. Since sort() sorts a list ascending (and works correctly), shouldn't reverse() sort the list descending? Am I using the wrong function? I have attached my program:
Bill.....
#EX38.PY Get listing of all files in a directory
#http://stackoverflow.com/questions/237079/how-to-get-file-creation-modification-date-times-in-python
# Answer 37
import os, datetime
topDir = "C:/BrcmCDs"
dateFirst = True # put dates before file names
# DateFirst = False # put file names before dates
def modDate(fileN): # returns a 10-place date string
t = os.path.getmtime(directory+"/"+fileN)
return str(datetime.datetime.fromtimestamp(t))[0:10]
for directory, dirnames, filenames in os.walk(topDir):
outList = []
print "Directory: ", directory
print
for fileA in filenames:
if (fileA[0:10] == "B57IBMCD_T" and
fileA[-4:] == ".zip"):
dateString = modDate(fileA)
if dateFirst:
fileString = dateString + " " + fileA
else:
fileString = fileA + " " + dateString
outList.append(fileString)
outList.sort() # sort the file list, ascending
# outList.reverse() # reverse the file list, desending
print outList #show all files
# now save list to a file:
# https://bbs.archlinux.org/viewtopic.php?id=75839
f = open("fileList.TXT", "w")
f.write("\n".join(map(lambda x: str(x), outList)))
f.close()
Regards from:
William Jefferson Photography
514 Daniels St., #211
Raleigh, NC 27605
Cell Phone: (919) 931-6681
EMail: shaggers3@yahoo.com
Brides & Weddings: http://www.WilliamJeffersonPhotography.com
Special Events: http://www.DancingLight.org
________________________________
From: Eric V. Smith <report@bugs.python.org>
To: shaggers3@yahoo.com
Sent: Tuesday, April 10, 2012 5:45 PM
Subject: [issue14542] reverse() doesn't reverse sort correctly
Eric V. Smith <eric@trueblade.com> added the comment:
list.reverse() does not reverse a list, it reverses its current values.
Help on built-in function reverse:
reverse(...)
L.reverse() -- reverse *IN PLACE*
>>>
----------
nosy: +eric.smith
resolution: -> invalid
stage: -> committed/rejected
status: open -> closed
_______________________________________
Python tracker <report@bugs.python.org>
<http://bugs.python.org/issue14542>
_______________________________________ |
|