[Tutor] verify the email
hello here is my code for sending the mail, using this code email is going 'CODE '' import smtplib from time import strftime from email.mime.multipart import MIMEMultipart from email.mime.text import MIMEText from email.Utils import COMMASPACE, formatdate # Create message container - the correct MIME type is multipart/alternative. msg = MIMEMultipart('alternative') msg['Subject'] = " is sending the mail" msg['From'] = 'jitu.ic...@domain.com' msg['Date'] = formatdate(localtime=True) msg['To'] = 'jitu.ic...@gmail.com' # Create the body of the message (a plain-text and an HTML version). #text = "jitendra kya huy a!\nHow are you?\nHere is the link you wanted:\nhttp://www.python.org"; html = """\ Hi! How are you? This mail is send by wjitenrda Here is the http://www.python.org";>link you wanted. """ part2 = MIMEText(html, 'html') msg.attach(part2) # Send the message via local SMTP server. s = smtplib.SMTP('smtp.domain name.com') s.login("user","password") s.sendmail(msg['From'], msg['To'], msg.as_string()) s.close() 'CODE END '' using this code i am able to send the email , but problem is when i am changing msg['To'] = "wrongu...@wrongdomain.comddsdjsdsdsjdh" some wrong email then i am getting back failure notice in my inbox, which i dont want.. is there any way so that i can identify wrong email during the run time (when i am sending the email) ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] confusing enumerate behavior
On Fri, Feb 6, 2009 at 5:43 AM, Emad Nawfal (عماد نوفل) wrote: > Hi Tutors, > I'm a little, actually a lot confused by the behavior of the enumerate > function here. I have a text and I want to get each word within the context > of the three preceding and the three following words. I tried this: > #BEGIN > my_input = "one two three four five six seven eight nine ten" > text = my_input.split() > for i,v in enumerate(text): > line = text[i-3], text[i-2], text[i-1], v, text[i+1], text[i+2], > text[i+3] > print line > # END > The ouput was not as I expected. It did not start from the beginning > (actually I had expected it to throw and exception immediately) > ('eight', 'nine', 'ten', 'one', 'two', 'three', 'four') > ('nine', 'ten', 'one', 'two', 'three', 'four', 'five') > ('ten', 'one', 'two', 'three', 'four', 'five', 'six') > ('one', 'two', 'three', 'four', 'five', 'six', 'seven') > ('two', 'three', 'four', 'five', 'six', 'seven', 'eight') > ('three', 'four', 'five', 'six', 'seven', 'eight', 'nine') > ('four', 'five', 'six', 'seven', 'eight', 'nine', 'ten') > Traceback (most recent call last): > File "enumerate.py", line 13, in > line = text[i-3], text[i-2], text[i-1], v, text[i+1], text[i+2], > text[i+3] > IndexError: list index out of range > e...@emad-laptop:~/Desktop$ > > I then though of adding dummy words to the beginning and the end and exclude > them later like this: > #BEGIN > my_input = "one two three four five six seven eight nine ten" > > text2 = " nothing " *6 + my_input + " nothing "* 6 > > text2 = text2.split() > for i,v in enumerate(text2[6:-6]): > line = text2[i-3], text2[i-2], text2[i-1], v, text2[i+1], text2[i+2], > text2[i+3] > print line > #END > > The output this time was even more confusing: > e...@emad-laptop:~/Desktop$ python enumerate.py > ('nothing', 'nothing', 'nothing', 'one', 'nothing', 'nothing', 'nothing') > ('nothing', 'nothing', 'nothing', 'two', 'nothing', 'nothing', 'nothing') > ('nothing', 'nothing', 'nothing', 'three', 'nothing', 'nothing', 'nothing') > ('nothing', 'nothing', 'nothing', 'four', 'nothing', 'nothing', 'one') > ('nothing', 'nothing', 'nothing', 'five', 'nothing', 'one', 'two') > ('nothing', 'nothing', 'nothing', 'six', 'one', 'two', 'three') > ('nothing', 'nothing', 'nothing', 'seven', 'two', 'three', 'four') > ('nothing', 'nothing', 'one', 'eight', 'three', 'four', 'five') > ('nothing', 'one', 'two', 'nine', 'four', 'five', 'six') > ('one', 'two', 'three', 'ten', 'five', 'six', 'seven') > > Can somebody please explain what is going on here? Have I done something > wrong? How can this be fixed? > > Thanks in anticipation, > Emad > > ___ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor > > hello Emad Try this if u r looking for this kind of solution >>>my_input = "one two three four five six seven eight nine ten" >>>text = my_input.split() >>>for i in range(len(text)): if i+3>=len(text): print text[i-3:len(text):1] elif i<=2: print text[0:i+4] else: print text[i-3:i+4] Output is... ['one', 'two', 'three', 'four'] ['one', 'two', 'three', 'four', 'five'] ['one', 'two', 'three', 'four', 'five', 'six'] ['one', 'two', 'three', 'four', 'five', 'six', 'seven'] ['two', 'three', 'four', 'five', 'six', 'seven', 'eight'] ['three', 'four', 'five', 'six', 'seven', 'eight', 'nine'] ['four', 'five', 'six', 'seven', 'eight', 'nine', 'ten'] ['five', 'six', 'seven', 'eight', 'nine', 'ten'] ['six', 'seven', 'eight', 'nine', 'ten'] ['seven', 'eight', 'nine', 'ten'] Jitendra Kumar Hyderabad ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Unit test case
Hi, I am working one tool, which will do compile/run the workspace (that code is written on c/c++). on that my requirment is i need to compile subfolder also, i have wrote code for that also. My problem is , i am unable to write the Unit test case for that. Since my method (called run_subfolder) is not retrurning any thing (this will create one command line argument in that i am adding subfolder condition and passing to the another class which will do actual thing) . For this method i need to write unit test case. Since i dont have to workspace also , so that i can test this case . Please advise on this. what i need to do. this is possible or not, if not why. Some forum suggested use mox. but i dont have more idea on this . in mox how i will get thet output of the function Thanks Jitendra Kumar ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] Unit test cases for Object intraction using mox/unittest
Hi I need to write the unit test cases for similary kind of sitution. I need to write the unit test case for Foo.testCall. for both case true or false. I am unalbe to do that. kindly please help me on this. as function is not returning any thing. from google i got mox is good for this case. but i did not found any solution for this case ** Enter.py from run import RunComp def enter(): runC = RunComp("ComName", "~/pathToHome") """ This is based on some database condition we are passing name true or false """ foo = Foo(true) foo.testCall(runC) if __name__ == "__main__": enter() ** * foo.py Class Foo(): def __init__(self, found): self.found = found def testCall(self, SomeClassObject): if self.found: RunCompObject.call_run("codeRun -s " + self.found) else: RunCompObject.call_run("codeRun") * ** run.py ** from subprocess import call class RunComp(object): def __init__(self, com, home): self.comp = comp self.home = home def call_and_raise(*args, **kwargs): if call(*args, **kwargs): raise RuntimeError("LDF command failed!") def call_run(self, command): if self.comp: command = " ".join((command,myldfrc)) call(command, cwd=self.home) * Thanks & Regards Jitu ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] xml parsing from xml
Hi I just want to create a new xm file from existing xml file. so basically i want to put contry details in countryName.xml from these file. I thought to do via read a line by line with normal file handling. but there a problem with that. So i want to handle python XML . Could you please suggest on this. Any Idea is welcome Thanks & regards Jitendra 2 2008 141100 5 2011 59900 69 2011 13600 ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] xml parsing from xml
@All thanks, I cant use etree/SAX because there we cant get complete line , of course we can get it by tag name but we are not sure about tag also. Only we know what ever child of we need to put in new file with country name. Note: File size is around 800MB, for other requirement(Like converting xml to csv) i used lxml/others. but in my current scenario i dont know what child tag will be there . ## INPUT XML ### 2 2008 141100 ... ... 69 2011 13600 outputxml (Liechtenstein.xml) ## 2 2008 141100 ... ... # # 69 2011 13600 On Thu, May 8, 2014 at 1:19 AM, Stefan Behnel wrote: > Neil D. Cerutti, 07.05.2014 20:04: > > On 5/7/2014 1:39 PM, Alan Gauld wrote: > >> On 07/05/14 17:56, Stefan Behnel wrote: > >>> Alan Gauld, 07.05.2014 18:11: > and ElementTree (aka etree). The documenation gives examples of both. > sax is easiest and fastest for simple XML in big files ... > >>> > >>> I wouldn't say that SAX qualifies as "easiest". Sure, if the task is > >>> something like "count number of abc tags" or "find tag xyz and get an > >>> attribute value from it", then SAX is relatively easy and also quite > >>> fast. > >> > >> That's pretty much what I said. simple task, big file. sax is easy. > >> > >> For anything else use etree. > >> > >>> BTW, ElementTree also has a SAX-like parsing mode, but comes with a > >>> simpler interface and saner parser configuration defaults. > >> > >> My experience was different. Etree is powerful but for simple > >> tasks I just found sax easier to grok. (And most of my XML parsing > >> is limited to simple extraction of a field or two.) > > > > If I understand this task correctly it seems like a good application for > > SAX. As a state machine it could have a mere two states, assuming we > aren't > > troubled about the parent nodes of Country tags. > > Yep, that's the kind of thing I meant. You get started, just trying to get > out one little field out of the file, then notice that you need another > one, and eventually end up writing a page full of code where a couple of > lines would have done the job. Even just safely and correctly getting the > text content of an element is surprisingly non-trivial in SAX. > > It's still unclear what the OP wanted exactly, though. To me, it read more > like the task was to copy some content over from one XML file to another, > in which case doing it in ET is just trivial thanks to the tree API, but > SAX requires you to reconstruct the XML brick by brick here. > > > > In my own personal case, I partly prefer xml.sax simply because it > ignores > > namespaces, a nice benefit in my cases. I wish I could make ElementTree > do > > that. > > The downside of namespace unaware parsing is that you never know what you > get. It works for some input, but it may also just fail arbitrarily, for > equally valid input. > > One cool thing about ET is that it makes namespace aware processing easy by > using fully qualified tag names (one string says it all). Most other XML > tools (including SAX) require some annoying prefix mapping setup that you > have to carry around in order to tell the processor that you are really > talking about the thing that it's showing to you. > > Stefan > > ___ > Tutor maillist - Tutor@python.org > To unsubscribe or change subscription options: > https://mail.python.org/mailman/listinfo/tutor > ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] xml parsing from xml
no only XML (Complex) On Thu, May 8, 2014 at 1:51 AM, Danny Yoo wrote: > On Wed, May 7, 2014 at 6:13 AM, jitendra gupta > wrote: > > > I just want to create a new xm file from existing xml file. so basically > i > > want to put contry details in countryName.xml from these file. > > > > Side question: does your input have to be XML, or can it be in a > simpler format such as JSON? > ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Help with Python
Hi This will solve your purpose: Yes we can write in better way also : -- #The Dice Game #add libraries needed import random #the main function def main(): print #initialize variables playerOne = 'No Name' playerTwo = 'No Name' endProgram ="no" #call to inputNames playerOne, playerTwo = inputNames(playerOne, playerTwo) #while loop to run program again while endProgram == 'no': #call to rollDice winnersName = rollDice(playerOne, playerTwo) #call to displayInfo print "Winner is ", winnersName endProgram = raw_input('Do you want to end program? (Enter yes or no): ') #this function gets the players names def inputNames(playerOne, playerTwo): playerOne = raw_input("Enter Name") playerTwo = raw_input("Enter Name") return playerOne, playerTwo #this function will get the random values def rollDice(playerOne, playerTwo): p1number = random.randint(1, 6) p2number = random.randint(1, 6) #this function displays the winner if p1number == p2number: winnerName = "TIE" elif p1number > p2number: winnerName = playerOne else: winnerName = playerTwo return winnerName if __name__ == "__main__": # calls main main() On Sun, May 11, 2014 at 8:46 AM, Glen Chan wrote: > Hello, I am a student trying to figure out Python. I am getting errors > that I don't know how to fix. What do you do after you get the error > message and something is highlighted? Does that have to be deleted? Anyway, > here is what I mean... > > > #>>> The Dice Game > #add libraries needed > import random > #the main function > def main(): > print > #initialize variables > playerOne = 'No Name' > playerTwo = 'No Name' > > #call to inputNames > playerOne, playerTwo = inputNames(playerOne, playerTwo) > #while loop to run program again > while endProgram == 'no': > #initialize variables > winnersName = 'NO NAME' > p1number = 0 > p2number = 0 > #call to rollDice > winnerName = rollDice(p1number, p2number, playerOne, playerTwo, > winnerName) > > #call to displayInfo > winnerName > endProgram = raw_input('Do you want to end program? (Enter yes or > no): ') > > > > #this function gets the players names > def inputNames(playerOne, playerTwo): > playerOne = raw_input("Enter Name") > playerTwo = raw_input("Enter Name") > > return playerOne, playerTwo > #this function will get the random values > def rollDice(p1numer, p2numer, playerOne, playerTwo, winnerName): > p1number = random.randint(1, 6) > p1number = random.randint(1, 6) > > #this function displays the winner > > if p1number == p2number: > winnerName = "TIE" > elif p1number > p2number: > winnerName = playerOne > else: > winnerName = playerTwo > return winnerName > > # calls main > main() > > > ___ > Tutor maillist - Tutor@python.org > To unsubscribe or change subscription options: > https://mail.python.org/mailman/listinfo/tutor > > ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
[Tutor] Error Handling in python
Hi All My shell script is not throwing any error when I am having some error in Python code. test.py ~~ def main(): print "Test" #some case error need to be thrown raise Exception("Here is error") if __name__ == "__main__" main() ~~ second.py ~~ def main(): print "Second function is called" if __name__ == "__main__" main() ~~ ~ shellTest.sh ~~~ python test.py python second.py ~~~ In this case, I dont want to run my second.py Even I am throwing error from my test.py, but still second.py is getting executed, which i dont want, Thanks & Regards Jitendra ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Error Handling in python
@All Thanks a lot, Yes "set -e" It work fine. This is what I am looking for but I got some extra things to learn :) . Thanks you again Thanks Jitendra On Thu, Jul 24, 2014 at 6:10 PM, Wolfgang Maier < wolfgang.ma...@biologie.uni-freiburg.de> wrote: > On 24.07.2014 14:37, Chris “Kwpolska” Warrick wrote: > >> >> It’s recommended to switch to the [[ syntax anyways, some people >> consider [ deprecated. Also, [ is actually /bin/[ while [[ lives in >> your shell (and is therefore faster). >> >> About the equals sign, == is the preferred syntax, and = is also >> considered deprecated (zsh explicitly says so, bash says “only for >> POSIX compatibility”. >> >> > I see. There is always something to learn, thanks (even if it's not > Python-related as Steven points out correctly) :) > > > ___ > Tutor maillist - Tutor@python.org > To unsubscribe or change subscription options: > https://mail.python.org/mailman/listinfo/tutor > ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor