Re: Need help in xml
Thanx Dennis Lee Bieber for ur suggestion. After following ur suggestion i am getting 3 list after reading and comparing the 2 xml document. +, adds ['/home/moq/buc/2+add.py,200606281354\r \n', '/home/moq/buc/1+add.py,200607031215\r \n'] Modified ['/home/moq/buc/2+mod2.py,200607111031\r \n', '/home/moq/buc/1+mod.py,200607111031\r \n'] deletes ['/home/moq/buc/2+del.py,200606281354\r \n', '/home/moq/buc/1+del.py,200607031215\r \n'] I have to put these in to an xml format of type /home/moq/buc/2 add.py 200606281354 /home/moq/buc/1 add 200607031215 Similarly for Modified and deleted. can someone help me with the code for this. Thanx -- http://mail.python.org/mailman/listinfo/python-list
Problem with "&" charater in xml.
i have walked a directory and have written the foll xml document. one of the folder had "&" character so i replaced it by "&" #--test1.xml C:\Documents and Settings\Administrator\Desktop\1\bye w&y def.txt 200607130417 C:\Documents and Settings\Administrator\Desktop\1\hii wx abc.txt 200607130415 http://mail.python.org/mailman/listinfo/python-list
Re: Problem with "&" charater in xml.
How do i append characters to a string?
actually my entire handler code is
class oldHandler(ContentHandler):
def __init__(self):
self.fn = 0
self.dn = 0
self.i=[]
self.x=""
self.y=""
self.z=""
self.t=0
self.xx=''
def startElement(self, name, attrs):
if name=='dirname':
self.dn=1
if name=='name':
self.fn=1
if name=='time':
self.t=1
def characters(self,str):
if self.dn:
self.x=str
if self.fn:
self.y=str
if self.t:
self.z=str
ss= self.x+'/'+self.y+','+self.z+ '\r \n'
self.i.append(ss)
def endElement(self, name):
if name == 'dirname':
self.dn=0
if name=='name':
self.fn=0
if name=='time':
self.t=0
def endDocument(self):
f=open('old.txt', 'w')
self.i.sort
f.writelines(self.i)
f.close
so my old.txt now looks like this
y+def.txt,200607130417
C:\Documents and Settings\Administrator\Desktop\1\hii
wx\abc.txt,200607130415
But i wont the output as
C:\Documents and Settings\Administrator\Desktop\1\bye
w&y\def.txt,200607130417
C:\Documents and Settings\Administrator\Desktop\1\hii
wx\abc.txt,200607130415
Stefan Behnel wrote:
> Kirt wrote:
> > i have walked a directory and have written the foll xml document.
> > one of the folder had "&" character so i replaced it by "&"
> > #--test1.xml
> >
> > C:\Documents and Settings\Administrator\Desktop\1\bye
> > w&y
> >
> > def.txt
> > 200607130417
> >
> >
> >
> > C:\Documents and Settings\Administrator\Desktop\1\hii
> > wx
> >
> > abc.txt
> > 200607130415
> >
> > >
> > now in my python code i want to parse this doc and print the directory
> > name.
> > ###--handlerfilename---handler.py
> > from xml.sax.handler import ContentHandler
> > class oldHandler(ContentHandler):
> >def __init__(self):
> > self.dn = 0
> > def startElement(self, name, attrs):
> > if name=='dirname':
> > self.dn=1
> >
> > def characters(self,str):
> > if self.dn:
> >print str
>
>
> The problem is here. "print" adds a newline. Don't use print, just append the
> characters (to a string or list) until the endElement callback is called.
>
>
> > def endElement(self, name):
> > if name == 'dirname':
> > self.dn=0
> >
> >
> > #-
> > #main code--- fnameart.py
> > import sys
> > from xml.saximport make_parser
> > from handlers importoldHandler
> >
> > ch = oldHandler()
> > saxparser = make_parser()
> >
> > saxparser.setContentHandler(ch)
> > saxparser.parse(sys.argv[1])
> > #-
> > i run the code as: $python art.py test1.xml
> >
> > i am getting output as:
> >
> > C:\Documents and Settings\Administrator\Desktop\1\bye w
> > &
> > y
> > C:\Documents and Settings\Administrator\Desktop\1\hii wx
> >
> > where as i need an output which should look like this.
> > C:\Documents and Settings\Administrator\Desktop\1\bye w&y
> >
> > C:\Documents and Settings\Administrator\Desktop\1\hii wx
> >
> > Can someone tell me the solution for this.
> >
--
http://mail.python.org/mailman/listinfo/python-list
Re: Problem with "&" charater in xml.
thanx stefan ur approach worked. Stefan Behnel wrote: > Kirt wrote: > > How do i append characters to a string? > > I think the normal approach is to store an empty string (or list) in an > attribute in startElement(), append to it in characters() and use the result > in endElement(). > > def startElement(self, ...): > self.chars = '' > def characters(self, s): > self.chars += s > def endElement(self, ...): > value = self.chars > > Or use a list and do this: > > def endElement(self, ...): > value = ''.join(self.char_list) > > Maybe you should consider switching to iterparse() of ElementTree or lxml. > Should be a bit easier to use than SAX ... > > http://effbot.org/zone/element-iterparse.htm > http://codespeak.net/svn/lxml/trunk/doc/api.txt > > Stefan > > > > Stefan Behnel wrote: > >> Kirt wrote: > >>> i have walked a directory and have written the foll xml document. > >>> one of the folder had "&" character so i replaced it by "&" > >>> #--test1.xml > >>> > >>> C:\Documents and Settings\Administrator\Desktop\1\bye > >>> w&y > >>> > >>> def.txt > >>> 200607130417 > >>> > >>> > >>> > >>> C:\Documents and Settings\Administrator\Desktop\1\hii > >>> wx > >>> > >>> abc.txt > >>> 200607130415 > >>> > >>> >>> > >>> now in my python code i want to parse this doc and print the directory > >>> name. > >>> ###--handlerfilename---handler.py > >>> from xml.sax.handler import ContentHandler > >>> class oldHandler(ContentHandler): > >>>def __init__(self): > >>> self.dn = 0 > >>> def startElement(self, name, attrs): > >>> if name=='dirname': > >>> self.dn=1 > >>> > >>> def characters(self,str): > >>> if self.dn: > >>>print str > >> > >> The problem is here. "print" adds a newline. Don't use print, just append > >> the > >> characters (to a string or list) until the endElement callback is called. > >> > >> > >>> def endElement(self, name): > >>> if name == 'dirname': > >>> self.dn=0 > >>> > >>> > >>> #- > >>> #main code--- fnameart.py > >>> import sys > >>> from xml.sax import make_parser > >>> from handlers import oldHandler > >>> > >>> ch = oldHandler() > >>> saxparser = make_parser() > >>> > >>> saxparser.setContentHandler(ch) > >>> saxparser.parse(sys.argv[1]) > >>> #- > >>> i run the code as: $python art.py test1.xml > >>> > >>> i am getting output as: > >>> > >>> C:\Documents and Settings\Administrator\Desktop\1\bye w > >>> & > >>> y > >>> C:\Documents and Settings\Administrator\Desktop\1\hii wx > >>> > >>> where as i need an output which should look like this. > >>> C:\Documents and Settings\Administrator\Desktop\1\bye w&y > >>> > >>> C:\Documents and Settings\Administrator\Desktop\1\hii wx > >>> > >>> Can someone tell me the solution for this. > >>> > > -- http://mail.python.org/mailman/listinfo/python-list
help in xml and python
i have a List modifiedfiles= [['/home/moq/buc/2/mod2.py', '200607131001'], ['/home/moq/buc/1/mod2.py', '200607131000'], ['/home/moq/buc/1/mod3.py', '200607131001'], ['/home/moq/buc/1+mod1.py', '200607131001']] i have to put them in am xml format like the follg. /home/moq/buc/2 mod2.py 200607131001 /home/moq/buc/1 mod1.py 200607131001 mod2.py 200607131001 mod3.py 200607131001 can someone please with the code for this. -- http://mail.python.org/mailman/listinfo/python-list
locked file
i have a code that backsup file from src to dest. Now if some of the files are locked , i need to skip those files.. I was trying to use fctl module but it can be used only in unix i suppose. is there anyother way? i am using windows os. -- http://mail.python.org/mailman/listinfo/python-list
Re: locked file
By locked files i mean Outlook PST file while Outlook has it open Simon Forman wrote: > Kirt wrote: > > i have a code that backsup file from src to dest. > > Now if some of the files are locked , i need to skip those files.. > > I was trying to use fctl module but it can be used only in unix i > > suppose. > > > > is there anyother way? i am using windows os. > > What does locked mean in this case? No read permissions? In use by > another program? > > I haven't used windows in a long time, and I wasn't aware that one > could lock files in it. > > Peace, > ~Simon -- http://mail.python.org/mailman/listinfo/python-list
Need help in Py2exe
I have a simple scrips that Parses a XML file and prints its element.
1)Main.py
2)Handler.py
3)test.xml
The scripts works fine from comand prompt.
Now i wanted to convert it to an exe. So i wrote a setup.py scripts as
folows:
#-Setup.py--
from distutils.core import setup
import py2exe
setup(
name = "Main",
description = " Parse XML",
version = "0.1",
windows = [
{"script": "main.py",
"icon_resources": [(1, "xml.ico")]
}
],
data_files=[("List.xml"),("handler.py")],
)
---
When i run this as python setup.py py2exe. I get an main.exe file in
dist folder. But when i run the file i get an error --
Traceback (most recent call last):
File "main.py", line 7, in ?
File "xml\sax\sax2exts.pyc", line 37, in make_parser
File "xml\sax\saxexts.pyc", line 77, in make_parser
xml.sax._exceptions.SAXReaderNotAvailable: No parsers found..
I think i am missing something in setup.py file. Can anyone help?
--
http://mail.python.org/mailman/listinfo/python-list
Re: Need help in Py2exe
> > there's a page on the py2exe site about tweaks necessary for specific > modules: > > http://www.py2exe.org/index.cgi/WorkingWithVariousPackagesAndModules > > look for: > > If you're getting File "xml\sax\saxexts.pyc", line 77, in > make_parser; xml.sax._exceptions.SAXReaderNotAvailable: No > parsers found, read this > > Thanx for the help. It worked. -- http://mail.python.org/mailman/listinfo/python-list
http call.
Hi! I have a php program (test.php) on a server. eg: http://abc.xyz.com/test.php I need my python scripts to make a http call to these program pass some data and get back a secret key from the php program.. Could anyone help me this, what will i need to make a http call to the php application? -- http://mail.python.org/mailman/listinfo/python-list
Need help in xml
i have two xml documemts of type test 2006-12-12 12:12:12 /home/ test2 12:12:12 /home/test test3 12:12:12 i have to compare 2 similar xml document and get the add, changed and deleted files.and write it into acd.xml file. can u help me with the python code for this. I am using SAX. -- http://mail.python.org/mailman/listinfo/python-list
Problem with List of List
I am a newbie and stuck over this for a week I have a code ==CODE= List=[['1', 'a', '6'], ['1', 'b', '6'], ['1', 'c', '6'], ['1', 'd', '6'],['2', 'a','6'], ['2', 'b', '6'], ['2', 'c', '6'], ['2', 'd', '6'], ['3', 'a', '6'], ['3','b', '6'], ['4', 'a', '6'], ['4', 'b', '6']] for x in List: temp=[] print x for y in List: if x[0]==y[0]: print y[0],y[1] temp.append(y) for z in temp: List.remove(z) print 'rem', z === the output i am getting at Present is: ==Current OP= ['1', 'a', '6'] 1 a 1 b 1 c 1 d rem ['1', 'a', '6'] rem ['1', 'b', '6'] rem ['1', 'c', '6'] rem ['1', 'd', '6'] ['2', 'b', '6'] 2 a 2 b 2 c 2 d rem ['2', 'a', '6'] rem ['2', 'b', '6'] rem ['2', 'c', '6'] rem ['2', 'd', '6'] ['4', 'a', '6'] 4 a 4 b rem ['4', 'a', '6'] rem ['4', 'b', '6'] i am wondering where " ['3', 'a', '6'], ['3','b', '6']" is not showing. I want an output like this: ['1', 'a', '6'] 1 a 1 b 1 c 1 d rem ['1', 'a', '6'] rem ['1', 'b', '6'] rem ['1', 'c', '6'] rem ['1', 'd', '6'] ['2', 'b', '6'] 2 a 2 b 2 c 2 d rem ['2', 'a', '6'] rem ['2', 'b', '6'] rem ['2', 'c', '6'] rem ['2', 'd', '6'] ['3', 'a', '6'] 3 a why is this portion 3 b not present in my current op rem ['3', 'a', '6'] rem ['3', 'b', '6'] = ['4', 'a', '6'] 4 a 4 b rem ['4', 'a', '6'] rem ['4', 'b', '6'] I hope ull wil get what i am trying to say. Can anyone help: Thanx -- http://mail.python.org/mailman/listinfo/python-list
Re: Problem with List of List
Fredrik Lundh wrote: > Fredrik Lundh wrote: > > >> I have a code > >> ==CODE= > >> List=[['1', 'a', '6'], ['1', 'b', '6'], ['1', 'c', '6'], > >> ['1', 'd', '6'],['2', 'a','6'], ['2', 'b', '6'], > >> ['2', 'c', '6'], ['2', 'd', '6'], ['3', 'a', '6'], > >> ['3','b', '6'], ['4', 'a', '6'], ['4', 'b', '6']] > >> > >> > >> for x in List: > >> temp=[] > >> print x > >> for y in List: > >> if x[0]==y[0]: > >> print y[0],y[1] > >> temp.append(y) > >> for z in temp: > >>List.remove(z) > >> print 'rem', z > > > > the for loop uses an internal index to fetch items from the list you're > > looping over, so if you remove items from it, you'll end up skipping > > over items. > > forgot to mention that the fix is to change the first for statement to: > > for x in List[:]: > > Thanx Fredrik Lundh for ur response. I tried ur fix But the output i am getting is repeated. for x in List[:]: t2=[] print x[0] for y in List: if x[0]==y[0]: print y[1],y[2] t2.append(y) for z in t2: List[:].remove(z) The output i am getting is now is: 1 a 6 b 6 c 6 d 6 1 a 6 b 6 c 6 d 6 1 a 6 b 6 c 6 d 6 1 a 6 b 6 c 6 d 6 2 a 6 b 6 c 6 d 6 2 a 6 b 6 c 6 d 6 2 a 6 b 6 c 6 d 6 2 a 6 b 6 c 6 d 6 3 a 6 b 6 3 a 6 b 6 4 a 6 b 6 4 a 6 b 6 Can u show me where i am going wrong. -- http://mail.python.org/mailman/listinfo/python-list
Re: Problem with List of List
Fredrik Lundh wrote: > Fredrik Lundh wrote: > > >> I have a code > >> ==CODE= > >> List=[['1', 'a', '6'], ['1', 'b', '6'], ['1', 'c', '6'], > >> ['1', 'd', '6'],['2', 'a','6'], ['2', 'b', '6'], > >> ['2', 'c', '6'], ['2', 'd', '6'], ['3', 'a', '6'], > >> ['3','b', '6'], ['4', 'a', '6'], ['4', 'b', '6']] > >> > >> > >> for x in List: > >> temp=[] > >> print x > >> for y in List: > >> if x[0]==y[0]: > >> print y[0],y[1] > >> temp.append(y) > >> for z in temp: > >>List.remove(z) > >> print 'rem', z > > > > the for loop uses an internal index to fetch items from the list you're > > looping over, so if you remove items from it, you'll end up skipping > > over items. > > forgot to mention that the fix is to change the first for statement to: > > for x in List[:]: > > Thanx Fredrik Lundh for ur response. I tried ur fix But the output i am getting is repeated. for x in List[:]: t2=[] print x[0] for y in List: if x[0]==y[0]: print y[1],y[2] t2.append(y) for z in t2: List[:].remove(z) The output i am getting is now is: 1 a 6 b 6 c 6 d 6 1 a 6 b 6 c 6 d 6 1 a 6 b 6 c 6 d 6 1 a 6 b 6 c 6 d 6 2 a 6 b 6 c 6 d 6 2 a 6 b 6 c 6 d 6 2 a 6 b 6 c 6 d 6 2 a 6 b 6 c 6 d 6 3 a 6 b 6 3 a 6 b 6 4 a 6 b 6 4 a 6 b 6 Can u show me where i am going wrong. -- http://mail.python.org/mailman/listinfo/python-list
Re: Problem with List of List
Kirt wrote: > Fredrik Lundh wrote: > > Fredrik Lundh wrote: > > > > >> I have a code > > >> ==CODE= > > >> List=[['1', 'a', '6'], ['1', 'b', '6'], ['1', 'c', '6'], > > >> ['1', 'd', '6'],['2', 'a','6'], ['2', 'b', '6'], > > >> ['2', 'c', '6'], ['2', 'd', '6'], ['3', 'a', '6'], > > >> ['3','b', '6'], ['4', 'a', '6'], ['4', 'b', '6']] > > >> > > >> > > >> for x in List: > > >> temp=[] > > >> print x > > >> for y in List: > > >> if x[0]==y[0]: > > >> print y[0],y[1] > > >> temp.append(y) > > >> for z in temp: > > >>List.remove(z) > > >> print 'rem', z > > > > > > the for loop uses an internal index to fetch items from the list you're > > > looping over, so if you remove items from it, you'll end up skipping > > > over items. > > > > forgot to mention that the fix is to change the first for statement to: > > > > for x in List[:]: > > > > > Thanx Fredrik Lundh for ur response. I tried ur fix But the output i am > getting is repeated. > > for x in List[:]: > t2=[] > print x[0] > for y in List: > if x[0]==y[0]: > print y[1],y[2] > t2.append(y) > > for z in t2: > List[:].remove(z) > > The output i am getting is now is: > > 1 > a 6 > b 6 > c 6 > d 6 > > 1 > a 6 > b 6 > c 6 > d 6 > > 1 > a 6 > b 6 > c 6 > d 6 > 1 > a 6 > b 6 > c 6 > d 6 > > 2 > a 6 > b 6 > c 6 > d 6 > > 2 > a 6 > b 6 > c 6 > d 6 > > 2 > a 6 > b 6 > c 6 > d 6 > > 2 > a 6 > b 6 > c 6 > d 6 > > 3 > a 6 > b 6 > > 3 > a 6 > b 6 > > 4 > a 6 > b 6 > > 4 > a 6 > b 6 > > Can u show me where i am going wrong. Actually here in my code ['1', 'a', '6'], ['1', 'b', '6'], ['1', 'c', '6'] means: 1==> Directory name; a,b,c,d=== Filename 6 ==> modified time So i want the out put like: Directory name: 1 Filename:a modified time:6 Filename:b modified time:6 Filename:c modified time:6 and so on.. -- http://mail.python.org/mailman/listinfo/python-list
Re: Problem with List of List
Paul Rubin wrote: > "Kirt" <[EMAIL PROTECTED]> writes: > > Actually here in my code ['1', 'a', '6'], ['1', 'b', '6'], ['1', 'c', > > '6'] means: > > 1==> Directory name; > > a,b,c,d=== Filename > > 6 ==> modified time > > > > So i want the out put like: > > Directory name: 1 > > Filename:a > > modified time:6 > > Try writing the code in a style with fewer side effects. I like using > itertools.groupby for this type of thing (not exactly tested): > > from itertools import groupby > > List=[['1', 'a', '6'], ['1', 'b', '6'], ['1', 'c', '6'], > ['1', 'd', '6'],['2', 'a','6'], ['2', 'b', '6'], > ['2', 'c', '6'], ['2', 'd', '6'], ['3', 'a', '6'], > ['3','b', '6'], ['4', 'a', '6'], ['4', 'b', '6']] > > # retrieve directory name from one of those tuples > def directory_name(t): return t[0] > > for dirname,dir_contents in groupby(sorted(List), directory_name): > print 'Directory name:, dirname > for dname2,filename,modtime in dir_contents: > print 'Filename:%s\nmodified time:%s'% (filename, modtime) > > The output is: > > >>> ## working on region in file /usr/tmp/python-9013z7X... > Directory name: 1 > Filename:a > modified time:6 > Filename:b > modified time:6 > Filename:c > modified time:6 > Filename:d > modified time:6 > Directory name: 2 > Filename:a > modified time:6 > Filename:b > modified time:6 > Filename:c > modified time:6 > Filename:d > modified time:6 > Directory name: 3 > Filename:a > modified time:6 > Filename:b > modified time:6 > Directory name: 4 > Filename:a > modified time:6 > Filename:b > modified time:6 > >>> > > Is that what you wanted? Thanx Paul. Thats exactly what i wanted. ur piece of code has reduced my overall code by half. thanx again. -- http://mail.python.org/mailman/listinfo/python-list
File I/O
Hi! I need some help in file I/O I have an xml file.. xyz I want to open these file in append mode and add the line abd Such that i have: xyz xyz can anyone show me the way to achieve this?? thanx -- http://mail.python.org/mailman/listinfo/python-list
Re: File I/O
jimburton wrote:
> Kirt wrote:
> > Hi! I need some help in file I/O
> >
> > I have an xml file..
> [snip]
> See http://diveintopython.org/xml_processing/
i dont wanna parse the xml file..
Just open the file as:
f=open('test.xml','a')
and write a line "abc" before tag http://mail.python.org/mailman/listinfo/python-list
Re: File I/O
jimburton wrote:
> Kirt wrote:
> > Hi! I need some help in file I/O
> >
> > I have an xml file..
> [snip]
> See http://diveintopython.org/xml_processing/
i dont wanna parse the xml file..
Just open the file as:
f=open('test.xml','a')
and append a line "abc" before tag
--
http://mail.python.org/mailman/listinfo/python-list
