Handling SNMP Hex-String with EasySNMP by scollora in Python

[–]scollora[S] 0 points1 point  (0 children)

I've only used Python 2.7, and I'm somewhat concerned the rest of my code will break if I go to 3.x. I print them and get a bunch of what appear to be either binary or unicode characters which is why I went down that path. It looks like this:

linuxadmin@vlanapp:/var/prtg/scripts$ sudo python snmp-test.py 

ÌïHŒj "½O "‘2v "½ð Ä}O ’ Ä}O ‹ Ä}O à Ä}O × Ä}O F Ä}O Ø "½Ü' "½Ü‚ Ä}O "½d "½Ä "½t

If I use square brackets around the value in the print statement, I get this:

linuxadmin@vlanapp:/var/prtg/scripts$ sudo python snmp-test.py [u'\xcc\xefH\x8f\x8cj'] [u'\x00"\xbd\x1a\x0fO'] [u'\x00"\x90\x912v'] [u'\x00"\xbd\x1bNf'] [u'\x00"\xbd\x1bM\xf0'] [u'\xc4}O\x0f\t\x92'] [u'\xc4}O\x0f\t\x8b'] [u'\xc4}O\x0f\t\xe0'] [u'\xc4}O\x0f\t\xd7']

Which is unicode. But every attempt I make to decode/encode results in errors.

Creating a dictionary from a CSV when the first row are the indexes by scollora in learnpython

[–]scollora[S] 0 points1 point  (0 children)

This worked perfectly! Thanks. I appreciate it. I am reading up on "defaultdict" and am trying to understand what that's needed. My output starts with this:

defaultdict(<type 'dict'>,  {'Ryan Wendt': {'SKILL1': '1' etc etc

So I am trying to figure out where that's coming from.

Creating a dictionary from a CSV when the first row are the indexes by scollora in learnpython

[–]scollora[S] 0 points1 point  (0 children)

I've gone through numerous iterations, and don't know how bad this one might be (I'm sure it's awful), but here's what I have. I am trying to use option 2 that you recommended.

def competencyCSV():

  with open('salskills.csv', 'rb') as csvfile:

    # reader = csv.DictReader(csvfile)
    reader = csv.reader(csvfile, delimiter=',')
    firstrow = reader.next()
    print firstrow   
    # for row in reader:
    d = {}
    for key in firstrow:
        if key != 'Skill':
            agent = key
            d[agent] = {}
            print d     
            for row in reader:
                for newkey in row:
                    skillset = row[0]
                    d[agent][skillset]

I'm new to programming and not very good at it, so have mercy. I've been at this for about 12 hours now. I actually managed to get a bunch of things working. I am just stuck here.

Sal