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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: log in to a website

2005-06-16 Thread Jeff Epler
You may find the third-party modules "ClientForm" and "ClientCookie" to be useful. Using ClientForm, the following code uploads a file to a particular web form: forms = ClientForm.ParseResponse(urllib2.urlopen(url)) f = forms[0] f.add_file(open(local, "rb"), filename=remote, name="file

Re: Programmatic links in a TKinter TextBox

2005-06-15 Thread Jeff Epler
Based on the location where the user clicked, you can find the associated tags. Then you must loop through them to find the one that gives the "href" value. Jeff :r /tmp/link.py import Tkinter app = Tkinter.Tk() text = Tkinter.Text(app) text.pack() def click(event): #this doesn't work

Re: Strange socket problem

2005-06-15 Thread Jeff Epler
When using os.system(), files that are open in the parent are available in the child, as you can see here in Linux' listing of the files open by the child program: [EMAIL PROTECTED] jepler]$ python -c 'f = open("/tmp/test", "w"); print f.fileno(); import os; os.system("ls -l /proc/self/fd")' 3 to

Re: [Python-Dev] A bug in pyconfig.h under Linux?

2005-06-14 Thread Jeff Epler
[sent to python-list and poster] Did you follow the direction that Python.h be included before any system header? This is mentioned at least in http://docs.python.org/ext/simpleExample.html It's a crummy thing for Python to insist on, but if you can re-organize your headers to do this it sho

Re: Get drives and partitions list (Linux)

2005-06-12 Thread Jeff Epler
Using /proc/partitions is probably preferable because any user can read it, not just people who can be trusted with read access to drives, and because the format of /proc/partitions is probably simpler and more stable over time. That said, what you do is import commands fdisk_output = comm

Re: count string replace occurances

2005-06-12 Thread Jeff Epler
On Sun, Jun 12, 2005 at 04:55:38PM -0700, Xah Lee wrote: > if i have > mytext.replace(a,b) > how to find out many many occurances has been replaced? The count isn't returned by the replace method. You'll have to count and then replace. def count_replace(a, b, c): count = a.count(b) retur

Re: TKinter -- '' event executing more than once?

2005-06-12 Thread Jeff Epler
For me, an 'is' test works to find out what widget the event is taking place on. # import Tkinter def display_event(e): print "event received", e.widget, e.widget is t t = Tkinter.Tk() t.bind("", display_event) w = Tkint

Re: Hiding X windows

2005-06-11 Thread Jeff Epler
You may want to use a standalone program to do this. "xwit" has the ability to iconify a window which can be selected in a variety of ways. http://hpux.connect.org.uk/hppd/hpux/X11/Misc/xwit-1.0/man.html There's a direct Python interface to the X protocol in python-xlib. You could re-write t

Re: Socket Speed

2005-06-06 Thread Jeff Epler
The machines with the 100mbps ethernet link are slightly different---Pentium 4, 2.8GHz, Python 2.2, RedHat 9. File size: 87490278 Best of 4 runs: 7.50 MB/s reported by "wget". There was other network activity and system load at the time. Jeff pgpNVPeW3ghJL.pgp Description: PGP signature -- h

Re: PyArg_ParseTuple and dict

2005-06-05 Thread Jeff Epler
I tried to recreate the problem based on what you described in your message. I was unable to recreate the problem. I wrote the following file "sjh.c": #include PyObject *f(PyObject *self, PyObject *args) { PyObject *ob = NULL; if(!PyArg_ParseTuple(args, "O", &ob)) return NULL; Py_I

Re: GUI builders considered harmful (Was: anygui, anydb, any opinions?)

2005-06-05 Thread Jeff Epler
On Sun, Jun 05, 2005 at 02:38:16PM -0500, Mike Meyer wrote: [...] > The first, and most obvious, thing that GUI builders do is force the > developer to specify an exact position - if not size - for the > graphical elements of the UI. [...] Certainly some---or even most---builders work like this.

Re: Socket Speed

2005-06-05 Thread Jeff Epler
300KB/s sounds dreadfully low. I simply ran "python /usr/lib/python2.3/SimpleHTTPServer.py &", then "wget -O /dev/null http://0.0.0.0:8000/70megfile";. On the best of 4 runs (when the file was cached) wget measured 225.20MB/s. The hardware is a Pentium-M laptop with 768MB RAM runnng at 1.5GHz.

Re: method = Klass.othermethod considered PITA

2005-06-04 Thread Jeff Epler
On Sat, Jun 04, 2005 at 10:43:39PM +, John J. Lee wrote: > 1. In derived classes, inheritance doesn't work right: Did you expect it to print 'moo'? I'd have been surprised, and expected the behavior you got. > 2. At least in 2.3 (and 2.4, AFAIK), you can't pickle classes that do >this.

Re: thread vs GC

2005-06-02 Thread Jeff Epler
I suspect that getting the threads to die will be tricky, and as written the thread holds a reference to the 'primegen' instance (this part can be cured, but it still doesn't ever make the thread exit). Instead of figuring out how to get this to clean itself up, why not make sure you only make one

Re: Easy way to detect hard drives and partitions in Linux

2005-06-02 Thread Jeff Epler
You're not going to find a single portable "unix" way of doing this. The format of /etc/fstab and /etc/mtab are pretty portable, but they only list mountable/mounted partitions, not all partitions. In addition to the linux possibilities mentioned in another reply, there is also /proc/partitions.

Re: TkInter Listbox Widget Formatting

2005-06-02 Thread Jeff Epler
This isn't an option in the stock Tk listbox or any of the alternatives I know of offhand (bwidget ListBox, TixTList). The TkTable widget, which can also display multiple columns, can select different justifications, either for the whole table, or for single cells. I've never used TkTable with Pyt

Re: Unicode string in exec

2005-06-02 Thread Jeff Epler
First off, I just have to correct your terminology. "exec" is a statement, and doesn't require parentheses, so talking about "exec()" invites confusion. I'll answer your question in terms of eval(), which takes a string representing a Python expression, interprets it, and returns the result. In

Re: scripting browsers from Python

2005-06-01 Thread Jeff Epler
I wanted to have a Python program make my browser do a POST. I am using Firefox on Linux. Here's what I did: * Prepare a HTML page on the local disk that looks like this: http://www.example.com/cgi-bin/example.cgi";> Submitting form.

Re: exit after process exit

2005-05-31 Thread Jeff Epler
You might want os.spawnv(os.P_WAIT, "a.exe", ["a.exe"]) os.system("a.exe") Jeff pgpp3Fxdo0nYA.pgp Description: PGP signature -- http://mail.python.org/mailman/listinfo/python-list

Re: Strange behaviour of floating point constants in imported modules

2005-05-23 Thread Jeff Epler
This may be relevant to the problems you're seeing: https://sourceforge.net/tracker/?func=detail&atid=305470&aid=774665&group_id=5470 The short story, as the tracker item paints it, is that setting LC_NUMERIC to anything other than 'C' can give results like the ones you describe---Python itse

Re: Shift-JIS to UTF-8 conversion

2005-05-23 Thread Jeff Epler
On Fri, May 20, 2005 at 12:16:15AM -0700, [EMAIL PROTECTED] wrote: > Hello, I think the answer is basically correct but shift-jis is not a > standard part of Python 2.3. Ah, I was fooled --- I tested on Python 2.3, but my packager must have included the codecs you went on to mention. Jeff pgp4q

Re: Shift-JIS to UTF-8 conversion

2005-05-19 Thread Jeff Epler
I think you do something like this (untested): import codecs def transcode(infile, outfile, incoding="shift-jis", outcoding="utf-8"): f = codecs.open(infile, "rb", incoding) g = codecs.open(outfile, "wb", outcoding) g.write(f.read()) # If the file is so large that it can't be

Re: Tkinter special math chars

2005-05-19 Thread Jeff Epler
On Thu, May 19, 2005 at 12:56:12PM -0500, phil wrote: > Why is it so slow? (RH Linux, 2.4.20, 1.6Ghz AMD) > 3/4 second slower to display widget w/unicode, > even if I encode u'\u221e' u'\u221e' vs u'\N{INFINITY}' should make no noticible run-time difference--they both specify exactly the same stri

Re: Tkinter special math chars

2005-05-19 Thread Jeff Epler
I wrote the following code: import Tkinter t = Tkinter.Label() t.configure( text=u"As the function approaches \N{INFINITY}, \N{HORIZONTAL ELLIPSIS}") t.pack() t.mainloop() It worked for me on Windows NT 4.0 with Python 2.4, and on RedHat 9 with a self-compiled Python 2.

Re: Byte-operations.

2005-05-19 Thread Jeff Epler
In Python, "chr" gives a 1-byte string from a small integer, "ord" does the reverse. Strings are concatenated with "+" and substrings are taken with the slice operator, s[pos1:pos2]. I'm not a visual basic expert, but it looks like these are the operations the code below performs. Jeff pgpWpqb

Re: iso_8859_1 mystery/tkinter

2005-05-18 Thread Jeff Epler
this isn't about the "sign bit", it's about assumed encodings for byte strings.. In iso_8859_1 and unicode, the character with value 0xb0 is DEGREE SIGN. In other character sets, that may not be true---For instance, in the Windows "code page 437", it is u'\u2591' aka LIGHT SHADE (a half-tone patte

Re: Interaction between TclTk editor with Python code

2005-05-17 Thread Jeff Epler
One way to get a handle on some Tcl variables from Python is to create Tkinter.Variable instances with the names of the existing Tcl variables (normally, the variable names are chosen arbitrarily). Once you've done this, you can do things like add variable traces (the trace_variable method) on the

Re: Recommended version of gcc for Python?

2005-05-16 Thread Jeff Epler
Most versions of gcc should be just fine to compile Python. Python is targeted at ANSI/ISO C compilers, but does not yet use any C99 features. I don't think there was ever such a thing as "gcc 3.5"; http://gcc.gnu.org/ lists 4.0 as the "current release series" and 3.4.3 as the "previous release s

Re: Precision?

2005-05-15 Thread Jeff Epler
If you want to do decimal arithmetic, use the decimal module which is new in Python 2.4. Python 2.4 (#1, Jan 22 2005, 20:45:18) [GCC 3.3.3 20040412 (Red Hat Linux 3.3.3-7)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> from decimal import Decimal as D >>> D(

Re: How "return" no return ?

2005-05-13 Thread Jeff Epler
At the interactive prompt, a result is printed when both these things are true: * The entered code is an expression, not any other kind of statement * The result of the expression is not 'None' If an expression occurs, information about it will be printed instead. So the interpreter won't

Re: Using TCL files in Python ?

2005-05-11 Thread Jeff Epler
While I've never used it, there *is* a Tix module in Python which appears to wrap the widgets provided by Tix. In Fedora Core 2, Python doesn't seem to be configured to use Tix OOTB but a one-liner (that should be harmless elsewhere) does make it work. These classes are defined in the Tix module:

Re: [HELP] Tkinter Application Minimized to System Tray :)

2005-05-06 Thread Jeff Epler
Tk, the library that Tkinter wraps, does not offer a way to "minimize to the taskbar". Jeff pgp3ATXnxg0dO.pgp Description: PGP signature -- http://mail.python.org/mailman/listinfo/python-list

Re: New Python regex Doc (was: Python documentation moronicities)

2005-05-06 Thread Jeff Epler
To add to what others have said: * Typos and lack of spell-checking, such as "occurances" vs "occurrences" * Poor grammar, such as "Other characters that has special meaning includes:" * You dropped version-related notes like "New in version 2.4" * You seem to love the use of s, while docs.py

Re: Best way to convert a list into function call arguments?

2005-05-05 Thread Jeff Epler
Your question is answered in the tutorial: http://docs.python.org/tut/node6.html#SECTION00674 4.7.4 Unpacking Argument Lists The reverse situation occurs when the arguments are already in a list or tuple but need to be unpacked for a function call requiring separate positional arg

Re: descriptor dilemma

2005-05-04 Thread Jeff Epler
On Wed, May 04, 2005 at 09:14:18AM -0700, Sébastien Boisgérault wrote: > > Yup ?!? Weird ... especially as: > > >>> id(c.f) == id(C.__dict__['f'].__get__(c,C)) > True Here, c.f is discarded by the time the right-hand-side of == is executed. So the object whose id() is being calculated on the ri

Re: A faster method to generate a nested list from a template?

2005-05-04 Thread Jeff Epler
Are there only a few, unchanging templates? If so, (dynamiclly) create a function for each template. This will be nearly the fastest you can go in Python, excluding the time to create and byte-compile the nesting function. # This code is in the public domain def make_nesting_expression(l, s):

Re: How to read an integer value from a binary file?

2005-05-03 Thread Jeff Epler
As your 'for' loop shows, the number of items in the slice [2:5] is only 3, not 4. Maybe you want the slice [2:6] instead. >>> x = "xx\xb6/\0\0" >>> struct.unpack('i', x[2:6]) (12214,) Jeff pgprzSG2OzoK4.pgp Description: PGP signature -- http://mail.python.org/mailman/listinfo/python-list

Re: cgi "print statement" in multithreaded enviroment?

2005-05-02 Thread Jeff Epler
You could write something like class ThreadSpecificFile: def set_stdout(f): self.files[thread_id] = f def write(data): self.files[thread_id].write(data) sys.stdout = ThreadSpecificFile() where you'll have to fill out a few more things like thread_id,

Re: How to track down all required shared libraries?

2005-04-30 Thread Jeff Epler
One poster suggests 'ldd' for executables. You can also use this on shared libraries: $ ldd /usr/lib/python2.3/lib-dynload/_tkinter.so libtix8.1.8.4.so => /usr/lib/libtix8.1.8.4.so (0x009b6000) libtk8.4.so => /usr/lib/libtk8.4.so (0x00111000) libtcl8.4.so => /usr/lib/libtc

Re: tkinter OptionMenu column break

2005-04-30 Thread Jeff Epler
I don't think that Tk's menus ever use more than one column. They certainly don't on Unix. Jeff pgpsVnvjgm3Qy.pgp Description: PGP signature -- http://mail.python.org/mailman/listinfo/python-list

Re: python equivalent of php implode

2005-04-27 Thread Jeff Epler
On Tue, Apr 26, 2005 at 09:59:29PM -0500, Mike Meyer wrote: > Jeff Epler <[EMAIL PROTECTED]> writes: > > > items = query_param.items() > > keys = [item[0] for item in items] > > values = [item[1] for item in items] > > Is there some reason not to

Re: python equivalent of php implode

2005-04-26 Thread Jeff Epler
It looks like php's implode(sep, seq) is like sep.join(seq) in Python. But this is a lousy way to write database queries. You should use the Python's DB-API interface's execute(statement, parameters) instead. Assuming that paramstyle is 'qmark', I think it ends up looking something like this:

Re: Why is Python not supporting full derivation of built-in file class?

2005-04-24 Thread Jeff Epler
This issue was discussed in another recent python-list thread, called "Writing to stdout and a log file". My second post includes a patch to Python's "fileobject.c" that made the code that started that thread work, but for reasons I mentioned in that post I didn't want to push for inclusion of my

Re: Writing to stdout and a log file

2005-04-19 Thread Jeff Epler
In that case, it looks like you won't be able to get what you want without modifying CPython. PRINT_ITEM calls PyFile_SoftSpace, PyFile_WriteString, and PyFile_WriteObject, which all use PyFile_Check(). It might be as simple as changing these to PyFile_CheckExact() calls in PyFile_WriteString / P

Re: Writing to stdout and a log file

2005-04-19 Thread Jeff Epler
This variation works: # class Tee: def __init__(self, *args): self.files = args def write(self, data): for f in self.files: result = f.write(data) return result def writelines(s

Re: fpectl

2005-04-19 Thread Jeff Epler
On Tue, Apr 19, 2005 at 02:05:11AM -0700, Sébastien Boisgérault wrote: > Thanks for this answer. > > Did you forward this info to python-dev ? I created a patch on the sf tracker. It's been responded to by several developers. You can read what they said there. http://python.org/sf/1185529 Jef

Re: Tkinter Event Types

2005-04-18 Thread Jeff Epler
The "type" field is related to the definition of different events in X11. In Xlib, the event structure is a "C" union with the first (common) field giving the type of the event so that the event-dependant fields can be accessed through the proper union member. Generally, you won't use this field

Re: fpectl

2005-04-18 Thread Jeff Epler
It looks like the automatic build of the 'fpectl' module was broken somewhere along the line, perhaps when the transition from Modules/Setup to setup.py took place. Once I made the change below and rebuilt, I got the fpectl module. Furthermore, it appeared to "do something" on my Linux/x86 system:

Re: New Python regex Doc (was: Python documentation moronicities)

2005-04-18 Thread Jeff Epler
On Mon, Apr 18, 2005 at 01:40:43PM -0700, Xah Lee wrote: > i have rewrote the Python's re module documentation. > See it here for table of content page: > http://xahlee.org/perl-python/python_re-write/lib/module-re.html For those who have long ago consigned Mr. Lee to a killfile, it looks like he'

Re: Get the entire file in a variable - error

2005-04-14 Thread Jeff Epler
It's not clear to me what you mean by "the first line" (gzip does not output a file composed of lines, its output is byte-oriented). Printing tst.getvalue() is probably not a very useful thing to do, since it won't do anything useful when the output is a terminal, and it will add an extra newline

Re: Why won't someone step up and make use of the Free tools (was Re: Python 2.4 killing commercial Windows Python development ?)

2005-04-12 Thread Jeff Epler
On Tue, Apr 12, 2005 at 08:25:58PM +, Bengt Richter wrote: > But credit where due. Someone has stepped up to a large chunk of the problem: > >http://jove.prohosting.com/iwave/ipython/pyMinGW.html Yay. I'm glad somebody *is* doing this. Maybe all that is needed is to "get the word out".

Re: Tkinter "withdraw" and "askstring" problem

2005-04-12 Thread Jeff Epler
The answer has to do with a concept Tk calls "transient". wm transient window ?master? If master is specified, then the window manager is informed that window is a transient window (e.g. pull-down menu) working on behalf of master (where master is the path name for

Why won't someone step up and make use of the Free tools (was Re: Python 2.4 killing commercial Windows Python development ?)

2005-04-12 Thread Jeff Epler
I'm sorry that this is going to come out sounding like a flame, but it seems to me that there today only a few technical problems remaining with Python when built with mingw32. If one of the people who has expressed such deep concern about this "msvcr71.dll" problem would simply install the Free t

Re: help: loading binary image data into memory

2005-04-11 Thread Jeff Epler
probably something like this: (untested) def make_ftplib_callback(f): def callback(block): f.write(block) return callback img = cStringIO.StringIO() retrbinary( "get ???", make_ftplib_callback(img)) Jeff pgpaecaxnsqYB.pgp Description: PGP signature -- http://mail.pyt

Re: curious problem with large numbers

2005-04-07 Thread Jeff Epler
You may want to read http://www.python.org/peps/pep-0754.html Part of the text reads The IEEE 754 standard defines a set of binary representations and algorithmic rules for floating point arithmetic. Included in the standard is a set of constants for representing special values, in

Re: Read 16 bit integer complex data

2005-04-07 Thread Jeff Epler
You may want to use the 'numeric' or 'numarray' extensions for this. The page on numarray is here: http://www.stsci.edu/resources/software_hardware/numarray numarray doesn't support "complex 16-bit integer" as a type, but you can get a complex, floating-point valued array from your integer val

Re: Resticted mode still active (error?)

2005-04-06 Thread Jeff Epler
Is there a script that causes this problem, without using mod_python or jepp? If so, please attach it to the sourceforge bug. http://sourceforge.net/tracker/index.php?func=detail&aid=1163563&group_id=5470&atid=105470 pgpiWdvwwFmcD.pgp Description: PGP signature -- http://mail.python.org/mailman

  1   2   >