Arrays, Got Me Confused

Robert Rawlins - Think Blue robert.rawlins at thinkbluemedia.co.uk
Fri Apr 13 08:04:02 EDT 2007


Hello Guys,

 

I'm struggling to get my head into arrays in python, I've used them plenty
in other languages but I'm struggling to find any decent documentation for
them in python. I'm looking to build a list of network MAC address's into an
array, which will probably be used for logging and firewalling and things.

 

I've build the basic class, the idea is that the class represents the
firewall, and I have functions for the firewall like addDevice() and
isFirewalled() where I pass in the address and it returns a value or updates
the array. However I'm getting an error when trying to create an empty array
on the init.

 

#!/usr/bin/python

# Filename: Firewall.py

 

class Firewall:

 

       def __init__(self):

              Self.FireArray = array(c)

 

p = Firewall()

print p

 

 

Throws:

 

Traceback (most recent call last):

  File "./firewall.py", line 9, in ?

    p = Firewall()

  File "./firewall.py", line 7, in __init__

    Self.FireArray = array(c)

NameError: global name 'array' is not defined

 

How can I solve this problem? From what I've seen writing I can't see
anything wrong with my syntax, perhaps you can shed some light on the
situation. Whilst I'm writing there is also another question I would like to
pose briefly. How do a create an object from an external file? Obviously in
my one above all I need do is call Firewall() and it creates an instance,
but I'm used to creating my class's as separate files, how do I create them
as an object in my main application?

 

Thanks,

 

Rob

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20070413/e1f8578f/attachment.html>


More information about the Python-list mailing list