Steven Bethard wrote:
>
> I don't know the implementation enough to know whether or not a tuple is
> actually created when "b" and "c" are bound to their values, but I'd be
> willing to bet that whatever happens to "(b, c)" is exactly the sa
M.E.Farmer wrote:
>>They're both an UNPACK_SEQUENCE byte-code.
>
> I have dissed it myself ;)
> My argument, if you can call it that, is that it is not clear that
> Python is going to do a tuple unpacking here or not !
Hmm... Well, I wouldn't say that. I think it's quite clear that
Python's do
Ron Adam wrote:
>
> Do exceptions that take place get stored in a stack or list someplace?
[snip]
> I know I can catch the error and store it myself with,
>
> except Exception, exc:
>
> or possibly,
>
> errlist = []
> errlist.append(sys.exc_info())
>
> But what I want to know is do
Fredrik Lundh wrote:
> which is one of the things you really love when you link against
> underdocumented Fortran programs from C. ("is that parameter
> a scalar or an array? crash! oh, an array. how many values does
> it expect? crash! oh, a few more, I suppose").
+1 QOTW
STeVe
--
http://mail.
tiissa wrote:
> Steffen Glückselig wrote:
>
> 1.0 + 3.0 + 4.6
>> 8.5996
>>
>> Ehm, how could I get the intuitively 'correct' result of - say - 8.6?
>> ;-)
>
> You may find annex B of the python tutorial an interesting read:
> http://docs.python.org/tut/node16.html
Yes, the simple
Joseph Garvin wrote:
> [EMAIL PROTECTED] wrote:
>
>>It has something called "reval" looks that would fit my needs
>>perfectly.
>>
>>Details:
>>http://www.faqts.com/knowledge_base/view.phtml/aid/4550/fid/538
>
> If I remember correctly reval and it's brothers were deemed insecure,
> are no longer
Ron Adam wrote:
> I had read somewhere that exception objects were global, but that wasn't
> correct, after testing it, they appear to be part of the local frame. So
> once a function exits, any exceptions objects that happened inside the
> function are no longer retrievable.
>
> And checking e
Kay Schluehr wrote:
> but PEP 340 is already withdrawn by the BDFL.
> There won't be any Ruby-like blocks because they hide control flow.
Well, there won't be any blocks that can perform *arbitrary* control
flow, but it does look like we might have blocks that can perform
try/finally-like acquis
Matt Feinstein wrote:
> Is there an optimal way to apply a function to the elements of a two-d
> array?
>
> What I'd like to do is define some function:
>
> def plone(x):
> return x+1
>
> and then apply it elementwise to a 2-D numarray. I intend to treat the
> function as a variable, so ufu
Matt Feinstein wrote:
> On Mon, 16 May 2005 11:07:06 -0600, Steven Bethard
> <[EMAIL PROTECTED]> wrote:
>
>
>
>>I must be missing something, because the simplest possible thing seems
>>to work for me:
>>
>>py> import numarray as na
>>py>
Ville Vainio wrote:
>>"Kay" == Kay Schluehr <[EMAIL PROTECTED]> writes:
>
>
> Kay> but PEP 340 is already withdrawn by the BDFL. [1]
>
> Kay> There won't be any Ruby-like blocks because they hide control
> Kay> flow.
>
> Bummer. I would have greatly enjoyed seeing the only real
Matt Feinstein wrote:
> Well, for example, suppose I want to modify the elements of the matrix
> in some fashion. However, I'm not entirely sure how I want to do it.
> As a strawman, I generate a function with a Boolean test in it that
> multiplies by one factor if the matrix element is in an inter
Paul Rubin wrote:
> I'm trying the super() function as described in Python Cookbook, 1st ed,
> p. 172 (Recipe 5.4).
>
> class A(object):
> def f(self):
> print 'A'
>
>
> class B(object):
> def f(self):
> print 'b'
>
>
> class C(A,B):
Laszlo Zsolt Nagy wrote:
> I tested this and I realized that if you change the parameter list in
> the descendants then it is not wise to use super.
> I'm going to publish the example below, I hope others can learn from it
> too.
>
[snip and fixed formatting]
>
> Example (bad):
>
> class A(obj
Ron Adam wrote:
> You can sort your grades list however you want. If you want to sort by
> student name instead of student_id, you would use:
>
> # Sort grades list by student name.
> grades.sort(lambda x,y: cmp(students[x[1]][0], students[y[1]][0]))
>
> Assuming the name is in the first
Mayer wrote:
> Hello:
>
> I need some help in understanding generators. I get them to work in
> simple cases, but the following example puzzles me. Consider the
> non-generator, "ordinary" procedure:
>
> def foo(n):
> s = []
> def foo(n):
> if n == 0:
> print s
>
could ildg wrote:
> Thank you for your help.
> I know the function g is changed after setting the func_name.
> But I still can't call funciton g by using f(), when I try to do
> this, error will occur:
>
>
g.func_name="f"
print g
>
>
>
f()
>
> Traceback (most recent call last):
>
could ildg wrote:
> I think decorator is a function which return a function, is this right?
> e.g. The decorator below if from http://www.python.org/peps/pep-0318.html#id1.
>
> def accepts(*types):
> def check_accepts(f):
> assert len(types) == f.func_code.co_argcount
> def new
George Sakkis wrote:
> "Steven Bethard" wrote:
>
>>py> def bin(n):
>>... s = []
>>... def bin(n):
>>... if n == 0:
>>... yield s
>>... else:
>>... s.append(0)
>>.
Bill Mill wrote:
>py> alpha = 'abcdefghijklmnopqrstuvwxyz'
>py> for i, digraph in enumerate(sorted([''.join((x, y)) for x in alpha
> ...for y in [''] + [z for z in alpha]], key=len)):
> ... locals()[digraph] = i + i
> ...
It would probably be better to get in the habit of writing
glob
Jason Drew wrote:
> z = lambda cp: (int(cp[min([i for \
> i in xrange(0, len(cp)) if \
> cp[i].isdigit()]):])-1,
> sum(((ord(cp[0:min([i for i in \
> xrange(0, len(cp)) if \
> cp[i].isdigit()])][x])-ord('A')+1) \
> * (26 ** (len(cp[0:min([i for i in \
> xrange(0, len(cp)
Gary Wilson Jr wrote:
> Gary Wilson Jr wrote:
>
>>alpha = 'abcdefghijklmnopqrstuvwxyz'.upper()
>>pairs = [x for x in alpha] + [''.join((x,y)) for x in alpha for y in alpha]
>
> I forget, is string concatenation with '+' just as fast as join()
> now (because that would look even nicer)?
Certain l
Jason Drew wrote:
> ##def tuple2coord(tupl):
[snip]
> ##rowfromzero, colfromzero = tupl
Just a side note here that if you want a better function signature, you
might consider writing this as:
tuple2coord((rowfromzero, colfromzero)):
...
Note that the docstrings are nicer this way:
py>
James Stroud wrote:
> import sys
>
> try:
> arg1 = sys.argv[1]
> except IndexError:
> print "This script takes an argument, you boob!"
> sys.exit(1)
Also possible, to guarantee that exactly one argument was given:
try:
arg1, = sys.argv
except ValueError:
print "This script takes an a
rbt wrote:
> Heiko Wundram wrote:
> import os
> path = "/home/heiko"
> file_count = sum((len(f) for _, _, f in os.walk(path)))
> file_count
>
> Thanks! that works great... is there any significance to the underscores
> that you used? I've always used root, dirs, files when using o
[EMAIL PROTECTED] wrote:
> """box.py"""
>
> class box:
> def __init__(self):
> print "in box"
>
> This program passes running "python box.py".
>
> I had put this program under /work/dev/mytests/new
>
> Now I want to use it from a second python program, which
> resides in a totally differe
could ildg wrote:
> When I try to learn metaclass of python by article at this place:
> http://www.python.org/2.2/descrintro.html#metaclasses,
> I changed the autosuper example a little as below:
>
> class autosuper(type):
> def __init__(cls,name,bases,dict):
> super(autosuper,cls).__i
Steve Holden wrote:
> Steven Bethard wrote:
>>
>> Also possible, to guarantee that exactly one argument was given:
>>
>> try:
>>arg1, = sys.argv
>> except ValueError:
>>print "This script takes an argument, you boob!"
>>s
John Doe wrote:
> If you need a function that prints stuff, consider these two examples:
> [snip]
> PrintFunc = lambda x: print x
py> printfunc = lambda x: print x
Traceback ( File "", line 1
printfunc = lambda x: print x
^
SyntaxError: invalid syntax
See Inap
C Gillespie wrote:
> Does anyone know of any examples on how (& where) to use staticmethods and
> classmethods?
My personal experience is that I almost *never* want a staticmethod.
The things that I would have written as a staticmethod in Java I simply
write as a module-level function in Python.
Simon Brunning wrote:
> On 5/24/05, Cameron Laird <[EMAIL PROTECTED]> wrote:
>> General principle: if in doubt about the significance of an item in
>> "Python-URL!", assume that it's intended in a constructive way.
>
> I find that if you make the same assumption about c.l.py in general,
> you are
gry@ll.mit.edu wrote:
> I have a string like:
> {'the','dog\'s','bite'}
> or maybe:
> {'the'}
> or sometimes:
> {}
>
[snip]
>
> I want to end up with a python array of strings like:
>
> ['the', "dog's", 'bite']
>
> Any simple clear way of parsing this in python would be
> great; I just assume
Paul McGuire wrote:
text = r"'the','dog\'s','bite'"
def unquote(s,l,t):
>
> ... t2 = t[0][1:-1]
> ... return t2.replace("\\'","'")
> ...
Note also, that the codec 'string-escape' can be used to do what's done
with str.replace in this example:
py> s
"'the','dog\\'s','bite'"
py> s
[EMAIL PROTECTED] wrote:
> vbox = array(m) (size: 1000x1000 approx)
> for b in bx:
> vbox[ b[1], b[0]:b[2] ] = 0
> vbox[ b[3], b[0]:b[2] ] = 0
> vbox[ b[1]:b[3], b[0] ] = 0
> vbox[ b[1]:b[3], b[2] ] = 0
This may not help, but you could try to minimize the number of times you
call
Paul McNett wrote:
> Sriek wrote:
>> i come from a c++ background. i ws happy to find myself on quite
>> familiar grounds with Python. But, what surprised me was the fact that
>> the __init__(), which is said to be the equivlent of the constructor in
>> c++, is not automatically called.
>
[snip]
Sriek wrote:
> maybe like this:
> we can have the default behaviour as calling the default constructor
> ( with default arguements where required ). Along with this, keep the
> option open to call constructors explicitly.
Ok, so here's another example:
def init(self):
print "An __init__ met
This has probably been answered before, but my Google skills have failed
me so far...
Is there an os independent way of checking to see if a particular
executable is on the path? Basically what I want to do is run code like:
i, o, e = os.popen3(executable_name)
but I'd like to give an info
GMane Python wrote:
> string repetition can not repeat a value negative times:
> 'hello' * -3 is invalid.
Well, it's not invalid:
py> 'a' * -1
''
py> 'a' * -42
''
but you could definitely say that
S * N1 == S * N2
does not imply that
N1 == N2
STeVe
--
http://mail.python.org/mailman/l
Elliot Temple wrote:
>
> On May 27, 2005, at 12:17 PM, [EMAIL PROTECTED] wrote:
>
>> I have read in a file and need to get the number of lines.
>>
>> cpn_file = open('Central Part number list.txt')
>> cpn_version = cpn_file.read().split('\n')
>>
>> I want to know the number of elements in
Benji York wrote:
> I'll extrapolate from your message that you want to get the values of
> the dict in sorted order. If so, here's how:
>
> >>> d = {'a': 1, 'b': 2, 'c':3}
> >>> d
> {'a': 1, 'c': 3, 'b': 2}
> >>> v = d.values()
> >>> v
> [1, 3, 2]
> >>> v.sort()
> >>> v
> [1, 2, 3]
Or in
John Machin wrote:
> >>> import re
> >>> text = "(word1 & (Word2|woRd3))".lower()
> # you seem to want downshifting ...
> >>> re.split(r"\W+", text)
> ['', 'word1', 'word2', 'word3', '']
> >>>
>
> Hmmm ... near, but not exactly what you want. We need to throw away
> those empty strings, which
Andy Leszczynski wrote:
> Chris F.A. Johnson wrote:
>>And to answer the question in the subject line:
>>
>> last_line = file(argv[1]).readlines()[-1]
>>
>>Both of which assume "from sys import argv".
>
> What if a file is long enough?
Huh? You mean what if it's too big to fit in memory?
LenS wrote:
> class names:
> def __init__(self, format = "F"):
> self.format = format
>
> def namesplit(self, name):
> if self.format == "F":
> self.namelist = name.split()
> self.first = self.namelist[0]
> self.init = self.namelist[1]
>
Duncan Booth wrote:
> Dan Bishop wrote:
>> Or if you do use eval, don't give it access to any names.
[snip]
>> os.system("rm -rf *")
>> Traceback (most recent call last):
>> File "", line 1, in ?
>> File "", line 0, in ?
>> NameError: name 'os' is not defined
>
> Have you tried giving it the s
I have a list of strings that looks something like:
lst = ['0', '0', '(*)', 'O', '(*', '*', '(*', '*))', '((*', '*)', '*)']
The parentheses in the labels indicate where an "annotation" starts and
ends. So for example, the label '(*)' at index 2 of the list means that
I have an annotation at (2
tiissa wrote:
> I'd personnally extract the parenthesis then zip the lists of indices.
> In short:
>
> >>> def indices(mylist):
> ... lopen=reduce(list.__add__, [[i]*s.count('(') for i,s in
> enumerate(mylist)],[])
> ... lclose=reduce(list.__add__, [[i]*s.count(')') for i,s in
> enume
Duncan Booth wrote:
> Steven Bethard wrote:
>
>>But you can try it at home if you set __builtins__ to something other
>>than the default:
>>
>>py> eval("""__import__("os").system('echo "hello"')""&quo
Raymond Hettinger wrote:
> [Steven Bethard]
>
>>>I have a list of strings that looks something like:
>>>lst = ['0', '0', '(*)', 'O', '(*', '*', '(*', '*))', '((*', '*)',
Duncan Booth wrote:
> e.g. Assuming that the MyDatabase class does something nasty to a file:
>
class MyDatabase(object):
>
> def __init__(self, filename):
> self.filename = filename
> def initialise(self):
> print "Splat %s" % self.filename
>
eval('''[ cls for cl
Fernando M. wrote:
> i was just wondering about the need to put "self" as the first
> parameter in every method a class has because, if it's always needed,
> why the obligation to write it? couldn't it be implicit?
py> import this
The Zen of Python, by Tim Peters
Beautiful is better than ugly.
Ex
Michael wrote:
> Do expicit pointers exist in python??
>
> if i do:
>
> a = [5,7]
> b = a
>
> a.empty()
>
> b = ?
This is what the interactive prompt is for. Try it:
py> a = [5,7]
py> b = a
py> a.empty()
Traceback (most recent call last):
File "", line 1, in ?
AttributeError: 'list' objec
Michael wrote:
> if i do
> a=2
> b=a
> b=0
> then a is still 2!?
>
> so when do = mean a reference to the same object and when does it mean make
> a copy of the object??
It *always* means a reference. It *never* makes a copy.
Although the terminology isn't quite right, you can think of all
"var
[EMAIL PROTECTED] wrote:
> b is a string b = '(1,2,3,4)' to b = (1,2,3,4)
py> tuple(int(s) for s in '(1,2,3,4)'[1:-1].split(','))
(1, 2, 3, 4)
Or if you're feeling daring:
py> eval('(1,2,3,4)', dict(__builtins__=None))
(1, 2, 3, 4)
Python makes no guarantees about the security of this second o
[EMAIL PROTECTED] wrote:
> Pass it to eval:
>
eval('(1, 2, 3, 4, 5)')
> (1, 2, 3, 4, 5)
Just be sure you know where your strings come from. You wouldn't want
someone to pass you
"""__import__('os').system('rm -rf /')"""
and then send that to eval. =)
STeVe
--
http://mail.python.org/m
Duncan Booth wrote:
> Steven Bethard wrote:
>
>
>>Interestingly, I don't seem to be able to create a file object as a
>>class attribute in restricted mode:
>>
>>py> class C(object):
>>... def __init__(self):
>>... self.f = file(
Jeff Elkins wrote:
> I've like to use python to maintain a small addressbook which lives on a
> Sharp
> Zaurus. This list will never grow beyond 200 or so entries. I've installed
> pyxml.
If you're not committed to pyxml, you might consider using ElementTree:
http://effbot.org/zone/element-ind
Mac wrote:
> Is there a nice Python idiom for constructors which would expedite the
> following?
>
> class Foo:
> def __init__(self, a,b,c,d,...):
> self.a = a
> self.b = b
> self.c = c
> self.d = d
> ...
py> class Foo(object):
... def __init__(self, a, b, c, d):
...
Stian Søiland wrote:
> There are several ways to create a copy of a list:
[snip]
> a2 = list(a) # create a new list object out of any sequence
I'll just point out that FWIW, this is by far my favorite idiom of the
ones offered because it applies to pretty much all the builtin container
typ
Koncept wrote:
> #!/usr/bin/perl
>
> # Parse comma delimited lines and create a final frequency hash
> # Real example would read a file line by line
> my %dict = {};
> my @lines = ( "1,2,3,4,5", "2,3,4,5", "3,4,5", "4,5", "5" );
> foreach(@lines) { map( $dict{ $_ }++, split( "," ) ); }
> foreach(
John Machin wrote:
> freq_dict = {}
> ...
> if thing in freq_dict:
> freq_dict[thing] += 1
> else:
> freq_dict[thing] = 1
>
> or, less plainly,
>
> freq_dict[thing] = freq_dict.get(thing, 0) + 1
or
try:
freq_dict[thing] += 1
except KeyError:
freq_dict[thing] = 1
STeVe
--
htt
Christopher J. Bottaro wrote:
> I want to get the name of the function from within the function. Something
> like:
>
> def myFunc():
> print __myname__
>
myFunc()
> 'myFunc'
There's not a really good way to do this. Can you give some more detail
on what exactly you're trying to do here
Christopher J. Bottaro wrote:
> Basically I want to wrap every function in try/except automatically.
[snip]
> every function (err, method) is enclosed in the exact
> same try/except error handling code. Everytime I make a new function, I
> copy/paste that try/catch block.
Yes, has's suggestion is
Christopher J. Bottaro wrote:
> I haven't tried it yet, but this is what I would do with __call():
>
> function __call($name, $args) {
> $name .= 'IMPL';
> try { $this->$name($args); }
> except { # error handling; }
> }
>
> function funcA() {
> # do something
> }
>
> function funcBIMPL
Ilpo Nyyssönen wrote:
> How about this instead:
>
> with locking(mutex), opening(readfile) as input:
> ...
>
I don't like the ambiguity this proposal introduces. What is input
bound to? The return value of locking(mutex).__enter__() or the return
value of opening(readfile).__enter__()?
Peter Dembinski wrote:
>class A:
>def __init__(self, a, b, c, d):
>initial = {'a' : a, 'b' : b, 'c' : c, 'd' : d}
>for param in initial.keys():
>exec "self.%s = initial['%s']" % (param, param)
This is not a good use case for exec. Use setattr:
for param in initial
Andrew Dalke wrote:
> On Sat, 04 Jun 2005 10:43:48 -0600, Steven Bethard wrote:
>
>>Ilpo Nyyssönen wrote:
>>
>>>How about this instead:
>>>
>>>with locking(mutex), opening(readfile) as input:
>>>...
>
>>I don't like the amb
Peter Dembinski wrote:
> From the other side: what are the usual uses of 'exec'?
I have to say, I have yet to find a use for it.
My intuition is that the good use cases for 'exec' have something to do
with writing programs that allow users to interactively script the
program actions. But I've
Christopher J. Bottaro wrote:
> Kent Johnson wrote:
>>class C(object):
>>@in_try
>>def func_a(self):
>>print "func_a"
>>
>>@in_try
>>def func_b(self):
>>print "func_b"
>>raise Exception
>>
>>You could probably create a metaclass to apply the wrappers
Peter Dembinski wrote:
> AFAIK inc is builtin function. And builtin functions doesn't have to
> be real functions, they can be just aliases to Python's VM bytecodes
> or sets of bytecodes.
Wrong on both counts. ;)
py> inc
Traceback (most recent call last):
File "", line 1, in ?
NameError: nam
John J. Lee wrote:
> It seems nice to do this
>
> class Klass:
>
> def _makeLoudNoise(self, *blah):
> ...
>
> woof = _makeLoudNoise
Out of curiosity, why do you want to do this?
> 1. In derived classes, inheritance doesn't work right:
>
>
class A:
> ... def foo(s):print
Erik Max Francis wrote:
> For instance, for a chat network bot framework, a certain form of bot
> will look for any attribute in its instance that starts with verb_ and a
> command and execute it when it hears it spoken:
>
> def verb_hello(self, convo):
> "Respond to a greeting."
>
Nicolas Fleury wrote:
> I prefer the optional-indentation syntax. The reason is simple (see my
> discussion with Andrew), most of the time the indentation is useless,
> even if you don't have multiple with-statements. So in my day-to-day
> work, I would prefer to write:
>
> def getFirstLine(f
John J. Lee wrote:
> Steven Bethard <[EMAIL PROTECTED]> writes:
>>In Python 2.4:
>>
>>py> class A(object):
>>... def foo(self):
>>... print 'foo'
>>... bar = foo
>>...
>>py> import pickle
>>py> pick
Nicolas Fleury wrote:
> Since the current syntax would be there, the no-indentation syntax can
> be explained in terms of the indentation syntax:
>
> """
> To avoid over-indentation, a with-statement can avoid defining a new
> indentation block. In that case, the end of the with block is the en
bruno modulix wrote:
> Here's a somewhat more pythonic version:
>
> filelist = os.listdir(path)
> for filename in filelist:
> # I assume you want to remember what's the ext is
> ext = os.path.splitext(filename)
Check the docs[1]. This should probably read:
_, ext = os.path.splitext
Christopher J. Bottaro wrote:
> Steven Bethard wrote:
>>... def _impl_wrapper(self, func):
>>... def wrapper(*args, **kwargs):
>>... try:
>>... return func(*args, **kwargs)
>>... except:
>>..
venkata subramanian wrote:
> If you have any doubts,
> try to remeber this when creating tuples,
>
> if a tuple is to have 0 elements,
> then it must be given as a=()
> in other words, the ( and the ) are essential
>
> if it has one element,
> then a comma after that element is essential
> a=1,
Grops wrote:
> Hi All,
>
> I've been lurking the list for a month and this is my first post. I am
> hoping this post is appropriate here, otherwise, my apologies.
>
> I'm somewhat new to Python, (I'm reading all the tutorials I can find,
> and have read through Andre Lessa's Developers Handb
Andrew wrote:
> Newb here... For one of my programs I want to initialize a variable for
> each letter of the alphabet. For example, a,b,c = 0,0,0.
Why do you want to do this? This looks like a particularly bad idea to
me. Can't you just use a dict of the "variables", e.g.:
py> d = dict.fromkeys
John Reese wrote:
> I now do:
>
> if isinstance(x, list):
>
> It is my understanding that this is what people do nowadays.
I wouldn't go that far. I don't have an isinstance check for lists
anywhere in my entire codebase. Why do you think you need to check to
see if something is of type
John Reese wrote:
> I now do:
> if isinstance(x, list):
[snip]
>
> I'm not saying I do it a lot, but sometimes it's useful to write
> methods with interfaces like, well, isinstance's, whose second argument
> can be a single type object or a sequence of class objects.
Personally, I'd just write t
Bjoern Schliessmann wrote:
> Eduardo "EdCrypt" O. Padoan wrote:
>
>> No. Quoting PEP 8:
>> Functions:
>> """
>> mixedCase is allowed only in contexts where that's already the
>> prevailing style (e.g. threading.py), to retain backwards
>> compatibility.
>> """
>> Methods and instances:
Sergey Dorofeev wrote:
> Please help, is there way to use sub-expressions in lambda?
> For example, if I want to calculate sin(x^2)+cos(x^2) I must code:
> lambda x: sin(x*x)+cos(x*x)
[and later]
> This code is needed once in a map,
Peter Otten wrote:
> Perhaps you like [sin(y)+cos(y) for y in (x
Wildemar Wildenburger wrote:
> I thought: I'll just write a decorator that lets me react to method
> calls easily (the ever so popular observer-pattern). I've looked at some
> recepies, but I just don't get them (I'm feeling kinda dumb today, sorry).
[snip]
> This is more complicated than expecte
David Wahler wrote:
> On Jun 2, 12:27 am, Steven Bethard <[EMAIL PROTECTED]> wrote:
>> I think you want to define __get__ on your Observable class so that it
>> can do the right thing when the method is bound to the instance:
[snip]
> Is this desired behavior?
>
Wildemar Wildenburger wrote:
class Observable(object):
> ... def __init__(self, func, instance=None, observers=None):
> ... self.func = func
> ... self.instance = instance
> ... self.observers = observers or []
Unless you also changed code in __get__, this means yo
Horace Enea wrote:
> My example wasn't very good. Here's another try:
>
> def foo():
>yield 1
>yield 2
>yield 3
>
> f = foo()
> f.next()
> 1
>
> g=copy(f) # copy the generator after an iteration
>
> f.next()
> 2
> f.next()
> 3
>
> g.next()
> 2
>
> I want to copy the generat
George Sakkis wrote:
> On Jun 11, 8:27 am, Frank Millman <[EMAIL PROTECTED]> wrote:
>> On Jun 11, 1:56 pm, Steven D'Aprano
>>
>> <[EMAIL PROTECTED]> wrote:
>>
>>> Unless you have thousands and thousands of instances, __slots__ is almost
>>> certainly not the answer. __slots__ is an optimization to
Ed Leafe wrote:
> I have a simple module that reads in values from disk when imported,
> and stores them in attributes, allowing for code like:
>
> >>> import moduleFoo
> >>> print moduleFoo.someSetting
> 'the value'
>
> What I'd like to do is have a more property-like behavior, so tha
pelon wrote:
> On Jun 5, 6:27 am, [EMAIL PROTECTED] wrote:
>> On 5 Jun., 13:12, Peter Otten <[EMAIL PROTECTED]> wrote:
>>
>>> or like this:
>> "%s %.s %s" % ("first", "second", "third")
>>> 'first third'
>> Hey, that's great, thanks Peter!
>>
>> Tom
>
> Why not be consistent with other aspect
Evan Klitzke wrote:
> What frameworks are there available for doing pattern classification?
> I'm generally interested in the problem of mapping some sort of input
> to one or more categories. For example, I want to be able to solve
> problems like taking text and applying one or more tags to it li
Rob Wolfe wrote:
> Steve Howell wrote:
>> Hi, I'm offering a challenge to extend the following
>> page by one good example:
>>
>> http://wiki.python.org/moin/SimplePrograms
>
> What about simple HTML parsing? As a matter of fact this is not
> language concept, but shows the power of Python standar
Rob Wolfe wrote:
> Steven Bethard <[EMAIL PROTECTED]> writes:
>> I'd hate to steer a potential new Python developer to a clumsier
>
> "clumsier"???
> Try to parse this with your program:
>
> page2 = '''
> URLs
>
>
Steven Bethard wrote:
> Rob Wolfe wrote:
>> Steven Bethard <[EMAIL PROTECTED]> writes:
>>> I'd hate to steer a potential new Python developer to a clumsier
>>
>> "clumsier"???
>> Try to parse this with your program:
>>
>> pa
Steve Howell wrote:
> --- George Sakkis <[EMAIL PROTECTED]> wrote:
>> from itertools import count, ifilter
>> def sieve():
>> seq = count(2)
>> while True:
>> p = seq.next()
>> seq = ifilter(p.__rmod__, seq)
>> yield p
[snip]
> Is there a way to broaden the problem s
Steve Howell wrote:
> --- Steven Bethard <[EMAIL PROTECTED]> wrote:
>> How about we just comment it better?
>>
>> import itertools
>>
>> def iter_primes():
>> # an iterator of all numbers between 2 and +infinity
>> numbers = itertools.c
Stefan Behnel wrote:
> Steven Bethard wrote:
>> If you want to parse invalid HTML, I strongly encourage you to look into
>> BeautifulSoup. Here's the updated code:
>>
>> import ElementSoup # http://effbot.org/zone/element-soup.htm
>> import cStrin
Rob Wolfe wrote:
> Steve Howell wrote:
>
>> I suggested earlier that maybe we post multiple
>> solutions. That makes me a little nervous, to the
>> extent that it shows that the Python community has a
>> hard time coming to consensus on tools sometimes.
>
> We agree that BeautifulSoup is the bes
Rob Wolfe wrote:
> Steven Bethard <[EMAIL PROTECTED]> writes:
>
>>> I vote for example with ElementTree (without xpath)
>>> with a mention of using ElementSoup for invalid HTML.
>> Sounds good to me. Maybe something like::
>>
>> import
James Turk wrote:
> Hi,
>
> I have a situation where I have some class members that should only be
> done once. Essentially my problem looks like this:
>
> class Base(object):
> dataset = None
>
> def __init__(self, param):
> if type(self).dataset is None:
> # code t
1101 - 1200 of 1538 matches
Mail list logo