Re: What XML lib to use?
You can try xml.dom and xml.sax. Both are inbuilt libraries with Python standard package. You can read and write xml files with these very easily. There are number of third party modules for Python that manipulate XML. But the above are the basic ones. -- http://mail.python.org/mailman/listinfo/python-list
Re: What XML lib to use?
You can try xml.dom and xml.sax. Both are inbuilt libraries with Python standard package. You can read and write xml files with these very easily. There are number of third party modules for Python that manipulate XML. But the above are the basic ones. -- http://mail.python.org/mailman/listinfo/python-list
How do I add users using Python scripts on a Linux machine
How do I add users using Python scripts on a Linux machine? Someone has a script? -- http://mail.python.org/mailman/listinfo/python-list
Re: How do I add users using Python scripts on a Linux machine
Well, I need to add users from a web interface for a web server, which runs only Python. I need to add users, set quotas and in future even look at managing ip tables to limit bandwidth. I know os.system(), but this has to be done through a form entry through a web interface. Anyways thanks, do advise if there more pythonic solutions Ramdas Hari Sekhon wrote: > That is shell scripting with a python layer on top. Is there a > specific reason you have to use python? Why not just use shell, that's > what it's designed for? Unless you have some complex maths/networking > requirement or something on top. > > -h > > On 01/01/07, Daniel Klein <[EMAIL PROTECTED]> wrote: > > On 1 Jan 2007 11:33:42 -0800, "Ramdas" <[EMAIL PROTECTED]> wrote: > > > > >How do I add users using Python scripts on a Linux machine? > > > > > >Someone has a script? > > > > This should be as easy as something like: > > > > os.system("/usr/sbin/useradd -m -d /home/newuser -s /bin/ksh") > > > > Dan > > -- > > http://mail.python.org/mailman/listinfo/python-list > > > > > -- > Hari Sekhon -- http://mail.python.org/mailman/listinfo/python-list
How do I trap errors in win32com.client?
How do I trap errors from win32com.client. I have tried the com_error classes from pywintypes and pythoncom sub modules. It is not catching for all cases. Is there any docs available? -- http://mail.python.org/mailman/listinfo/python-list
Any HTML to Latex module available in Python
Any HTML to Latex module available in Python which I can use to convert HTML text to Latex Ramdas -- http://mail.python.org/mailman/listinfo/python-list
creating color gradients using PIL
Any ideas how we can create a color gradient using Python Imaging Library. Has any got some sample code that can give me some idea. I need to create a horizontal and vertical color gradient for a college project Thanks -- http://mail.python.org/mailman/listinfo/python-list
Finding Line numbers of HTML file
I am doing some HTML scrapping for a side project. I need a method using sgmllib or HTMLParser to parse an HTML file and get line nos of all the tags I tried a few things, but I am just not able to work with either if the parsers. Can someone help -- http://mail.python.org/mailman/listinfo/python-list
Re: Finding Line numbers of HTML file
Hey paul, Thanks a Ton! Never heard of pyparsing module. This is more a hobby, than any homework. This is exactly what I wanted. I am scrapping a few web pages for data. I am using Beautiful Soup for tag extraction. However for some quirky reasons, I need to reference back to the exact line number. BS does not support line nos right now, and Richardson, says he will include the same in future. On Dec 13, 5:27 am, Paul McGuire <[EMAIL PROTECTED]> wrote: > On Dec 12, 3:56 pm, Ramdas <[EMAIL PROTECTED]> wrote:> I am doing some HTML > scrapping for a side project. > > > I need a method using sgmllib or HTMLParser to parse an HTML file and > > get line nos of all the tags > > Homework, perhaps? Well, I don't think your instructor will give many > points for a pyparsing solution, but it was an interesting 10-minute > exercise anyway. Once you use pyparsing's built-in expression for > anyOpenTag, and scan through the input html, the rest is just > bookkeeping in a defaultdict. > > -- Paul > > import urllib > from collections import defaultdict > from pyparsing import anyOpenTag, lineno > > # read in a random html page > pg = urllib.urlopen("http://www.yahoo.com";) > html = pg.read() > pg.close() > > # print out what we got > print html > print > > # create a defaultdict to tally up list of line numbers for each tag > tagLocs = defaultdict(list) > > # use a parse action to update the tally whenever a tag is found > def tallyTagLineNumber(strg, locn, tagTokens): > line = lineno(locn,strg) > tagLocs[tagTokens[0]].append(line) > anyOpenTag.setParseAction(tallyTagLineNumber) > > # scan the input html, and add tag line numbers to the tally dict > anyOpenTag.searchString(html) > > # print out the results > tagnames = sorted(tagLocs.keys()) > for t in tagnames: > print t, len(tagLocs[t]) > print tagLocs[t] > print > > --- > Prints: > > <... extracted HTML not shown...> > > a 46 > [54, 68, 96, 97, 98, 99, 110, 111, 112, 113, 114, 115, 116, 117, 120, > 121, 122, 123, 124, 125, 126, 127, 130, 131, 132, 133, 134, 135, 136, > 139, 140, 141, 142, 143, 150, 159, 160, 161, 162, 163, 164, 165, 166, > 168, 169, 170] > > b 5 > [91, 109, 119, 129, 138] > > base 1 > [6] > > body 1 > [17] > > br 34 > [91, 93, 93, 94, 110, 111, 112, 113, 114, 115, 116, 117, 120, 121, > 122, 123, 124, 125, 126, 127, 130, 131, 132, 133, 134, 135, 136, 139, > 140, 141, 142, 143, 167, 167] > > center 1 > [18] > > font 15 > [30, 36, 54, 68, 90, 96, 97, 98, 99, 109, 119, 129, 138, 158, 168] > > form 1 > [31] > > head 1 > [2] > > html 1 > [1] > > img 2 > [26, 150] > > input 5 > [32, 33, 34, 36, 37] > > meta 2 > [4, 5] > > spacer 26 > [21, 24, 47, 50, 52, 53, 55, 56, 58, 61, 64, 66, 67, 69, 70, 72, 79, > 82, 83, 89, 101, 104, 146, 148, 156, 157] > > span 1 > [39] > > style 2 > [7, 12] > > table 26 > [19, 21, 29, 30, 35, 46, 49, 54, 63, 68, 79, 82, 83, 84, 87, 88, 95, > 106, 107, 108, 146, 148, 149, 156, 157, 158] > > td 58 > [20, 21, 24, 25, 28, 29, 30, 36, 37, 45, 47, 48, 50, 52, 53, 54, 54, > 55, 56, 58, 61, 62, 64, 66, 67, 68, 68, 69, 70, 72, 78, 79, 82, 83, > 86, 87, 89, 90, 96, 97, 98, 99, 101, 104, 105, 106, 107, 109, 119, > 129, 138, 146, 148, 149, 156, 157, 157, 158] > > title 1 > [3] > > tr 37 > [20, 21, 23, 29, 30, 35, 44, 46, 49, 51, 54, 57, 63, 65, 68, 71, 78, > 79, 82, 83, 85, 87, 88, 96, 97, 98, 99, 106, 107, 108, 146, 148, 149, > 156, 157, 157, 158] -- http://mail.python.org/mailman/listinfo/python-list
Re: Finding Line numbers of HTML file
Hi Paul, I am cross posting the same to grab your attention at pyparsing forums too. 1000 apologies on the same count! I am a complete newbie to parsing and totally new to pyparsing. I have adapted your code to store the line numbers as below. Surprisingly, the line numbers printed, when I scrap some of the URLs, is not accurate and is kind of way off. page = urlli2b.urlopen("www.com).read() def tallyTagLineNumber(strg, locn, tagTokens): line = lineno(locn,strg) tagLocs[tagTokens[0]].append(line) def getlinenos(page): anyOpenTag.setParseAction(tallyTagLineNumber) anyOpenTag.searchString(page.lower()) # changing the entire string to lower case to get INPUT tagnames = sorted(tagLocs.keys()) taglinedict={} for t in tagnames: taglinedict[t]= unique(tagLocs[t]) return taglinedict -- http://mail.python.org/mailman/listinfo/python-list
Re: Finding Line numbers of HTML file
Hi Paul, I am cross posting the same to grab your attention at pyparsing forums too. 1000 apologies on the same count! I am a complete newbie to parsing and totally new to pyparsing. I have adapted your code to store the line numbers as below. Surprisingly, the line numbers printed, when I scrap some of the URLs, is not accurate and is kind of way off. page = urlli2b.urlopen("www.com).read() def tallyTagLineNumber(strg, locn, tagTokens): line = lineno(locn,strg) tagLocs[tagTokens[0]].append(line) def getlinenos(page): anyOpenTag.setParseAction(tallyTagLineNumber) anyOpenTag.searchString(page.lower()) # changing the entire string to lowercase, to grab # input and INPUT from html as input tag ONLy tagnames = sorted(tagLocs.keys()) taglinedict={} for t in tagnames: taglinedict[t]= unique(tagLocs[t]) return taglinedict What did I do wrong and why this problem! Ramdas -- http://mail.python.org/mailman/listinfo/python-list
Re: string payload expected: error
On Nov 27, 2:39 am, Lie Ryan wrote: > Ramdas wrote: > > Dear all, > > > I believe this is an error which was fixed in Python 2.3 itself. But I > > am running Python 2,5.2 and error keeps on cropping up. > > > Here is my code to construct emails . It works perfectly when I dont > > have any attachments. Please find my code at > > >http://dpaste.com/hold/125574/ > > > However when I try constructing with attachments it crashes with this > > error string payload expected: error. > > Except if the traceback is due to a recursive function that doesn't > terminate, please always post the FULL traceback. Don't summarize the > error message. > > > Going through the trace error I discover that as I call the function > > msg.as_string, the function . _handle_text(self, msg) expects a string > > object but I am generating list object. Can someone advise what I need > > to code to parse series of attachments into an email. > > > Help appreciated > > I smell this part of the code as particularly fishy: > > msg1 = MIMEBase(maintype, subtype) > msg1.set_payload(MIMEText(fp.read())) > > why are you wrapping a MIMEText inside a MIMEBase? I tried with MIMEBASE but it still fails.. I changed it to MIMEText, hoping that might trick __handletext to think its a string Anyway that also doesn't work. Any ideas -- http://mail.python.org/mailman/listinfo/python-list
string payload expected: error
Dear all, I believe this is an error which was fixed in Python 2.3 itself. But I am running Python 2,5.2 and error keeps on cropping up. Here is my code to construct emails . It works perfectly when I dont have any attachments. Please find my code at http://dpaste.com/hold/125574/ However when I try constructing with attachments it crashes with this error string payload expected: error. Going through the trace error I discover that as I call the function msg.as_string, the function . _handle_text(self, msg) expects a string object but I am generating list object. Can someone advise what I need to code to parse series of attachments into an email. Help appreciated -- http://mail.python.org/mailman/listinfo/python-list
Re: string payload expected: error
On Nov 27, 1:33 am, MRAB wrote: > Ramdas wrote: > > Dear all, > > > I believe this is an error which was fixed in Python 2.3 itself. But I > > am running Python 2,5.2 and error keeps on cropping up. > > > Here is my code to construct emails . It works perfectly when I dont > > have any attachments. Please find my code at > > >http://dpaste.com/hold/125574/ > > > However when I try constructing with attachments it crashes with this > > error string payload expected: error. > > > Going through the trace error I discover that as I call the function > > msg.as_string, the function . _handle_text(self, msg) expects a string > > object but I am generating list object. Can someone advise what I need > > to code to parse series of attachments into an email. > > > Help appreciated > > I've been looking at the example in the Python 2.6.2 documentation. It > looks like you should have: > > msg1.add_header('Content-Disposition', 'attachment', filename=filename) Thanks! I did that correction, however the error still persists . -- http://mail.python.org/mailman/listinfo/python-list