[Tutor] mac users
Dear Group, I am a macOSX user and I would like to simultaneously learn how to program and learn python. Does anyone know of a good book, or online tutorial that would be helpful? I got the book, "Learning to Program in Python for the absolute beginner". but... its was made for Windows users and the examples in the book dont work for me, for example, print "\a" does not make my macOSX system "beep" any guidance would be great! thanks, Shane ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Senior Project With Python
Greetings! My name is Deric Roach, and I am a senior at Sterling High School in Sterling, Kansas. This year, the school is conducting senior projects. For my senior project, I have decided to learn the python programming language and design a simple (yet amusing) role-playing game. For the undertaking, I must find a "mentor" to assist my development, guide my progress, and prepare me for the final presentation of the finished product. This mentor is to put in around 10 hours of service from now until the end of April, at which point the projects will be completed. I would like to find somebody who would be willing to help me out and adopt the title of "mentor." You don't necessarily have to be fluent in Python, but you must be able to give me guidance in the way of programming and/or game development. If you live farther away than is of convenience, we could maintain an e-mail partnership. A thank you all, and to all a "thank you. Respectfully, Deric E. Roach ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] PLZ REPLY SOON
Hi sir, I'm new to python & postgres as I've created a form in html & a table in postgres. There is a field in form which will take multiple value the problem which i'm facing is i'm getting single value but when i want multiple values to be inserted to postgres table it is not happening the dtml script is Eno EmpName Facility you want HRA Travel Food Accomodation State Delhi Harayana UP Kerala J&K -- python script import psycopg import sys def add(REQUEST): try: con=psycopg.connect("dbname=mission2007 user= postgres") cur=con.cursor() d=[] d.append(REQUEST.get("txtEmpName")) d.append(REQUEST.get("arrFacility")) d.append(REQUEST.get("txtState")) sql1="select max(eno) from empdetail" cur.execute(sql1) eno=cur.fetchone() sql="insert into empdetail (empname,facility,state) values('"+REQUEST.get("txtEmpName")+"','"+REQUEST.get("arrFacility")+" ','"+REQUEST.get("txtState")+"')" return sql cur.execute(sql) con.commit() cur.close() con.close() return "You had successfully entered data" ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] How can I clean the screen
Dear group, If I am executing a python prog from the command line and need to clear the screen (like using the cls command at the windows cmd prompt) midway into the program, how do I do it?? Any inputs will be greatly appreciated. Thanks. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] How can I clean the screen
Try :import osos.system('cls')you will able to see the effect when you run in windows console.Cheers,pujoOn 1/23/06, Suri Chitti <[EMAIL PROTECTED]> wrote:Dear group, If I am executing a python prog from the command line andneed to clear the screen (like using the cls command at the windows cmdprompt) midway into the program, how do I do it?? Any inputs will be greatly appreciated.Thanks.___Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] processing a text file w/ OO?
> I'm processing a tab-delimited text file where I read in a file, > perform a bunch of operations on the items, and then write them out > again to a fixed-width text file. > > I've been doing this with a very functional approach: > > Anyway, this all works fine. Not knowing much about OO, I'm wondering > if there's a way to approach this from an object-oriented > perspective. Is there anything to be gained? Or is this type of > problem best tackled with a functional approach? This is one of the types of problem where I personally don't try to use objects too much. Where objects might be helpful is if you have a number of similar but slightly different data records such that the processing consists of lots of if/elif chains. In that case identifying the type once and relying on polymorphism to deal with the differences is useful. But if the records all have similar processing then OOP will make the code bulkier, slower and not add too much IMHO. OTOH if you were to write a lot of these kinds of applications OOP might provide a higher level of code reuse between projects But remember that the cost of reuse means that you need to reuse code 3(*) or more times to make it economical! (*) Metrics suggest the actual figure varies between 3-10 times depending on language, object complexity and level of generality. HTH, Alan G Author of the learn to program web tutor http://www.freenetpages.co.uk/hp/alan.gauld ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] mac users
Hi Shane, > I am a macOSX user and I would like to simultaneously learn how to program > and learn python. Does anyone know of a good book, or online tutorial that > would be helpful? The Python web site lists lots of tutorials and they are all free so try them and see which suits your style. Tutorials tend to be very individual in nature, what suits one may not work for another. > Python for the absolute beginner". but... its was made for Windows users > and the examples in the book dont work for me, for example, > > print "\a" > > does not make my macOSX system "beep" Did you try it in the Terminal (Applications->Utilities) I don't think \a works in the IDE that comes with MacPython but the Terminal should work I think...(Where is my iBook when I need it?!) regards, Alan G Author of the learn to program web tutor http://www.freenetpages.co.uk/hp/alan.gauld ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] How can I clean the screen
>If I am executing a python prog from the command line and > need to clear the screen (like using the cls command at the windows cmd Thus should be a FAQ somewhere... Clearing the screen is terminal specific so Python doesn't have a single way to do it. Since you mention Windows I'll assume thats what you are using and suggest you simply use the CLS command via an os.system() call: import os os.system('CLS') If you have Linux substitute 'clear' for CLS Or as a last resort write your own: def cls(rows=100): for row in rows: print If you use curses it has a couple of functions for clearing a window. HTH, Alan G. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] python-based system programming and admin?
> I just have to tell the user to ssh in and run 'ipython' to > get a familiar and flexible environment. Put a link on his Desktop which points to "ssh -X [EMAIL PROTECTED] ipython" man ssh > The system is a server - doesn't even need X libraries, which are a > significant source of security concerns. The security risk is running an X-Server, but the server doesn't need one. The _client_ needs to run X so ipython (running on the server) can draw its windows on the screen of the client machine. So this should not be a problem. HTH -- Freedom, Freedom, Freedom, Oi! -- Zoidberg Telefonieren Sie schon oder sparen Sie noch? NEU: GMX Phone_Flat http://www.gmx.net/de/go/telefonie ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Totorial announcement
Saves me ordering the book :-) I saw it on bol.com together with another of your books. Those hours is too much for me otherwise you'd have a Dutch version too :-) ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] How can I clean the screen
I tried os.system('cls')...the screen seemed to hang. -Original Message- From: Alan Gauld [mailto:[EMAIL PROTECTED] Sent: Monday, January 23, 2006 3:37 PM To: Suri Chitti; tutor@python.org Subject: Re: [Tutor] How can I clean the screen >If I am executing a python prog from the command line and > need to clear the screen (like using the cls command at the windows cmd Thus should be a FAQ somewhere... Clearing the screen is terminal specific so Python doesn't have a single way to do it. Since you mention Windows I'll assume thats what you are using and suggest you simply use the CLS command via an os.system() call: import os os.system('CLS') If you have Linux substitute 'clear' for CLS Or as a last resort write your own: def cls(rows=100): for row in rows: print If you use curses it has a couple of functions for clearing a window. HTH, Alan G. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Totorial announcement
> Saves me ordering the book :-) > I saw it on bol.com together with another of your books. The book is slightly different and has some extra chapters but it is now quite out of date, I recommend the web version (which also has a lot of material not in the book, so swings and roundabouts there...). But I don't have any other books published (yet) the stuff about hypnotism and psychic stuff is another Alan Gauld based in Chicago USA - I get a lot of email for him! :-) Alan G. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Searching for email id in MySQL giving wrong results [ Try out pattern Search ]
Hi Thanks for the tip now I am trying to do pattern matching for MySQL , but I am not getting the result on MySQL , to select for all email starting with jos we do select * from contact where email_id like "jos%"; but I get confused how to use it , while executing it in python , how to call the pattern matching inside mysql query I had added my code Thanks Joseph John *** import MySQLdb s_email= raw_input("Enter the some part of 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 like %s''', (s_email,)) #s = entry.fetchall() #print s entry.execute('''SELECT * FROM contact WHERE email_id like %s''', (s_email,)) s = entry.fetchall() print s ~ ~ --- "ZIYAD A. M. AL-BATLY" <[EMAIL PROTECTED]> wrote: > On Sun, 2006-01-22 at 12:43 +, John Joseph > wrote: > > Hi > Hi John... > > Most of your problems in your code seems to be > caused by a single > mistake. Compare the following two strings and you > should figure out > what's wrong by yourself: > > email_id = '[EMAIL PROTECTED]' > > wrong_string = '''SELECT s FROM t WHERE > id=%s''' , (email_id) > right_string = '''SELECT s FROM t WHERE > id=%s''' % (email_id) > > print "Wrong:", wrong_string > print "Right:", right_string > > This is the output: > Wrong: ('SELECT s FROM t WHERE id=%s', > '[EMAIL PROTECTED]') > Right: SELECT s FROM t WHERE > [EMAIL PROTECTED] > > Now, which one is the right one? And which one is > the one you want? > > > I suggest you study strings more, especially > concatenation and '%'. > > If you need more help, just post to the mailing list > again. > Ziyad. > > ___ To help you stay safe and secure online, we've developed the all new Yahoo! Security Centre. http://uk.security.yahoo.com ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Totorial announcement
LOL! Did you know I actually thought "wtf and a book about coding and a book about hypnotism? WOW". :D :D :D Well I like books cuz it's easier to carry around inside trains and busses ;) Wim On 1/23/06, Alan Gauld <[EMAIL PROTECTED]> wrote: > > Saves me ordering the book :-) > > I saw it on bol.com together with another of your books. > > The book is slightly different and has some extra chapters but it > is now quite out of date, I recommend the web version (which > also has a lot of material not in the book, so swings and > roundabouts there...). > > But I don't have any other books published (yet) the stuff about > hypnotism and psychic stuff is another Alan Gauld based in > Chicago USA - I get a lot of email for him! :-) > > Alan G. > ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Totorial announcement
Sorry to both A.Gauld and Rinzwind for my previous mistake in addressing. Great,Alan,I got pretty much help from your OS tutorial in my past hard times in learning Python. I'm glad you've completed it :) Cheers Ivan ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] How can I clean the screen
2006/1/23, Suri Chitti <[EMAIL PROTECTED]>: > > Dear group, >If I am executing a python prog from the command line and > need to clear the screen (like using the cls command at the windows cmd > prompt) midway into the program, how do I do it?? Any inputs will be > greatly appreciated. > Thanks. > > ___ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor > Hi there A nice neat trick which is: print '\n' * 100 Will print a hundred lines on the screen,thus shifting the cursor down so the screen will seem to have been cleaned. Or it's possible to implement these lines in a program: import os, platform def clear_screen(): if platform.system() == 'Linux': os.system('clear') if platform.system() == 'Windows': os.system('cls') clear_screen() (Both them are excerpt from the Python Tips and Tricks published from the Italian Python User Group). Cheers Ivan ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] How can I clean the screen
> I tried os.system('cls')...the screen seemed to hang. Did you try hitting Enter after it? cls will just clear the screeen... Alan G. -Original Message- From: Alan Gauld [mailto:[EMAIL PROTECTED] Sent: Monday, January 23, 2006 3:37 PM To: Suri Chitti; tutor@python.org Subject: Re: [Tutor] How can I clean the screen >If I am executing a python prog from the command line and > need to clear the screen (like using the cls command at the windows cmd Thus should be a FAQ somewhere... Clearing the screen is terminal specific so Python doesn't have a single way to do it. Since you mention Windows I'll assume thats what you are using and suggest you simply use the CLS command via an os.system() call: import os os.system('CLS') If you have Linux substitute 'clear' for CLS Or as a last resort write your own: def cls(rows=100): for row in rows: print If you use curses it has a couple of functions for clearing a window. HTH, Alan G. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] How can I clean the screen
You can use the function system() of the os module. os.system('clear') in Unix or in Windows os.system('clear')-- Edgar A. Rodriguez V. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Searching for email id in MySQL giving wrong results
On Sun, 2006-01-22 at 21:23 +0300, ZIYAD A. M. AL-BATLY wrote: > wrong_string = '''SELECT s FROM t WHERE id=%s''' , (email_id) The string is being used in a call to cursor.execute. The email_id is a second parameter getting passed to execute. That is the *correct* approach to use. That is no help in explaining why the SELECT command is failing to return the expected results. -- Lloyd Kvam Venix Corp ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Linux Python install?
Sorry to bother the list with so simple a question but on moving to Linux from Windows XP, it's not clear to me how to accomplish a Python install on Linux. On XP it was mostly point and click on a ".msi" file (with msi standing for Microsoft install). I've loaded the latest Fedora/Redhat release on an old AMD machine. How do I install Python such that it shows up as a selection under the Programming task bar with EMACS? I assume I have to do this under root, right? Step by step please. Thanks. _ Dont just search. Find. Check out the new MSN Search! http://search.msn.click-url.com/go/onm00200636ave/direct/01/ ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] PLZ REPLY SOON
At 10:24 PM 1/22/2006, Shalini R wrote: >Hi sir, > I'm new to python & postgres as I've created a form in html & a >table in postgres. There is a field in form which will take multiple >value My guess is that each checkbox needs its own name, rather than all of them using arrFacility. Give that a try. >the problem which i'm facing is i'm getting single value but >when i want multiple values to be inserted to postgres table it is >not happening >the dtml script is > > > > >Eno >EmpNamename="txtEmpName"> >Facility you want >HRA >Travel >Food >value="Accomodation">Accomodation > > > > >State >Delhi >Harayana >UP >Kerala >J&K > > > > > > > > > > >-- >python script > > >import psycopg >import sys >def add(REQUEST): > try: > con=psycopg.connect("dbname=mission2007 user= >postgres") > cur=con.cursor() > d=[] > d.append(REQUEST.get("txtEmpName")) > d.append(REQUEST.get("arrFacility")) > d.append(REQUEST.get("txtState")) > sql1="select max(eno) from empdetail" > cur.execute(sql1) > eno=cur.fetchone() > sql="insert into empdetail (empname,facility,state) >values('"+REQUEST.get("txtEmpName")+"','"+REQUEST.get("arrFacility")+" >','"+REQUEST.get("txtState")+"')" > return sql > cur.execute(sql) > con.commit() > cur.close() > con.close() > return "You had successfully entered data" > > > > >___ >Tutor maillist - Tutor@python.org >http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Linux Python install?
On Mon, 2006-01-23 at 09:28 -0500, CPIM Ronin wrote: > Sorry to bother the list with so simple a question but on moving to Linux > from Windows XP, it's not clear to me how to accomplish a Python install on > Linux. On XP it was mostly point and click on a ".msi" file (with msi > standing for Microsoft install). I've loaded the latest Fedora/Redhat > release on an old AMD machine. How do I install Python such that it shows up > as a selection under the Programming task bar with EMACS? I assume you are using yum for package management. It should have been installed by default. As root, you can issue the command yum install python python-docs python-devel python-tools The package yumex provides a GUI interface to the yum package manager. You can think of yumex as the Windows "Add/Remove Programs" application on steroids. yum install yumex The yumex install view with a filter of python will provide an extensive list of additional python packages. Finally, I do not know if this includes the best python integration with EMACS. > I assume I have to do this under root, right? > > Step by step please. > > Thanks. > > _ > Dont just search. Find. Check out the new MSN Search! > http://search.msn.click-url.com/go/onm00200636ave/direct/01/ > > ___ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor -- Lloyd Kvam Venix Corp ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Starbucks does not use two-phase commit
Hi Danny, Just to report something regarding the code you have provided. I noticed that when I do a keyboard interrupt, I get the keyboard interrupt exception messages, but after that it keeps hangning and never returns to the command line input mode. I have to close the shell to really end the program afaics. After reading Todd's emails, I wondered if it had something to do with how the threaded queue is started. In your example, you use: Thread( target = ).start() While I have been using the thread module, using: thread.start_new( , ( , ) ) When I implemented your example in my program, I also used your approach, and started having the hanging behavior. I reconverted the thread spawn to my own approch, just to see if it would make a difference. And with my approach, the keyboard interrupts really aborts the program, the shell returns to command line input mode. Any idea why those two methods of starting threads can behave so differently? Thanks Bernard On 1/20/06, Bernard Lebel <[EMAIL PROTECTED]> wrote: > Ultra-nice Danny, it works (ie: I have implemented your example in my > code and it runs as it should). > > I have to admit that I'm a little bit puzzled by this chain of > instantiation and argument passing, however I intend to decipher it > properly. > > > Thanks again! > Bernard > > > > > On 1/20/06, Danny Yoo <[EMAIL PROTECTED]> wrote: > > > > > > On Fri, 20 Jan 2006, Bernard Lebel wrote: > > > > > So have written a little test script. The fact is that I want to be able > > > to manage the same queue from separate threads. Below is an example of > > > what my real program is doing: > > > > > > Hi Bernard, > > > > One problem is that there's a single outputQueue being presented to get > > results back from the Server. > > > > A different approach is to use a lot of outputQueues. *grin* > > > > The idea is that when we send a job submission, we immediately get back a > > "ticket". We can then use this ticket to claim() our result. Each ticket > > is unique to a job submission, so we shouldn't see any bleeding going on > > between clients. > > > > > > Here's some code that implements this idea. It's a little complex, so you > > may want to read through it slowly: > > > > > > > > from threading import Thread > > from Queue import Queue > > > > > > class Ticket: > > """A small token that we can use to claim our result.""" > > def __init__(self, q): > > self.q = q > > self.result = None > > self.done = False > > > > def claim(self): > > if not self.done: > > self.result = self.q.get() > > self.done = True > > return self.result > > > > > > class Server: > > _QUIT_JOB = ['Quit!'] > > > > def __init__(self): > > """A queue will contain 2-tuples of (job, outputQueue) > > elements.""" > > self.queue = Queue() > > > > > > def startServer(self): > > """Brings the server online.""" > > Thread(target=self._jobLoop).start() > > > > > > def schedule(self, job): > > """Schedules a job to be done and returns a ticket that the > > client can use later to claim the result of the job.""" > > outputQueue = Queue() > > self.queue.put((job, outputQueue)) > > return Ticket(outputQueue) > > > > > > def scheduleShutdown(self): > > """Add a 'job' that shuts the system down.""" > > self.queue.put((Server._QUIT_JOB, None)) > > > > > > def _jobLoop(self): > > """Continue looping through tasks.""" > > while True: > > print "Looping..." > > (nextJob, outputQueue) = self.queue.get() > > if nextJob is Server._QUIT_JOB: > > return > > returnValue = self._doJob(nextJob) > > outputQueue.put(returnValue) > > > > > > def _doJob(self, job): > > print "I'm doing", job > > return job + job ## something to show that we're doing something > > > > > > > > def separateCaller(server): > > for i in range(1000, 1004 + 1): > > print "--Separate caller asks %d" % i > > ticket = server.schedule(str(i)) > > print "--Separate caller got %s" % ticket.claim() > > > > > > if __name__ == '__main__': > > server = Server() > > server.startServer() > > Thread(target=separateCaller, args=(server,)).start() > > > > result1 = server.schedule("1") > > print "result1: %s" % result1.claim() > > result2 = server.schedule("2") > > print "result2: %s" % result2.claim() > > result3 = server.schedule("3") > > print "result3: %s" % result3.claim() > > server.scheduleShutdown() > > # > > > > > > Play around with this a bit and see if it makes sense to you. You might > > also be interested in the amusing article "Starbucks Does Not Use > > Two-Phase Commit": > > > > ht
Re: [Tutor] python-based system programming and admin?
> > > Subject: > [Tutor] python-based system programming and admin? > From: > Neal McBurnett <[EMAIL PROTECTED]> > Date: > Fri, 20 Jan 2006 21:01:03 -0700 (MST) > To: > tutor > > To: > tutor > > > I'm an experienced linux guy, with lots of python interest and some > python experience. > > I'm helping a colleague develop software to run on our linux server. > He has python skill, but doesn't know the shell or linux very well at > all. > > I'd like to give him a secure, safe, flexible development environment > on the serve, (which does audio streaming and other fun things). > > At the moment, he has an account and can connect from his mac via ssh, > and copy files back and forth (ftp-like stuff - I forget which ssh > client). But he doesn't want to log in to a bash shell and learn a > whole new way to do things. But he does want to run programs. > > Editing python scripts spawned by cron is one of the goals. > But developing them by waiting for cron to fire and send the output > via email is pretty painful > > The server currently doesn't need to run a web server, and I'm > reluctant to introduce new services that have much security risk > associated with them, but something like that seems like a > possibility. > > One idea that just popped in my brain is to give him a python login > shell on linux - any advice on how to do that? > > Other possibilities, I guess: > > - An https-based web server with and mod-python, somehow configured >so that his jobs run as him. > > - a pure-python server (via twisted?) running as him > > - moinmoin or the like > > - zope or plone (not sounding very simple any more, but I've done a >bit of this ) > > What would be the safest, simplest solution that was adequate for > providing a reasonable development environment? > > Any ideas I haven't thought of yet? > > Cheers, > > Neal McBurnett http://bcn.boulder.co.us/~neal/ Sorry to pop in late on this discussion. I get the digest and it's sent to my work, so I got all weekend's digests to catch up on. Rather than having you bend over backwards setting up a weird environment, I think your colleague should learn some basic unix commands. Since he's running a Mac(I'm assuming OS X), the basic commands will help him with Darwin OS which is underneath the Mac GUI. Darwin is a flavor of BSD, and BSD is a flavor of unix. There's not a lot to learn. Basic file management(copy, delete, move, rename), setting the permissions(chmod, chown), navigating the directory structure(cd, ls), and finally running a python program. Some editors have FTP built into them, so he could write the code on his mac and have the editor FTP the file to his account on the server. He could then telnet to the server and run the script. Mike ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Searching for email id in MySQL giving wrong results
> On Sun, 2006-01-22 at 21:23 +0300, ZIYAD A. M. AL-BATLY wrote: >> wrong_string = '''SELECT s FROM t WHERE id=%s''' , (email_id) > > The string is being used in a call to cursor.execute. The email_id is a > second parameter getting passed to execute. That is the *correct* > approach to use. Nope, sorry. This sends the string SELECT . id=%s [EMAIL PROTECTED] ie the %s is kept in the string, not what is wanted. The OP must replace the comma with a % character for the string substitution to take place. > That is no help in explaining why the SELECT command is failing to > return the expected results. The rogue %s in the select string will mess things up. Alan G. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Linux Python install?
> from Windows XP, it's not clear to me how to accomplish a Python install > on Linux. That depends on your distro. Each distribution has its own package management tool. eg. On RedHat its rpm(and there is a GUI tool too), on Debian its getappt or somesuch... Python should already be installed on most distros, but of course you may want a more recent version. > standing for Microsoft install). I've loaded the latest Fedora/Redhat > release on an old AMD machine. How do I install Python such that it shows > up as a selection under the Programming task bar with EMACS? No idea how to put it into Emacs automatically. I suspect that needs some editing of the .emacs file or somesuch. Some packages may do that for you but its beyond my outdated knowledge of Linux... I just run Linux, I don't tweak it very much. > I assume I have to do this under root, right? Not necessarily, but if you use another user you will sometimes find that you don't have access to the default fiolder locations. And even ifg you do only that user will be able to run the application. So root is usually best. HTH, Alan G ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Searching for email id in MySQL giving wrong results
On Mon, 2006-01-23 at 18:17 +, Alan Gauld wrote: > > On Sun, 2006-01-22 at 21:23 +0300, ZIYAD A. M. AL-BATLY wrote: > >> wrong_string = '''SELECT s FROM t WHERE id=%s''' , (email_id) > > > > The string is being used in a call to cursor.execute. The email_id is a > > second parameter getting passed to execute. That is the *correct* > > approach to use. > > Nope, sorry. > This sends the string > > SELECT . id=%s [EMAIL PROTECTED] > > ie the %s is kept in the string, not what is wanted. > > The OP must replace the comma with a % character for the string > substitution to take place. > > > That is no help in explaining why the SELECT command is failing to > > return the expected results. > > The rogue %s in the select string will mess things up. > > Alan G. -- Lloyd Kvam Venix Corp ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Starbucks does not use two-phase commit
> I noticed that when I do a keyboard interrupt, I get the keyboard > interrupt exception messages, but after that it keeps hangning and never > returns to the command line input mode. I have to close the shell to > really end the program afaics. Hi Bernard, When we're using the high-level 'threading' interface, the server thread --- which runs independently of the main thread --- will continue to run until it's shut down. But we can call setDaemon() on the server's thread to allow Python to exit. Look at the bottom of: http://www.python.org/doc/lib/thread-objects.html So we can modify server.startServer() to flag the server thread as a daemon: def startServer(self): t = Thread(thread=self._jobLoop) t.setDaemon(True) t.start() > While I have been using the thread module, using: > > thread.start_new( , ( , ) ) > > When I implemented your example in my program, I also used your > approach, and started having the hanging behavior. I reconverted the > thread spawn to my own approch, just to see if it would make a > difference. The low level 'thread' library is a bit more platform specific. Here's what the documentation says: (http://www.python.org/doc/lib/module-thread.html) """When the main thread exits, it is system defined whether the other threads survive. On SGI IRIX using the native thread implementation, they survive. On most other systems, they are killed without executing try ... finally clauses or executing object destructors.""" Does this make sense? ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Searching for email id in MySQL giving wrong results
On Mon, 2006-01-23 at 18:17 +, Alan Gauld wrote: > > On Sun, 2006-01-22 at 21:23 +0300, ZIYAD A. M. AL-BATLY wrote: > >> wrong_string = '''SELECT s FROM t WHERE id=%s''' , (email_id) > > > > The string is being used in a call to cursor.execute. The email_id is a > > second parameter getting passed to execute. That is the *correct* > > approach to use. > > Nope, sorry. > This sends the string > > SELECT . id=%s [EMAIL PROTECTED] > > ie the %s is kept in the string, not what is wanted. > > The OP must replace the comma with a % character for the string > substitution to take place. The wrong_string line was lifted from the following code in the OP. entry = db.cursor() entry.execute("""SELECT * FROM contact WHERE email_id = %s""", (s_email,)) The execute method will handle the string substitution. This is better than doing it yourself, because execute will deal with any quoting issues for feeding the data to the database. I should have included the original code as I did here. Sorry if I created any confusion as related to regular Python string substitution. It is a very common mistake for people to do the SQL string interpolation themselves as opposed to leaving it for the execute method. > > > That is no help in explaining why the SELECT command is failing to > > return the expected results. > > The rogue %s in the select string will mess things up. > > Alan G. -- Lloyd Kvam Venix Corp ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Python install on Linux
A simple way to migrate to Linux and get a recent version of Python by default would be to download a copy of Ubuntu Linux. You can burn it onto a CD, then pop it ino the cd drive and boot it on your Windows machine. It runs in a virtual machine, so you are assured that your Windows installation will never become corrupted by Linux. Or you can load it directly onto your hard drive in place of Windows. Python is loaded by default. Ubuntu is designed to ease your migration to Linux, You should be fairly comfortably up and running within two hours. I have it on my laptop, and it boots up in just over a minute. http://www.ubuntulinux.org/ __ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Searching for email id in MySQL giving wrong results
>> >> wrong_string = '''SELECT s FROM t WHERE id=%s''' , (email_id) >> > >> The OP must replace the comma with a % character for the string >> substitution to take place. > > The wrong_string line was lifted from the following code in the OP. > >entry = db.cursor() >entry.execute("""SELECT * FROM contact WHERE email_id = %s""", > (s_email,)) > Ah I see. Yes that's a different proposition entirely! I really should read the whole thread before jumping in... :-( Alan G. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Starbucks does not use two-phase commit
Hi Danny, Yes that makes sense, but.. what is a "daemon"? Sorry if this is super basic question. Thanks Bernard On 1/23/06, Danny Yoo <[EMAIL PROTECTED]> wrote: > > > > I noticed that when I do a keyboard interrupt, I get the keyboard > > interrupt exception messages, but after that it keeps hangning and never > > returns to the command line input mode. I have to close the shell to > > really end the program afaics. > > Hi Bernard, > > When we're using the high-level 'threading' interface, the server thread > --- which runs independently of the main thread --- will continue to run > until it's shut down. But we can call setDaemon() on the server's thread > to allow Python to exit. Look at the bottom of: > > http://www.python.org/doc/lib/thread-objects.html > > So we can modify server.startServer() to flag the server thread as a > daemon: > > def startServer(self): > t = Thread(thread=self._jobLoop) > t.setDaemon(True) > t.start() > > > > > While I have been using the thread module, using: > > > > thread.start_new( , ( , ) ) > > > > When I implemented your example in my program, I also used your > > approach, and started having the hanging behavior. I reconverted the > > thread spawn to my own approch, just to see if it would make a > > difference. > > The low level 'thread' library is a bit more platform specific. Here's > what the documentation says: > > (http://www.python.org/doc/lib/module-thread.html) > > """When the main thread exits, it is system defined whether the other > threads survive. On SGI IRIX using the native thread implementation, > they survive. On most other systems, they are killed without > executing try ... finally clauses or executing object destructors.""" > > > Does this make sense? > > ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Searching for email id in MySQL giving wrong results
On Mon, 2006-01-23 at 19:46 +, Alan Gauld wrote: > >> >> wrong_string = '''SELECT s FROM t WHERE id=%s''' , (email_id) > >> > > >> The OP must replace the comma with a % character for the string > >> substitution to take place. > > > > The wrong_string line was lifted from the following code in the OP. > > > >entry = db.cursor() > >entry.execute("""SELECT * FROM contact WHERE email_id = %s""", > > (s_email,)) > > > > Ah I see. Yes that's a different proposition entirely! > I really should read the whole thread before jumping in... :-( > > Alan G. > Well I created the trap by not pasting in the execute call and posting what was on its face an invalid piece of Python coding. -- Lloyd Kvam Venix Corp ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Why doesn't this work?
I copied this code from Learning Python while learning about extending types by subclassing: class Set(list): def __init__(self, value=[]): list.__init__([]) self.concat(value) def intersect(self, other): res = [] for x in self: if x in other: res.append(x) return Set(res) def union(self, other): res = Set(self) res.concat(other) return res def concat(self, value): for x in value: if not x in self: self.append(x) def __and__(self, other): return self.intersect(other) def __or__(self, other): return self.union(other) def __repr__(self): return 'Set:' + list.__repr__(self) if __name__ == '__main__': x = Set([1,3,5,7]) y = Set([2,1,4,5,6]) print x, y, len(x) print x.intersect(y), y.union(x) print x & y, x | y x.reverse(); print x Here is the result: [EMAIL PROTECTED]:/imports/home/cspears/Documents/Python/chap23> python setsubclass.py [1, 3, 5, 7] [2, 1, 4, 5, 6] 4 [1, 5] [2, 1, 4, 5, 6, 3, 7] Traceback (most recent call last): File "setsubclass.py", line 32, in ? print x & y, x | y TypeError: unsupported operand type(s) for &: 'Set' and 'Set' According to the book, here is what I should get: Set:[1, 3, 5, 7] Set:[2, 1, 4, 5, 6] 4 Set:[1, 5] Set:[2, 1, 4, 5, 6, 3, 7] Set:[1, 5] Set:[1, 3, 5, 7, 2, 4, 6] Set:[7, 5, 3, 1] Problem 1: Why isn't "Set:" being printed? I thought def __repr__(self): return 'Set:' + list.__repr__(self) would facilitate that. Problem 2: What is causing the TypeError? I'm pretty sure I copied this exactly from the book, so I'm not sure what is not working. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Why doesn't this work?
Christopher, I copied and pasted your code and it worked only a few modifications. The thing I had to change was the indention level of the: def __and__(self, other): return self.intersect(other) def __or__(self, other): return self.union(other) def __repr__(self): return 'Set:' + list.__repr__(self)statements. These statements need to be on the same indention level as your __init__, intersection and union satements. Here's what I got: class Set(list): def __init__(self, value=[]): list.__init__([]) self.concat(value) def intersect(self, other): res = [] for x in self: if x in other: res.append(x) return Set(res) def union(self, other): res = Set(self) res.concat(other) return res def concat(self, value): for x in value: if not x in self: self.append(x) def __and__(self, other): return self.intersect(other) def __or__(self, other): return self.union(other) def __repr__(self): return 'Set:' + list.__repr__(self) if __name__ == '__main__': x = Set([1,3,5,7]) y = Set([2,1,4,5,6]) print x, y, len(x) print x.intersect(y), y.union(x) print x & y, x | y x.reverse(); print x On 1/23/06, Christopher Spears <[EMAIL PROTECTED]> wrote: I copied this code from Learning Python while learningabout extending types by subclassing:class Set(list):def __init__(self, value=[]):list.__init__([])self.concat (value)def intersect(self, other):res = []for x in self:if x in other:res.append(x)return Set(res)def union(self, other):res = Set(self)res.concat(other)return res def concat(self, value):for x in value:if not x in self:self.append(x)def __and__(self, other): return self.intersect(other)def __or__(self, other): return self.union(other)def __repr__(self): return 'Set:' + list.__repr__(self)if __name__ == '__main__':x = Set([1,3,5,7])y = Set([2,1,4,5,6])print x, y, len(x)print x.intersect(y), y.union(x)print x & y, x | y x.reverse(); print xHere is the result:[EMAIL PROTECTED]:/imports/home/cspears/Documents/Python/chap23>python setsubclass.py[1, 3, 5, 7] [2, 1, 4, 5, 6] 4[1, 5] [2, 1, 4, 5, 6, 3, 7] Traceback (most recent call last): File "setsubclass.py", line 32, in ?print x & y, x | yTypeError: unsupported operand type(s) for &: 'Set'and 'Set'According to the book, here is what I should get: Set:[1, 3, 5, 7] Set:[2, 1, 4, 5, 6] 4Set:[1, 5] Set:[2, 1, 4, 5, 6, 3, 7]Set:[1, 5] Set:[1, 3, 5, 7, 2, 4, 6]Set:[7, 5, 3, 1]Problem 1: Why isn't "Set:" being printed? I thought def __repr__(self): return 'Set:' +list.__repr__(self)would facilitate that.Problem 2: What is causing the TypeError?I'm pretty sure I copied this exactly from the book,so I'm not sure what is not working. ___Tutor maillist - Tutor@python.orghttp://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Starbucks does not use two-phase commit
On Mon, 23 Jan 2006, Bernard Lebel wrote: > Yes that makes sense, but.. what is a "daemon"? Sorry if this is > super basic question. According to: http://docs.python.org/lib/thread-objects.html """A thread can be flagged as a ``daemon thread''. The significance of this flag is that the entire Python program exits when only daemon threads are left. The initial value is inherited from the creating thread. The flag can be set with the setDaemon() method and retrieved with the isDaemon() method.""" So that's what "daemon" technically does when we apply that term it to a thread. But what it means to us humans is up to interpretation: I think of daemon threads as being more "ephemeral" than other threads. Not sure if that makes any sense to anyone besides myself, though. *grin* There's a traditional use of the word "daemon" that deals with programs that run in the background: http://en.wikipedia.org/wiki/Daemon_(computer_software) so the word "daemon" is, like most words, a bit overloaded. *grin* ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Totorial announcement
On Mon, 23 Jan 2006, Alan Gauld wrote: > But I don't have any other books published (yet) the stuff about > hypnotism and psychic stuff is another Alan Gauld based in > Chicago USA - I get a lot of email for him! :-) A friend of mine is the author of "Just Java," "Not Just Java," "Expert C Programming," and "Peter van der Linden's Guide to Linux." When looking up his books on Amazon, I found "Great Lakes Ships We Remember" and "Forest and Shade Trees of Iowa" by an entirely different Peter van der Linden. "The Official Handbook of Practical Jokes" is his, though. (BTW, each of Peter's technical books is highly recommended, if you're in the market for a book covering that subject matter.) ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Why doesn't this work?
Thanks! Is there a name for the type of myopia that develops after staring at the computer screen too long? -Chris --- Jason Massey <[EMAIL PROTECTED]> wrote: > Christopher, > > I copied and pasted your code and it worked only a > few modifications. The > thing I had to change was the indention level of > the: > > def __and__(self, other): return > self.intersect(other) > def __or__(self, other): return self.union(other) > def __repr__(self): return 'Set:' + > list.__repr__(self) > > statements. These statements need to be on the same > indention level as your > __init__, intersection and union satements. > > Here's what I got: > > class Set(list): > def __init__(self, value=[]): > list.__init__([]) > self.concat(value) > > def intersect(self, other): > res = [] > for x in self: > if x in other: > res.append(x) > return Set(res) > > def union(self, other): > res = Set(self) > res.concat(other) > return res > > def concat(self, value): > for x in value: > if not x in self: > self.append(x) > > def __and__(self, other): return > self.intersect(other) > def __or__(self, other): return > self.union(other) > def __repr__(self): return 'Set:' + > list.__repr__(self) > > if __name__ == '__main__': > x = Set([1,3,5,7]) > y = Set([2,1,4,5,6]) > print x, y, len(x) > print x.intersect(y), y.union(x) > print x & y, x | y > x.reverse(); > print x > > On 1/23/06, Christopher Spears > <[EMAIL PROTECTED]> wrote: > > > > I copied this code from Learning Python while > learning > > about extending types by subclassing: > > > > class Set(list): > > def __init__(self, value=[]): > > list.__init__([]) > > self.concat(value) > > > > def intersect(self, other): > > res = [] > > for x in self: > > if x in other: > > res.append(x) > > return Set(res) > > > > def union(self, other): > > res = Set(self) > > res.concat(other) > > return res > > > > def concat(self, value): > > for x in value: > > if not x in self: > > self.append(x) > > > > def __and__(self, other): return > self.intersect(other) > > def __or__(self, other): return self.union(other) > > def __repr__(self): return 'Set:' + > > list.__repr__(self) > > > > if __name__ == '__main__': > > x = Set([1,3,5,7]) > > y = Set([2,1,4,5,6]) > > print x, y, len(x) > > print x.intersect(y), y.union(x) > > print x & y, x | y > > x.reverse(); print x > > > > Here is the result: > > > > > [EMAIL PROTECTED]:/imports/home/cspears/Documents/Python/chap23> > > python setsubclass.py > > [1, 3, 5, 7] [2, 1, 4, 5, 6] 4 > > [1, 5] [2, 1, 4, 5, 6, 3, 7] > > Traceback (most recent call last): > > File "setsubclass.py", line 32, in ? > > print x & y, x | y > > TypeError: unsupported operand type(s) for &: > 'Set' > > and 'Set' > > > > According to the book, here is what I should get: > > > > Set:[1, 3, 5, 7] Set:[2, 1, 4, 5, 6] 4 > > Set:[1, 5] Set:[2, 1, 4, 5, 6, 3, 7] > > Set:[1, 5] Set:[1, 3, 5, 7, 2, 4, 6] > > Set:[7, 5, 3, 1] > > > > Problem 1: Why isn't "Set:" being printed? I > thought > > > > > >def __repr__(self): return 'Set:' + > > list.__repr__(self) > > > > would facilitate that. > > > > Problem 2: What is causing the TypeError? > > > > I'm pretty sure I copied this exactly from the > book, > > so I'm not sure what is not working. > > ___ > > Tutor maillist - Tutor@python.org > > http://mail.python.org/mailman/listinfo/tutor > > > "I'm the last person to pretend that I'm a radio. I'd rather go out and be a color television set." -David Bowie "Who dares wins" -British military motto "I generally know what I'm doing." -Buster Keaton ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Starbucks does not use two-phase commit
Thanks a lot Danny. Bernard On 1/23/06, Danny Yoo <[EMAIL PROTECTED]> wrote: > > > On Mon, 23 Jan 2006, Bernard Lebel wrote: > > > Yes that makes sense, but.. what is a "daemon"? Sorry if this is > > super basic question. > > According to: > > http://docs.python.org/lib/thread-objects.html > > """A thread can be flagged as a ``daemon thread''. The significance of > this flag is that the entire Python program exits when only daemon > threads are left. The initial value is inherited from the creating > thread. The flag can be set with the setDaemon() method and retrieved > with the isDaemon() method.""" > > So that's what "daemon" technically does when we apply that term it to a > thread. > > > But what it means to us humans is up to interpretation: I think of daemon > threads as being more "ephemeral" than other threads. Not sure if that > makes any sense to anyone besides myself, though. *grin* > > There's a traditional use of the word "daemon" that deals with programs > that run in the background: > > http://en.wikipedia.org/wiki/Daemon_(computer_software) > > so the word "daemon" is, like most words, a bit overloaded. *grin* > > ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] passwords in scripts
Hi Ivan I'm not sure I understand what you are saying here. Surely if the file is compiled it can just run (and will only need to be RE-compiled when I have to change the code (such as when one of the servers has their password changed). I would never need to de-compile, because I'll just keep a copy of the file on a memory stick, edit it there, compile it and replace the current compiled file with the newly compiled file. Not that I know anything about compiling Python programs, I just want to know if this is a possibility Thanks Ben --- Ivan Furone <[EMAIL PROTECTED]> wrote: > 2006/1/21, Ben Vinger <[EMAIL PROTECTED]>: > > Hello > > > > I've written a couple of scripts that check log > files > > on our WIndows and Unix servers. These scripts > have > > plain text passwords in them, so anyone who can > access > > the filesystem of the Windows server that runs the > > scripts can discover the passwords of the servers. > > Is there a way to hide/encrypt these passwords? > Or > > can the scripts be converted to compiled code in > order > > for the passwords to be hidden? > > > > > > Thanks > > Ben > > > > > > Hello, > Compiling a file in python is a big time > loss,because there's not a > built-in function for decompiling,but you can just > use the 'dis'module > for disassembling it and the result is always > different from the > original,because it uses Abstract Source Tree syntax > in spite of > Python language for translating the bytecode;on the > other hand it > wouldn't secure the file itself from being accessed > but makes it > useless IMHO.Thus,with a slight impact on > complexity,a module with the > crypted passwords would be imported, which would > proceed for checking > the passwords and exporting them in a StringIO > object at runtime.For > enhancing security,once used it could be removed and > used again when > needed,without removing the scripts themselves.You > can check the > 'crypt' module for this task. > Cheers, > Ivan > ___ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor > ___ Win a BlackBerry device from O2 with Yahoo!. Enter now. http://www.yahoo.co.uk/blackberry ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Searching for email id in MySQL giving wrong results
On Mon, 2006-01-23 at 14:00 -0500, Python wrote: > The wrong_string line was lifted from the following code in the OP. > > entry = db.cursor() > entry.execute("""SELECT * FROM contact WHERE email_id = %s""", > (s_email,)) > > The execute method will handle the string substitution. This is better > than doing it yourself, because execute will deal with any quoting > issues for feeding the data to the database. > > I should have included the original code as I did here. Sorry if I > created any confusion as related to regular Python string substitution. > > It is a very common mistake for people to do the SQL string > interpolation themselves as opposed to leaving it for the execute > method. > Okay, here's a quote from the definition of "execute()": def execute(self, query, args=None): """Execute a query. query -- string, query to execute on server args -- optional sequence or mapping, parameters to use with query. Note: If args is a sequence, then %s must be used as the parameter placeholder in the query. If a mapping is used, %(key)s must be used as the placeholder. Returns long integer rows affected, if any""" So, my answer is correct. And it seems there are other solutions (using sequences and "%s" (just like Lloyd Kvam said) or "%(key1)s" in case of passing a mapping sequence (which, I think, is just a dictionary)). Why it didn't work for him in the first place? I really don't know. DISCLAIMER: I *NEVER* used "MySQLdb". I just wanted to help. The sentence: """%s""", (email_id) seemed awfully wrong to me, and since nobody replied to him for more than a day, I suggested (what seemed to me) the right answer. That's a wrong thing to do since I don't know anything about "MySQLdb". So, I apologise to all of you. Ziyad. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] passwords in scripts
Hi Danny The Unix servers are ancient HP-UX ones. I doubt if an SSH implementation for them exists, but it is not worth my while trying to find out, because I will not be allowed to install anything on them (or even suggest it). So I access them using telnetlib: host = 'hpserver' user = 'backupuser\r' password = 'backuppassword\r' telnetConnection = telnetlib.Telnet(host) telnetConnection.read_until('login: ') telnetConnection.read_until('Password: ') telnetConnection.write(password) menu = telnetConnection.read_until('Please Enter choice :') etc - doing the things programatically what I would have done if I opened a regular telnet session On the Windows servers the scheduled task I use runs with my domain logon credentials. This is fine for the majority of the servers, but some are in other domains where my credentials don't do the job. For them, I just open a connection to the ipc$ share in advance, like so: os.system(r'net use \\farserver\ipc$ /u:fardomain\administrator farpassword') The information about all the backup results is finally served as a single web page, so anyone can see at a glance whether the backups worked. This can also easily be emailed out, or warnings can be sent. But surely my problem is a very common one. Every web-app must supply a username and password to make a connection to its backend database, for example. Thanks Ben --- Danny Yoo <[EMAIL PROTECTED]> wrote: > I guess one question might be: why are the passwords > there in the first > place? *grin* > > > It's usually a good idea to try avoiding hardcoding > things in a program, > and that goes for passwords too. If you're using > passwords to connect to > the Unix servers, you might want to consider looking > at Keychain: > > http://www.gentoo.org/proj/en/keychain/ > > to avoid having to do manual password entry. > Alternatively, 'ssh' can > be used to run remote commands on a Unix server. > There's a good example > of this here: > > http://www.jdmz.net/ssh/ > > > If you could tell us more details on why those > passwords are there, we > might have some better suggestions. > > > Good luck! > > ___ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor > ___ Yahoo! Messenger - NEW crystal clear PC to PC calling worldwide with voicemail http://uk.messenger.yahoo.com ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Searching for email id in MySQL giving wrong results
Hi Ziyad, Don't beat yourself up over this, you were trying to be helpful and that's a good thing. The original syntax looked weird to me too, but mainly because the variable was inside a pair of parens, but because I didn't know MySql I didn't say anything at the time. But your answer seemed reasonable enough. >> entry.execute("""SELECT * FROM contact WHERE email_id = %s""", >> (s_email,)) >> >> The execute method will handle the string substitution. This is better >> than doing it yourself, because execute will deal with any quoting >> issues for feeding the data to the database. Personally I never use this feature of execute because I then can't print out the SQL statement sent to the database if anything unexpected happens. I'd rather take responsibility for awkward escape strings than have a string I can't debug being sent to the database, but I'm aware that others take the opposite view and have more confidence in Python's libraries than I do! > Okay, here's a quote from the definition of "execute()": >def execute(self, query, args=None): >"""Execute a query. > >query -- string, query to execute on server >args -- optional sequence or mapping, parameters to use > with query. Actually this might still be the issue since the OP used a single variable not a sequence but I suspect Python is smart enough to deal with that. > So, my answer is correct. And it seems there are other solutions (using > sequences and "%s" (just like Lloyd Kvam said) or "%(key1)s" in case of > passing a mapping sequence (which, I think, is just a dictionary)). You would have been correct if he had been building the query outside of execute(). > Why it didn't work for him in the first place? I really don't know. Me neither! :-) >I *NEVER* used "MySQLdb". I just wanted to help. The sentence: >"""%s""", (email_id) Maybe he just needs a comma after email_id to force the second arg to be a tuple - who knows, I certainly don't. >more than a day, I suggested (what seemed to me) the right >answer. > >That's a wrong thing to do since I don't know anything about >"MySQLdb". So, I apologise to all of you. No apology is necessary, you were trying to help. Without your wrong answer Lloyd may not have posted the correction and we might not have had a discussion about the options available in cursor.execute() Alan G Author of the learn to program web tutor http://www.freenetpages.co.uk/hp/alan.gauld ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] passwords in scripts
Hi Ben, Jon Libes of the National Institute of Standards and Technology (NIST) has written a guide on how to handle passwords in backgrounded processes: http://expect.nist.gov/doc/bgpasswd.pdf It has more suggestions on how to handle passwords securely. As you might expect, it doesn't have a single definitive answer to your question either. There are many ways to handle passwords with varying levels of convenience and security in mind. [comments about telnet] The use of telnet is already problematic in terms of security. Telnet passwords are sent in the clear. (So, although this is unrelated to your particular problem, I think you should encourage your system administrators to look into ssh in the long term. HP appears to support it: http://h20293.www2.hp.com/portal/swdepot/displayProductInfo.do?productNumber=T1471AA) > But surely my problem is a very common one. Every web-app must supply a > username and password to make a connection to its backend database, for > example. One approach that's often used in these kinds of applications is to keep a separate configuration file with those usernames and passwords. Then we can use the operating system's mechanisms (like file permissions) to keep that file mostly safe from prying eyes. This is mentioned in the "Handing Passwords with Security and Reliability in Background Processes" link above. One problem, though, is that anyone who has privileges to execute the password-reading program will probably have the same power to read that configuration file directly. I can see encrypting the configuration file as a way of making it a bit more difficult for people to accidently run across the passwords, and perhaps that's enough security for your purposes. Best of wishes! ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] passwords in scripts
On Mon, 23 Jan 2006, Danny Yoo wrote: > Jon Libes of the National Institute of Standards and Technology (NIST) ^^^ Gaah. I'm sorry, that should be "Don", not "Jon". My muscle memory slipped. *grin* ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] [webbrowser] some help on an error running mozilla firefox
On 1/22/06, Rinzwind <[EMAIL PROTECTED]> wrote: > Why does this: > > >>> import webbrowser > >>> webbrowser.open('http://www.google.com";) > > give me this: > > run-mozilla.sh: Cannot execute > /opt/firefox/mozilla-firefox-bin. > I would assume it's a permissions error. Can you execute /opt/firefox/mozilla-firefox-bin? Is python running as a different user? -- --H.F. My penguin is bigger than yours, mister... ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] processing a text file w/ OO?
Thanks, Alan. That's exactly the kind of explanation I was looking for. As this is pretty much a one-off project and the data transformations are pretty different for each field, I'll stick with the functional approach. The rule of thumb you mention is useful, too. I hadn't heard that before. On Jan 23, 2006, at 2:53 AM, Alan Gauld wrote: >> I'm processing a tab-delimited text file where I read in a file, >> perform a bunch of operations on the items, and then write them >> out again to a fixed-width text file. >> I've been doing this with a very functional approach: >> Anyway, this all works fine. Not knowing much about OO, I'm >> wondering if there's a way to approach this from an object- >> oriented perspective. Is there anything to be gained? Or is this >> type of problem best tackled with a functional approach? > > This is one of the types of problem where I personally don't try to > use objects too much. Where objects might be helpful is if you have > a number of similar but slightly different data records such that > the processing consists of lots of if/elif chains. In that case > identifying the type once and relying on polymorphism to deal with > the differences is useful. But if the records all have similar > processing then OOP will make the code bulkier, slower and not add > too much IMHO. > > OTOH if you were to write a lot of these kinds of applications OOP > might provide a higher level of code reuse between projects But > remember that the cost of reuse means that you need to reuse code 3 > (*) or more times to make it economical! > > (*) Metrics suggest the actual figure varies between 3-10 times > depending on language, object complexity and level of generality. > > HTH, > > Alan G > Author of the learn to program web tutor > http://www.freenetpages.co.uk/hp/alan.gauld > > ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Linux Python install?
I highly recommend you have a look into ipython. It is a breeze to work with. I usually have a couple of terminal screens open, one with the ipython interpreter, which helps me a lot when testing code snipplets. You can install it using yumex, or just run 'yum install ipython' from the root command line. If you just started with Fedora, go into this site and follow the tips provided. It really improves your working environment. It will also provide you with extra repositories which allow you the installation of ipython among other packages. Fedora Core 4 Tips and Tricks http://home.gagme.com/greg/linux/fc4-tips.php On Mon, 2006-01-23 at 10:06 -0500, Python wrote: > On Mon, 2006-01-23 at 09:28 -0500, CPIM Ronin wrote: > > Sorry to bother the list with so simple a question but on moving to Linux > > from Windows XP, it's not clear to me how to accomplish a Python install > > on > > Linux. On XP it was mostly point and click on a ".msi" file (with msi > > standing for Microsoft install). I've loaded the latest Fedora/Redhat > > release on an old AMD machine. How do I install Python such that it shows > > up > > as a selection under the Programming task bar with EMACS? > > I assume you are using yum for package management. It should have been > installed by default. As root, you can issue the command > yum install python python-docs python-devel python-tools > > The package yumex provides a GUI interface to the yum package manager. > You can think of yumex as the Windows "Add/Remove Programs" application > on steroids. > yum install yumex > > The yumex install view with a filter of > python > will provide an extensive list of additional python packages. > > Finally, I do not know if this includes the best python integration with > EMACS. > > > I assume I have to do this under root, right? > > > > Step by step please. > > > > Thanks. > > > > _ > > Dont just search. Find. Check out the new MSN Search! > > http://search.msn.click-url.com/go/onm00200636ave/direct/01/ > > > > ___ > > Tutor maillist - Tutor@python.org > > http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor