[Tutor] Tutor Digest, Vol 61, Issue 42

Samuel Avinash samuelavinash at in.com
Wed Mar 11 13:22:06 CET 2009


 Reply to Message 3 : How can I extract a specific sublist from a nested list?Comments Inline Original message From:tutorrequest at python.org< tutorrequest at python.org >Date: 11 Mar 09 12:12:51Subject:Tutor Digest, Vol 61, Issue 42To: tutor at python.orgSend Tutor mailing list submissions to tutor at python.orgTo subscribe or unsubscribe via the World Wide Web, visit http://mail.python.org/mailman/listinfo/tutor or, via email, send a message with subject or body 'help' to tutorrequest at python.orgYou can reach the person managing the list at tutorowner at python.orgWhen replying, please edit your Subject line so it is more specific than "Re: Contents of Tutor digest..." Today's Topics: 1. Re: memory error files over 100MB (Alan Gauld)2. Re: memory error files over 100MB (Lie Ryan)3. How can I extract a specific sublist from a nested list? (Emad Nawfal (???? ????))4. Issues Parsing XML (marc at marcd.org)5. Re: How to send an email using Python (Senthil Kumaran)6. Re: How to send an email us
 ing Python (Stefan Lesicnik) Message: 1 Date: Wed, 11 Mar 2009 01:20:58 0000 From: "Alan Gauld"Subject: Re: [Tutor] memory error files over 100MB To: tutor at python.org MessageID:ContentType: text/plain; format=flowed; charset="utf8"; replytype=original "Sander Sweers"wrote>> out again in a single operation, that will use twice the space of>> the >> uncompressed files  plus some extra for overhead. > > Question, Do you mean the file in the zipfile (zfilename) or the> whole > zipfile (zf)? I would expect zf.read(zfilename) to only read the > requested file in the zipfile.That's a dangerous assumption. You might be right but I'd want to do some tests first to see. But if even one zipped file was big the same would apply.Alan G.Message: 2 Date: Wed, 11 Mar 2009 12:26:16 +1100 From: Lie RyanSubject: Re: [Tutor] memory error files over 100MB To: tutor at python.org MessageID:ContentType: text/plain; charset=UTF8; format=flowedSander Sweers wrote: > 2009/3/10 Alan Gauld : >>> newFile.w
 rite(zf.read(zfilename)) >> Remember you are reading the file into memory and then writing it >> out again in a single operation, that will use twice the space of the >> uncompressed files  plus some extra for overhead. >> Question, Do you mean the file in the zipfile (zfilename) or the whole > zipfile (zf)? I would expect zf.read(zfilename) to only read the > requested file in the zipfile.I've never used zipfile extensively, but I think it depends on thearchive and the compression algorithm. Solid archive (multiple filescompressed as a single big file) may need to be fully extracted, exceptif the algorithm can somehow figure out a way of extracting a singlefile from a solid archive without extracting everything first.Message: 3 Date: Tue, 10 Mar 2009 21:44:30 0400 From: Emad Nawfal (???? ????)Subject: [Tutor] How can I extract a specific sublist from a nested list? To: tutorMessageID:ContentType: text/plain; charset="windows1256"Hi Tutors, How can I extract a specific subli
 st (??) from a nested list, for example, if I want to extract the sublist ["ADJ", "good"], or the bigger sublist ["NP",["DET", "The"],["ADJ", "good"],["NOUN", "man"]] from the following nested list?nestedlist = ["S",["NP",["DET", "The"],["ADJ", "good"],["NOUN", "man"]], ["VP", ["V", "came"]]]?? ???? ?????? ????? ????? ??? ???? ??? ????? ?? ?????? ????????.....???? ???????>>> x=nestedlist[1]>>> x['NP', ['DET', 'The'], ['ADJ', 'good'], ['NOUN', 'man']]>>> x[2]['ADJ', 'good']>>>  "No victim has ever been more repressed and alienated than the truth"Emad Soliman Nawfal Indiana University, Bloomington  next part  An HTML attachment was scrubbed... URL: Message: 4 Date: Tue, 10 Mar 2009 19:02:21 0400 (EDT) From: marc at marcd.org Subject: [Tutor] Issues Parsing XML To: tutor at python.org MessageID:ContentType: text/plain;charset=iso88591Hello,I am new to Python and as a first project decided to try to parse an XML report using Python.I have the following, which works to extract one ele
 ment.I am stuck, however, at one element.I want to extract several differenct elements per line, creating a comma separated variable (CSV) line that can be imported to a spreadsheet.Not all elements are in each line or part of the XML document  so if an element is not in a line, I would leave a blank (2 commas).I can probably figure that out  it's the extracting multiple elements and putting them in one line that has me stumped.Help would be greatly appreciated.Thank you.What I have so far (and I would like to stick to the DOM model):import xml.dom.minidom import sys datasource=open(sys.argv[1]) domDatasource=xml.dom.minidom.parse(datasource)def getText(nodelist): rc="" for node in nodelist: if node.nodeType == node.TEXTNODE: rc=rc+node.data return rcdef HandleStatus(Finding): for Status in Finding: print getText(Status.childNodes)HandleStatus (domDatasource.getElementsByTagName("FINDINGSTATUS"))domDatasource.unlink()An excerpt of the xml file:GD2.0.8.8TRUEDTBI134Allow paste
  operations via scriptsRestric2 TYPE="VK">V0006310NFGD2.0.8.8TRUEDTBI135Scripting of Java applets  Restricted2 TYPE="VK">V0006311O OVERRIDE="O">The value: Software\Policies\Microsoft\Windows\CurrentVersion\Internet Settings\Zones\4\1A00 does not exist.The value: Software\Policies\Microsoft\Windows\CurrentVersion\Internet Settings\Zones\4\1A00 does not exist.GD2.0.8.8TRUEDTBI136User Authentication  Logon  Restricted2 TYPE="VK">V0006312NFGD2.0.8.8TRUEDTBI150Microsoft Java VM is installed2 TYPE="VK">V0006313NFGD2.0.8.8TRUEDTBI151Cipher setting for DES 56/56 not set2 TYPE="VK">V0006314NFGD2.0.8.8TRUEDTBI152Cipher setting for Null is not set2 TYPE="VK">V0006315NFGD2.0.8.8TRUEDTBI153Cipher setting for Triple DES is not set2 TYPE="VK">V0006316O OVERRIDE="O">The value: SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Hashes\SHA\Enabled does not exist.The value: SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Hashes\SHA\Enabled does not exist.GD2.0.8.8TRUEDTBI1
 60Hash setting for SHA is not set properly2 TYPE="VK">V0006317NFGD2.0.8.8TRUEDTBG007IE is not capable to use 128bit encryptio2 TYPE="VK">V0006318O OVERRIDE="O">The key: SOFTWARE\Microsoft\SystemCertificates\Root\Certificates\10F193F340AC91D6DE5F1EDC006247C4F25D9671 does not exist.The key: SOFTWARE\Microsoft\SystemCertificates\Root\Certificates\10F193F340AC91D6DE5F1EDC006247C4F25D9671 does not exist.GD2.0.8.8TRUEDTBG010DoD Root Certificate is not installed2 TYPE="VK">V0006319NAGD2.0.8.8TRUEDTBI140Error Reporting tool is installed or enabl2 TYPE="VK">V0007006O OVERRIDE="O">The value: Software\Microsoft\Internet Explorer\Main\AutoSearch does not exist.The value: Software\Microsoft\Internet Explorer\Main\AutoSearch does not exist.Message: 5 Date: Wed, 11 Mar 2009 09:58:53 +0530 From: Senthil KumaranSubject: Re: [Tutor] How to send an email using Python To: Samuel AvinashCc: tutorMessageID:ContentType: text/plain; charset=UTF8Hello Samuel,When sending through smtp.gmail.com you m
 ight need to starttls() and do a login() before sending.>>> import smtplib >>> headers = "From: %s\r
To: %s\r
Subject: %s\r
\r
" %(from,to,subject) >>> message = headers + "Hello, How are you?" >>> mailserver = smtplib.SMTP('smtp.gmail.com') >>> mailserver.ehlo() >>> mailserver.starttls() >>> mailserver.login('username','password') >>> mailserver.sendmail(from,to,message)As I try it now, startls() was giving me a message " reply: '454 TLS not available due to temporary reason\r
'"  As the error message says, it could be temporary.Try it at your end and report if you succeed.Thanks, SenthilOn Tue, Mar 10, 2009 at 4:41 PM, Samuel Avinashwrote: > Hi, > Can anybody tell me how to send an email to a recipient using Python > I am trying to send an email using Gmail > I create an instance of ?smtplib and use : > x=smtplib.SMTP(sever,port) > and then > x.login(user,pwd) > I try to send the email using > x..sendmail(SENDER, RECIPIENTS, msg) > But I get the following error > Traceback (most recent call last): > File "C:UsersAvisDesktopMail.py", line 13, in> session = smtplib.SMTP(smtpserver,port) > File "C:Python26libsmtplib.py", line 239, in init > (code, msg) = self.connect(host, port) > File "C:Python26libsmtplib.py", line 295, in connect > self.sock = self.getsocket(host, port, self.timeout) > File "C:Python26libsmtplib.py", line 273, in getsocket > return socket.createconnection((port, host), timeout) > File "C:Python26libsocket.py", line 498, in createc
 onnection > for res in getaddrinfo(host, port, 0, SOCKSTREAM): > socket.gaierror: [Errno 11001] getaddrinfo failed > > This is in Windows Vista and I am trying to connect to "smtp.gmail.com" with > port 465 >  > Tutor maillist ? ?Tutor at python.org > http://mail.python.org/mailman/listinfo/tutor > >Senthil Message: 6 Date: Wed, 11 Mar 2009 08:42:45 +0200 From: Stefan LesicnikSubject: Re: [Tutor] How to send an email using Python To: Senthil KumaranCc: Samuel Avinash , tutorMessageID:ContentType: text/plain; charset=ISO88591Hi.I use the following to send through gmail. message = headers + text mailserver = smtplib.SMTP('smtp.gmail.com') if debug == 1: mailserver.setdebuglevel(1) mailserver.ehlo() mailserver.starttls() mailserver.ehlo()#Define username / password if using SMTP Auth username = 'email at gmail.com' password = getpass.getpass("%s's password: " % username)mailserver.login(username,password) mailserver.sendmail(sender, to, message) mailserver.close() I believe for gmail
  smtp you need the ehlo() and then the starttls() and then another ehlo(). My first post, been lurking a while.:) On Wed, Mar 11, 2009 at 6:28 AM, Senthil Kumaranwrote: > Hello Samuel, > > When sending through smtp.gmail.com you might need to starttls() and > do a login() before sending. > >>>> import smtplib >>>> headers = "From: %s\r
To: %s\r
Subject: %s\r
\r
" %(from,to,subject) >>>> message = headers + "Hello, How are you?" >>>> mailserver = smtplib.SMTP('smtp.gmail.com') >>>> mailserver.ehlo() >>>> mailserver.starttls() >>>> mailserver.login('username','password') >>>> mailserver.sendmail(from,to,message) > > As I try it now, startls() was giving me a message " reply: '454 TLS > not available due to temporary reason\r
'" >  As the error message says, it could be temporary. > > Try it at your end and report if you succeed. > > Thanks, > Senthil > > On Tue, Mar 10, 2009 at 4:41 PM, Samuel Avinashwrote: >> Hi, >> Can anybody tell me how to send an email to a recipient using Python >> I am trying to send an email using Gmail >> I create an instance of ?smtplib and use : >> x=smtplib.SMTP(sever,port) >> and then >> x.login(user,pwd) >> I try to send the email using >> x..sendmail(SENDER, RECIPIENTS, msg) >> But I get the following error >> Traceback (most recent call last): >> File "C:UsersAvisDesktopMail.py", line 13, in>> session = smtplib.SMTP(smtpserver,port) >> File "C:Python26libsmtplib.py", line 239, in init >> (code, msg) = self.connect(host, port) >> File "C:Python26libsmtplib.py", line 295, in connect >> self.sock = self.getsocket(host, port, self.timeout) >> File "C:Python26libsmtplib.py", line 273, in getsocket >> return socket.createconnection((port, host), timeout) >> File "C:Pyth
 on26libsocket.py", line 498, in createconnection >> for res in getaddrinfo(host, port, 0, SOCKSTREAM): >> socket.gaierror: [Errno 11001] getaddrinfo failed >> >> This is in Windows Vista and I am trying to connect to "smtp.gmail.com" with >> port 465 >>  >> Tutor maillist ? ?Tutor at python.org >> http://mail.python.org/mailman/listinfo/tutor >> >> > > > >  >  > Senthil >  > Tutor maillist ? ?Tutor at python.org > http://mail.python.org/mailman/listinfo/tutor >  Tutor maillistTutor at python.org http://mail.python.org/mailman/listinfo/tutor End of Tutor Digest, Vol 61, Issue 42 ************************************* 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20090311/34a23c09/attachment-0001.htm>


More information about the Tutor mailing list