Starting Python... some questions

jezonthenet at yahoo.com jezonthenet at yahoo.com
Tue Mar 13 00:39:11 EDT 2007


I started using Python a couple of days ago - here are a few
questions:

* Doesn't the __main__() method automatically execute when I run my
python program?
* Only when I do an import of my test.py file within python and then
run test.__main__() I can see where my bugs are. Is this correct?
(right now this is my only way of running my python program and see
where I have problems)
* Once I've done an import and then I wish to make a change to the
file I've imported I have to quit Python, restart and import that
module again in order for the module to be refreshed. Is there no "re-
import" ?
* Finally, could someone tell me why I'm having problems with the
small module below?
  - Python pretends I provide chassis_id() with three parameters, even
though I clearly only provide it with two - why?

Thanks!

#!/usr/bin/python
import scapy
import struct

class lldp_class:
	def __init__(self):
		self.chassis_id_tlv = None

	def chassis_id(subtype, chassis_info):
		if subtype == 4:
			chassis_data = struct.pack("!B",chassis_info)
		subtype_data = struct.pack("!B",subtype)
		self.chassis_id_tlv = subtype_data + chassis_data

def __main__():
	p = lldp_class()
	p.chassis_id(4, "01:80:C2:00:00:0E")
	payload = p.chassis_id_tlv
	ether = scapy.Ether(dst="01:02:03:04:05:06")
	fullpayload = ether + payload
	sendp(fullpayload)




More information about the Python-list mailing list