DispatchWithEvents not working for SQLDMO.Backup
Hi, I tried the following: >>> from win32com.client import DispatchWithEvents >>> class BackupEvent: ... def OnPercentComplete(self, sMessage, nPercent): ... print sMessage, nPercent >>> oSqlBackup = DispatchWithEvents('SQLDMO.Backup', BackupEvent) Traceback (most recent call last): raise ValueError, "This COM object does not support events." ValueError: This COM object does not support events. SQLDMO.Backup is a COM object with EVENT, why the error "does not support events"? I tried the demo of DispatchWithEvents using IExplorer and it's working, so I think the installation is correct. Is there anyone facing the same problem? Thanks, Chandra -- http://mail.python.org/mailman/listinfo/python-list
How to execute a python script in .NET application
Hi, Is there a way to execute a python script(file) in ASP.NET application (programmatically)?? Regards, Chandra -- http://mail.python.org/mailman/listinfo/python-list
Re: How to execute a python script in .NET application
Thanks all of them, i used the command line process (executing the script in cmd shell) method for executing python script. Regards, Chandra Gerard Flanagan wrote: > Chandra wrote: > > > Hi, > > > > Is there a way to execute a python script(file) in ASP.NET application > > (programmatically)?? > > > > Regards, > > Chandra > > > I thought IIS would prevent this, but the following works for me at > home (ASP.NET 1.1). A production setup may be a different matter. > > using System.Diagnostics > > public class WebForm1 : System.Web.UI.Page > { > protected System.Web.UI.WebControls.Label Label1; > > private void Page_Load(object sender, System.EventArgs e) > { > ProcessStartInfo startInfo; > Process process; > string directory = > @"c:\python\python24\Lib\site-packages"; > string script = "test.py"; > > startInfo = new ProcessStartInfo("python"); > startInfo.WorkingDirectory = directory; > startInfo.Arguments = script; > startInfo.UseShellExecute = false; > startInfo.CreateNoWindow = true; > startInfo.RedirectStandardOutput = true; > startInfo.RedirectStandardError = true; > > process = new Process(); > process.StartInfo = startInfo; > process.Start(); > > string s; > while ((s = process.StandardOutput.ReadLine()) != null) > { > Label1.Text += s; > } > } > } -- http://mail.python.org/mailman/listinfo/python-list
Writing a string.ishex function
Folks, I am new to Python and could not find a function along the lines of string.ishex in Python. There is however, a string.hexdigits constant in the string module. I thought I would enhance the existing modlue but am unsure how I should go about it. Specifically, I have attempted this much: ---cut--- #! /usr/bin/python # -*- coding: utf-8 -*- import string def ishex(string): ishex = False for i in string: if i in string.hexdigits: ishex = True else: ishex = False break return ishex ---cut--- Can someone help me get further along please? Thanks. -- http://mail.python.org/mailman/listinfo/python-list
Re: Writing a string.ishex function
On Jan 15, 12:22 am, "D'Arcy J.M. Cain" wrote: > Just return False once you find a non-hex digit. > > def ishex(s): > for c in s: > if not c in string.hexdigits: return False > > return True > > And here are your unit tests. Every line should print "True". > > print ishex('123') is True > print ishex('abc') is True > print ishex('xyz') is False > print ishex('0123456789abcdefABCDEF') is True > print ishex('0123456789abcdefABCDEFG') is False > Thanks to Iain and to you. One further question: even though it is a single function, is there any way to convert it into a module? Can existing modules be enhanced with functions such as these? If not, how may I make my own module, called, say mystring? At present, I am saving the file as ishex.py and calling it after declaring from ishex import ishex Is there a more elegant way to integrate this function and make it available to other python scripts using the import mechanism? Thanks. Chandra -- http://mail.python.org/mailman/listinfo/python-list
simple array question
Hello, I have a simple question.Hoping not to take much of your valuable time...:-). I am trying to get the data from a string, and am wondering if I get http://groups.google.com/intl/en/googlegroups/tour/index.html from the array : array('c', '\x00=http://groups.google.com/intl/en/googlegroups/tour/index.html')) Thanks in advance, regards, purna. -- http://mail.python.org/mailman/listinfo/python-list
Getting and/or setting network interface parameters on OS X
Looking for a Python 2.7 module through which I can fetch the below details for all available network interfaces on a OS X device : Gateways DNS server DHCP server WINS server IP address DNS suffix I also want to set them for a specific interface. -- https://mail.python.org/mailman/listinfo/python-list
Python not finding modules
Hey! I installed a few python modules through the freebsd ports, but when I try to import them in the interpreter it says "module xxx not found". This seems to happen for some modules and not for the others. ex:- I installed psyco and parallel python which seem to be found but then scipy, PIL aren't being imported. Below is my $PYTHONPATH ['', '/usr/local/lib/python2.5/site-packages/setuptools-0.6c7-py2.5.egg', '/usr/local/lib/python25.zip', '/usr/local/lib/python2.5', '/usr/local/lib/python2.5/plat-freebsd6', '/usr/local/lib/python2.5/lib-tk', '/usr/local/lib/python2.5/lib-dynload', '/usr/local/lib/python2.5/site-packages', '/usr/local/lib/python2.5/site-packages/gtk-2.0', '/usr/local/lib/vtk/python', '/usr/local/lib/python2.5/site-packages'] The scipy libs are located at "/usr/local/lib/python2.4/site-packages/scipy" so I manually added this path to the PYTHONPATH but it still doesn't seem to find it. Can someone please help me out here?:) ps Also does including a directory in PYTHONPATH include all of it's sub-directories too? Download prohibited? No problem. CHAT from any browser, without download. Go to http://in.messenger.yahoo.com/webmessengerpromo.php/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Python not finding modules
Hey, Thanks for replying. But what about the module whose path I included manually. That didn't work too!Is it like packages that are made for python2.4 do not work for 2.5? Also are folders recursively included? Thanks Mani chandra --- On Wed, 13/2/08, Guilherme Polo <[EMAIL PROTECTED]> wrote: > From: Guilherme Polo <[EMAIL PROTECTED]> > Subject: Re: Python not finding modules > To: [EMAIL PROTECTED], python-list@python.org > Date: Wednesday, 13 February, 2008, 3:56 PM > 2008/2/13, Mani Chandra <[EMAIL PROTECTED]>: > > Hey! > > I installed a few python modules through the > freebsd ports, but when I try to import them in the > interpreter it says "module xxx not found". This > seems to happen for some modules and not for the others. > ex:- I installed psyco and parallel python which seem to be > found but then scipy, PIL aren't being imported. Below > is my $PYTHONPATH > > > > ['', > '/usr/local/lib/python2.5/site-packages/setuptools-0.6c7-py2.5.egg', > '/usr/local/lib/python25.zip', > '/usr/local/lib/python2.5', > '/usr/local/lib/python2.5/plat-freebsd6', > '/usr/local/lib/python2.5/lib-tk', > '/usr/local/lib/python2.5/lib-dynload', > '/usr/local/lib/python2.5/site-packages', > '/usr/local/lib/python2.5/site-packages/gtk-2.0', > '/usr/local/lib/vtk/python', > '/usr/local/lib/python2.5/site-packages'] > > > > The scipy libs are located at > "/usr/local/lib/python2.4/site-packages/scipy" > so I manually added this path to the PYTHONPATH but it > still doesn't seem to find it. > > > > You need to install python modules for python2.5, you > clearly installed for 2.4. > > > Can someone please help me out here?:) > > > > ps Also does including a directory in PYTHONPATH > include all of it's sub-directories too? > > > > > > > > Download prohibited? No problem. CHAT from any > browser, without download. Go to > http://in.messenger.yahoo.com/webmessengerpromo.php/ > > > > -- > > http://mail.python.org/mailman/listinfo/python-list > > > > > -- > -- Guilherme H. Polo Goncalves Get your domain and website for less than Rs.100/month*. Go to http://in.business.yahoo.com/ -- http://mail.python.org/mailman/listinfo/python-list
Fw: error in importing scipy
--- On Wed, 13/2/08, Mani Chandra <[EMAIL PROTECTED]> wrote: > From: Mani Chandra <[EMAIL PROTECTED]> > Subject: error in importing scipy > To: [EMAIL PROTECTED] > Date: Wednesday, 13 February, 2008, 9:30 PM > Hi > I get the following error while importing scipy. > /usr/local/lib/python2.4/site-packages/scipy_base/__init__.py:16: > RuntimeWarning: Python C API version mismatch for module > fastumath: This Python has API version 1013, module > fastumath has version 1012. import fastumath # no need to > use scipy_base.fastumath > > Can someone please help me out? > > Thanks, > Mani chandra > > > Get the freedom to save as many mails as you wish. To > know how, go to > http://help.yahoo.com/l/in/yahoo/mail/yahoomail/tools/tools-08.html Unlimited freedom, unlimited storage. Get it now, on http://help.yahoo.com/l/in/yahoo/mail/yahoomail/tools/tools-08.html/ -- http://mail.python.org/mailman/listinfo/python-list
[no subject]
I want to know hint about web development... can any one get me... -- https://mail.python.org/mailman/listinfo/python-list
[no subject]
sir how can i improve my basic knowledge about programming.can u give me some hint...just give me way -- https://mail.python.org/mailman/listinfo/python-list
Dynamic variable names
Dear Folks, I have read that one should use a dictionary in python to accommodate dynamic variable names. Yet, I am puzzled how to achieve that in my case. Here is what I want to do: 1. The user inputs a number of six-digit hex numbers as a comma-separated list. These numbers represent colours, but the number of colours is not known beforehand. 2. Using these colours in pairs, I am generating image files whose names must be unique. I could use the respective hex numbers for this, but would like to explore generating filenames like colour_1-colour_2.jpg Because I do not know how many colours there would be in advance, I need to generate the colour_n names on the fly. So, my two questions are: 1. How do I do this properly in python? 2. If there is a better scheme than what I have outlined, can someone please point me to a Web link? Thank you. Chandra -- http://mail.python.org/mailman/listinfo/python-list
Sorting a list of lists
Dear Folks, I have lines of values like so: 14, [25, 105, 104] 10, [107, 106, 162] 21, [26, 116, 165] I need to sort them in two ways: (a) By the numeric value of the first column; and (b) by the sum of the elements of the second item in each list, which is a list in itself. At present, I have appended each line into a list L so that I for teh above minimal data, I have a list of lists thus: [[14, [25, 105, 104]], [10, [107, 106, 162]], [21, [26, 116, 165]]] I have tried using (a) sorted(L, key = lambda x:(x[0])) and (b) sorted(L, key = lambda x:(sum(x[1]))) and get the anticipated results for (a) and (b0, at least with the above minimal data set. Is this a sensible way to go about the sorting, or are there better ways of doing it in Python? Also, I am baffled because the above fails obviously when len(L) is about a hundred and I can't figure out why. TIA Chandra -- http://mail.python.org/mailman/listinfo/python-list
Re: Sorting a list of lists
MRAB wrote: You'd have to post an example of that, but you could try deleting some of the entries before sorting so see whether you can still reproduce the problem with a smaller list. John Posner wrote: Please cut-and-paste the exact error message (or other evidence of "failure") into a message. Thank you both. It appears that the problem was in the way the data were being read in from a file, than in the sorting itself. Once I fixed that, the results are as expected. Chandra -- http://mail.python.org/mailman/listinfo/python-list
Executing a command from within python using the subprocess module
Dear Folks, I want to execute a command from within python using the subprocess module. Coming from a Perl background, I thought I could use variable interpolation in strings, but found that this is neither supported nor the Python way. Accordingly, I am a little at sea about how to accomplish it. I have stated what I am trying to do in the minimal example below: --- import subprocess width = 5 height = 30 colors = ['#abcdef]', '#456789'] filename = "/tmp/image.png" # I want to get the equivalent of variable interpolation in Perl # so that the command # # convert -size 5x30 gradient:#abcdef-#456789 /tmp/image.png # # is derived from the variables above # and executed by subprocess.call() or subprocess.Popen() # from within Python # # Note that the command "convert" is from the ImageMagick suite # It exists and is executable by the shell; # the remaining values are arguments. # The command has been confirmed to execute correctly. --- Thanks in advance. Chandra -- http://mail.python.org/mailman/listinfo/python-list
Re: Executing a command from within python using the subprocess module
Peter Otten wrote: import subprocess def convert(width=5, height=30, colors=['#abcdef', '#456789'], filename="tmp/image with space in its name.png"): lookup = locals() assert all("\n" not in str(s) for s in lookup.values()) subprocess.call("""\ convert -size {width}x{height} gradient:{colors[0]}-{colors[1]} {filename}""".format(**lookup).splitlines()) convert() Peter Thank you. It works. Now I need to understand why and am able to follow what you are doing part of the way: 1. Assign default values in the function definition. 2. Store the variables existing in the local namespace in the list lookup. 3. Assert that there are no newlines in the values in lookup converted to strings. (Why? Is this because of splitlines() later on?) 4. Assemble a string (array?) for the subprocess.call argument using the format string syntax (section 8.1.3 et seq. of the Python documentation for 2.6.4). Your example works with default option of shell=False for subprocess.call(). 5. I am unable to decipher how you got to format(**lookup).splitlines()) especially the **prefix part, although I guess that splitlines() is dishing out the arguments one by one from each line in the subprocess.call argument. Any correction of (1) to (4) and an explanation of (5) would be most appreciated. All in all, your code is a magnificent example of wrapping the function within python. This is the first time I have seen something like this. Thank you very much. Chandra -- http://mail.python.org/mailman/listinfo/python-list
Re: Executing a command from within python using the subprocess module
Peter Otten wrote: import subprocess def convert(width=5, height=30, colors=['#abcdef', '#456789'], filename="tmp/image with space in its name.png"): lookup = locals() assert all("\n" not in str(s) for s in lookup.values()) subprocess.call("""\ convert -size {width}x{height} gradient:{colors[0]}-{colors[1]} {filename}""".format(**lookup).splitlines()) convert() Peter One other question I forgot to ask is this why is there a terminal backslash in subprocess.call("""\ Removing the backslash makes the function fail. I wonder why, because """ is supposed to allow multi-line strings. I am sorry if this sounds obtuse but that backslash baffles me. -- http://mail.python.org/mailman/listinfo/python-list
Re: Executing a command from within python using the subprocess module
Alf P. Steinbach wrote: * R (Chandra) Chandrasekhar: width = 5 height = 30 colors = ['#abcdef]', '#456789'] filename = "/tmp/image.png" # I want to get the equivalent of variable interpolation in Perl # so that the command # # convert -size 5x30 gradient:#abcdef-#456789 /tmp/image.png # # is derived from the variables above Assuming that the extra right square bracket in 'colors' is a typo, here's one way: s = "convert -size {w}x{h} gradient:{g1}-{g2} {f}".format( w = width, h = height, g1 = colors[0], g2 = colors[1], f = filename ) Cheers & hth., - ALf Thanks, Alf. It works if I use it so: subprocess.call(s, shell=True) and I think that is because s is a single string assembled in almost the variable interpolation fashion of Perl. It does not work with the default shell=False argument, presumably because the arguments are not split into separate strings (something that was horrible to do by hand using the %s and %() syntax that I had tried out previously). I think that you and Peter have, between you, shown me two ways of using subprocess.call(): one with shell=True and the other with shell = False. Thanks. Chandra -- http://mail.python.org/mailman/listinfo/python-list
Is automatic reload of a module available in Python?
Dear Folks, I am currently developing a python program, let us call it "generic.py", and I am testing out the functions therein by testing them out interactively in the python interpreter by invoking python and doing import generic Once I hit an error, I need to revise my file and reload the module using reload(generic) The difference in syntax between invoking import and reload is really costing me time and patience. Therefore, I would like to ask: 1. Is there a method of auto-reloading a module while developing it and testing it with the interactive python interpreter? 2. Is there a better way of developing a program? Thank you. Chandra -- http://mail.python.org/mailman/listinfo/python-list
Re: Is automatic reload of a module available in Python?
Arnaud Delobelle wrote: Here is a very simple way to improve what you do, which won't require you to change the way you work or to learn a new paradigm: Instead of testing your functions interactively, put your testing code in a file, e.g. 'program_tests.py'. Your can then type python program_tests.py at the shell interactive prompt. To perform the tests again, just re-execute that file. If your tests are divided into different units, you can put these in functions: def test_frobz(): #testing code for frobzation of klops def test_frizz(): #testing code for frizzment of frobzied klops # etc.. So if you want to keep doing interactive tests, you can import program_tests and call whichever testing functions you want. You may even have arguments to those functions to test them with different parameters. I know some people will point at more 'pro' ways of testing but this has the merit of being very straightforward. Then when you move on to more sophisticated techniques, I think you will understand better the motivations behind them. It took me some time to cotton on to exactly what you were saying, but once I grasped it and tried it out, I found it very effective and time-saving. Thank you very much Arnaud. -- Chandra -- http://mail.python.org/mailman/listinfo/python-list
RE: Array programming
Thank you, Sakesun. -Original Message- From: Sakesun Roykiattisak [mailto:[EMAIL PROTECTED] Sent: Saturday, May 07, 2005 12:17 PM To: V.C.Sekhar Cc: python-list@python.org Subject: Re: Array programming V.C.Sekhar wrote: >Hi there, > I couldnt get to do the following task using Python. Can some pls >suggest me a way to do this. > >I have an array with duplicate strings filled in it. Now am looking for >a way to extract only the DISTINCT Values from that array. > >Could some one pls help me out. > >Thanks in advance, >Sekhar > > > > try use "set" or "frozenset", if you use python2.4 or try "sets.Set" or "sets.ImmutableSet", if you use python2.3 >>> import sets >>> s = sets.Set([1,1,2,3,2,4]) >>> for x in s: print x 1 2 3 4 __ Do you Yahoo!? Yahoo! Mail - Find what you need with new enhanced search. http://info.mail.yahoo.com/mail_250 -- http://mail.python.org/mailman/listinfo/python-list
Outlook-Python Issue
Hi there, Can any one please help in getting me Python-Outlook programming issue clarified. I just wanted to do the following using Python: 1)Open a New Oulook Mail Window 2) Fill the field: to-email address and Write some body to it.(I DON’t want to send it automatically) That’s all. But, I am getting an error when I try to initiate the MAPI-Session using object = win32com.client.Dispatch("Outlook.Application") ns = object.GetNamespace("MAPI") mapi = win32com.client.dynamic.Dispatch("MAPI.session") Error I see is : File "C:\Program Files\GNU\WinCvs 2.0\Macros\TemplateCvsMacro.py", line 140, in SendMAPIMail mapi = win32com.client.Dispatch("MAPI.session") File "C:\Python24\Lib\site-packages\win32com\client\__init__.py", line 95, in Dispatch dispatch, userName = dynamic._GetGoodDispatchAndUserName(dispatch,userName,clsctx) File "C:\Python24\Lib\site-packages\win32com\client\dynamic.py", line 91, in _GetGoodDispatchAndUserName return (_GetGoodDispatch(IDispatch, clsctx), userName) File "C:\Python24\Lib\site-packages\win32com\client\dynamic.py", line 79, in _GetGoodDispatch IDispatch = pythoncom.CoCreateInstance(IDispatch, None, clsctx, pythoncom.IID_IDispatch) pywintypes.com_error: (-2147221005, 'Invalid class string', None, None) Can any one please help me in this regard. Thanks, Sekhar __Do You Yahoo!?Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com -- http://mail.python.org/mailman/listinfo/python-list