Re: Controlling newlines when writing to stdout (no \r\n).

2005-01-03 Thread Jeff Epler
Well, here's the first page turned up by google for the terms 'python binary stdout': http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/65443 Code from that page: import sys if sys.platform == "win32": import os, msvcrt msvcrt.setmode(sys.stdout.fileno(), os.O_B

Re: Octal notation: severe deprecation

2005-01-13 Thread Jeff Epler
On Thu, Jan 13, 2005 at 11:04:21PM +, Bengt Richter wrote: > One way to do it consistently is to have a sign digit as the first > digit after the x, which is either 0 or base-1 -- e.g., +3 and -3 would be > > 2x011 2x101 > 8x03 8x75 > 16x03 16xfd > 10x03 10x97 ... so that 0x8

Re: directory bug on linux; workaround?

2005-01-13 Thread Jeff Epler
Python is at the whim of the services the OS provides. Maybe you should ask in a linux-related newsgroup or mailing list, they might know more about the specifics of both detecting and working around "weird" filesystems like "fat". To find the type of a filesystem, Linux provides the statfs(2) fu

Re: Classical FP problem in python : Hamming problem

2005-01-23 Thread Jeff Epler
Your formulation in Python is recursive (hamming calls hamming()) and I think that's why your program gives up fairly early. Instead, use itertools.tee() [new in Python 2.4, or search the internet for an implementation that works in 2.3] to give a copy of the output sequence to each "multiply by N

Re: Tuple slices

2005-01-24 Thread Jeff Epler
The cpython implementation stores tuples in memory like this: [common fields for all Python objects] [common fields for all variable-size python objects, including tuple size] [fields specific to tuple objects, if any] [array of PyObject*, one for each item in the tuple] This way of

Re: tkinter: Can You Underline More Than 1 Char In A Menu Title

2005-01-27 Thread Jeff Epler
On Thu, Jan 27, 2005 at 06:38:22AM -0500, Tim Daneliuk wrote: > Is it possible to underline more than a single character as I am doing > with the 'underline=0' above. I tried 'underline=(0,2)' but that didn't > work. No. Jeff pgpFCNSGSpXA9.pgp Description: PGP signature -- http://mail.python.o

Re: [Tkinter] problem

2005-01-29 Thread Jeff Epler
These lines > if __name__ == '__main__': > OptionsWindow() mean "if this source code is the main program (not an imported module), call OptionsWindow()". So the behavior should be different when the source code is the main program ('python opt_newlogin.py') and when it's imported ('python -c "

Re: Embedding Python - Deleting a class instance

2005-06-21 Thread Jeff Epler
I wrote the following module to test the behavior of PyInstance_New. I called it something like this: import vedel class k: def __del__(self): print "deleted" vedel.g(k) I get output like: after creation, x->refcnt = 1 doing decref deleted after decref Unles

Re: eval() in python

2005-06-21 Thread Jeff Epler
On Tue, Jun 21, 2005 at 08:13:47AM -0400, Peter Hansen wrote: > Xah Lee wrote: > > the doc seems to suggest that eval is only for expressions... it says > > uses exec for statements, but i don't seem to see a exec function? > > Because it's a statement: http://docs.python.org/ref/exec.html#l2h-563

Re: utf8 silly question

2005-06-21 Thread Jeff Epler
If you want to work with unicode, then write us = u"\N{COPYRIGHT SIGN} some text" You can also write this as us = unichr(169) + u" some text" When you have a Unicode string, you can convert it to a particular encoding stored in a byte string with bs = us.encode("utf-8") It's gen

Re: PEP ? os.listdir enhancement

2005-06-22 Thread Jeff Epler
Why not just define the function yourself? Not every 3-line function needs to be built in. def listdir_joined(path): return [os.path.join(path, entry) for entry in os.listdir(path)] dirs = [x for x in listdir_joined(path) if os.path.isdir(x)] path_size = [(x, getsize(x)) for x in listdir_jo

Re: Loop until condition is true

2005-06-22 Thread Jeff Epler
def until(pred): yield None while True: if pred(): break yield None def example(): i = 0 for _ in until(lambda: x==0): x = 10 - i i += 1 print x, i example() pgpeP7iW6mcQm.pgp Description: PGP signature -- http://mail.python.org/mailman/l

Re: Is this a bug? I don't know where to start

2005-06-22 Thread Jeff Epler
Your list "targets" contains some values twice. >>> targets=[97,101,139,41,37,31,29,89,23,19,8,13,131,19,73,97,19,139,79,67,61,17,113,127] >>> for t in set(targets): ... if targets.count(t) > 1: print t ... 97 139 19 It looks like the "duplicated" items in the output contain one of the dupli

Re: Frame widget (title and geometry)

2005-06-24 Thread Jeff Epler
It would help if you posted your code, as we're in the dark about exactly what you tried to do and the error you received. It sounds like you may be using the wrong type of widget for what you want. The terms used in Tk are different than in some other systems. If you want a separate window with

Re: Frame widget (title and geometry)

2005-06-24 Thread Jeff Epler
Tkinter.Frame instances are not created with "geometry" or "title" attributes. Whatever 'classtitle' and 'classtitle2' are, they are not written to work with Tkinter.Frame instances. Jeff pgppDkXNnBRVL.pgp Description: PGP signature -- http://mail.python.org/mailman/listinfo/python-list

Re: Beginner question: Converting Single-Element tuples to list

2005-06-27 Thread Jeff Epler
On Mon, Jun 27, 2005 at 08:21:41AM -0600, John Roth wrote: > Unfortunately, I've seen that behavior a number of times: > no output is None, one output is the object, more than one > is a list of objects. That forces you to have checks for None > and list types all over the place. maybe you can at

Re: Dictionary to tuple

2005-06-28 Thread Jeff Epler
It looks like you want tuple(d.iteritems()) >>> d = {1: 'one', 2: 'two', 3: 'three'} >>> tuple(d.iteritems()) ((1, 'one'), (2, 'two'), (3, 'three')) You could also use tuple(d.items()). The result is essentially the same. Only if the dictionary is extremely large does the difference matter. (or

Re: It seems that ZipFile().write() can only write files, how can empty directories be put into it?

2005-07-01 Thread Jeff Epler
This has been discussed before. One thread I found was http://mail.python.org/pipermail/python-list/2003-June/170526.html The advice in that message might work for you. Jeff pgpPSqdIxsPgx.pgp Description: PGP signature -- http://mail.python.org/mailman/listinfo/python-list

Re: Trapping user logins in python ( post #1)

2005-07-04 Thread Jeff Epler
I don't know of a portable way for an inetd-style daemon to "listen" for user logins. On some systems (including RedHat/Fedora and debian), you may be able to use PAM to do this. (pam modules don't just perform authentication, they can take other actions. As an example, pam_lastlog "prints the l

Re: importing pyc from memory?

2005-07-04 Thread Jeff Epler
This stupid code works for modules, but not for packages. It probably has bugs. import marshal, types class StringImporter: def __init__(self, old_import, modules): self._import = old_import self._modules = modules def __call__(self, name, *args): module = self.

Re: Tkinter + Tcl help

2005-07-05 Thread Jeff Epler
I think you need to write root.tk.eval('load', '...\\libtcldot.so.0') When you write root.tk.eval("x y z") it's like doing this at the wish/tclsh prompt: # {x y z} Not like this: # x y z Now, how useful it is to have a command called "x y z", I can't guess... but tcl would let you

Re: resume upload

2005-07-05 Thread Jeff Epler
probably by using REST. This stupid program puts a 200 line file by sending 100 lines, then using REST to set a resume position and sending the next 100 lines. import getpass, StringIO, ftplib lines = ["Line %d\n" % i for i in range(200)] part1 = "".join(lines[:100]) part2 = "".join(lines[:100])

Re: math.nroot [was Re: A brief question.]

2005-07-06 Thread Jeff Epler
On Tue, Jul 05, 2005 at 09:49:33PM +0100, Tom Anderson wrote: > Are there any uses for NaN that aren't met by exceptions? Sure. If you can naturally calculate two things at once, but one might turn out to be a NaN under current rules. x, y = calculate_two_things() if isnan(x): pe

Re: Strange os.path.exists() behaviour

2005-07-06 Thread Jeff Epler
Pierre wrote: > Python 2.4 (#60, Nov 30 2004, 11:49:19) [MSC v.1310 32 bit (Intel)] on win32 ^^^ Here's the bug. You're using Windows. It's a filesystem, but not as we know it... Anyway, You are getting exactly what the

Re: Query

2005-07-08 Thread Jeff Epler
python-xlib includes an implementation of the xtest extension, which is enabled on most users' X servers, and can be used to send arbitrary keyboard or mouse events. jeff pgpo7pqhBafPe.pgp Description: PGP signature -- http://mail.python.org/mailman/listinfo/python-list

Re: About undisclosed recipient

2005-07-09 Thread Jeff Epler
You provided far too little information for us to be able to help. If you are using smtplib, it doesn't even look at message's headers to find the recipient list; you must use the rcpt() method to specify each one. If you are using the sendmail method, the "to_addrs" list has no relationship to t

Re: cursor positioning

2005-07-11 Thread Jeff Epler
Here's a simple module for doing progress reporting. On systems without curses, it simply uses "\r" to return the cursor to the first column. On systems with curses, it also clears to the end of the line. This means that when the progress message gets shorter, there aren't droppings left from the

Re: Parsing Data, Storing into an array, Infinite Backslashes

2005-07-11 Thread Jeff Epler
Your code is needlessly complicated. Instead of this business while 1: try: i = fetch.next() except stopIteration: break simply write: for i in fetch: (if there's an explicit 'fetch = iter(somethingelse)' in code you did not show, then get rid of tha

Re: Browser plug-in for Python?

2005-07-12 Thread Jeff Epler
Back in the day there was 'grail', which was a browser in its own right. There may also have been a plug-in for other browsers, but I don't know any real details about them. Python itself has deprecated the 'restricted execution' environment it had in previous versions, because ways to break out o

Re: ssh popen stalling on password redirect output?

2005-07-15 Thread Jeff Epler
In your ssh configuration, specify something like PreferredAuthentication "hostbased,publickey" this will skip trying to use the methods called keyboard-interactive and password. You can give this flag on the ssh commandline, too. read the ssh(1) and ssh_config(5) manpages for more informatio

Re: stdin/stdout fileno() always returning -1 from windows service

2005-07-18 Thread Jeff Epler
On Sun, Jul 17, 2005 at 06:43:00PM -0700, chuck wrote: > I have found that sys.stdin.fileno() and sys.stdout.fileno() always > return -1 when executed from within a win32 service written using the > win32 extensions for Python. > > Anyone have experience with this or know why? because there *is*

Re: stdin/stdout fileno() always returning -1 from windows service

2005-07-18 Thread Jeff Epler
It seems to simply be common wisdom. e.g., http://mail.python.org/pipermail/python-win32/2004-September/002332.html http://mail.mems-exchange.org/pipermail/quixote-users/2004-March/002743.html http://twistedmatrix.com/pipermail/twisted-python/2001-December/000644.html etc If you can find chapter

Re: Windows command line problem

2005-07-18 Thread Jeff Epler
I don't exactly know what is going on, but '\x96' is the encoding for u'\N{en dash}' (a character that looks like the ASCII dash, u'\N{hyphen-minus}', u'\x45') in the following windows code pages: cp1250 cp1251 cp1252 cp1253 cp1254 cp1255 cp1256 cp1257 cp1258 cp874 Windows is clearly doing

Re: Opinions on KYLIX 3 (Delphi 4 Linux)

2005-07-18 Thread Jeff Epler
I honestly don't know why anyone would spend money for a development environment, no matter how fancy. I don't know why anyone would develop software in a language that doesn't have at least one open implementation. It's a great way to get screwed when Borland goes under or decides they only want

Re: Image orientation and color information with PIL?

2005-07-18 Thread Jeff Epler
>>> i = Image.open("blue.jpg") >>> i.size (3008, 2000) >>> i.mode 'RGB' 'RGB' is the value for color jpeg images. I believe that for black&white images, i.mode is 'L' (luminosity). If you want to determine whether an existing image is landscape or portrait, then just compare i.size[0] (width) an

Re: Image orientation and color information with PIL?

2005-07-18 Thread Jeff Epler
On Mon, Jul 18, 2005 at 10:55:42AM -0600, Ivan Van Laningham wrote: > How are you going to determine the orientation of an image without > sophisticated image analysis? There is research on automatic image > orientation detection. [...] > If you write it I'll use it;-) There's research going on in

Re: Filling up commands.getstatusoutput's buffer

2005-07-21 Thread Jeff Epler
On Wed, Jul 20, 2005 at 03:10:49PM -0700, [EMAIL PROTECTED] wrote: > Hey, > > Has anyone ever had commands.getstatusoutput's buffer fill up when > executing a verbose command? [...] How much output are you talking about? I tried outputs as large as about 260 megabytes without any problem. (RedHa

Re: time.time() under load between two machines

2005-07-22 Thread Jeff Epler
What makes you believe that the two machines' clocks are perfectly synchronized? If they're not, it easily explains the result. I wrote a simple client/server program similar to what you described. Running on two RedHat 9 machines on a local network, I generally observed a time delta of 2ms (comp

Re: Mapping a drive to a network path

2005-07-22 Thread Jeff Epler
import os os.system(r"net use z: \\computer\folder") Something in the win32net module of win32all may be relevant if you don't want to do it through os.system: http://aspn.activestate.com/ASPN/docs/ActivePython/2.4/pywin32/win32net__NetUseAdd_meth.html Jeff pgp7mEoPdAfNP.pgp Description: P

Re: Mapping a drive to a network path

2005-07-22 Thread Jeff Epler
in fact, see this thread, it may have something useful for you: http://mail.python.org/pipermail/python-win32/2003-April/000959.html Jeff pgprYPOH3yOyI.pgp Description: PGP signature -- http://mail.python.org/mailman/listinfo/python-list

Re: Getting TypeError in Changing file permissions

2005-07-22 Thread Jeff Epler
If you are using Unix, and all you have is the file object, you can use os.fchmod(outfile.fileno(), 0700) Jeff pgp8U05e26RUt.pgp Description: PGP signature -- http://mail.python.org/mailman/listinfo/python-list

Re: Question about namespaces and import. How to avoid calling os.system

2005-07-22 Thread Jeff Epler
In main.py, execfile("gen.py") or In gen.py, have something like from __main__ import env_params or In main.py, have something like import __builtins__; __builtins__.env_params = env_params or call a function in the gen.py with env_params as a parameter import gen gen.do(env_p

Re: How to realize ssh & scp in Python

2005-07-24 Thread Jeff Epler
Rather than doing anything with passwords, you should instead use public key authentication. This involves creating a keypair with ssh_keygen, putting the private key on the machine opening the ssh connection (~/.ssh/id_rsa), then listing the public key in the remote system's ~/.ssh/authorized_key

Re: Tkinter - Resizing a canvas with a window

2005-07-26 Thread Jeff Epler
You should just use 'pack' properly. Namely, the fill= and expand= parameters. In this case, you want to pack(fill=BOTH, expand=YES). For the button, you may want to use pack(anchor=E) or anchor=W to make it stick to one side of the window. The additional parameters for the button (both creation

Re: Stripping C-style comments using a Python regexp

2005-07-27 Thread Jeff Epler
# import re, sys def q(c): """Returns a regular expression that matches a region delimited by c, inside which c may be escaped with a backslash""" return r"%s(\\.|[^%s])*%s" % (c, c, c) single_quoted_string = q('

Re: codecs.getencoder encodes entire string ?

2005-07-28 Thread Jeff Epler
On Thu, Jul 28, 2005 at 08:42:57AM -0700, nicolas_riesch wrote: > And a last question: can I call this "enc" function from multiple > threads ? Yes. Jeff pgphSka1eU9PQ.pgp Description: PGP signature -- http://mail.python.org/mailman/listinfo/python-list

Re: poplib.POP3.list() returns extra value?

2005-07-28 Thread Jeff Epler
With a judicious bit of UTSL, that count seems to be the total number of octets in the reply. This information comes from any user of _getlongresp(), which actually returns a tuple (resp, list, octets). These methods would be: list retr top uidl I'd consider it a doc bug too. If

Re: A replacement for lambda

2005-07-30 Thread Jeff Epler
On Fri, Jul 29, 2005 at 10:14:12PM -0700, Tim Roberts wrote: > C++ solves this exact problem quite reasonably by having a greedy > tokenizer. Thus, that would always be a left shift operator. To make it > less than and a function, insert a space: > < Incidentally, I read in an article by Bj

Re: Newb: Telnet 'cooked data','EOF' queries.

2005-07-31 Thread Jeff Epler
On Sun, Jul 31, 2005 at 01:30:43PM +0100, glen wrote: > Could someone explain what "cooked data" is. The telnet protocol contains special sequences which are interpreted by the telnet client or server program. These are discussed in the telnet RFC, which is RFC854 according to the telnetlib docst

Re: Getting not derived members of a class

2005-08-01 Thread Jeff Epler
On 'y', Python has no way of recording where '_a' and '_b' were set, so you can't tell whether it comes from class 'a' or 'b'. You can find the attributes that are defined on 'b' only, though, by using 'b.__dict__.keys()', or 'y.__class__.__dict__.__keys__()'. This gives ['__module__', 'who1'

Re: [noob] Questions about mathematical signs...

2005-02-06 Thread Jeff Epler
On Sun, Feb 06, 2005 at 12:26:30PM -0800, administrata wrote: > Hi! I'm programming maths programs. > And I got some questions about mathematical signs. > > 1. Inputing suqare like a * a, It's too long when I do time-consuming >things. Can it be simplified? You can write powers with the "**"

Re: Is Python as capable as Perl for sysadmin work?

2005-02-08 Thread Jeff Epler
No. Unlike Perl, Python implements only a *finite turning machine* model of computation. An easy way to see this limitation is in the following code: >>> 1.0 / 10.0 0.10001 In an infinite Turning machine, there would be an unbounded number of zeros before the second 1, giving

Re: Tkinter.Canvas saved as JPEG?

2005-02-10 Thread Jeff Epler
The Tkinter Canvas directly supports saving to postscript format, but not any standard bitmap format (or even modern vector formats like pdf or svg). Jeff pgpBVvDhXslRq.pgp Description: PGP signature -- http://mail.python.org/mailman/listinfo/python-list

Re: exec function

2005-02-12 Thread Jeff Epler
In this case, you can use getattr() instead of the exec statement: getattr(self.frame, t).SetTable(DataTable(d, r[0]), True) Jeff pgp6KrffC7xJf.pgp Description: PGP signature -- http://mail.python.org/mailman/listinfo/python-list

Re: Why Tk treat F10, F11, F12 diferently from F1...F9?

2005-02-12 Thread Jeff Epler
The reason that F10 does nothing is because there is already a binding on all for . In Motif apps, F10 moves focus to the menu bar, like pressing and releasing Alt does on Windows. When there is a binding for a key, the handling of the event "event add" never takes place. If you want to get rid

Re: SCons build tool speed

2005-02-13 Thread Jeff Epler
On Sun, Feb 13, 2005 at 08:39:10PM -0500, Peter Hansen wrote: > That answer, combined with Mike's response pointing out > that tools more sophisticated than basic "make" actually > can delve into the source and identify the dependencies, Argh argh argh. Of course you can write a makefile to "delv

Re: 64 bit Python

2005-02-14 Thread Jeff Epler
There's not enough information to guess the "real problem", but it could be this: "variable size" objects (declared with PyObject_VAR_HEAD) are limited to INT_MAX items since the ob_size field is declared as 'int'. This means that a Python string, tuple, or list (among other types) may be limited

Re: [Errno 18] Invalid cross-device link using os.rename

2005-02-14 Thread Jeff Epler
mv is a surprisingly complex program, while os.rename is a wrapper around rename(2) which is probably documented on your system to return EXDEV under these circumstanes. os.xxx is generally a fairly thin wrapper around what your OS provides, and inherits all the "gotchas". For some activities, os

Re: How can I tell if my host supports Python?

2005-02-14 Thread Jeff Epler
If you have a shell, it's as simple as typing "python" and seeing if the interactive interpreter appears: $ python Python 2.3.3 (#1, May 7 2004, 10:31:40) [GCC 3.3.3 20040412 (Red Hat Linux 3.3.3-7)] on linux2 Type "help", "copyright", "credits" or "license" for more information.

Re: super not working in __del__ ?

2005-02-15 Thread Jeff Epler
When a Python program exits, various steps of cleanup occur. One of them is that each entry in the __dict__ of each module is set to 'None'. Imagine that your __del__ runs after this step of the cleanup. The reference to the module-level variable that names your class is no longer available I lo

Re: Attaching to a Python Interpreter a la Tcl

2005-02-24 Thread Jeff Epler
Cameron Laird mentioned Tk's send working with Python; if you are writing your app with Tkinter, here is some code to let you use tcl commands like send python for remote control. You could build a more sophisticated front-end for this, and you'll probably also want to add stuff like sending

Re: Running Python Scripts With 'sudo'

2005-03-02 Thread Jeff Epler
Does "sudo" sanitize the environment? Imagine that the user can set PYTHONPATH, PYTHONINSPECT, etc. Beyond that, you have the same problems as with any code that runs with "extra privileges". Can the user supply any code that is fed to patently unsafe primitives (like the unpickler, eval() or th

Re: tkinter absorb chars

2005-03-03 Thread Jeff Epler
On Wed, Mar 02, 2005 at 04:58:03PM -0600, phil wrote: > Sorry for the repost, but moderator > jeld the last one, We saw both posts. > In a Tkinter entry field (or Pmw entry) > how could I eat charactres? create a binding on the widget for the particular character you want to treat specially. If

Re: Tough Spawn Problem

2005-03-06 Thread Jeff Epler
By using os.spawn* and the os.P_NOWAIT, the spawn function will return immediately, with the return value being the PID of the new process. Later, you can use os.kill() to force the program to terminate, os.waitpid() to retrieve the exit status if it has terminated, or you could use the signal modu

Re: reversed heapification?

2005-03-07 Thread Jeff Epler
Can you use something like (untested) class ComparisonReverser: def __init__(self, s): self.s = s def __cmp__(self, o): return cmp(o, self.s) def __lt__... # or whichever operation hashes use then use (ComparisonReverser(f(x)), i, x) as the decorated item instead of (f(

Re: pyconfig.h

2005-03-07 Thread Jeff Epler
The pyconfig.h file (/usr/include/python2.3/pyconfig.h) should begin something like this /* pyconfig.h. Generated by configure. */ /* pyconfig.h.in. Generated from configure.in by autoheader. */ and shouldn't cause problems. If it starts in a wildly different way than that, then it's p

Re: Unicode BOM marks

2005-03-07 Thread Jeff Epler
On Mon, Mar 07, 2005 at 11:56:57PM +0100, Francis Girard wrote: > BTW, the python "unicode" built-in function documentation says it returns a > "unicode" string which scarcely means something. What is the python > "internal" unicode encoding ? The language reference says farily little about unic

Re: pymem.h In function '__declspec'

2005-03-07 Thread Jeff Epler
What does this command print? gcc -c -I/usr/Python-2.3.3/Include -x c -o /dev/null \ /usr/Python-2.3.3/Include/pymem.h If it prints an error like the one you included in this message, then the set of header files in /usr/Python-2.3.3/Include is damaged, incomplete, or wrong for your com

Re: problem with "time"

2005-03-08 Thread Jeff Epler
Without your code, it's hard to tell. Here's a small program I wrote: import time t = time.time() print time.localtime(t - 86400) print time.localtime(t) on both lines, the tm_isdst flag is the same. If I choose two times that are on either side of the DST change in my timezone,

Re: Is there a short-circuiting dictionary "get" method?

2005-03-09 Thread Jeff Epler
untested def my_getter(m, i, f): try: return m[i] except (KeyError, IndexError): return f() my_getter(d, 'x', bigscaryfunction) my_getter(d, 'y', lambda: scaryinlineexpresion) pgp04VRKFqQL1.pgp Description: PGP signature -- http://mail.python.org/mailman/listinfo/python

Re: Apparently, I don't understand threading

2005-03-14 Thread Jeff Epler
Ah -- I'm sorry I was off-target, and I'm glad someone else had what may be better advice for you. Jeff pgptOZnkOhiE1.pgp Description: PGP signature -- http://mail.python.org/mailman/listinfo/python-list

Re: Accessing the contents of a 'cell' object from Python

2005-03-15 Thread Jeff Epler
Here's an old thread I contributed to which had a similar function (called 'cell_get' in this case) http://groups-beta.google.com/group/comp.lang.python/browse_thread/thread/baba3b943524a92c/71b57a32b311ffc8?q=func_closure#71b57a32b311ffc8 http://groups-beta.google.com/group/comp.lang.python/msg/7

Re: Pre-PEP: Dictionary accumulator methods

2005-03-18 Thread Jeff Epler
Maybe something for sets like 'appendlist' ('unionset'?) Jeff pgpCq9GushexV.pgp Description: PGP signature -- http://mail.python.org/mailman/listinfo/python-list

Re: Pre-PEP: Dictionary accumulator methods

2005-03-19 Thread Jeff Epler
> [Jeff Epler] > > Maybe something for sets like 'appendlist' ('unionset'?) > On Sat, Mar 19, 2005 at 04:18:43AM +, Raymond Hettinger wrote: > I do not follow. Can you provide a pure python equivalent? Here's what I had in mind: $ python /tmp/uni

Re: subprocess 'wait' method causes .py program to hang.

2005-03-19 Thread Jeff Epler
You can use PROC.poll() to find out whether the process has exited yet or not (for instance, in a 'while' loop along with a delay). I don't know what facilities exist to forcibly terminate programs on Windows, though. On Unix, os.kill() can be used to kill a process given its pid. Perhaps some of

Re: List limits

2004-12-20 Thread Jeff Epler
I'm referring to Python 2.2's C headers as I answer this question. I believe some of may have changed by 2.4. The number of elements in a "variable-sized object" (those with Py_VAR_HEAD; I believe this includes lists, tuples, and strings) is stored in a platform 'int'. On most (desktop) systems,

Re: Processes and their childs

2004-12-21 Thread Jeff Epler
"flush" your files before forking. For me, this program gives the correct output 'hello\n' when correct=1. When correct=0, I get either 'hello\nhello' or 'hellohello\n' as output. correct = 0 import sys, os sys.stdout.writ

Re: character set gobbledy-gook ascii translation ...

2004-12-24 Thread Jeff Epler
>>> email.Header.decode_header("=?us-ascii?Q?Re=3A=20=5Bosg=2Duser=5D=20Culling=20problem?=") [('Re: [osg-user] Culling problem', 'us-ascii')] >>> email.Header.decode_header("=?gb2312?B?cXVlc3Rpb24gYWJvdXQgbG9hZGluZyBmbHQgbGFyZ2UgdGVycmFpbiA=?=") [('question about loading flt large terrain ', 'gb23

Re: Clearing the screen

2004-12-24 Thread Jeff Epler
I don't know about idle, but the "real" python supports the PYTHONSTARTUP environment variable. PYTHONSTARTUP If this is the name of a readable file, the Python commands in that file are executed before the first prompt is displayed in interactive mode. The file is executed

Re: Execute code after death of all child processes - (corrected posting)

2004-12-25 Thread Jeff Epler
First, you'll want to exit from each forked copy, or else it will reach the code-after-the-for-loop: import sys, os, time texts = ['this is text1', 'this is text 2'] for current_text in texts[0:]: pid = os.fork() if pid == 0: time.sleep(2) print c

Re: copying classes?

2004-12-29 Thread Jeff Epler
You copied an instance, not a class. Here's an example of attempting to deepcopy a class: >>> class X: pass ... >>> import copy >>> X is copy.deepcopy(X) Traceback (most recent call last): File "", line 1, in ? File "/usr/lib/python2.2/copy.py", line 179, in deepcopy raise error, \ copy.E

Re: how can I put a 1Gb file in a zipfile??

2005-03-20 Thread Jeff Epler
The limits of ZIP files according to the folks who make info-zip: http://www.info-zip.org/pub/infozip/FAQ.html#limits statistic limit number of files65,536 uncompressed size of a single file 4 GB compressed size of a single file 4

Re: Shell re-direction

2005-03-20 Thread Jeff Epler
buffering. In the first case, there is either no buffering, or line buffering on sys.stdout, so you see the lines in order. In the second case, there is a buffer of a few hundred or thousand bytes for stdout in the python process, and you see the two lines of python output together (in this case,

Re: spaces in re.compile()

2005-03-21 Thread Jeff Epler
Maybe you want r'\b'. From 'pydoc sre': \b Matches the empty string, but only at the start or end of a word. import re r = re.compile( r'\btest\b' ) print r.findall("testy") print r.findall(" testy ") print r.findall(" test ") print r.findall("test") pgps8PNW4uDgh.pgp Description: PG

Re: possible bug?

2005-03-22 Thread Jeff Epler
On Tue, Mar 22, 2005 at 07:16:11AM -0700, Earl Eiland wrote: > I've been having trouble with a program hanging when using the > subprocess modules "wait()" method. Replacing it with with a loop that > used "poll()" solved the problem. Please include an example, and more information about what pla

Re: possible bug?

2005-03-22 Thread Jeff Epler
I wrote a program to use subprocess.Popen 1 times, and never had .wait() hang. If this is a bug, it may be Windows specific. Here's the program I ran: #- import subprocess, signal def timeout(*args): print "Timed out

Re: possible bug?

2005-03-22 Thread Jeff Epler
hm, I guess SIGALRM doesn't exist on Windows. You can run the program without the 'signal.signal' line or the 'signal.alarm' line, and you'll be stuck with a hung Python if subprocess.Popen exhibits the bug. Jeff pgp80TDX5i7qo.pgp Description: PGP signature -- http://mail.python.org/mailman/li

Re: possible bug?

2005-03-22 Thread Jeff Epler
On Tue, Mar 22, 2005 at 02:19:52PM -0700, Earl Eiland wrote: > Well, your program ran successfully. Perhaps WinRK is not well > behaved. How can a process terminate in such a way that poll() can read > it, but wait() won't? I don't have any idea. Both are implemented in terms of win32event.Wait

Re: Python RegExp

2005-03-22 Thread Jeff Epler
On my machine the program finishes in 30 seconds. (it's a 1.5GHz machine) If the 'parm' group is removed, or if the buffer is shortened, the time is reduced considerably. There are "pathological cases" for regular expressions which can take quite a long time. In the case of your expression, it's

Re: How to get TabError?

2005-03-27 Thread Jeff Epler
When running with "-tt", you can get this error. [EMAIL PROTECTED] src]$ python -tt Python 2.3.3 (#1, May 7 2004, 10:31:40) [GCC 3.3.3 20040412 (Red Hat Linux 3.3.3-7)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> exec "def f():\n\ta\nb" Traceback

Re: [Tkinter] LONG POST ALERT: Setting application icon on Linux

2005-03-27 Thread Jeff Epler
Here is a short program that sets Tk's window icon on Linux. My window manager is icewm, and it uses a scaled version of the "flagup" image both at the upper-left corner of the window and on the task bar entry for the window. import Tkinter app = Tkinter.Tk() app.iconbitmap("@/usr/X11

Re: [Tkinter] LONG POST ALERT: Setting application icon on Linux

2005-03-30 Thread Jeff Epler
I have written a rather hackish extension to use NET_WM_ICON to set full-color icons in Tkinter apps. You can read about it here: http://craie.unpy.net/aether/index.cgi/software/01112237744 you'll probably need to take a look at the EWMH spec, too. If KDE supports NET_WM_ICON, this may work f

Re: Our Luxurious, Rubinesque, Python 2.4

2005-03-31 Thread Jeff Epler
In my experience, when built with the same compiler (gcc 3.3.3) the size of the python library file (libpython2.x.a on unix machines) hasn't changed much between 2.3, 2.4, and current CVS: -rw-r--r-- 1 jepler jepler 950426 Mar 31 21:37 libpython2.3.a -rw-rw-r-- 1 jepler jepler 1002158 Mar 31 21:

Re: Spider - path conflict [../test.htm,www.nic.nl/index.html]

2005-04-01 Thread Jeff Epler
I think you want urllib.basejoin(). >>> urllib.basejoin("http://www.example.com/test/page.html";, "otherpage.html") 'http://www.example.com/test/otherpage.html' pgpSOZBAEHiWi.pgp Description: PGP signature -- http://mail.python.org/mailman/listinfo/python-list

Re: Corectly convert from %PATH%=c:\\X; "c:\\a; b" TO ['c:\\X', 'c:\\a; b']

2005-04-03 Thread Jeff Epler
if your goal is to search for files on a windows-style path environment variable, maybe you don't want to take this approach, but instead wrap and use the _wsearchenv or _searchenv C library functions http://msdn.microsoft.com/library/en-us/vclib/html/_crt__searchenv.2c_._wsearchenv.asp Incid

Re: "specialdict" module

2005-04-03 Thread Jeff Epler
The software you used to post this message wrapped some of the lines of code. For example: > def __delitem__(self, key): > super(keytransformdict, self).__delitem__(self, > self._transformer(key)) In defaultdict, I wonder whether everything should be viewed as a factory: def setde

Re: Corectly convert from %PATH%=c:\\X; "c:\\a; b" TO ['c:\\X', 'c:\\a; b']

2005-04-03 Thread Jeff Epler
The C code that Python uses to find the initial value of sys.path based on PYTHONPATH seems to be simple splitting on the equivalent of os.pathsep. See the source file Python/sysmodule.c, function makepathobject(). for (i = 0; ; i++) { p = strchr(path, delim); // ";" on win

Re: Silly question re: 'for i in sys.stdin'?

2005-04-03 Thread Jeff Epler
The iterator for files is a little bit like this generator function: def lines(f): while 1: chunk = f.readlines(sizehint) for line in chunk: yield line Inside file.readlines, the read from the tty will block until sizehint bytes have been read or EOF is seen. If

Re: Silly question re: 'for i in sys.stdin'?

2005-04-04 Thread Jeff Epler
On Sun, Apr 03, 2005 at 09:49:42PM -0600, Steven Bethard wrote: > Slick. Thanks! does isatty() actually work on windows? I'm a tiny bit surprised! Jeff pgp2TeZpqhdyV.pgp Description: PGP signature -- http://mail.python.org/mailman/listinfo/python-list

Re: Tkinter - pixel or widget color

2005-04-04 Thread Jeff Epler
On Mon, Apr 04, 2005 at 10:43:11AM +0200, pavel.kosina wrote: > I would need to get at canvas pixel color under certain moving widget or > better (= faster?) colors/"types" of underlying static widgets that are > of polygon shape (not rectangle). I don't believe this information is available any

  1   2   >