Re: Can't get exclusive file lock when safely renaming a file

2008-12-06 Thread Steve M
On Dec 6, 12:25 am, Steven D'Aprano [EMAIL PROTECTED] cybersource.com.au wrote: The rename works, but here is my problem: after getting what I thought was an exclusive lock on the new file, but before calling os.rename(), I can still over-write it from another process: $ echo this comes from

Re: How to avoid a warning message box when sending email via Outlook

2006-08-31 Thread Steve M
[Dermot Doran] | I'm very new to using win32com! I just want to send an email | message via Outlook. However, I keep getting an annoying | message box (generated by Outlook) indicating that my program | could be a virus. Does anybody know how to get around this? The users in our office

Re: newb question: file searching

2006-08-08 Thread Steve M
[EMAIL PROTECTED] wrote: I must ask, in the interest of learning, what is [file for file in files if file.endswith(extension)] actually doing? I know that 'file' is a type, but what's with the set up and the brackets and all? Other people explained the list comprehension, but you might

Re: newb question: file searching

2006-08-08 Thread Steve M
[EMAIL PROTECTED] wrote: Okay. This is almost solved. I just need to know how to have each entry in my final list have the full path, not just the file name. from http://docs.python.org/lib/os-file-dir.html: walk() generates the file names in a directory tree, by walking the tree either top

Re: Unicode question

2006-07-28 Thread Steve M
Ben Edwards (lists) wrote: I am using python 2.4 on Ubuntu dapper, I am working through Dive into Python. There are a couple of inconsictencies. Firstly sys.setdefaultencoding('iso-8859-1') does not work, I have to do sys.setdefaultencoding = 'iso-8859-1' When you run a Python script, the

Re: getaddrinfo not found on SCO OpenServer 5.0.5

2006-07-21 Thread Steve M
In case you haven't heard Microsoft is suing SCO for stealing his Internet concepts and letters and numbers, so you should probably just ditch OpenServer and get Debian like all the smart people have done. I guess the quality of SCO software has declined over the last forty or fifty years and

Re: iterate over a series of nodes in an XML file

2006-07-05 Thread Steve M
I see you've had success with elementtree, but in case you are still thinking about SAX, here is an approach that might interest you. The idea is basically to turn your program inside-out by writing a standalone function to process one myID node. This function has nothing to do with SAX or parsing

How to get the target of a Windows shortcut file

2006-05-05 Thread Steve M
Below is some code adapted from something I think was written by Mark Hammond. Originally I needed to create a Windows shortcut (link), and this code does the trick, requiring only the target filename and the desired shortcut name. Now, I find I need to open a shortcut and extract the target

Re: Memory limit to dict?

2006-04-11 Thread Steve M
An alternative is to use ZODB. For example, you could use the BTree class for the outermost layers of the nested dict, and a regular dict for the innermost layer. If broken up properly, you can store apparently unlimited amount of data with reasonable performance. Just remember not to iterate

Re: tips for this exercise?

2006-03-28 Thread Steve M
You have two lines inside the loop that ought to be outside the loop - the initial assignment to fiveNumbers and the return statement. Also, the line that appends new numbers to fiveNumbers is not quite correct - the append() method modifies the list in place, rather than return a new list.

Re: Python types

2006-03-24 Thread Steve M
I think it means that names, not objects, are weakly typed. So you can have: a = 4 a = 'hello' and there is no problem. The name 'a' doesn't have any type associated with it. This contrasts with strongly typed language like C where you declare the type of the name (variable) and the compiler

Re: Good thread pool module

2006-03-22 Thread Steve M
I believe Python in a Nutshell has a couple of clear examples using Queue and Threading, including one with a pool of worker threads that wait for entries in one queue and place results in another. Also you should look at the Python Cookbook, which probably includes the same or similar examples

Re: How can I load python script into Html ??

2005-12-13 Thread Steve M
Man, I don't even know where to start. There is no way this will work if you don't have a web browser that can interpret Python. I don't know of one, and I don't think anybody wants one because using a browser that would execute arbitrary Python code provided by the server would be an obscene

Re: How To Read Excel Files In Python?

2005-12-13 Thread Steve M
Derived from _Python Programming on Win32_ by Mark Hammond and Andy Robinson import win32com.client import win32com.client.dynamic class Excel: def __init__(self, filename=None): self.xlApp = win32com.client.dynamic.Dispatch('Excel.Application') if filename:

Re: Dive into Python PDF

2005-11-29 Thread Steve M
You should buy the book in hardcopy, that one looks fine. -- http://mail.python.org/mailman/listinfo/python-list

Re: the PHP ternary operator equivalent on Python

2005-11-18 Thread Steve M
Another way to simulate the ternary operator is this: a = (quantity 90 and It is very huge) or The value is correct You have to be careful of semantics of 'and' and 'or'. But in this case I wonder why you don't just test whether quantity is greater than 90 and assign the corresponding value to

Re: newbie - How do I import automatically?

2005-11-16 Thread Steve M
The file C:\Python24\Lib\sitecustomize.py (which I think doesn't exist by default) executes every time Python starts. (This means not just your IDLE session but every time you run any Python script.) One use for this file is to invoke sys.setdefaultencoding because that name gets deleted during

Re: A Tcl/Tk programmer learns Python--any advice?

2005-11-08 Thread Steve M
Even though its for any (not just Tcl) experienced programmer, and even though you've got all the appropriate resources, I'll mention that you should get a lot out of the book Dive Into Python, at http://www.diveintopython.org/ -- http://mail.python.org/mailman/listinfo/python-list

Re: So, Which Version is Suitable for Beginners

2005-11-06 Thread Steve M
There is a new gratis VMWare player at http://www.vmware.com/download/player/ You can download an image http://www.vmware.com/vmtn/vm/browserapp.html that they call a Browser Appliance, but if I remember correctly it is Ubuntu. -- http://mail.python.org/mailman/listinfo/python-list

Re: Using Which Version of Linux

2005-11-06 Thread Steve M
Max wrote: (Mark Shuttleworth, ... really loves Python - he gave me quite a lot of money for using it). Please elaborate. -- http://mail.python.org/mailman/listinfo/python-list

Re: Python for .NET and IronPython

2005-11-02 Thread Steve M
I was under the impression that IronPython is like CPython and Jython, namely an implementation of the Python language. So in that sense it is exactly like normal Python, although I don't know how convenient it is to deploy. I was also under the impression that Python for .NET is like an API

Re: convert COM obj to integer

2005-11-02 Thread Steve M
I don't know exactly what a COM object is, but those aren't them. The win32com package takes care of converting everything to Python types. The excel call returns a tuple of tuples. That is, the outer tuple is the sequence of rows, and each such row is itself a tuple with one member per column

Re: Problem Pythoncard tutorial

2005-10-17 Thread Steve M
I'd say that the tutorial text (by Dan Shafer) and the file starter1.py are not in sync. The word 'self' doesn't appear in the source file, it isn't a keyword (just a convention) or a literal, and it isn't imported by wildcard or some other trickery. So just by inspection you can tell that the

Re: Queue question

2005-10-15 Thread Steve M
According to my Python in a Nutshell: q.get(block=True) is the signature, so, as you use it above, the call will hang until something is on the queue. If block is false and the queue is empty, q.get() will raise the exception Empty. q.get_nowait is apparently synonymous with q.get(block=False)

Re: Well written open source Python apps

2005-10-13 Thread Steve M
Here is an article discussing the coding style of BitTorrent. http://www.onlamp.com/pub/a/python/2003/7/17/pythonnews.html Maybe that code is worth looking at. -- http://mail.python.org/mailman/listinfo/python-list

Re: Advice on this code

2005-10-12 Thread Steve M
output.write(wrkmisc(ifile,2582)) output.write(wrkviol(ifile,2774,16)) output.write(wrkaccid(ifile,3270,16)) output.write(wrkmisc2(ifile,3638)) output.write(wrkcov(ifile,3666,6))

Changing console text color

2005-10-10 Thread Steve M
Hello, I've been trying to change the text color on a windows console program I've been working on with no luck. I should mention that I'm a novice so please dummy up your replies. Thanks-in-Advance Steve -- http://mail.python.org/mailman/listinfo/python-list

Re: Changing console text color

2005-10-10 Thread Steve M
Thank you. I appreciate the help. Steve Larry Bates wrote: You can use this module to control console windows background and text colors. http://www.effbot.org/zone/console-index.htm -Larry Bates Steve M wrote: Hello, I've been trying to change the text color on a windows

Re: Bug in COM Makepy utility? (ActivePython 2.4)

2005-10-07 Thread Steve M
After exploring the bug database I discovered that this bug has been reported since March, and appears to derive from a bug in Python itself. http://bugs.activestate.com/show_bug.cgi?id=38052 It apparently only happens when the code generated by Makepy is really big (which it is for Word or

Re: Lambda evaluation

2005-10-06 Thread Steve M
Here's another one: d = {} for x in [1,2,3]: ... d[x] = (lambda z: lambda y: y * z) (x) ... d[1](3) 3 d[2](3) 6 -- http://mail.python.org/mailman/listinfo/python-list

Bug in COM Makepy utility? (ActivePython 2.4)

2005-10-06 Thread Steve M
When I use the COM Makepy utility on one computer with WindowsXP, ActivePython 2.3 and I select the library Microsoft Word 10.0 Object Library (8.2), things work fine. When I have WindowsXP, ActivePython 2.4 (build 247) and Microsoft Word 11.0 Object Library (8.3), then I get the following

Re: MS Word mail merge automation

2005-10-05 Thread Steve M
I was finally able to get things working right, so I thought I'd stick an example here for posterity. An example of a MS Word mail merge using the COM interface. In order for this script to work you must first run the COM Makepy utility and select Microsoft Word 10.0 Object Library (8.2) or

MS Word mail merge automation

2005-09-30 Thread Steve M
I'm trying to do invoke the mail merge functionality of MS Word from a Python script. The situation is that I have a template Word document, and a record that I've generated in Python, and I want to output a new Word .doc file with the template filled in with the record I've generated. (To

Re: Windows paths, Java, and command-line arguments, oh my!

2005-09-21 Thread Steve M
Thank you. I was able to fix it by putting the '-Dwhatever=x' bit before the '-jar y.jar' bit. I had no idea this could matter. Thanks all for the help. -- http://mail.python.org/mailman/listinfo/python-list

Re: Getting tired with py2exe

2005-09-20 Thread Steve M
What about PyInstaller that was announced the other day? The feature list looks great, and it appears the developers intend to maintain and enhance the program indefinitely.

Windows paths, Java, and command-line arguments, oh my!

2005-09-19 Thread Steve M
I'm trying to invoke a Java command-line program from my Python program on Windows XP. I cannot get the paths in one of the arguments to work right. The instructions for the program describe the following for the command-line arguments: java -jar sforcedataloader.jar

Re: Windows paths, Java, and command-line arguments, oh my!

2005-09-19 Thread Steve M
Well, apparently I fried my brain trying to sort this out. There is a typo in my example code in the post but not in my real program. (I know it is a no-no when asking help on c.l.py but I simplified some details from the real code in order not to confuse the issues. Probably backfired by this

Re: O'Reilly book on Twisted

2005-09-14 Thread Steve M
Does anybody know: Is this book fully up to date with Twisted 2.0? Does the book cover Nevow at all? Does the book cover general programming concepts related to concurrency? I'm reminded of those high quality articles about Deferreds and event programming by one of the Twisted developers? What

Re: How to protect Python source from modification

2005-09-12 Thread Steve M
This is a heck of a can of worms. I've been thinking about these sorts of things for awhile now. I can't write out a broad, well-structured advice at the moment, but here are some things that come to mind. 1. Based on your description, don't trust the client. Therefore, security, whatever that

Re: where is sys.path initialized?

2005-09-09 Thread Steve M
The PYTHONPATH environment variable is good for that. For general customizing beyond the path, you can make a file called: C:\Python24\Lib\site-packages\sitecustomze.py and it will be executed every time python runs. It might look like this: import sys sys.path.insert(0,

Re: encryption with python

2005-09-07 Thread Steve M
My goal is to combine two different numbers and encrypt them to create a new number that cann't be traced back to the originals. Here's one: def encrypt(x, y): Return a number that combines x and y but cannot be traced back to them. return x + y --

Re: is there a better way to check an array?

2005-09-01 Thread Steve M
You can check for membership in a list at least these ways: my_list.index(candidate) -returns the index into my_list of the first occurrence of candidate. Raises ValueError if candidate doesn't occur in my_list. my_list.find(candidate) -returns the index into my_list of the first occurrence of

Re: Mapping network drive on Linux

2005-08-31 Thread Steve M
You can approximate it by doing this at the command prompt: # mkdir /z #mount //blah/data /z I assume 'blah' is the hostname for a Windows machine and 'data' is the name of a share on blah. You might need to install smbfs and/or use 'mount.smb' and/or use 'mount -t smbfs'. Of course this can all

Re: Problem with Pythoncard

2005-08-26 Thread Steve M
There are some Python packages that I prefer to get from the developer instead of from my Linux distribution (Debian). Usually it is because I intend to upgrade the package before, or more often than, my distribution releases a new version. (A likely scenario if you use Debian - zing!) So I

Re: Binary Trees in Python

2005-08-20 Thread Steve M
[diegueus9] Diego Andrés Sanabria [EMAIL PROTECTED] wrote: Hello!!! I want know if python have binary trees and more? You might be interested that ZODB comes with some B-tree implementations. They can be used alone or you can persist them in the ZODB quite easily.

Re: Python Light Revisted?

2005-08-20 Thread Steve M
I agree with you in part and disagree in part. I don't see the point to making the distribution any smaller. 10MB for the installer from python.org, 16MB for ActiveState .exe installer. How is 5MB lightweight while 10MB isn't? The Windows XP version of Java at java.com is 16+ MB, and the .NET

Re: Iterparse and ElementTree confusion

2005-08-17 Thread Steve M
when i attempted [to load 150MB xml file] my PC goes to lala land, theres much HDD grinding followed by windows runnign low on virtual memory popup after 10-15mins. Then just more grinding...for an hour before i gave up I have had great success using SAX to parse large XML files. If you use care

Re: Python's Exception, and Capitalization

2005-08-12 Thread Steve M
You might find the Python Style Guide to be helpful: http://www.python.org/doc/essays/styleguide.html -- http://mail.python.org/mailman/listinfo/python-list

Re: Printing to printer

2005-08-12 Thread Steve M
it helps. Larry Bates Steve M wrote: Hello, I'm having problems sending information from a python script to a printer. I was wondering if someone might send me in the right direction. I wasn't able to find much by Google TIA Steve Thank you, I'll give it a try. Steve -- http

Re: Printing to printer

2005-08-12 Thread Steve M
Kristian Zoerhoff wrote: On 8/11/05, Steve M [EMAIL PROTECTED] wrote: Kristian Zoerhoff wrote: On 8/11/05, Steve M [EMAIL PROTECTED] wrote: Hello, I'm having problems sending information from a python script to a printer. I was wondering if someone might send me

Re: Psyco Linux

2005-08-12 Thread Steve M
c/codegen.h:19:3: #error sorry -- I guess it won't work like that on 64-bits machines The first error output by gcc suggests the 64-bit OS might be the problem. But I don't actually know what that error means. -- http://mail.python.org/mailman/listinfo/python-list

Printing to printer

2005-08-11 Thread Steve M
Hello, I'm having problems sending information from a python script to a printer. I was wondering if someone might send me in the right direction. I wasn't able to find much by Google TIA Steve -- http://mail.python.org/mailman/listinfo/python-list

Re: Printing to printer

2005-08-11 Thread Steve M
Kristian Zoerhoff wrote: On 8/11/05, Steve M [EMAIL PROTECTED] wrote: Hello, I'm having problems sending information from a python script to a printer. I was wondering if someone might send me in the right direction. I wasn't able to find much by Google Which platform? Directions

Re: Psyco Linux

2005-08-11 Thread Steve M
First, I tried the usual python setup.py install but that did not work. How exactly did it fail? Perhaps you can paste the error output from this command. -- http://mail.python.org/mailman/listinfo/python-list

Re: trying to parse non valid html documents with HTMLParser

2005-08-03 Thread Steve M
You were right, the HTMLParser of htmllib is more permissive. He just ignores the bad tags ! The HTMLParser on my distribution is a she. But then again, I am using ActivePython on Windows... -- http://mail.python.org/mailman/listinfo/python-list

Re: Create a variable on the fly

2005-07-27 Thread Steve M
PythonWin 2.3.5 (#62, Feb 9 2005, 16:17:08) [MSC v.1200 32 bit (Intel)] on win32. Portions Copyright 1994-2004 Mark Hammond ([EMAIL PROTECTED]) - see 'Help/About PythonWin' for further copyright information. locals()['OSCAR'] = 'the grouch' OSCAR 'the grouch' --

Re: How to run python script in background after i logout

2005-07-24 Thread Steve M
Harlin Seritt wrote: I have a remote linux server where I can only access it via ssh. I have a script that I need to have run all the time. I run like so: python script.py It runs fine. When I log off ssh I notice that the script died when I logged off. How do I make sure it stays running?

Re: Help with mass remove in text file

2005-07-13 Thread Steve M
First, in your intro you say you want to remove all strings of the form f=n; where n can be 0-14. So you want to remove f=0; and f=1; and ... Later, you appear to be trying to remove f=; which may be what you want but it doesn't match your described intentions. Second, the formatting (whitespace)

Re: PY2EXE = Is there a way to go backwards? EXE2PY

2005-07-13 Thread Steve M
I have the executable of a script that I wrote, that has been erased. Is there any way to retrieve the uncompiled python script from the executable that was created with py2exe? You're gonna need a case of 20-weight ball bearings and several quarts of antifreeze. Preferably Quakerstate. No,

Re: Overcoming herpetophobia (or what's up w/ Python scopes)?

2005-06-17 Thread Steve M
This link seems to be about Closures in Python, but I am not feeling sharp enough at the moment to evaluate the correctness of the discussion. http://en.wikipedia.org/wiki/Python_programming_language#Closures As others have said, you might get more useful responses if you can elaborate upon what

Re: Pressing A Webpage Button

2005-06-01 Thread Steve M
Do you actually need to 'press' the button? Or do you just need the effect that pressing the button would bring about (e.g., submitting a Google search query and receiving the results page)? If the latter, then you might want to search for, e.g., html form get post and check out some results.

Re: ZODB memory problems (was: processing a Very Large file)

2005-05-22 Thread Steve M
class ExtendedTupleTable(Persistent): def __init__(self): self.interning = ObjectInterning() # This Set stores all generated ExtendedTuple objects. self.ets = Set() # et(s): ExtendedTuple object(s) # This dictionary stores a mapping of elements to Sets of

Re: Is Python suitable for a huge, enterprise size app?

2005-05-18 Thread Steve M
This thread: http://mail.python.org/pipermail/python-dev/2005-January/051255.html discusses the problem with memory allocation in CPython. Apparently CPython is not good at, or incapable of, releasing memory back to the operating system. There are ways to compensate for this. I guess the comment

Re: processing a Very Large file

2005-05-17 Thread Steve M
I'm surprised you didn't recommend to use ZODB. Seems like an ideal way to manage this large amount of data as a collection of Python objects... -- http://mail.python.org/mailman/listinfo/python-list

Re: compile shebang into pyc file

2005-04-27 Thread Steve M
I just happened across the page linked to below, and remembered this thread, and, well... here you go: http://www.lyra.org/greg/python/ Executable .pyc files Ever wanted to drop a .pyc file right into your web server's cgi-bin directory? Frustrated because the OS doesn't know what to do

Function to log exceptions and keep on truckin

2005-04-14 Thread Steve M
import sys, traceback def e2str(id): Return a string with information about the current exception. id is arbitrary string included in output. exc = sys.exc_info() file, line, func, stmt = traceback.extract_tb(exc[2])[-1] return(%s: %s line %s (%s): %s % (id, func, line,

Re: Version Number Comparison Function

2005-03-25 Thread Steve M
I recently saw this: http://www.egenix.com/files/python/mxTools.html mx.Tools.verscmp(a,b) Compares two version strings and returns a cmp() function compatible value (,==, 0). The function is useful for sorting lists containing version strings. The logic used is as follows: the strings

Re: Tuple index

2005-02-21 Thread Steve M
John Machin wrote: Steve M wrote: Hello, I'm trying to figure out the index position of a tuple member. I know the member name, but I need to know the members index position. Tuples, like lists, don't have members in the sense that they can be named like t.foo. The only way

Re: Tuple index

2005-02-21 Thread Steve M
Steven Bethard wrote: Steve M wrote: I guess I explained my problem incorrectly. Let me try again. tuple = (fred, barney, foo) I know that foo is an element of tuple, but what I need to know is what the index of foo is, tuple[?]. Larry Bates's solution is probably the best way to go

Re: Tuple index

2005-02-21 Thread Steve M
Michael Hartl wrote: I actually find it strange that tuples don't have an index function, since finding the index doesn't involve any mutation. Anyone know why Python doesn't allow a statement like t.index('foo')? In any case, you can use the index method of list objects if you convert

Re: Tuple index

2005-02-21 Thread Steve M
John Machin wrote: Steve M wrote: I'm actually doing this as part of an exercise from a book. What the program is supposed to do is be a word guessing game. The program automaticly randomly selects a word from a tuple. Care to tell us which book is using a tuple for this, but hasn't got

Re: Tuple index

2005-02-21 Thread Steve M
Steven Bethard wrote: Steve M wrote: I'm actually doing this as part of an exercise from a book. What the program is supposed to do is be a word guessing game. The program automaticly randomly selects a word from a tuple. You then have the oportunity to ask for a hint. I created another

Tuple index

2005-02-20 Thread Steve M
Hello, I'm trying to figure out the index position of a tuple member. I know the member name, but I need to know the members index position. I know that if I use the statement print tuple[4] that it will print the contents of that location. What I don't understand is if I know that foo