Login Register


[Python] File Sorter filter_list
Author
Message
RE: [Python] File Sorter #11
Good Job Bro! keep up the good work Confusedmile:







Reply

RE: [Python] File Sorter #12
(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.

Reply

RE: [Python] File Sorter #13
@Anima Templi Probably right on the main() function point, Well I found sys.argv to be more easy to use
My Blog: http://www.procurity.wordpress.com
Donations: 1HLjiSbnWMpeQU46eUVCrYdbkrtduX7snG

Reply

RE: [Python] File Sorter #14
Code updated! Thanks to the suggestion of @L0aD1nG and @Anima Templi
My Blog: http://www.procurity.wordpress.com
Donations: 1HLjiSbnWMpeQU46eUVCrYdbkrtduX7snG

Reply

RE: [Python] File Sorter #15
looks really good man. how long did that take you type up?

Reply

RE: [Python] File Sorter #16
(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
My Blog: http://www.procurity.wordpress.com
Donations: 1HLjiSbnWMpeQU46eUVCrYdbkrtduX7snG

Reply







Users browsing this thread: