arg = Base(arg)
> # Do something with arg.
>
> is a simple and explicit solution of the problem.
What if someone wants to call bar with an argument that mimics a Base
but isn't a subclass? Your function would try to convert it to an
actual Base.
Something to think about
e you
or argue with you. I'm just telling you why it's like that.
I will also tell you that claims like "it's doesn't use good OOP
principles" or "C++ does it that way" carry almost no credit. How C++
does something is a suggestion, nothing more.
Carl Banks
--
http://mail.python.org/mailman/listinfo/python-list
why I said the questionable thing is not so much related with dynamic
> programming or not.
Because it makes dynamicism harder to do.
Like I said, Python's goal isn't simply to make dynamicism possible,
it's to make it easy.
"foo.new_attr = 'blah'" is eas
an ASCII
nightmare. Still, it hasn't stopped binary APIs in other kinds of
libraries.
Carl Banks
--
http://mail.python.org/mailman/listinfo/python-list
On Jun 27, 4:35 pm, Ben Finney wrote:
> Carl Banks writes:
> > Seriously, almost every other kind of library uses a binary API.
>
> Except for the huge number that deal with text protocols or languages.
No, not really. Almost all types of libraries have binary APIs,
including
On Jun 27, 3:20 pm, Roy Smith wrote:
> In article
> <14e44c9c-04d9-452d-b544-498adfaf7...@d8g2000yqf.googlegroups.com>,
> Carl Banks wrote:
>
>
>
> > Seriously, almost every other kind of library uses a binary API. What
> > makes databases so special that
te cruft, and can devote that time to fixing bugs and
maintaining useful stuff instead.
So they will benefit even if they don't actually use new features.
Carl Banks
--
http://mail.python.org/mailman/listinfo/python-list
On Jun 27, 8:19 pm, Owen Jacobson wrote:
> On 2010-06-27 22:51:59 -0400, Carl Banks said:
> > On Jun 27, 3:20 pm, Roy Smith wrote:
> >> In article
> >> <14e44c9c-04d9-452d-b544-498adfaf7...@d8g2000yqf.googlegroups.com>,
> >> Carl Banks wrote:
>
ssive language like Python. Not everything is a simple
inner joins. I defer to the community then, as my knowledge of
advanced SQL is minimal.
We'll just have accept the risk of injection attacks as a trade off,
and try to educate people to use placeholders when writing SQL.
Carl Banks
--
ht
On Jun 27, 8:33 pm, Ben Finney wrote:
> Carl Banks writes:
> > I'm disappointed, usually when you sit on your reinforced soapbox and
> > pretense the air of infinite expertise you at least use reasonable
> > logic.
>
> Kindly stop inventing straw men to at
On Jun 27, 9:02 pm, Stephen Hansen wrote:
> On 6/27/10 8:48 PM, Carl Banks wrote:
>
> > I don't know the exact details of all of these, but I'm going to opine
> > that at least some of these are easily expressible with a function
> > call API. Perhaps more
lingly stupid thing about the
standard C library, which has lots of mind-boggling stupidity.
Whenever I do an audit of someone's C code the first thing I do is
search for strncpy and see if they set the nth character to 0. (They
usually didn't.)
Carl Banks
--
http://mail.python.org/mailman/listinfo/python-list
lemented by inherence.
> >> Most object oriented programming languages starting with Smalltalk
> >> have allowed adding attributes (addInstVarName) to classes at runtime.
>
> > Thanks, I have to admit that I know nothing about Smalltalk.
>
> Then you really don't kn
On Jun 29, 9:48 am, WANG Cong wrote:
> On 06/27/10 12:01, Carl Banks wrote:
>
>
>
>
>
> > On Jun 25, 8:24 pm, WANG Cong wrote:
> >> Understand, but please consider my proposal again, if we switched to:
>
> >> setattr(foo, 'new_attr', &quo
on 2.x will be in use (I'm still on 2.5)...
> Imagine the sluggishness in having database engines converted
> (especially in a shared provider environment, where the language
> specific adapters also need updating -- ODBC drivers, etc.)
Thanks, your replies to this subthread have been most enlightening.
Carl Banks
--
http://mail.python.org/mailman/listinfo/python-list
On Jun 28, 2:44 am, Gregory Ewing wrote:
> Carl Banks wrote:
> > Indeed, strncpy does not copy that final NUL if it's at or beyond the
> > nth element. Probably the most mind-bogglingly stupid thing about the
> > standard C library, which has lots of mind-boggling stupi
On Jun 30, 2:55 am, Cameron Simpson wrote:
> On 29Jun2010 21:49, Carl Banks wrote:
> | On Jun 28, 2:44 am, Gregory Ewing wrote:
> | > Carl Banks wrote:
> | > > Indeed, strncpy does not copy that final NUL if it's at or beyond the
> | > > nth element. Proba
In Scheme
it's a special form that looks like an ordinary function call, but you
can "return" from the call any number of times.
A while back, Stackless Python supported continuations, but it was
removed because (IIRC) it made stackless too platform-dependent (plus
there wasn't much interest).
Carl Banks
--
http://mail.python.org/mailman/listinfo/python-list
return wrap
def expose(arg):
"""Magic function to allow omitting argument."""
if type(arg) is types.FunctionType:
print "Calling with arg as function"
return expose_as(None)(arg)
print "Calling with arg as protocol"
return expose_as(arg)
I believe it's a good practice to isolate magic so that it's easy to
see, and also to ensure there's a non-magical way to do it if that is
needed. However, the world won't come to an end if you do it your
way.
Carl Banks
--
http://mail.python.org/mailman/listinfo/python-list
on't care no
matter how many times you repeat it, because it's simply wrong. So,
please do everyone a favor, and stop wasting your own time, and stop
repeating this.
Carl Banks
--
http://mail.python.org/mailman/listinfo/python-list
ts window.
>
> > The pixel can be hard to see depending on your background colors and
> > whether your screen is adjusted correctly (I could see the white, but
> > not the black). But on XP Pro is still works.
>
> works for me too
I'm confirming that it even works with Wine emulator in Linux.
Carl Banks
--
http://mail.python.org/mailman/listinfo/python-list
ut not "9if 0else 1")
9and 0
9or 0
9in (1,2,3)
9is None
> Side effect: If this behaviour is considered as correct,
> it makes a correct Python code styling (IDLE, editors, ...)
> practically impossible to realise.
I'm not sure why an odd corner of the grammar would mess the w
except syntax, all of these are things you're already doing to support
2.3 to 2.6, so it seems suggest supporting 3.1 and 2.6 is maybe a
little more work than supporting 2.3 and 2.6.
We all know that Python is quite successful even with a history of
backward-incompatible changes and feature additions and even minor
paradigm shifts. What I'm interested in is, what things about the 2
to 3 transition is harder than already exists?
>From Paul's post it looks like not as much as you'd think--but as he
says it's a pretty simple package.
Carl Banks
--
http://mail.python.org/mailman/listinfo/python-list
mpy is released, maintain a
single codebase (translating from 2 version to 3) for awhile, then at
some point fork them and maintain them separately.
Given that I add features about once every 2 years I don't think it'll
be too much of a burden, though.
Carl Banks
--
http://mail.python.org/mailman/listinfo/python-list
#x27;<='|'<>'|'!='|'in'|'not' 'in'|'is'|'is' 'not'
Happy thing, too. I use "is not" a lot more than "is" and am happy to
avoid the extra set of parentheses.
Carl Banks
--
http://mail.python.org/mailman/listinfo/python-list
on. In Python 2 it's limited since you
cannot rebind variables in the surrounding scope; that's possible in
Python 3, though.
> 6. Is there a Python Checker that enforces Strunk and White and is
> bad English grammar anti-python? (Only half
> joking)http://www.python.org/dev/pe
def foo():
bar()
def bar():
print "hello"
del bar # bar is an internal function
It won't work; foo will raise NameError on bar if you try that.
However, del is useful to clean up code you run at module import time,
for example:
squares = []
for i in xrange(101):
squ
anguages. Visitor Pattern
is probably the worst example of it.
In Python it's completely unnecessary (at least in its boilerplate-
heavy incarnation as used in C++), and the fact that Python isn't
strongly typed, as you put it, is exactly the reason why.
Say you have a bunch of unre
On Jul 15, 8:33 pm, Stefan Behnel wrote:
> Carl Banks, 16.07.2010 01:14:
>
>
>
>
>
> > Around these parts, we consider the main use of most Design Patterns
> > to be to work around limitations of other languages. Visitor Pattern
> > is probably the worst
an not be (re) dumped without getting a MemoryError
>
> This seems like a bug in pickle?
No
> Any ideas (other than the obvious - don't save all of these files
> contents into a list! Although that is the only "answer" I can see at
> the moment :-)).
You should at least consider if one of the dbm-style databases (dbm,
gdbm, or dbhash) meets your needs.
Carl Banks
--
http://mail.python.org/mailman/listinfo/python-list
ndarray((10,10),type=numpy.float32,buffer=m)
As far as I know this procedure won't be too different under PEP 3118;
if anything it's simplified in Python 3 since it can discover type and
shape information itself. (You'll have to check with the numpy people
on that.)
Carl Banks
--
http://mail.python.org/mailman/listinfo/python-list
On Jul 20, 6:04 pm, Ken Watford wrote:
> On Tue, Jul 20, 2010 at 8:28 PM, Carl Banks wrote:
> > On Jul 20, 3:09 pm, Ken Watford wrote:
> >> Is there any way to expose the PEP 3118 buffer interface for objects
> >> that aren't extension types?
>
> >
the special variables, like __foo__?
Python Language Reference
> 4. Is there any work on deparsing (like Perl's deparse) lambda
> functions to inline algebra and get a performance gain?
psyco (q.g.) might help, not sure if it'll help much for lambdas,
though.
> Thanks
guage.
And yet your previous thoughts seem oddly constrained by Perl
If you really want a language that can accommodate any thought you
could possibly have, you should check out Lisp.
(defmacro swap (a b)
'(let ((t1 ,a)
(t2 ,b))
(setq ,b t1)
(setq ,a t2)))
hygiene-le
ate a module called foo.py,
and it have it import all the objects from the most recent release
module. IOW, you should have a foo.py module that looks like this:
from foo1 import *
Which you update whenever there's a new release. Then in your code
you simply use:
import foo
This is, in
umented as supporting inheritance
Furthermore, if you want to stay sane, don't mulitply inherit from any
class unless
A. you own it, or
B. it's explicitly documented as supporting MULTIPLE inheritance
Inheritance is always risky if you don't know what you're inheriting
from.
Carl
ope that it won't explode when you try to use it :/
Type casts in C and non-pathlogical C++ don't modify the object they
are casting.
int (and str, float, etc.) is the closest thing to a type cast in
Python.
Carl Banks
--
http://mail.python.org/mailman/listinfo/python-list
On Jul 28, 7:45 pm, Steven D'Aprano wrote:
> On Wed, 28 Jul 2010 08:47:52 -0700, Carl Banks wrote:
> > On Jul 28, 7:32 am, Steven D'Aprano > cybersource.com.au> wrote:
> >> On Wed, 28 Jul 2010 09:35:52 -0400, wheres pythonmonks wrote:
> >> > Thank
ust
throwing it out there.
Carl Banks
--
http://mail.python.org/mailman/listinfo/python-list
a wonderful, holy thing. But, sex outside of marriage, and
inheriting from classes you don't know, is deadly sin and you will
burn in Hell.
> and in my current view from a
> maintenance perspective, best practice is to only use super() in the
> multiple-inheritance scenarios it was specifically designed for
I use super() exclusively for all types of inheritance, unless I'm
inheriting from a class I know uses old form (which is none of mine,
and I only rarely inherit from classes I don't own).
Carl Banks
--
http://mail.python.org/mailman/listinfo/python-list
On Jul 31, 8:48 pm, Carl Banks wrote:
> When you have a class you that don't anything about the implementation
> of, that is NOT the place for inheritance.
And, just to be clear, if the class is explicity documented as being
subclassable and the documentation states the proper pr
e a way to do this.
My general feeling is that ElementTree is a lot handier for reading
and writing your own XML formats, than for handling XML files produced
by other tools.
The lxml package has an ElementTree like interface but with some
methods to handle namespace abbreviations.
Carl Banks
--
http://mail.python.org/mailman/listinfo/python-list
On Aug 1, 5:43 pm, Lawrence D'Oliveiro wrote:
> In message
> <96e47fd8-c939-48a2-9a2b-92afa720c...@k1g2000prl.googlegroups.com>, Carl
>
> Banks wrote:
> > My general feeling is that ElementTree is a lot handier for reading
> > and writing your own XML formats, t
ass:
class Bar {
virtual int foo(int);
virtual int bar(int);
};
might be generated like this in one cfront:
struct Bar$$Vtable$ {
int (*Bar$$bar$d)(int);
int (*Bar$$foo$d)(int);
};
and like this in another:
struct class_Foo___vtable_ {
int (*foo)(int);
in
want that in *.pyc files. In PEP
3147 they proposed a fat-format file (so a glob for each version) and
it was not popular.
> I have
> no idea what it does now,
There's a short header, then the rest of the file is a single
marshaled glob.
> but I suspect not that. It might make
so there's a risk of these objects escaping
from the context where they make sense.
This is just a bad idea. The type is not the place to implement
behavior that makes sense only in a limited context. Instead, do
something like this:
print "Item %d is %s." % (i+1, s[i])
Carl Banks
--
http://mail.python.org/mailman/listinfo/python-list
On Aug 3, 2:29 am, John Bokma wrote:
> Carl Banks writes:
> > On Aug 1, 6:09 pm, John Bokma wrote:
> >> Roy Smith writes:
> >> > In article <4c55fe82$0$9111$426a3...@news.free.fr>,
> >> > candide wrote:
>
> >> &g
On Aug 3, 3:19 pm, John Bokma wrote:
> Carl Banks writes:
> > On Aug 3, 2:29 am, John Bokma wrote:
>
> [..]
>
> >> But they call both the C libraries in the same way.
>
> > Go look at the original claim, the one that you responded to. "It's
&g
#x27;m starting to get the feeling one of these languages is going to hit
a sweet spot and turn C into the next Cobol.
Carl Banks
--
http://mail.python.org/mailman/listinfo/python-list
>
> and then later,
>
> C('Hello')
>
> does not work; the first argument, self, is assigned all rigth, but
> you cannot write the second argument with a dot, self.name .
> Or can I somehow?
__init__=lambda self,name:setattr(self,'name',name)
However
was C++ able to get popular in the first place?
>
> Building on C's popularity helped.
AT&T + Money + C backward compatibility
> > And how was Java able to grab some share from it?
>
> Good question. Both IBM and Sun put a lot of effort/money behind
> Java.
Sun + IBM
y, actually. However, omitting generics was probably
the second worst thing about Java (the worst thing being the awful AWT
design).
Carl Banks
--
http://mail.python.org/mailman/listinfo/python-list
arch), then you have an numpy integer array
that stores the indices into this string where the word boundaries
are, and then an Nx7 numpy integer array storing the int return
vslues. That's three compact arrays.
Carl Banks
--
http://mail.python.org/mailman/listinfo/python-list
esn't use type-
casting?
int a, b;
double ratio;
ratio = (double)a/b;
> It is unfortunate that cast's in Python share the same name, but
> it is kind of unavoidable because it is about the proper CS name to use.
Not really. Very few people call int(), float(), and company "type
casts". They aren't type casts at all, they are constructors that
sometimes have the same semantics as type casts in C.
Carl Banks
--
http://mail.python.org/mailman/listinfo/python-list
On Aug 7, 8:18 pm, Dennis Lee Bieber wrote:
> On Sat, 7 Aug 2010 13:02:56 -0700 (PDT), Carl Banks
> declaimed the following in
> gmane.comp.python.general:
>
>
>
> > Not really. Very few people call int(), float(), and company "type
> > casts".
xpected ctc:
> notice period:
#1: You should post this on the Python jobs board.
http://www.python.org/community/jobs/
#2: I know the economy's bad but not everyone is going to apply to
every job posting they see. You should include a least a little
information about the job.
Carl Ban
cally
equivalent) C++. But if you don't actively try to write code that is
compatible with both languages, chances are the C code will invoke one
of those "'minor' 'backwards' incompatibilies", the most common one
being failure to cast a pointer.
Carl Banks
--
http://mail.python.org/mailman/listinfo/python-list
e modules according to "dependencies", so
as to remove the circular import, makes it more confusing. Sometimes
organizing by function makes more sense than organizing by dependency,
and it's better to live with circular imports than to use a less-
sensical organization.
Carl Banks
--
http://mail.python.org/mailman/listinfo/python-list
On Aug 10, 12:06 am, Ulrich Eckhardt wrote:
> Carl Banks wrote:
> > I highly doubt the Python source would build with a C++ compiler.
>
> As Christian showed, it doesn't. However, look around the sources a bit.
> There are lots of places where e.g. the returnvalue of mall
If you're going to send me unsolicited email, the least you can do it
include pics of Erin.
Carl Banks
--
http://mail.python.org/mailman/listinfo/python-list
building up some
> kind of stack overflow or something which will bite me later.
What do you think a few words of data the stack are going to do?
Just do it this way.
Carl Banks
--
http://mail.python.org/mailman/listinfo/python-list
f if there wasn't an error
def main():
try:
run_program()
except MyException as exc:
print >> sys.stderr, str(exc)
sys.exit(1)
If you call sys.exit() deep within your call tree, the world won't
come to an end, but raising an exception is the preferred
. Is there an easy way to avoid this problem?
> Pretty much any performance-intensive part of my program is going to be
> dealing with these arrays, so I don't want to just replace them with a
> slower dictionary instead.
>
> I can't imagine this issue hasn't come up before; I encountered it by
> using NumPy arrays to store Python structs, something I can imagine is
> done fairly often. As such, I apologize for bringing it up again!
I doubt a very high percentage of people who use numpy do character
manipulation, so I could see it as something that hasn't come up
before.
Carl Banks
--
http://mail.python.org/mailman/listinfo/python-list
wning function, but with
iterators you can. In fact, iterators are (almost) orthogonally
recombinable; the whole input space of a problem can be spanned simply
by combining simple iterators.
So, I will have to ultimately agree with Gabriel: itertools are best
kept simple and complex interator beha
ther solving this?
In my experience, if you want a custom print function that prints
things the way you want, you have to write it yourself. People's
expectations are too different.
Carl Banks
--
http://mail.python.org/mailman/listinfo/python-list
tines are shaky when ill-conditioned, but it could help
newbies and computer science experts to be explicit about it.
Carl Banks
--
http://mail.python.org/mailman/listinfo/python-list
sp code in
your .emacs file, defines a command to automatically insert the a
super call with the class and method name filled in:
http://code.activestate.com/recipes/522990/
Carl Banks
--
http://mail.python.org/mailman/listinfo/python-list
o go strictly by the book, I would say he ought to be
using a set since his collection of numbers has no meaningful order
nor does it make sense to list any item twice.
I don't think it's very important, however, to stick to rules like
that for objects that don't live for more than a single line of code.
Carl Banks
--
http://mail.python.org/mailman/listinfo/python-list
On Jun 8, 6:02 pm, Ben Finney wrote:
> Carl Banks writes:
> > If you want to go strictly by the book, I would say he ought to be
> > using a set since his collection of numbers has no meaningful order
> > nor does it make sense to list any item twice.
>
> Yes, a
On Jun 9, 2:47 am, "Hendrik van Rooyen" wrote:
> "Diez B. Roggisch" wrote:
>
> > I think
>
> > lb = list(s)
>
> > is good enough.
>
> It does the job, of course, but it is not a string method.
A. Your post's subject included t
ere, chief.
[ "%.1f" % x for x in lst ]
BTW, I took the liberty of making a few style choices, highly
recommended: not to use "i" for floating points ("i" strongly suggests
integer value to many programmers), and not using "l" (the letter ell)
as
cution time to
"item in set" if item is always the first element in list.
Furthermore, the Python compiler appears to be optimizing this
specific case to always use a precompiled set. Well, almost
always
> You will also note
> that performance to fall off drastically for the last set of values.
> I'm not sure what happens there; I guess I'll file a bug report.
Please don't; it's not a bug. The slowdown is because at sizes above
a certain threshold the Python compiler doesn't try to precompile in-
line lists, sets, and tuples. The last case was above that limit.
Carl Banks
--
http://mail.python.org/mailman/listinfo/python-list
flawed.
> assuming that the list has less than 8K members. Above 16K
> members, sets are much faster than lists. I'm not sure where the
> break is, or even why there's a break.
The break comes from the compiler, not the objects themselves.
Carl Banks
--
http://mail.python.org/mailman/listinfo/python-list
s way:
1. log messages to a buffer
2. periodically flush the buffer to the flash drive, if it's available
The "periodically" part could be accomplished with a thread or
scheduled delays, however suits your application. It might not be a
final if you need to log messages promptly
h is a method of str
but a constructor of list?
Perhaps instead of worrying about symmetry all the time we should just
accept the inevitability that things will always be asymmetric and
impure from someone's perspective. Terry's symmetry is Hendrik's
asymmetry and vice versa.
Carl Banks
--
http://mail.python.org/mailman/listinfo/python-list
ff the bits of
the number into the mantissa of a double, along with -1 as the
exponent, and return that.
Implementation left as exercise, mostly because it really won't make a
difference.
Carl Banks
--
http://mail.python.org/mailman/listinfo/python-list
r is pretty simple
I'd say just go with that.
Unless you have some other things happening downstream that would also
benefit from the source data being in a database, or something.
Carl Banks
--
http://mail.python.org/mailman/listinfo/python-list
te the
attributes. I'd also recommend using self.__dict__.clear() for that,
it gets all of them (usually) and doesn't need to be updated with you
add a new attribute to a class.
Carl Banks
--
http://mail.python.org/mailman/listinfo/python-list
image = Image.fromstring("RGBA",shape,pixels)
image.save('voronoi.png')
if __name__ == '__main__':
draw_map(voronoi(([100,100],[356,301],[400,65],[324,145],
[200,399])))
Carl Banks
--
http://mail.python.org/mailman/listinfo/python-list
ve forever, and bound
classmethods are lightweight and hardly worth the effort.
Maybe show us what you need to weak reference classmethods for and we
can help you better.
Carl Banks
--
http://mail.python.org/mailman/listinfo/python-list
d-of-line characters in text files are automatically altered
> "slightly when data is read or written.
>
> I don't see any obvious way to at docs.python.org to get that corrected: Is
> there some standard procedure?
What's wrong with it?
Carl Banks
--
http://mail.python.org/mailman/listinfo/python-list
it.
P.S. Someone will be by to post the "How to ask smart questions" essay
shortly.
Carl Banks
--
http://mail.python.org/mailman/listinfo/python-list
On Jun 17, 5:36 pm, "steve" wrote:
> >"Carl Banks" wrote in message
> >news:2f6271b1-5ffa-4cec-81f8->>0276ad647__begin_mask_n#9g02mg7!__...__end_mask_i?a63jfad$...@p5g2000pre.googlegroups.com...
> >On Jun 15, 7:56 pm, "steve" wrote:
> &g
nto CPython unless makes extensions are just as
easy to write. That is something I have serious doubts they can pull
off.
Which means a GIL-less unladen-swallow is likely to end being another
fork like IronPython and Jython. Those projects already have no GIL.
Carl Banks
--
http://mail.python.org/mailman/listinfo/python-list
t enough?
Jesus. I wish people would just say, "This is a limitation of
CPython. There are reasons why it's there, and it helps some people,
but unfortunately it has drawbacks for others", instead of the typical
"all u hav 2 do is rite it in C LOL".
Carl Banks
--
http://mail.python.org/mailman/listinfo/python-list
On Jun 19, 4:42 pm, Christian Heimes wrote:
> OdarR schrieb:
>
> > On 19 juin, 21:41, Carl Banks wrote:
> >> He's saying that if your code involves extensions written in C that
> >> release the GIL, the C thread can run on a different core than the
> >&
On Jun 19, 4:35 pm, a...@pythoncraft.com (Aahz) wrote:
> In article <157e0345-74e0-4144-a2e6-2b4cc854c...@z7g2000vbh.googlegroups.com>,
> Carl Banks wrote:
> >I wish Pythonistas would be more willing to acknowledge the (few)
> >drawbacks of the language (or implementatio
pecially things that quite reasonably appear to be a silly
limitation.
Maybe you don't intend to sound like you're saying "shut up and use
C", but to me, that's how you come off. If you're going to advise
someone to use C, at least try to show some understanding for their
concerns--it would go a long way.
Carl Banks
--
http://mail.python.org/mailman/listinfo/python-list
edups.
Just for the record, I am not taking issue with the advice itself
(except that you forgot "use Jython/IronPython which have no GIL").
I'm not even saying that Python was wrong for having the GIL.
All I'm saying is that [this is not aimed specifically at you] this
advice can be delivered with more respect for the complainer's
problem, and less fanboy-like knee-jerk defensiveness of Python.
Carl Banks
--
http://mail.python.org/mailman/listinfo/python-list
interactive prompt:
>>> foo.r
{'f': 4}
You want an instance attribute, a value attached to the instance of
the class. You create those in the __init__ method:
class foo:
def __init__(self):
self.r = {}
def setn(self,n):
self.r["n"] = n
Carl Banks
--
http://mail.python.org/mailman/listinfo/python-list
n'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 it was originally was like this:
value = foo.bar()['first'][0]*baz.quux(1, 2)[5:9] \
+ calculate_number(10, 20)*forbulate(500, 360)
Carl Banks
--
http://mail.python.org/mailman/listinfo/python-list
On Jun 23, 7:20 am, Rolf Wester wrote:
> Philip Semanchuk wrote:
>
> > On Jun 23, 2009, at 9:51 AM, Rolf Wester wrote:
>
> >> Hi,
>
> >> I have a C++ program that I would like to steer using Python. I made the
> >> wrapper using swig and linked the code (without the main function) into
> >> a shar
t for other readers): this method can't tell the
difference between a class defined in the module and a class imported
into it.
Finally, despite the warning, I think you are ok to use dir() for that
purpose. It's not likely to change.
Carl Banks
--
http://mail.python.org/mailman/listinfo/python-list
take weeks in C or C++.
If that [teaching them this] is the case, it might be best use of time
they will ever have.
Carl Banks
--
http://mail.python.org/mailman/listinfo/python-list
that this idea is worth it.
>
> Any feedback is welcome.
If you don't mind abusing Python syntax, you can do it using something
like this:
def DictMaker(name,bases,dct):
dct.pop('__metaclass__',None)
return dct
class a:
__metaclass__ = DictMaker
home = "/home/test"
user1 = home + "/user1"
user2 = home + "/user2"
python_dev = user1 + "/py-dev"
print a
Carl Banks
--
http://mail.python.org/mailman/listinfo/python-list
nternal','_y_internal']
x = MemberDescriptorWrapper('_x_internal')
y = MemberDescriptorWrapper('_y_internal')
MemberDescriptorWrapper class would have to implement __get__,
__set__, and __del__ methods and have them call the corresponding
methods on the slot; details are left as an exercise.
Carl Banks
--
http://mail.python.org/mailman/listinfo/python-list
nique above to wrap up the root Element if you
use et.fromstring.
[snip]
> Why isn't et.parse the only way to do this? Why have XML or fromstring
> at all?
Because Fredrick Lundh wanted it that way. Unlike most Python
libraries ElementTree is under the control of one person, which
On Jun 25, 8:53 pm, Kee Nethery wrote:
> On Jun 25, 2009, at 8:04 PM, Carl Banks wrote:
> > A few minor
> > things should be no big deal.
>
> True and I will eventually get past the minor quirks. As a newbie,
> figured I'd point out the difficult portions, thi
On Jun 25, 10:11 pm, Stefan Behnel wrote:
> Carl Banks wrote:
> >> Why isn't et.parse the only way to do this? Why have XML or fromstring
> >> at all?
>
> > Because Fredrick Lundh wanted it that way. Unlike most Python
> > libraries ElementTree is und
On Jun 25, 11:20 pm, Stefan Behnel wrote:
> Carl Banks wrote:
> > On Jun 25, 10:11 pm, Stefan Behnel wrote:
> >> Carl Banks wrote:
> >>>> Why isn't et.parse the only way to do this? Why have XML or fromstring
> >>>> at all?
> >>&g
1401 - 1500 of 1709 matches
Mail list logo