gt; look?
I recommend you look in the "Modules" subdirectory of the Python source
tree.
Cheers,
-M
--
Michael J. Fromberger | Lecturer, Dept. of Computer Science
http://www.dartmouth.edu/~sting/ | Dartmouth College, Hanover, NH, USA
--
http://mail.python.org/mailman/listinfo/python-list
anning Parsing And Rewriting Kit)
http://pages.cpsc.ucalgary.ca/~aycock/spark/
You might also find the following an interesting read, if this sort of
thing interests you:
http://www.python.org/sigs/parser-sig/towards-standard.html
Cheers,
-M
--
Michael J. Fromberger | Lecturer
for the Sep.
1996 issue of Dr. Dobbs, you might have a look:
http://www.dogma.net/markn/articles/bwt/bwt.htm
I hope this helps you get started.
-M
--
Michael J. Fromberger | Lecturer, Dept. of Computer Science
http://www.dartmouth.edu/~sting/ | Dartmouth College, Hanover, NH, USA
--
http://mail.python.org/mailman/listinfo/python-list
In article <[EMAIL PROTECTED]>,
[EMAIL PROTECTED] wrote:
> Michael J. Fromberger:
> > I can send you a Python implementation I wrote, if you like; but if
> > you're interested in better understanding how the transform works,
> > I would recommend you try
"j test" instruction. Even if forward conditional
jumps are bad for your particular architecture, this method avoids the
problem neatly.
Personally, I'd be pretty suspicious of the quality of a compiler that
produced radically different code for these two constructs without s
ccur in ALL positions, not just the beginning and the end.
Cheers,
-M
--
Michael J. Fromberger | Lecturer, Dept. of Computer Science
http://www.dartmouth.edu/~sting/ | Dartmouth College, Hanover, NH, USA
--
http://mail.python.org/mailman/listinfo/python-list
exp = re.compile('|'.join(re.escape(x) for x in r.keys()))
. return exp.sub(lambda m: r.get(m.group()), s)
Cheers,
-M
--
Michael J. Fromberger | Lecturer, Dept. of Computer Science
http://www.dartmouth.edu/~sting/ | Dartmouth College, Hanover, NH, USA
--
http://mail.python.org/mailman/listinfo/python-list
u draw the
line? Do you really want to hard-code user opinions into the language?
Right now, we have a nice, simple yet effective mechanism for
controlling the contents of our namespaces. I don't think this would be
a worthwhile change. -1.
-M
--
Michael J. Fromberger | Lecturer, Dept. of Computer Science
http://www.dartmouth.edu/~sting/ | Dartmouth College, Hanover, NH, USA
--
http://mail.python.org/mailman/listinfo/python-list
aying you
couldn't deal with this, but it rules out some of the more obvious ways
of detecting and automatically handling this kind of substitution.
Naturally, you might well ask, "why would you do such a fool thing?" To
this I can only respond: "Never underestimate the inge
ed back to the
> originals.
>
> It would be great if there exists a library already written to do this,
> and if there is, can somebody please point me to it??
I recommend you investigate PyCrypto:
http://www.amk.ca/python/code/crypto
http://sourceforge.net/projects/pycrypto
gt; enc = cipher.new("abcdefgh")
>>> dec = cipher.new("abcdefgh")
>>> x = enc.encrypt("This is some random text")
>>> x
"\x05o\xd5XH|\xa4\xfc\xf7z\xecd\xe92\xfb\x05rR'\xbf\xc0F\xfc\xde"
>>> y = dec.decrypt(x)
>&
, "bar")
It's not the most elegant solution in the world. This code does NOT
deal with the problem of commented text. I think it will handle triple
quotes, though I haven't tested it on that case.
At any rate, I hope it may help you get started.
Cheers,
-M
--
Michael J. Fromberger | Lecturer, Dept. of Computer Science
http://www.dartmouth.edu/~sting/ | Dartmouth College, Hanover, NH, USA
--
http://mail.python.org/mailman/listinfo/python-list
## ==> False
>>> lloc = "foo!"
>>> print isset('lloc')## ==> True
Perhaps this is not the most elegant solution, but I believe it handles
scoping correctly.
-M
--
Michael J. Fromberger | Lecturer, Dept. of Computer Science
http://www.dartmouth.edu/~sting/ | Dartmouth College, Hanover, NH, USA
--
http://mail.python.org/mailman/listinfo/python-list
) = 4 * atan(1/5) - atan(1/239)
Or, pi = 16 * atan(1/5) - 4 * atan(1/239). The Taylor series will
converge more quickly for atan(1/5) and atan(1/239).
(LaTeX: \mathrm{atan}(x) = \sum_{i=0}^\infty\frac{(-1^i)x^i}{2i+1})
Cheers,
-M
--
Michael J. Fromberger | Lecturer, Dept. of Computer
It seems to me that one
should not have to "know" (i.e., write down the names of) the ancestors
of C in order to dispatch to superclass methods in D, since C and D
share no common ancestors south of object.
Is there a better (i.e., more elegant) way to handle the case
In article <[EMAIL PROTECTED]>,
"Michele Simionato" <[EMAIL PROTECTED]> wrote:
> Michael J. Fromberger ha scritto:
>
> > Consider the following class hierarchy in Python:
> >
>
> > Is there a better (i.e., more elegant) way to handle the ca
stuctor it is an initializer
Yes, you're right; I apologize for the imprecision. However, for the
purposes of this example, the distinction is irrelevant.
Cheers,
-M
--
Michael J. Fromberger | Lecturer, Dept. of Computer Science
http://www.dartmouth.edu/~sting/ | Dartmouth Colle
_init__(self, ...) form is probably the best
solution!
Thanks for your feedback.
Cheers,
-M
--
Michael J. Fromberger | Lecturer, Dept. of Computer Science
http://www.dartmouth.edu/~sting/ | Dartmouth College, Hanover, NH, USA
--
http://mail.python.org/mailman/listinfo/python-list
Or, if you
really want to use one of the existing exception types, then perhaps you
can catch the exceptions from functions called by f, within f itself,
and raise some other error (or suppress the errors, if appropriate).
Cheers,
-M
--
Michael J. Fromberger | Lecturer, Dep
GNU readline I installed via Darwin ports. The Tk
headers allow pythonw to build properly.
Having configured, I built and installed via:
make
sudo make frameworkinstall
I hope this may be helpful to you.
-M
--
Michael J. Fromberger | Lecturer, Dept. of Computer Science
http://www.dartmouth.edu/~sting/ | Dartmouth College, Hanover, NH, USA
--
http://mail.python.org/mailman/listinfo/python-list
m with Unicode support
in the MacOS build of Python 2.5.
For reference, I have done a framework build of Python, and it seems to
work fine for everything else I have tried. Do you have any idea what
might be causing this trouble? I'd be grateful for your insights.
Cheers,
-M
--
Michael J
on, as the "anti-Perl," is heavily invested in maintaining Order.
> >
> > In the state of the onion address?
> >
> > http://www.perl.com/pub/a/2006/09/21/onion.html
>
> There is also this:
> 'But I think the basic Perl paradigm is "Whatever-orie
option is to use the .sort() method of a list:
Emails.sort(key = lambda s: list(reversed(s.split('@'
The "key" parameter specifies how to obtain a sort key from each element
in the source list.
Cheers,
-M
--
Michael J. Fromberger | Lecturer, Dept. of Computer Science
http://www.dartmouth.edu/~sting/ | Dartmouth College, Hanover, NH, USA
--
http://mail.python.org/mailman/listinfo/python-list
]]) for k in dict1 if dict1[k] in dict2)
Cheers,
-M
--
Michael J. Fromberger | Lecturer, Dept. of Computer Science
http://www.dartmouth.edu/~sting/ | Dartmouth College, Hanover, NH, USA
--
http://mail.python.org/mailman/listinfo/python-list
ctly once, and pos is its index in the
original sequence. This implementation traverses the input sequence
exactly once, and requires storage proportional to the length of the
input.
-M
--
Michael J. Fromberger | Lecturer, Dept. of Computer Science
http://www.dartmouth.edu/~sting/
value = d.get('sex', 'unknown')
This accomplishes what your above code does, using a method of the
built-in dict object.
If you also wish to ADD the new value to the dictionary, you may also
use the following:
value = d.setdefault('sex', 'unknown')
descendants also behave in this manner, as do the
AND and OR of Lisp or Scheme. It is possible that beginners may find it
a little bit confusing at first, but I believe such confusion is minor
and easily remedied.
Cheers,
-M
--
Michael J. Fromberger | Lecturer, Dept. of Computer Science
http://www.dartmouth.edu/~sting/ | Dartmouth College, Hanover, NH, USA
--
http://mail.python.org/mailman/listinfo/python-list
"abc", and the
result shows you only the last occurrence of the matching.
Compare this with the following:
] import re
] m = re.match('([abc]+)', 'abc')
] m.groups()
=> ('abc',)
I suspect the latter is what you are after.
Cheers,
-M
--
Michael J. Fromberger | Lecturer, Dept. of Computer Science
http://www.dartmouth.edu/~sting/ | Dartmouth College, Hanover, NH, USA
--
http://mail.python.org/mailman/listinfo/python-list
ile descriptor, it
does not have a convenient way to obtain the file's name. However, you
might also want to look at the TemporaryFile and NamedTemporaryFile
classes in the tempfile module -- these expose a file-like API,
including a .name attribute.
Assuming tempfile.mkstemp()
p://newcenturycomputers.net/projects/gdmodule.html>
I do not know, however, whether or not the Python wrapper supports the
animated GIF portions of the library. You'll probably have to do some
digging.
Cheers,
-M
--
Michael J. Fromberger | Lecturer, Dept. of Computer Scie
,
] import errno
] errno.errorcode[35]
'EDEADLOCK'
Note that some codes have multiple names (e.g., EAGAIN and EWOULDBLOCK)
so that this lookup may not return exactly the name you're expecting.
Cheers,
-M
--
Michael J. Fromberger | Lecturer, Dept. of Computer Sci
count = {}
for elt in lst:
count[elt] = count.get(elt, 0) + 1
return [elt for elt in lst if count[elt] == 1]
This solution is not particularly tricky, but it has the nice properties
that:
1. It works on lists of any hashable type, not just strings,
2. It preserves the order of the u
t by using time.strptime(), e.g.,
import time
def month2int(mName):
return time.strptime(mName, '%b').tm_mon # parses "short" names
Without knowing anything further about your needs, I would probably
suggest the latter simply because it makes the hard work be somebody
else's problem.
Cheers,
-M
--
Michael J. Fromberger | Lecturer, Dept. of Computer Science
http://www.dartmouth.edu/~sting/ | Dartmouth College, Hanover, NH, USA
--
http://mail.python.org/mailman/listinfo/python-list
.:
test1 = '''
[New client].
|-Invoices
|-Offers
|--Denied
|--Accepted
|---Reasons
|---Rhymes
|-Delivery notes
'''
from StringIO import StringIO
result = parse_folders(StringIO(test1))
As the documentation suggests, the result is a nested dictionary
structure, representing the folder structure you encoded. I hope this
helps.
Cheers,
-M
--
Michael J. Fromberger | Lecturer, Dept. of Computer Science
http://www.dartmouth.edu/~sting/ | Dartmouth College, Hanover, NH, USA
--
http://mail.python.org/mailman/listinfo/python-list
t; [New client].
>
> Won't work with the dot on the end.
My mistake. The period was a copy-and-paste artifact, which I missed.
Cheers,
-M
--
Michael J. Fromberger | Lecturer, Dept. of Computer Science
http://www.dartmouth.edu/~sting/ | Dartmouth College, Hanover, NH, USA
--
http://mail.python.org/mailman/listinfo/python-list
range itself is not written as a generator, it does
return a generator as its result. The syntax is like that of list
comprehensions; see:
<http://docs.python.org/ref/genexpr.html>
Cheers,
-M
--
Michael J. Fromberger | Lecturer, Dept. of Computer Science
http://www.dartmouth.edu/~sting/ | Dartmouth College, Hanover, NH, USA
--
http://mail.python.org/mailman/listinfo/python-list
"]
>
> thanks,
>
> aine
Try:
lst.sort(key = lambda s: int(s))
Assuming, of course, that "lst" is your original list; this will sort it
in place. Also, you should probably read about the "sorted" function
here:
<http://docs.python.org/lib/built-in-funcs.
def marked(self):
| return self._end
And finally, matching:
| class matching (marker):
| def __init__(self, seq, func):
| super(matching, self).__init__(seq)
| self._func = func
| self._mark = False
|
| def next(self):
| out = super(matching, sel
an you now see how you would re-write "fact3" into legal Python code,
using this equivalence? Once you have done so, you will also be able to
get rid of the extra accumulating parameter, and then you will have what
you wanted.
I hope this helps.
Cheers,
-M
--
Michael J. Fromber
n,
<http://docs.python.org/lib/built-in-funcs.html>
Look near the bottom of the page.
Example:
zip([1,2,3], [4,5,6], [7,8,9])
==> [(1, 4, 7), (2, 5, 8), (3, 6, 9)]
Cheers,
-M
--
Michael J. Fromberger | Lecturer, Dept. of Computer Science
http://www.dartmouth.edu/~st
*v**v = 2**2**2**2 = 65536
> >>>
>
> I would expect 2**2**2**2 to be 256
Python's ** operator associates to the right, not to the left; thus,
2 ** 2 ** 2 ** 2
... really means
2 ** (2 ** (2 ** 2))
... and not
((2 ** 2) ** 2) ** 2
... as you seem to expect. As
> [a,1,b,2,c,3] as the result.
>
> I've been searching around but I can't seem to find a good example.
Here's one possibility:
list(reduce(lambda s, t: s + t, zip(L1, L2), ()))
-M
--
Michael J. Fromberger | Lecturer, Dept. of Computer Science
http://www
regular expression
operators if you wanted. The basic problem isn't all that hard to
solve, though the full generality of the re module's input syntax is far
more expressive than truly "regular" expressions from language theory.
Cheers,
-M
--
Michael J. Fromberger | Lecturer, Dept. of Computer Science
http://www.dartmouth.edu/~sting/ | Dartmouth College, Hanover, NH, USA
--
http://mail.python.org/mailman/listinfo/python-list
y = datetime.today()
yesterday = today - timedelta(1)
# See the .month, .day, and .year fields of yesterday
Cheers,
-M
--
Michael J. Fromberger | Lecturer, Dept. of Computer Science
http://www.dartmouth.edu/~sting/ | Dartmouth College, Hanover, NH, USA
--
http://mail.python.org/mailman/listinfo/python-list
44 matches
Mail list logo