Send Python-list mailing list submissions to
python-list@python.org
To subscribe or unsubscribe via the World Wide Web, visit
http://mail.python.org/mailman/listinfo/python-list
or, via email, send a message with subject or body 'help' to
[EMAIL PROTECTED]
You can reach the person managing the list at
[EMAIL PROTECTED]
When replying, please edit your Subject line so it is more specific
than "Re: Contents of Python-list digest..."
Today's Topics:
1. Re: python bug in this list implementation? (Fredrik Lundh)
2. Re: python coding contest (Bengt Richter)
3. Re: python coding contest (Roman Susi)
4. Re: sorting with expensive compares? (Stuart D. Gathman)
5. Re: Timing out arbitrary functions (antti kervinen)
6. Re: python coding contest (Duncan Booth)
7. Re: Patch : doct.merge (Nicolas Lehuen)
8. Re: [EVALUATION] - E04 - Leadership! Google, Guido van
Rossum, PSF (Martin P. Hellwig)
9. getting the status codes from the ftplib module (Alvin A. Delagon)
10. Re: getting the status codes from the ftplib module
(Fredrik Lundh)
Chris Smith wrote:
I've been working on some multi-dimensional lists and I've encountered some
very strange behaviour in what appears to be simple code, I'm using python
2.4.2 and IDLE. If anyone can tell me why it's behaving so strange please
let me know, any improvements to my general coding style are also
appreciated.
code below:
import sys
import copy
grid = []
oGrid = []
sGrid = []
def createGrid():
f = open(r"...sudoku.txt", "rb") ## see attached for the file.
for line in f:
aLine = line.strip().split(',')
if aLine != [""]:
for i in xrange(len(aLine)):
aLine[i] = int(aLine[i])
grid.append(aLine)
at this point, grid contains a list of lists.
oGrid = copy.deepcopy(grid)
if you assign to a name inside a function, that name is considered to be
*local*, unless you specify otherwise. in other words, this doesn't touch
the *global* (module-level) oGrid variable.
sGrid.append(copy.deepcopy(grid))
here you add a list of lists to a list. the result is a list with a single item.
def printGrid():
print "original grid:"
for line in oGrid:
print line #why doesn't this print anything?
because the *global* oGrid is still empty.
print "S grid:"
for line in sGrid:
print line #this prints the grid but the formatting is all over the
place.
because sGrid contains a single item; a copy of your original grid.
print "Iteration grid: "
for line in grid:
print line #works fine!
as expected.
I suggest reading up on list methods and global variables in your favourite
python tutorial.
also read:
http://www.catb.org/~esr/faqs/smart-questions.html#id3001405
</F>
On 27 Dec 2005 09:24:44 GMT, Duncan Booth <[EMAIL PROTECTED]> wrote:
Scott David Daniels wrote:
I definitively need a new algorythm. <g>
And I am sadly stuck at 169. Not even spitting distance from 149 (which
sounds like a non-cheat version).
Throw it away and start again with a fresh (clean) solution. That's what I
did when I'd reached the limit of nested maps and lambdas at 150
characters. I'm now on 134 characters and the solution is very nearly
legible. (Frustratingly, I'm away for the next few days, so I may not get a
chance to submit my solution).
It would be a nice idea to come up with a scoring system which better
reflects Python's ideals. For example, use the parser in Python to count up
various syntactic elements, score 0 for comments, indents, dedents,
newlines, docstrings, 1 for each name or operation used and higher scores
for things like lambda or overly complex expressions.
[23:28] C:\pywk\clp\seven\pycontest_01>py24 test.py
.
--------------------------------------------------------------
Ran 1 test in 0.391s
OK
[23:28] C:\pywk\clp\seven\pycontest_01>wc -lc seven_seg.py
2 136 seven_seg.py
2 lines, 136 chars including unix-style lineseps (is that cheating on windows?)
No imports.
Guess I'll have to try another tack ;-/
Regards,
Bengt Richter
Tim Hochberg wrote:
py pan wrote:
When you guys say 127~150 characters, did you guys mean
usinging test_vectors.py in some way? Or there's no import at all?
No import at all. The shortest solution reported so far is 131
characters. Getting down to 127 is just a guess as to where the lower
bound is likely to be.
Note that in principle it's possible to encode the data for how to
display a digit in one byte. Thus it's at least theoretically possible
to condense all of the information about the string into a string that's
10 bytes long. In practice it turns out to be hard to do that, since a
10 byte string will generally have a representation that is longer than
10 bytes because of the way the escape sequences get printed out. As a
result various people seem to be encoding the data in long integers of
one sort or another. The data is then extracted using some recipe
involving shifts and &s.
-tim
Condensing is good but only as far as code for decompressing is small...
By the way, after I noticed that I program for 2.3, I tried with 2.4 and
get out extra characters thanks for generator _expression_ and .join()
integration. So now I am at 147. Probably a lot of reserve as I have 3
fors... One for just for the purpose of getting a name:
...x.... for x in [scalar]
Probably its time rething solution from scratch...
Roman Susi
On Sat, 24 Dec 2005 15:47:17 +1100, Steven D'Aprano wrote:
On Fri, 23 Dec 2005 17:10:22 +0000, Dan Stromberg wrote:
I'm treating each file as a potentially very large string, and "sorting
the strings".
Which is a very strange thing to do, but I'll assume you have a good
reason for doing so.
I believe what the original poster wants to do is eliminate duplicate
content from a collection of ogg/whatever files with different names.
E.g., he has a python script that goes out and collects all the free music
it can find on the web. The same song may appear on many sites under
different names, and he wants only one copy of a given song.
In any case, as others have pointed out, sorting by MD5 is sufficient
except in cases far less probable than hardware failure - and deliberate
collisions. E.g., the RIAA creates collision pairs of MP3 files where one
member carries a freely redistributable license, and the other a "copy
this and we'll sue your ass off" license in an effort to trap the unwary.
AOP would be a quite elegant way set timeouts for functions, in my
opinion. The nice thing in it is that, in principle, you can write a
single timeout advice code and then wrap it over any function you want
to timeout.
I wrote timeout_advice.py to demonstrate this a couple of years ago
(see http://www.cs.tut.fi/~ask/aspects/aspects.html). It may not
directly solve the problem at hand because it is thought to be used
with a wrap_around implementation that wraps methods in classes rather
than ordinary functions in modules. urllib.URLopener.open is used as an
example in the code. Unfortunately, I still have not implemented the
wrapping for ordinary functions, although it should be straight-forward
with the same idea that is explained in the web page.
Of course, in the real life, timeouts are tricky and dangerous. The
consequences of interrupting a function that is not designed to be
interrupted, or leaving it running in the background after the timeout
(which is what timeout_advice.py does) may be surprising.
-- Antti Kervinen
Christian Tismer wrote:
And then help me to setup a different contest about content -- chris
Count me in.
Here's method 3 :
# Python 2.3 (no generator _expression_)
a.update([(k,v) for k,v in b.iteritems() if k not in a])
# Python 2.4 (with generator _expression_)
a.update((k,v) for k,v in b.iteritems() if k not in a)
It's a bit cleaner but still less efficient than using what's already
in the PyDict_Merge C API. It's even less efficient than method 1 and 2
! Here is the benchmark I used :
import timeit
init = '''a = dict((i,i) for i in xrange(1000) if i%2==0); b =
dict((i,i+1) for i in xrange(1000))'''
t = timeit.Timer('''for k in b:\n\tif k not in a:\n\t\ta[k] =
b[k]''',init)
print 'Method 1 : %.3f'%t.timeit(10000)
t = timeit.Timer('''temp = dict(b); temp.update(a); a = temp''',init)
print 'Method 2 : %.3f'%t.timeit(10000)
t = timeit.Timer('''a.update((k,v) for k,v in b.iteritems() if k not in
a)''',init)
print 'Method 3 : %.3f'%t.timeit(10000)
t = timeit.Timer('''a.merge(b)''',init)
print 'Using dict.merge() : %.3f'%t.timeit(10000)
Here are the results :
Method 1 : 5.315
Method 2 : 3.855
Method 3 : 7.815
Using dict.merge() : 1.425
So using generator expressions is a bad idea, and using the new
dict.merge() method gives an appreciable performance boost (~ x 3.73
here).
Regards,
Nicolas
Ilias Lazaridis wrote:
Martin P. Hellwig wrote:
Ilias Lazaridis wrote:
<cut>
So I guess you volunteer http://www.python.org/psf/volunteer.html ?
I volunteer and contribute already (with a general validity and python
specific analysis)
A mediator should communicate the findings and suggestion (after
verifying them) to the responsibles / community:
http://lazaridis.com/efficiency/process.html#mediator
This would include to pass the relevant ones to the list you've
mentioned:
http://www.python.org/psf/volunteer.html
-
TAG.efficiency.process.mediator
Last time I checked a "mediator" otherwise known to me as a
communication manager, is only effective when he/she is recognized as
authoritative by the participating group _and_ him/herself.
As from other posts I read that the last part is the issue, well since
this is a voluntary bunch of people with a slightly social democratic
architecture you fall back on spokesman and that can be anybody,
including or perhaps even especially you.
The only thing that holds "you" theoretically back is "acknowledged
authority by the participating group _and_ yourself" and of course the
resource for "restricted" information.
For the first part you got my vote, for second, well that should grow
in time.
I'm writing a simple python code that will upload files onto a ftp
server. Everything's fine and working great except that the script I
wrote don't know is an upload is successful or not. Is there a way to
obtain the ftp status codes with this module? Thanks in advance!
Alvin A. Delagon wrote:
I'm writing a simple python code that will upload files onto a ftp
server. Everything's fine and working great except that the script I
wrote don't know is an upload is successful or not. Is there a way to
obtain the ftp status codes with this module? Thanks in advance!
the module raises an exception if something fails. if you didn't get
an exception, everything worked as expected.
most methods, including the storlines and storbinary methods, also
return the status code.
</F>
Thanks of the heads up! I think I found a way storing the result of the storline onto a variable for comparison. ^_^