[Tutor] detect 64-bit windows
In Python, how to do that ? sys.platform only gives 'win32', no info about 32-bit or 64 bit ? Thanks. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] WinXP IDLE -> open file : how-to change default directory ?
Try right-clicking on the shortcut, select properties, and change the "start in" value. Matthew P.S. When posting to the list, please use plain text format. From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of learner404 Sent: 15 June 2006 20:09 To: tutor@python.org Subject: [Tutor] WinXP IDLE -> open file : how-to change default directory ? Hello, On WinXP IDLE will always 'open' in Python24 folder at startup. A beginner friend of mine hate that (personally I use SPE) and I tried 'quickly' to find a way to configure that for him. I found all the .cfg files in idlelib and also the .idlerc folder in the "Documents and settings" but I don't see how to give IDLE a default directory at startup (or kipping in memory the last one opened). How to do that or is it just not possible ? Thanks learner404 ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] lambda and creating GUIs
>I have been reading though the PyGTK tutorial. > Can anyone explain how lambda is being used in this > statement: > > button.connect("clicked", lambda w: gtk.main_quit()) lambda is being used to create an anonymous function. The code could be rewritten like this: def f(w): gtk.main_quit() button.connect("clicked", f) lambda simply saves cluttering up the code with lots of tiny function derfinitions which are never referred to apart from in the binding operation. You can read about lambdas in the functional programming topic in my tutor HTH, Alan Gauld Author of the Learn to Program web site http://www.freenetpages.co.uk/hp/alan.gauld ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] XML: Expletive Deleted (OT)
> [ The only SOA/XML book that addresses this side of XML usage > is the excellent "SOA - A Field Guide" by Peter Erls. Erls also > suggests some mitigating strategies to get round it.] Oops, don't rely on memory... That is Thomas Erl not Peter Erls. And of course there may be other SOAP/XML books deal with these issues, but Erl's book is the only one I've read that does so! Alan G. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Writing to a remote file
Hi I want to run a script on one machine and log output messages to a remote file located on another machine. Is there any easy method of doing this ?. Thanks Kieran-- "Behind every great man, there is a great woman. Behind that woman is Mr.T." ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Writing to a remote file
kieran flanagan wrote: > Hi > > I want to run a script on one machine and log output messages to a > remote file located on another machine. Is there any easy method of > doing this ?. Depends on the details, I suppose... If the remote file is on a network file system accessible to the machine running the script it should be easy - just open the file and write to it. For example on Windows you should be able to write f = open(r'\\server\path\to\logfile.txt', 'w') print >>f, 'This is a very serious matter' or configure the file path in your logging properties or whatever... If the remote file system is *not* accessible from the local machine, then you need some way to talk to the remote machine. Kent ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Delete directories recursively
Hi,I need to delete a directory and its sub directories. However all dir's, sub dir;s and files have read only access. How do i do this efficeintly using the os.walk command. I cannot run this command on the dir as it gives me an error due to the read only attribute. Is there any other way to do this? -- ~~AMRESH~~ ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Delete directories recursively
Amresh Kulkarni wrote: > Hi, > > I need to delete a directory and its sub directories. However all dir's, > sub dir;s and files have read only access. How do i do this efficeintly > using the os.walk command. > I cannot run this command on the dir as it gives me an error due to the > read only attribute. Is there any other way to do this? Maybe I'm missing something, but I don't understand how you expect to delete a directory if you don't have delete permission? Kent ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Delete directories recursively
You must change the directory and file permissions before attempting to remove them; even if you are using a python script. Take a look at os.chmod() -mtw On Fri, Jun 16, 2006 at 10:26:34AM -0500, Amresh Kulkarni ([EMAIL PROTECTED]) wrote: > Hi, > > I need to delete a directory and its sub directories. However all dir's, sub > dir;s and files have read only access. How do i do this efficeintly using > the os.walk command. > I cannot run this command on the dir as it gives me an error due to the read > only attribute. Is there any other way to do this? > > -- > ~~AMRESH~~ > ___ > 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] Writing to a remote file
On Fri, 2006-06-16 at 14:47 +0100, kieran flanagan wrote: > Hi > > I want to run a script on one machine and log output messages to a > remote file located on another machine. Is there any easy method of > doing this ?. http://docs.python.org/lib/module-logging.html If the remote machine is a file server, you can use the logging module to write to a file on the remote machine Also the logging module can be used to easily log to a syslog handler. If this remote file is a "normal" log file managed by a syslog process then you should find the python part pretty easy. The syslog process still needs to be configured to accept your logging messages, but that should not be too difficult. Scanning the logging module docs, it looks like you can use it to write your own process to run on the remote machine to handle "logging messages". Then use the logging module on the local machine to send "logging messages" to the remote machine. > Thanks > Kieran > > -- > "Behind every great man, there is a great woman. Behind that woman is > Mr.T." > ___ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor -- Lloyd Kvam Venix Corp. 1 Court Street, Suite 378 Lebanon, NH 03766-1358 voice: 603-653-8139 fax:320-210-3409 ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Writing to a remote file
Lloyd Kvam wrote: > On Fri, 2006-06-16 at 14:47 +0100, kieran flanagan wrote: >> Hi >> >> I want to run a script on one machine and log output messages to a >> remote file located on another machine. Is there any easy method of >> doing this ?. > Scanning the logging module docs, it looks like you can use it to write > your own process to run on the remote machine to handle "logging > messages". Then use the logging module on the local machine to send > "logging messages" to the remote machine. Cool. There's even a complete example in the docs: http://docs.python.org/lib/network-logging.html Kent ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Machine Vs. Human Parsing (Was: XML: Expletive Deleted) (Way OT!)
Greetings: > -Original Message- > Date: Fri, 16 Jun 2006 00:05:41 +0100 > From: "Alan Gauld" <[EMAIL PROTECTED]> > Subject: Re: [Tutor] XML: Expletive Deleted (OT) > To: tutor@python.org > Message-ID: <[EMAIL PROTECTED]> > > Just picked this up after being out for most of the week... > > "Carroll, Barry" <[EMAIL PROTECTED]> wrote in message > > > One reason to for choosing a human-readable format is the desire to > > visually confirm the correctness of the stored data and format. > > Thats a very dangerous asumption, how do you detect unprintable > characters, tabs instead of spaces, trailing spaces on a line etc etc. > Whole text representations are helpful you should never rely on the > human eye to validate a data file. > > > can be invaluable when troubleshooting a bug involving stored data. > > If > > there is a tool between the user and the data, one must then rely > > upon > > the correctness of the tool to determine the correctness of the > > data. > > Or the correctness of the eye. I know which one i prefer - a tested > tool. > The human eye is not a dta parser, but it flatters to deceive by being > nearly good enough. > > > In a case like this, nothing beats the evidence of one's eyes, IMHO. > > Almost anything beats the human eye IME :-) > Actually if you must use eyes do so on a hex dump of the file, that > is usually reliable enough if you can read hex... > <> > > Alan g. If I gave the impression that the human eye is the only useful means of examining and verifying stored data, I apologize. I indented to say that the human eye, and the brain that goes with it, is an invaluable tool in evaluating data. I stand by that statement. The most sophisticated tool is only as good as the developer(s) who made it. Since software is ultimately written by humans, it is fallible. It contains mistakes, gaps, holes, imperfections. When the tool gives bad, or erroneous, or incomplete results, what do you do? You look at the data. A case in point. I used to test audio subsystems on PC motherboards. The codec vendor released a new version of their chip with new driver software. Suddenly our tests began to fail. The vendor insisted their HW and SW were correct. The test owner insisted his SW was correct. Somebody was mistaken. I used an audio editing program to display the waveform of the data in the capture buffer. The first several hundred samples were not a waveform, but apparently random noise. I now knew why the test is failing, but why was there noise in the buffer? It wasn't there before. The editing SW was no help there. So I switched tools, and displayed the capture buffer with simple file dump program. The first 2K of the buffer was filled with text! The story goes on, but that's enough to illustrate my point. Neither the audio driver, nor the test SW, nor the editing tool could show the real problem. All of them were 'tested tools', but when presented with data they were not designed to handle, they produced incorrect or incomplete results. I could cite other examples from other disciplines, but this one suffices: no SW tool should be relied upon to be correct in all cases. I trust my eyes to see things tools can't, not because they can detect nonprintable characters in a HEX dump (I can read HEX dumps, and binary when necessary, but I usually just print out '\t', '[SP]', etc) but because they are not bound by anyone else's rules as to what is correct and incorrect. The programmer's two most valuable tools are her/his eyes and brain. They are always useful, sometimes indispensable. Regards, Barry [EMAIL PROTECTED] 541-302-1107 We who cut mere stones must always be envisioning cathedrals. -Quarry worker's creed ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Delete directories recursively
Amresh, I had this problem a few months back. I approached it backwards. Maybe not the right way to do it. I removed all the files and directories and then had my exception handle the file if it was read only. The exception handler changes the file from read-only to not read only and then calls the function again. Is there a better way to do it? Would appreciate feedback on the code below. import shutil import os def zaps(self): try: shutil.rmtree('f:/m2m') except OSError, inst: print OSError os.chmod(inst.filename, 0666) self.zaps() Regards, John. -Original Message-From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]On Behalf Of Amresh KulkarniSent: 16 June 2006 16:27To: tutor@python.orgSubject: [Tutor] Delete directories recursivelyHi,I need to delete a directory and its sub directories. However all dir's, sub dir;s and files have read only access. How do i do this efficeintly using the os.walk command. I cannot run this command on the dir as it gives me an error due to the read only attribute. Is there any other way to do this? -- ~~AMRESH~~ ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Delete directories recursively
John Corry wrote: > > Amresh, > > I had this problem a few months back. I approached it backwards. Maybe > not the right way to do it. I removed all the files and directories and > then had my exception handle the file if it was read only. The > exception handler changes the file from read-only to not read only and > then calls the function again. > > Is there a better way to do it? Would appreciate feedback on the code > below. > > import shutil > import os > > def zaps(self): > > try: > shutil.rmtree('f:/m2m') > > > except OSError, inst: > print OSError > os.chmod(inst.filename, 0666) > self.zaps() I imagine this could be expensive if you have a deep directory hierarchy with lots of read-only files - you have to start the traversal from scratch each time you get an error. If you have more than 1000 read-only files you will get a stack overflow from the recursion. shutil.rmtree() actually takes an optional error handler argument. According to the docs, "If onerror is provided, it must be a callable that accepts three parameters: function, path, and excinfo. The first parameter, function, is the function which raised the exception; it will be os.listdir(), os.remove() or os.rmdir()." So something like this should work and be faster because the directory traversal doesn't restart each time (UNTESTED!!): def handle_error(fn, path, excinfo): if fn is os.rmdir: # handle readonly dir os.chmod(path, 0666) # ?? not sure if this is correct for a dir os.rmdir(path) # try again elif fn is os.remove: os.chmod(path, 0666) os.remove(path) shutil.rmtree(top, onerror=handle_error) Kent ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Delete directories recursively
Thanks guys,Error handling seems to be a nice idea to approach this problem. i checked Kent's code and it works fine.I was using a more crude method.def removeDir(dirName) : #Remove any read-only permissions on file. removePermissions(dirName) for name in os.listdir(dirName): file = os.path.join(dirName, name) if not os.path.islink(file) and os.path.isdir(file): removeDir(file) else: removePermissions(file) os.remove(file) os.rmdir(dirName) returndef removePermissions(filePath) : #if (os.access(filePath, os.F_OK)) : #If path exists if (not os.access(filePath, os.W_OK)) : os.chmod(filePath, 0666) returnhowever shutil seems to be more simple and efficient here!Regards,Amresh On 6/16/06, Kent Johnson <[EMAIL PROTECTED]> wrote: John Corry wrote:>> Amresh,>> I had this problem a few months back. I approached it backwards. Maybe> not the right way to do it. I removed all the files and directories and> then had my exception handle the file if it was read only. The > exception handler changes the file from read-only to not read only and> then calls the function again.>> Is there a better way to do it? Would appreciate feedback on the code> below. >> import shutil> import os>> def zaps(self):>> try:> shutil.rmtree('f:/m2m')>>> except OSError, inst:> print OSError > os.chmod(inst.filename, 0666)> self.zaps()I imagine this could be expensive if you have a deep directory hierarchywith lots of read-only files - you have to start the traversal from scratch each time you get an error. If you have more than 1000 read-onlyfiles you will get a stack overflow from the recursion.shutil.rmtree() actually takes an optional error handler argument.According to the docs, "If onerror is provided, it must be a callable that accepts three parameters: function, path, and excinfo. The firstparameter, function, is the function which raised the exception; it willbe os.listdir(), os.remove() or os.rmdir()."So something like this should work and be faster because the directory traversal doesn't restart each time (UNTESTED!!):def handle_error(fn, path, excinfo): if fn is os.rmdir: # handle readonly dir os.chmod(path, 0666) # ?? not sure if this is correct for a dir os.rmdir(path) # try again elif fn is os.remove: os.chmod(path, 0666) os.remove(path)shutil.rmtree(top, >Kent___ Tutor maillist - Tutor@python.orghttp://mail.python.org/mailman/listinfo/tutor -- ~~AMRESH~~ ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Delete directories recursively
> I need to delete a directory and its sub directories. However all > dir's, sub > dir;s and files have read only access. How do i do this efficeintly > using > the os.walk command. You can'ty since the reasoin the files are read-only is to prevent them being over-written or deleted! You need to convert them from read-only and then delete them. Its not too hard provided you have the relevant access rights to change mode. > I cannot run this command on the dir as it gives me an error due to > the read > only attribute. Is there any other way to do this? You can only do from Python what you can do from the OS. If you don't have access to the files from the OS you won't have access from Python - thats why access rights are there! For more on how to do it we need to know your OS, since this is almost certainly a job for the OS rather than Python, unless you want to do more than just delete the files. If you do have access rights then you can find out all the needed steps in the OS topic in my tutor. Alan Gauld Author of the Learn to Program web site http://www.freenetpages.co.uk/hp/alan.gauld ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Machine Vs. Human Parsing (Was: XML: Expletive Deleted)(Way OT!)
> > Almost anything beats the human eye IME :-) > > Actually if you must use eyes do so on a hex dump of the file, > > that > > is usually reliable enough if you can read hex... > If I gave the impression that the human eye is the only useful means > of > examining and verifying stored data, I apologize. I indented to say > that the human eye, and the brain that goes with it, is an > invaluable > tool in evaluating data. I stand by that statement. > > The most sophisticated tool is only as good as the developer(s) who > made it. Of course and thats why i said I trusted a *tested* tool. You have to be sure the tool is functioning correctly before you can use it confidently. > Since software is ultimately written by humans Not always, but that's a whole other OT debate :-) > You look at the data. I agree, thats part of testing/debugging the tool. Most specifically you find known data, whether that be the data causing the problem or a reference data source with which you can compare. > A case in point. I used to test audio subsystems on PC > motherboards. > ... > I used an audio editing program to display the waveform ie a Tool. > The editing SW was no help there. So I switched tools, > and displayed the capture buffer with simple file dump program. Again a tool. Why because your eyes couldn't parse the audio data. Your eyes could parse the tool output which was intended for human consumption. > The story goes on, but that's enough to illustrate my point. And mine. You needed the right tools to interpret the raw data in the file before your eyes and brain could diagnose the problem. The issue I was raising was that textual data on disk is notoriously difficult to accurately interpret. Once it has passsed through a tool that presents it in an unambiguous format the human eye is entirely appropriate. > the audio driver, nor the test SW, nor the editing tool could > show the real problem. All of them were 'tested tools', The need for the *right* tool does not obviate the need for a tool designed to interpret the raw data. Arguably the editing SW did highlight the real problem - the corruption at the start of the file. Its representation was good enough to poiunt you at the hex editor. > data they were not designed to handle, they produced incorrect > or incomplete results. Just like the human eye when reading raw data out of a text file! > I could cite other examples from other disciplines, > but this one suffices: no SW tool should be relied upon to be > correct > in all cases. Indeed, diagnosing data problems is always fraught with difficulty. Its one of the hardest problem types to track down. My point was merely that the human eye is not reliable when reading raw text files and other, better tools exist. I did not mean to imply that any magic tool exists that works for any kind of data, but the eye is no better than any other kind of tool in this regard. It is very good when presented with data that is formatted for it but not si good when presented with "nearly right" data. > I trust my eyes to see things tools can't And I trust tools to see what my eyes can't! Neither is infallible and I need both. If I'm looking at a text file I'll fire it up in a text editor first for the obvious checks. But if it looks OK I'll then either load it in a hex editor or some other tool designed to read that data format. > when necessary, but I usually just print out '\t', '[SP]', etc) I'm curious how you do that? Presumably a tool? (Not joking, how do you get that kind of display without a specialist tool?) > and incorrect. The programmer's two most valuable tools are her/his > eyes and brain. They are always useful, sometimes indispensable. I completely agree (see my chapter on denbugging in my paper book for a confirmation of that claim!). I was simply pointing out that belief that text files are somehow easy to analyse with the human eye is a dangerous fallacy, and I've spent enough man-days debugging plain-text to be very, very wary. OTOH I detest the modern tendency to use binary formats where plain text makes more sense such as in configuration files! But thats a very different use than for bulk data. Alan G. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] lambda and creating GUIs
I understand this: > > def f(w): gtk.main_quit() > button.connect("clicked", f) > > lambda simply saves cluttering up the code with lots > of tiny function > derfinitions which are never referred to apart from > in the binding > operation. > Now my question is what is "w"? What is being passed to the function? ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] lambda and creating GUIs
On 17/06/06, Christopher Spears <[EMAIL PROTECTED]> wrote: > I understand this: > > > > def f(w): gtk.main_quit() > > button.connect("clicked", f) > > > Now my question is what is "w"? What is being passed > to the function? I don't know GTK, but I would guess some kind of event class. Other GUIs I've used (Tkinter, wxPython) pass event objects to callbacks, which contain information like - which mouse button was clicked - the exact mouse coordinates (relative to the corner of the screen or the corner of the widget) - which key was pressed etc. You may know some of the information, some of it may not apply, you may not care about the rest of it, but you usually get it anyway :-) In this case, the program doesn't care about any of the extra information, so it accepts the event, but it does nothing with it. Try this: def show(e): print e print 'Class:', e.__class__ print 'Members:' for attr in dir(e): print '%s: %s' % (attr, getattr(e, attr)) button.connect("clicked", show) -- John. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor