BetaPost Count: 12 |
Posted On: 07th Aug 11 @ 06:55 am
So I've recently just been working on an application that does file management. As of now it only does mass changes of file extensions or mass changes of file names, but what I'd like to know is my code readable? Is it well written? Am I writing good code, or does it look like I've been mashing my face to my keyboard?
http://www.cybershade.org/modules/pastebin/view/e042bd82.py |
|
Post Has Been Edited 2 Times. Last Edited By Beta.
|
|
LK-Post Count: 39 |
Posted On: 07th Aug 11 @ 09:14 am
It looks like you are mashing your face to your keyboard.
It isn't PEP8 compliant. It'd also be neater if you used OOP. ![]()
|
BetaPost Count: 12 |
Posted On: 11th Aug 11 @ 07:09 am
Thanks LK-! I think that's helped, and I'm now working on something a bit different. It's a bit of code designed to get a list of the files in the current directory, search the contents of each file for a keyphrase, and every time it finds the keyphrase in a file it adds it to an array. In return the array is printed out. Here's what I have:
Python Code:
from os import * def listget(array): iteration = 0 #Iter for the listdir. while iteration < len(array):#Finish after listing is done. try: #Prints array[iter] and array[iter + 1] seperated by a tab. print(str(array[iteration]) + '\t' + str(array[iteration + 1])) #Since array[iter + 1] was printed increase iter by 2. iteration += 2 #In case the array has an odd amount of items, and iter goes over. except IndexError: break print() def filesearch(keyword): results = []#Array in which the files keyword is located is kept. for item in listdir(): try: file = open(item,'r')#Open a file. content = file.readlines()#Get the contents of the file. file.close()#Close the file. except: pass count = 0 for line in content[count]: if keyword in line:#Hunting for the keyword in the file. results.append(item) count += 1 listget(results) |
|
Post Has Been Edited 3 Times. Last Edited By Beta.
|
|