![]() |
|
[Python] File Sorter - Printable Version +- Sinisterly (https://sinister.ly) +-- Forum: Coding (https://sinister.ly/Forum-Coding) +--- Forum: Python (https://sinister.ly/Forum-Python) +--- Thread: [Python] File Sorter (/Thread-Python-File-Sorter) Pages:
1
2
|
RE: [Python] File Sorter - BlueCat - 06-19-2014 Good Job Bro! keep up the good work mile:
RE: [Python] File Sorter - Anima Templi - 06-19-2014 (06-19-2014, 02:59 PM)L0aD1nG Wrote: First of all i havent tried that argparse module but i think that same can happen with optparse..but i am not sure as i havent check the argparse module yet. I'm part of the Python Software Foundation, and no, it's not recommended. You're actually having two main functions in your code. Code: def main():
parser = optparse.OptionParser("Usage : " + sys.argv[0] + " -p <path you would like sort>" )
parser.add_option('-p', dest = 'sort_path', type = 'string', help = 'This is the path location you want to sort')
(options, args) = parser.parse_args()
sort_path = options.sort_path
if not sort_path:
print parser.usage
exit(1)
else:
my_sweet_sort(sort_path)
exit(0)and Code: if __name__ == '__main__':
main()The last is in fact, the correct way of creating "main" functions in Python. In your code, you have two... Also, no matter why you write your code, I do think you should strive to use proper style. Otherwise you'll turn into a lazy programmer and unnoticed write bad code. I don't know who your professional pythonitas are, but they are indeed very wrong. RE: [Python] File Sorter - Ex094 - 06-19-2014 @Anima Templi Probably right on the main() function point, Well I found sys.argv to be more easy to use RE: [Python] File Sorter - Ex094 - 06-19-2014 Code updated! Thanks to the suggestion of @L0aD1nG and @Anima Templi RE: [Python] File Sorter - Cosh - 06-21-2014 looks really good man. how long did that take you type up? RE: [Python] File Sorter - Ex094 - 06-21-2014 (06-21-2014, 02:43 AM)Cosh Wrote: looks really good man. how long did that take you type up? 1 Hour max, Had to do the update too because members gave some useful suggestions |