Re: weak reference to bound method

2009-10-02 Thread Miles Kaufmann
On Oct 2, 2009, at 1:54 AM, Ole Streicher wrote: I am trying to use a weak reference to a bound method: class MyClass(object): def myfunc(self): pass o = MyClass() print o.myfunc 0xc675d0>> import weakref r = weakref.ref(o.myfunc) print r() None This is what I do not understand

Re: Timestamps for TCP packets?

2009-10-02 Thread Miles Kaufmann
On Oct 2, 2009, at 12:03 AM, Thomas Johnson wrote: Is there any way to get kernel-level timestamps for TCP packets while still using the standard python sockets library for communication? I need to communicate over a TCP connection as easily as possible, but also record the timestamps of the inc

Re: Are min() and max() thread-safe?

2009-09-17 Thread Miles Kaufmann
On Sep 16, 2009, at 10:39 PM, Steven D'Aprano wrote: On Wed, 16 Sep 2009 22:08:40 -0700, Miles Kaufmann wrote: On Sep 16, 2009, at 9:33 PM, Steven D'Aprano wrote: I have two threads, one running min() and the other running max() over the same list. I'm getting some mysteriou

Re: (A Possible Solution) Re: preferred way to set encoding for print

2009-09-16 Thread Miles Kaufmann
On Sep 16, 2009, at 12:39 PM, ~flow wrote: so: how can i tell python, in a configuration or using a setting in sitecustomize.py, or similar, to use utf-8 as a default encoding? [snip Stdout_writer_with_ncrs solution] This should work: sys.stdout = io.TextIOWrapper(sys.stdout.buffer,

Re: Are min() and max() thread-safe?

2009-09-16 Thread Miles Kaufmann
On Sep 16, 2009, at 9:33 PM, Steven D'Aprano wrote: I have two threads, one running min() and the other running max() over the same list. I'm getting some mysterious results which I'm having trouble debugging. Are min() and max() thread-safe, or am I doing something fundamentally silly by having

Re: list as an instance attribute

2009-09-14 Thread Miles Kaufmann
On Sep 14, 2009, at 1:55 AM, Robin Becker wrote: Bruno Desthuilliers wrote: pep08 : class names should be Capitalized. Also, if you're using Python 2.x, make it: class Primitive(object): #... ... I find it remarkable that the most primitive classes appear to break the pep08 convention

Re: Why indentation is use to denote block of code?

2009-09-14 Thread Miles Kaufmann
On Sep 13, 2009, at 5:38 PM, AggieDan04 wrote: On Sep 13, 6:27 pm, Steven D'Aprano wrote: On Sun, 13 Sep 2009 15:15:40 -0700, Chris Rebert wrote: In fact it's pretty much impossible to automatically indent Python code that has had its indentation removed; it's impossible to know for sure wh

Re: Variables vs attributes

2009-09-12 Thread Miles Kaufmann
On Apr 17, 2009, at 8:56 PM, Steven D'Aprano wrote: If an integer variable is an integer, and a string variable is a string, and float variable is a float, and a list variable is a list (there's a pattern here), shouldn't a class variable be a class and an instance variable be an instance? I

Re: Where regexs listed for Python language's tokenizer/lexer?

2009-09-11 Thread Miles Kaufmann
On Sep 11, 2009, at 11:10 PM, Chris Seberino wrote: Where regexs listed for Python language's tokenizer/lexer? If I'm not mistaken, the grammar is not sufficient to specify the language you also need to specify the regexs that define the tokens right?..where is that? The Python tokenizati

Re: Why does this group have so much spam?

2009-08-30 Thread Miles Kaufmann
"casebash" wrote in message news:7294bf8b-9819-4b6d-92b2- afc1c8042...@x6g2000prc.googlegroups.com... So much of it could be removed even by simple keyword filtering. Funny, I was just thinking recently about how *little* spam this list gets--on the other hand, I'm following it via the pyth

Re: Need help with Python scoping rules

2009-08-27 Thread Miles Kaufmann
On Aug 27, 2009, at 4:49 PM, kj wrote: Miles Kaufmann writes: Guido's design justifications: http://mail.python.org/pipermail/python-dev/2000-November/010598.html Ah! Clarity! Thanks! How did you find this? Did you know of this post already? Or is there some special way to s

Re: Need help with Python scoping rules

2009-08-27 Thread Miles Kaufmann
On Aug 26, 2009, at 1:11 PM, kj wrote: I think I understand the answers well enough. What I *really* don't understand is why this particular "feature" of Python (i.e. that functions defined within a class statement are forbidden from "seeing" other identifiers defined within the class statement)

Re: Object Reference question

2009-08-20 Thread Miles Kaufmann
On Aug 20, 2009, at 11:07 PM, josef wrote: To begin, I'm new with python. I've read a few discussions about object references and I think I understand them. To be clear, Python uses a "Pass By Object Reference" model. x = 1 x becomes the object reference, while an object is created with the typ

Re: Waiting for a subprocess to exit

2009-08-20 Thread Miles Kaufmann
On Aug 20, 2009, at 10:13 PM, Ben Finney wrote: The module documentation has a section on replacing ‘os.system’ , which says to use:: process = subprocess.Popen("mycmd" + " myarg", shell=True) status = os.waitpid(process.pid, 0

Re: Skipping a superclass

2009-08-02 Thread Miles Kaufmann
On Aug 2, 2009, at 5:36 AM, Steven D'Aprano wrote: I have a series of subclasses like this: class A(object): def method(self, *args): print "Lots of work gets done here in the base class" class B(A): def method(self, *args): print "A little bit of work gets done in B"

Re: python 3 and stringio.seek

2009-07-29 Thread Miles Kaufmann
On Jul 28, 2009, at 6:30 AM, Michele Petrazzo wrote: Hi list, I'm trying to port a my library to python 3, but I have a problem with a the stringio.seek: the method not accept anymore a value like pos=-6 mode=1, but the "old" (2.X) version yes... The error: File "/home/devel/Py3/lib/pyt

Re: trouble with minidom

2009-07-22 Thread Miles Kaufmann
On Jul 21, 2009, at 8:08 PM, Ronn Ross wrote: Hello I'm trying to read an xml file using minidome. The xml looks like: myProj /here/ My code looks like so: from xml.dom.minidom import parse dom = parse("myfile.xml") for node in dom.getElementsByTagName("project'): p

Re: Why not enforce four space indentations in version 3.x?

2009-07-15 Thread Miles Kaufmann
On Jul 15, 2009, at 4:26 PM, David Bolen wrote: Miles Kaufmann writes: On Jul 14, 2009, at 5:06 PM, David Bolen wrote: Are you sure? It seems to restrict them in the same block, but not in the entire file. At least I was able to use both space and tab indented blocks in the same file

Re: Why not enforce four space indentations in version 3.x?

2009-07-15 Thread Miles Kaufmann
On Jul 14, 2009, at 5:06 PM, David Bolen wrote: Are you sure? It seems to restrict them in the same block, but not in the entire file. At least I was able to use both space and tab indented blocks in the same file with Python 3.0 and 3.1. It seems to me that, within an indented block, Python

Re: python first assignment of a global variable

2009-07-15 Thread Miles Kaufmann
On Jul 15, 2009, at 1:55 PM, Rodrigue wrote: Basically, I was very surprised to discover that e() raises an exception, but even more that e_raise() points to if not MY_GLOBAL Is the problem not really when I assign? My assumption is that some reordering is happening behind the scenes that creat

Re: missing 'xor' Boolean operator

2009-07-15 Thread Miles Kaufmann
On Jul 15, 2009, at 1:55 PM, Emile van Sebille wrote: On 7/15/2009 10:43 AM Jean-Michel Pichavant said... Hrvoje Niksic wrote: [snip] Note that in Python A or B is in fact not equivalent to not(not A and not B). Did I make twice the same obvious error ? No -- but in the not(not... example

Re: missing 'xor' Boolean operator

2009-07-15 Thread Miles Kaufmann
On Jul 15, 2009, at 1:43 PM, Jean-Michel Pichavant wrote: Hrvoje Niksic wrote: [snip] Note that in Python A or B is in fact not equivalent to not(not A and not B). >>> l = [(True, True), (True, False), (False, True), (False, False)] >>> for p in l: ... p[0] or p[1] [snip] Did I make twic

Re: missing 'xor' Boolean operator

2009-07-14 Thread Miles Kaufmann
On Jul 15, 2009, at 12:07 AM, Dr. Phillip M. Feldman wrote: I appreciate the effort that people have made, but I'm not impressed with any of the answers. For one thing, xor should be able to accept an arbitrary number of input arguments (not just two) You originally proposed this in the c

Re: How to keep a function as a generator function when the yield operator is moved into its sub-functions??

2009-07-14 Thread Miles Kaufmann
On Jul 14, 2009, at 2:03 PM, weafon wrote: Hi guys, I have a question about the usage of yield. As shown in the below example, in general, if there is a code segment commonly used by two or more functions, we may isolate the segment into a function and then call it from other functions if

Re: Catching control-C

2009-07-09 Thread Miles Kaufmann
On Jul 9, 2009, at 9:20 AM, Lie Ryan wrote: Michael Mossey wrote: I want to understand better what the "secret" is to responding to a ctrl-C in any shape or form. Are you asking: "when would the python interpreter process KeyboardInterrupt?" ... In single threaded python program, the currentl

Re: function local namespace question

2009-07-08 Thread Miles Kaufmann
On Jul 8, 2009, at 1:35 PM, Paul LaFollette wrote: I cannot figure out any way to get a hook into the local namespace of a user defined function. I have tried making a wrapper class that grabs the function call and then uses exec to invoke myfunction.__code__ with my own dictionaries. This run

Re: Passing parameters for a C program in Linux.

2009-06-30 Thread Miles Kaufmann
On Jun 30, 2009, at 6:46 AM, venutaurus...@gmail.com wrote: I have to write an automted script which will test my c program. That program when run will ask for the commands. Keep in mind that, if your test script checks the program's output before giving it input, you can run into pro

Re: No trees in the stdlib?

2009-06-27 Thread Miles Kaufmann
João Valverde wrote: To answer the question of what I need the BSTs for, without getting into too many boring details it is to merge and sort IP blocklists, that is, large datasets of ranges in the form of (IP address, IP address, string). Originally I was also serializing them in a binary

Re: Regular Expression Non Capturing Grouping Does Not Work.

2009-06-27 Thread Miles Kaufmann
On Jun 27, 2009, at 3:28 AM, Virtual Buddha wrote: Hello all, I am having some difficulties with the non-capturing grouping in python regular expression module. Even the code from the online documentation (http://docs.python.org/ howto/regex.html#non-capturing-and-named-groups) does not seem t

Re: No trees in the stdlib?

2009-06-25 Thread Miles Kaufmann
On Jun 26, 2009, at 2:23 AM, Chris Rebert wrote: On Thu, Jun 25, 2009 at 10:55 PM, João Valverde wrote: Aahz wrote: In article , Tom Reed wrote: Why no trees in the standard library, if not as a built in? I searched the archive but couldn't find a relevant discussion. Seems like a g

Re: urllib2.urlopen issue

2009-06-24 Thread Miles Kaufmann
On Jun 24, 2009, at 2:59 PM, David wrote: On Jun 24, 11:27 am, Chris Rebert wrote: On Wed, Jun 24, 2009 at 10:50 AM, David wrote: hello, I have a url that is "http://query.directrdr.com/ptrack? pid=225&v_url=http:// www.plentyoffish.com&keyword=flowers&feed=1&ip=12.2.2.2&said=$said". If I open

Re: [Mac] file copy

2009-06-23 Thread Miles Kaufmann
On Jun 23, 2009, at 9:52 AM, Tobias Weber wrote: Hi, which is the best way to copy files on OS X? I want to preserve resource forks and extended attributes. ... bin/cp -p This. cp -p, mv, rsync -E, tar, and other utilities will use the copyfile(3) API to preserve extended attributes, r

Re: Idioms and Anti-Idioms Question

2009-06-22 Thread Miles Kaufmann
On Jun 22, 2009, at 12:14 AM, Ben Charrow wrote: What is subtly wrong about this piece of code? I can't see any bugs and can't think of subtle gotchas (e.g. the '\' is removed or the lines become separated, because in both cases an IndentationError would be raised). Perhaps, along with o

Re: class or instance method

2009-06-21 Thread Miles Kaufmann
On Jun 21, 2009, at 5:23 PM, Scott David Daniels wrote: Hrvoje Niksic wrote: ... class class_or_instance(object): def __init__(self, fn): self.fn = fn def __get__(self, obj, cls): if obj is not None: return lambda *args, **kwds: self.fn(obj, *args, **kwds) e

Re: generator expression works in shell, NameError in script

2009-06-21 Thread Miles Kaufmann
On Jun 19, 2009, at 8:45 AM, Bruno Desthuilliers wrote: >>> class Foo(object): ... bar = ['a', 'b', 'c'] ... baaz = list((b, b) for b in bar) but it indeed looks like using bar.index *in a generator expression* fails (at least in 2.5.2) : >>> class Foo(object): ... bar = ['a', 'b

Re: urllib2 content-type headers

2009-06-21 Thread Miles Kaufmann
On Jun 21, 2009, at 12:01 PM, TYR wrote: Unfortunately, I'm getting nothing but 400 Bad Requests. I suspect this is due to an unfeature of urllib2. Notably, although you can use urllib2.Request's add_header method to append a header, the documentation (http://docs.python.org/library/urllib2.html

Re: random number including 1 - i.e. [0,1]

2009-06-09 Thread Miles Kaufmann
On Jun 9, 2009, at 7:05 PM, Mensanator wrote: On Jun 9, 4:33 pm, Esmail wrote: Hi, random.random() will generate a random value in the range [0, 1). Is there an easy way to generate random values in the range [0, 1]? I.e., including 1? I am implementing an algorithm and want to stay as true

Re: Function/method returning list of chars in string?

2009-06-09 Thread Miles Kaufmann
On Jun 9, 2009, at 6:05 AM, Diez B. Roggisch wrote: Also as list-comps are going away and are replaced by list() Where did you hear that? -Miles -- http://mail.python.org/mailman/listinfo/python-list

Re: Winter Madness - Passing Python objects as Strings

2009-06-06 Thread Miles Kaufmann
On Jun 4, 2009, at 3:25 AM, Hendrik van Rooyen wrote: A can is like a pickle, in that it is a string, but anything can be canned. Unlike a pickle, a can cannot leave the process, though, unless the object it points to lives in shared memory. If you have any interest, contact me and I will send