Erik Max Francis wrote:
[EMAIL PROTECTED] wrote:
UnboundLocalError: local variable 't2' referenced before assignment
...
t2=""
def Proc(text): # "text" is some random text or use OrigText
...
The fix is to declare t2 global at the top of Proc:
def Proc(text):
global t2
.
gargonx wrote:
This works much better, aside from the fact that it does'nt work for
the std dictionary. the letters used from here stay the same. that
dictionary looks like this:
std = {
"A":"Z",
"Z":"A",
"B":"Y",
"Y":"B",
"C":"X",
"X":"C",
"E":"V",
"V":"E",
"H":
Stefan Behnel wrote:
Is there a way to change __call__ after class creation?
Check out this thread on the topic:
http://mail.python.org/pipermail/python-list/2004-January/203142.html
Basically, the answer is no -- at least not on a per-instance basis.
You can try something like:
py> class Test(ob
gargonx wrote:
yes the items in std are always single to single, and ext single to
double. basicly the ext are refernce to the std itmes. the second
character in ext is a number depending on how far it is from the item
in std. this is just a simple encoding program.
If your keys are always single c
Roose wrote:
I need this a lot: a one line way to do a n-ary and or 'or'.
e.g.,
result = True
for x in L:
if not boolean_function(x):
result = False
or
reduce(operator.__and__, [boolean_function(x) for x in L)
Can you use itertools?
py> def boolfn(x):
... print "boolfn: %r" % x
... re
gargonx wrote:
Well that seems to work like a champion, but my prob then would be; how
do i get the double character values of ext to turn back to the single
character keys. The reversed (decode if you will).
It's unclear what you want to do here. If you have say:
ext = dict(aa='A', ab='B', bb='C'
Brian Beck wrote:
Roose wrote:
I need this a lot: a one line way to do a n-ary and or 'or'.
Here's a one-liner for the n-ary and:
bool(min(bool(x) for x in L))
py> bool(min(bool(x) for x in [1, 1, 1, 0]))
False
py> bool(min(bool(x) for x in [1, 1, 1, 1]))
True
py> bool(min(bool(x) for x in ['a', ''
gargonx wrote:
let's take the word "dogs"
ext = dict("D":"V1", "O":"M1", "G":"S1")
std = dict("S":"H")
encode("DOGS") # proc()
we'll get: "V1M1S1H"
let's say i want to do just the opposite
word: "V1M1S1H"
decode("V1M1S1H")
#how do i decode "V1" to "D", how do i keep the "V1" together?
an
vegetax wrote:
How can i make my custom class an element of a set?
class Cfile:
def __init__(s,path): s.path = path
def __eq__(s,other):
print 'inside equals'
return not os.popen('cmp %s %s' % (s.path,other.path)).read()
def __hashcode__(s): return s.path.__hashcode__()
the idea is that
Grant Edwards wrote:
Is it true that a datetime object can convert itself into a
string, but not the other way around? IOW, there's no simple
way to take the output from str(d) and turn it back into d?
I assume this is true because there is not one standard format for a
date-time string. But I d
F. Petitjean wrote:
Le Sun, 13 Feb 2005 13:19:03 -0500, Hans Nowak a écrit :
Note that it works just fine if you don't use a new-style class:
class Test:
... def __init__(self):
... self.__call__ = self.foobar
... def foobar(self, *args, **kwargs):
... print "Called with:",
[EMAIL PROTECTED] wrote:
class baseClass(object):
__Something = "Dumb!"
def getSomething( self ):
return self.__Something
class subClass(baseClass):
def setSomething( self , aSomething ):
self.__Something = aSomething
anObject = subClass()
anO
Paul Rubin wrote:
[EMAIL PROTECTED] writes:
How do i handle this piece of code in python:
# define vZero 15
# define vOne 20
unsigned int vTable[Zero][One]
if(vGroup[vZero][vOne] == 0)
{
vGroup[vZero][vOne]--
.
.
}
Simplest might be with a dictionary:
vGroup =
Antoon Pardon wrote:
Op 2005-02-11, Steven Bethard schreef <[EMAIL PROTECTED]>:
George Sakkis wrote:
"Steven Bethard" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
Is there a good way to determine if an object is a numeric type?
In your example, what does you
Thomas Lotze wrote:
another question: What's the most efficient way of copying data between
two file-like objects?
f1.write(f2.read()) doesn't seem to me as efficient as it might be, as a
string containing all the contents of f2 will be created and thrown away.
You could try f1.writelines(f2).
Stev
Sean wrote:
Sean wrote:
Then I would have a script that uses the
print_this function defined in the module
without using the module name in the call.
from module_name import print_this
or, even:
from module_name import print_this as other_nice_name
So what if I have a whole bunch of functions - say
Felix Wiemann wrote:
Sometimes (but not always) the __new__ method of one of my classes
returns an *existing* instance of the class. However, when it does
that, the __init__ method of the existing instance is called
nonetheless, so that the instance is initialized a second time.
[snip]
How can I p
Sean wrote:
from module_name import print_this
or, even:
from module_name import print_this as other_nice_name
So what if I have a whole bunch of functions - say 25 of them.
Is there a way to do this without naming each function?
Yes [1], but it's basically deprecated and you shouldn't use it. Co
Rory Campbell-Lange wrote:
Hi. I'm just starting to use python.
I am anxious about how best to set and access items one level down in a
data structure if I am using __setitem__ and __getitem__.
At the moment I can do
for a data structure Data:
object.Data = { 'one' : [1, 2, {}, 4],
Felix Wiemann wrote:
> Steven Bethard wrote:
>> http://www.python.org/2.2.3/descrintro.html#__new__
>
[snip]
>
> I'm just seeing that the web page says:
>
> | If you return an existing object, the constructor call will still
> | call its __init__ method. If you
Aahz wrote:
In article <[EMAIL PROTECTED]>,
Steven Bethard <[EMAIL PROTECTED]> wrote:
Yeah, I saw the same thing in playing around with this. Don't know
what to make of it. I wonder if we should file a documentation bug? I
can't find __new__ explained anywhere in the La
Fredrik Lundh wrote:
Steven Bethard wrote:
Actually no, floats don't meet this behaviour or more specifically
floats don't guarantee this behaviour. It depends of course on
your implementation of f, but it is possible with floats to keep
incrementing and never reach a maximum.
My code
Colin J. Williams wrote:
This prompts a similar query. __new__ appears to be intended for
immutable objects but it seems to be called as part of constructor
process for all instances.
That's because Python has no builtin way of determining whether or not a
given type is immutable. If you wante
alex wrote:
So how can I test if a variable 'a' is either a single character string
or a list?
py> def test(x):
... return (isinstance(x, list) or
... isinstance(x, basestring) and len(x) == 1)
...
py> test('a')
True
py> test('ab')
False
py> test([])
True
py> test(['a', 'b'])
True
B
Leo Breebaart wrote:
I'm not complaining as such -- sep.join(str(i) for i in seq) is
not *that* ugly, but what annoys me is that I don't understand
*why* this was never changed.
py> chars = [u'ä', u'å']
py> ', '.join(chars)
u'\xe4, \xe5'
py> ', '.join(str(c) for c in chars)
Traceback (most recent c
Michael Hartl wrote:
I use a function isListLike in cases such as this one:
# def isListLike(L):
# """Return True if L is list-like, False otherwise."""
# try:
# L + []
# return True
# except:
# return False
Then you can use a standard if-else construct:
# if isL
alex wrote:
I am thinking of something like this:
def __init__(self, par1, par2):
self.init(par1, par2);
def __init__(self, par1):
self.init(par1, None)
def init(self, par1, par2):
...
...
So if the call is with one parameter only the second class is executed
(calling the 'i
[EMAIL PROTECTED] wrote:
I was wondering if the following two "if" statements compile down to
the same bytecode for a standard Dictionary type:
m = {"foo": 1, "blah": 2}
if "foo" in m:
print "sweet"
if m.has_key("foo"):
print "dude"
To answer the question you actually asked, you can use dis.dis
kowboy wrote:
I posted too quickly. A little performance testing told me that has_key
is somewhat slower than "in". I used a large number of string keys in
my test.
See my other post, but the reason has_key is slower is almost certainly
that it has to do a LOAD_ATTR:
$ python -m timeit -s "m = di
Rory Campbell-Lange wrote:
Hi Steve
I've been playing around with your two suggestions.
The Record class is an elegant solution. It doesn't however help in the
case where the class has the following general data structure (something
I should have stated originally):
class.config1 = param
So, I have a list of lists, where the items in each sublist are of
basically the same form. It looks something like:
py> data = [[('a', 0),
... ('b', 1),
... ('c', 2)],
...
... [('d', 2),
... ('e', 0)],
...
... [('f', 0),
... ('g', 2),
...
Michael Spencer wrote:
Steven Bethard wrote:
So, I have a list of lists, where the items in each sublist are of
basically the same form. It looks something like:
...
Can anyone see a simpler way of doing this?
Steve
You just make these up to keep us amused, don't you? ;-)
Heh heh. I
John M. Gabriele wrote:
1. Are all of my class's methods supposed to take 'self' as their
first arg?
If by "class's methods" you mean methods on which you called
classmethod, then no, they shouldn't take a 'self' parameter, they
should take a 'cls' parameter because the first argument to the func
John wrote:
Steven Bethard wrote:
John M. Gabriele wrote:
class C(object):
@classmethod
def f(cls, *args):
# do stuff
Sorry -- I'm not as far along as you suspect. :) I've
never yet seen this "@classmethod" syntax. I'm supposing that
it's part of th
[EMAIL PROTECTED] wrote:
1) Is there any advantage to use the
y = a.keys()
for z in y:
looping technique rather than the
for x in a:
looping technique?
2) What are the tradeoffs for using each of the techniques?
Calling dict.keys creates a list in memory of the keys to the dict.
Using the dict dir
Grant Edwards wrote:
Here's another choice, that's sometimes handy:
d = {1:'one',2:'two',3:'three'}
for k,v in d.items():
print k,v
1 one
2 two
3 three
I wouldn't recommend this for large dictionaries.
Yes, for large dictionaries, you should use:
for k, v in d.iteritems():
print k,
Michael Spencer wrote:
Christos TZOTZIOY Georgiou wrote:
On Sat, 12 Feb 2005 16:01:26 -0800, rumours say that Michael Spencer
<[EMAIL PROTECTED]> might have written:
OK - then my entry is:
assert obj+1 >= 1
:-)
So -1 is not a number.
At least not a legal one for Steven's function as I understoo
Grant Edwards wrote:
I want to subclass an IMAP connection so that most of the
methods raise an exception if the returned status isn't 'OK'.
This works, but there's got to be a way to do it that doesn't
involve so much duplication:
class MyImap4_ssl(imaplib.IMAP4_SSL):
def login(*args):
Grant Edwards wrote:
I want to subclass an IMAP connection so that most of the
methods raise an exception if the returned status isn't 'OK'.
This works, but there's got to be a way to do it that doesn't
involve so much duplication:
class MyImap4_ssl(imaplib.IMAP4_SSL):
def login(*args):
raver2046 wrote:
How to have a global var in python ?
You can, but you probably don't want to. What's your use case? Example
code and what you'd like it to do would be helpful.
STeVe
--
http://mail.python.org/mailman/listinfo/python-list
Duncan Booth wrote:
Diez B. Roggisch wrote:
Duncan Booth wrote:
Bound methods get created whenever you reference a method of an
instance.
That did escape me so far - interesting. Why is it that way? I'd
expect that creating a bound method from the class and then storing it
in the objects dictionary
Paddy McCarthy wrote:
x=lambda : A < B
y=lambda : C+6 >= 7
[snip]
Z=lambda : (A=7)
See "Inappropriate use of Lambda" in
http://www.python.org/moin/DubiousPython
Perhaps your real example is different, but notice that
= lambda :
is equivalent to
def ():
return
except that the latt
I have two classes that implement the same interface, e.g. something like:
class C(object):
def foo(self):
"""Foo things"""
...
def bar(self):
"""Bar things"""
...
def baz(self):
"""Baz things in a C manner"""
...
class D(object):
def
I have a list of dictionaries. Each dictionary holds counts of various
'words', e.g.:
py> countdicts = [
... dict(a=9, b=9, c=9),
... dict(a=8, b=7),
... dict(a=4, b=5, c=12)]
I need to select dicts with the constraint that the number of each
'word' totalled over all selected dicts
John Machin wrote:
Steven Bethard wrote:
I have a list of dictionaries. Each dictionary holds counts of
various 'words'...
...
Basically, I use a greedy approach -- adding a dict each time if I
can.
...
This leads to some suboptimal solutions given that, while the total
counts must
Brian Beck wrote:
Steven Bethard wrote:
I have a list of dictionaries. Each dictionary holds counts of
various 'words', e.g.:
py> countdicts = [
... dict(a=9, b=9, c=9),
... dict(a=8, b=7),
... dict(a=4, b=5, c=12)]
I need to select dicts with the constraint that the n
Carl Banks wrote:
You may not be aware of it, but what you're trying to do is called
"currying"; you might want to search the Python Cookbook for recipes on
it.
Or look for "partial function application" which has been argued to be
the correct term for this use... Also see PEP 309:
http://www.py
gargonx wrote:
I think there's a problem with the code:
py> decode_replacements.update([(std[key], key) for key in std])
py> decode_replacements.update([(ext[key], key) for key in ext])
when i run this i get an error:
AttributeError: keys
I can't get that figured out
Can you show the part of you
rbt wrote:
Jeff Shannon wrote:
You could probably also do this as a factory function, rather than as
a class (also untested!):
def Wrapper(func):
def wrapped(self, *args, **kwargs):
s, r = func(self, *args, **kwargs)
if s != 'OK':
raise NotOK((s,r))
return
Terry Hancock wrote:
> But you probably shouldn't do that. You should probably just test to
> see if the object is iterable --- does it have an __iter__ method?
>
> Which might look like this:
>
> if hasattr(a, '__iter__'):
> print "'a' quacks like a duck"
Martin Miller top-posted:
I don't beli
Erik Max Francis wrote:
Roman Suzi wrote:
I think that if any object (from standard library at least) doesn't
support
iteration, it should clearly state so.
My guess is that 'for' causes the use of 'm[0]', which is (rightfully)
an error...
Can this behaviour of email be considered a bug?
Is the
gargonx wrote:
Even if i put it in exactly the way you did:
import re
charmatcher = re.compile(r' [A-Z] [\d]?')
ext = dict(D="V1", O="M1", G="S1")
std = dict(S="H")
decode_replacements ={}
decode_replacements.update([(std[key], key) for key in std])
Traceback (most recent call last):
File "", lin
snacktime wrote:
I need to convert a generator expression to a list expression so it
will work under python 2.3.
I rewrote this:
for c in range(128):
even_odd = (sum(bool(c & 1<
As this:
for c in range(128):
bo = [bool(c & 1<
Seems to work, is there a better way to do this?
Well, if you were ha
Dennis Lee Bieber wrote:
On 20 Feb 2005 20:12:50 -0800, "gargonx" <[EMAIL PROTECTED]> declaimed
the following in comp.lang.python:
decode_replacements.update([(std[key], key) for key in std])
Traceback (most recent call last):
File "", line 1, in ?
AttributeError: keys
Did you read the reference
> Steven Bethard wrote:
>>
>>Right. str and unicode objects support iteration through the old
>>__getitem__ protocol, not the __iter__ protocol. If you want to use
>>something as an iterable, just use it and catch the exception:
>>
>>try:
>> itr
Antoon Pardon wrote:
So and if I have code like this:
f = lamda x:x
for g in some_iter:
f = compose(g,f)
Do you still think that one should use a named function in this case?
Yes. If you really don't like taking two lines, Python still allows you
to write this as:
def f(x): return x
Antoon Pardon wrote:
def F():
... l = []
... def pop():
... return l.pop()
... def push(e):
... l.append(e)
... return pop, push
...
Just a side note to point out that another way of writing this is:
py> def F():
... l = []
... return l.pop, l.append
...
You'll get the same
Martin Miller broke the order of reading again by top-posting:
However, to handle the more general problem of allow *any* argument to
be either a single item or a list seems to require a combination of
both EAPF and LBYL. This is the best solution I've been able to come up
with so far:
def asList(a
markscottwright wrote:
Just for the hell of it, I've been going through the old Scheme-based
textbook "Structure and Interpretation of Computer Programs" and seeing
what I can and can't do with python. I'm trying to create a function
that returns the function (not the results of the function, but
Steve M wrote:
I guess I explained my problem incorrectly. Let me try again.
tuple = ("fred", "barney", "foo")
I know that foo is an element of tuple, but what I need to know is what
the index of foo is, tuple[?].
Larry Bates's solution is probably the best way to go here:
py> t = ("fred", "barney"
Michael Hartl wrote:
I actually find it strange that tuples don't have an index function,
since finding the index doesn't involve any mutation. Anyone know why
Python doesn't allow a statement like t.index('foo')?
Tuples aren't really intended for this kind of use. See:
http://www.python.org/doc/
[EMAIL PROTECTED] wrote:
I was interested in playing around with Decimal and
subclassing it. For example, if I wanted a special
class to permit floats to be automatically converted
to strings.
from decimal import Decimal
class MyDecimal(Decimal):
def __init__(self, value):
Steve M wrote:
I'm actually doing this as part of an exercise from a book. What the program
is supposed to do is be a word guessing game. The program automaticly
randomly selects a word from a tuple. You then have the oportunity to ask
for a hint. I created another tuple of hints, where the order o
Igorati wrote:
list = [ ]
a = 1
print 'Enter numbers to add to the list. (Enter 0 to quit.)'
while a != 0 :
a = input('Number? ')
list.append(a)
zero = list.index(0)
del list[zero]
list.sort()
A simpler approach is to use the second form of the builtin iter
function which takes a callab
Fuzzyman wrote:
Iterators are available in python 2.2
class enumerate:
def __init__(self, inlist):
self.inlist = inlist
self.index = 0
def next(self):
if self.index >= len(self.inlist): raise StopIteration
thisone = self.inlist[self.index]
self.index
Scott David Daniels wrote:
or even (if you can't be bothered to look up when features happened):
try:
test = enumerate
except NameError:
def enumerate(iterable):
...
try:
test = sorted
except NameError:
def sorted(iterable, cmp=None, key=N
Mike Brown wrote:
class C:
... def __str__(self):
... return 'asdf\xff'
...
o = C()
unicode(o, errors='replace')
Traceback (most recent call last):
File "", line 1, in ?
TypeError: coercing to Unicode: need string or buffer, instance found
[snip]
What am I doing wrong? Is this a bug in Pyt
Kent Johnson wrote:
Steven Bethard wrote:
No, this is documented behavior[1]:
"""
unicode([object[, encoding [, errors]]])
...
For objects which provide a __unicode__() method, it will call
this method without arguments to create a Unicode string. For all
other objects, t
John M. Gabriele wrote:
class Vector3d:
def __init__(self):
...
def __init__(self, x_from, y_from, z_from, x_to, y_to, z_to):
...
def __init__(self, point_from, point_to):
...
def __init__(self, same_as_this_vec):
...
My prefer
Nick Coghlan wrote:
Time for another random syntax idea. . .
So, I was tinkering in the interactive interpreter, and came up with the
following one-size-fits-most default argument hack:
[snip]
But consider a syntax like the following:
def f():
use x, y from:
y = x + 1 # [
[EMAIL PROTECTED] wrote:
I was starting to write a dictionary to map operator strings to their
equivalent special methods such as:
{
'+' : 'add',
'&' : 'and_'
}
The idea is to build a simple interactive calculator.
and was wondering if there is already something like this builtin?
Or is there a
Tom Willis wrote:
Question on decorators in general. Can you parameterize those?
If I wanted to something and after the function call for example, I
would expect something like this would work.
def prepostdecorator(function,pre,post):
def wrapper(*args,**kwargs):
pre()
result =
I wrote:
Tom Willis wrote:
Question on decorators in general. Can you parameterize those?
[snip]
If you want to call prepostdecorator with 2 arguments, you need to write
it this way. A few options:
Sorry, I forgot my favorite one:
(4) Use a class and functional.partial:
py> class prepostdecorato
Tom Willis wrote:
Question on decorators in general. Can you parameterize those?
Wow thanks for the explanation!! Some of it is a bit mind bending to
me at the moment , but I'm going to mess with it a bit.
Oh, I also should have mentioned that there's some explanation at:
http://www.python.org/peps
Samantha wrote:
input = open(r'C:\Documents and Settings\Owner\Desktop\somefile.html','r')
L = input.readlines()
input.close
output = open(r'C:\Documents and
Settings\Owner\Desktop\somefile_test.html','w')
for t in range(len(L)):
output.writelines(L[t])
output.close
I think you want to do [1]:
in
Tom Willis wrote:
Getting back to your recipe. Through the explanation of how to get
parameters in there, I see how it is possible to get a logger in
there.
Cool. But credit where it's due, the recipe's Scott David Daniels's. =)
STeVe
--
http://mail.python.org/mailman/listinfo/python-list
Nick Coghlan wrote:
Anyway, if others agree that the ability to execute a suite at def
exeuction time to preinitialise a function's locals without resorting to
bytecode hacks is worth having, finding a decent syntax is the next
trick :)
I'm not certain how many use cases really require a full su
Anthony Liu wrote:
I want to use the set function like
mylist = ['a', 'b', 'b', 'd', 'e', 'a']
myset = set (mylist)
But I don't know what to import, I tried sys, sets,
they don't work.
If you're using Python 2.4, they're builtin. If you're using Python
2.3, you'll probably want to do som
Nick Coghlan wrote:
Jimmy Retzlaff wrote:
The approach you are considering may be easier than you think:
filter(str.isalpha, 'The Beatles - help - 03 - Ticket to ride')
'TheBeatleshelpTickettoride'
Hmm, I think this is a case where filter is significantly clearer than
the equivalent list comprehen
Stan Cook wrote:
Does anyone know how I can access and read data from a dbase (.dbf) file?
I know nothing about them, but Raymond Hettinger recently posted a
recipe that I believe should help:
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/362715
STeVe
--
http://mail.python.org/mailman/l
[EMAIL PROTECTED] wrote:
Since Python does not have declarations, I wonder if people think it is
good to name function arguments according to the type of data structure
expected, with names like "xlist" or "xdict".
In general, I find that naming collections for their contents is much
more useful t
Brent W. Hughes wrote:
I copied and pasted some text into my Python code and then Pythowin put a
red squiggley underline under the two tabs at the beginning of the line.
What does that mean? I've tried various things including deleting the white
space in front of the line and reinserting the ta
Sean McIlroy wrote:
f = lambda x: (x[0]=='@' and x[6:] + '.0') or (x=='/' and x + '\n') or
x
See "Inappropriate use of Lambda" in
http://www.python.org/moin/DubiousPython.
You're creating a named function, so there's no reason to use the
anonymous function syntax. Try:
def f(x):
return (x[
Antoon Pardon wrote:
Can anyone explain why descriptors only work when they are an attribute
to an object or class. I think a lot of interesting things one can
do with descriptors would be just as interesting if the object stood
on itself instead of being an attribute to an other object.
Not sure
Sean McIlroy wrote:
Alright, now it's too much. It's not enough that you're eliminating it
from the language, you have to stigmatize the lambda as well.
You misunderstand me. I don't have a problem with lambda when it's
appropriate, e.g. when used as an expression, where a statement is
forbidden
I tried to Google for past discussion on this topic, but without much
luck. If this has been discussed before, I'd be grateful for a pointer.
Does anyone know why you can't assign a custom mapping type to an
object's __dict__?
py> class M(object):
... def __getitem__(self, key):
...
Daniel Cer wrote:
Why not just inherit from dict? That seems to work.
Because that isn't the question - Steven knows how to make it work, what
he's
curious about is why things are the way they are :)
Sorry, didn't mean to be a pest :)
I guess I assumed Steve already knew that he could inherit from
Gary Ruben wrote:
OK, I've managed to get this to work with Rainer's method, but I
realised it is not the best way to do it, since the methods are being
added by the constructor, i.e. they are instance methods. This means
that every time a foo object is created, a whole lot of code is being
run
Steve Holden wrote:
Steven Bethard wrote:
Antoon Pardon wrote:
Can anyone explain why descriptors only work when they are an attribute
to an object or class. I think a lot of interesting things one can
do with descriptors would be just as interesting if the object stood
on itself instead of being
Nick Coghlan wrote:
> Hmm, it might be nice if there was a UserList.ListMixin that was the
> counterpart to UserDict.DictMixin
I've thought this occasionally too. One of the tricky issues though is
that often you'd like to define __getitem__ for single items and have
ListMixin add the code for s
David S. wrote:
I am looking for a way to implement the same simple validation on many
instance attributes and I thought descriptors
(http://users.rcn.com/python/download/Descriptor.htm) looked like the
right tool.
But I am confused by their behavior on instance of my class.
I can only get th
Mike C. Fletcher wrote:
... it nicely encapsulates the learning of "generators" so that
when you see yield up front you know something generatish is going on.
+1 for "generatish" as VOTW (Vocabulation of the Week). =)
STeVe
--
http://mail.python.org/mailman/listinfo/python-list
David S. wrote:
Steven Bethard gmail.com> writes:
Looks like you're trying to reinvent the property descriptor. Try using
the builtin property instead:
py> def getchar(self):
... if not hasattr(self, '_char'):
... self._char = None
... return self._char
...
Michael Spencer wrote:
Anthony Liu wrote:
I cannot figure out how to specify a list of a
particular size.
For example, I want to construct a list of size 10,
how do I do this?
A list does not have a fixed size (as you probably know)
But you can initialize it with 10 somethings
>
>>> [None]*10
[N
Anthony Liu wrote:
Yes, that's helpful. Thanks a lot.
But what if I wanna construct an array of arrays like
we do in C++ or Java:
myArray [][]
Basically, I want to do the following in Python:
myArray[0][1] = list1
myArray[1][2] = list2
myArray[2][3] = list3
How to do this, gurus?
You might be able
mx2k wrote:
Hello @ all,
we have written a small program (code below) for our own
in-developement rpg system, which is getting values for 4
RPG-Characters and doing some calculations with it.
now we're trying hard to find out how to get it working with 'n'
Characters, so you will be asked to enter
Douglas Alan wrote:
In this case, that is great, since I'd much prefer
yield *gen1(arg)
than
yield_all gen1(arg)
I'm guessing the * syntax is pretty unlikely to win Guido's approval.
There have been a number of requests[1][2][3] for syntax like:
x, y, *rest = iterable
for unpacking a va
Douglas Alan wrote:
Steven Bethard <[EMAIL PROTECTED]> writes:
I'm guessing the * syntax is pretty unlikely to win Guido's
approval. There have been a number of requests[1][2][3] for syntax
like:
x, y, *rest = iterable
Oh, it is so wrong that Guido objects to the above. Py
Nick Coghlan wrote:
Steven Bethard wrote:
The problem with inheriting from dict is that you then need to
override *all* the methods in the dict object, because they all go
straight to Python's dict'c C code functions. So just because you
redefine __getitem__ doesn't mean you d
mx2k wrote:
indeed, we're it is our combat timeline. we enter the initiative and
reaction time, it should find out the lowest then the next, then the
'n'th etc. and shouw it on the screen like
Next action 'Character Name1' at tick No 'Initiative1
2nd action 'Character Name2' at tick No 'Initia
401 - 500 of 1538 matches
Mail list logo