Re: Is unicode_escape broken?

2005-12-13 Thread jepler
I also believe this is a bug. Here's an even shorter demonstration of the behavior: u\\.encode(unicode_escape).decode(unicode_escape) Traceback (most recent call last): File stdin, line 1, in ? UnicodeDecodeError: 'unicodeescape' codec can't decode byte 0x5c in position 0: \ at end of string

Re: Overloading

2005-12-09 Thread jepler
On Fri, Dec 09, 2005 at 06:29:12PM +0100, Johannes Reichel wrote: Hi! In C++ you can overload functions and constructors. For example if I have a class that represents a complex number, than it would be nice if I can write two seperate constructors Python doesn't support this, but it does

Re: uuDecode problem

2005-12-07 Thread jepler
Note that you can use the 'uu' encoding, which will handle arbitrary-length input and give multi-line uuencoded output, including the 'begin' and 'end' lines: print (\377 * 120).encode(uu) begin 666 data M

Re: junk pointer ????

2005-12-06 Thread jepler
It means there is a bug in a Python extension or in Python itself. If you can reproduce the bug by importing only modules written in Python or included with Python, then you should document the steps to do so in a bug report in the bug tracker on http://sourceforge.net/python If you can only

Re: Constructing RFC2822 Message

2005-12-05 Thread jepler
On Mon, Dec 05, 2005 at 06:27:44AM -0800, Narendra wrote: I was able to do that but my e-mail is ending in bulk when i'm trying to senf to hotmail/msn. Perhaps this is an over-zealous filter on the hotmail/msn side, not a problem with Python. I don't know for sure, but some news stories

Re: Detect character encoding

2005-12-05 Thread jepler
Perhaps this project's code or ideas could be of service: http://freshmeat.net/projects/enca/ Jeff pgpYyDfS0xrTp.pgp Description: PGP signature -- http://mail.python.org/mailman/listinfo/python-list

Re: apply()?

2005-12-05 Thread jepler
First, get the method with getattr() and then use the *-notation or apply to call it with args. getattr(obj, func_name)(*args) or apply(getattr(obj, func_name), args) Jeff pgpm38MC4TzIU.pgp Description: PGP signature -- http://mail.python.org/mailman/listinfo/python-list

Re: hash()

2005-12-05 Thread jepler
[John Marshall] For strings of 1 character, what are the chances that hash(st) and hash(st[::-1]) would return the same value? On Mon, Dec 05, 2005 at 09:11:14PM -0500, Tim Peters wrote: First, if `st` is a string, `st[::-1]` is a list. Do you really mean to compare string hashes with

Re: How to execute an EXE via os.system() with spaces in the directory name?

2005-12-03 Thread jepler
This comes up from time to time. The brain damage is all Windows', not Python's. Here's one thread which seems to suggest a bizarre doubling of the initial quote of the commandline. http://groups.google.com/group/comp.lang.python/browse_frm/thread/89d94656ea393d5b/ef40a65017848671

Re: A bug in struct module on the 64-bit platform?

2005-12-01 Thread jepler
I'm guessing that the expected behavior is struct.calcsize('idi') 20 because the double should be aligned to an 8-byte boundary. This is the case on my linux/x86_64 machine: $ python -c 'import struct; print struct.calcsize(idi)' 20 I don't know much about 'itanium', but i'd be

Re: Is there no compression support for large sized strings in Python?

2005-12-01 Thread jepler
On this system (Linux 2.6.x, AMD64, 2 GB RAM, python2.4) I am able to construct a 1 GB string by repetition, as well as compress a 512MB string with gzip in one gulp. $ cat claudio.py s = '1234567890'*(1048576*50) import zlib c = zlib.compress(s) print len(c)

Re: URI http get

2005-12-01 Thread jepler
The urllib2 module is designed for tasks like this. The tutorial shows how to use urllib2.urlopen() to fetch the contents of a URL using the http protocol. Jeff pgpdV8higv7SR.pgp Description: PGP signature -- http://mail.python.org/mailman/listinfo/python-list

Re: Death to tuples!

2005-11-29 Thread jepler
On Tue, Nov 29, 2005 at 10:41:13AM +, Bengt Richter wrote: Seems like str.__mod__ could take an arbitary (BTW, matching length, necessarily? Or just long enough?) iterable in place of a tuple, just like it can take an arbitrary mapping object in place of a dict for e.g. '%(name)s'%

Re: run runs away

2005-11-29 Thread jepler
run is not the name of a Python built-in function. That leaves everyone but you somewhat in the dark about why it does or does not wait for the created process to complete. If you want a function that starts a new process and waits for it to complete, you probably want to use

Re: unicode speed

2005-11-29 Thread jepler
On Tue, Nov 29, 2005 at 09:48:15AM +0100, David Siroky wrote: Hi! I need to enlighten myself in Python unicode speed and implementation. My platform is AMD [EMAIL PROTECTED] (x86-32), Debian, Python 2.4. First a simple example (and time results): x = a*5000 real0m0.195s user

Re: Data Structure in Python like STL Stack?

2005-11-28 Thread jepler
What property of the STL stack is important to you? You can use a Python list as a stack. It has methods append() and pop() which run in amortized-constant-time. It can be tested for empty/nonempty in constant time too (if st: # stack is not empty). Jeff pgpU1CCrfIPhk.pgp Description: PGP

Re: exception KeyboardInterrupt and os.system command

2005-11-27 Thread jepler
You can tell by the exit code from system() whether the subprocess exited due to a signal. Consider this code: import os while 1: print os.system(sleep 1) unless you happen to hit ctrl-c at the right time, you'll see it print 2 (and 0 when the sleep finishes). The exit code can

Re: How to find the port a server is listening on (from within the server)

2005-11-25 Thread jepler
If I understand correctly, you're looking for the socket method getsockname(), documented at http://docs.python.org/lib/socket-objects.html Jeff pgppauvaXgXhK.pgp Description: PGP signature -- http://mail.python.org/mailman/listinfo/python-list

Re: strange behaviour when writing a large amount of data on stdout

2005-11-23 Thread jepler
That code works here. Python2.4 (#60, Nov 30 2004, 11:49:19) [MSC v.1310 32 bit (Intel)] on win32 It's Windows XP, Pentium 4, unknown amount of RAM. I'm running python.exe in a console window. It also worked in IDLE. Jeff pgptwrbVpG8CR.pgp Description: PGP signature --

Re: Why is dictionary.keys() a list and not a set?

2005-11-23 Thread jepler
You can already get a set from a dictionary's keys in an efficient manner: l = dict.fromkeys(range(10)) set(l) Set([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]) Jeff pgplWRjKoPA4t.pgp Description: PGP signature -- http://mail.python.org/mailman/listinfo/python-list

Re: Would cgi be the only option if my webhosting doesn't have psp, zpt, cheetah or mod_python?

2005-11-23 Thread jepler
You might benefit some from scgi. From the httpd side, you can either use mod_scgi in the server or cgi2scgi if can't install mod_scgi. cgi2scgi doesn't have all the performance benefit of mod_scgi, but cgi2scgi is a fairly lightweight C program.

Re: Why is dictionary.keys() a list and not a set?

2005-11-23 Thread jepler
One reason might be Practicality. The zip() versions handily beat the listcomp versions on a 10kitem dict. (python2.4) $ timeit.py -s 'd = dict.fromkeys(range(1))' '[(v, k) for (k, v) in d.iteritems()]' 100 loops, best of 3: 5.05 msec per loop $ timeit.py -s 'd =

Re: after sorted from the lists

2005-11-22 Thread jepler
ll = [[1,2],[2,1],[3,1],[1,4],[3,3],[1,4]] ls = [frozenset(i) for i in ll] ss = set(ls) ss set([frozenset([1, 3]), frozenset([1, 2]), frozenset([1, 4]), frozenset([3])]) [list(i) for i in ss] [[1, 3], [1, 2], [1, 4], [3]] pgphz7iINDVUi.pgp Description: PGP signature --

Re: user-defined operators: a very modest proposal

2005-11-22 Thread jepler
If your proposal is implemented, what does this code mean? if [1,2]+[3,4] != [1,2,3,4]: raise TestFailed, 'list concatenation' Since it contains ']+[' I assume it must now be parsed as a user-defined operator, but this code currently has a meaning in Python. (This code is the first

Re: user-defined operators: a very modest proposal

2005-11-22 Thread jepler
On Tue, Nov 22, 2005 at 04:08:41PM -0800, Steve R. Hastings wrote: Actually, that's a better syntax than the one I proposed, too: __+__ # __add__ # this one's already in use, so not allowed __outer*__ Again, this means something already. __ = 3 __+__ 6 __outer = 'x' __outer*__

Re: writing a generic method

2005-11-21 Thread jepler
You could use a format like #s#sO, and then use PyFloat_Check, PyFloat_AsDouble, and the equivalent PyInt macros to get the C value out of the Python object. You should be able to use the converter O to get what you want. The conversion function might look like: int double_only(PyObject

Re: Python install minimum requirements

2005-11-21 Thread jepler
If I found the right U3 when I googled, then maybe this is relevant: http://www.voidspace.org.uk/python/movpy/ Jeff pgp1AjuUdEskN.pgp Description: PGP signature -- http://mail.python.org/mailman/listinfo/python-list

Re: Tkinter: scrollbar in grid-managed frame

2005-11-16 Thread jepler
Tkinter frames don't scroll. Instead, you need to use something like bwidget's ScrollableFrame widget. You may want to combine this with bwidget's ScrolledWindow. Below is an example which uses my pybwidget package, available at http://tkinter.unpy.net/bwidget/ #

Re: strange file.write() behavior on windows: $ConvertToNonresident, $ReplaceAttribute2

2005-11-16 Thread jepler
This is really just a snide joke at the expense of Microsoft, but have you checked the MSDN documentation about ConvertToNonresident or ReplaceAttribute2? Your search - site:msdn.microsoft.com ConvertToNonresident OR ReplaceAttribute2 - did not match any documents. -- google.com

Re: Can anyone tell me if pygame and Tkinter can work together?

2005-11-15 Thread jepler
It's likely to be a challenge; each one has its own event loop, and the exact pitfalls of trying to use both at the same time probably depend on the operating system too. For instance, on X, Tk and SDL probably both expect full control of the handlers registered with XSetErrorHandler and

Re: Can anyone tell me if pygame and Tkinter can work together?

2005-11-15 Thread jepler
On Tue, Nov 15, 2005 at 06:33:40PM -0700, Nathan Pinno wrote: Thanks. I was going to use TKInter to pop up a message box, then use pygame to run the game and display the score on the playing surface. Is this still possible (I'm using Python 2.4.1 and Pygame 1.7.0 on WinXP with Service Pack 2)?

Re: how do i use tkinter.createfilehandler with a regular c program?

2005-11-14 Thread jepler
Compared to your program, I * Made sure that the slave program actually flushed its stdout buffers * didn't call read(), which will by default continue reading until it reaches EOF, not merely read the available data #!/usr/bin/env python import sys, time, Tkinter, itertools, _tkinter, os

Re: Tix BUG? Where to submit?

2005-11-14 Thread jepler
Since this is a bug in Python (Tix.py), it should be submitted to the Python Patch tracker at sf.net/projects/python You need a free sourceforge account to submit an item to the bug or patch tracker. Jeff pgp1zmMFcYHrz.pgp Description: PGP signature --

Re: Iterator addition

2005-11-13 Thread jepler
On Sun, Nov 13, 2005 at 09:44:43PM +, Bengt Richter wrote: even if expr1 had a __unaryop__ method, expr1 - expr2 could not become expr1.__unaryop__(-expr2) unless you forced the issue with expr1 (-expr2) as opposed to being a function call? I don't think you've solved the

Re: Sorting dominoes

2005-11-13 Thread jepler
So if you have the dominoes (1 2), (3 2) and (3 1) you must arrange them as 1|2|3 2|3|1 ? If so, then it seems to me your algorithm is this: 1. pick an arbitrary domino to be first, and an arbitrary side to be the top 2a. until the dominoes are exhausted, pick the other domino

Re: changeing users on linux

2005-11-12 Thread jepler
On Fri, Nov 11, 2005 at 11:25:56PM -0500, Mike Meyer wrote: You didn't say what the password was for, so I skipped asking for it. You're a real comedian. Jeff pgpxqmFz5jalu.pgp Description: PGP signature -- http://mail.python.org/mailman/listinfo/python-list

Re: Tkinter and the re/sizing of columns in a grid

2005-11-12 Thread jepler
Normally, an entry widget requests horizontal space equal to the value of the width= option times the average character width of the font it displays. Setting it to 0 makes the entry request exactly enough width to show the string it contains. Making them sticky to the east and west sides of

Re: x, y coordinates in Tkinter canvas

2005-11-11 Thread jepler
Let's find out! This program creates a series of rectangles, with the color going from black to nearly white. White corresponds to higher x and y coordinate values. So the answer to your question can be seen in the output of the program. import Tkinter c = Tkinter.Canvas(width=220,

Re: struct, IEEE-754 and internal representation

2005-11-09 Thread jepler
Use 'd' as the format character for 64-bit double precision numbers with struct. x = 148.73 unpack(d, pack(d, x))[0] == x True unpack(f, pack(f, x))[0] == x False Jeff pgpB2b9owxZs7.pgp Description: PGP signature -- http://mail.python.org/mailman/listinfo/python-list

Re: user account logon from python

2005-11-08 Thread jepler
login APIs vary widely from system to system. Classic Unix systems use calls like getpwent and crypt to check passwords, and then call setuid, setgid and setgroups to set the identity of the user who is logging in. These are all available in stock Python, check the library reference for more

Re: Tkinter and X11

2005-11-07 Thread jepler
There should be no problem with this. After all, even the greeter is just an X application. Depending on which login manager you use (xdm/kdm/gdm/whatever) the details of getting your Tkinter app to actually be run will vary, though. In gdm, it looks like adding it to the file

Re: O_DIRECT on stdin?

2005-11-07 Thread jepler
I think this is fcntl(..., F_SETFL, ...), so something like import os, fcntl, sys flags = fcntl.fcntl(sys.stdin.fileno(), fcntl.F_GETFL) flags |= os.O_DIRECT fcntl.fcntl(sys.stdin.fileno(), fcntl.F_SETFL, flags) Jeff pgpx52DBavw3Y.pgp Description: PGP signature --

Re: O_DIRECT on stdin?

2005-11-07 Thread jepler
Here's some text from my open(2) manpage: Transfer sizes, and the alignment of user buffer and file offset must all be multiples of the logical block size of the file system. It's unlikely that in practice you can get Python's sys.stdin.read() or os.read() to reliably use a buffer that

Re: fcntl.flock() not working when called from a function

2005-11-04 Thread jepler
The file you open() may be closed as soon as it is no longer possible to refer to it. So in the first case, because the top-level variable 'f' continues to refer to the opened file, the file may not be closed. In the second case, no variable refers to the opened file after lock() returns, so

Re: taking x-window screen shot

2005-10-31 Thread jepler
I recommend using 'xwd' to actually get the screenshot, because xwd is installed nearly everwhere X is. xwd-format images are documented by the header file X11/XWDFile.h. This program works in a pipeline to convert certain xwd-format images to postscript. You can use it something like this:

Re: Tkinter problem

2005-10-31 Thread jepler
On Mon, Oct 31, 2005 at 03:17:05PM -0800, dale cooper wrote: Thanks, but I've got another question: can't find Tcl configuration script tclConfig.sh This file comes from the following package: $ rpm -qf /usr/lib*/tclConfig.sh tcl-devel-8.4.9-3 Fedora generally splits packages which are

Re: Where to save classes? How to access classes?

2005-10-31 Thread jepler
This section of the tutorial discusses the module search path: http://docs.python.org/tut/node8.html 6.1.1 The Module Search Path When a module named spam is imported, the interpreter searches for a file named spam.py in the current directory, and then in the list of

Re: sys.exit call from pythonw.exe gives error

2005-10-27 Thread jepler
I wrote the following small program: #--- import sys, Tkinter t = Tkinter.Tk() b = Tkinter.Button(command=lambda: sys.exit(0), text=Click to exit) b.pack() t.mainloop()

Re: Errno 8 Exec format error

2005-10-25 Thread jepler
On Tue, Oct 25, 2005 at 04:11:39PM +0100, Matthew Fowler wrote: problem with execution of xhpl on AxisProduct: [Errno 8] Exec format error In this case, it appears that Python is reporting the error of some operating system call, such as execve. On my operating system, here's a program which

Re: textwidget.tag_bind(name, Any-KeyPress, self.donothing) not working

2005-10-25 Thread jepler
I'm not sure why Tk behaves this way, but you can observe the same behavior with a wish script. It would seem that break skips any other scripts associated with item tags, but still proceeds to bindings at the widget level. Using a binding with break on the canvas itself may help you get the

Re: Extention String returning

2005-10-24 Thread jepler
I think that you want to use return PyString_FromStringAndSize(buf, 8); Jeff pgp3nNxegNjmk.pgp Description: PGP signature -- http://mail.python.org/mailman/listinfo/python-list

Re: TK question

2005-10-21 Thread jepler
In the FileDialog module there are both LoadFileDialog and SaveFileDialog. Is the latter what you want? Jeff pgptzMbfYw5VI.pgp Description: PGP signature -- http://mail.python.org/mailman/listinfo/python-list

Re: C replacement for Queue module

2005-10-21 Thread jepler
does collections.deque have a blocking popleft()? If not, it's not very suitable to replace Queue.Queue. Jeff pgp9S3BEmciKx.pgp Description: PGP signature -- http://mail.python.org/mailman/listinfo/python-list

Re: Set an environment variable

2005-10-20 Thread jepler
In Unix, you generally can't affect the environment of your parent program (in a broad sense, which includes environment variables, current working directory, opened files, effective user ID, etc). You have two basic choices to achieve an effect like this. First, you can start a subshell with

Re: nested escape chars in a shell command

2005-10-20 Thread jepler
I think you're mistaken about how 'sh -c' works. The next argument after -c is the script, and following arguments are the positional arguments. (what, you've never used -c in conjunction with positional arguments? me either!) Example:

os.makedirs should not succeed when the directory already exists (was Re: Python Doc Error: os.makedirs)

2005-10-20 Thread jepler
On Wed, Oct 19, 2005 at 09:26:16AM -0700, Dr. Who wrote: The fact that the directory already exists is irrelevant to the function...it still failed to create the directory. That's not true. Imagine that os.makedirs() is used inside tempfile.mkdtemp() (I looked, and it isn't) and the proposed

Re: Bloodhound.Exploit.49 trojan found in MIMEBase.pyc

2005-10-18 Thread jepler
It's almost certainly a false positive. In my day job we run into false positive antivirus detections like this once or twice a year, and typically get a runaround from the AV vendor (who often have the gall to suggest that we should buy a copy of their broken software before they'll fix their

Re: reading hebrew text file

2005-10-17 Thread jepler
= codecs.open(/users/jepler/txt/UTF-8-demo.txt, r, utf-8) for i in range(5): print repr(f.readline()) ... u'UTF-8 encoded sample plain-text file\n' u'\u203e\u203e\u203e\u203e\u203e\u203e\u203e\u203e\u203e\u203e\u203e\u203e\u203e\u203e\u203e\u203e\u203e\u203e\u203e\u203e\u203e\u203e\u203e\u203e\u203e\u203e

Re: Python's garbage collection was Re: Python reliability

2005-10-12 Thread jepler
On Mon, Oct 10, 2005 at 08:37:03PM +0100, Tom Anderson wrote: So python doesn't use the old SmallTalk 80 SmallInteger hack, or similar? Fair enough - the performance gain is nice, but the extra complexity would be a huge pain, i imagine. I tried to implement this once. There was not a

Re: dictionnaries and lookup tables

2005-10-11 Thread jepler
On Tue, Oct 11, 2005 at 11:06:32AM -0700, [EMAIL PROTECTED] wrote: Note that when I type: dir(D) [...] the functions __ge__, __gt__, __lt__, __le__ seem to be non-implemented but there is some __doc__ in them. Is there the intention to do something similar as is described above or are they

Re: unable to import os

2005-10-11 Thread jepler
Concatenating filenames with + is seldom what you want. Instead, you should use os.path.join (or, to decrease portability, nt.path.join). Jeff pgpUKTuVnB2qh.pgp Description: PGP signature -- http://mail.python.org/mailman/listinfo/python-list

Re: Profiling Python using gprof

2005-10-11 Thread jepler
It should be the same as for any program $ program-compiled-with-pg $ gprof /path/to/program-compiled-with-pg you'll need to make sure that python is not only *compiled* with -pg but that the *link line* contains -pg as well. That's a common gotcha when it comes to profiling. Jeff

Re: are there internal functions for these ?

2005-10-11 Thread jepler
there's 'os.rename' for moving (single) files, and several functions in 'shutil' for moving and copying trees of files. Jeff pgpS5MgPvRJQZ.pgp Description: PGP signature -- http://mail.python.org/mailman/listinfo/python-list

Re: [PIL]: Question On Changing Colour

2005-10-11 Thread jepler
If you're always going from grey to tinted, then the easiest way is to treat it as a 'P' image with a special palette. I believe this function will prepare the palette: def make_palette(tr, tg, tb): l = [] for i in range(255): l.extend([tr*i / 255,

Re: Wanted: Python module allowing direct access to raw sectors of harddrives (MFT, boot sector, etc.) in MS Windows

2005-10-10 Thread jepler
I took the advice from this web page: http://support.microsoft.com/kb/q100027/ (I don't know how this extends to floppies, and the 9x family of OSes isn't listed in applies to, so this may not help your case) Here, I open physical drive 0 and see that the magic number indicates a valid

Re: Python name lookups

2005-10-10 Thread jepler
On Mon, Oct 10, 2005 at 03:02:30PM -0700, Dave wrote: Hello All, As far as I understand, Python deals with a lot of string objects, i.e. it looks up all names. Is there a way to find out how many name lookup operations take place in a Python program? Is it the name lookup operation or hash

Re: pyparallel and MAKE controller board for CRYDOM AC/DC switches

2005-10-10 Thread jepler
Recalling the parallel pinout, pin 3 is data bit 2. Have you tried def BIT(x): return 1x p.setData(BIT(2)) ? pgprfRaNUTBBH.pgp Description: PGP signature -- http://mail.python.org/mailman/listinfo/python-list

Re: Why asci-only symbols?

2005-10-10 Thread jepler
I'm not aware of any PEPs on the subject, but google groups turns up some past threads. Here's one from February 2004: http://groups.google.com/group/comp.lang.python/browse_frm/thread/d5fcc1c8825a60dc/96856af647ce71d5 I didn't immediately find this message of Guido's that everyone's

Re: Looking for info on Python's memory allocation

2005-10-10 Thread jepler
While there may be a discussion somewhere in the archives, the comments in listobject.c are enlightening too. /* Ensure ob_item has room for at least newsize elements, and set * ob_size to newsize. If newsize ob_size on entry, the content * of the new slots at exit is undefined heap trash;

Re: non descriptive error

2005-10-09 Thread jepler
On Mon, Oct 10, 2005 at 09:12:13AM +1000, Timothy Smith wrote: FAYI i have already found it and it was a wrongly indented code block :/ When indentation leaves an illegal program structure, Python gives a very informative error message, such as File /tmp/x.py, line 3 return 3 ^

Re: Idle bytecode query on apparently unreachable returns

2005-10-09 Thread jepler
On Mon, Oct 10, 2005 at 12:20:13AM +0100, Tom Anderson wrote: What puzzles me, though, are bytecodes 17, 39 and 42 - surely these aren't reachable? Does the compiler just throw in a default 'return None' epilogue, with routes there from every code path, even when it's not needed? If so,

Re: Function decorator that caches function results

2005-10-08 Thread jepler
On Sat, Oct 08, 2005 at 01:53:28PM +, Duncan Booth wrote: Unless the results stored in the cache are very large data structures, I would suggest that you simply store (args,kwargs) as the cache key and accept the hit that sometime you'll cache the same call multiple times. ... except

Re: List performance and CSV

2005-10-08 Thread jepler
You'll probably see a slight speed increase with something like for a in CustomersToMatch: for b in Customers: if a[2] == b[2]: a[1] = b[1] break But a really fast approach is to use a dictionary or other structure that turns the inner loop

Re: 2d array slicing problem

2005-10-07 Thread jepler
Do you have a simple program that demonstrates the problem? I have an x86 machine with Python 2.3, and an x86_64 machine with Python 2.4 available. I wrote a simple test program which performs a slice operation, but it behaves the same on both platforms. Here's the program:

Re: how to debug when Segmentation fault

2005-10-05 Thread jepler
Interesting. I'd noticed that the metaclass one didn't crash my 2.2, but I didn't check the marshal one. This one core dumps in 'Python 2.2.2 (#1, Feb 24 2003, 19:13:11) ... linux2' but inexplicably prints 'keys' when I ran it on the 2.4.1 I used in my last post. import marshal f = lambda:

Re: How to create temp file in memory???

2005-10-05 Thread jepler
Here's how: 1. open your web browser 2. visit the url http://docs.python.org 3. click the link Library Reference (keep this under your pillow) 4. scan down the list of modules until you see these two items: 4.6 StringIO -- Read and write strings as files 4.7 cStringIO -- Faster

Re: updating local()

2005-10-05 Thread jepler
I'm surprised you found any example of 'locals().update' that worked. Here's one that doesn't work: def f(y): locals().update({'x': y}) return x print f(3) # prints 3? Jeff pgpLVe48NBWmT.pgp Description: PGP signature --

Re: Newbie regular expression ?

2005-10-04 Thread jepler
Here are two ideas that come to mind: files = glob.glob(UNQ*.dat) + glob.glob(Unq*.dat) + glob.glob(unq.dat) files = [f for f in glob.glob(*.dat) if f[:3] in (UNQ, Unq, unq)] Jeff pgp30Rue2EGi7.pgp Description: PGP signature -- http://mail.python.org/mailman/listinfo/python-list

Re: how to debug when Segmentation fault

2005-10-04 Thread jepler
I've rewritten your middle example to be clearer. $ python2.4 Python 2.4.1 (#1, May 16 2005, 15:15:14) [GCC 4.0.0 20050512 (Red Hat 4.0.0-5)] on linux2 Type help, copyright, credits or license for more information. type(Y, (type,), {mro: lambda x: [float]})(X, (), {}) and here's another one for

Re: how to get any available port

2005-10-04 Thread jepler
Apparently, calling bind() with a zero port will choose some available port number, as demonstrated by this program: import socket s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.bind((, 0)) print s.getsockname() Here's how it behaved over several runs: $ python soc.py ('0.0.0.0',

Re: how to get any available port

2005-10-04 Thread jepler
On Tue, Oct 04, 2005 at 05:19:37PM -0400, Mohammed Smadi wrote: what else would you do? I am using examples from the web and they all bind to a port at the localhost before connecting to the remote host. [...] the web must be stupider than I thought. Here's how Python's own ftplib connects

Re: Convert hex to string

2005-10-03 Thread jepler
it *is* a string. because most of the characters are not printable, they're presented using hex notation when you repr() the string. That's what entering an expression in the interactive interpreter does (except that it never prints 'None'). If you really want to write whatever those bytes are,

Re: Exception raising, and performance implications.

2005-10-03 Thread jepler
As for performance, you'll need to benchmark it. However, I think the functionality you're asking for is available as inspect.currentframe(), and if the implementation is in C it may have a tiny performance advantage over the Python version. Jeff pgpENIs7apfaF.pgp Description: PGP signature --

Re: Exception raising, and performance implications.

2005-10-03 Thread jepler
On Mon, Oct 03, 2005 at 02:34:40PM -0700, leo wrote: I come from a java background, where Exceptions are a big Avoid Me, but are the performance implications the same in Python? We're expecting a big load on our app (100,000 users/hour) , so we'd like to be as tuned as possible. I don't know

Re: Statement orders

2005-10-02 Thread jepler
Here's one case where it's bad to call update. def perform_longrunning_calculation(): time.sleep(1) app.update() time.sleep(1) suppose you kick this off with a keybinding, such as: app.bind(c, lambda e:

Re: Statement orders

2005-10-02 Thread jepler
would it be advisable to guard against this with something like this? def perform_longrunning_calculation(): if not app.busy: app.busy = 1 [...] By using that kind of construct, instead of using update_idletasks(), you force all code to be aware of and manage the app.busy

Re: Printing and prompting adds a mysterious extra space

2005-10-01 Thread jepler
Use sys.stdout.write instead of print. It will solve these problems you are having. If you really want to know what's going on, read the language manual, http://docs.python.org/ref/print.html It explains the behavior of this extra space, which is output by a successive 'print' statement. The

Re: Wits end with Python and cron

2005-09-28 Thread jepler
You need to export the variables. otherwise, they exist only in the shell, not in the processes it starts. Jeff pgplXE5VuF44A.pgp Description: PGP signature -- http://mail.python.org/mailman/listinfo/python-list

Re: Getting a number out of a string

2005-09-27 Thread jepler
You can index into a string: s = '06897' s[2] '8' You can also turn each character into an integer, in various ways: [int(c) for c in s] [0, 6, 8, 9, 7] map(int, s) [0, 6, 8, 9, 7] Jeff pgpDMq5e3RucB.pgp Description: PGP signature -- http://mail.python.org/mailman/listinfo/python-list

Re: Human readable number formatting

2005-09-27 Thread jepler
Compared to your program, I think the key to mine is to divide by limit before taking the log. In this way, things below the limit go to the next lower integer. I think that instead of having 'step' and 'base', there should be a single value which would be 1000 or 1024. import math def

Re: Using '__mul__' within a class

2005-09-24 Thread jepler
For the same reason that def f(z): z *= z c = 1 f(c) print c prints 1. Jeff pgpF5jQBO3otJ.pgp Description: PGP signature -- http://mail.python.org/mailman/listinfo/python-list

Re: Using '__mul__' within a class

2005-09-24 Thread jepler
Oops! I should have used '2' in the example, or some other number. I was trying to make a point about what x *= ... means when it is in the context of a function (or method) body. I think this is key to understanding what Python did in the case the user posted. Being rude wasn't my

Re: subprocess.Popen and replacing the shell pipe line

2005-09-22 Thread jepler
Probably the quoting of the argument to grep. try this instead: p1 = Popen(['grep', 'Sep 22', '/var/log/auth.log'], stdout=PIPE) etc Jeff -- http://mail.python.org/mailman/listinfo/python-list

Re: execfile eats memory

2005-09-19 Thread jepler
I generated a ~22-megabyte file with this small Python program: print [ for i in xrange(200): print ' + str(i) + ', print ] As the original poster suggested, Python uses at least several hundreds of megabytes when execfile()ing that source. I had to kill

Re: reading files with error

2005-09-18 Thread jepler
On Sun, Sep 18, 2005 at 02:15:00PM +1000, Maurice Ling wrote: Sorry but what are SEEK_END and SEEK_SET? Oops, that's what I get for snipping a part of a larger program. SEEK_SET = 0 SEEK_END = 2 Jeff pgpC1OTox5VvO.pgp Description: PGP signature --

Re: How to obtain a 'interactive session' of a script?

2005-09-18 Thread jepler
The 'code' module contains 'Utilities needed to emulate Python's interactive interpreter.'. By subclassing code.InteractiveConsole and replacing the raw_input method with one which reads from a file, I think you can get what you want. The example below the classes uses StringIO so that it can be

Re: reading files with error

2005-09-17 Thread jepler
I have written a program to do something similar. My strategy is: * use os.read() to read 512 bytes at a time * when os.read fails, seek to the next multiple of 512 bytes and write '\0' * 512 to the output I notice this code doesn't deal properly with short reads, but in my experience they

Re: socket.gethostbyaddr problem

2005-09-17 Thread jepler
Perhaps you mean to use the function socket.gethostbyname instead. import socket socket.gethostbyaddr(www.google.ca) Traceback (most recent call last): File stdin, line 1, in ? socket.herror: (1, 'Unknown host') socket.gethostbyname(www.google.ca) '64.233.167.147' Jeff pgpsZ1m3OcqVP.pgp

pybwidget release 0.1.2

2005-09-15 Thread jepler
pybwidget is a Python wrapper around the 'bwidget' family of widgets for Tkinter. It includes these classes: Entry Label Button ArrowButton ProgressBar ScrollView Separator MainFrame LabelFrame TitleFrame PanelFrame ScrolledWindow ScrollableFrame PanedWindow ButtonBox PagesManager

Re: Creating Pie Chart from Python

2005-09-15 Thread jepler
There are many. One choice would be Tkinter's Canvas. def frac(n): return 360. * n / 500 import Tkinter c = Tkinter.Canvas(width=100, height=100); c.pack() c.create_arc((2,2,98,98), fill=red, start=frac(0), extent = frac(100)) c.create_arc((2,2,98,98), fill=blue, start=frac(100), extent =

  1   2   >