Search Results
|
Post |
Author |
Forum |
Replies |
Views |
Posted
[asc]
|
|
|
Thread: Preventing: IndexError: list index out of range
Post: Preventing: IndexError: list index out of range
I understand how to use a for loop with range(len(list)) to be able to cycle through and address each item in a list.
However (and in my case a directory listing), I'm trying to figure out how to pr... |
|
PappaBear |
General Coding Help |
1 |
6,533 |
Jun-03-2019, 04:57 PM |
|
|
Thread: Iteration of an array
Post: RE: Iteration of an array
OMG!!!!! @Yoriz that's exactly what I was looking for!! So elegant!
and I know as a beginner, my code is far from "elegant" but that is so much better than my for loop!
-- it makes sense [array1][arr... |
|
PappaBear |
General Coding Help |
5 |
2,787 |
May-23-2019, 06:54 PM |
|
|
Thread: Iteration of an array
Post: RE: Iteration of an array
Sorry, here's some better formatting, and hopefully a better explanation:::
import time
import os
import collections
from collections import namedtuple
grp_list=[]
obj_list=[]
nt_object = namedtupl... |
|
PappaBear |
General Coding Help |
5 |
2,787 |
May-23-2019, 05:48 PM |
|
|
Thread: Iteration of an array
Post: Iteration of an array
I have an two-dimm array, with the "internal" array as a named tuple.
EG: I have
obj_list= []
my_Object = namedtuple('my_Object', 'name attribute1 attribute2')then throughout my program
obj_list.ap... |
|
PappaBear |
General Coding Help |
5 |
2,787 |
May-22-2019, 11:11 PM |
|
|
Thread: Please help me get this code working that i haven't posted yet
Post: RE: HELP FOR A NUB
Well, assuming this is for school... otherwise you'd provide code...
but let's get you "thinking" :-)
variable
a = 12
b = 6
then we want to add them and assign them to c
c = a+b
then of course we... |
|
PappaBear |
Homework |
3 |
2,428 |
May-22-2019, 09:45 PM |
|
|
Thread: multi-dimm array -- dynamic
Post: RE: multi-dimm array -- dynamic
I figured this out... basically in the first array, you insert the additional array
import time
import os
import collections
howmany=6
rulenumber=0
my_2d_list =[]
for counter1 in range(howmany):
f... |
|
PappaBear |
General Coding Help |
3 |
2,566 |
May-03-2019, 02:07 AM |
|
|
Thread: multi-dimm array -- dynamic
Post: multi-dimm array -- dynamic
I'm trying to figure out how to declare a 2d array (rows & columns); where the rows are dynamic
What I've been able to do is define number of rows, and columns are dynamic; which is the opposite... |
|
PappaBear |
General Coding Help |
3 |
2,566 |
May-02-2019, 11:04 PM |
|
|
Thread: Multi-Dimm Array or Class?
Post: RE: Multi-Dimm Array or Class?
ahhh, would never have known to look for that -- namedtuple is exactly what I'm looking for!!
I felt like a class was "too much" and an array wasn't enough...this should do the trick!
Huge thanks,... |
|
PappaBear |
General Coding Help |
2 |
2,275 |
May-02-2019, 07:04 PM |
|
|
Thread: Multi-Dimm Array or Class?
Post: Multi-Dimm Array or Class?
I'm working on a config converter for firewalls. (Take ASA config, make it a Palo Alto config, or a Juniper config, etc).
What I'm actually trying to do is store the following type of data
rul... |
|
PappaBear |
General Coding Help |
2 |
2,275 |
May-02-2019, 05:14 PM |
|
|
Thread: Populating Array2 from Array1
Post: RE: Populating Array2 from Array1
Persistence!
elif (current_line[0] == "username"):
username_list.append(current_line[1])
No need to set the list, simply append it! |
|
PappaBear |
General Coding Help |
1 |
2,065 |
Aug-22-2018, 04:30 AM |
|
|
Thread: Populating Array2 from Array1
Post: Populating Array2 from Array1
High level -- working on converting vendor-A network switch config to Vendor-B syntax
I am reading a config file, of which I have the current line; if the current line starts with "username", then I ... |
|
PappaBear |
General Coding Help |
1 |
2,065 |
Aug-22-2018, 12:20 AM |
|
|
Thread: Best construct? Array, class, other?
Post: Best construct? Array, class, other?
So as I recently modified my script to now take input from Vendor-A (asa) to Vendor-C (palo alto), I'm seeing that I may be better off using a CLASS.
The issue is that any _one security policy_ could... |
|
PappaBear |
General Coding Help |
1 |
2,979 |
May-10-2017, 06:08 AM |
|
|
Thread: Code Review?
Post: RE: Code Review?
Great feedback and mucho appreciatedo!
double quotes -- The Fortinet FW requires a double quote around (some) objects. But I was not aware Python sees " & ' equal, so good to know.
# of prints... |
|
PappaBear |
General Coding Help |
9 |
7,195 |
Apr-18-2017, 10:25 PM |
|
|
Thread: Code Review?
Post: RE: Looking for constructive criticism, thoughts, ...
Print one multi-line constant because it's resource intensive to call print, or simply "cleaner" or easier to update, etc?
Appreciate the feedback, but not sure _why_ multiple prints are bad. Seems l... |
|
PappaBear |
General Coding Help |
9 |
7,195 |
Apr-18-2017, 07:45 PM |
|
|
Thread: Code Review?
Post: Looking for constructive criticism, thoughts, and ...
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 s... |
|
PappaBear |
General Coding Help |
9 |
7,195 |
Apr-18-2017, 07:03 PM |
|
|
Thread: Code Review?
Post: RE: Code Review?
Interesting...Dictionaries... Did not know, but may be very useful as the app grows!
Thanks!
Wow, not sure I used GitHub correctly... another thing to learn...
But I believe you can now see the ... |
|
PappaBear |
General Coding Help |
9 |
7,195 |
Apr-18-2017, 02:03 PM |
|
|
Thread: Code Review?
Post: Code Review?
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 s... |
|
PappaBear |
General Coding Help |
9 |
7,195 |
Apr-18-2017, 06:06 AM |
|
|
Thread: General questions
Post: RE: General questions
Many thanks everyone! I was using NotePad++ (as I use it for all my networking stuff) with the NppPython plugin...
D/L Pycharm now :-) |
|
PappaBear |
News and Discussions |
9 |
5,951 |
Apr-11-2017, 03:22 PM |
|
|
Thread: General questions
Post: General questions
Prologue:::
Old guy here... been doing I.T. (Networking) for over 25 years now... and for the most part had a "scripter" on the team, so I never HAD to learn*.
written a few Bash scripts when needed,... |
|
PappaBear |
News and Discussions |
9 |
5,951 |
Apr-11-2017, 05:57 AM |
|
|
Thread: Simple Function Call
Post: RE: Simple Function Call
that was it -- I was missing the () when calling the function.. Huge thanks for the quick reply.
for counter in range(len(original_lines)):
if addressword in original_lines[counter]:
... |
|
PappaBear |
General Coding Help |
2 |
3,175 |
Apr-04-2017, 11:12 PM |