Re: [Tutor] Trying to enter text from a file to a Dictionary
Hi Bob, > "list comprehension" (once understood) is often easier to read and more > efficient than the for loop. They are often more efficient but I don't know if I'd ever claim they were easier to read than an explicit for loop. Perhaps the most trivial cases like z = [x*2 for x in L] and even then I'm not sure that is easier to read than z = [] for x in L: z.append(x*2) And personally I still find map() easier for those cases z = map(lambda x: x*2, L) But you do need to be comfortable with lambda for that, and lambda is just as hard to grok as list comprehensions! :-) Alan G. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Trying to enter text from a file to a Dictionary
Alan Gauld wrote: > Hi Bob, > > >>"list comprehension" (once understood) is often easier to read and more >>efficient than the for loop. > > > They are often more efficient but I don't know if I'd ever claim they were > easier to read than an explicit for loop. Perhaps the most trivial cases > like > > z = [x*2 for x in L] > > and even then I'm not sure that is easier to read than > > z = [] > for x in L: z.append(x*2) I find simple list comps far easier to read and write than the equivalent for loop, and they fit the way I think about problems - I will think, "I need a list of the squares of everything in L." This matches exactly the order of elements in a list comp. Personally I avoid using list comps purely for the side effects, to me that breaks the conceptual "I need a list...". I admit that some of the most unreadable one-liners on comp.lang.python use list comps in creative ways...I write out the loop rather than going to contortions to make an expression I can use in a list comp. I don't see the point in twistng the code to fit it into a list comp. Kent ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] remove from mailing list
please remove [EMAIL PROTECTED] from the mailing list! thank you ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] beginner
iam beginner, Iam try to use pyhon What should I do to understhand python langguage, thanks ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Iam beginner
Hallo my name is tony iam from indonesia, Iam beginer iam try use python for my music program via athenaCL. what should I so, to understhand python langguage ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] remove from mailing list
[kristi holsinger] > please remove [EMAIL PROTECTED] from the mailing list! thank you This is self-service. You need to go to http://mail.python.org/mailman/listinfo/tutor and unsubscribe youself (look for the "Unsubscribe or edit options" button near the bottom of the page). ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Trying to enter text from a file to a Dictionary
On Sat, 28 Jan 2006, Kent Johnson wrote: > I find simple list comps far easier to read and write than the > equivalent for loop, and they fit the way I think about problems... I don't know if my experience is typical, but I found list comprehensions difficult to get. There's something, maybe about the syntax, that my intuition resists. Once I got it, though -- after maybe three attempts -- it stuck very well, and I like them better than their equivalent for-loops. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] beginner
tony wrote: > iam beginner, Iam try to use pyhon What should I do to understhand > python langguage, thanks The Beginners Guide has some suggestions: http://wiki.python.org/moin/BeginnersGuide Kent ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Off-topic query for rur-ple users
Please, accept my apologies to bring this slightly off-topic question. This is the only way I know to reach RUR-PLE users. How important is it to have a browser included within rur-ple itself? Would there be any objections in eliminating the browser, and using your favourite browser (firefox, etc.) to read the lessons in a separate window? You may want to send your reply directly to me (return address should be part of the message; if not: andre dot roberge at gmail dot com) so as to not "pollute" induly this list. Thanks, André P.S. Just a note about the fact that this is not *completely* off-topic for this list: the PLE in RUR-PLE stands for Python Learning Environment. It is designed for learning Python for people that don't know anything about programming (hence the post to the python-tutor list). It has been used by some teachers in a classroom environment (hence the post to the edu-sig list). It has been very strongly inspired by Guido van Robot (hence the post to the gvr-devel list) and has served as the basis of the world-builder module now included with GvR. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] email-sending..
Hello,i am trying to send emails through a python script , but it complains thatsocket error 10061 conection refused..any help with this would be great...import smtplibsmtpserver = 'mailserver'AUTHREQUIRED = 1 # if you need to use SMTP AUTH set to 1smtpuser = '#' # for SMTP AUTH, set SMTP username heresmtppass = '#' # for SMTP AUTH, set SMTP password hereflname = 'c:\\Python24\\mssg.txt'#c:\\tst.txtRECIPIENTS = ['[EMAIL PROTECTED]']SENDER = '[EMAIL PROTECTED]'mssg = open(flname , 'r').read()session = smtplib.SMTP(smtpserver)if AUTHREQUIRED: session.login(smtpuser, smtppass)smtpresult = session.sendmail(SENDER, RECIPIENTS, mssg)if smtpresult: errstr = "" for recip in smtpresult.keys(): errstr = """Could not delivery mail to: %sServer said: %s%s%s""" % (recip, smtpresult[recip][0], smtpresult[recip][1], errstr) raise smtplib.SMTPException, errstr Find your next car at Yahoo! Canada Autos___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] email-sending..
Hi Jan, Side question: how much Python do you know already? It really seems like you've just picked up an introductory example, so I'm not exactly sure I see where you might be getting stuck or what things you've tried already. Anyway, when you mention: > i am trying to send emails through a python script , but it complains that > > socket error 10061 conection refused.. although this is useful, you should also copy-and-paste the exact error message. I know that you have to be paraphrasing somewhere because the word "connection" is misspelled above. Copying-and-pasting error messages is perfectly fine: they provide information in even their most trivial-looking details, which is why we really want to see that information in its fullness. It will also help to see at one line things start going wrong. Do you remember seeing any kind of stack trace that pointed out which line of the program wasn't going so well? On quick question about the program you're showing us: > smtpserver = 'mailserver' ^^ Is this the real name of your SMTP mail server? ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Searching for email id in MySQL giving wrong results
Hi I am sending the code of the function "searchbyemail" and the output of the program when I run I am trying to search and display the results , even if we give a part of the email_id thanks Joseph John SEARCH by email _id function def searchbyemail(): s_email = raw_input("Enter the Email to be searched ") db = MySQLdb.connect(host="localhost",user = "john", passwd = "asdlkj", db = 'learnpython') entry = db.cursor() entry.execute("""SELECT * FROM contact WHERE email_id = %s """, (s_email,)) p = entry.fetchall() print p ### *** Output of the short run * [EMAIL PROTECTED] experiement]$ python mysqlentry.py Data Base Entry for the Testing Env 0 - Quit 1 - Enter the Data 2 - Display The data 3 - Search The Company 4 - Delete Some info Choice :2 (('Joseph', '[EMAIL PROTECTED]', '1234', '4321'), ('John', '[EMAIL PROTECTED]', '4567', '7654'), ('CityBank', '[EMAIL PROTECTED]', '987', '789'), ('ABN amro', '[EMAIL PROTECTED]', '456', '654')) Data Base Entry for the Testing Env 0 - Quit 1 - Enter the Data 2 - Display The data 3 - Search The Company 4 - Delete Some info Choice :3 Do U want to search by Name , email id , phone or fax U want to search the contacts by 0 - Quit 1 - Name 2 - email_id 3 - phone 4 - fax Choice :2 Enter the Email to be searched [EMAIL PROTECTED] (('ABN amro', '[EMAIL PROTECTED]', '456', '654'),) U want to search the contacts by 0 - Quit 1 - Name 2 - email_id 3 - phone 4 - fax Choice :2 Enter the Email to be searched loan () U want to search the contacts by 0 - Quit 1 - Name 2 - email_id 3 - phone 4 - fax Choice : --- Kent Johnson <[EMAIL PROTECTED]> wrote: > John Joseph wrote: > > Hi > >Thanks to Allan,Danny,Pujo > >I did my simple python script for MySQL , > the > > scripts add the data , and search for the data and > > display > > I have problem in searching email id > ,ie > > If search for the [EMAIL PROTECTED] , I will not get > any > > result , Guidance and advice needed for the > reason > > for this behavior > > Does it work when you search for other data such as > name or phone? > > Can you show the output from a short run where you > add a contact, > display the data and search for an email? > > Kent > > > I had added my script in this mail > > Thanks > > Joseph John > > > > > * > > > > """ This program is for to learn > > how to enter data to MySQL using python > > How to search > > not using OOP > > > > Have problem in searching email-id > > Why I do not get correct results when > > searching email id > >"@" string search containg "@" gives empty > > results > > > > """ > > > > > > > > import MySQLdb > > > > def selecter(): > > choice = None > > while choice != "0": > > print \ > > """ > > Data Base Entry for the Testing Env > > 0 - Quit > > 1 - Enter the Data > > 2 - Display The data > > 3 - Search The Company > > """ > > choice = raw_input("Choice :") > > print > > > > if choice == "0": > > print "Good Bye ..." > > elif choice == "1": > > dataentry() > > > > elif choice == "2": > > datashow() > > elif choice == "3": > > datasearch() > > > > > > > > def dataentry(): > > name = raw_input("Enter the name of the company > ") > > email_id = raw_input("\n Enter the email ID : ") > > phone_no = raw_input("Enter the Phone No : ") > > fax_no = raw_input("\n Enter the fax no : ") > > > > db = MySQLd