and connected with the
caller's history of `champagne.drink()` calls. The `person.is_pretty`
property is most definitely linked to that call history in many instances.
Ciao,
Marc 'BlackJack' Rintsch
--
http://mail.python.org/mailman/listinfo/python-list
e other program will say:
> tok = Toker( text_array )
> tokens = tok.tokenize()
>
> So how does the constructor make the array of strings available to the
> tokenize() method?
Assuming the `__init__()` above belongs to the `Toker` class then the
`tokenize()` method can access it via `self.text`
On Mon, 17 Dec 2007 06:20:23 -0800, vimal wrote:
>i have a list of numbers
>
> say a = [1,-1,3,-2,4,-6]
>
> how should i check for negative values in the list
In [6]: a = [1, -1, 3, -2, 4, -6]
In [7]: any(n < 0 for n in a)
Out[7]: True
Ciao,
Marc 'Blac
arBasic for the conversion.
Full story:
http://www.xml.com/pub/a/2006/01/11/from-microsoft-to-openoffice.html
Ciao,
Marc 'BlackJack' Rintsch
--
http://mail.python.org/mailman/listinfo/python-list
implement it. :-)
`itertools.groupby()` might be handy.
And you have to think about digits in the source if that's allowed.
Ciao,
Marc 'BlackJack' Rintsch
--
http://mail.python.org/mailman/listinfo/python-list
tarting to parse XML with regular expressions you are
making the very same mistake. XML may look somewhat simple but
producing correct XML and parsing it isn't. Sooner or later you stumble
across something that breaks producing or parsing the "naive" way.
Ciao,
Marc
= [do_something(item) for item in old]
Or:
new = map(do_something, old)
Ciao,
Marc 'BlackJack' Rintsch
--
http://mail.python.org/mailman/listinfo/python-list
rst
> '\0' are counted.
If you want to deal with bytes better open the file in binary mode.
Windows alters line endings and stops at a specific byte (forgot the
value) otherwise.
Ciao,
Marc 'BlackJack' Rintsch
--
http://mail.python.org/mailman/listinfo/python-list
On Tue, 11 Dec 2007 20:08:21 -0300, Gabriel Genellina wrote:
> data = [row for row in csv.reader(..)]
A bit shorter::
data = list(csv.reader(..))
Ciao,
Marc 'BlackJack' Rintsch
--
http://mail.python.org/mailman/listinfo/python-list
On Tue, 11 Dec 2007 17:58:37 -0800, mariox19 wrote:
> If I am supposed to send messages to Tkinter objects only from the
> main thread, how can I get the letters to appear 1 per second?
Take a look at the `after()` method on widgets.
Ciao,
Marc 'BlackJack'
ful than the real default. What is the
> reasoning behind NOT using this as the default implementation for a
> dict in python?
How's that more useful in the general case? Maybe if you come from a
language where some default value pops up if the key is not present you
are used to write code in a way that exploits this fact. But in the
general case!? I need `defaultdict` not very often but want to know if a
key is not present in a dictionary. Because most of the time that's a
special condition or error that has to be handled or signaled up the call
chain.
Ciao,
Marc 'BlackJack' Rintsch
--
http://mail.python.org/mailman/listinfo/python-list
s no effect. IMHO that should emit at least a warning…
Ciao,
Marc 'BlackJack' Rintsch
--
http://mail.python.org/mailman/listinfo/python-list
ke it as ugly and unusable as you can. Spend the time you planned
for writing documentation for this task. ;-)
Ciao,
Marc 'BlackJack' Rintsch
--
http://mail.python.org/mailman/listinfo/python-list
In [469]: a = collections.defaultdict(int)
In [470]: callable(a.default_factory)
Out[470]: True
In [471]: a.default_factory(42)
Out[471]: 42
`a.default_factory` is callable but hardly a method of `a` or `defaultdict`
but a "data attribute" that happens to be callable.
Ciao,
Marc 'BlackJack' Rintsch
--
http://mail.python.org/mailman/listinfo/python-list
;
dictionary with a tuple of both as keys:
data = dict(((i, j), randint(0, 10)) for i in xrange(11) for j in xrange(11))
And just for completeness: The given data in the example can be stored in a
list of lists of course:
data = [[randint(0, 10) for dummy in xrange(11)] for dummy in xrange(11)]
>>>> n += 1
>>>> n
> 2
>>>> ++n
> 2
There is no syntax error. It is just some unary pluses "chained". Maybe
unexpected but no syntax error.
Ciao,
Marc 'BlackJack' Rintsch
--
http://mail.python.org/mailman/listinfo/python-list
object bindings and methods are objects.
Ciao,
Marc 'BlackJack' Rintsch
--
http://mail.python.org/mailman/listinfo/python-list
On Sat, 08 Dec 2007 00:34:06 -0800, MonkeeSage wrote:
> I think he means callable attributes (methods) and non-callable
> attributes (variables).
But not every callable attribute is a method.
Ciao,
Marc 'BlackJack' Rintsch
--
http://mail.python.org/mailman/listinfo/python-list
er it's easy but
providing functions in the standard library for arbitrary date calculation
involving years is not so easy.
Ciao,
Marc 'BlackJack' Rintsch
--
http://mail.python.org/mailman/listinfo/python-list
he decision is easy -- everything on an
object is an attribute. ;-)
Ciao,
Marc 'BlackJack' Rintsch
--
http://mail.python.org/mailman/listinfo/python-list
turn item...
>
> Yuck.
I guess Duncan's point wasn't the construction of the dictionary but the
throw it away part. If you don't keep it, the loop above is even more
efficient than building a dictionary with *all* lines of the file, just to
pick one value afterwards.
Ciao,
Marc 'BlackJack' Rintsch
--
http://mail.python.org/mailman/listinfo/python-list
re's an alternative way with the `functools.partial()`
function:
from functools import partial
# ...
msg = Button(win,
text='Write Something',
command=partial(salutation, tree))
Ciao,
Marc 'BlackJack' Rintsch
--
http://mail.python.org/mailman/listinfo/python-list
!
>>
>>Wasn't Ra the Sun god?
>>
>
> He meant quetzatcoatl. We could rename the language.
That name is already taken in the programming language domain. There's a
Tiny C compiler for 6510 based targets:
http://www.kdef.com/geek/vic/quetz.html
Ciao,
Marc 'BlackJack' Rintsch
--
http://mail.python.org/mailman/listinfo/python-list
e time.
If the function looking style would be adopted for 2.x, do *you* want to
explain confused newbies why they can write::
print('hello!')
but this acts "strange":
print('hello, my name is ', name)
Ciao,
Marc 'BlackJack' Rintsch
--
http://mail.python.org/mailman/listinfo/python-list
plit function, but this mini-monster wouldn't properly get
> split up due to those random quotations postgresql returns to me.
I hope you don't use Python to access the database, get a tuple back,
convert it to a string and then try to break up that string into a list!?
Ciao,
Marc 'BlackJack' Rintsch
--
http://mail.python.org/mailman/listinfo/python-list
Out[83]: >
In [84]: type(Parrot.cmethod)
Out[84]:
In [85]: Parrot.__dict__['cmethod']
Out[85]:
In [86]: type(Parrot.__dict__['cmethod'])
Out[86]:
Ciao,
Marc 'BlackJack' Rintsch
--
http://mail.python.org/mailman/listinfo/python-list
rings. If you don't
do this explicitly Python tries to encode as ASCII and fails if there's
anything non-ASCII in the string. The `encode()` method is your friend.
Ciao,
Marc 'BlackJack' Rintsch
--
http://mail.python.org/mailman/listinfo/python-list
On Sat, 24 Nov 2007 08:27:56 -0800, samwyse wrote:
> On Nov 24, 7:50 am, Marc 'BlackJack' Rintsch <[EMAIL PROTECTED]> wrote:
>> On Sat, 24 Nov 2007 02:54:27 -0800, samwyse wrote:
>> > On Nov 24, 4:07 am, Marc 'BlackJack' Rintsch <[EMAIL PROTECTED]&g
On Sat, 24 Nov 2007 14:09:04 +0100, Ton van Vliet wrote:
> On 24 Nov 2007 08:48:30 GMT, Marc 'BlackJack' Rintsch <[EMAIL PROTECTED]>
> wrote:
>
>>On Sat, 24 Nov 2007 09:12:34 +0100, Ton van Vliet wrote:
>>
>>> Just bringing up something I sometimes m
On Sat, 24 Nov 2007 02:54:27 -0800, samwyse wrote:
> On Nov 24, 4:07 am, Marc 'BlackJack' Rintsch <[EMAIL PROTECTED]> wrote:
>> On Sat, 24 Nov 2007 01:55:38 -0800, samwyse wrote:
>> > I've had the same thought, along with another. You see, on of my pet
erhaps there is a Python
> Elder here that knows?
AFAIK strings of length 1 and strings that would be valid Python
identifiers are treated this way.
Ciao,
Marc 'BlackJack' Rintsch
--
http://mail.python.org/mailman/listinfo/python-list
> dog = 'rover'
> def example():
> global cat, dog # not always required, but frequently needed
> return ', '.join((cat, dog))
Ouch that's bad design IMHO. The need to use ``global`` is a design
smell, if needed *frequently* it starts to stink.
Ciao,
M
a record
definition to make that decision.
Ciao,
Marc 'BlackJack' Rintsch
--
http://mail.python.org/mailman/listinfo/python-list
> expands to
>
> def abs(self):
> x, y, z = self.__unpack__("x","y","z")
> return math.sqrt(x**2 + y**2 + z**2)
What about ``from`` instead of ``by``? That's already a keyword so we
don't have to add a new one.
Ciao,
Marc 'BlackJack' Rintsch
--
http://mail.python.org/mailman/listinfo/python-list
ook like if whitespace is
preserved. What matters is the actual text in the source, not the
formatting. That's left to the browser.
Ciao,
Marc 'BlackJack' Rintsch
--
http://mail.python.org/mailman/listinfo/python-list
ic" way to define
`comma_separate()` is::
comma_separate = ','.join
Ciao,
Marc 'BlackJack' Rintsch
--
http://mail.python.org/mailman/listinfo/python-list
which ``if`` does the ``else``
belong to here? ::
if 1: print 1 if: 1 print 1 else: print 1
Ciao,
Marc 'BlackJack' Rintsch
--
http://mail.python.org/mailman/listinfo/python-list
On Mon, 19 Nov 2007 10:50:28 -0800, Jens wrote:
> Generating documentation form code is a nice thing, but this pydoc.py
> is driving me insane - isn't there are better way?
Epydoc!?
Ciao,
Marc 'BlackJack' Rintsch
--
http://mail.python.org/mailman/listinfo/python-list
UpKey(self,event):
> self.canv.move(tagOrId,xAmount=0,yAmount=10)
Where's `tagOrId` coming from? That's a `NameError` here.
Ciao,
Marc 'BlackJack' Rintsch
--
http://mail.python.org/mailman/listinfo/python-list
rgs)
return new_func
class A(object):
@pre
def func(self, a, b):
print a + b
a = A()
a.func(3, 5)
Ciao,
Marc 'BlackJack' Rintsch
--
http://mail.python.org/mailman/listinfo/python-list
gt;
> This one returns the lowest value Object, but not the lowest value of
> age in all the Objects of the table.
In the example `min()` finds the object with the lowest `id()`. To change
that you can implement the `__cmp__()` method on your `Block` objects.
Ciao,
Marc 'BlackJack' Rintsch
--
http://mail.python.org/mailman/listinfo/python-list
o build
something with those functions.
Ciao,
Marc 'BlackJack' Rintsch
--
http://mail.python.org/mailman/listinfo/python-list
gt; Of course if you want to have more or less realistic imaging for whatever
> purpose, 3D is the way to go. If you are after traffic-simulations, it's
> unneeded complexity.
Not if their solution includes flying buses and taxis. Or this pneumatic
delivery system for people from `Fut
ct. Changing the dictionary bound to `h` changes it::
h = orig['ca']
h['adanac'] = 69
> Yet since names are not exactly references, something else is needed
> for generalized ngram multi-level counting hash -- what?
Names *are* implemented as references to objects, but binding the name to
a different object has no effect on the object bound to that name before.
Ciao,
Marc 'BlackJack' Rintsch
--
http://mail.python.org/mailman/listinfo/python-list
f.read(chunksize)
>
> I just don't feel comfortable with it for some reason I can't explain...
chunksize = 26
f = open('datafile.dat', 'rb')
for chunk in iter(lambda: f.read(chunksize), ''):
compute_data(chunk)
f.close()
Ciao,
Marc 'BlackJack' Rintsch
--
http://mail.python.org/mailman/listinfo/python-list
#x27;s
> equivalent to the following perl's search string?
> m/^\S{1,8}\.\S{0,3}/
It is ``re.match(r'\S{1,8}\.\S{0,3}', string)``. There's something called
"documentation"…
Ciao,
Marc 'BlackJack' Rintsch
--
http://mail.python.org/mailman/listinfo/python-list
tion between
processes.
Ciao,
Marc 'BlackJack' Rintsch
--
http://mail.python.org/mailman/listinfo/python-list
erations to easily find out the
differences between two set of names and the `pickle` module to store
Python objects in files.
Ciao,
Marc 'BlackJack' Rintsch
--
http://mail.python.org/mailman/listinfo/python-list
{}
> for line in open('keys.txt'):
> v[long(line.strip())] = True
Takes about 40 seconds here.
[EMAIL PROTECTED]:~$ time python test.py
real 0m38.758s
user0m25.290s
sys 0m1.580s
Ciao,
Marc 'BlackJack' Rintsch
--
http://mail.python.org/mailman/listinfo/python-list
On Sat, 10 Nov 2007 17:39:04 +, Marc 'BlackJack' Rintsch wrote:
> On Sat, 10 Nov 2007 18:53:08 +0200, Donn Ingle wrote:
>>>> print b.ref.attribute # print "haschanged"
>>>>
>>>> print j.ref.attribute #prints "original
] ││
>│ │ [S2] [S3] └┬┘│
>│ │││┌─< C4 >─┐│
>│ │││ [S4] ││
>│ │││└───┬┘│
>│ └───┬┴┴┘ │
>│ [S5] │
>│ └───
his is kind of weird. It's not clear like Python usually is. Is this
> something intentional or did it 'fall through the cracks'? I mean, can one
> rely on it or will it be 'fixed'?
Don't think so. It's a surprise for many but then class attributes are
not that common in code or they even use this "gotcha" for
immutable default values. As long a the value isn't changed the default
value is just referenced from the class then and not every instance.
Ciao,
Marc 'BlackJack' Rintsch
--
http://mail.python.org/mailman/listinfo/python-list
mbers that you are adding and not strings or something!?
Ciao,
Marc 'BlackJack' Rintsch
--
http://mail.python.org/mailman/listinfo/python-list
nd setBlah for every little thing?
Good $GOD no! He's talking about the `__get__` method on properties. Read
the docs for the built in `property()` function. It's a nice mechanism to
actually avoid all those getters and setters because you can turn "simple"
attributes into "computed" attributes without changing the API of the
objects.
Ciao,
Marc 'BlackJack' Rintsch
--
http://mail.python.org/mailman/listinfo/python-list
on names in tracebacks? What about nesting these anonymous
multiline functions? What about the impact on the grammar?
Ciao,
Marc 'BlackJack' Rintsch
--
http://mail.python.org/mailman/listinfo/python-list
der ? And if so, how could
> I *then* notify her ?-)
Ask a medium? Use a crystal ball for the very long distance call? Call
Dr. Frankenstein for help? =:o)
Ciao,
Marc 'BlackJack' Rintsch
--
http://mail.python.org/mailman/listinfo/python-list
On Fri, 09 Nov 2007 02:51:10 -0800, Michel Albert wrote:
> Obviously this won't work as you cannot access a slice of a csv-file.
> Would it be possible to subclass the csv.reader class in a way that
> you can somewhat efficiently access a slice?
An arbitrary slice? I guess not as all records bef
On Thu, 08 Nov 2007 22:53:16 -0800, r.grimm wrote:
>>>> (1).__cmp__(10)
> -1
As the dot is an operator like ``+`` or ``/`` you can also add spaces to
avoid the ambiguity:
In [493]: 1 . __cmp__(10)
Out[493]: -1
In [494]: 1 .__cmp__(10)
Out[494]: -1
Ciao,
Marc
On Wed, 07 Nov 2007 18:35:51 +, kyosohma wrote:
> I've never had to put the command into a list or tuple...but you're
> welcome to try it that way.
You don't *have* to but if you do the module takes care of quoting the
arguments if necessary.
Ciao,
Marc 'B
return cmp(self.value, other.value)
Ciao,
Marc 'BlackJack' Rintsch
--
http://mail.python.org/mailman/listinfo/python-list
in a module named `inspect.py` that is
definitely not the one from the standard libarary. If that module has an
``import inspect`` it imports *itself*!
Ciao,
Marc 'BlackJack' Rintsch
--
http://mail.python.org/mailman/listinfo/python-list
; > Could you explain a little more because I am new in scripting?
>>
>> Not really. I showed you the call I made and the result I got. How can I
>> be more clear and precise!?
>
> Ok but I run in Windows and I cannot understand your '!touch test.py'
Ah, sorry t
On Tue, 06 Nov 2007 01:45:02 -0800, awel wrote:
> On 6 nov, 09:00, Marc 'BlackJack' Rintsch <[EMAIL PROTECTED]> wrote:
>> On Mon, 05 Nov 2007 23:33:16 -0800, awel wrote:
>> > I am trying to to make a script to move all the files that has been
>> >
one that I receive from the 'datetime.date.today()'.
Build a `datetime.date` object from the timestamp you get from the stat
call:
In [438]: !touch test.py
In [439]: datetime.date.fromtimestamp(os.stat('/home/bj/test.py').st_ctime)
Out[439]: datetime.date(2007, 11, 6)
a 3.5G file that may be
broken.
Ciao,
Marc 'BlackJack' Rintsch
--
http://mail.python.org/mailman/listinfo/python-list
hat UTF-8 encoded 'Ä' and shows it. If you expected the output
'\xc3\x84' then remember that you ask the soup object for its
representation and not a string. The object itself decides what
`repr(obj)` returns. Soup objects represent themselves as UTF-8 encoded
strings.
Ciao,
Marc 'BlackJack' Rintsch
--
http://mail.python.org/mailman/listinfo/python-list
re(Word(alphas))`` part "eats" the 'end' and when it
can't get more, the parser moves to the ``Literal('end')`` part which
fails because the 'end' is already gone.
> Is there a way to get pyparsing to parse a grammar like this?
Negative lookahead
ee read only one record of the data at a time?
Have you tried `iterparse()`?
Ciao,
Marc 'BlackJack' Rintsch
--
http://mail.python.org/mailman/listinfo/python-list
t; return rows
>
> How would you modify this to exclude lines between "Begin VB.Form" and
> "End" as described above?
Introduce the flag and look up the docs for the `startswith()` method on
strings.
Ciao,
Marc 'BlackJack' Rintsch
--
http://mail.python.org/mailman/listinfo/python-list
>
> idiom, which is a bit of a pity I think.
And what should ``'string'.find('str')`` return? How do you distinguish
the not found at all case from the found at the very beginning case!?
The simple test you want can be written this way:
if 'something' in chec
te over `something` directly. That loop can be written as:
for pixval in data:
rgb = pixval2rgb(pixval)
rgbs.append(rgb)
Or even shorter in one line:
rgbs = map(pixval2rgb, data)
If the `numpy` array is what you want/need it might be more efficient to do
the RGB to "pixval" conversion with `numpy`. It should be faster to shift
and "or" a whole array instead of every pixel one by one in pure Python.
Ciao,
Marc 'BlackJack' Rintsch
--
http://mail.python.org/mailman/listinfo/python-list
")
…this line will raise an exception. `file.write()` takes just one
argument, not three as in this call. If you don't get an exception maybe
you have other places with a bare ``except`` like in the snippet above.
Don't do that. Catch the specific exception you want to handle with an
``except`` and not simply *all*.
Ciao,
Marc 'BlackJack' Rintsch
--
http://mail.python.org/mailman/listinfo/python-list
().
>>
>> But consider rewriting the following:
>>
>> def table(func, seq):
>> return zip(seq, map(func,seq))
>>
>> table(len, ('', (), []))
>
> table(lambda x:x.__len__(), ('',[],()))
>
> What was the point again ?
Beauti
misunderstand his intention. He wanted to give the
optional third argument of `getattr()` as keyword argument.
Ciao,
Marc 'BlackJack' Rintsch
--
http://mail.python.org/mailman/listinfo/python-list
to stuff them as static methods into classes or even
uglier you see code like ``Spam().spammify(eggs)`` instead of a plain
function call.
And functions are first class objects in Python. That sounds quite OO to
me. You can think of a module with functions as a singleton.
Ciao,
Marc
blocksize * number of blocks math to get
> the % of used space.
Just go ahead and do it:
In [185]: stat = os.statvfs('/')
In [186]: stat.f_bsize
Out[186]: 4096
In [187]: stat.f_blocks
Out[187]: 2622526L
In [188]: stat.f_bsize * stat.f_blocks
Out[188]: 10741866496L
Ciao,
Marc 'BlackJack' Rintsch
--
http://mail.python.org/mailman/listinfo/python-list
e issues aside, I
> think it would be a good idea if built-in functions behaved exactly
> the same as normal functions.
As Steven D'Aprano showed they behave like normal functions. Even pure
Python functions can have arguments without names:
def spam(*args):
pass
Ciao,
Mar
ass the
other local to the function.
> Any examples??
def something(lines):
for line in lines:
print lines
And the call it with the object.
Ciao,
Marc 'BlackJack' Rintsch
--
http://mail.python.org/mailman/listinfo/python-list
)
> CREATE INDEX ind3 ON test USING btree (id2)
> CREATE INDEX ind4 ON test USING btree (w)
> CREATE INDEX ind5 ON test USING btree (d)
This isn't a Python question. You'll get more and probably better
feedback in a group, mailing list or forum dealing with PostgreSQL.
Ciao,
erting the *value* '019'.
Starting to number tables and the need to dynamically create table names is
usually sign of a bad schema design BTW.
Ciao,
Marc 'BlackJack' Rintsch
--
http://mail.python.org/mailman/listinfo/python-list
OK | os.W_OK | os.X_OK)
>
> which explicitly (rather than implicitly) spells it out?
And the equivalent of ``os.chmod(filename, 0777)`` looks like what!?
Ciao,
Marc 'BlackJack' Rintsch
--
http://mail.python.org/mailman/listinfo/python-list
On Sat, 27 Oct 2007 17:57:06 +, [EMAIL PROTECTED] wrote:
> On Oct 27, 6:27 pm, Marc 'BlackJack' Rintsch <[EMAIL PROTECTED]> wrote:
>> On Sat, 27 Oct 2007 17:10:13 +, [EMAIL PROTECTED] wrote:
>> >http://eigenclass.org/hiki/xmpfilter
>> > look
)
> del_tree(subdir)
…and here you are calling the your function recursively which then calls
again `os.walk()` on that subdirectory. That's a little bit too much.
Just use `os.listdir()` (and `os.path.isdir()`) in your recursive function.
>#os.rmdir(path)
>print "Removing: %s" % (path, )
> #--snap
Or `shutil.rmtree()`. :-)
Ciao,
Marc 'BlackJack' Rintsch
--
http://mail.python.org/mailman/listinfo/python-list
tual code, i.e. if the code is wrong it
nonetheless adds assertions that don't fail. I always thought one writes
assertions to test what the code should do and not what it actually does!?
Ciao,
Marc 'BlackJack' Rintsch
--
http://mail.python.org/mailman/listinfo/python-list
while the latter raises an `IndexError`.
Ciao,
Marc 'BlackJack' Rintsch
--
http://mail.python.org/mailman/listinfo/python-list
> Python 3.0a1 (py3k:57844, Aug 31 2007, 16:54:27) [MSC v.1310 32 bit
> (Intel)] on win32
>
>>>> type(0b1)
>
>>>> type(0o1)
>
>>>> type(0x1)
>
>>>> assert 0b1 is 0x1
>>>>
That this doesn't raise `Assertion
#x27;tagA', None, [('tagB', None, ['bobloblaw], None)], None)...
>
> Fact is that my xml is much more deep... and I'm not sure how to
> resolve it
Resolve *what*? The problem isn't clear yet; at least to me. Above you
say what you get. What exactly do you want? Examples please.
Ciao,
Marc 'BlackJack' Rintsch
--
http://mail.python.org/mailman/listinfo/python-list
ong? Thanks in advance.
You feed decoded data to `TidyHTMLTreeBuilder`. As the `encoding`
argument suggests this class wants bytes not unicode. Decoding twice
doesn't work.
Ciao,
Marc 'BlackJack' Rintsch
--
http://mail.python.org/mailman/listinfo/python-list
defined so it should working. Or at least it's not the
problem you think it is. The code above, the dots replaced with nothing,
will of course run "forever" until the stack limit is reached.
Ciao,
Marc 'BlackJack' Rintsch
--
http://mail.python.org/mailman/listinfo/python-list
iterate over the text file line by line and match or
search within the line? Untested:
needle = re.compile(r'create\s+or\s+replace\s+package(\s+body)?\s+',
re.IGNORECASE)
for i, line in enumerate(lines):
if needle.match(line):
print 'match in line %d' % (i + 1)
Ciao,
Marc 'BlackJack' Rintsch
--
http://mail.python.org/mailman/listinfo/python-list
f `int` with the values 1 and 0 it's
possible to replace the dictionary by a list:
tmp = [[], []]
for arg in cls.arguments:
tmp[bool(arg)].append(arg)
return tmp[1], tmp[0]
Maybe that's nicer. Maybe not.
Ciao,
Marc 'BlackJack' Rintsch
--
http://mail.python.org/mailman/listinfo/python-list
itertools import ifilter
classes = set(ifilter(isclass, globals().itervalues()))
Ciao,
Marc 'BlackJack' Rintsch
--
http://mail.python.org/mailman/listinfo/python-list
e:
> lOptional.append(arg)
> return (lMandatory, lOptional)
>
> I think there is a better way, but I can't see how...
Drop the prefixes. `l` is for list? `d` is for what!? Can't be
dictionary because the code doesn't make much sense.
Where is `cls` coming from?
Ciao,
On Tue, 23 Oct 2007 21:51:20 +, mrstephengross wrote:
> Ok, I see how to use issubclass(). How can I get a list of classes
> present in the file?
import module
from inspect import getmembers, isclass
classes = getmembers(module, isclass)
Ciao,
Marc 'BlackJack'
e a way I can find out the classes that have been derived from
> Base?
Take a look at the `issubclass()` function.
Ciao,
Marc 'BlackJack' Rintsch
--
http://mail.python.org/mailman/listinfo/python-list
; class Base:
> def __init__ (self):
> self.foo = Foo()
`Base` has no `foo` attribute but *instances* of `Base` have.
> class Derived(Base):
> def __init__(self):
> Base.__init__(self)
> Base.foo.x = 5
Instances of `Derived` have a `foo` attribute inherited from
d before assignment.
> Isn't the if statement supposed to keep python from going there since if
> they didn't enter any input, the length of the list should just be zero.
Which list? If the branch for ``choice == 1`` isn't executed then the
list will never be created an the name `nums` doesn't exist.
Ciao,
Marc 'BlackJack' Rintsch
--
http://mail.python.org/mailman/listinfo/python-list
On Tue, 23 Oct 2007 11:48:08 +0200, Loic Mahe wrote:
> even shorter:
>
> def funcA(tarray):
> s = min(len(tarray), 3)
> return [2, 3, 4][0:s] + [e for e in funcB(3-s)[0:3-s]]
Why the list comprehension!?
Ciao,
Marc 'Blackjack' Rintsch
--
http:
t_array_length = len(t_array)
remaining_length = len(result) - t_array_length
if t_array_length < len(result):
result = (result[:t_array_length]
+ func_b(remaining_length)[:remaining_length])
return tuple(result)
Ciao,
Marc 'BlackJack' Rintsch
--
http://mail.python.org/mailman/listinfo/python-list
say `is_active`, and a wrapper
that has a property with the same name that returns the value of the
wrapped objects attribute.
Or lazy computation of an attribute. Breaks expectations for the first
access -- long calculation for simple attribute access -- but meets it for
every subsequent access.
501 - 600 of 1508 matches
Mail list logo