RE: assistance with python coding
Title: Message Dear John, This is a switch. In other words if you have two variables, a and b, switch the values. The author of the exercise is trying to point out that without the sequence operation, you must do it the same way as in nearly all other languages. That is: tmp = a a = b b = tmp Python gives you the ability to switch two variables with just a single statement. To perform the above with a sequence assignment would be: a, b = b, a Your example only slightly complicated this by using an array. The answer you are looking for is: tmp = self.cards[i] self.cards[i] = self.cards[j] self.cards[j] = tmp Let me know if you need any more help! Yours truly, Richard Morello -Original Message-From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of John ShappellSent: Monday, September 11, 2006 12:23 PMTo: python-list@python.orgSubject: assistance with python coding I don’t understand what this question is asking; can you clarify for me and maybe point me in the right direction? As an exercise, rewrite this line of code without using a sequence assignment. self.cards[i], self.cards[j] = self.cards[j], self.cards[i] V/R CW2 John Shappell 931-980-4707 FAX 775-618-2455 [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list
RE: Curious issue with simple code
Dear Tony, You're not in that directory (start_dir) when the isfile() function is called. See function os.path.curdir() and os.chdir(). Also, you may be confusing the behavior of os.path.walk(), in which the function called will happen once you have been chdired to the directory it is examining. Hope this was helpful. Yours truly, Rich. -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of codefire Sent: Tuesday, September 19, 2006 1:08 PM To: python-list@python.org Subject: Curious issue with simple code Hi, I have some simple code - which works...kind of..here's the code: [code] import os def print_tree(start_dir): for f in os.listdir(start_dir): fp = os.path.join(start_dir, f) print fp if os.path.isfile(fp): # will return false if use f here! if os.path.splitext(fp)[1] == '.html': print 'html file found!' if os.path.isdir(fp): print_tree(fp) print os.path print_tree(r'c:\intent\docn') [/code] As above it all works as expected. However, on the marked line, if I use f instead of fp then that condition returns false! Surely, isfile(f) should return true, even if I just give a filename, rather than the full path? If anyway can explain this I'd be grateful, Tony -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list