Run wxPython app remotely under XWindows
Is there something special you have to do to get a wxPython app to run remotely under xwindows? My Tkinter apps always automatically work that way, so I was surprised to even be confronted with this problem. ~Sean -- http://mail.python.org/mailman/listinfo/python-list
Re: Run wxPython app remotely under XWindows
On Feb 28, 3:50 pm, Bjoern Schliessmann usenet- [EMAIL PROTECTED] wrote: Sean DiZazzo wrote: Is there something special you have to do to get a wxPython app to run remotely under xwindows? My Tkinter apps always automatically work that way, so I was surprised to even be confronted with this problem. Could you please provide more detail? My wxPython apps run perfectly remotely in the X Window System like this: $ ssh some-other-machine $ DISPLAY=:0 ./my_app.py huh...I am logging into the remote machine with ssh -X (actually with '-Y' in this case because its a mac), then I execute the program ie. `./test.py' Under Tkinter, this would send the app to display on the ssh client. Under wxPython it opens it on the ssh server. Maybe I am missing something obvious, but if I run 'xcalc' from the same shell, the app opens where I expect it...ssh forwarding seems to be working. ~Sean -- http://mail.python.org/mailman/listinfo/python-list
Re: Run wxPython app remotely under XWindows
On Feb 28, 3:50 pm, Bjoern Schliessmann usenet- [EMAIL PROTECTED] wrote: Sean DiZazzo wrote: Is there something special you have to do to get a wxPython app to run remotely under xwindows? My Tkinter apps always automatically work that way, so I was surprised to even be confronted with this problem. Could you please provide more detail? My wxPython apps run perfectly remotely in the X Window System like this: $ ssh some-other-machine $ DISPLAY=:0 ./my_app.py Should wxPython apps work this way? Do you think it's something with the server? -- http://mail.python.org/mailman/listinfo/python-list
Re: Run wxPython app remotely under XWindows
On Feb 28, 5:26 pm, Sean DiZazzo [EMAIL PROTECTED] wrote: On Feb 28, 3:50 pm, Bjoern Schliessmann usenet- [EMAIL PROTECTED] wrote: Sean DiZazzo wrote: Is there something special you have to do to get a wxPython app to run remotely under xwindows? My Tkinter apps always automatically work that way, so I was surprised to even be confronted with this problem. Could you please provide more detail? My wxPython apps run perfectly remotely in the X Window System like this: $ ssh some-other-machine $ DISPLAY=:0 ./my_app.py Should wxPython apps work this way? Do you think it's something with the server? Just to close the loop I think think this is a problem with the ssh server. ~Sean -- http://mail.python.org/mailman/listinfo/python-list
Re: Run wxPython app remotely under XWindows
On Feb 29, 8:19 am, Mike Driscoll [EMAIL PROTECTED] wrote: On Feb 28, 7:49 pm, Sean DiZazzo [EMAIL PROTECTED] wrote: On Feb 28, 5:26 pm, Sean DiZazzo [EMAIL PROTECTED] wrote: On Feb 28, 3:50 pm, Bjoern Schliessmann usenet- [EMAIL PROTECTED] wrote: Sean DiZazzo wrote: Is there something special you have to do to get a wxPython app to run remotely under xwindows? My Tkinter apps always automatically work that way, so I was surprised to even be confronted with this problem. Could you please provide more detail? My wxPython apps run perfectly remotely in the X Window System like this: $ ssh some-other-machine $ DISPLAY=:0 ./my_app.py Should wxPython apps work this way? Do you think it's something with the server? Just to close the loop I think think this is a problem with the ssh server. ~Sean If it's not the server, then please post the issue to the wxPython list. They can probably help: http://wxpython.org/maillist.php Mike To follow up with a solution. I learned that the default install of wxPython, and Tkinter for that matter is compiled to run under Aqua as opposed to X11. It won't run remotely, as I first posted, compiled this way. To get Tkinter to work under X11 you simply need to configure and install a version of python for the X11 environment. The default Mac install (Leopard) and the MacPython distro are configured to run under Aqua. Instead of compiling my own, I found that the default Fink install is configured to run under X11, so if you install it, and run that version of Python, you can run Tkinter apps remotely from a Mac box. wxPython is a bit more complicated. The idea is the same, but the process is much more complicated to get it working. You need to compile wxPython under GTK2, which I found is not well supported for Mac. I followed the instructions at this site: http://wiki.wxpython.org/wxGTK_on_Mac_OSX to get it working. Even with the instructions, I had to finagle a few things to get it to work properly. But it does work! My first successful install was on Tiger, but I'm trying an install on Leopard as we speak. Thanks to Cody Precord for the instructions. I would have never been able to do it without. Now my users will have a prettier GUI! ~Sean -- http://mail.python.org/mailman/listinfo/python-list
os.path.getsize() on Windows
Hi all, I'm seeing some behavior that is confusing me. I often use a simple function to tell if a file is growing...ie being copied into a certain location. (Can't process it until it's complete) My function is not working on windows, and I'm wondering if I am missing something simple, or if I have just never tried this before. Here's what I'm trying to do: def isGrowing(f, timeout): ssize = os.path.getsize(f) time.sleep(timeout) esize =os.path.getsize(f) return esize != ssize On windows, this returns the size of the file as it _will be_, not the size that it currently is. Is this a feature? What is the proper way to get the current size of the file? I noticed win32File.GetFileSize() Does that behave the way I expect? PS. I also tried os.stat()[6] ~Sean -- http://mail.python.org/mailman/listinfo/python-list
Re: os.path.getsize() on Windows
On Mar 18, 2:27 pm, Duncan Booth [EMAIL PROTECTED] wrote: Sean DiZazzo [EMAIL PROTECTED] wrote: On windows, this returns the size of the file as it _will be_, not the size that it currently is. Is this a feature? What is the proper way to get the current size of the file? I noticed win32File.GetFileSize() Does that behave the way I expect? PS. I also tried os.stat()[6] I think all of those will return the current size of the file, but that may be the same as the final size: just because the data hasn't been copied doesn't mean the file space hasn't been allocated. You don't say how you are copying the file, but I seem to remember that Windows copy command pre- allocates the file at its final size (so as to reduce fragmentation) and then just copies the data after that. If you need to make sure you don't access a file until the copy has finished then get hwatever is doing the copy to copy it to a temporary filename in the same folder and rename it when complete. Then you just have to check for existence of the target file. Hmmm... The file could be copied in by several different sources of which I have no control. I can't use your technique in my situation. I also tried getting md5 hashes with some time in between on advice, but the file is not opened for reading until the copy completes so I can't get the hashes. Any other ideas? -- http://mail.python.org/mailman/listinfo/python-list
Re: os.path.getsize() on Windows
On Mar 20, 6:42 am, Duncan Booth [EMAIL PROTECTED] wrote: Steven D'Aprano [EMAIL PROTECTED] wrote: On Wed, 19 Mar 2008 12:34:34 +, Duncan Booth wrote: By default Python on Windows allows you to open a file for reading unless you specify a sharing mode which prevents it: But the OP is talking about another process having opened the file for WRITING, not reading. It's that other process that has exclusive access, and the OP was trying to determine when it was safe to attempt opening the file according to whether or not it was still growing. No, unless the other process has specified that it wants exclusive access there is nothing stopping his process also opening the file. That's why he has to specify when he opens it that he wants exclusive access: then it doesn't matter what the other process does, he won't be able to open it until the other process has closed the file. This all of course assumes that the other process writes the file in one single atomic chunk. If it were to create it and then separately open and write to it then all bets are off. Thanks for your input. After trying again this morning, the file is opened for reading. I must have had some wonky permissions on that file, so the error method won't work. Trying to use the md5 technique won't work here either. It takes quite awhile to run one md5, let alone two on a growing file. These files can be 20-50GB. The overall idea is to be able to tell if a file has finished being placed in a directory without any control over what is putting it there. If I'm in control of the process, I know I can put it in a temp area, etc. I use the method I mention in my original post regularly without knowing how the file gets there, and was surprised to see it didn't work on Windows. In this case, there will be so few people touching the system, that I think I can get away with having the copy be done from Unix, but it would be nice to have a general way of knowing this on Windows. ~Sean -- http://mail.python.org/mailman/listinfo/python-list
Re: text adventure game problem
On Apr 8, 6:01 pm, [EMAIL PROTECTED] wrote: okay, I'm having this one problem with a text adventure game. It's kind of hard to explain, but I'll do my best. [code] def prompt_kitchen(): global gold gold_taken = False while True: prompt_kit = raw_input('') if prompt_kit == 'examine cabinet 1' and not gold_taken: print '''This cabinet has a lot of cups in it with all different designs and shapes. Where are the people anyway? How come there's nobody here? In one of the cups you find 8 gold.''' gold = gold+8 gold_taken = True pass4() elif prompt_kit == 'examine cabinet 1' and gold_taken: print \ '''This cabinet has a lot of cups in it with all different designs and shapes. Where are the people anyway? How come there's nobody here?''' pass4() def pass4(): global gold print 'You have', gold, 'gold' pass [/code] Okay, now for my problem. In the above function, there's the option to examine a cabinet and get 8 gold. (everyone here knows that...but I'm just trying to state my problem...) Unfortunately, it kind of doesn't work. After the first time I 'examine cabinet 1' in my game, I get 8 gold and I can't get it again. But, If I leave the room and come back to it, then it's as if I had never gotten the gold the first time, and I can get it again. How do I fix this? Thank you! Just downloaded and am about to have a blast into the past with PlanetFall! -- http://mail.python.org/mailman/listinfo/python-list
Re: TypeError: unsupported operand type(s) for /: 'NoneType' and 'NoneType'
On May 1, 5:21 pm, Jordan Harry [EMAIL PROTECTED] wrote: I'm trying to write a simple program to calculate permutations. I created a file called mod.py and put the following in it: def factorial(n): a = n b = n while a0 and b1: n = (n)*(b-1) b = b-1 def perm(n, r): a = factorial(n) b = factorial(n-r) q = a / b print q Then I went back to IDLE and input the following: import mod mod.perm(5, 4) I recieved the following error message: Traceback (most recent call last): File pyshell#1, line 1, in module mod.perm(5, 4) File C:\Python25\mod.py, line 27, in perm q = a / b TypeError: unsupported operand type(s) for /: 'NoneType' and 'NoneType' I have no idea how to fix it. I'm pretty new to Python. I have IDLE 1.2.2 and Python 2.5.2, Please help. Your factorial function needs to return something. ~Sean -- http://mail.python.org/mailman/listinfo/python-list
setattr() on object instance
Why is it that you can setattr() on an instance of a class that inherits from object, but you can't on an instance of object itself? o = object() setattr(o, x, 1000) Traceback (most recent call last): File stdin, line 1, in module AttributeError: 'object' object has no attribute 'x' class Object(object):pass ... o = Object() setattr(o, x, 1000) o.x 1000 I notice that the first example's instance doesn't have a __dict__. Is the second way the idiom? ~Sean -- http://mail.python.org/mailman/listinfo/python-list
Re: How to run PyOS_InputHook from python code (i.e. yield to event loops)
On Sep 6, 1:00 pm, [EMAIL PROTECTED] (Ville M. Vainio) wrote: Background: PyOS_InputHook is something that gets run when python is doing raw_input. TkInter and friends use it to run their event loops, so that their events are handled while python is doing raw_input. What I'd like to do is run the same function without having to do raw_input. I.e. I'd like to run whatever event loop is available, without incorporating any gui-specific code (PyOS_InputHook seems like a nifty way to accomplish this). My actual use case is to keep a tkinter application responsive while launching a background process (and waiting for it to complete!). My eventual code would be something like: launch_process_in_thread('bzr pull') while not is_done: pyos_inputhook() time.sleep(0.1) print Done! I'm still recovering from a hangover, so don't quote me. I think you want the after function: launch_process_in_thread('bzr pull') self.update() def update(self): while not self.is_done: self.after(2000, self.update) -- http://mail.python.org/mailman/listinfo/python-list
Re: Catching subprocess stdout stream
On Sep 8, 8:37 am, Thomas Jansson [EMAIL PROTECTED] wrote: Dear all I have tkinkter based frontend to a Fortran based program. I use subprocess to launch the fortran program as a child process and I wish to see the output of the fortran program as it is created in the console. The fortran program can take up to 20 minuttes to finish and at the moment the I will first see any output after the fortran program is done. How make my function write the output of the process as it comes? def runprogram(Icommand, Ijobfile, Ioutput): if os.name == posix: os.system(pythonpath+/bin/+Icommand+ +Ijobfile+ | tee +Ioutput) elif os.name == nt: import subprocess ofile = open(Ioutput, 'w') p = subprocess.Popen([os.path.join(pythonpath, bin, Icommand + '.exe')], stdin=open(Ijobfile, rb),bufsize=1024,shell=False, stdout=subprocess.PIPE) while p.poll() is None: #Check if child process has terminated. o = p.stdout.readline() ofile.writelines(o) print o, ofile.close Kind regards Thomas Jansson import threading, Queue, subprocess class iCommand(threading.Thread): def __init__ (self, iCommand, iJobFile, queue): threading.Thread.__init__(self) self.iCommand = iCommand self.queue = queue self.iJobFile = iJobFile def run(self): p = subprocess.Popen([os.path.join(C:/Python25, bin, self.iCommand + '.exe')], stdin=open(self.iJobFile, rb),bufsize=1024,shell=False, stdout=subprocess.PIPE) while p.poll() == None: q.put(p.stdout.readline()) command = FOO jobFile = =FAH aQueue = Queue.Queue() fo = open(C:/temp/foo.out, 'w') aThread = iCommand(command, jobFile, aQueue) aThread.start() while aThread.isAlive() or not aQueue.empty(): l = aQueue.get().rstrip() fo.write(l) print l fo.close() A bit of fun for a sleepless night... ~Sean -- http://mail.python.org/mailman/listinfo/python-list
Re: formating a filesystem with python
On Sep 10, 1:57 pm, Ricardo Tiago [EMAIL PROTECTED] wrote: Hi all, is there a package in python that allows to mount/umount and format (to ext3) a filesystem? I know that this is possible by just calling the os commands 'mount/umount and mkfs' but this would imply to have to change sudoers to run the script as non-root. Thanks Ric You can use pexpect to become root without changing sudoers. Assuming you know the root password... ~Sean -- http://mail.python.org/mailman/listinfo/python-list
Re: PLEASE HELP ME WITH THIS ASSIGNMENT...PLEASE....
On Sep 10, 3:33 pm, Daniel Fetchinson [EMAIL PROTECTED] wrote: I know I'm to late to ask you for helpbut please help me out..I am really new to unix and dont know how to finish this assignment on time.proff. said he will be using MOSS to detect whether I downloaded the code..please help me.. email me : [EMAIL PROTECTED] Assignment 1 Processes, Inter-Process Communication, and Concurrency Due September 13th midnight Summary In this assignment, you will create two versions of a simple multi-process game : one without and another with inter-process synchronization. You will also measure the relative performance of the two versions of your multi-process game. Objectives * Learn how to create and terminate processes. * Learn use of inter-process communication using shared memory, semaphores, signals, etc. * Learn the basic workings of CPU scheduling code in Linux. Part A: Multi-Process Game of Turns In this part, you are asked to write a simple program that takes two command-line arguments P and N. The main process creates P other child processes, waits for all of them to complete, and then exits. All the child processes form one logical ring among each other. (In rest of the description, the term process refers to a child process.) For example, if the processes are numbered 1 to P, then * The next neighbor of process 1 is process 2, * The next neighbor of process i is process i+1 for all i P , and * The next neighbor of process P is process 1, which completes a ring among the processes. Assume that a shared integer variable, called turn, identifies the number of the processes whose turn it is at any instant. A second process-local variable in each process, called me, identifies the identity of each process (i.e. each process stores its own identity in a per-process local variable me). A third per-process local variable, called next, identifies the next process in the ring. The processes sequentially pass the turns among each other in the logical ring. When each process gets its turn, it increments another shared variable called counter. The pseudo-code within each process for passing turns might look something as follows. (Note: Replace turn and counter below with appropriate ways of accessing data within shared memory regions). while(turn != me ) /* do nothing - just busy loop*/ ; /* got my turn - increment counter */ counter = counter + 1; /* give the turn to next process */ turn = next; The program terminates when the each process has received N turns. In the above description, several programming details have been omitted for you to figure out. This includes * Creating P child processes from main process. * Constructing the logical ring among child processes. o Initializing each child process's identity in the me variable. o Initializing each child process' next neighbor in the next variable. * Initializing the shared memory region and the shared data values. * Have the main process wait for child processes to complete N turns before exiting. Part B: More Efficient Game of Turns You might notice that the program you wrote in Part A is inefficient because each process busy loops till the CPU scheduler kicks it out (after its time-slice is over) and allows another process to execute and make progress. (Does the program in Part A have a race condition? Why or why not?) What we ideally want is that each process should be given control of the CPU only when it is that process' turn. Modify the program you wrote in Part A (using appropriate synchronization mechanisms) such that each process gets to run (i.e., gets control of the CPU) only when it is that process's turn, and at no other time. Again, you would need to work out the programming details of how and where to use inter-process synchronization. Part C: Profiling the Game of Turns In this part, you are asked to write user-level profiling code in order to measure the performance of the two versions of programs you wrote in Part A and Part B. Use a combination of gettimeofday() system call and inter-process synchronization to measure (1) the average hand-over time between two consecutive processes in the ring and (b) the total execution time to complete N turns. Plot the measured values as graphs when varying number of processes P and number of turns N. Explain the results you obtain. Submission Guidelines Thanking you, Ms. Vaidehi Pawar How much do you pay? Cheers, Daniel -- Psss, psss, put it down! -http://www.cafepress.com/putitdown Maybe. If I cant sleep tonite. -- http://mail.python.org/mailman/listinfo/python-list
Re: SSH using PEXPECT
On Sep 10, 6:04 pm, [EMAIL PROTECTED] wrote: Hey , I need to SSH into a server .. (10.8.42.38) using pexpect the username is 'admin' and password is 'abc123' so far i have the following code import pexpect import sys import time import os foo = pexpect.spawn('ssh [EMAIL PROTECTED]') ssh_newKey = 'Are you sure you want to continue connecting' foo.expect = ssh_newKey foo.send = 'yes' foo.expect = 'password:' foo.send = 'abc123' --- -- does this look right? if not , could someone suggest a way to do this .. your help is much appreciated https://svn.lal.in2p3.fr/projects/CMT/CMTManagement/utils/ssh_session.py I use a modified version of this. Simple and effective. import ssh_session ssh = ssh_session.ssh_session(user, host, password) print ssh.ssh(ls -l /tmp) Thanks Eric and Nigel! ~Sean -- http://mail.python.org/mailman/listinfo/python-list
Re: Python platform.
On Sep 11, 9:59 am, Fredrik Lundh [EMAIL PROTECTED] wrote: [EMAIL PROTECTED] wrote: I want to build a desktop application. I am searching for some kind of environment that would provide all the elements ready (Windows...). Then I would have to code the business logic only. start here: http://wiki.python.org/moin/GuiProgramming The big ones are Tkinter, which is usually bundled with Python; wxPython, and PyQt. There's also a trend towards using the web browser as a presentation engine also for local applications; for libraries that help you with that, you can start here: http://wiki.python.org/moin/WebProgramming or jump directly to http://www.djangoproject.com/ /F I saw a message in the last few days showing how to use Flash as a front end for Python apps. It looked interested. Can anyone point me to it? ~Sean -- http://mail.python.org/mailman/listinfo/python-list
Re: Python platform.
On Sep 11, 11:39 am, Sean DiZazzo [EMAIL PROTECTED] wrote: On Sep 11, 9:59 am, Fredrik Lundh [EMAIL PROTECTED] wrote: [EMAIL PROTECTED] wrote: I want to build a desktop application. I am searching for some kind of environment that would provide all the elements ready (Windows...). Then I would have to code the business logic only. start here: http://wiki.python.org/moin/GuiProgramming The big ones are Tkinter, which is usually bundled with Python; wxPython, and PyQt. There's also a trend towards using the web browser as a presentation engine also for local applications; for libraries that help you with that, you can start here: http://wiki.python.org/moin/WebProgramming or jump directly to http://www.djangoproject.com/ /F I saw a message in the last few days showing how to use Flash as a front end for Python apps. It looked interested. Can anyone point me to it? ~Sean Ahh...i see. It was the xml-rpc method you mentioned. Looks interesting to me if it's fairly responsive for normal gui apps. http://www.artima.com/weblogs/viewpost.jsp?thread=208528 ~Sean -- http://mail.python.org/mailman/listinfo/python-list
Re: Good python web programming books
On Sep 12, 6:08 pm, Chris Rebert [EMAIL PROTECTED] wrote: I've heard good things about The Django Book:http://www.djangobook.com/ - Chris On Fri, Sep 12, 2008 at 5:57 PM, bhaarat Sharma [EMAIL PROTECTED] wrote: Hi Guys, I am very new to python. I am looking for a good book about python web programming. I looked at a few online like Web Programming In Python but most are quite old. If you've read a good book on python web programming can you please suggest some? Thanks -- http://mail.python.org/mailman/listinfo/python-list -- Follow the path of the Iguana...http://rebertia.com Im exploring TurboGears and loving it. However I don't know how well you will do learning a web framework at the same time as the language. Spend a few weeks (at least) learning the language basics from the tutorials, then maybe try Django or TurboGears. You could do some neat stuff with mod_python as a beginner, so maybe start there. http://docs.python.org/tut/ http://diveintopython.org/ http://www.modpython.org/ http://www.turbogearsbook.com/ Good luck! m2c, ~Sean -- http://mail.python.org/mailman/listinfo/python-list
Re: Good programming style
On Sep 14, 7:10 pm, Grant Edwards [EMAIL PROTECTED] wrote: On 2008-09-15, Ben Finney [EMAIL PROTECTED] wrote: Grant Edwards [EMAIL PROTECTED] writes: On 2008-09-14, Ben Finney [EMAIL PROTECTED] wrote: Second: please do yourself a favour and drop the camelCaseNames. Follow PEP 8 URL:http://www.python.org/dev/peps/pep-0008 for style and naming in your Python code. If he finds camelcase more readable and easier to type (as do I), how is switching to underscores doing himself a favor? I'm generally in favor of using a consistent naming style throughout a project, but I don't see why the naming style used in my source code should be subject to somebody else's arbitrary standard. Because the code we write rarely stays isolated from other code. There is an existing convention, There are many existing conventions. and it's better to pick a (sufficiently sane) style convention and stick to it than argue about what the convention should be. I suppose if everybody agreed to pick one, and all the source code in the world was changed to meet it, that would a good thing. It just seems like a goal so unrealistic as to make it a bit of an overstatement to tell people they're better off following convention X than following convention Y. When packages as significant as wxPython use naming conventions other than PEP 8, I find it hard to make a case that the PEP 8 naming convention is any better than any other. When it comes to writing code intended for the standard library in the main Python distribution, I would certainly defer to the existing standard as defined in PEP 8. However, I don't see any reason that style should be imposed on all everybody else. Who's imposing? I'm saying it's a good idea for everyone to do it, and going so far as to say that one is doing oneself a favour by following the convention. I have no more power than you to impose convention on anyone. My apologies -- impose was too strong a word to use. If we were starting from scratch and there was no extant source code in the world, then it would make sense to encourage everybody to pick one convention. [I still think it would be rather quixotic.] But, there are so many projects out there with naming conventions other than PEP 8, that I don't see how there's an advantage to picking one over another (except for the obvious also-rans like all upper case, no vowels, and a maximum length of 6 characters). I'll agree that sticking with a single convention within a project is definitely a good thing. I'm personally aware of mixed/camel-case projects from 25+ years ago, so I'm afraid PEP 8 came along a bit too late... -- Grant +1 CamelCase FTW! ~Sean -- http://mail.python.org/mailman/listinfo/python-list
Re: explain slice assignment to newb
On Sep 20, 2:20 pm, Andrew [EMAIL PROTECTED] wrote: please explain this behavior to a newb: a = [1,2,3,4] b = [a,b,c,d] a [1, 2, 3, 4] b ['a', 'b', 'c', 'd'] a[0:2] [1, 2] a [1, 2, 3, 4] b[2:4] ['c', 'd'] a[0:2] = b[0:2] b[2:4] = a[2:4] a ['a', 'b', 3, 4] b ['a', 'b', 3, 4] What else would you expect to happen? -- http://mail.python.org/mailman/listinfo/python-list
Re: appending * to glob returns files with '*' !!
On Sep 19, 1:37 pm, John [H2O] [EMAIL PROTECTED] wrote: I have a glob.glob search: searchstring = os.path.join('path'+'EN*') shouldn't that be os.path.join(path, 'EN*') ? ___ This returns some files: EN082333 EN092334 EN* Mine doesn't return that last string. My routine cannot handle the '*' and it should'nt be returned anyway? :-/ Well, its an easy fix. files = glob.glob(searchstring) for f in files: if not f[-1] ==*: print f A bug? Post a small *tested* example that recreates the error on your system. ~Sean -- http://mail.python.org/mailman/listinfo/python-list
Re: Folder Actions on Mac OSX Leopard?
On Sep 24, 12:31 pm, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: Greetings, I've been trying to figure out if it's possible to attach a Python script to an action via Mac OSX Leopard's File Actions system. I'm wanting to call a Python script every time a file is added to the monitored folder. Just adding a .py file doesn't seem to do anything at all, and I can't find any log output anywhere to see what's going on. I'm more just looking to see if this is or is not possible. I'm not interested in other solutions, as I already have them lined up in case this is a no-go, but I'd really love to be able to do it this way if anyone has any experience. Googling around revealed pretty much nothing. Any help is much appreciated, Greg I always wondered about Folder Actions... I just tested. You can have applescript call python scripts via `do shell script`. But it seemed a bit flakey. I would either go with applescript all the way, or look in to your other options. ~Sean -- http://mail.python.org/mailman/listinfo/python-list
Re: empty csv file attachments
On Sep 24, 1:17 pm, Bobby Roberts [EMAIL PROTECTED] wrote: hi group. I'm new to python but a veteran at programming. This one has me stumped. I have a simple contact form which the user fills out. The email is sent to the site user as well and it is delivered with the content in the body of the email as well in nice order. I have modified my code to also send the content as a csv attachment. On the server, the file is perfectly generated with content. The attachment, however, is completely blank. Any ideas what that could be? My code snippet is shown below: if int(attachmenttype)==2 or int(attachmenttype)==3: for field in ctx.request.field_names(): if field=='last_name': myfilename=ctx.request.field_value(field)+'.txt' if myfilename=='': myfilename='tempfile.txt' mypath= mynewfilepath + '/' + myfilename f=open(mypath, 'w') mynewstring='' counter=0 for field in ctx.request.field_names(): if field != 'inquiry_required': mynewstring=mynewstring + field +',' if mynewstring[-1]==',': mynewstring=mynewstring[0:len(mynewstring)-1] f.write(mynewstring) f.write ('\n') mynewstring='' counter=1 for field in ctx.request.field_names(): fielddata=ctx.request.field_value(field) if counter==1: dummydata=0 else: mynewstring=mynewstring + '' + fielddata.replace('','') + ',' counter = counter + 1 if mynewstring[-1]==',': mynewstring=mynewstring[0:len(mynewstring)-1] f.write(mynewstring) f.write('\n') f.close attachments.append('/'.join((ctx.request.library, myfilename))) [snip... sends email just after this] any ideas? I would sprinkle some print statements in there to narrow it down... ~Sean -- http://mail.python.org/mailman/listinfo/python-list
Re: Off topic: Sent from my Foo messages
-- Steven I don't appreciate the two lines you put above your name in your posts. Please remove them in the future. ~Sean -- http://mail.python.org/mailman/listinfo/python-list
Re: SimpleXMLRPCServer -- turning off request log?
On Sep 25, 6:01 pm, [EMAIL PROTECTED] wrote: My SimpleXMLRPCServer program prints to stderr a line like this for each request: ohm..pixar.com - - [25/Sep/2008 17:57:50] POST /RPC2 HTTP/1.0 200 - Is there a way to turn this logging off? I have RTFM and can't seem to find a way to do so. Many TIA! Mark -- Mark Harrison Pixar Animation Studios Im pretty sure there's a more pythonic way, but you could redirect stdout to /dev/null import sys sys.stdout = open(/dev/null, 'w') assuming you're not on windows... ~Sean -- http://mail.python.org/mailman/listinfo/python-list
Re: SimpleXMLRPCServer -- turning off request log?
On Sep 25, 9:04 pm, Sean DiZazzo [EMAIL PROTECTED] wrote: On Sep 25, 6:01 pm, [EMAIL PROTECTED] wrote: My SimpleXMLRPCServer program prints to stderr a line like this for each request: ohm..pixar.com - - [25/Sep/2008 17:57:50] POST /RPC2 HTTP/1.0 200 - Is there a way to turn this logging off? I have RTFM and can't seem to find a way to do so. Many TIA! Mark -- Mark Harrison Pixar Animation Studios Im pretty sure there's a more pythonic way, but you could redirect stdout to /dev/null import sys sys.stdout = open(/dev/null, 'w') assuming you're not on windows... ~Sean Here's the more pythonic version: # Fake a file handle with the write method class NullDevice(object): def write(self, s): pass import sys sys.stdout = NullDevice() * http://code.activestate.com/recipes/278731/ Comment 1: attributed to Mr. Lundh ~Sean -- http://mail.python.org/mailman/listinfo/python-list
Re: Writing a well-behaved daemon
On Sep 25, 10:08 pm, Ben Finney [EMAIL PROTECTED] wrote: Howdy all, Writing a Python program to become a Unix daemon is relatively well-documented: there's a recipe for detaching the process and running in its own process group. However, there's much more to a Unix daemon than simply detaching. At a minimum, a well-behaved Unix daemon must at least: * Detach the process into its own process group * Close stdin, redirect stdout and stderr to a null device * Handle its own PID file: refuse to start if the PID file already exists, write the PID file on startup otherwise, and remove the PID file on termination * Revoke setuid and setgid privileges, which are strongly deprecated these days * Handle interrupts, cleaning up the process and PID file as necessary * (possible others) There are also many other commonly-expected tasks that well-behaved Unix daemons perform (drop privileges to a nominated non-root user and group after daemonising, redirect output to syslog instead, operate in a chroot jail, respawn when terminated, etc.). All of this stuff has been done numerous times before, and the basics are mostly agreed upon. Yet all of these are tricky to implement correctly, and tedious to re-implement in every program intended to run as a daemon. The 'daemon' program URL:http://www.libslack.org/daemon/ covers all these, and allows an arbitrary process to be started as a well-behaved Unix daemon process. It's not a good assumption that this program is installed on an arbitrary system though, and it seems excessive to ask the recipient of one's program to get a third-party program just in order to make a daemon process. I'd love to be able to have something similar for Python programs, e.g. a 'become_well_behaved_daemon()' function that implements all the above and perhaps takes optional arguments for the optional features. My searches for such functionality haven't borne much fruit though. Apart from scattered recipes, none of which cover all the essentials (let alone the optional features) of 'daemon', I can't find anything that could be relied upon. This is surprising, since I'd expect this in Python's standard library. Can anyone point me to the equivalent of the 'daemon' program in the form of a well-tested Python library? -- \ “Tis more blessed to give than to receive; for example, wedding | `\ presents.” —Henry L. Mencken | _o__) | Ben Finney http://code.activestate.com/recipes/66012/ I actually use a brew of the original recipe combined with several of the great comments. The commenters add alot of the functionality that you are looking for. It works very well on most counts, but doesn't handle being killed well. The daemons often last for a few weeks to a month before something unexpected kills them off. If I was more careful, I think they could live much longer. Looks like somebody did the same thing I did and posted it. http://svn.plone.org/svn/collective/bda.daemon/trunk/bda/daemon/daemon.py ~Sean -- http://mail.python.org/mailman/listinfo/python-list
Re: Writing a well-behaved daemon
On Sep 26, 12:13 am, Ben Finney [EMAIL PROTECTED] wrote: Sean DiZazzo [EMAIL PROTECTED] writes: Looks like somebody did the same thing I did and posted it. http://svn.plone.org/svn/collective/bda.daemon/trunk/bda/daemon/daemo... Thanks, I've not seen that before. It still seems loony to me that something this difficult to do right, yet so similar across different use cases, isn't in the standard library, where bugs need only be fixed in one place. -- \ “Pinky, are you pondering what I'm pondering?” “Wuh, I think | `\ so, Brain, but how will we get three pink flamingos into one | _o__) pair of Capri pants?” —_Pinky and The Brain_ | Ben Finney +1 I think it would be a great addition. -- http://mail.python.org/mailman/listinfo/python-list
Re: how to search multiple textfiles ?
On Sep 26, 6:35 am, Stef Mientki [EMAIL PROTECTED] wrote: hello, I want to search multiple textfiles (python source files) for a specific word. I can find all files, open them and do a search, but I guess that will be rather slow. I couldn't find any relevant information through google. Does anyone know of a search library that performs this task fast ? If it indeed only concerns py-files, is there another way of searching words ? ( I could imagine that such a py-only-search would have benefits, because you could set a flag to see the words in comment yes or no ) thanks, Stef Mientki Het UMC St Radboud staat geregistreerd bij de Kamer van Koophandel in het handelsregister onder nummer 41055629. The Radboud University Nijmegen Medical Centre is listed in the Commercial Register of the Chamber of Commerce under file number 41055629. I use 'fgrep' ie... `fgrep -r toFind /source` ~Sean -- http://mail.python.org/mailman/listinfo/python-list
Re: check if file is MS Word or PDF file
On Sep 27, 4:01 pm, Chris Rebert [EMAIL PROTECTED] wrote: On Sat, Sep 27, 2008 at 3:42 PM, Michael Crute [EMAIL PROTECTED] wrote: On Sat, Sep 27, 2008 at 5:43 PM, A. Joseph [EMAIL PROTECTED] wrote: What should I look for in a file to determine whether or not it is a MS Word file or an Excel file or a PDF file, etc., etc.? including Zip files I don`t want to check for file extension. os.path.splitext('Filename.jpg') will produce a tuple of filename and extension, but some file don`t even have extension and can still be read by MS Word or NotePad. i want to be 100% sure of the file. You could use the mimetypes module... import mimetypes mimetypes.guess_type(LegalNotices.pdf) ('application/pdf', None) Looking at the docs for the mimetypes module, it just guesses based on the filename (and extension), not the actual contents of the file, so it doesn't really help the OP, who wants to make sure their program isn't misled by an inaccurate extension. Regards, Chris -- Follow the path of the Iguana...http://rebertia.com -mike -- Michael E. Crute http://mike.crute.org God put me on this earth to accomplish a certain number of things. Right now I am so far behind that I will never die. --Bill Watterson -- http://mail.python.org/mailman/listinfo/python-list Check http://sourceforge.net/project/showfiles.php?group_id=23617 for the 'file' command for Windows. ~Sean -- http://mail.python.org/mailman/listinfo/python-list
Re: Web programming in Python.
On Sep 28, 4:51 pm, Kurda Yon [EMAIL PROTECTED] wrote: 1. On my server (in my directory) I found cgi-bin subdirectory. 2. In the cgi-bin I have created a file test.py. 3. In that file I put: #!/usr/bin/python2.4 python print Hello, World! (I have checked, I have /usr/bin/python2.4 directory.) 4. I give the following permissions to the test.py: -rwx---r-x 5. The cgi-bin directory has the following permissions: drwx---r-x 6. In the cgi-bin I have created the .htaccess file which contains: Options +ExecCGI AddHandler cgi-script .py And it still does not work! If I try to see the page by my browser I see: Internal Server Error The server encountered an internal error or misconfiguration and was unable to complete your request. ... Your server logs are your friend. Check /var/log/httpd/error.log for errors. Have you loaded the modpython module in your httpd.conf? ~Sean -- http://mail.python.org/mailman/listinfo/python-list
Re: PYTHON WORKING WITH PERL ??
On Sep 29, 12:44 pm, Blubaugh, David A. [EMAIL PROTECTED] wrote: Sir, You are absolutely correct. I was praying to G_d I did not have to slaughter my project's source code in this manner. However, like life itself, I was given legacy source code (i.e. someone else errors to fix) in Perl. However, I have just found out that there is a way to import the Perl interpreter within Python!!! I now believe I can utilize python as the main platform to develop the project upon !! Thanks, David -Original Message- From: D'Arcy J.M. Cain [mailto:[EMAIL PROTECTED] Sent: Monday, September 29, 2008 1:32 PM To: Blubaugh, David A. Cc: [EMAIL PROTECTED] Subject: Re: PYTHON WORKING WITH PERL ?? On Mon, 29 Sep 2008 13:16:14 -0400 Blubaugh, David A. [EMAIL PROTECTED] wrote: I was wondering if it was possible to have a situation where a programming project would utilized BOTH python and perl? Such as utilizing python for internet programming and then utilize perl for text processing and systems programming? Is this even feasible??? I don't see why not but I also question if it is a good idea. Once you have all your objects and low level methods written in Python it just makes sense to re-use them rather than trying to duplicate the functionality in another language. Of course, sometimes we don't have control over our entire environment so yes, you can mix them if you have to. Rewrite everything in python. Save yourself now...while you still can. ~Sean -- http://mail.python.org/mailman/listinfo/python-list
Re: python sms
On Sep 29, 8:47 pm, sui [EMAIL PROTECTED] wrote: Hii i want a script to send sms to any mobile. can u help me ?? Thanks in advance.. Must...be...smarter...than...cell...phone... -- http://mail.python.org/mailman/listinfo/python-list
Re: using SSh problem!
On Oct 2, 3:27 am, sa6113 [EMAIL PROTECTED] wrote: No, my problem isn't entering password or not ? I want to know what should I do to connect between different platform and copy a file . Lawrence D'Oliveiro wrote: In message [EMAIL PROTECTED], sa6113 wrote: I want to connect form a windows machine to a Linux one using SSH (I use Paramiko) and simply copy a file to Linux machine. Do you want to be able to connect without having to enter a password? You'll need to set up a public/private key pair for that. -- http://mail.python.org/mailman/listinfo/python-list -- View this message in context:http://www.nabble.com/using-SSh-problem%21-tp19775680p19776775.html Sent from the Python - python-list mailing list archive at Nabble.com. I do it by wrapping plink. http://www.chiark.greenend.org.uk/~sgtatham/putty/ I believe you can also install a version of OpenSSH on Windows. ~Sean -- http://mail.python.org/mailman/listinfo/python-list
Re: Using subprocess module to launch a shell shell script that itself forks a process
On Oct 8, 11:24 am, Samuel A. Falvo II [EMAIL PROTECTED] wrote: On Oct 7, 6:23 pm, Gabriel Genellina [EMAIL PROTECTED] wrote: Is your shell script doing something else, apart from invoking the java process? Obviously, yes. The script is some 150 lines long. But the hang-up occurs because of the forked Java process, not the other lines. If not, you could just invoke java directly from Python. Also, you set stdin=PIPE - is your java process expecting some input? you're not writing anything to stdin. It does not expect input from stdin. However, this does not affect any OTHER scripts or commands I run. Let's remember to look at the objective facts: for shell scripts that launch child processes of their own, Python hangs. For all other types of commands, it works 100% as expected. Anyway, it's better to use the communicate method instead (it uses select to read from both stdout and stderr): That doesn't help me. See http://docs.python.org/library/subprocess.html#subprocess.Popen.commu... I have. You should be nicer to Gabriel. He is a guru. -- http://mail.python.org/mailman/listinfo/python-list
Re: Developing for Python (2.x or 3)?
I would use 2.5.2 or 2.6. I don't think 3 is anywhere near stable yet. Paulo J. Matos wrote: Hi all, I am in the process of choosing which Python version for a brand new application. Van Rossum in an interview recently advised all new applications to use Python3 but I am afraid, most libraries (PyGtk, PyQt, Networking Libs, etc) won't follow suit to 3.0 and I will end up using a version of the language which can't connect to libraries because they haven't been ported yet. Should this be a concern? Cheers, -- Paulo Jorge Matos - pocmatos at gmail.com Webpage: http://www.personal.soton.ac.uk/pocm -- http://mail.python.org/mailman/listinfo/python-list
Re: How to open a shell prompt from an existing shell prompt
On Oct 21, 4:52 am, gaurav kashyap [EMAIL PROTECTED] wrote: Dear all, I have a file in which i have written some shell commands to execute. Herein i require to open another shell prompt from this file. or simply i want to open a new shell prompt from an existing shell prompt. How could this be achieved. Thanks Check the subprocess module -- http://mail.python.org/mailman/listinfo/python-list
Python for Kids
Pretty cool!! Our base will be *much* bigger in about twenty years. I remember doing Basic on my dads Apple IIe. http://wiki.laptop.org/go/Pippy#Summary -- http://mail.python.org/mailman/listinfo/python-list
Re: Determining when a file has finished copying
On Jul 9, 5:34 pm, keith [EMAIL PROTECTED] wrote: -BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Ethan Furman wrote: writeson wrote: Guys, Thanks for your replies, they are helpful. I should have included in my initial question that I don't have as much control over the program that writes (pgm-W) as I'd like. Otherwise, the write to a different filename and then rename solution would work great. There's no way to tell from the os.stat() methods to tell when the file is finished being copied? I ran some test programs, one of which continously copies big files from one directory to another, and another that continously does a glob.glob(*.pdf) on those files and looks at the st_atime and st_mtime parts of the return value of os.stat(filename). From that experiment it looks like st_atime and st_mtime equal each other until the file has finished being copied. Nothing in the documentation about st_atime or st_mtime leads me to think this is true, it's just my observations about the two test programs I've described. Any thoughts? Thanks! Doug The solution my team has used is to monitor the file size. If the file has stopped growing for x amount of time (we use 45 seconds) the file is done copying. Not elegant, but it works. -- Ethan Also I think that matching the md5sums may work. Just set up so that it checks the copy's md5sum every couple of seconds (or whatever time interval you want) and matches against the original's. When they match copying's done. I haven't actually tried this but think it may work. Any more experienced programmers out there let me know if this is unworkable please. K -BEGIN PGP SIGNATURE- Version: GnuPG v1.4.6 (GNU/Linux) Comment: Using GnuPG with Mozilla -http://enigmail.mozdev.org iD8DBQFIdVkX8vmNfzrLpqoRAsJ2AKCp8wMz93Vz8y9K+MDSP33kH/WHngCgl/wM qTFBfyIEGhu/dNSQzeRrwYQ= =Xvjq -END PGP SIGNATURE- I use a combination of both the os.stat() on filesize, and md5. Checking md5s works, but it can take a long time on big files. To fix that, I wrote a simple sparse md5 sum generator. It takes a small number bytes from various areas of the file, and creates an md5 by combining all the sections. This is, in fact, the only solution I have come up with for watching a folder for windows copys. The filesize solution doesn't work when a user copies into the watch folder using drag and drop on Windows because it allocates all the attributes of the file before any data is written. The filesize will always show the full size of the file. ~Sean -- http://mail.python.org/mailman/listinfo/python-list
RegExp Help
Hi group, I'm wrapping up a command line util that returns xml in Python. The util is flaky, and gives me back poorly formed xml with different problems in different cases. Anyway I'm making progress. I'm not very good at regular expressions though and was wondering if someone could help with initially splitting the tags from the stdout returned from the util. I have the following example string, and am simply trying to split it into two xml tags... simplified = 2007-12-13 tag1 attr1=text1 attr2=text2 /tag1 \n2007-12-13 tag2 attr1=text1 attr2=text2 attr3=text3\n /tag2 \n Basically I want the two tags, and to discard anything in between using a reg exp. Like this: tags = [tag1 attr1=text1 attr2=text2 /tag1, tag2 attr1=text1 attr2=text2 attr3=text3\n /tag2] I've tried several approaches, some of which got close, but the newline in the middle of one of the tags screwed it up. The closest I've been is something like this: retag = re.compile(r'.+*') # tried here with re.DOTALL as well tags = re.findall(retag) Can anyone help me? ~Sean -- http://mail.python.org/mailman/listinfo/python-list
Re: RegExp Help
On Dec 13, 5:49 pm, Sean DiZazzo [EMAIL PROTECTED] wrote: Hi group, I'm wrapping up a command line util that returns xml in Python. The util is flaky, and gives me back poorly formed xml with different problems in different cases. Anyway I'm making progress. I'm not very good at regular expressions though and was wondering if someone could help with initially splitting the tags from the stdout returned from the util. I have the following example string, and am simply trying to split it into two xml tags... simplified = 2007-12-13 tag1 attr1=text1 attr2=text2 /tag1 \n2007-12-13 tag2 attr1=text1 attr2=text2 attr3=text3\n /tag2 \n Basically I want the two tags, and to discard anything in between using a reg exp. Like this: tags = [tag1 attr1=text1 attr2=text2 /tag1, tag2 attr1=text1 attr2=text2 attr3=text3\n /tag2] I've tried several approaches, some of which got close, but the newline in the middle of one of the tags screwed it up. The closest I've been is something like this: retag = re.compile(r'.+*') # tried here with re.DOTALL as well tags = re.findall(retag) Can anyone help me? ~Sean I found something that works, although I couldn't tell you why it works. :) retag = re.compile(r'.+?', re.DOTALL) tags = retag.findall(retag) Why does that work? ~Sean -- http://mail.python.org/mailman/listinfo/python-list
Elementtree tag
I have a another question... using elementtree, is there a proper way to get at the data '123456789' in this tag? 'id 123456789 /' I tried making it an element, but the only attribute that returns anything is the tag attribute. Does that section of a tag have any proper name that I'm missing? Or is it just bad XML style? Thanks! ~Sean -- http://mail.python.org/mailman/listinfo/python-list
Re: Elementtree tag
On Dec 13, 8:46 pm, Waldemar Osuch [EMAIL PROTECTED] wrote: On Dec 13, 7:52 pm, Sean DiZazzo [EMAIL PROTECTED] wrote: I have a another question... using elementtree, is there a proper way to get at the data '123456789' in this tag? 'id 123456789 /' I tried making it an element, but the only attribute that returns anything is the tag attribute. Does that section of a tag have any proper name that I'm missing? Or is it just bad XML style? It is not even legal xml. This may work. from xml.etree import ElementTree as ET elm = ET.fromstring('atag id=123456789 /') elm Element atag at 1ba2f80 elm.attrib {'id': '123456789'} Thanks. I was afraid of that. Yet another hack for my code. argggh -- http://mail.python.org/mailman/listinfo/python-list
Re: RegExp Help
On Dec 14, 12:04 am, Marc 'BlackJack' Rintsch [EMAIL PROTECTED] wrote: On Thu, 13 Dec 2007 17:49:20 -0800, Sean DiZazzo wrote: I'm wrapping up a command line util that returns xml in Python. The util is flaky, and gives me back poorly formed xml with different problems in different cases. Anyway I'm making progress. I'm not very good at regular expressions though and was wondering if someone could help with initially splitting the tags from the stdout returned from the util. [...] Can anyone help me? Flaky XML is often produced by programs that treat XML as ordinary text files. If you are starting to parse XML with regular expressions you are making the very same mistake. XML may look somewhat simple but producing correct XML and parsing it isn't. Sooner or later you stumble across something that breaks producing or parsing the naive way. Ciao, Marc 'BlackJack' Rintsch It's not really complicated xml so far, just tags with attributes. Still, using different queries against the program sometimes offers differing results...a few examples: id 123456 / tag name=foo / tag2 name=foo moreattrs=... /tag2 tag3 name=foo moreattrs=... tag3/ It's consistent (at least) in that consistent queries always return consistent tag styles. It's returned to stdout with some extra useless information, so the original question was to help get to just the tags. After getting the tags, I'm running them through some functions to fix them, and then using elementtree to parse them and get all the rest of the info. There is no api, so this is what I have to work with. Is there a better solution? Thanks for your ideas. ~Sean -- http://mail.python.org/mailman/listinfo/python-list
Re: RegExp Help
On Dec 14, 3:06 am, Gabriel Genellina [EMAIL PROTECTED] wrote: En Fri, 14 Dec 2007 06:06:21 -0300, Sean DiZazzo [EMAIL PROTECTED] escribió: On Dec 14, 12:04 am, Marc 'BlackJack' Rintsch [EMAIL PROTECTED] wrote: On Thu, 13 Dec 2007 17:49:20 -0800, Sean DiZazzo wrote: I'm wrapping up a command line util that returns xml in Python. The util is flaky, and gives me back poorly formed xml with different problems in different cases. Anyway I'm making progress. I'm not very good at regular expressions though and was wondering if someone could help with initially splitting the tags from the stdout returned from the util. Flaky XML is often produced by programs that treat XML as ordinary text files. If you are starting to parse XML with regular expressions you are making the very same mistake. XML may look somewhat simple but producing correct XML and parsing it isn't. Sooner or later you stumble across something that breaks producing or parsing the naive way. It's not really complicated xml so far, just tags with attributes. Still, using different queries against the program sometimes offers differing results...a few examples: id 123456 / tag name=foo / tag2 name=foo moreattrs=... /tag2 tag3 name=foo moreattrs=... tag3/ Ouch... only the second is valid xml. Most tools require at least a well formed document. You may try using BeautifulStoneSoup, included with BeautifulSouphttp://crummy.com/software/BeautifulSoup/ I found something that works, although I couldn't tell you why it works. :) retag = re.compile(r'.+?', re.DOTALL) tags = retag.findall(retag) Why does that work? That means: look for a less-than sign (), followed by the shortest sequence of (?) one or more (+) arbitrary characters (.), followed by a greater-than sign () If you never get nested tags, and never have a inside an attribute, that expression *might* work. But please try BeautifulStoneSoup, it uses a lot of heuristics trying to guess the right structure. Doesn't work always, but given your input, there isn't much one can do... -- Gabriel Genellina Thanks! I'll take a look at BeautifulStoneSoup today and see what I get. ~Sean -- http://mail.python.org/mailman/listinfo/python-list
Keyword args to SimpleXMLRPCServer
Why is the following not working? Is there any way to get keyword arguments working with exposed XMLRPC functions? server.py import SocketServer from SimpleXMLRPCServer import SimpleXMLRPCServer,SimpleXMLRPCRequestHandler # Threaded mix-in class AsyncXMLRPCServer(SocketServer.ThreadingMixIn,SimpleXMLRPCServer): pass class XMLFunctions(object): def returnArgs(*args, **kwargs): return kwargs.items() # Instantiate and bind to localhost:1234 server = AsyncXMLRPCServer(('', 8080), SimpleXMLRPCRequestHandler) # Register example object instance server.register_instance(XMLFunctions()) # run! server.serve_forever() client.py from xmlrpclib import ServerProxy, Error server = ServerProxy(http://localhost:8080;, allow_none=1) # local server try: print server.returnArgs(foo, bar=bar, baz=baz) except Error, v: print ERROR, v [seans-imac:~/Desktop/] halfitalian% ./client.py Traceback (most recent call last): File ./XMLRPC_client.py, line 9, in module print server.returnArgs(foo, bar=bar, baz=baz) TypeError: __call__() got an unexpected keyword argument 'bar' ~Sean -- http://mail.python.org/mailman/listinfo/python-list
Re: Keyword args to SimpleXMLRPCServer
On Dec 17, 4:13 pm, Sean DiZazzo [EMAIL PROTECTED] wrote: Why is the following not working? Is there any way to get keyword arguments working with exposed XMLRPC functions? server.py import SocketServer from SimpleXMLRPCServer import SimpleXMLRPCServer,SimpleXMLRPCRequestHandler # Threaded mix-in class AsyncXMLRPCServer(SocketServer.ThreadingMixIn,SimpleXMLRPCServer): pass class XMLFunctions(object): def returnArgs(*args, **kwargs): return kwargs.items() # Instantiate and bind to localhost:1234 server = AsyncXMLRPCServer(('', 8080), SimpleXMLRPCRequestHandler) # Register example object instance server.register_instance(XMLFunctions()) # run! server.serve_forever() client.py from xmlrpclib import ServerProxy, Error server = ServerProxy(http://localhost:8080;, allow_none=1) # local server try: print server.returnArgs(foo, bar=bar, baz=baz) except Error, v: print ERROR, v [seans-imac:~/Desktop/] halfitalian% ./client.py Traceback (most recent call last): File ./XMLRPC_client.py, line 9, in module print server.returnArgs(foo, bar=bar, baz=baz) TypeError: __call__() got an unexpected keyword argument 'bar' ~Sean PS. The same thing happens if you don't use **kwargs... ... class XMLFunctions(object): def returnArgs(foo, bar=None, baz=None): return foo, bar, baz ... -- http://mail.python.org/mailman/listinfo/python-list
askopenfilename() as root window
Is there any way to open a Tkinter.askopenfilename() without opening a root window alongside the file chooser? I simply want a script to open a dialog and return the chosen file's path to stdout. from tkFileDialog import askopenfilename print askopenfilename() ...does the job, but it opens that nagging root window beside it. I tried setting parent=None to no avail. The second window always shows up. Any ideas? ~Sean -- http://mail.python.org/mailman/listinfo/python-list
Re: askopenfilename() as root window
On Dec 18, 6:06 pm, Gabriel Genellina [EMAIL PROTECTED] wrote: On 18 dic, 22:43, Sean DiZazzo [EMAIL PROTECTED] wrote: Is there any way to open a Tkinter.askopenfilename() without opening a root window alongside the file chooser? I simply want a script to open a dialog and return the chosen file's path to stdout. Yes, create the root yourself so you can call the withdraw() method: root = Tk() root.withdraw() print askopenfilename() -- Gabriel Genellina As usual... Thank you Gabriel. -- http://mail.python.org/mailman/listinfo/python-list
Re: read_nonblocking error in pxssh
Just glanced at the docs, but it might be worth a shot... try: import pxssh s=pxssh.pxssh() s.login(myhost,root,mypass, auto_prompt_reset=False) Maybe??? Otherwise, I have used and modified this script with great success: (ssh_session.py) http://www.koders.com/python/fidA430838E5789710E4DCF34C414AD75EB4EEE63CF.aspx Good luck. ~Sean On Jan 16, 9:24 am, jrpfinch [EMAIL PROTECTED] wrote: I'm attempting to use the pxssh to execute commands on a remote machine and do stuff with the output. Both machines are running SSH Version Sun_SSH_1.0, protocol versions 1.5/2.0 and Intel Solaris 9. I am hitting a problem with read_nonblocking in the pexpect module as follows: import pxssh s=pxssh.pxssh() s.login(myhost,root,mypass) Trying command: ssh -q -l root gerard Expect returned i=2 Expect returned i=1 Traceback (most recent call last): File stdin, line 1, in module File pxssh.py, line 244, in login if not self.synch_original_prompt(): File pxssh.py, line 134, in synch_original_prompt self.read_nonblocking(size=1,timeout=10) # GAS: Clear out the cache before getting the prompt File /opt/python2.5.1/lib/python2.5/site-packages/pexpect.py, line 824, in read_nonblocking raise TIMEOUT ('Timeout exceeded in read_nonblocking().') pexpect.TIMEOUT: Timeout exceeded in read_nonblocking(). Running the ssh command from the shell yields: bash-2.05# ssh -q -l root myhost [EMAIL PROTECTED]'s password: Last login: Wed Jan 16 17:10:32 2008 from x.x.x.x Sun Microsystems Inc. SunOS 5.9 Generic January 2003 Sun Microsystems Inc. SunOS 5.9 Generic January 2003 [EMAIL PROTECTED]:/ # I would be grateful if anyone could make a suggestion as to where I go next? Is read_nonblocking(), the correct method to be using here? Are there any options in pxssh I need to explore (I've tried ssh -t, but this means the password entry fails with raise ExceptionPxssh ('password refused')). Many thanks Jon -- http://mail.python.org/mailman/listinfo/python-list
Re: Doubt
On Jul 23, 7:51 am, ജഗന്നാഥ് [EMAIL PROTECTED] wrote: Friends I am a Perl programmer new to Python. I have a small doubt. How to convert the perl notation $a = ; expression in Python ? How to represent the loop for ($a = $b; $a=$c;$a++){ } in Python Jagan Linguist On most occasions you don't need to use the incrementing loop behavior. Lists are the main data structure comparable to an array, and you can iterate over them without using a counter. If you have: aList = [1, 2, 3] you can do for item in aList: print item Hope this helps. ~Sean -- http://mail.python.org/mailman/listinfo/python-list
Re: applescript/python question
On Aug 1, 5:41 pm, [EMAIL PROTECTED] wrote: I can't seem to figure this out. I just installed Python 2.5.2 a few days ago on my OS X 10.4.11 system. It runs fine and if I type Python -V in the Terminal it outputs Python 2.5.2 which is correct. However, if I try to run a 'do shell script' in AppleScript which I'm wanting to run a Python program, it reverts to using Python 2.3. For example, if I run this code in AppleScript: set p to #!/usr/bin/python import sys print sys.version[:3] set x to do shell script Python -c \ p \ return x I get 2.3. Does anyone have any ideas why AppleScript is using the older version of Python? Is there a way to fix this? Thanks. Jay Change the first line to set p to #!/usr/bin/env python That will execute the default python installation...assuming 2.5.2 is the default. Otherwise, you can change that to the absolute path of the 2.5.2 version. ~Sean -- http://mail.python.org/mailman/listinfo/python-list
Re: Teething troubles with Python on a Mac
Question 1: How can I locate the Python installation? There a few files under Applications MacPython 2.5, but this is clearly not the entire installation. find / -name site-packages Will lead you to where SciPy and Numpy should be installed for each Python installation. You can work backwards from there. Question 2: In Finder, If I click on Search For Past week, I can see a sequence of folders under the horizontal scroll bar at the bottom of the window, allowing me to determine that some files that were placed under Applications MacPython 2.5 Extra Demo. But I do not seem to be able to see the sequence of folders under the horizontal scroll bar in any finder window. What do I need to do to make the folder sequence visible in all Finder Windows? You can do what you want in Leopard, but not in Tiger. I Don't have a Leopard install in front of me. Check Finder-Preferences, or Finder- View-Show View Options Question 4. How do I get MacPython 2.5.2 to see SciPy, NumPy etc. I've had very good luck with easy_install It downloads and installs the right package for your install. http://peak.telecommunity.com/DevCenter/EasyInstall Question 5. How can I find the current value of the PYTHONPATH environment variable, and how can I edit it and add a directory in which I keep my Python programs. I'm not even sure it's set. I have never had to worry about it. Question 6. Apparently there's a Property List Editor that must be used to create a file called ~ /.MacOSX/environment.plist. I can't find a directory called ~/.MacOSX. Is this a hidden directory? It doesn't exist by default, you have to create it. I don't have the format of the environment.plist in front of me, but if I remember correctly, you can create it with any text editor. Or you can download a freeware program to do the whole shebang for you: http://www.versiontracker.com/dyn/moreinfo/macosx/15073 Item 4. I opened a terminal window, and typed ipython. Here's what I got: The ipython/IPython directory should be in a directory belonging to your PYTHONPATH environment variable (that is, it should be in a directory belonging to sys.path). You can copy it explicitly there or just link to it. Question 7. What is this cryptic message all about? I'm completely confused. Try copying the ipython directory into the corresponding site- packages directory from earlier. Otherwise, scrap it and use easy_install. Good luck! ~Sean -- http://mail.python.org/mailman/listinfo/python-list
Re: Why doesn't import work?
On Aug 4, 3:34 pm, ssecorp [EMAIL PROTECTED] wrote: I have in Lib/site-packages a module named pdfminer. when I do import pdfminer it complains: import pdfminer Traceback (most recent call last): File pyshell#3, line 1, in module import pdfminer ImportError: No module named pdfminer I created a file pdfminer.py and put it in site-packages and that works. so I apparently can't import a directory pdfminer. In the directory pdfminer there are 3 other directoriees and inside them python-files. how would I import them? Make packages? I just (finally) got around to learning this the other day... make a file called __init__.py in each of you lib subfolders in each do something like: all = [file1.py, file2.py, file3.py] Then you should be able to import each directory as a package, and access the individual modules. ~Sean -- http://mail.python.org/mailman/listinfo/python-list
Re: Testing for the first few letters of a string
try string1 = My name is alex string2 = My name is alex, and I like pie if string2.startswith(string1): process() or if you want to match a set number of characters you can use a slice: if string2[:15] == string1[:15]: process() or if you dont care where the characters appear in the string, beginning, middle, end, etc: if string2 in string1: process() Theres lots of other ways as well. http://docs.python.org/lib/string-methods.html ~Sean On Aug 7, 8:40 am, Alexnb [EMAIL PROTECTED] wrote: Okay, I have a fix for this problem, but it is messy and I think there might be a better way. Heres an example: Lets say I have a string: My name is alex and I have another string My name is alex, and I like pie. I want to test to see if just the My name is alex part is there. I don't care about the pie part. My first instinct was to just create a for loop and test for the string like this: n = 0 for x in string1: if string1[n] == string2[n] n = n +0 else: break and then later testing to see what n was = to and figuring out if it got through the whole loop. I feel like there should be an easier way to do this, and probably is. So Does anyone have a suggestion? -- View this message in context:http://www.nabble.com/Testing-for-the-first-few-letters-of-a-string-t... Sent from the Python - python-list mailing list archive at Nabble.com. -- http://mail.python.org/mailman/listinfo/python-list
Re: Create a short way to save typing script over and over....
On Aug 7, 11:56 am, frankrentef [EMAIL PROTECTED] wrote: I have a statement url = 'http://xyzserver/' so in my code every time I need to use xyzserver I state url + What I' m now trying to do is create a call to a login process. The script for the login process is below. I'd like to call adminlogin and not have to keep entering the same several lines of script each and everytime (I'm testing various login functions and rule changes.) I'm a newbie, can someone walk me through this? THNX #Login to ISeDeposit Admin ie.navigate (url + 'isweb/admin/default.aspx') ie.textBoxSet ('AdminLogin1:Username','Admin') ie.textBoxSet ('AdminLogin1:inputPassword','Password') ie.buttonClick ('AdminLogin1:btnLogin') def login(url): ie.navigate (url + 'isweb/admin/default.aspx') ie.textBoxSet ('AdminLogin1:Username','Admin') ie.textBoxSet ('AdminLogin1:inputPassword','Password') ie.buttonClick ('AdminLogin1:btnLogin') login(http://xyzserver/;) Maybe? ~Sean -- http://mail.python.org/mailman/listinfo/python-list
Re: SSH utility
On Aug 11, 5:17 am, [EMAIL PROTECTED] wrote: for similar tasks, I use pexpecthttp://pypi.python.org/pypi/pexpect. spawning bash process and simulate an interactive session. Here sending ls command, retrieving results and exiting. In the spawned process ssh or any other command, is just another command. actual session-- $ python Python 2.5.1 (r251:54863, May 18 2007, 16:56:43) [GCC 3.4.4 (cygming special, gdc 0.12, using dmd 0.125)] on cygwin Type help, copyright, credits or license for more information. import pexpect c = pexpect.spawn('/bin/bash') c.expect([pexpect.TIMEOUT, pexpect.EOF, '\$ ']) 2 c.before, c.after ('[EMAIL PROTECTED]:~\r\n', '$ ') c.sendline('ls') 3 c.expect([pexpect.TIMEOUT, pexpect.EOF, '\$ ']) 2 c.before, c.after ('ls\r\x.txt xx.txt xy.txt [EMAIL PROTECTED]:~\r\n', '$ ') c.sendline('exit') 5 c.expect([pexpect.TIMEOUT, pexpect.EOF, '\$ ']) 1 c.before, c.after ('exit\r\nexit\r\n', class 'pexpect.EOF') exit() [EMAIL PROTECTED]:~ $ --- hope that helps. regards. Edwin -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of James Brady Sent: Monday, August 11, 2008 12:26 AM To: [EMAIL PROTECTED] Subject: SSH utility Hi all, I'm looking for a python library that lets me execute shell commands on remote machines. I've tried a few SSH utilities so far: paramiko, PySSH and pssh; unfortunately all been unreliable, and repeated questions on their respective mailing lists haven't been answered... It seems like the sort of commodity task that there should be a pretty robust library for. Are there any suggestions for alternative libraries or approaches? Thanks! James --http://mail.python.org/mailman/listinfo/python-list The information contained in this message and any attachment may be proprietary, confidential, and privileged or subject to the work product doctrine and thus protected from disclosure. If the reader of this message is not the intended recipient, or an employee or agent responsible for delivering this message to the intended recipient, you are hereby notified that any dissemination, distribution or copying of this communication is strictly prohibited. If you have received this communication in error, please notify me immediately by replying to this message and deleting it and all copies and backups thereof. Thank you. I second pexpect and the nice little module that comes with it ssh_session.py. Been using it for ages now! ~Sean -- http://mail.python.org/mailman/listinfo/python-list
Re: searching through a string and pulling characters
On Aug 19, 6:11 am, Wojtek Walczak [EMAIL PROTECTED] wrote: On Mon, 18 Aug 2008 15:34:12 -0700 (PDT), Alexnb wrote: Also, on a side-note, does anyone know a very simple dictionary site, that isn't dictionary.com or yourdictionary.com. This one is my favourite:http://www.lingro.com/ -- Regards, Wojtek Walczak,http://tosh.pl/gminick/ Thats hot! -- http://mail.python.org/mailman/listinfo/python-list
Re: Seeking ideas for a cron implementation
On Aug 22, 1:30 pm, Karthik Gurusamy [EMAIL PROTECTED] wrote: Hi, I'm working on a cron like functionality for my application. The outer loops runs continuously waking every x seconds (say x=180, 300, ..). It needs to know what events in cron has expired and for each event do the work needed. It's basically like unix cron or like a calendar application with some restrictions. The outer loop may come back a lot later and many events might have missed their schedule -- but this is okay.. We don't have to worry about missed events (if there were n misses, we just need to execute call back once). Let's take some examples [Let e denotes an event] e1: hour=1 min=30 # Run every day once at 1:30 AM e2: wday=0, hour=1 min=0 # run every Monday at 1 AM e3: month=10, day=10, hour=10 min=0 # run on October 10th, 10 AM every year class Cron_Event (object): def __init__ (year=None, month=None, day=None, hour=None ..etc) # do init class Cron (object): def __init__ (): # do init def event_add (e): # add an event def execute() # see if any events has expired .. call it's callback # I'm looking for ideas on how to manage the events here From outer loop cron = Cron() # create various events like e1 = Cron_Event(hour=1) cron.event_add(e1) e2 = Cron_Event(wday=0, hour=1) cron.event_add(e2) while True: sleep x seconds (or wait until woken up) cron.execute() # do other work.. x may change here If I can restrict to hour and minute, it seems manageable as the interval between two occurrences is a constant. But allowing days like every Monday or 1st of every month makes things complicated. Moreover I would like each constraint in e to take on multiple possibilities (like every day at 1AM, 2 AM and 4 AM do this). I'm looking for solutions that can leverage datetime.datetime routines. My current ideas include for each e, track the next time it will fire (in seconds since epoch as given by time.time()). Once current time has passed that time, we execute the event. e.g. datetime.datetime.now() datetime.datetime(2008, 8, 22, 13, 19, 54, 5567) time.time() 1219436401.741966 --- compute event's next firing in a format like this The problem seems to be how to compute that future point in time (in seconds since epoch) for a generic Cron_Event. Say how do I know the exact time in future that will satisfy a constraint like: month=11, wday=1, hour=3, min=30 # At 3:30 AM on a Tuesday in November Thanks for your thoughts. Karthik I only scanned your message, but maybe datetime.timedelta() will help.. import datetime now = datetime.datetime.now() print now 2008-08-22 13:48:49.335225 day = datetime.timedelta(1) print day 1 day, 0:00:00 print now + day 2008-08-23 13:48:49.335225 ~Sean -- http://mail.python.org/mailman/listinfo/python-list
Re: Wild Card String Comparison
On Aug 27, 8:49 pm, W. eWatson [EMAIL PROTECTED] wrote: Is it possible to do a search for a wild card string in another string. For example, I'd like to find v*.dat in a string called bingo. v must be matched against only the first character in bingo, and not simply found somewhere in bingo, as might be the case for *v*.dat. -- Wayne Watson (Watson Adventures, Prop., Nevada City, CA) (121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time) Obz Site: 39° 15' 7 N, 121° 2' 32 W, 2700 feet Web Page: www.speckledwithstars.net/ Check: http://docs.python.org/lib/string-methods.html http://docs.python.org/lib/module-re.html http://docs.python.org/lib/module-glob.html http://docs.python.org/lib/module-fnmatch.html ~Sean -- http://mail.python.org/mailman/listinfo/python-list
Access to Windows Add/Remove Programs?
Hi all, I'm trying to find a way to get a list of all the installed programs on a Windows box via Python. I thought of a few hacks that might partially work, and then thought about Add/Remove Programs Seems like the right way to go. I looked over the pywin32 docs a bit, but nothing slapped me in the face. Is there any reliable way to get at that info? Thanks in advance, ~Sean -- http://mail.python.org/mailman/listinfo/python-list
Re: Access to Windows Add/Remove Programs?
On Sep 3, 7:13 pm, Gabriel Genellina [EMAIL PROTECTED] wrote: En Wed, 03 Sep 2008 21:51:59 -0300, Sean DiZazzo [EMAIL PROTECTED] escribi : I'm trying to find a way to get a list of all the installed programs on a Windows box via Python. I thought of a few hacks that might partially work, and then thought about Add/Remove Programs Seems like the right way to go. I looked over the pywin32 docs a bit, but nothing slapped me in the face. Is there any reliable way to get at that info? You may enumerate the entries under this registry key: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall -- Gabriel Genellina Thank both of you. Perfect! ~Sean -- http://mail.python.org/mailman/listinfo/python-list
SQLObject - Connect to established DB with non-int 'id' field
Hi all, I am just beginning with TurboGears and have run into a problem with SQLObject. I'm trying to connect to an established mysql DB, and use TurboGears to display results from the DB only. The problem is that the DB already has an 'id' field that is a string as opposed to an int. SQLObject complains because it wants to use the id field for it's own purposes. How can I use TurboGears to get data out of this DB? Thanks in advance. ~Sean -- http://mail.python.org/mailman/listinfo/python-list
Re: SQLObject - Connect to established DB with non-int 'id' field
On Oct 19, 11:51 pm, Diez B. Roggisch [EMAIL PROTECTED] wrote: Sean DiZazzo schrieb: Hi all, I am just beginning with TurboGears and have run into a problem with SQLObject. I'm trying to connect to an established mysql DB, and use TurboGears to display results from the DB only. The problem is that the DB already has an 'id' field that is a string as opposed to an int. SQLObject complains because it wants to use the id field for it's own purposes. How can I use TurboGears to get data out of this DB? http://sqlobject.org/FAQ.html#non-integer-ids While I personally prefer SQLObject over SQLAlchemy, the latter has better legacy-database-support. Maybe a switch would be the better solution. Diez doh...I swear I looked there! This time I see it. Thanks. ~Sean -- http://mail.python.org/mailman/listinfo/python-list
Re: popen function of os and subprocess modules
On Oct 28, 7:15 am, banu varun.nagp...@gmail.com wrote: On Oct 28, 3:02 pm, Jon Clements jon...@googlemail.com wrote: On 28 Oct, 13:39, banu varun.nagp...@gmail.com wrote: Hi, I am a novice in python. I was trying to write a simple script on Linux (python 3.0) that does the following #cd directory #ls -l I use the following code, but it doesn't work: import os directory = '/etc' pr = os.popen('cd %s' % directory,'w') pr.close() pr = os.popen('ls -l','w') # prints the content of present folder and not '/etc' pr.close() Can anyone suggest me how to fix this simple script? Also what is the use of read(), readlines() and write() functions? Now, I also read in the online python documentation that os.popen is deprecated and no longer recommended in pyhton 3.0. Instead they ask to use subprocess.popen. I am not able to figure out how to accomplish my task with subprocess.poepn also. Can anyone suggest please? Regards Varun If you're only trying to get the contents of a directory, there are more suitable functions - you don't need a separate process. The popen* () commands are deprecated. Try using os.listdir() - can't remember off the top of my head if that's been moved to os.path.listdir() in the 3.* series, but a read of the doc's will set you straight. Ditto for read() and write(). If you describe what you're trying to achieve, maybe we can help more. Also, if you're using 3.0, may I suggest moving to 3.1? hth, Jon. Thanks for the reply Jon Basically I need to move into a folder and then need to execute some shell commands(make etc.) in that folder. I just gave 'ls' for the sake of an example. The real problem I am facing is, how to stay in the folder after popen('cd directory') finishes. It seems trivial, but I am not able to do it. Varun Use subprocess.Popen() with it's cwd argument. Something like: import subprocess p = subprocess.Popen([ls,-l] stdout=subprocess.PIPE, cwd=/etc) print p.stdout.read() ~Sean -- http://mail.python.org/mailman/listinfo/python-list
Re: ImportError: No module named _md5 - Please help
On Oct 29, 8:49 am, wadi wadi wadie...@gmail.com wrote: I can't alter the import statement as the error log is pointing to one of the installed python files 'hashlib.py' /python/2.6.2/lib/python2.6/hashlib.py and I don't have the right permissions to alter the python installation. Any idea? On 10/29/09, Diez B. Roggisch de...@nospam.web.de wrote: Hi, please don't post this to comp.lang.python *and* the python mailinglist. Both are synchronized, so your post shows up twice on both. I am trying to run a python script and got this error. import _md5 ImportError: No module named _md5 I've never seen this import. Normally, it should be import md5 So you might try to alter the import statement to import md5 as _md5 and see if things work. It might be of course that the author of your script provided a home-grown implementation of md5 which has a different interface, and called this _md5 to prevent name-clashes. Then you need to modify your whole script to make it work. Googling the problem suggested that I install the 'py25-hashlib'. the following does not work for me 'sudo port install py25-hashlib' , trying to install MacPorts raised many problems. My question is: any idea on how to install it using yum? I am running python 2.6.2 on a centos machine. I don't understand this - you are talking about ports which is a Mac-thing, but run on centos? However that may be, this *should* be part of core python anyway. If not, you might look in yum for some python-dependency-packages, no idea how to do that though (debian user here) Diez -- http://mail.python.org/mailman/listinfo/python-list -- Wadienil. You are being vague and confusing. There is no default _md5 python library in the standard library. You should be either using import md5 (deprecated) or import hashlib. Unless perhaps the code you show is from inside one of those libraries, and there is a _md5.so that it uses but cant find. Not sure about that. Did you write the code above? Or did you find it inside another file? If you found it inside another file what is the file? If you still have questions, I have another approach. Please cover your palm and fingers with a thick layer of black ink (making sure to cover your entire hand). Press your hand down firmly on a piece of bright white paper. Allow the ink to dry. Finally, scan the page and post it here. I will attempt to read your palm to find the answer. ~Sean -- http://mail.python.org/mailman/listinfo/python-list
Re: substituting list comprehensions for map()
On Nov 2, 9:01 pm, Ben Finney ben+pyt...@benfinney.id.au wrote: Anh Hai Trinh anh.hai.tr...@gmail.com writes: Yes, just about any ‘map()’ operation has a corresponding list comprehension. (Does anyone know of a counter-example, a ‘map()’ operation that doesn't have a correspondingly simple list comprehension?) Try turning this into a list comprehension: vectorsum = lambda *args: map(sum, zip(*args)) By “this” I take you to mean “the usage of ‘map’ in this code”, since that's the limit of my question. vectorsum = lambda *args: [sum(items) for items in zip(*args)] vectorsum([1,2], [3,4], [5,6]) [9, 12] vectorsum([1,2], [3,4], [5,6], [7,8]) [16, 20] -- \ “The apparent lesson of the Inquisition is that insistence on | `\ uniformity of belief is fatal to intellectual, moral, and | _o__) spiritual health.” —_The Uses Of The Past_, Herbert J. Muller | Ben Finney prickly -- http://mail.python.org/mailman/listinfo/python-list
Re: extracting info from media files
MediaInfo is your best bet. http://mediainfo.sourceforge.net/en ~Sean On Nov 6, 11:59 pm, Michele Simionato michele.simion...@gmail.com wrote: I would like to extract some simple info from media files, such as size, resolution, duration, codec. What's the simplest way to do it? Once in a time there was pymedia but I see the latest release is of February 2006. The solution should work on Linux and provide support for a large set of video formats. -- http://mail.python.org/mailman/listinfo/python-list
Re: Reading a file that is changing and getting the new lines
On Dec 1, 3:09 pm, Ouray Viney ovi...@gmail.com wrote: Problem: = I want to read a ASCII text file that can have data appended to it. Example scenario: As the python script is running a user/application adds new entries to the end of the test case file, example, adds the following to the file. Question: = What is the best way to handle this type of scenario using python? There was a thread regarding 'imitating tail -f' recently that you might find useful. The best approach IMO is this one: http://www.dabeaz.com/generators/follow.py ~Sean -- http://mail.python.org/mailman/listinfo/python-list
daemon.DaemonContext and logging
I'm finally getting around to trying out the python-daemon module and have hit a wall. I'm trying to set up logging inside of the with daemon.DaemonContext block. But when I try to use a logger inside the block it throws an error: ~~ from __future__ import with_statement import logging import logging.handlers import daemon import daemon.pidlockfile import sys logger = logging.getLogger(DaemonLog) logger.setLevel(logging.INFO) formatter = logging.Formatter(%(asctime)s - %(name)s - %(levelname)s - %(message)s) handler = logging.FileHandler(log.file) logger.addHandler(handler) pid = daemon.pidlockfile.TimeoutPIDLockFile(/var/run/daemontest.pid, 10) with daemon.DaemonContext(pidfile=pid, gid=0, uid=0, stdout=sys.stdout, stderr=sys.stderr): logger.info(POO) ~~ I get the following traceback: ~~ [seans_imac:~/Downloads] halfitalian% Traceback (most recent call last): File /Library/Frameworks/Python.framework/Versions/2.5/lib/ python2.5/logging/__init__.py, line 753, in emit self.flush() File /Library/Frameworks/Python.framework/Versions/2.5/lib/ python2.5/logging/__init__.py, line 731, in flush self.stream.flush() IOError: [Errno 9] Bad file descriptor Error in atexit._run_exitfuncs: Traceback (most recent call last): File /Library/Frameworks/Python.framework/Versions/2.5/lib/ python2.5/atexit.py, line 24, in _run_exitfuncs func(*targs, **kargs) File /Library/Frameworks/Python.framework/Versions/2.5/lib/ python2.5/logging/__init__.py, line 1355, in shutdown h.close() File /Library/Frameworks/Python.framework/Versions/2.5/lib/ python2.5/logging/__init__.py, line 784, in close self.stream.close() IOError: [Errno 9] Bad file descriptor Error in sys.exitfunc: Traceback (most recent call last): File /Library/Frameworks/Python.framework/Versions/2.5/lib/ python2.5/atexit.py, line 24, in _run_exitfuncs func(*targs, **kargs) File /Library/Frameworks/Python.framework/Versions/2.5/lib/ python2.5/logging/__init__.py, line 1355, in shutdown h.close() File /Library/Frameworks/Python.framework/Versions/2.5/lib/ python2.5/logging/__init__.py, line 784, in close self.stream.close() IOError: [Errno 9] Bad file descriptor ~~~ Any advice? Also, I left in the call to TimeoutPIDLockfile() as well, because the library's documentation is pretty sparse, and I want to know if I'm using it properly. Thanks in advance. ~Sean -- http://mail.python.org/mailman/listinfo/python-list
Re: daemon.DaemonContext and logging
On Dec 10, 5:37 pm, Sean DiZazzo half.ital...@gmail.com wrote: I'm finally getting around to trying out the python-daemon module and have hit a wall. I'm trying to set up logging inside of the with daemon.DaemonContext block. But when I try to use a logger inside the block it throws an error: Got it! The DaemonContext closes all open file descriptors, including the one inside the logging handler. I got it to work by passing the logger's file handle in with the preserve_files option. ~Sean -- http://mail.python.org/mailman/listinfo/python-list
Re: insert unique data in a list
On Dec 13, 8:37 am, mattia ger...@gmail.com wrote: How can I insert non-duplicate data in a list? I mean, is there a particular option in the creation of a list that permit me not to use something like: def append_unique(l, val): if val not in l: l.append(val) Thanks, Mattia Check out the set() data type. ~Sean -- http://mail.python.org/mailman/listinfo/python-list
Re: python 2.x and running shell command
On Dec 23, 1:57 pm, tekion tek...@gmail.com wrote: All, some of the servers I have run python 2.2, which is a drag because I can't use subprocess module. My options that I know of is popen2 module. However, it seems it does not have io blocking capabilities. So every time run a command I have open and close a file handle. I have command that requires interactive interaction. I want to be be able to perform following action: fout, fin = popen2.open2(cmd) #open up interactive session fin.write(cmd2); block (input) fout.readline() block output fin.write(cmd2) and so on... is this possible with popen2 or do I have to use pexpect for the job? Thanks. I've never done that with subprocess, but maybe this will help: http://www.lysator.liu.se/~astrand/popen5/ ~Sean -- http://mail.python.org/mailman/listinfo/python-list
Re: python 2.x and running shell command
On Dec 24, 5:34 am, tekion tek...@gmail.com wrote: On Dec 23, 5:22 pm, Sean DiZazzo half.ital...@gmail.com wrote: On Dec 23, 1:57 pm, tekion tek...@gmail.com wrote: All, some of the servers I have run python 2.2, which is a drag because I can't use subprocess module. My options that I know of is popen2 module. However, it seems it does not have io blocking capabilities. So every time run a command I have open and close a file handle. I have command that requires interactive interaction. I want to be be able to perform following action: fout, fin = popen2.open2(cmd) #open up interactive session fin.write(cmd2); block (input) fout.readline() block output fin.write(cmd2) and so on... is this possible with popen2 or do I have to use pexpect for the job? Thanks. I've never done that with subprocess, but maybe this will help:http://www.lysator.liu.se/~astrand/popen5/ ~Sean Sean, popen5 is old name for subprocess. Right. Thats why I thought it would help. You _can_ use the subprocess module on 2.2. -- http://mail.python.org/mailman/listinfo/python-list
Re: Printing plain text with exact positioning on Windows
On Jan 5, 11:40 am, KvS keesvansch...@gmail.com wrote: On Jan 5, 7:16 pm, Nobody nob...@nowhere.com wrote: On Tue, 05 Jan 2010 04:40:14 -0800, KvS wrote: Did you mean borderless printing? Every printer needs his margins, some more some less. Some printers have the ability to do borderless printing but usualy they can do it only on special or photo paper. So you can adjust the pdf as you wish, even with no margins, and then try to find under printer options borderless printing. That is why I didn't understand :-)) it is a printer thing not pdf! As much as possible borderless, yes. Of course the printer will still apply some small margin, but that's ok. A margin of say 0.5 cm. is fine. So it's not a printer thing, I accept the (physical) limitations of the printer, but I want to avoid any extra margins due to software settings. Hardcopy document formats such as PostScript and PDF use positions relative to the edges of the page, not the margins. Right. Still, Acrobat Reader by default scales the contents to fit on a page and creates some margins by doing so, no? So if my text is close to the left and right edges, as I want, it will get scaled and extra margins will occur. Avoiding this still requires me to be able to turn off this scaling in the printing preferences somehow programmatically, so it doesn't seem to make the problem easier? Maybe you could have the user print your data on a larger sheet of paper;one that is sure to include all of the data, and include crop marks on the printout. The user then cuts along the crop marks to leave a perfectly sized, marginless page. This is how printers do bleeds. -- http://mail.python.org/mailman/listinfo/python-list
Re: PIL how to display multiple images side by side
On Jan 8, 1:43 pm, suresh.amritapuri suresh.amritap...@gmail.com wrote: Hi, In PIL, how to display multiple images in say m rows and n colums when I have m*n images. suresh Sounds like a good project to learn PIL with. ~Sean -- http://mail.python.org/mailman/listinfo/python-list
setattr() oddness
Should the following be legal? class TEST(object): pass ... t = TEST() setattr(t, , 123) getattr(t, ) '123' ~Sean -- http://mail.python.org/mailman/listinfo/python-list
Re: setattr() oddness
On Jan 15, 2:22 pm, Terry Reedy tjre...@udel.edu wrote: On 1/15/2010 3:37 PM, Sean DiZazzo wrote: Should the following be legal? class TEST(object): pass ... t = TEST() setattr(t, , 123) getattr(t, ) '123' Different people have different opinions as to whether setattr (and correspondingly getattr) should be strict or permissive as to whether or not the 'name' string is a legal name. CPython is permissive. The rationale is that checking would take time and prevent possible legitimate use cases. CPython is actually looser than this. Try t.__dict__[1] = 2 Now there is an 'attribute' whose 'name' is an int! -- and which can only be accessed via the same trick of delving into the internals. This is, however, implementation behavior that would go away if an implementation used string-key-only dicts to store attributes. Terry Jan Reedy Interesting. I can understand the would take time argument, but I don't see any legitimate use case for an attribute only accessible via getattr(). Well, at least not a pythonic use case. Thanks for the info! ~Sean -- http://mail.python.org/mailman/listinfo/python-list
Re: deriving MySQLdb class
On Jan 21, 5:48 pm, tekion tek...@gmail.com wrote: All, I am trying to write a class which inherits from MySQLdb class. Below is code snippet: import MySQLdb import sys class msql_connect(MySQLdb): def __init__(self): self.host = hostname self.user = user self.password = passoword self.database = database name I am running into below error: class msql_connect(MySQLdb): TypeError: Error when calling the metaclass bases module.__init__() takes at most 2 arguments (3 given) Does any one have an idea why? Thanks. MySQLdb is the name of the module, not the class you want to subclass. But MySQLdb.connect() is not the class either...it's a factory function that returns instances of the class you actually want to subclass...connections.Connection(). The below works for me. from MySQLdb import connections import sys class mysql_connect(connections.Connection): def __init__(self): self.host = host self.user = user self.password = password self.database = database connections.Connection.__init__(self, host=self.host, user=self.user, passwd=self.password, db=self.database) p = mysql_connect() ~Sean -- http://mail.python.org/mailman/listinfo/python-list
Re: deriving MySQLdb class
On Jan 21, 8:00 pm, tekion tek...@gmail.com wrote: Sean, Thanks. This is useful. For future reference, how do I know what class is in MySQLdb module? You have to explore. ;) I found the MySQLdb module, and looked inside the __init__.py. Then looked for connect and followed the trail. -- http://mail.python.org/mailman/listinfo/python-list
Re: deriving MySQLdb class
On Jan 21, 8:17 pm, tekion tek...@gmail.com wrote: Sean, I did a little investigation, there are other classes besides Connection. So, could I only set up a derived class from Connection and still be able to use the connection to query database and retrieve data? Im not sure I understand you completely... In theory, you could use the C API directly and subclass _mysql.connection to get at the database. But I think the point of MySQLdb is that they've done all the hard work. Why not use it? I think the other stuff in the module is in support of the Connection () class. ie. You cant get a cursor unless you already have a connection. -- http://mail.python.org/mailman/listinfo/python-list
Re: Terminal application with non-standard print
On Jan 24, 11:27 am, Rémi babedo...@yahoo.fr wrote: Hello everyone, I would like to do a Python application that prints data to stdout, but not the common way. I do not want the lines to be printed after each other, but the old lines to be replaced with the new ones, like wget does it for example (when downloading a file you can see the percentage increasing on a same line). I looked into the curses module, but this seems adapted only to do a whole application, and the terminal history is not visible anymore when the application starts. Any ideas? Thanks, Remi You might want to take a look at the readline module. ~Sean -- http://mail.python.org/mailman/listinfo/python-list
Re: Wrap a function
On Jan 28, 12:13 pm, Joan Miller pelok...@gmail.com wrote: On 28 ene, 19:58, John Posner jjpos...@optimum.net wrote: On 1/28/2010 2:24 PM, Joan Miller wrote: On 28 ene, 19:16, Josh Hollandj...@joshh.co.uk wrote: On 2010-01-28, Joan Millerpelok...@gmail.com wrote: I've to call to many functions with the format: run(cmd) Check the docs on os.system(). No. I've a function that uses subprocess to run commands on the same shell and so substitute to bash scrips. But a script full of run (shell_command --with --arguments) is too verbose. I'm suspicious of your original intent. Essentially, you want to write code in which a literal string, such as ... ls -l ... is *not* enclosed in quotes. Why run the risk of creating confusion (in other people who look at your code, in syntax-checking tools, etc.) between variables and literals? Yes but to that code could be prepend a sign as '$' to be identified and so be parsed. But I'm in sympathy with your desire to make the code as clean as possible and to minimize the number of times you have to type a quote character. My suggestions: 1. Create a function (say, Run) that encapsulates as much of the syntax as possible: os.system(), subprocess.call(), string-splitting, whatever. So an invocation would look like this: Run(ls -l *.txt) (I think you've already done this step.) Yes, I made a funtion very cool to call to system commands, that works well with pipes and passes the variables (i.e. LANG=C grep -e 'foo' / home) 2. Find a text editor that supports keyboard macros, so that a single keystroke turns this text line: ls -l *.txt ... into this one: Run(ls -l *.txt) This is not what I'm looking for. I'm supposing that could be solved with a DSL or a macro library, any? Python is not perl. Thank God/Guido. -- http://mail.python.org/mailman/listinfo/python-list
Re: get error install MySQLdb on Mac OS X
On Jan 28, 12:53 pm, PS.OHM ps.o...@gmail.com wrote: Hello Guys I have get some error when i install MySQLdb on Mac OS X after i key command $python setup.py build rusult is : : error: command 'gcc-4.0' failed with exit status 1 How to config this poblem? Please show a little bit more of the error -- http://mail.python.org/mailman/listinfo/python-list
Re: SimpleXMLRPCServer daemon
On Jan 29, 7:54 am, Thomas Allen thomasmal...@gmail.com wrote: I have a script that runs an instance of SimpleXMLRPCServer and in general it works as expected. In its __del__, it is supposed to clean up its PID file (written on boot). I have two problems with this server instance: The first is that tt doesn't always clean up its PID file; is there a more reliable way to do this than how I am currently? The second is that when it does crash, I don't know about it...what would be sufficient as a keep-alive script to restart it? I suppose I could use something like EventMachine (already installed on my server) to watch the PID file if it were deleted reliably. Thomas Allen You should check out python-daemon. I use home grown daemons all the time, and have only played a little with the python-daemon library, but it is surely written well, and handles lockfiles and pidfiles. I believe you can map a function to any signal that the daemon receives to do any kind of cleanup etc. Ssometimes those PID files might be left around, but the runner included with the module (i think) checks for stale pid files. There's all kinds of useful stuff. In my home grown daemons I use Adam's technique, and wrap the while 1: block in a try except clause. ~Sean -- http://mail.python.org/mailman/listinfo/python-list
Re: PEP 3147 - new .pyc format
Here is a recent list of magic numbers: Python 2.6a0: 62151 (peephole optimizations and STORE_MAP opcode) Python 2.6a1: 62161 (WITH_CLEANUP optimization) Python 2.7a0: 62171 (optimize list comprehensions/change LIST_APPEND) Python 2.7a0: 62181 (optimize conditional branches: introduce POP_JUMP_IF_FALSE and POP_JUMP_IF_TRUE) Python 2.7a0 62191 (introduce SETUP_WITH) Python 2.7a0 62201 (introduce BUILD_SET) Python 2.7a0 62211 (introduce MAP_ADD and SET_ADD) #define MAGIC (62211 | ((long)'\r'16) | ((long)'\n'24)) Regards, Martin Does magic really need to be used? Why not just use the revision number? -- http://mail.python.org/mailman/listinfo/python-list
Re: Your beloved python features
On Feb 4, 3:03 pm, Julian maili...@julianmoritz.de wrote: Hello, I've asked this question at stackoverflow a few weeks ago, and to make it clear: this should NOT be a copy of the stackoverflow-thread hidden features of Python. I want to design a poster for an open source conference, the local usergroup will have a table there, and in the past years there were some people that came to the python-table just to ask why should I use python?. For those guys would be a poster quite cool which describes the most popular and beloved python features. So, may you help me please? If there's a similar thread/blogpost/ whatever, please give it to me, google couldn't. Regards Julian I love list comprehensions, but am currently falling for 'with'. ~Sean -- http://mail.python.org/mailman/listinfo/python-list
Re: equivalent of Ruby's Pathname?
On Feb 3, 6:08 pm, alex23 wuwe...@gmail.com wrote: On Feb 4, 8:47 am, Phlip phlip2...@gmail.com wrote: Yes, calling os.path.walk() and os.path.join() all the time on raw strings is fun, but I seem to recall from my Ruby days a class called Pathname, which presented an object that behaved like a string at need, and like a filesystem path at need. path + 'folder' would call .join() and insert the / correctly, for example. What's the best equivalent in Python-land? It's no longer supported, but the 3rd party 'path' module used to be the go-to module for this: from path import path C:\Python26\lib\site-packages\path.py:32: DeprecationWarning: the md5 module is deprecated; use hashlib instead import sys, warnings, os, fnmatch, glob, shutil, codecs, md5 c = path('C:\\') c.listdir() [path(u'C:\\AUTOEXEC.BAT'), path(u'C:\\boot.ini'), ...] (c + 'python26').listdir() [path(u'C:\\python26\\circuits.pth_disabled_for_egg'), path(u'C:\ \python26\\DLLs'), ...] (c / 'python26').listdir() [path(u'C:\\python26\\circuits.pth_disabled_for_egg'), path(u'C:\ \python26\\DLLs'), ...] I've hand edited the results for brevity... The module could do with some TLC to bring it up to date, but warning aside it still seems to work fine under 2.6. (From memory, I think the original author gave up when it became clear it would never be integrated into the standard lib[1], which is a shame, I think there's scope for a pathtools addition to the lib that provides this level of convenience...) There was also a PEP with another possible implementation:http://www.python.org/dev/peps/pep-0355/ Hope this helps. It's too bad that something like this can't be agreed to. I used a homegrown module like this for a couple of years in my early days with python. It was great, but I didn't know enough at the time to make it really useful. Why did Path() get rejected? Is it the idea itself, or just the approach that was used? What are the complaints? ~Sean -- http://mail.python.org/mailman/listinfo/python-list
Re: Executing Commands From Windows Service
On Feb 7, 11:02 am, T misceveryth...@gmail.com wrote: I have a script, which runs as a Windows service under the LocalSystem account, that I wish to have execute some commands. Specifically, the program will call plink.exe to create a reverse SSH tunnel. Right now I'm using subprocess.Popen to do so. When I run it interactively via an admin account, all is well. However, when I'm running it via service, no luck. I'm assuming this is to do with the fact that it's trying to run under the LocalSystem account, which is failing. What would be the best way around this? Thanks! Try running/debugging your service from the commandline as servicename debug That should lead you to the error. Otherwise, we need to see a traceback and some code to be better able to help. ~Sean -- http://mail.python.org/mailman/listinfo/python-list
Re: Executing Commands From Windows Service
On Feb 7, 4:57 pm, T misceveryth...@gmail.com wrote: Thanks for the suggestions - I think my next step is to try running it under an admin user account, as you guys both mentioned. Alf - you're absolutely right, Microsoft has srvany.exe, which allows you to run any EXE as a Windows service. I've done this in the past, but it's more of a hack..so this go around (since I will be distributing this program), I wanted to go the more professional route..which, unfortunately, involves learning the scum. :) I posted this to comp.os.ms-windows.programmer.win32, so we'll see if what the Win32 programmers have to say as well. Thanks again! I use windows services and they are very reliable. I would say though that relying on plink.exe is much less reliable than either python or the service that it is running under. Why not take a look at paramiko as the ssh client library? I think it runs under windows. Also perhaps Twisted has something. Either way would be light years ahead of using subprocess with plink. Just my thoughts. ~Sean -- http://mail.python.org/mailman/listinfo/python-list
Re: Executing Commands From Windows Service
It's working fine when I run it via servicename debug - that's how I was testing before. It's when I start the service that it fails - and you can see that, when you run it with debug, plink.exe runs under my username. When I run it as a service, it runs under System... You can have the service run as any user under the service properties. Perhaps set the service to run under your username? There may be some environment variables set in your session that aren't in the one its running as. So maybe check there as well. Off to drink beer. Good luck. -- http://mail.python.org/mailman/listinfo/python-list
Re: Executing Commands From Windows Service
On Feb 9, 6:52 am, T misceveryth...@gmail.com wrote: On Feb 8, 2:25 pm, David Bolen db3l@gmail.com wrote: T misceveryth...@gmail.com writes: I have a script, which runs as a Windows service under the LocalSystem account, that I wish to have execute some commands. Specifically, the program will call plink.exe to create a reverse SSH tunnel. Right now I'm using subprocess.Popen to do so. When I run it interactively via an admin account, all is well. However, when I'm running it via service, no luck. I'm assuming this is to do with the fact that it's trying to run under the LocalSystem account, which is failing. What would be the best way around this? Thanks! The LocalSystem account is not, if I recall correctly, permitted to access the network. You'll have to install the service to run under some other account that has appropriate access to the network. -- David The more testing I do, I think you may be right..I was able to get it to work under a local admin account, and it worked under debug mode (which would also have been running as this user). I'm a bit surprised though - I was under the assumption that LocalSystem had rights to access the network? You really need a way to see the error you are getting. If you can't get it to show you the error in the shell, set up some logging to a file, and find the error that way. I think the user can access the network just fine, but that maybe plink.exe is not in his path or some such thing. Find the error! -- http://mail.python.org/mailman/listinfo/python-list
Re: equivalent of Ruby's Pathname?
On Feb 8, 2:36 pm, a...@pythoncraft.com (Aahz) wrote: In article dcace5fc-5ae9-4756-942d-6da7da2f6...@s36g2000prh.googlegroups.com, Sean DiZazzo half.ital...@gmail.com wrote: On Feb 3, 6:08=A0pm, alex23 wuwe...@gmail.com wrote: There was also a PEP with another possible implementation: http://www.python.org/dev/peps/pep-0355/ Why did Path() get rejected? Is it the idea itself, or just the approach that was used? What are the complaints? You should search for the discussiona around it. -- Aahz (a...@pythoncraft.com) * http://www.pythoncraft.com/ import antigravity I read the discussion, and there was definitely some going back and forth on whether it should be sub-classed from string, but the conversation just seemed to stop abruptly with no decision one way of the other. Maybe I missed a thread. I guess being dropped without a final go-ahead is just as good as a formal no anyway. -- http://mail.python.org/mailman/listinfo/python-list
Re: How do you implement a Progress Bar
On Feb 12, 11:33 pm, J Wolfe vorticitywo...@gmail.com wrote: I would really appreciate some help with this. I'm fairly new to using classes...What am I doing wrong? All I get is a blank window. I can't seem to figure out how to initialize this Progress Bar. Study and hack on this: http://uucode.com/texts/pylongopgui/pyguiapp.html ~Sean -- http://mail.python.org/mailman/listinfo/python-list
Re: Question about getmtime
On Feb 19, 10:06 am, MRAB pyt...@mrabarnett.plus.com wrote: Brandon wrote: Hi everyone, Does copying or moving a file affect the return value of os.path.getmtime(path)? The modification time of a copied file should be the same as the original. The creation time of a copied file will be the time at which it was copied, so that can result in the paradoxical state of a file having been modified _before_ it was created! :-) ctime does not stand for creation time. I went through this a couple of months ago. It's updated whenever the inode is updated, so changing permissions, among other things will update it. It blew me away when I finally found this out. ~Sean -- http://mail.python.org/mailman/listinfo/python-list
Re: Executable problem - correction
On Feb 24, 9:22 pm, Gib Bogle g.bo...@auckland.no.spam.ac.nz wrote: The program doesn't fail with the write error on the other XP machine, it actually fails to execute at all, complaining about the configuration information. Therefore I'm seeing different behaviour on three XP machines: Box 1 (SP2): runs OK Box 2 (SP3): fails to start Box 3 (SP3): starts up, all Qt stuff works, fails after invoking the Fortran DLL Just to add to the confusion, execution is successful on a Windows 7 box. I forgot to mention that the laptop on which the program was built (and where it runs OK) is using Vista. I now see that it will probably be necessary to build separate Vista and XP versions - I should have realized this earlier, but was misled by the fact that the Vista-built program runs OK on my XP SP2 box. Did you compile the program with python 2.6? Try compiling with 2.5. ~Sean -- http://mail.python.org/mailman/listinfo/python-list
Re: Updates about Tk
Are the new Tk comaprable with other toolkits(Qt, GTK,Wx?)? Does Tk lack other features compared to the Qt,GTK,Wx...? (Or: is there things you can't simply do with Tk?) Thanks in advance for replying tkinter is a good starting point. You can get some definite benefits going to wx or Qt. I guess it depends on how much experience you have creating GUIs. Choose the one you are comfortable with. -- http://mail.python.org/mailman/listinfo/python-list
Re: basic thread question
On Aug 18, 4:58 pm, birdsong david.birds...@gmail.com wrote: On Aug 18, 3:18 pm, Derek Martin c...@pizzashack.org wrote: On Tue, Aug 18, 2009 at 03:10:15PM -0500, Derek Martin wrote: I have some simple threaded code... If I run this with an arg of 1 (start one thread), it pegs one cpu, as I would expect. If I run it with an arg of 2 (start 2 threads), it uses both CPUs, but utilization of both is less than 50%. Can anyone explain why? Ah, searching while waiting for an answer (the e-mail gateway is a bit slow, it seems...) I discovered that the GIL is the culprate. Evidently this question comes up a lot. It would probably save a lot of time on the part of those who answer questions here, as well as those implementing solutions in Python, if whoever is maintaining the docs these days would put a blurb about this in the docs in big bold letters... Concurrency being perhaps the primary reason to use threading, essentially it means that Python is not useful for the sorts of problems that one would be inclined to solve they way my code works (or rather, was meant to). It would be very helpful to know that *before* one tried to implement a solution that way... especially for solutions significantly less trivial than mine. ;-) Thanks -- Derek D. Martinhttp://www.pizzashack.org/ GPG Key ID: 0x81CFE75D application_pgp-signature_part 1KViewDownload I would still watch that video which will explain a bit more about the GIL. Thank you for the video! It's good to know, but it raises lots of other questions in my mind. Lots of examples would have helped. ~Sean -- http://mail.python.org/mailman/listinfo/python-list
Re: Permanently adding to the Python path in Ubuntu
On Aug 29, 5:39 pm, Chris Colbert sccolb...@gmail.com wrote: I'm having an issue with sys.path on Ubuntu. I want some of my home built packages to overshadow the system packages. Namely, I have built numpy 1.3.0 from source with atlas support, and I need it to overshadow the system numpy 1.2.1 which I had to drag along as a dependency for other stuff. I have numpy 1.3.0 installed into /usr/local/lib/python2.6/dist-packages/. The issue is that this directory is added to the path after the /usr/lib/python2.6/dist-packages/ is added, so python doesnt see my version of numpy. I have been combating this with a line in my .bashrc file: export PYTHONPATH=/usr/local/lib/python2.6/dist-packages So when I start python from the shell, everything works fine. Problems show up when python is not executed from the shell, and thus the path variable is never exported. This can occur when I have launcher in the gnome panel or i'm executing from within wing-ide. Is there a way to fix this so that the local dist-packages is added to sys.path before the system directory ALWAYS? I can do this by editing site.py but I think it's kind of bad form to do it this way. I feel there has to be a way to do this without root privileges. Any ideas? Cheers, Chris I think you can modify sys.path inside your application. Maybe this will work (at the top of your script): import sys sys.path[0] = /usr/local/lib/python2.6/dist-packages import numpy PS. Say hi to Steven for me! ~Sean -- http://mail.python.org/mailman/listinfo/python-list