Sinisterly
[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 Confusedmile:


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.

On the other hand now i didnt recommend him naming functions like that i just wanted to show him the way that optparse works so i just putted a random and little funny name to the function.Also using the main funtion is highly recommended by pro pythonistaz cause its a way to nicely organize all the code at last and run it like that after check if not debuging flag is on.

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