Re: Does a function like isset() exist in Python?
Patrick Fitzsimmons wrote: Hi, I'm sure I should know this, but I can't find it in the manual. Is there a function in Python like the function in PHP isset()? It should take a variable name and return True or False depending on whether the variable is initialized. Thanks for any help, Patrick There are no unitialized variables in python; if you try to access an undefined name, a NameError exception is raised: try: print foo is, foo except NameError: print foo is undefined To undefine a defined name, use del: foo=None print foo None del foo print foo NameError: name 'foo' is not defined George -- http://mail.python.org/mailman/listinfo/python-list
Profiling extension modules
Is there a (relatively) simple way to profile an extension module, preferably without static linking ? It compiles with 'gcc -pg' but there are a bunch of undefined references at linking (_mcount, _monstartup, __mcleanup); googling for them didn't bring back anything particularly useful. Any ideas ? George -- http://mail.python.org/mailman/listinfo/python-list
Re: Database recommendations for Windows app
On 2005-06-23, Peter Hansen [EMAIL PROTECTED] wrote: Your list didn't mention a few things that might be critical. Referential integrity? You can implement it in sqlite with triggers. I only bother with cascading delete triggers, myself. Type checking? SQLite currently supports neither. sqlite3 has a strict affinity mode, but I'm not exactly sure how one sets it. http://www.sqlite.org/datatype3.html Dave Cook -- http://mail.python.org/mailman/listinfo/python-list
RE: os.system(cmd) isn't working
[Gregory Piñero] | | I'm trying to run this statement: | | os.system(r'C:\Program Files\Mozilla Firefox\firefox.exe' + ' | www.blendedtechnologies.com') | | The goal is to have firefox open to that website. | | When I type r'C:\Program Files\Mozilla Firefox\firefox.exe' + ' | www.blendedtechnologies.com' in the python interpreter I get: | | 'C:\\Program Files\\Mozilla Firefox\\firefox.exe | www.blendedtechnologies.com' | | And when I copy this into my command prompt (less outermost ' ) | firefox opens up to that page like I would expect. However in python | nothing happens and I get exit status 1. This is only half an answer, but I personally find faffing about with the double-quote / double-backslash stuff between Python and Windows a pain in the neck, so where I can I avoid it. In this case, you have a few options: 1) Use the webbrowser module. import webbrowser webbrowser.open (www.blendedtechnologies.com) 2) Use os.startfile (or its beefed-up cousin win32api.ShellExecute): import os os.startfile (http://www.blendedtechnologies.com;) 3) Find out from Windows where the default browser is: (There are alternative ways of doing this, for example querying the registry for AppPaths). import os import tempfile import win32api f = tempfile.TemporaryFile (suffix=.html) hInstance, exe_filename = win32api.FindExecutable (f.name) os.system (%s %s % (exe_filename, www.blendedtechnologies.com)) Hope all that leads you somewhere. Obviously, it doesn't answer the underlying question about double-slashes and quotes and so on, but it seems to meet your current need. TJG This e-mail has been scanned for all viruses by Star. The service is powered by MessageLabs. For more information on a proactive anti-virus service working around the clock, around the globe, visit: http://www.star.net.uk -- http://mail.python.org/mailman/listinfo/python-list
Re: voicemail program written with python
It is relatively easy to write voice applications for the Asterisk software PBX using the CGI-like AGI (Asterisk Gateway Interface). The following document describes the AGI and has some examples in Python: http://home.cogeco.ca/~camstuff/agi.html -- http://mail.python.org/mailman/listinfo/python-list
Re: os.system(cmd) isn't working
Gregory Piñero [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] Hi guys, I'm trying to run this statement: os.system(r'C:\Program Files\Mozilla Firefox\firefox.exe' + ' www.blendedtechnologies.com') The goal is to have firefox open to that website. When I type r'C:\Program Files\Mozilla Firefox\firefox.exe' + ' www.blendedtechnologies.com' in the python interpreter I get: 'C:\\Program Files\\Mozilla Firefox\\firefox.exe www.blendedtechnologies.com' And when I copy this into my command prompt (less outermost ' ) firefox opens up to that page like I would expect. However in python nothing happens and I get exit status 1. I'm using Python 2.3 on Windows XP pro service pack 2. I'd greatly appriciate any help. Thanks, Greg === These seemed to work on one machine for Python 2.1 and 2.4. os.system('\C:/Program Files/Mozilla Firefox/firefox.exe\ http://www.blendedtechnologies.com/') 1 os.system('\C:\\Program Files\\Mozilla Firefox\\firefox.exe\ http://www.blendedtechnologies.com/') 1 os.system(r'C:\Program Files\Mozilla Firefox\firefox.exe http://www.blendedtechnologies.com/') 1 -- http://mail.python.org/mailman/listinfo/python-list
Re: Avoiding deadlocks in concurrent programming
Thanks for all of the replies, I'm glad I posted here, you guys have been very helpful. Obviously, I only know what you've told us about your data, but 20-100 queries? That doesn't sound right ... RDBMSes are well- studied and well-understood; they are also extremely powerful when used to their potential. Well I doubt there'd be even as many as 20 unique queries in any one action, but 20-100 queries executed is about average, and it can be over ten thousand for one action, clearly painfull to any RDBM or programmer. And as Paul McGuire points out, RDBMs don't help avoid deadlocks, in fact it makes them easier to create in my opinion. Paul Rubin, I think you're right, a single lock is the approach I'm going to take. I don't want to seem stupid, but I don't understand what you're talking about with the Queues, isn't a Queue just a synchronized sequence? If you've got the time and you don't mind, I'd love a more detailed explanation. Niel, thanks for the link, I read through the article. I try to pick up crumbs of knowledge from my co-workers, and one of the smarter ones gave me this rubric for testing for deadlocks. That's true, I'm going to remember that one. Thanks a lot guys, I'm leaving on a trip tomorrow so I won't be able to reply to this thread again, but I will read any other posts on it when I come back. -Dan -- http://mail.python.org/mailman/listinfo/python-list
Allowing only one instance of a script?
Hi, I have a script which I double-click to run. If i double-click it again, it will launch another instance of the script. Is there a way to allow only one instance of a script, so that if another instance of the script is launched, it will just return with an error. Thanks Regards, Ali -- http://mail.python.org/mailman/listinfo/python-list
RE: Allowing only one instance of a script?
[Ali] | | I have a script which I double-click to run. If i double-click it | again, it will launch another instance of the script. | | Is there a way to allow only one instance of a script, so that if | another instance of the script is launched, it will just | return with an | error. If you're on Windows, have a look at this recent thread: http://groups-beta.google.com/group/comp.lang.python/msg/2a4fadfd3d6e3d4b?hl=en TJG This e-mail has been scanned for all viruses by Star. The service is powered by MessageLabs. For more information on a proactive anti-virus service working around the clock, around the globe, visit: http://www.star.net.uk -- http://mail.python.org/mailman/listinfo/python-list
Re: Python API to manipulate CAB files.
Konstantin Veretennicov [EMAIL PROTECTED] writes: On 6/22/05, Peter Maas [EMAIL PROTECTED] wrote: Isaac Rodriguez schrieb: Does anyone know of a Python API to manipulate CAB files? I guess you'll have to interface with setupapi.dll (SetupIterateCabinet) via ctypes, or with Microsoft Cabinet utilities via subprocess module. Neither is what people call fun... - kv Probably not what you mean with 'manipulate CAB files', but it may give a start with ctypes and cab: http://starship.python.net/crew/theller/moin.cgi/CreateCab Thomas -- http://mail.python.org/mailman/listinfo/python-list
Re: Loop until condition is true
Stelios Xanthakis wrote: Magnus Lycka wrote: Right. Silly me. Maybe in some future Python version, True and False will be constants, like None is since Python 2.4. Actually, there is support in marshal to write True and False objects so I don't understand why this isn't in 2.4 Because it would break existing code. -- Michael Hoffman -- http://mail.python.org/mailman/listinfo/python-list
Re: Database recommendations for Windows app
Dave Cook [EMAIL PROTECTED] writes: On 2005-06-22, Will McGugan [EMAIL PROTECTED] wrote: [...] Can anyone recommend a database that runs on Windows, is fast / efficient and can be shipped without restrictions or extra downloads? http://pysqlite.org Or APSW http://www.rogerbinns.com/apsw.html. -- Joel Rosdahl [EMAIL PROTECTED] Key BB845E97; fingerprint 9F4B D780 6EF4 5700 778D 8B22 0064 F9FF BB84 5E97 -- http://mail.python.org/mailman/listinfo/python-list
Re: Does a function like isset() exist in Python?
George Sakkis wrote: There are no unitialized variables in python; if you try to access an undefined name, a NameError exception is raised: try: print foo is, foo except NameError: print foo is undefined note the order of evaluation: try: ... print foo is, foo ... except NameError: ... print foo is undefined ... foo is foo is undefined /F -- http://mail.python.org/mailman/listinfo/python-list
Where is Word - COM solution
Hi all, This goes back to my previous post called Where is Word. In short, I wanted to make a temporary file (directory listing), open it in Word to let the user edit, layout and print it, and then delete the temp file afterwards. I almost got it to work without using COM, but there was a problem when the user runs the script a second time without closing Word after the first time. In that case, the temp file could not be deleted (see original post). Luckily, the following code was provided to me by a good fellow named Hughes, Chad O. Thanks again for your time and effort on this, Chad! code import os from win32com.client import Dispatch dirlist = os.listdir(os.getcwd()) word = Dispatch('Word.Application') word.Documents.Add(Visible = True) word.Visible = True for line in dirlist: word.Selection.TypeText(line + '\r\n') /code So the questions 'where is Word' and 'how to delete the temp file' have become obsolete. Nice, eh? COM rules! Cheers, g -- http://mail.python.org/mailman/listinfo/python-list
Re: Database recommendations for Windows app
Cameron Laird wrote: OK, I'm with you part of the way. Typical Access developers are *always* involved with DLL hell, right? You're surely not saying that Python worsens that frustration, are you? I think Dan was commenting on flaws in Microsoft's products, not in Python. As I understand it, he was suggesting to use something else than Access with Python, not something else than Python with Access. The O.P. wanted a database for his Python app, and Thomas Bartkus suggested Access. -- http://mail.python.org/mailman/listinfo/python-list
Re: create a pdf file
Alberto Vera wrote: Hello: I found a script that convert a file to PDF format , but it was made in PHP Do you know any script using Python? What do you mean by convert a file to PDF format? The solution obviously depends on what the file you start with looks like. If you want to create PDF yourself via API calls, ReportLab is what you need. If you want to convert an existing file in a format such as PS or MS Word, there are a lot of solutions out there, but I don't know of any Python based, and I don't see a point in using a Python based solution for that kind of task. The simplest would probably be to invoke a command line tool such as ps2pdf from your Python script. -- http://mail.python.org/mailman/listinfo/python-list
Re: os.system(cmd) isn't working
Le Thu, 23 Jun 2005 01:19:11 -0500, Paul Watson a écrit : Gregory Piñero [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] Hi guys, I'm trying to run this statement: os.system(r'C:\Program Files\Mozilla Firefox\firefox.exe' + ' www.blendedtechnologies.com') The goal is to have firefox open to that website. I suggest to use the subprocess module. You don't have insert around a path with embedded spaces and you can give the exact executable pathname, set the directory for the child process, etc import os import os.path import subprocess path_exe = r'C:\Program Files\Mozilla Firefox\firefox.exe' assert os.path.exists(path_exe) url = http://www.blendedtechnologies.com; child = subprocess.Popen( (path_exe, url), executable = path_exe) rc = child.wait() I'm using Python 2.3 on Windows XP pro service pack 2. I think that subprocess is a new Python2.4 module, but you should be able to find a 2.3 version (perhaps effbot.org) I'd greatly appriciate any help. -- http://mail.python.org/mailman/listinfo/python-list
Re: Optimize a cache
- Original Message - From: Florian Lindner [EMAIL PROTECTED] Hello, I am building a object cache in python, The cache has a maximum size and the items have expiration dates. At the moment I'm doing like that: What possible you see to optimize this lookup? Or anything else you see to make it better? Have a look at http://py.vaults.ca/apyllo.py/514463245.769244789.92554878 it already has some of your requirements, and can be used as a building block. -- http://mail.python.org/mailman/listinfo/python-list
Re: PEP ? os.listdir enhancement
On Wed, 22 Jun 2005 11:27:06 -0500, Jeff Epler wrote: Why not just define the function yourself? Not every 3-line function needs to be built in. Of course I can code such a function, and I agree with the second sentence, but I think that obtaining absolutes path is a task so commonly needed that adding a keyword to an existing function would give a plus to the library without adding complexity (speaking of number of modules). Usually when you use os.listdir do you end using os.path.join to obtain absolutes path? I'm interested to know if the task is so common as I think, or if I'm wrong. Thank you, Riccardo -- Riccardo Galli Sideralis Programs http://www.sideralis.net -- http://mail.python.org/mailman/listinfo/python-list
Re: PEP ? os.listdir enhancement
What's wrong with (os.path.join(d, x) for x in os.listdir(d)) It's short, and easier to understand then some obscure option ;) Andreas On Thu, Jun 23, 2005 at 11:05:57AM +0200, Riccardo Galli wrote: On Wed, 22 Jun 2005 11:27:06 -0500, Jeff Epler wrote: Why not just define the function yourself? Not every 3-line function needs to be built in. Of course I can code such a function, and I agree with the second sentence, but I think that obtaining absolutes path is a task so commonly needed that adding a keyword to an existing function would give a plus to the library without adding complexity (speaking of number of modules). Usually when you use os.listdir do you end using os.path.join to obtain absolutes path? I'm interested to know if the task is so common as I think, or if I'm wrong. Thank you, Riccardo -- Riccardo Galli Sideralis Programs http://www.sideralis.net -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
pydoc - suppressing builtins?
Is it possible to persuade pydoc not to include documentation for methods inherited from built-in classes? I have several classes that inherit from dict, and don't really need documentation thousands of lines long that consists mostly of dict's methods repeated multiple times. I'm sure I could qite easily write something to post-process the HTML files; just wondering if there might be an easier way. thanks Alan -- http://mail.python.org/mailman/listinfo/python-list
Re: Avoiding deadlocks in concurrent programming
On 22 Jun 2005 17:50:49 -0700, Paul Rubin http://phr.cx@nospam.invalid wrote: Even on a multiprocessor system, CPython (because of the GIL) doesn't allow true parallel threads, ... . Please excuse my ignorance, do you mean that python threads are always scheduled to run on the same single CPU? Or just that python threads are often blocked waiting for GIL? - kv -- http://mail.python.org/mailman/listinfo/python-list
Re: PEP ? os.listdir enhancement
On 6/22/05, Riccardo Galli [EMAIL PROTECTED] wrote: I propose to add an 'abs' keyword which would make os.listdir return the absolute path of files instead of a relative path. What about os.listdir(dir='relative/path', abs=True)? Should listdir call abspath on results? Should we add another keyword rel? Would it complicate listdir unnecessarily? - kv -- http://mail.python.org/mailman/listinfo/python-list
Re: Loop until condition is true
Op 2005-06-22, Michael Hoffman schreef [EMAIL PROTECTED]: Remi Villatel wrote: Fredrik Lundh wrote: checking if a logical expression is true by comparing it to True is bad style, and comparing values using is is also bad style. I wrote it this way because, first, it's perfectly valid Python code and, second and most important, it's also a valid english sentence. As others have pointed out, it's not perfectly valid code. In fact it is frequently incorrect. That the same code would be incorrect in other circumstances doesn't make it invalid as it was used in a specific situation. I have written code my self with an if var is True statement and that is exactly what I wanted. Replacing it with if var would have broken the the program. -- Antoon Pardon -- http://mail.python.org/mailman/listinfo/python-list
List of all installed applications (XP)?
Hi all, I'm trying to generate a (exhaustive) list of all the applications that are installed on a user's machine. I've written some code that reads the registry ('App Paths'): code appKey = win32api.RegOpenKeyEx(win32con.HKEY_LOCAL_MACHINE, 'SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths', 0, win32con.KEY_READ) sklist = win32api.RegEnumKeyEx(appKey) for skey in sklist: print skey[0] try: wPath = win32api.RegQueryValue(appKey, skey[0]) print '' + wPath except pywintypes.error,details: print '### Error [pywintypes.error]: ' + details[2] win32api.RegCloseKey(appKey) /code This works, but I was wondering wether that is the best way to go about this? Can I be sure it lists *all* the applications? What does it mean when a pywintypes.error is thrown (code 13, 'Invalid data')? Thanks, g -- http://mail.python.org/mailman/listinfo/python-list
Re: Does a function like isset() exist in Python?
On Wed, 22 Jun 2005 23:09:57 -0400, Patrick Fitzsimmons wrote: Hi, I'm sure I should know this, but I can't find it in the manual. Is there a function in Python like the function in PHP isset()? It should take a variable name and return True or False depending on whether the variable is initialized. What would you use such a function for? The closest thing I can think of is testing whether a particular object exists. Eg to test whether your program is running under a version of Python that defines bools, and if not, define your own objects which act in a similar way, you would say try: False except NameError: False = 0 True = not False Note that there is no need to do something with the name False in the try clause -- just use it. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list
Re: pickle broken: can't handle NaN or Infinity under win32
On Thu, 23 Jun 2005 00:11:20 -0400, Tim Peters wrote: Well, I try, Ivan. But lest the point be missed wink, 754 doesn't _want_ +0 and -0 to act differently in almost any way. The only good rationale I've seen for why it makes the distinction at all is in Kahan's paper Branch Cuts for Complex Elementary Functions, or Much Ado About Nothing's Sign Bit. There are examples in that where, when working with complex numbers, you can easily stumble into getting real-world dead-wrong results if there's only one flavor of 0. And, of course, atan2 exists primarily to help convert complex numbers from rectangular to polar form. It isn't necessary to look at complex numbers to see the difference between positive and negative zero. Just look at a graph of y=1/x. In particular, look at the behaviour of the graph around x=0. Now tell me that the sign of zero doesn't make a difference. Signed zeroes also preserve 1/(1/x) == x for all x, admittedly at the cost of y==x iff 1/y == 1/x (which fails for y=-0 and x=+0). Technically, -0 and +0 are not the same (for some definition of technically); but practicality beats purity and it is more useful to have -0==+0 than the alternative. Odd bit o' trivia: following the rules for signed zeroes in 754 makes exponeniation c**n ambiguous, where c is a complex number with c.real == c.imag == 0.0 (but the zeroes may be signed), and n is a positive integer. The signs on the zeroes coming out can depend on the exact order in which multiplications are performed, because the underlying multiplication isn't associative despite that it's exact. That's an implementation failure. Mathematically, the sign of 0**n should depend only on whether n is odd or even. If c**n is ambiguous, then that's a bug in the implementation, not the standard. I stumbled into this in the 80's when KSR's Fortran compiler failed a federal conformance test, precisely because the test did atan2 on the components of an all-zero complex raised to an integer power, and I had written one of the few 754-conforming libms at the time. They wanted 0, while my atan2 dutifully returned -pi. I haven't had much personal love for 754 esoterica since then ... Sounds to me that the Feds wanted something broken and you gave them something that was working. No wonder they failed you :-) -- Steven. -- http://mail.python.org/mailman/listinfo/python-list
RE: List of all installed applications (XP)?
[Guy Lateur] | I'm trying to generate a (exhaustive) list of all the | applications that are | installed on a user's machine. I've written some code that reads the | registry ('App Paths'): [.. snip code ..] | Can I be sure it lists *all* the applications? What -- from your point of view -- is an application? I can pretty much guarantee that by no means does every app install an AppPath: it's merely a convenience. Neither does every app have an Add/Remove Program entry. (And some things have entries which aren't apps). And where do you draw the line between some arbitrary executable and an app? Just asking, because I don't think you can do anything exhaustive until you know the scope you're trying to exhaust. TJG This e-mail has been scanned for all viruses by Star. The service is powered by MessageLabs. For more information on a proactive anti-virus service working around the clock, around the globe, visit: http://www.star.net.uk -- http://mail.python.org/mailman/listinfo/python-list
Re: PEP ? os.listdir enhancement
On Thu, 23 Jun 2005 11:34:02 +0200, Andreas Kostyrka wrote: What's wrong with (os.path.join(d, x) for x in os.listdir(d)) It's short, and easier to understand then some obscure option ;) Andreas how does it help in using list comprehension, as the ones in the first post? -- Riccardo Galli Sideralis Programs http://www.sideralis.net -- http://mail.python.org/mailman/listinfo/python-list
Re: PEP ? os.listdir enhancement
On Thu, 23 Jun 2005 12:56:08 +0300, Konstantin Veretennicov wrote: On 6/22/05, Riccardo Galli [EMAIL PROTECTED] wrote: I propose to add an 'abs' keyword which would make os.listdir return the absolute path of files instead of a relative path. What about os.listdir(dir='relative/path', abs=True)? Should listdir call abspath on results? Should we add another keyword rel? Would it complicate listdir unnecessarily? - kv keyword dir not exists (don't know if you added as example or not) and abs set to true would return abspath on result. What else could it do ? -- Riccardo Galli Sideralis Programs http://www.sideralis.net -- http://mail.python.org/mailman/listinfo/python-list
Re: case/switch statement?
Andrew Durdin wrote: In this case the dictionary is obviously a better and clearer choice. I've generally found for other circumstances where I've used switch statements that the code ends up more readable if it's reorganised so that the switch statements are all of the form above, or are eliminated entirely--so I don't miss a switch/case statement in Python. I find the lack of a switch statement encourages me to write data-driven programs (which is a god-send when I have to enhance them later to deal with additional cases). The thing I love most about Python is the fact that callables can be slung around at run-time, just like any other object. So, I set up (usually for command-line options) mappings from options to callables which define how to perform action x. Then as the options are translated, I query the lookup tables, and store the results in appropriately named variables (e.g create_connection, connect_link for a program I use to test serial data circuits with a variety of connections and links running over different hardware). The main body of the program is then comparatively trivial, because it just calls methods whose names describe (in a high-level way) what they do. A new connection or link type can be handled just by adding an entry to the appropriate dictionary. Basically, it's the GoF Strategy pattern, without all the pain that's required to set it up in static languages. Cheers, Nick. -- http://mail.python.org/mailman/listinfo/python-list
Re: Database recommendations for Windows app
On 2005-06-23, Joel Rosdahl [EMAIL PROTECTED] wrote: Or APSW http://www.rogerbinns.com/apsw.html. Interesting. I was hoping it would not have one pysqlite2 limitation: if you have an empty database, cursor.description always returns None, even if you have pragma empty_result_callbacks=1 (pysqlite 1.x doesn't have the problem). But apsw also requires data to be avaliable before you can get column descriptions. However, the tracing stuff and the various hooks you can set look really interesting. Dave Cook -- http://mail.python.org/mailman/listinfo/python-list
Re: PEP ? os.listdir enhancement
Riccardo Galli wrote: On Thu, 23 Jun 2005 12:56:08 +0300, Konstantin Veretennicov wrote: What about os.listdir(dir='relative/path', abs=True)? Should listdir call abspath on results? Should we add another keyword rel? Would it complicate listdir unnecessarily? keyword dir not exists (don't know if you added as example or not) and abs set to true would return abspath on result. What else could it do ? He probably meant that a 'join' option would be more natural than an 'abs' option. After all, your examples use os.path.join to create a valid path that can be used as the argument to other module os functions. Whether the results are absolute or relative should depend on the initial argument to os.listdir. Daniel -- http://mail.python.org/mailman/listinfo/python-list
re:Single Application Instance Example
Whit this mutex is it possible when an instance is running in background and you try to open a new instance. you cancel it and show the first? Greetz -- http://mail.python.org/mailman/listinfo/python-list
Re: List of all installed applications (XP)?
| What -- from your point of view -- is an application? Good question. Let me try to elaborate: I would like to know if people in our company (building techniques) are using non-licensed software (eg Photoshop, Office, AutoCad). So I guess by 'application' I mean commercial software packages like those. Is it safe to assume those apps get listed in AppPath? I don't think my users are cunning enough to mess with the registry, so I guess we're talking about the 'standard' installation. | Neither does every app have an Add/Remove Program | entry. (And some things have entries which aren't apps). Just out of curiosity: can one read the info/list one gets in Add/Remove Programs? It's not a problem I get results that aren't actually apps, but it is important I get all apps. Thanks, g -- http://mail.python.org/mailman/listinfo/python-list
Re: PEP ? os.listdir enhancement
Konstantin Veretennicov wrote: On 6/22/05, Riccardo Galli [EMAIL PROTECTED] wrote: I propose to add an 'abs' keyword which would make os.listdir return the absolute path of files instead of a relative path. What about os.listdir(dir='relative/path', abs=True)? Should listdir call abspath on results? Should we add another keyword rel? Would it complicate listdir unnecessarily? - kv I'm in favour of Riccardo's suggestion, but I think he's got the name of the keyword wrong. The signature should be listdir(path, with_path=False) and cater absolute and relative paths alike. The need for such an enhancement is not particularly pressing, as workarounds abound. Here's another one: glob.glob(/usr/lib/games/../games/*) ['/usr/lib/games/../games/schwarzerpeter'] Peter -- http://mail.python.org/mailman/listinfo/python-list
RE: List of all installed applications (XP)?
[Guy Lateur] | | | [TJG] | | What -- from your point of view -- is an application? | | Good question. Let me try to elaborate: I would like to know | if people in | our company (building techniques) are using non-licensed software (eg | Photoshop, Office, AutoCad). So I guess by 'application' I | mean commercial software packages like those. Hmmm. While I understand your requirement, it's not as thought there's some easily-discernible charactersistics of commercial software packages which should have licenses but which don't unless you're prepared to compile a list and to add to it over time. | Is it safe to assume those apps get listed in AppPath? I wouldn't have said so: AppPaths is basically useful if you want to be able to go Start Run blah.exe without having to hunt through Program Files etc. Since many apps simply set up a Start Menu shortcut, there's no need for this. | Just out of curiosity: can one read the info/list one gets in | Add/Remove | Programs? It's not a problem I get results that aren't | actually apps, but it | is important I get all apps. I honestly don't know: I imagine Googling around will give some hits (for the question in general and for Add/Remove in particular): it can hardly be an unheard of issue. If someone's solved it in one way, it's almost certainly possible to translate that to Python (or to use their tool, if it's accessible). I have an idea it's held in the registry, but I'm not sure. You could try running up regedit and searching for likely strings. By the sound of it, you're almost better off compiling a list of .exe from machines and building up a blacklist from those. TJG This e-mail has been scanned for all viruses by Star. The service is powered by MessageLabs. For more information on a proactive anti-virus service working around the clock, around the globe, visit: http://www.star.net.uk -- http://mail.python.org/mailman/listinfo/python-list
Re: os.system(cmd) isn't working
On 23/06/05 Tim Golden said: This is only half an answer, but I personally find faffing about with the double-quote / double-backslash stuff between Python and Windows a pain in the neck, so where I can I avoid it. Indeed. I believe this is why Python has os.sep. Mike -- Michael P. Soulier [EMAIL PROTECTED] http://www.digitaltorque.ca http://opag.ca python -c 'import this' Jabber: [EMAIL PROTECTED] signature.asc Description: Digital signature -- http://mail.python.org/mailman/listinfo/python-list
RE: os.system(cmd) isn't working
[Michael P. Soulier] | On 23/06/05 Tim Golden said: | | This is only half an answer, but I personally find faffing | about with the double-quote / double-backslash stuff between | Python and Windows a pain in the neck, so where I can I avoid it. | | Indeed. I believe this is why Python has os.sep. | | Mike Well, true, but if you were trying to enter a particular file path as the OP was (c:\program files\ etc.) would you really want to have c: + os.sep + program files... or os.path.join (c:, program files...)? And where do the double-quotes go etc? I'm not saying all these things aren't possible; my only point is that rather than try to remember / work it out, I generally try to avoid the issue. TJG This e-mail has been scanned for all viruses by Star. The service is powered by MessageLabs. For more information on a proactive anti-virus service working around the clock, around the globe, visit: http://www.star.net.uk -- http://mail.python.org/mailman/listinfo/python-list
Re: PEP ? os.listdir enhancement
Riccardo Galli wrote: On Thu, 23 Jun 2005 11:34:02 +0200, Andreas Kostyrka wrote: What's wrong with (os.path.join(d, x) for x in os.listdir(d)) It's short, and easier to understand then some obscure option ;) Andreas how does it help in using list comprehension, as the ones in the first post? You can nest list comprehension [ e for e in (os.path.join(d, x) for x in os.listdir(d)) if os.path.isdir (e)] You might also want to look at module itertools, which has better support for transforming and filtering in multiple steps. Daniel -- http://mail.python.org/mailman/listinfo/python-list
Re: Does a function like isset() exist in Python?
In article [EMAIL PROTECTED], Patrick Fitzsimmons [EMAIL PROTECTED] wrote: Hi, I'm sure I should know this, but I can't find it in the manual. Is there a function in Python like the function in PHP isset()? It should take a variable name and return True or False depending on whether the variable is initialized. Thanks for any help, Patrick The straight-forward thing would be to simply access the variable and catch any resulting NameError exception that's raised if it's not defined: try: x print x is defined except NameError: print no it's not Next question, why do you want to do this? I suspect for most idioms where you would something like this, the more pythonic way would be to set the variable to None at some point, then test to see if it's still None later on: x = None while foo: if blah: x = baz if x != None: print x was assigned a value -- http://mail.python.org/mailman/listinfo/python-list
Re: python create WMI instances
I've got as far as this. I don't get any errors but still no printer import win32com.client WBEM = win32com.client.GetObject(rwinmgmts:{impersonationLevel=impersonate}!\\ + . + r\root\cimv2) printer = WBEM.Get(Win32_Printer).SpawnInstance_() printer.Properties_('DeviceID').Value = 'myprinter' printer.Properties_('DriverName').Value = 'HP 2000C' printer.Properties_('Location').Value = 'myoffice' printer.Properties_('Network').Value = 'True' printer.Properties_('Shared').Value = 'True' printer.Properties_('ShareName').Value = 'myprintershare' printer.Put_ Do I need to specify any flags with Put_ ? Thanks for all your help, I can almost taste victory! MW. Tim Golden wrote: [EMAIL PROTECTED] | Win32_Printer doesn't work with the Create method and | AddPrinterConnection only lets me add a connection to a share. I'll | try and work out how to set the printer object properties in | the format | suggested; | | oPrinter.Properties_ (DriverName).Value = strDriver | | Cheers, MW. I'm sorry my module won't have been much use to you in this, but it would be *really* helpful if you could post [a fragment of] the code you come up with so I can see what changes I need to make to help our future instance-spawners. It's just that I've never had the need to do this, and don't have any time to experiment at present. Thanks TJG This e-mail has been scanned for all viruses by Star. The service is powered by MessageLabs. For more information on a proactive anti-virus service working around the clock, around the globe, visit: http://www.star.net.uk -- http://mail.python.org/mailman/listinfo/python-list
Re: case/switch statement?
NickC [EMAIL PROTECTED] wrote: The thing I love most about Python is the fact that callables can be slung around at run-time, just like any other object. Yup. A while ago, I was doing a lot of file parsing with state machines. Each state was a function. The main loop of the state machine was just: state = start while state != end: state, output = state (input) Each function was responsible for returning a (nextState, output) tuple. -- http://mail.python.org/mailman/listinfo/python-list
Re:
I'm using Eric3 and realy like it. http://www.die-offenbachs.de/detlev/eric3.html Adriaan Renting| Email: [EMAIL PROTECTED] ASTRON | Phone: +31 521 595 217 P.O. Box 2 | GSM: +31 6 24 25 17 28 NL-7990 AA Dwingeloo | FAX: +31 521 597 332 The Netherlands| Web: http://www.astron.nl/~renting/ Doug Ly [EMAIL PROTECTED] 06/22/05 4:37 PM Is there a good IDE for Python? I have heard that Eclipse has a plugin for Jython only. Thanks --Doug -- http://mail.python.org/mailman/listinfo/python-list
User interfaces in console (dialog like)
Hi all. I need to provide to my users a graphical interface to be used from os' command line. Initially I thought something equivalent to Unix dialog, and googling around I have found Python Dialog (http://pythondialog.sourceforge.net/). This would be the perfect solution for me if it could be cross platform. However, it doesn't work on Windows, just on Linux/Unix. Do you guys know an alternative that fits my needings without moving from Python? Thanks, -ng -- http://mail.python.org/mailman/listinfo/python-list
RE: python create WMI instances
[EMAIL PROTECTED] | I've got as far as this. I don't get any errors but still no | printer | | import win32com.client | WBEM = | win32com.client.GetObject(rwinmgmts:{impersonationLevel=imper | sonate}!\\ + . + r\root\cimv2) | printer = WBEM.Get(Win32_Printer).SpawnInstance_() | printer.Properties_('DeviceID').Value = 'myprinter' | printer.Properties_('DriverName').Value = 'HP 2000C' | printer.Properties_('Location').Value = 'myoffice' | printer.Properties_('Network').Value = 'True' | printer.Properties_('Shared').Value = 'True' | printer.Properties_('ShareName').Value = 'myprintershare' | printer.Put_ | | Do I need to specify any flags with Put_ ? Well you certainly need to call it -- printer.Put_ () -- and not just refer to it. But maybe that's just a cut-and-paste problem. In theory (according to the docs) you could pass a CREATE_ONLY flag (or something like that) but I don't think it's strictly necessary. I'd imagine that it would create if it didn't exist. Check out msdn for more details than you want to know. TJG This e-mail has been scanned for all viruses by Star. The service is powered by MessageLabs. For more information on a proactive anti-virus service working around the clock, around the globe, visit: http://www.star.net.uk -- http://mail.python.org/mailman/listinfo/python-list
Swig wrapping C++ Polymorphism
Hi, I asked this on the SWIG mailing list, but it's pretty dead over there... I'm trying to get Python to pass a subclass of a C++ object to another C++ object... I have three C++ classes, TiledImageSource ZoomifyReaderWx which ISA TiledImageSource TiffWriter which has a method which takes a TiledImageSource reader = bright.ZoomifyReaderWx() writer = bright.TiledTiffWriter() writer.SetImageSource(reader) - doesn't work, error below. TiffWriter has a SetImageSource method that takes a pointer to a TiledImageSource. When I try to pass an instance of ZoomifyReaderWx to TiffWriter, SWIG can't hook the two up. How can I fix this? I think I need a typemap, but I'm not sure of the syntax. Thanks! -Jim Test script reader = bright.ZoomifyReaderWx() reader.Open(C:/Slides/test.pff) writer = bright.TiledTiffWriter() writer.SetImageSource(reader) writer.CreateFile(C:/Slides/test.tif) while not writer.IsFinished(): writer.ProcessABit() print ., Exception C:\jimc\prj\bright\scripts\vsEditpython piplineTest.py Traceback (most recent call last): File piplineTest.py, line 11, in ? writer.SetImageSource(reader) File C:\jimc\prj\bright\scripts\vsEdit\bright.py, line 88, in SetImageSource def SetImageSource(*args): return _bright.TiledTiffWriter_SetImageSource(*ar gs) TypeError: argument number 2: a 'TiledImageSource *' is expected, 'PySwigObject( _p_ZoomifyReaderWx)' is received Interface files (exceprts) class ZoomifyReaderWx: public TiledImageSource { public: bool Open(wxString filename); void Close(); ZoomifyReaderWx(); //%pragma(python) addtomethod = __init__:self._setOORInfo(self) // necessary for ZoomableImageReader virtual int GetWidth(int reduction = 0); virtual int GetHeight(int reduction = 0); ... class TiledTiffWriter { public: TiledTiffWriter(); //%pragma(python) addtomethod = __init__:self._setOORInfo(self) void SetImageSource(TiledImageSource *source); void SetJpegQuality(int quality) { m_iJpegQuality = quality; } void CreateFile(char *filename); ... class TiledImageSource { public: //%pragma(python) addtomethod = __init__:self._setOORInfo(self) virtual int GetWidth(int reduction = 0); virtual int GetHeight(int reduction = 0); -- http://mail.python.org/mailman/listinfo/python-list
Re: PEP ? os.listdir enhancement
On Thu, 23 Jun 2005 13:25:06 +0200, Daniel Dittmar wrote: He probably meant that a 'join' option would be more natural than an 'abs' option. After all, your examples use os.path.join to create a valid path that can be used as the argument to other module os functions. Whether the results are absolute or relative should depend on the initial argument to os.listdir. Daniel I got the point, and you're right. I didn't though about that and 'abs' as keyword becomes nonsense. Needing a more general kewyword, as pointed out by Peter Otten -- Riccardo Galli Sideralis Programs http://www.sideralis.net -- http://mail.python.org/mailman/listinfo/python-list
Python 2.1 / 2.3: xreadlines not working with codecs.open
Hi all, I just found a problem in the xreadlines method/module when used with codecs.open: the codec specified in the open does not seem to be taken into account by xreadlines which also returns byte-strings instead of unicode strings. For example, if a file foo.txt contains some text encoded in latin1: import codecs f = codecs.open('foo.txt', 'r', 'utf-8', 'replace') [l for l in f.xreadlines()] ['\xe9\xe0\xe7\xf9\n'] But: import codecs f = codecs.open('foo.txt', 'r', 'utf-8', 'replace') f.readlines() [u'\ufffd\ufffd'] The characters in latin1 are correctly dumped with readlines, but are still in latin1 encoding in byte-strings with xreadlines. I tested with Python 2.1 and 2.3 on Linux and Windows: same result (I haven't Python 2.4 installed here) Can anybody confirm the problem? Is this a bug? I searched this usegroup and the known Python bugs, but the problem did not seem to be reported yet. TIA -- python -c print ''.join([chr(154 - ord(c)) for c in 'U(17zX(%,5.zmz5(17;8(%,5.Z65\'*9--56l7+-']) -- http://mail.python.org/mailman/listinfo/python-list
Re: List of all installed applications (XP)?
Guy Lateur [EMAIL PROTECTED] writes: | What -- from your point of view -- is an application? Good question. Let me try to elaborate: I would like to know if people in our company (building techniques) are using non-licensed software (eg Photoshop, Office, AutoCad). So I guess by 'application' I mean commercial software packages like those. Is it safe to assume those apps get listed in AppPath? I don't think my users are cunning enough to mess with the registry, so I guess we're talking about the 'standard' installation. | Neither does every app have an Add/Remove Program | entry. (And some things have entries which aren't apps). Just out of curiosity: can one read the info/list one gets in Add/Remove Programs? It's not a problem I get results that aren't actually apps, but it is important I get all apps. I think it's this registry key: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall Maybe you should try HKEY_CURRENT_USER\.. or HKEY_USERS\..\.. as well. Thomas -- http://mail.python.org/mailman/listinfo/python-list
Re: Looking For Geodetic Python Software
For spherical earth, this is easy, just treat the 2 locations as vectors whose origin is at the center of the earth and whose length is the radius of the earth. Convert the lat-long to 3-D rectangular coordinates and now the angle between the vectors is arccos(x dotproduct y). The over-ground distance is then just R*theta where theta is the angle. It's a bit more complicated in the real world - usually one takes a spheroid as defined by the wgs84 standard: http://www.codeguru.com/Cpp/Cpp/algorithms/article.php/c5115/ Maybe for python, this is enteresting (haven't used it myself though): http://pyogclib.sourceforge.net/ Diez -- http://mail.python.org/mailman/listinfo/python-list
Re: Database recommendations for Windows app
Dennis Lee Bieber wrote: Firebird might be a contender... I recently completed a 5 user Java based Windows reporting system that used Firebird as the SQL server based database. I found Firebird performed very well and I would not hesitate to use it again. Jussi Jumppanen Author of: Zeus for Windows Editor (New version 3.94 out now) The C/C++, Cobol, Java, HTML, Python, PHP, Perl folding editor Home Page: http://www.zeusedit.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Allowing only one instance of a script?
... lock file? -- http://mail.python.org/mailman/listinfo/python-list
Re: Allowing only one instance of a script?
On 2005-06-23, Tim Golden [EMAIL PROTECTED] wrote: [Ali] | | I have a script which I double-click to run. If i double-click it | again, it will launch another instance of the script. | | Is there a way to allow only one instance of a script, so that if | another instance of the script is launched, it will just | return with an | error. If you're on Windows, have a look at this recent thread: http://groups-beta.google.com/group/comp.lang.python/msg/2a4fadfd3d6e3d4b?hl=en If you're on Unix/Linux, the usual way to do this is with a lockfile. -- Grant Edwards grante Yow! I'd like MY data-base at JULIENNED and stir-fried! visi.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Python internals and parser
Hi, On 22.06.2005, at 23:18, Michael Barkholt wrote: Is there any detailed documentation on the structure of Pythons internals, besides the source code itself? More specifically I am looking for information regarding the C parser, since I am looking into the viability of using it in another project that needs to parse python code (and I would like the code to be written in C). maybe this link might help you: http://wiki.cs.uiuc.edu/cs427/PYTHON -- Wahrheit ist die Erfindung eines Lügners -- Heinz von Foerster -- http://mail.python.org/mailman/listinfo/python-list
RE: Single Application Instance Example
[DeRRudi] | | Whit this mutex is it possible when an instance is running in | background and you try to open a new instance. you cancel it and show | the first? | | Greetz All the Mutex is doing is providing a single token which only one instance of the app can hold at a time. Of itself, it doesn't provide any facility to awake background applications or do anything at all except exclude other apps from holding the same token. What you describe could be achieved a number of ways. (He says, sounding knowledegeable, but having little real experience to back himself up). Once the Mutex check proves that you're not the only instance running, you could, for example, find the top-level window of your app and activate it (assuming it has a window). You could embed some sort of mini-messaging within the application, say a small Pyro class, or a socket server, or a Windows pipe, or whatever, which will let your second instance send a message to the first which will then activate (whatever that means). In fact, you could probably combine the two by using a private Windows pipe which would both serve as a anyone else here? check and as a signal to an existing instance to wake up and dance. It all depends on what the app is doing, and how hard you want to try. TJG This e-mail has been scanned for all viruses by Star. The service is powered by MessageLabs. For more information on a proactive anti-virus service working around the clock, around the globe, visit: http://www.star.net.uk -- http://mail.python.org/mailman/listinfo/python-list
Re: how to use more than 1 __init__ constructor in a class ?
Steven D'Aprano wrote: On Wed, 22 Jun 2005 12:34:21 -0500, Rocco Moretti wrote: You could also turn __init__ into a dispatch fuction: #-- class myPointClass: def __init__(self, *args): if len(args) = 2: self.__init_two(*args) if len(args) == 3: self.__init_three(*args) Oh wow, so that's what I've been doing for years. Dispatching. And I thought I was just calling other functions :-) I think the distinction between just calling other functions and dispatching is that with dispatching, the function doesn't do any actual work by itself, but just hands off the work to a different function. http://www.c2.com/cgi/wiki?DispatchingForDummies That's the joys of a mostly self-taught programming knowledge: you miss out on all the buzzwords. Being mostly self taught myself, I have a tendancy to use infrequently encountered terms in related but technically inappropriate contexts, confusing the better informed people I deal with. ;-) -- http://mail.python.org/mailman/listinfo/python-list
Re: pydoc - suppressing builtins?
Alan Is it possible to persuade pydoc not to include documentation for Alan methods inherited from built-in classes? Alan I'm sure I could qite easily write something to post-process the Alan HTML files; just wondering if there might be an easier way. If you're going to go to the trouble of writing something to post-process the HTML, maybe it would be no more difficult to simply patch pydoc, then everyone wins. Skip -- http://mail.python.org/mailman/listinfo/python-list
Re: Database recommendations for Windows app
Magnus Lycka [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] Cameron Laird wrote: OK, I'm with you part of the way. Typical Access developers are *always* involved with DLL hell, right? You're surely not saying that Python worsens that frustration, are you? I think Dan was commenting on flaws in Microsoft's products, not in Python. As I understand it, he was suggesting to use something else than Access with Python, not something else than Python with Access. The O.P. wanted a database for his Python app, and Thomas Bartkus suggested Access. Not exactly! I suggested the built in Microsoft DAO or ADO database libraries which he could use without need to distribute with his app. The Access application is simply another client app that sits on top of DAO/ADO and would be quite unnecessary here. Any Python/DB application you wished to distribute for MS Windows would do best talk to the ADO library directly - end of distribution problems. * Everyone with WindowsXP already has the DAO and ADO libraries. * Not everyone has (or needs) MS Access which one would have to pay for and could not distribute freely with ones Python app. * Python has no need of MS Access in order to create, maintain, and manipulate databases using Microsofts built in ADO database facilities - although a developer *might* find Access useful as an inspection/debugging tool on his own workstation. All of which used to confuse the hell out of me :-) Thomas Bartkus -- http://mail.python.org/mailman/listinfo/python-list
Reraise exception with modified stack
Hi, I've made a small utility to re-raise an exception with the same stack as before with additional information in it. Since I want to keep the same exception type and that some types have very specific constructors (which take, for example, more than one parameter), the only safe way I have found to made it is by hacking the str representation: import sys class ExceptionStr: def __init__(self, content): self.content = content self.infos = [] def addinfo(self, info): self.infos.insert(0, info) def __call__(self): return '\n' + '\n'.join(self.infos + [self.content]) def reraise(exception, additionalInfo): strFunc = getattr(exception, __str__, None) if not isinstance(strFunc, ExceptionStr): strFunc = ExceptionStr(str(exception)) exception.__str__ = strFunc strFunc.addinfo(additionalInfo) raise exception, None, sys.exc_info()[-1] if __name__ == '__main__': def foo(): raise AttributeError('Test') def bar(): foo() try: try: try: bar() except Exception, exception: reraise(exception, While doing x:) except Exception, exception: reraise(exception, While doing y:) except Exception, exception: reraise(exception, While doing z:) Suppose the resulted traceback is: Traceback (most recent call last): File somefile.py, line 52, in ? reraise(exception, While doing z:, MyException) File somefile.py, line 50, in ? reraise(exception, While doing y:, Exception) File somefile.py, line 48, in ? reraise(exception, While doing x:) File somefile.py, line 46, in ? bar() File somefile.py, line 40, in bar foo() File somefile.py, line 38, in foo raise AttributeError('Test') AttributeError: While doing z: While doing y: While doing x: Test I would like to know how to code the reraise function so that the lines 48, 50 and 52 don't appear in the stack. Is it possible? Thx and regards, Nicolas -- http://mail.python.org/mailman/listinfo/python-list
Re: Database recommendations for Windows app
In article [EMAIL PROTECTED], Dave Cook [EMAIL PROTECTED] wrote: On 2005-06-23, Peter Hansen [EMAIL PROTECTED] wrote: . . . Type checking? SQLite currently supports neither. sqlite3 has a strict affinity mode, but I'm not exactly sure how one sets it. http://www.sqlite.org/datatype3.html . . . While I'm still learning SQLite3, I already know enough to reinforce Mr. Cook's point, and report that Version 3 re- tains the data manager's yummy lightness, while significantly enhancing its functionality in such regards as type correctness. -- http://mail.python.org/mailman/listinfo/python-list
newbie - modules for jython (under grinder 3) ?
I'm just trying to use Grinder 3 to beat up my http-app. Grinder 3 comes with its own jython.jar. Some of the sample scripts: http://grinder.sourceforge.net/g3/script-gallery.html use import statements that don't work for me. Reading around, these are reference to modules. Do I need a proper jython instead of the one that grinder ships with? Or... Do I need to get and install some modules? If the latter, where from and how? I note that not all Python modules can be used as Jython modules. My most urgent need is for the threading module, although I've faked my way round that by using Doug Lea's concurrent library in java, which I can call from Jython. http://gee.cs.oswego.edu/dl/classes/EDU/oswego/cs/dl/util/concurrent/intro.html But I'd like to know how to do it right BugBear -- http://mail.python.org/mailman/listinfo/python-list
Re: Database recommendations for Windows app
Magnus Lycka [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] Cameron Laird wrote: OK, I'm with you part of the way. Typical Access developers are *always* involved with DLL hell, right? You're surely not saying that Python worsens that frustration, are you? I think Dan was commenting on flaws in Microsoft's products, not in Python. As I understand it, he was suggesting to use something else than Access with Python, not something else than Python with Access. The O.P. wanted a database for his Python app, and Thomas Bartkus suggested Access. Not exactly! I suggested the built in Microsoft DAO or ADO database libraries which he could use without need to distribute with his app. The Access application is simply another client app that sits on top of DAO/ADO and would be quite unnecessary here. Any Python/DB application you wished to distribute for MS Windows would do best talk to the ADO library directly - end of distribution problems. * Everyone with WindowsXP already has the DAO and ADO libraries. * Not everyone has (or needs) MS Access which one would have to pay for and could not distribute freely with ones Python app. * Python has no need of MS Access in order to create, maintain, and manipulate databases using Microsofts built in ADO database facilities - although a developer *might* find Access useful as an inspection/debugging tool on his own workstation. All of which used to confuse the hell out of me :-) Thomas Bartkus -- http://mail.python.org/mailman/listinfo/python-list
Re: List of all installed applications (XP)?
Get Tim Golden's wmi module (http://tgolden.sc.sabren.com/python/wmi.html). I recently had to help my brother remove some spyware, and so I used some of the example that came with WMI to read through the registry to extract startup keys, services, etc. Even if your users aren't sophisticated enough to mess with the registry, rest assured that the software installation programs are. You should be able to find traces of any installed commercial program that was released in the past 5 years - I suspect they *all* leave traces in the registry at this point. Go to HKEY_LOCAL_MACHINE\SOFTWARE and you will get a list of software vendors, and you can enumerate keys from there. Good luck! -- Paul -- http://mail.python.org/mailman/listinfo/python-list
Re: Allowing only one instance of a script?
Am Wed, 22 Jun 2005 23:49:21 -0700 schrieb Ali: Hi, I have a script which I double-click to run. If i double-click it again, it will launch another instance of the script. Is there a way to allow only one instance of a script, so that if another instance of the script is launched, it will just return with an error. Hi, Create a file which contains the PID (process ID) of the current process in a directory. If the file already exists, the file is running. If your script dies without removing the pid-file, you need to look during the start if the PID which is in the file is sill alive. There is a small race condition between os.path.exists() and writing the file. If you want to be 100% sure you need to use file locking. HTH, Thomas -- Thomas Güttler, http://www.thomas-guettler.de/ -- http://mail.python.org/mailman/listinfo/python-list
Re: python create WMI instances
Right I got it working. I had to put a printer port in aswell. I'll now look at a script to create printer ports. My goal is being able to query the printers on print server x and then recreate the printers (shares and ports) on print server y. Thanks, for all your help Tim, much appreciated. MW import win32com.client WBEM = win32com.client.GetObject(rwinmgmts:{impersonationLevel=impersonate}!\\ + . + r\root\cimv2) printer = WBEM.Get(Win32_Printer).SpawnInstance_() printer.Properties_('DeviceID').Value = 'myprinter' printer.Properties_('DriverName').Value = 'HP 2000C' printer.Properties_('Location').Value = 'myoffice' printer.Properties_('Network').Value = 'True' printer.Properties_('Shared').Value = 'True' printer.Properties_('ShareName').Value = 'myprintershare' printer.Properties_('PortName').Value = 'IP_169.254.110.14' printer.Put_() -- http://mail.python.org/mailman/listinfo/python-list
Re: os.system(cmd) isn't working
On Thu, 23 Jun 2005 00:02:55 -0400, Gregory Piñero [EMAIL PROTECTED] wrote: Hi guys, I'm trying to run this statement: os.system(r'C:\Program Files\Mozilla Firefox\firefox.exe' + ' www.blendedtechnologies.com') The goal is to have firefox open to that website. When I type r'C:\Program Files\Mozilla Firefox\firefox.exe' + ' www.blendedtechnologies.com' in the python interpreter I get: 'C:\\Program Files\\Mozilla Firefox\\firefox.exe www.blendedtechnologies.com' And when I copy this into my command prompt (less outermost ' ) firefox opens up to that page like I would expect. However in python nothing happens and I get exit status 1. I'm using Python 2.3 on Windows XP pro service pack 2. What is wrong with: os.startfile(www.blendedtechnologies.com) -- http://mail.python.org/mailman/listinfo/python-list
Re: Loop until condition is true
Michael Hoffman wrote: Stelios Xanthakis wrote: Magnus Lycka wrote: Right. Silly me. Maybe in some future Python version, True and False will be constants, like None is since Python 2.4. Actually, there is support in marshal to write True and False objects so I don't understand why this isn't in 2.4 Because it would break existing code. Yes. Code that has variables named 'True' and 'False'. Stelios -- http://mail.python.org/mailman/listinfo/python-list
Re: PEP 304 - is anyone really interested?
Am Wed, 22 Jun 2005 18:01:51 -0500 schrieb Skip Montanaro: I wrote PEP 304, Controlling Generation of Bytecode Files: http://www.python.org/peps/pep-0304.html ... Hi, I am interested in a small subset: I want to import a file without a '.pyc' being generated. Background: I sometimes missuse python for config files. For example there is a file $MYAPP/etc/debuglog.py. This file contains simple assignments search=0 indexing=1 In the code I use it like this: sys.path.append(...) # Put $MYAPP/etc into the path import debuglog ... if debuglog.search: print Searching for I don't want pyc files in the etc directory. Up to now I do it like this: import debuglog try: os.unlink(...debuglog.pyc) except: pass Thomas -- Thomas Güttler, http://www.thomas-guettler.de/ -- http://mail.python.org/mailman/listinfo/python-list
Re: PEP ? os.listdir enhancement
Am Wed, 22 Jun 2005 17:57:14 +0200 schrieb Riccardo Galli: Hi, I noticed that when I use os.listdir I need to work with absolute paths 90% of times. While I can use a for cycle, I'd prefere to use a list comprehension, but it becomes too long. Hi, I like it. But as you noticed, too, join would be better than abs. Example: # mylistdir.py import os import sys def mylistdir(dir, join=False): for file in os.listdir(dir): yield os.path.join(dir, file) print list(mylistdir(sys.argv[1])) Thomas -- Thomas Güttler, http://www.thomas-guettler.de/ -- http://mail.python.org/mailman/listinfo/python-list
Re: newbie - modules for jython (under grinder 3) ?
bugbear wrote: I'm just trying to use Grinder 3 to beat up my http-app. Grinder 3 comes with its own jython.jar. Some of the sample scripts: http://grinder.sourceforge.net/g3/script-gallery.html use import statements that don't work for me. Reading around, these are reference to modules. Do I need a proper jython instead of the one that grinder ships with? I guess so - at least there are jython-modules written as *py-files in my jython installation, including the threading.py module. Now - I don't exactly remember how to specify where to find those, but AFAIK there is a system property that you have to set to that path. So - go, fetch jython from jython.org, install it and try to proceed. Diez -- http://mail.python.org/mailman/listinfo/python-list
Re: Allowing only one instance of a script?
On 2005-06-23, Thomas Guettler [EMAIL PROTECTED] wrote: Create a file which contains the PID (process ID) of the current process in a directory. If the file already exists, the file is running. That's how it's usually done. If your script dies without removing the pid-file, you need to look during the start if the PID which is in the file is sill alive. There is a small race condition between os.path.exists() and writing the file. That's why it's pointless to call os.path.exists(). If you want to be 100% sure you need to use file locking. I've never seen it done that way. The standard method is to use open() with flags O_CREAT|O_EXCL. If the open() is sucessful, then you have the lock. If it fails, somebody else already has the lock. Another method is to create a temp file containing the PID and then call link() to rename it. Both open() and link() are atomic operations, so there's no race condition. -- Grant Edwards grante Yow! I don't know WHY I at said that... I think it visi.comcame from the FILLINGS inmy read molars... -- http://mail.python.org/mailman/listinfo/python-list
Re: Database recommendations for Windows app
Thomas Bartkus wrote: Magnus Lycka [EMAIL PROTECTED] wrote in message The O.P. wanted a database for his Python app, and Thomas Bartkus suggested Access. Not exactly! Sorty, I meant Jet or whatever the backend is called these days. I suggested the built in Microsoft DAO or ADO database libraries which he could use without need to distribute with his app. The Access application is simply another client app that sits on top of DAO/ADO and would be quite unnecessary here. Any Python/DB application you wished to distribute for MS Windows would do best talk to the ADO library directly - end of distribution problems. If we start with vanilla Python, we need just the tiny PySqlite module and DB-API compliant Python code to get a SQLite solution to work. One small 3rd party module which is trivial to bundle. There is no way you can access ADO with less 3rd party stuff bundled than that. The minimum is to bundle win32all or ctypes, but then you need to work much harder. You probably want a 3rd party python ADO library as well. Then it's much more stuff to bundle. -- http://mail.python.org/mailman/listinfo/python-list
Re: Allowing only one instance of a script?
On 2005-06-23, Grant Edwards [EMAIL PROTECTED] wrote: On 2005-06-23, Tim Golden [EMAIL PROTECTED] wrote: [Ali] | | I have a script which I double-click to run. If i double-click it | again, it will launch another instance of the script. | | Is there a way to allow only one instance of a script, so that if | another instance of the script is launched, it will just | return with an | error. If you're on Windows, have a look at this recent thread: http://groups-beta.google.com/group/comp.lang.python/msg/2a4fadfd3d6e3d4b?hl=en If you're on Unix/Linux, the usual way to do this is with a lockfile. You can also use a network port instead of a file. Binding a socket to a port is an exclusive and atomic operation. An advantage to the network port scheme is that the lock automatically goes away if the program dies. A disadvantiage is that it can't contain information (date/time/PID) like a file can. -- Grant Edwards grante Yow! I want DUSTIN at HOFFMAN!! ... I want visi.comLIBRACE!! YOW!! -- http://mail.python.org/mailman/listinfo/python-list
Re: python create WMI instances
Heres a script for creating printer ports import win32com.client WBEM = win32com.client.GetObject(rwinmgmts:{impersonationLevel=impersonate}!\\ + . + r\root\cimv2) printer = WBEM.Get(Win32_Printer).SpawnInstance_() printer.Properties_('DeviceID').Value = 'myprinter' printer.Properties_('DriverName').Value = 'HP 2000C' printer.Properties_('Location').Value = 'myoffice' printer.Properties_('Network').Value = 'True' printer.Properties_('Shared').Value = 'True' printer.Properties_('ShareName').Value = 'myprintershare' printer.Properties_('PortName').Value = 'IP_169.254.110.14' printer.Put_() -- http://mail.python.org/mailman/listinfo/python-list
Re: PEP ? os.listdir enhancement
Hi All-- Thomas Guettler wrote: I like it. But as you noticed, too, join would be better than abs. Example: # mylistdir.py import os import sys def mylistdir(dir, join=False): for file in os.listdir(dir): yield os.path.join(dir, file) print list(mylistdir(sys.argv[1])) Mmmm, how about: # mylistdir.py import os, os.path import sys def mylistdir(dir, join=False): for file in os.listdir(dir): if join: yield join(dir, file) else: yield file print list(mylistdir(sys.argv[1])) or print list(mylistdir(sys.argv[1],os.path.join)) That way I could def my own join and call it as print list(mylistdir(sys.argv[1],myjoin)) (Note that in your version the join argument isn't used at all.) Metta, Ivan -- Ivan Van Laningham God N Locomotive Works http://www.andi-holmes.com/ http://www.foretec.com/python/workshops/1998-11/proceedings.html Army Signal Corps: Cu Chi, Class of '70 Author: Teach Yourself Python in 24 Hours -- http://mail.python.org/mailman/listinfo/python-list
Re: PEP 304 - is anyone really interested?
Thomas Guettler [EMAIL PROTECTED] writes: Am Wed, 22 Jun 2005 18:01:51 -0500 schrieb Skip Montanaro: I wrote PEP 304, Controlling Generation of Bytecode Files: http://www.python.org/peps/pep-0304.html ... Hi, I am interested in a small subset: I want to import a file without a '.pyc' being generated. Background: I sometimes missuse python for config files. For example Although I was not interested originally, I think that's a use case I also have. Optional config files, which should not be compiled to .pyc or .pyo. Only removing the .py file doesn't have the expected effect if a .pyc and/or .pyo if is left. I don't think the PEP supports such a use case. BTW: While I'me reading the PEP to check the above, I encountered this: Add a new environment variable, PYTHONBYTECODEBASE, to the mix of environment variables which Python understands. PYTHONBYTECODEBASE is interpreted as follows: If not defined, Python bytecode is generated in exactly the same way as is currently done. sys.bytecodebase is set to the root directory (either / on Unix and Mac OSX or the root directory of the startup (installation???) drive -- typically C:\ -- on Windows). If defined and it refers to an existing directory to which the user has write permission, sys.bytecodebase is set to that directory and bytecode files are written into a directory structure rooted at that location. If defined but empty, sys.bytecodebase is set to None and generation of bytecode files is suppressed altogether. AFAIK, it is not possible to define empty env vars on Windows. c:\set PYTHONCODEBASE= would remove this env var instead of setting it to an empty value. Thomas -- http://mail.python.org/mailman/listinfo/python-list
Re: how to use more than 1 __init__ constructor in a class ?
Rocco Moretti wrote: Steven D'Aprano wrote: snip That's the joys of a mostly self-taught programming knowledge: you miss out on all the buzzwords. Being mostly self taught myself, I have a tendancy to use infrequently encountered terms in related but technically inappropriate contexts, confusing the better informed people I deal with. ;-) Indeed. I find I use even more buzzwords because I can just make up as many as I want. -- http://mail.python.org/mailman/listinfo/python-list
Re: Loop until condition is true
Stelios Xanthakis [EMAIL PROTECTED] writes: Michael Hoffman wrote: Stelios Xanthakis wrote: Magnus Lycka wrote: Right. Silly me. Maybe in some future Python version, True and False will be constants, like None is since Python 2.4. Actually, there is support in marshal to write True and False objects so I don't understand why this isn't in 2.4 Because it would break existing code. Yes. Code that has variables named 'True' and 'False'. Making None a constant broke existing code (and I just saw old code that assigned to None). Are True and False that much more common as variable names than None? mike -- Mike Meyer [EMAIL PROTECTED] http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. -- http://mail.python.org/mailman/listinfo/python-list
Re: Database recommendations for Windows app
Magnus Lycka [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] Thomas Bartkus wrote: Magnus Lycka [EMAIL PROTECTED] wrote in message The O.P. wanted a database for his Python app, and Thomas Bartkus suggested Access. Not exactly! Sorty, I meant Jet or whatever the backend is called these days. Hey! Even MS is confused these days. If we start with vanilla Python, we need just the tiny PySqlite module and DB-API compliant Python code to get a SQLite solution to work. One small 3rd party module which is trivial to bundle. There is no way you can access ADO with less 3rd party stuff bundled than that. The minimum is to bundle win32all or ctypes, but then you need to work much harder. You probably want a 3rd party python ADO library as well. Then it's much more stuff to bundle. I was thinking of Win32com which I expect lets you put a wrapper around ADO and work the ADO (or any other ActiveX) object model from within Python. However I must confess that while I am quite familiar with ADO, I haven't used it with Python. I do know that the ADO (or DAO) libraries are complete, SQL oriented, database systems that are available on every WinXP desktop. I *think* Jet refers to the underlying, .mdb file based storage engine that ADO rides on top of by default. All WinXP platforms have this and do not need another db platform - IOW we don't need to distribute a db platform here! Unless one simply prefers something else ;-) Thomas Bartkus -- http://mail.python.org/mailman/listinfo/python-list
Re: Database recommendations for Windows app
On 6/22/2005 3:08 PM, Cameron Laird wrote: In article [EMAIL PROTECTED], Dan [EMAIL PROTECTED] wrote: On 6/22/2005 1:14 PM, Dave Cook wrote: On 2005-06-22, Cameron Laird [EMAIL PROTECTED] wrote: Are you saying that Python-based applications are particularly vulnerable in this all-too-common scenario? If so, I'm not getting it; why is the architecture described more fragile than more traditional Windows-oriented development patterns? If not, then, ... well then I truly don't get your point. Maybe the point is the downside of depending on installed DLLs rather than shipping your own. Dave Cook Yes, DLL hell. ? OK, I'm with you part of the way. Typical Access developers are *always* involved with DLL hell, right? You're surely not saying that Python worsens that frustration, are you? No. -- http://mail.python.org/mailman/listinfo/python-list
Re: Database recommendations for Windows app
On 6/22/2005 9:51 PM, Peter Hansen wrote: Will McGugan wrote: Thanks for the replies. I think I'm going to go with sqllite for now. Your list didn't mention a few things that might be critical. Referential integrity? Type checking? SQLite currently supports neither. Just make sure you check the list of supported features to see that it really does what you need. -Peter So in SQLLite, what happens of you try to store XYZ in an integer field? -- http://mail.python.org/mailman/listinfo/python-list
Re: Loop until condition is true
Mike Meyer wrote: Making None a constant broke existing code (and I just saw old code that assigned to None). Are True and False that much more common as variable names than None? I would think so. I know that my pre-booleans-in-Python code routinely did something like from booleans import True, False. Of course the fix is easy, but it still must be applied before the code will run. -- Benji York -- http://mail.python.org/mailman/listinfo/python-list
Re: User interfaces in console (dialog like)
Do you only need to work on windows? if so you could use http://newcenturycomputers.net/projects/wconio.html to build your own gui. We used this for our inhouse ldap admin script. -- http://mail.python.org/mailman/listinfo/python-list
don't understand MRO
Hi, I have a subclassed PyQt class: class Node(object): def move(self, x,y): pass class CRhomb(QCanvasPolygon, Node): pass $ python v2.4.1 CRhomb.mro() [class '__main__.CRhomb', class 'qtcanvas.QCanvasPolygon', class 'qtcanvas.QCanvasPolygonalItem', class 'qtcanvas.QCanvasItem', class 'qt.Qt', type 'sip.wrapper', class '__main__.Node', type 'object'] a = CRhomb() a.move(1,2) This executes also Node.move(a, 1,2) Why? Because even QCanvasItem.move delegates the call to the derived object? But qt.Qt does not have a move() method... how does it get passed on to Node? Thanks in advance, Ciao Uwe -- http://mail.python.org/mailman/listinfo/python-list
Re: pickle broken: can't handle NaN or Infinity under win32
[Tim Peters'] Well, I try, Ivan. But lest the point be missed wink, 754 doesn't _want_ +0 and -0 to act differently in almost any way. The only good rationale I've seen for why it makes the distinction at all is in Kahan's paper Branch Cuts for Complex Elementary Functions, or Much Ado About Nothing's Sign Bit. There are examples in that where, when working with complex numbers, you can easily stumble into getting real-world dead-wrong results if there's only one flavor of 0. And, of course, atan2 exists primarily to help convert complex numbers from rectangular to polar form. [Steven D'Aprano] It isn't necessary to look at complex numbers to see the difference between positive and negative zero. Just look at a graph of y=1/x. In particular, look at the behaviour of the graph around x=0. Now tell me that the sign of zero doesn't make a difference. OK, I looked, and it made no difference to me. Really. If I had an infinitely tall monitor, maybe I could see a difference, but I don't -- the sign of 0 on the nose makes no difference to the behavior of 1/x for any x other than 0. On my finite monitor, I see it looks like the line x=0 is an asymptote, and the graph approaches minus infinity on that line from the left and positive infinity from the right; the value of 1/0 doesn't matter to that. Signed zeroes also preserve 1/(1/x) == x for all x, No, signed zeros preverse that identity for exactly the set {+Inf, -Inf}, and that's all. That's worth something, but 1/(1/x) == x isn't generally true in 754 anyway. Most obviously, when x is subnormal, 1/x overflows to an infinity (the 754 exponent range isn't symmetric around 0 -- subnormals make it heavy on the negative side), and then 1/(1/x) is a zero, not x. 1/(1/x) == x doesn't hold for a great many normal x either (pick a pile at random and check -- you'll find counterexamples quickly). admittedly at the cost of y==x iff 1/y == 1/x (which fails for y=-0 and x=+0). Technically, -0 and +0 are not the same (for some definition of technically); but practicality beats purity and it is more useful to have -0==+0 than the alternative. Can just repeat that the only good rationale I've seen is in Kahan's paper (previously referenced). Odd bit o' trivia: following the rules for signed zeroes in 754 makes exponeniation c**n ambiguous, where c is a complex number with c.real == c.imag == 0.0 (but the zeroes may be signed), and n is a positive integer. The signs on the zeroes coming out can depend on the exact order in which multiplications are performed, because the underlying multiplication isn't associative despite that it's exact. That's an implementation failure. Mathematically, the sign of 0**n should depend only on whether n is odd or even. If c**n is ambiguous, then that's a bug in the implementation, not the standard. As I said, these are complex zeroes, not real zeroes. The 754 standard doesn't say anything about complex numbers. In rectangular form, a complex zero contains two real zeroes. There are 4 possiblities for a complex zero if the components are 754 floats/doubles: +0+0i +0-0i -0+0i -0-0i Implement Cartesian complex multiplication in the obvious way: (a+bi)(c+di) = (ac-bd) + (ad+bc)i Now use that to raise the four complex zeroes above to various integer powers, trying different ways of grouping the multiplications. For example, x**4 can be computed as ((xx)x)x or (xx)(xx) or x((xx)x) etc. You'll discover that, in some cases, for fixed x and n, the signs of the zeroes in the result depend how the multiplications were grouped. The 754 standard says nothing about any of this, _except_ for the results of multiplying and adding 754 zeroes. Multiplication of signed zeroes in 754 is associative. The problem is that the extension to Cartesian complex multiplication isn't associative under these rules in some all-zero cases, mostly because the sum of two signed zeroes is (under 3 of the rounding modes) +0 unless both addends are -0. Try examples and you'll discover this for yourself. I was part of NCEG (the Numerical C Extension Group) at the time I stumbled into this, and they didn't have any trouble following it wink. It was a surprise to everyone at the time that Cartesian multiplication of complex zeroes lost associativity when applying 754 rules in the obvious way, and no resolution was reached at that time. I stumbled into this in the 80's when KSR's Fortran compiler failed a federal conformance test, precisely because the test did atan2 on the components of an all-zero complex raised to an integer power, and I had written one of the few 754-conforming libms at the time. They wanted 0, while my atan2 dutifully returned -pi. I haven't had much personal love for 754 esoterica since then ... Sounds to me that the Feds wanted something broken and you gave them something that was working. No wonder they failed you :-) Yup, and they did a lot of that
Re: pickle broken: can't handle NaN or Infinity under win32
Hi All-- Tim Peters wrote: Fortran is so eager to allow optimizations that failure due to numeric differences in conformance tests rarely withstood challenge. +1 QOTW Metta, Ivan -- Ivan Van Laningham God N Locomotive Works http://www.andi-holmes.com/ http://www.foretec.com/python/workshops/1998-11/proceedings.html Army Signal Corps: Cu Chi, Class of '70 Author: Teach Yourself Python in 24 Hours -- http://mail.python.org/mailman/listinfo/python-list
Re: how to use more than 1 __init__ constructor in a class ?
Singletoned wrote: Rocco Moretti wrote: Steven D'Aprano wrote: snip That's the joys of a mostly self-taught programming knowledge: you miss out on all the buzzwords. Being mostly self taught myself, I have a tendancy to use infrequently encountered terms in related but technically inappropriate contexts, confusing the better informed people I deal with. ;-) Indeed. I find I use even more buzzwords because I can just make up as many as I want. This thread 'branch' (humm, is this an appropriate term for the last few quotes, going to Steven's?) is soothing in reminding us we are not alone. That there is a sort of distributed 'Alma Mater' of the 'Teach-It-Yourself School of Computing', producing a virtual FOAF group (Is FOAF, Friend Of A Friend or Flock Of A Feather?) jm -- http://mail.python.org/mailman/listinfo/python-list
Re: Using PAMIE to upload and download files...is it possible?
If you go into the PAMIE users group and go to the files Section you will see modalPopupTest.py this will handles Uploads, pop-ups, alerts using PAMIE PAMIE will include this feature in the next release http://groups.yahoo.com/group/Pamie_UsersGroup/files/ RLM scrimp wrote: Well, thanx to Erin I got everything I needed to do to work. I basically used 2 classes and wrote a driver using PAMIE 1 for the two File Download windows and 1 for the Save As window Here are the classes I used. I took out the comments, but its really not too hard to understand class FileDownloadDialog (threading.Thread): def __init__(self): threading.Thread.__init__(self) self.windowName = File Download self.hwnd = None def fetchWindows (self,attempts=20): tries = 0 while triesattempts: tries = tries + 1 try: self.hwnd = winGuiAuto.findTopWindows(self.windowName) return except: print 'Checking for window named '+ self.windowName + '', print 'Attempt #',tries time.sleep(1) def run (self): self.fetchWindows() oButton = [] for hw in self.hwnd: tButton = winGuiAuto.findControls(hw,Save,Button) if len(tButton) 0: wHwnd = hw self.hwnd = wHwnd oButtons = winGuiAuto.findControls(self.hwnd,Save,Button) time.sleep(0.5) for oButton in oButtons: winGuiAuto.clickButton(oButton) Heres the 2nd class I used class SaveAsZipDialog (threading.Thread): def __init__(self, docPath): threading.Thread.__init__(self) self.windowName = Save As self.hwnd = None self.document = docPath def fetchWindow (self,attempts=20): tries = 0 while tries attempts: tries = tries + 1 try: self.hwnd = winGuiAuto.findTopWindow(self.windowName) return except: print 'Checking for window named '+ self.windowName + '', print 'Attempt ',tries time.sleep(1) def run (self): self.fetchWindow() fText = winGuiAuto.findControl(self.hwnd, None, Edit) winGuiAuto.setEditText(fText,self.document) oButtons = winGuiAuto.findControls(self.hwnd,Save) time.sleep(0.5) for oButton in oButtons: winGuiAuto.clickButton(oButton) I used PAMIE to get me through the web stuff and when it clicked on the link to download the zip file I wanted these two classes would kick in and take over from there. If anyone needs help feel free to email me or post up on here. Thanks again Erin! --Barry -- http://mail.python.org/mailman/listinfo/python-list
Urgent problem: Embedding Python questions....
Hi, I am embedding Python into a multi-threaded C++ application runnig on Solaris and need urgent clarification on the embedding architecture and its correct usage (as I am experience weird behaviors). Can anyone clarify: - if Python correctly supports multiple sub-interpreters (Py_NewInterpreter) ? - if Python correctly supports multiple thread states per sub-interpreter (PyThreadState_New) ? and the real question: - what is the rationale for choosing one of: [a] one sub-interpreter with many thread states [b] many sub-interpreters with one thread state each [c] many sub-interpreters with many threas states each Thanks for helping Alan -- http://mail.python.org/mailman/listinfo/python-list
Re: User interfaces in console (dialog like)
On Thu, 23 Jun 2005 05:45:07 -0700, Negroup wrote: Hi all. I need to provide to my users a graphical interface to be used from os' command line. Initially I thought something equivalent to Unix dialog, and googling around I have found Python Dialog (http://pythondialog.sourceforge.net/). This would be the perfect solution for me if it could be cross platform. However, it doesn't work on Windows, just on Linux/Unix. Do you guys know an alternative that fits my needings without moving from Python? Thanks, -ng It doesn't depend on the language. There aren't truely portable graphic interface libraries, which show more than a coloured rectangle. For *nix, there is also curses-extra, which offers various widgets (textview,combobox,radio and checkbuttons and so on). http://www.sideralis.net/index.php?action=4pjid=20 Bye, Riccardo -- Riccardo Galli Sideralis Programs http://www.sideralis.net -- http://mail.python.org/mailman/listinfo/python-list
Re: Loop until condition is true
Mike Meyer wrote: Making None a constant broke existing code (and I just saw old code that assigned to None). Are True and False that much more common as variable names than None? Yes. In fact, I count at least 4 different modules in the Python 2.4 standard library that assign to True or False, mainly as a compatibility measure for the days before they were built-ins. If you try assigning None, CPython will refuse to compile the module, even if the code where None is assigned is unreachable. If there was ever a good reason to assign to None, I don't know it. -- Michael Hoffman -- http://mail.python.org/mailman/listinfo/python-list
Re: Loop until condition is true
Antoon Pardon wrote: Op 2005-06-22, Michael Hoffman schreef [EMAIL PROTECTED]: Remi Villatel wrote: Fredrik Lundh wrote: checking if a logical expression is true by comparing it to True is bad style, and comparing values using is is also bad style. I wrote it this way because, first, it's perfectly valid Python code and, second and most important, it's also a valid english sentence. As others have pointed out, it's not perfectly valid code. In fact it is frequently incorrect. That the same code would be incorrect in other circumstances doesn't make it invalid as it was used in a specific situation. I have written code my self with an if var is True statement and that is exactly what I wanted. Replacing it with if var would have broken the the program. That point was not lost on me (which is why I said it was frequently incorrect). I think it was lost on the OP though. -- Michael Hoffman -- http://mail.python.org/mailman/listinfo/python-list
Re: Reraise exception with modified stack
Nicolas Fleury wrote: Hi, I've made a small utility to re-raise an exception with the same stack as before with additional information in it. Since I want to keep the same exception type and that some types have very specific constructors (which take, for example, more than one parameter), the only safe way I have found to made it is by hacking the str representation: import sys class ExceptionStr: def __init__(self, content): self.content = content self.infos = [] def addinfo(self, info): self.infos.insert(0, info) def __call__(self): return '\n' + '\n'.join(self.infos + [self.content]) def reraise(exception, additionalInfo): strFunc = getattr(exception, __str__, None) if not isinstance(strFunc, ExceptionStr): strFunc = ExceptionStr(str(exception)) exception.__str__ = strFunc strFunc.addinfo(additionalInfo) raise exception, None, sys.exc_info()[-1] How about dropping reraise and changing: reraise(...) to: addinfo(...) raise Where addinfo looks like: def addinfo(exception, additionalInfo): strFunc = getattr(exception, __str__, None) if not isinstance(strFunc, ExceptionStr): strFunc = ExceptionStr(str(exception)) exception.__str__ = strFunc strFunc.addinfo(additionalInfo) So you finale would be: if __name__ == '__main__': def foo(): raise AttributeError('Test') def bar(): foo() try: try: try: bar() except Exception, exception: addinfo(exception, While doing x:) raise except Exception, exception: addinfo(exception, While doing y:) raise except Exception, exception: addinfo(exception, While doing z:) raise --Scott David Daniels [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list
pass an event up to parent widget
I have a Tkinter (frame) widget that contains several other frame widgets, each containing entry widgets. In the parent frame I have a 'save' button that is initially disabled. As it is now, each widget has a hasChanged property that I can poll to see if updates to the source data need to be made. hasChanged is set to True by an event routine in each frame widget, and this works fine for my exit routine which knows to poll each widget for hasChanged. What I don't know how to do is send an event up the chain to the top so it can change the 'save' button to NORMAL (telling the user 'The data has been changed and can be saved if wanted') . I don’t think bind_class() to all entry widgets is the way to go. I could create an after() alarm callback to poll hasChanged, but again this seems to awkward. I have looked at widget.event_add() but, don't know if this is viable. I am thinking a virtual event without any SEQUENCE, and then triggering it programmatically (from within the sub-widget event handlers). Is that doable? Isn't there a better way? Any suggestions? Bill -- http://mail.python.org/mailman/listinfo/python-list
Re: newbie - modules for jython (under grinder 3) ?
Diez B. Roggisch wrote: bugbear wrote: I'm just trying to use Grinder 3 to beat up my http-app. Grinder 3 comes with its own jython.jar. Some of the sample scripts: http://grinder.sourceforge.net/g3/script-gallery.html use import statements that don't work for me. Reading around, these are reference to modules. Do I need a proper jython instead of the one that grinder ships with? I guess so - at least there are jython-modules written as *py-files in my jython installation, including the threading.py module. Now - I don't exactly remember how to specify where to find those, but AFAIK there is a system property that you have to set to that path. So - go, fetch jython from jython.org, install it and try to proceed. OK - of course this means I'll have to tell Grinder to use my Jython, not its Jython. Hopefully that's well documented :-) BugBear -- http://mail.python.org/mailman/listinfo/python-list
Re: suggestions invited
Aditi wrote: hi all...i m a software engg. student completed my 2nd yr...i have been asked to make a project during these summer vacations...and hereby i would like to invite some ideas bout the design and implementation of an APPLICATION MONITORING SYSTEMi have to start from scrach so please tell me how to go bout it rite from the beggining this is the first time i m making a project of this complexity... i have to make a system used by the IT department of a company which contains 31 applications and their details which are being used in a company ...the details are... Application sub application catagoryplatform languageversion IT owner functional ownerremarks source code documentation last updated dates i want to design a system such that it lets the it employee enter the name of the application and gives him all the details about it...please suggest an appropriate design and the language which you think would be best to use...as i have enouf time with me and i can learn a new language as well...i currently know c and c++...your advise is welcomed Aditi I suggest you first learn a bit of python: go to www.python.org and download/install the current release; go through the online tutorial: http://docs.python.org/tut/tut.html . Then you might look at xml as a means for storing the data. Xml is structured, readable without special software(very helpful for debugging), and easy to use for simple data. Try the xml module from http://pyxml.sourceforge.net/topics/download.html [look at the demos for simple usage] Don't be intimidated by complex formal definitions of XML, what you need is not hard to use. -- George -- http://mail.python.org/mailman/listinfo/python-list
Re: PEP ? os.listdir enhancement
On Thu, 23 Jun 2005 09:21:55 -0600, Ivan Van Laningham wrote: Mmmm, how about: # mylistdir.py import os, os.path import sys def mylistdir(dir, join=False): for file in os.listdir(dir): if join: yield join(dir, file) else: yield file print list(mylistdir(sys.argv[1])) or print list(mylistdir(sys.argv[1],os.path.join)) That way I could def my own join and call it as print list(mylistdir(sys.argv[1],myjoin)) I think that the implementation of listdir is done in C, so the functionality would be added in C too. by the way, I think 'join' (cute keyword) should be a boolean and not a callable: the obvious way is that we join path using os.path.join, and not some sophisticated function. With a boolean keyword code is smaller and if we want to use our special join function we can do it simply. e.g def func(dir,join=False): return (join and join(dir,x) or x for x in os.listdir(dir)) os.listdir is actually supposed not to be a generator, like you suggested. Are there known future changes ? Bye, Riccardo -- Riccardo Galli Sideralis Programs http://www.sideralis.net -- http://mail.python.org/mailman/listinfo/python-list
Re: Avoiding deadlocks in concurrent programming
In article [EMAIL PROTECTED], Konstantin Veretennicov [EMAIL PROTECTED] wrote: On 22 Jun 2005 17:50:49 -0700, Paul Rubin http://phr.cx@nospam.invalid wrote: Even on a multiprocessor system, CPython (because of the GIL) doesn't allow true parallel threads, ... . Please excuse my ignorance, do you mean that python threads are always scheduled to run on the same single CPU? Or just that python threads are often blocked waiting for GIL? Any thread may execute inside the interpreter, but not concurrently with another. I don't see the original point, though. If you have a C application with no GIL, the queueing model is just as useful -- more, because a GIL avoids the same kind of concurrency problems in your application that it intends to avoid in the interpreter. Rigorous application of the model can be a little awkward, though, if you're trying to adapt it to a basically procedural application. The original Stackless Python implementation had some interesting options along those lines. Donn Cave, [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list
Re: os.system(cmd) isn't working
If firefox is not your default browser, os.system(r'cd c:\Program Files\Mozilla Firefox firefox ' + 'www.blendertechnologies.com') works for me. -- http://mail.python.org/mailman/listinfo/python-list