Python Forum
Thread Rating:
  • 1 Vote(s) - 2 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Code Review?
#1
I'm back.  I have my first  _working_ python script! Woot!  It takes a Cisco ASA config, and converts certain aspects (network objects, services objects, access-list)(the ones I need)  to a Fortinet stanza. (Vendor A to Vendor B).

So it works.  But in the interest of being a n00b, I'd like feedback & constructive criticism.  (You can't hurt my feelings, the ex-wife got those along with the house).

It's ~650 lines.  Post it here in the forum?  provide a google drive link?  What's proper forum etiquette? 

I was looking at other peoples code and snippets, and just a bit of self critique:::

1) I don't have a _main_... but it works, so do I _need_ one, or is it simply best_practice to have one?  
-- yea, but it works, so obviously not REQUIRED

2) I couldn't get   (var_1, var_2 +=1 ) so I increment each on it's own line
-- wasn't sure what to google exactly for what I was trying to do

3) I create an object of an existing object simply to make it more readable 
-- having too long a name or non-intuitive name made it confusing to debug
--here's what I did ::: acl_line = original_lines[counter].split()  & used acl_line rather than original_lines
 
4) Variables -- I saw a code snippet saying certain things should be set to Global.
-- really not sure why or how some objects are known in a function, while only some are passed
-- RTFM time?

5) I have more If/elif/elif/else statements than Canada has Tim Horton's. 
-- it's okay because it's a parser and you have to do all those checks... or hey idiot, there's a better way called XYZ
-- I couldn't find a "CASE" statement in python, is it called something else?

6) I wrote a line de-duplicator - is there a better way 
-- actually thought i handled it pretty well....wait, what are you doing with that pin ??? <POP!!>

So, post code or no?

Thanks, 
PappaBear

Code now at::: https://github.com/PappaBearTroy/FWConverter
Reply


Messages In This Thread
Code Review? - by PappaBear - Apr-18-2017, 06:06 AM
RE: Code Review? - by micseydel - Apr-18-2017, 06:24 AM
RE: Code Review? - by PappaBear - Apr-18-2017, 02:03 PM
RE: Code Review? - by micseydel - Apr-18-2017, 08:14 PM
RE: Code Review? - by PappaBear - Apr-18-2017, 10:25 PM
RE: Code Review? - by metulburr - Apr-18-2017, 10:43 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Python best library for Excel reports & review of existing code MasterOfDestr 4 725 Feb-14-2024, 03:39 PM
Last Post: MasterOfDestr
  Review my code: convert a HTTP date header to a datetime object stevendaprano 1 2,026 Dec-17-2022, 12:24 AM
Last Post: snippsat
  Code review for S3 object creation beherap 0 2,153 Mar-29-2018, 01:31 PM
Last Post: beherap

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020