On Jan 29, 11:22 am, Peter Otten <__pete...@web.de> wrote:
> The name is looked up in the code object. As that is immutable you have to
> make a new one:
[details snipped]
thanks very much! sorry i didn't reply earlier - been travelling.
(also, thanks to any other replies - i'm just reading thro
On Jan 29, 5:37 pm, "Gabriel Genellina"
wrote:
> The decorator module is a very fine addition to anyone's tool set -- but
> in this case it is enough to use the wraps() function from the functools
> standard module.
ah, thanks! i thought something like this existed in the standard
lib, but c
On Jan 29, 11:50 am, exar...@twistedmatrix.com wrote:
> new.function and new.code will let you construct new objects with
> different values (and copying over whichever existing attributes you
> want to preserve).
unfortunately new is deprecated and dropped from 3. i can't see how
the same functi
On Jan 30, 7:17 pm, andrew cooke wrote:
> On Jan 29, 5:37 pm, "Gabriel Genellina"
> wrote:
>
> > The decorator module is a very fine addition to anyone's tool set -- but
> > in this case it is enough to use the wraps() function from the functools
>
On Jan 29, 1:09 pm, Michele Simionato
wrote:
> On Jan 29, 2:30 pm, andrew cooke wrote:
>
> > Is there any way to change the name of the function in an error
> > message? In the example below I'd like the error to refer to bar(),
> > for example (the motivation i
On Sep 21, 10:59 am, Nobody wrote:
> I have a similar question.
>
> What I want: a tokeniser generator which can take a lex-style grammar (not
> necessarily lex syntax, but a set of token specifications defined by
> REs, BNF, or whatever), generate a DFA, then run the DFA on sequences of
> bytes.
Is the third case here surprising to anyone else? It doesn't make
sense to me...
Python 2.6.2 (r262:71600, Oct 24 2009, 03:15:21)
[GCC 4.4.1 [gcc-4_4-branch revision 150839]] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from re import compile
>>> p1 = comp
On Apr 11, 8:12 pm, Lie Ryan wrote:
> In the first case, *python* will unescape the string literal '\x62' into
> letters 'b'. In the second case, python will unescape the double
> backslash '\\' into a single slash '\' and *regex* will unescape the
> single-slash-62 into 'b'. In the third case, *p
On Apr 11, 7:18 pm, Paul McGuire wrote:
[...]
>
> So I would say the surprise isn't that case 3 didn't match, but that
> case 2 matched.
>
> Unless I just don't get what you were testing, not being an RE wiz.
Case 2 is the regexp engine interpreting escapes that appear as
literal strings. It's w
On May 2, 3:54 pm, Andreas Löscher wrote:
> Hi,
> I am looking for an easy to use parser. I am want to get an overview
> over parsing and want to try to get some information out of a C-Header
> file. Which parser would you recommend?
>
> Best,
> Andreas
I develop Lepl - http://www.acooke.org/lepl
Hi,
The latest Lepl release includes an implementation of RFC 3696 - the
RFC that describes how best to validate email addresses and HTTP
URLs. For more information please see http://www.acooke.org/lepl/rfc3696.html
Lepl's main page is http://www.acooke.org/lepl
Because Lepl compiles to regula
> FYI, Fourthought's PyXML has a module called uri.py that contains
> regexes for URL validation. I've over a million URLs (harvested from
> the Internet) through their code. I can't say I checked each and every
> result, but I never saw anything that would lead me to believe it was
> misbe
This is a bit embarassing, but I seem to be misunderstanding how \b
works in regexps.
Please can someone explain why the following fails:
from re import compile
p = compile(r'\bword\b')
m = p.match(' word ')
assert m
My understanding is that \b matches a space a
On May 29, 11:24 am, Duncan Booth
wrote:
> andrew cooke wrote:
> > Please can someone explain why the following fails:
>
> > from re import compile
>
> > p = compile(r'\bword\b')
> > m = p.match(' word ')
> >
As ever, I guess it's most likely I've misunderstood something, but in
Python 2.6 lookback seems to actually be lookahead. All the following
tests pass:
from re import compile
assert compile('(a)b(?<=(?(2)x|c))(c)').match('abc')
assert not compile('(a)b(?<=(?(2)b|x))(c)'
On Jul 5, 8:56 pm, MRAB wrote:
> andrew cooke wrote:
> > What am I missing this time? :o(
> Nothing. It's a bug. :-(
Sweet :o)
Thanks - do you want me to raise an issue or will you?
Cheers,
Andrew
--
http://mail.python.org/mailman/listinfo/python-list
http://bugs.python.org/issue9179
On Jul 5, 9:38 pm, MRAB wrote:
> andrew cooke wrote:
> > On Jul 5, 8:56 pm, MRAB wrote:
> >> andrew cooke wrote:
> >>> What am I missing this time? :o(
> >> Nothing. It's a bug. :-(
>
> > Sweet :o)
>
&
I have some (library) code where an exception is caught and, since the
underlying cause is rather obscure, a different exception is raised that
more clearly explains the issue to the caller.
However, when printed via format_exc(), this new exception still has the
old exception attached via the me
David Bolen wrote:
> "andrew cooke" writes:
>
>> However, when printed via format_exc(), this new exception still has
the old exception attached via the mechanism described at
>> http://www.python.org/dev/peps/pep-3134/ (this is Python 3.0).
>
> If you're
On Aug 5, 10:46 am, "Martin P. Hellwig"
wrote:
> Hi List,
>
> On several occasions I have needed (and build) a parser that reads a
> binary piece of data with custom structure. For example (bogus one):
>
> BE
> +-+-+-+-+--++
> | Version | Command
Is there a way to make this work (currently scope and join are
undefined at runtime when the inner class attributes are defined):
class _StreamFactory(object):
@staticmethod
def __call__(lines, source, join=''.join):
class Line(object):
__source = source
correction: "source" and "join" are undefined. Sorry, Andrew
--
http://mail.python.org/mailman/listinfo/python-list
On Aug 12, 1:51 am, James Stroud
wrote:
> andrew cooke wrote:
> > Is there a way to make this work (currently scope and join are
> > undefined at runtime when the inner class attributes are defined):
>
> > class _StreamFactory(object):
>
> > @staticmethod
&
On Aug 12, 7:49 am, andrew cooke wrote:
> On Aug 12, 1:51 am, James Stroud
> wrote:
>
>
>
> > andrew cooke wrote:
> > > Is there a way to make this work (currently scope and join are
> > > undefined at runtime when the inner class attributes are define
On Aug 12, 8:52 am, Dave Angel wrote:
> Supply us with just enough source code to actually try it, give the full
> error message including traceback, and tell us what you expected to
> see. Also tell us Python version (sys.version)
>
> So far you've done none of these. When I try the following
On Sep 19, 9:34 pm, Peng Yu wrote:
> On Sep 19, 6:05 pm, Robert Kern wrote:
> >http://nedbatchelder.com/text/python-parsers.html
>
> This is more a less just a list of parsers. I would like some detailed
> guidelines on which one to choose for various parsing problems.
it would be simpler if you
On Sep 20, 8:11 am, Peng Yu wrote:
> On Sun, Sep 20, 2009 at 6:50 AM, andrew cooke wrote:
> > On Sep 19, 9:34 pm, Peng Yu wrote:
> >> On Sep 19, 6:05 pm, Robert Kern wrote:
> >> >http://nedbatchelder.com/text/python-parsers.html
>
> >> This is more a
On Sep 19, 11:39 pm, TerryP wrote:
[...]
> For flat data, simple unix style rc or dos style ini file will often
> suffice, and writing a parser is fairly trivial; in fact writing a
[...]
python already includes parsers for ".ini" configuration files.
[...]
> The best way to choose a parser, is e
One word of warning - the documentation for that format says at the
beginning that it is compressed in some way. I am not sure if that
means within some program, or on disk. But most parsers will not be
much use with a compressed file - you will need to uncompress it first.
--
http://mail.pytho
> The file size of a wig file can be very large (GB). Most tasks on this
> file format does not need the parser to save all the lines read from
> the file in the memory to produce the parsing result. I'm wondering if
> pyparsing is capable of parsing large wig files by keeping only
> minimum requir
also, parsing large files may be slow. in which case you may be
better with a non-python solution (even if you call it from python).
your file format is so simple that you may find a lexer is enough for
what you want, and they should be stream oriented. have a look at the
"shlex" package that i
> I don't quite understand this point. If I don't use a parser, since
> python can read numbers line by line, why I need a lexer package?
for the lines of numbers it would make no difference; for the track
definition lines it would save you some work.
as you said, this is a simple format, so the
> So for the track definition, using a lexer package would be better
> than using regex in python, right?
they are similar. a lexer is really just a library that packages
regular expressions in a certain way. so you could write your own
code and you would really be writing a simple lexer. the a
On Sep 20, 9:12 am, andrew cooke wrote:
> ps is there somewhere can download example files? this would be
> useful for my own testing. thanks.
i replied to a lot of your questions here; any chance you could reply
to this one of mine?
the wig format looks like it could be a good test fo
On Sep 20, 3:16 pm, Peng Yu wrote:
> On Sun, Sep 20, 2009 at 1:35 PM, andrew cooke wrote:
> > On Sep 20, 9:12 am, andrew cooke wrote:
> >> ps is there somewhere can download example files? this would be
> >> useful for my own testing. thanks.
>
> > i rep
This is a bit vague, I'm afraid, but is there any way for me to take
code like:
a = Foo()
beta = Bar()
and somehow attach the string "a" to the Foo instance and "beta" to
the Bar instance. At some later point in the program I want to be
able to look at the Bar instance and say to the user
For example, I assume it's possible to somehow access the dictionary
for the current block, but I can't see how to do this after
assignment. If I do it in the Foo constructor, for example, "a" will
not yet be bound.
On Sep 23, 8:15 pm, andrew cooke wrote:
> This is a bit
On Sep 23, 8:40 pm, "Rhodri James"
wrote:
> eggs[42] = Foo()
> beans['spam'] = Foo()
> chips.spam = Foo()
> spam[eggs.beans['chips']] = Foo()
> spam.append(Foo())
these are valid points, but in practice the main use (for the
restricted application i care about) is si,ple variables, and this is
an
On Sep 23, 10:11 pm, Dave Angel wrote:
> This comes up periodically in this list, and the answer is always
> something like: you can't get there from here.
Well, I'm both flexible and desperate, so this is a possible route
(perhaps near enough):
import sys
class Foo(object):
def __rlshif
for the record, googling for "f_back.f_locals" reveals a wide variety
of similar hacks and also a cleaner way to access the current frame:
inspect.currentframe()
--
http://mail.python.org/mailman/listinfo/python-list
On Sep 24, 7:12 am, Carl Banks wrote:
> with capture_changed_bindings() as changed:
> b = 5
> c = 4
> d = 6
> print changed
>
> test()
>
> Quick and dirty, not robust at all. But you get the idea.
>
> Carl Banks
brilliant. using the with context is an excellent i
On Sep 24, 5:20 am, Steven D'Aprano
wrote:
> Speaking as a user (although not of Andrew's domain specific language),
> I'd like to say to developers PLEASE PLEASE PLEASE don't try to "help me"
> with half-baked unreliable solutions that only work sometimes.
>
> There's few things worse than unreli
301 - 342 of 342 matches
Mail list logo