Win a copy of Java Challengers this week in the Java in General forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • paul wheaton
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Liutauras Vilda
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Piet Souris
Bartenders:
  • salvin francis
  • Mikalai Zaikin
  • Himai Minh

First Python script - any glaring issues?

 
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
We had to check for some duplicate files based off of hash on a large file share and decided to try my hand at Python. This appears to be working correctly but was wondering if there were any glaring mistakes the more experienced would change. Please let me know.


 
Bartender
Posts: 689
17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I've had a quick look through, and the things that stand out are:

1) you have an except block that does nothing but raise the exception it just caught. This is redundant. Was there meant to be some other logic in it? If not it should be removed.

2) you are filtering a list by looping through it and selectively deleting entries. This is not the pythonic way to do this. Instead you should use a list comprehension.

 
Scott Halepaska
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Mike. J. Thompson wrote:I've had a quick look through, and the things that stand out are:

1) you have an except block that does nothing but raise the exception it just caught. This is redundant. Was there meant to be some other logic in it? If not it should be removed.

2) you are filtering a list by looping through it and selectively deleting entries. This is not the pythonic way to do this. Instead you should use a list comprehension.




Thank you for taking a look. I will modify accordingly.
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic