Re: REALLY simple xml reader

2008-01-27 Thread Navtej Singh
check the implementation of XMLNode class here
http://hsivonen.iki.fi/group-feed/flickrapi.py

HTH
N

On Jan 27, 2008 11:05 PM, Simon Pickles <[EMAIL PROTECTED]> wrote:
> Hi
>
> Can anyone suggest a really simple XML reader for python? I just want to
> be able to do something like this:
>
> xmlDoc = xml.open("file.xml")
> element = xmlDoc.GetElement("foo/bar")
>
> ... to read the value of:
>
> 
>42
> 
>
>
> Thanks
>
> Simon
>
> --
> Linux user #458601 - http://counter.li.org.
>
>
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Urllib keyerror, confused

2008-02-02 Thread Navtej Singh
possibly the server did not sent the 'Content-Length' header.

On Feb 2, 2008 5:18 PM, Adam W. <[EMAIL PROTECTED]> wrote:
> I took this script: 
> http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/83208
> And decided to try it out, it works when I first download a file, and
> when I try to resume a downloaded file, but if the file is already
> downloaded, and I expect to see the print "File already downloaded"
> message come up, I get a keyerror instead:
>
> Traceback (most recent call last):
>   File "C:\Users\Adam\Desktop\ddd.py", line 26, in 
> if int(webPage.headers['Content-Length']) == existSize:
>   File "C:\Python25\lib\rfc822.py", line 384, in __getitem__
> return self.dict[name.lower()]
> KeyError: 'content-length'
>
> Why did the key disappear?
>
> Here is the code I used (a little modified but functionally the same):
>
> import urllib, os
>
> class myURLOpener(urllib.FancyURLopener):
> """Create sub-class in order to overide error 206.  This error
> means a
>partial file is being sent,
>which is ok in this case.  Do nothing with this error.
> """
> def http_error_206(self, url, fp, errcode, errmsg, headers,
> data=None):
> pass
>
> loop = 1
> dlFile =
> "Okidata_Digital_B4600_Black_and_White_Laser_PrinterlacDetail.jpg"
> existSize = 0
> myUrlclass = myURLOpener()
> if os.path.exists(dlFile):
> outputFile = open(dlFile,"ab")
> existSize = os.path.getsize(dlFile)
> #If the file exists, then only download the remainder
> myUrlclass.addheader("Range","bytes=%s-" % (existSize))
> else:
> outputFile = open(dlFile,"wb")
>
> webPage = myUrlclass.open("http://s3-external-1.amazonaws.com/
> wootsaleimages/%s" % dlFile)
>
> #If the file exists, but we already have the whole thing, don't
> download again
> print "flyby"
> if int(webPage.headers['Content-Length']) == existSize:
> loop = 0
> print "File already downloaded"
>
> numBytes = 0.0
> numBytes += existSize
> while loop:
> data = webPage.read(8192)
> if not data:
> break
> outputFile.write(data)
> numBytes += len(data)
> print (float(numBytes/int(webPage.headers['Content-Length']))*100)
>
> webPage.close()
> outputFile.close()
>
> for k,v in webPage.headers.items():
> print k, "=",v
> print "copied", numBytes, "bytes from", webPage.url
> raw_input("Cat")
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python GDB Wrapper

2008-03-07 Thread Navtej Singh
Raja,

Check this http://fusil.hachoir.org/trac/wiki/Ptrace [gdb.py]

On Fri, Mar 7, 2008 at 2:11 PM, Raja <[EMAIL PROTECTED]> wrote:
> On Mar 7, 1:21 pm, Raja <[EMAIL PROTECTED]> wrote:
>  > Hi All,
>  >   Thanks for replies. Daniel- I am looking at just a wrapper
>  > around GDB. I dont want to emulate the functionalities of GDB but
>  > instead use them in python scripting.
>  > Martin - Misc/gdbinit looks promising. Thanks a lot.
>  >
>  > Thanks,
>  > Raja.
>  >
>  > On Mar 7, 12:43 pm, "Martin v. Löwis" <[EMAIL PROTECTED]> wrote:
>  >
>  > > > Has anyone does this before ? Even some basic idea or code as to how
>  > > > to proceed would be great.
>  >
>  > > Have you seen Misc/gdbinit?
>  >
>  > > Regards,
>  > > Martin
>
>  Hi All,
>  Marting- I looked at the Misc/gdbinit but what I want is a Python
>  module which wraps around GDB and exposes its functionality, which has
>  some methods in it like pystack to which if I give the arguments as
>  program name and arguments displays the stack trace of that particular
>  program .
>
>  Thanks,
>  Raja.
>
>
> --
>  http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Override the '+' symbol

2008-09-21 Thread Navtej Singh
http://docs.python.org/ref/numeric-types.html

On Sun, Sep 21, 2008 at 8:37 PM, Mr.SpOOn <[EMAIL PROTECTED]> wrote:

> Hi,
> how can I override the '+' symbol (and other math symbols) so that it
> can have a new behavior when applied to some objects?
> --
> http://mail.python.org/mailman/listinfo/python-list
>
--
http://mail.python.org/mailman/listinfo/python-list