Re: need help on a data structure problem

2007-02-01 Thread Tom Plunket
Dongsheng Ruan wrote: > Not quite related with Python. But my Data Structure course is experiemented > on python and there is no data structure group, So I have to post here: > > Write a procedure (in pseudocode!) to increase the number of buckets in a > (closed) hash table. Analyze its time an

Non-blocking pipes during subprocess handling

2007-01-08 Thread Tom Plunket
I'm using subprocess to launch, well, sub-processes, but now I'm stumbling due to blocking I/O. Is there a way for me to know that there's data on a pipe, and possibly how much data is there so I can get it? Currently I'm doing this: process = subprocess.Popen( args,

Re: A python library to convert RTF into PDF ?

2007-01-05 Thread Tom Plunket
[EMAIL PROTECTED] wrote: > First, pdflatex is too slow. Second, my templates are M$-Word doc > files, and they cannot be easily converted to tex. I have tried to > convert them to tex using OpenOffice, but the result is ugly as hell. Ok, have you tried using the PDF printers (I've used PDFfactory

Re: A python library to convert RTF into PDF ?

2007-01-03 Thread Tom Plunket
[EMAIL PROTECTED] wrote: > So, what library can I use to convert from RTF to PDF ? GPL / BSD > Libraries are welcome. If you could write to LaTeX files instead, you could then just use pdflatex that comes with all of the LaTeX distributions. -tom! -- -- http://mail.python.org/mailman/listinf

Re: list/dictionary as case statement ?

2007-01-03 Thread Tom Plunket
Bjoern Schliessmann wrote: > Intels aren't RISC, are they? Not the ones in PCs. The OP didn't specify the CPU that's being used, however. -tom! -- -- http://mail.python.org/mailman/listinfo/python-list

Re: list/dictionary as case statement ?

2007-01-03 Thread Tom Plunket
Hendrik van Rooyen wrote: > It works well - and it is surprisingly fast too... > And its easy if the opcodes are all say one byte, > else you need an opcode length field too, and fancier > parsing. Often (always?) RISC architectures' instruction+operand lengths are fixed to the word size of the m

Re: DOS, UNIX and tabs

2007-01-02 Thread Tom Plunket
Peter Decker wrote: > > Maybe I'm also weird, but I use a variable-pitch font when programming > > in Python. So a "tab equals some number of spaces" really isn't useful > > to me. My setup is, "tab equals this much space". > > A year ago I would have thought you were weird, but after reading a

Re: DOS, UNIX and tabs

2007-01-01 Thread Tom Plunket
Lawrence D'Oliveiro wrote: > I think there should be a single environment variable, perhaps > called "TABS", which specifies the tab settings across all relevant tools > that work with text, including less and diff. So for example setting this > as > > export TABS=4 > > will cause these tool

Re: I want to see all the variables

2006-12-31 Thread Tom Plunket
Steven D'Aprano wrote: > What does the author of the original class know about *my* needs and > requirements? The only thing that the original class author might know is that mucking with data marked private may well cause problems, and hiding it therefore prevents those problems. > It may turn

Re: Why does Python never add itself to the Windows path?

2006-12-31 Thread Tom Plunket
vbgunz wrote: > I don't understand what all the fuss is about. Add a single page to the > installer and on it, have 3 radio buttons. I don't understand what the fuss is about, and would not give that recommendation based on my not understanding it! I have never ever needed or wanted to launch th

Re: Help with small program

2006-12-31 Thread Tom Plunket
Paul Watson wrote: > > It is certainly possible to construct a set of denominations for which the > > algorithm occasionally chooses badly. For example, if you give it the set > > (40,35,10) and ask it to make change for 70, it will be suboptimal. > > Unless I am missing the point, the minimum n

Re: Managing a queue of subprocesses?

2006-12-31 Thread Tom Plunket
cypher543 wrote: > That was a very good answer, and it sure sounds like it would work. > However, I failed at implementing it. :( My updated runQueue() function > is: > > def runQueue(self): > self.buildProcess = None > count = 1 # current position in the queue > while True: >

Re: DOS, UNIX and tabs

2006-12-31 Thread Tom Plunket
Marc 'BlackJack' Rintsch wrote: > >> Did you try to open your code files with another editor, which has a > >> different length for tabulator chars? It would look quite ugly, I > >> guess... > > > > Actually, no. Everyone can choose their own number of spaces-per-tab and > > it'll look right, as

Re: Easiest way to print from XP/DOS.

2006-12-29 Thread Tom Plunket
jim-on-linux wrote: > When the client runs the utility program the > output file is built but nothing prints and no > messages appear. If the file has a '.txt' extension, you could try os.system'ing "start ", which'll make the file pop open with notepad (or whatever happens to be associated wi

Re: Managing a queue of subprocesses?

2006-12-29 Thread Tom Plunket
cypher543 wrote: > self.buildPID = subprocess.Popen(buildCmd, stdout = subprocess.PIPE, stderr = > subprocess.STDOUT) Instead of calling it self.buildPID, you might just call it self.buildProcess or something. It's actually a Popen object that gets returned. So yes you can do what you want: _

Re: Starting a child process and getting its stdout?

2006-12-29 Thread Tom Plunket
Gabriel Genellina wrote: > Did you *actually* tried what Tom Plunket posted? Two tiny chars make > a difference. The sad irony is that before taking off for vacation I was struggling at work with the same problem in some sense. I couldn't figure out why for some processes I got

Re: textwrap.dedent replaces tabs?

2006-12-29 Thread Tom Plunket
OKB (not okblacke) wrote: > > (You dedent common leading tabs, except if preceded by common leading > > spaces (?)). > > There cannot be common leading tabs if they are preceded by > anything. If they were preceded by something, they wouldn't be > "leading". Right, but 'common leading w

Re: Starting a child process and getting its stdout?

2006-12-29 Thread Tom Plunket
cypher543 wrote: > Thank you for the examples, but I have tried all of that before. Did you try my example specifically? > No matter what I do, my program always hangs while it waits for the > process to exit and then it prints all of the output at once. > > self.buildPID = subprocess.Popen(["p

Re: Starting a child process and getting its stdout?

2006-12-29 Thread Tom Plunket
Tom Plunket wrote: > while p.poll() == None: > data = p.stdout.readline() > if data: > print data, If you change that print to something more decorated, like, print 'process said:', data, Then it might be more

Re: Starting a child process and getting its stdout?

2006-12-29 Thread Tom Plunket
cypher543 wrote: > This has been driving me insane for the last hour or so. I have search > everywhere, and nothing works. I am trying to use the subprocess module > to run a program and get its output line by line. But, it always waits > for the process to terminate and then return the output all

Re: A stupid question

2006-12-29 Thread Tom Plunket
luxnoctis wrote: > It says exactly: > > The specified module could not be found. > LoadLibrary(pythondll) failed > > Don't know if that helps at all. There's something installed on Compaq computers that uses the Python stuff too, but I never figured out what it was. I figured it may have been

Re: how to serve image files without disk use?

2006-12-29 Thread Tom Plunket
Ray Schumacher wrote: > But, how can I avoid disk writes? wx's *.SaveFile() needs a string > file name (no objects). > I'm going to investigate PIL's im.save(), as it appears to allow > file-objects. Take a look at the img2*.py files in wx.tools. They're sorta sketchy imo, but they do the tric

Re: textwrap.dedent replaces tabs?

2006-12-28 Thread Tom Plunket
Frederic Rentsch wrote: > Your rules seem incomplete. Not my rules, the stated documentation for dedent. "My" understanding of them may not be equivalent to yours, however. > What if common tabs remain after stripping common white space? What if we just go with, "[r]emove any whitespace than c

Re: DOS, UNIX and tabs

2006-12-28 Thread Tom Plunket
Steven D'Aprano wrote: > I don't know what "problems" with tabs you are talking about. I never have > problems with tabs. *Other people* who choose to use software that doesn't > understand tabs have problems. > > I've spent a lot of time reading both sides of the tabs versus spaces > argument, a

Re: getting a process's PID

2006-12-28 Thread Tom Plunket
eldorado wrote: > >>> g = os.popen("ps -ef | grep HUB | grep -v grep | awk '{ print $2 }'") > >>> h = g.readlines() > >>> g.close() > >>> h > ['87334\012'] > >>> h = h[:-1] > >>> h > [] > >>> I understand you're probably set, but instead of using readlines() you could also do this: g = os h

Installing python.org distro over ActivePython?

2006-12-26 Thread Tom Plunket
Hey gang- I just ran into the fabled "Secure Sockets not enabled in ActivePython," and the ActiveState FAQ says I should just grab _ssl.pyd from "somewhere", offering up the python.org distribution as a possible source. I'm on 2.4 at this time, and python.org has what appears to be a considerably

Re: textwrap.dedent replaces tabs?

2006-12-25 Thread Tom Plunket
Frederic Rentsch wrote: > It this works, good for you. I can't say I understand your objective. > (You dedent common leading tabs, except if preceded by common leading > spaces (?)). I dedent common leading whitespace, and tabs aren't equivalent to spaces. E.g. if some text is indented exclusi

Re: textwrap.dedent replaces tabs?

2006-12-23 Thread Tom Plunket
Frederic Rentsch wrote: > Following a call to dedent () it shouldn't be hard to translate leading > groups of so many spaces back to tabs. Sure, but the point is more that I don't think it's valid to change to tabs in the first place. E.g.: input = ' ' + '\t' + 'hello\n' + '\t' + 'wo

Re: textwrap.dedent replaces tabs?

2006-12-18 Thread Tom Plunket
Frederic Rentsch wrote: > > Well, there is that small problem that there are leading tabs that I > > want stripped. I guess I could manually replace all tabs with eight > > spaces (as opposed to 'correct' tab stops), and then replace them when > > done, but it's probably just as easy to write a n

Re: textwrap.dedent replaces tabs?

2006-12-18 Thread Tom Plunket
Peter Otten wrote: > > I guess I could manually replace all tabs with eight > > spaces (as opposed to 'correct' tab stops), and then replace them when > > done, but it's probably just as easy to write a non-destructive dedent. > > You mean, as easy as > > >>> "\talpha\tbeta\t".expandtabs() > '

Re: textwrap.dedent replaces tabs?

2006-12-16 Thread Tom Plunket
CakeProphet wrote: > Hmmm... a quick fix might be to temporarily replace all tab characters > with another, relatively unused control character. > > MyString = MyString.replace("\t", chr(1)) > MyString = textwrap.dedent(MyString) > MyString = MyString.replace(chr(1), "\t") > > Of course... this

textwrap.dedent replaces tabs?

2006-12-16 Thread Tom Plunket
The documentation for dedent says, "Remove any whitespace than can be uniformly removed from the left of every line in `text`", yet I'm finding that it's also modifying the '\t' characters, which is highly undesirable in my application. Is there any way to stop it from doing this, or alternatively

Re: Problem understanding how closures work

2006-12-12 Thread Tom Plunket
Rob Williscroft wrote: > "name" in the above code is bound to a an entry in "CreateTests1"'s > locals, and ExCall has a (hidden) reference to that locals, so > by the time ExCall is finally called the value associated > with "name" has been replaced by (count - 1). Ah, I got it. Thanks. Than

Problem understanding how closures work

2006-12-12 Thread Tom Plunket
...at least, I think that I'm having a problem understanding the way closures work. I'm trying to define a function for an object which will take certain objects from the parent scope at the time that function is defined. For some reason, if I do this function definition in a loop, the locals give

Re: type(foo) == function ?

2006-11-29 Thread Tom Plunket
Erik Max Francis wrote: > In dynamically-typed languages in general, explicit typechecks are not > a good idea, since they often preclude user-defined objects from being > used. Instead, try performing the call and catch the resulting > TypeError: Good point, although I need to figure out if

type(foo) == function ?

2006-11-29 Thread Tom Plunket
I'd like to figure out if a given parameter is a function or not. E.g. >>> type(1) >>> type(1) == int True implies: >>> def foo(): ... pass ... >>> type(foo) >>> type(foo) == function Traceback (most recent call last): File "", line 1, in ? NameError: name 'function' is not defined Is th

Re: Programmatically replacing an API for another module

2006-11-22 Thread Tom Plunket
Chris Lambacher wrote: > > > I'm just a bit loathe to download and install more stuff when > > > something simpler appears to be near-at-hand. ...especially > > > considering the page describing this module doesn't offer any download > > > links! http://python-mock.sourceforge.net/ > > Oh yeah,

wx.Process.Kill on Win32

2006-11-21 Thread Tom Plunket
Google indicates that wx.Process.Kill hadn't been implemented some time ago in wxPython for Win32. Is that still the case? It's kind of a drag since several sources (including wxPython wiki) strongly advise (by my reading and intended use) using wxProcess over the built-in stuff, but it's not ent

Re: Win32 COM

2006-11-02 Thread Tom Plunket
Tom Plunket wrote: > I don't know anything about COM beyond the fact that I can look in the > OLE/COM browser to maybe figure out the API that an object has that I > need to operate on. I'm still not entirely sure what's going on, because there are some methods and prope

Re: CSV module, DictReader problem (bug?)

2006-11-01 Thread Tom Plunket
John Machin wrote: > If you were to write 'c:\temp\book1.csv', it would blow up ... because > \t -> tab and \b -> backspace. Get into the habit of *always* using raw > strings r'C:\Temp\Book1.csv' for Windows file names (and re patterns). > You could use double backslashing 'C:\\Temp\\Book1.csv' b

Win32 COM

2006-11-01 Thread Tom Plunket
I don't know anything about COM beyond the fact that I can look in the OLE/COM browser to maybe figure out the API that an object has that I need to operate on. Usually this gets me by fine; I've written mostly utilities for Developer Studio which work fine if a little slow, and a bit of junk for

Re: Adding Worksheets to an Excel Workbook

2006-10-17 Thread Tom Plunket
wesley chun wrote: > welcome to Python!! i too, have (recently) been interested in COM > programming, so much so that i added some material... > from time import sleep > import win32com.client as win32 > > def excel(): > xl = win32.gencache.EnsureDispatch('Excel.Application') > ss = xl.

Re: Is a list static when it's a class member?

2006-10-12 Thread Tom Plunket
Fredrik Lundh wrote: > so what's the practical difference between > > def __init__(self, name): > self.name = name > self.data = [] > > and > > def __init__(self, name): > self.name = name > self.data=[] Ignoring nerd-extreme-pedantic-mode for this ci

Re: Is a list static when it's a class member?

2006-10-10 Thread Tom Plunket
Fredrik Lundh wrote: > if you want separate instances to use separate objects, make sure you > create new objects for each new instance. see Tim's reply for how to > do that. kath's response is probably better. In Python, you don't define the instance members in the class scope like the OP has

Re: C++ to Python?

2006-10-10 Thread Tom Plunket
Roman Yakovenko wrote: > you want to find some kind of "translator" > > C++ code: >std::cout << 1; > translator output: >print 1 > > Am I right? If so, I am pretty sure that such "translator" does not > exist - too complex. ...however such a "refactor" is easy for a human to do. What t

Re: Unicode strings, struct, and files

2006-10-09 Thread Tom Plunket
John Machin wrote: > > message = unicode('Hello, world') > > myFile.write(message) > > > > results in 'message' being converted back to a string before being > > written. Is the way to do this to do something hideous like this: > > > > for c in message: > >myFile.write(struct.pack('>H', ord(u

Unicode strings, struct, and files

2006-10-08 Thread Tom Plunket
I am building a file with the help of the struct module. I would like to be able to put Unicode strings into this file, but I'm not sure how to do it. The format I'm trying to write is basically this C structure: struct MyFile { int magic; int flags; short otherFlags; char pad[22];

Re: String handling and the percent operator

2006-07-14 Thread Tom Plunket
Erik Max Francis wrote: > > For enrichment purposes, is there a way to do this sort of thing with > > a generator? E.g. something like: > > > > def SentenceGenerator(): > >words = ['I', 'have', 'been', 'to', 'the', 'fair'] > >for w in words: > > yield w > > > > message = "%s %s %

Re: String handling and the percent operator

2006-07-14 Thread Tom Plunket
Justin Azoff wrote: > Of course.. > > I should read the python documentation at > http://docs.python.org/lib/typesseq-strings.html Excellent. Thanks. Has this been around long? I "learned" Python in the 1.6 days iirc, but haven't done much except simple scripting with it since... -tom! -- h

Deferred imports

2006-07-14 Thread Tom Plunket
I'm using this package that I can't import on startup, instead needing to wait until some initialization takes place so I can set other things up so that I can subsequently import the package and have the "startup needs" of that package met. Specifically this has to do with the interaction between

Re: String handling and the percent operator

2006-07-13 Thread Tom Plunket
Simon Forman wrote: > strings have a count() method. thanks! For enrichment purposes, is there a way to do this sort of thing with a generator? E.g. something like: def SentenceGenerator(): words = ['I', 'have', 'been', 'to', 'the', 'fair'] for w in words: yield w message = "%s %

String handling and the percent operator

2006-07-13 Thread Tom Plunket
I have some code to autogenerate some boilerplate code so that I don't need to do the tedious setup stuff when I want to create a new module. So, my script prompts the user for the module name, then opens two files and those files each get the contents of one of these functions: def GetPyContents

Re: to py or not to py ?

2006-06-28 Thread Tom Plunket
Carl J. Van Arsdall wrote: > Because of the GIL only one thread can actually run at a time. I've recently been wondering about this, since in the work I do, a lot of time is spent doing disk I/O. So if I want the UI to remain responsive, I could spawn an IO thread to handle requests, and do a pr