libxml2 Installation for Python 2.4

2008-05-13 Thread Alok Kumar
Hi,

Can someone point me how to install libxml2 for python. It works fine on my
Redhat 4.0 linux Box, but when I am trying to run my script on ARM target ,
it throws import error for libxml2.

I am using xpath in my script and in header trying to import libxml2.

Thanks in advance.
Alok
--
http://mail.python.org/mailman/listinfo/python-list

Struct usages in Python

2008-05-27 Thread Alok Kumar
Dear All,

This might be very basic question for python, but I have been struggling
with it.  Your help will be highly appreciated.

I have a class like below:

class Event():

   def __init__(self, cameraEventType="", zone=99, setDay="",setTime ="",
clrTime=""):

 self.cameraEventType = cameraEventType

 self.zone = zone

 self.setDay = setDay

 self.setTime = setTime

 self.clrTime = clrTime

I want to use array of Event class object in another class like below:

class EventTimeFilter:

   def __init__(self):
   self.event[] = Event()   *# Seems this is not allowed ?? *

Can someone help me how can I use array of Event object in EventTimeFilter
class. I planned to fill array of Event object in EventTimeFilter class
method.

Thanks in advance.

Regards
Alok
--
http://mail.python.org/mailman/listinfo/python-list

multi dimensional dictionary

2008-05-27 Thread Alok Kumar
Dear All,

I am using dictionary for filling my xpath parsed data.

I wanted to use in the following manner.

mydict[index] ["key1"] ["key2"]#Can someone help me with right
declaration.

So that I can fill my XML xpath parsed data

mydict[0] ["person"] ["setTime"] = "12:09:30"
mydict[0] ["person"] ["clrTime"] = "22:09:30"

Can someone help me with right declaration usages. Your help will be highly
appreciated.

Regards
Alok
--
http://mail.python.org/mailman/listinfo/python-list

Re: Struct usages in Python

2008-05-28 Thread Alok Kumar
while traversing I get out of index error as mentioned below.


class EventTimeFilter:

   def __init__(self):
*   self.event = [Event()]*


   def populateScheduleData(self):

   self.doc = libxml2.parseFile(self.FILENAME)
   for eachcamera in
self.doc.xpathEval('SetDeviceConfiguration/Camera/.'):
cameraIndex = eachcamera.get_properties()
#print cameraIndex
index = int(cameraIndex.content,10)
print index

xpathEventType = 'SetDeviceConfiguration/[EMAIL PROTECTED]' +
cameraIndex.content +']/Filter/Event'
for searchResults in self.doc.xpathEval(xpathEventType):
 eventType = searchResults.get_properties()

* self.event[index-1].cameraEventType = eventType.content #
Error*

*#Error as below*
self.event[index-1].cameraEventType = eventType.content
IndexError: list index out of range

Any guidance why I am getting *list index out of range error*?
index value runs from 1 to 4.
Thanks for all your help.
Alok

On Wed, May 28, 2008 at 1:09 AM, Casey McGinty <[EMAIL PROTECTED]>
wrote:

>
>self.event[] = Event()   *# Seems this is not allowed ?? *
>>
>
> self.event = [Event()]
>
> - Casey
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>



-- 
Regards
Alok Kumar
--
http://mail.python.org/mailman/listinfo/python-list

Re: Struct usages in Python

2008-05-28 Thread Alok Kumar
I am getting following error when tried as you suggested.

self.event = []  #Create an empty list, bind to the name "event" under the
"self" namespace
   self.event.append(Event())   #Create an event object and append
to the end of the list

*class Event():
^
SyntaxError: invalid syntax*


On Wed, May 28, 2008 at 1:07 AM, Patrick Mullen <[EMAIL PROTECTED]>
wrote:

> I don't know if this will go through (my posts seem to have become blocked
> lately), but I'll give it a shot anyhow.
>
> You seem to be under a misconception that a python list is similar to a
> list in say, Java or other languages that have a rigid idea of variables and
> types.  In python, a list is a list of objects - any type of object can be
> stored in a list.  Just as you don't declare types for variables, you also
> don't declare types for lists.  Here is your modified code:
>
> class Event():
>def __init__(self, cameraEventType="", zone=99, setDay="",setTime ="",
> clrTime=""):
>  self.cameraEventType = cameraEventType
>  self.zone = zone
>  self.setDay = setDay
>  self.setTime = setTime
>  self.clrTime = clrTime
>
> class EventTimeFilter:
>def __init__(self):
>self.event = []  #Create an empty list, bind to the name "event"
> under the "self" namespace
>self.event.append(Event())   #Create an event object and append
> to the end of the list
>
>
> Python won't stop you from putting other objects into self.event besides
> Event objects, but in practice this isn't often an issue.  The real benefit,
> is if you subclass event or make some other type of object that is similar
> to events, with maybe some of the same fields, you can still store them in
> the list and it will play along with the rest of your code.
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>



-- 
Regards
Alok Kumar
--
http://mail.python.org/mailman/listinfo/python-list

Re: multi dimensional dictionary

2008-05-28 Thread Alok Kumar
Thanks to all for their kind help and time.

Alok

On Wed, May 28, 2008 at 4:11 AM, Peter Otten <[EMAIL PROTECTED]> wrote:

> Gary Herron wrote:
>
> > Alok Kumar wrote:
> >> Dear All,
> >>
> >> I am using dictionary for filling my xpath parsed data.
> >>
> >> I wanted to use in the following manner.
> >>
> >> mydict[index] ["key1"] ["key2"]#Can someone help me with right
> >> declaration.
> >>
> >> So that I can fill my XML xpath parsed data
> >>
> >> mydict[0] ["person"] ["setTime"] = "12:09:30"
> >> mydict[0] ["person"] ["clrTime"] = "22:09:30"
>
> [I didn't see the original post]
>
> >>> from collections import defaultdict
> >>> def make_inner():
> ... return defaultdict(lambda: defaultdict(make_inner))
> ...
> >>> mydict = make_inner()
> >>> mydict[0]["person"]["setTime"] = "12:09:30"
> >>> mydict[0]["person"]["shoes"]["color"] = "bright yellow"
> >>> mydict
> defaultdict( at 0x2b7afd0025f0>, {0:
> defaultdict( make_inner at 0x2b7afd002578>, {'person': defaultdict( at
> 0x2b7afd002668>, {'setTime': '12:09:30', 'shoes': defaultdict( make_inner at 0x2b7afd002578>, {'color': 'bright yellow'})})})})
>
> If that looks too messy, try a subclass:
>
> >>> class Dict(defaultdict):
> ... def __init__(self):
> ... defaultdict.__init__(self, Dict)
> ... def __repr__(self):
> ... return dict.__repr__(self)
> ...
> >>> mydict = Dict()
> >>> mydict[0]["person"]["setTime"] = "12:09:30"
> >>> mydict
> {0: {'person': {'setTime': '12:09:30'}}}
> >>> mydict[0]["person"]["shoes"]["color"] = "bright yellow"
> >>> mydict
> {0: {'person': {'setTime': '12:09:30', 'shoes': {'color': 'bright
> yellow'
>
> Peter
> --
> http://mail.python.org/mailman/listinfo/python-list
>



-- 
Regards
Alok Kumar
--
http://mail.python.org/mailman/listinfo/python-list

Re: Struct usages in Python

2008-05-28 Thread Alok Kumar
Thanks to everyone for your help.

I am able to use array of structure (here Event is a class) in the following
manner. But here I am fixing the array index as 4. Is there any easy way to
keep it appending dynamically.

self.event = [Event() for x in range(4)]  # Event is a class as posted in
original message.

I have one set of structures and want to process them, subsequently couple
of them will not be able to pass the criteria and all passed ones I wanted
to put in another list where I can dynamically append the structure. So that
I can post this list to server.

Thanks in advance.

Regards
Alok


On Wed, May 28, 2008 at 1:53 PM, Arnaud Delobelle <[EMAIL PROTECTED]>
wrote:

> Arnaud Delobelle <[EMAIL PROTECTED]> writes:
>
> > "Alex Gusarov" <[EMAIL PROTECTED]> writes:
> >
> >>>  class Event(object):
> >>>
> >>> Always subclass object, unless you have a very compelling reason not
> to,
> >>> or you are subclassing something else.
> >>>
> >>
> >> I've thought that if I write
> >>
> >> class Event:
> >> pass
> >>
> >> , it'll be subclass of object too, I was wrong?
> >
> > You are wrong for Python 2.X, but right for Python 3 where old-style
> > classes are gone for good.
> >
> > What you define with the statement
> >
> > class Event: pass
> >
> > is an 'old-style' class.  Witness:
> >
> > >>> class Event: pass
> > ...
> > >>> class NewEvent(object): pass
> > ...
> > >>> type(Event)
> > 
> > >>> type(NewEvent)
> > 
> > >>> type(Event())
> > 
> > del>>> type(NewEvent())
> > 
> >
> > All old-style classes are actually objects of type 'classobj' (they
> > all have the same type!), all their instances are all of type 'instance'.
>
> Oops somthing disappeared in the copy/paste process:
>
>>>> class FooBar: pass
>...
>
> > >>> type(FooBar) == type(Event)
> > True
> > >>> type(FooBar()) == type(Event())
> > True
> >
> > Whereas instances of new-style classes are of type their class:
> >
> > >>> class NewFooBar(object): pass
> > ...
> > >>> type(NewFooBar) == type(NewEvent)
> > True
> > >>> type(NewFooBar()) == type(NewEvent())
> > False
> >
> > However, in python 2.X (X > 2?), you can force all classes to of a
> > certain type by setting the global variable '__metaclass__'. So:
> >
> > >>> type(Event) # Event is an old-style class
> > 
> > >>> __metaclass__ = type
> > >>> class Event: pass
> > ...
> > >>> type(Event) # Now Event is new-style!
> > 
> >
> > HTH
> >
> > --
> > Arnaud
> --
> http://mail.python.org/mailman/listinfo/python-list
>



-- 
Regards
Alok Kumar
--
http://mail.python.org/mailman/listinfo/python-list

UTC datetime.fromtimestamp

2008-06-03 Thread Alok Kumar
Dear All,

I have UTC  datetime as datetime.fromtimestamp(ParseDateTimeUTC("2007-12-06
20:37:05"))

How can I add a day into this. Your help will be highly appreciated.

Regards
Alok
--
http://mail.python.org/mailman/listinfo/python-list

ImportError: No module named _md5

2008-07-03 Thread Alok Kumar
I am trying to move from python 2.4 to python 2.5.2. After compiling the
python 2.5.2, I found it is throwing "ImportError: No module named _md5".

I found this topic on the mailing list, but no solution to fix it.

Can someone help me out. It will be highly appreciated.

Regards
Alok
--
http://mail.python.org/mailman/listinfo/python-list

Python HTTPS Bus Error

2008-07-08 Thread Alok Kumar
Hi,

Can someone help me what to look for fixing Bus error. I must mention that I
am working  in embedded environment and it does have selective installation
of python

I am getting following error from client when it is trying to talk with
server over *HTTPS*. HTTP works fine.

*Alignment trap: python2.5 (1030) PC=0x4058a738 Instr=0xe5902004
Address=0x01*

*35 FSR 0x001*

*Bus error*

Server throws SSL handshake failure error.


It will be great if someone can throw any pointers.
Regards
Alok
--
http://mail.python.org/mailman/listinfo/python-list

Basic Question about Python WebServer File handling

2008-07-10 Thread Alok Kumar
Hi,

I need to have a python webserver which can handle Get request from the
clients and upload the *files* from 4 different directories.

Can someone please point me what to exactly look for.

Thanks you very much for this great help.

Regards
Alok Kumar
--
http://mail.python.org/mailman/listinfo/python-list

HTTP Error code Info

2008-05-02 Thread Alok Kumar
Hi
I could get the HTTP error code using
try:
..
except:
..
else:

block.  Is there any better way to get the HTTP Error code using urllib2
lib. Something like know the  exact  response number (200, 404 etc) without
the above block.

Regards
Alok Kumar
--
http://mail.python.org/mailman/listinfo/python-list

State machine Example in Python

2008-05-03 Thread Alok Kumar
Can someone please redirect me for a state machine example or design pattern
used in Python.

Regards
Alok
--
http://mail.python.org/mailman/listinfo/python-list

Python Minidom Help

2008-05-05 Thread Alok Kumar
Hi,

I am reading a XML data from  HTTP server and giving it to parse method.

dom = parse(dataread)

It throws following error

  File "/usr/lib/python2.3/site-packages/_xmlplus/dom/minidom.py", line
1908, in parse
return expatbuilder.parse(file)
  File "/usr/lib/python2.3/site-packages/_xmlplus/dom/expatbuilder.py", line
922, in parse
fp = open(file, 'rb')

Can anyone please help?

Regards
Alok Kumar
--
http://mail.python.org/mailman/listinfo/python-list