_hash
--Scott David Daniels
scott.dani...@acm.org
--
http://mail.python.org/mailman/listinfo/python-list
Li Han wrote:
But what repr() do remain a black hole!
Han
Try: print repr(repr("'"))
that might enlighten you.
--
http://mail.python.org/mailman/listinfo/python-list
.
if discriminant: # two results
return ((-b - discriminant) / (2 * a),
(-b + discriminant) / (2 * a))
else: # a single result (discriminant is zero)
return (-b / (2 * a),)
--Scott David Daniels
scott.dani...@acm.org
--
http://mail.python.org/mailman/listinfo
% (
type(self).__name__, len(self))
(3.0):
class HiddenList(list):
def __repr__(self):
return '<{0} object: length={1}>'.format(
type(self).__name__, len(self))
--Scott David Daniels
scott.dani...@acm.org
--
http://mail.python.org/mailman/listinfo/python-list
ow if they cannot get
through in two hours.
--Scott David Daniels
scott.dani...@acm.org
--
http://mail.python.org/mailman/listinfo/python-list
Tim Rowe wrote:
2008/12/18 Scott David Daniels :
def quadsolve(a, b, c):
try:
discriminant = sqrt(b**2 - 4 * a * c)
The discriminant of a quadratic is more usually just the b**2 - 4 * a
* c part, not the square root of it. Testing that for negative, zero
or positive avoids the need
Joel Hedlund wrote:
Scott David Daniels wrote:
Perhaps your hash function could be something like:
I'm not sure I understand what you're suggesting.
/Joel
Sorry, a half-thought out idea based on the fact that you wanted a
consistent hash for a varying dictionary. The given
but for internationalization, you can change the format
string to take args in a different order if, for example,
French messages want modifiers on one side and English on the other.
The code can stay the same, while only the text used to do the
formatting must change.
--Scott David Daniels
scott.
ode solves your problems.
--Scott David Daniels
scott.dani...@acm.org
--
http://mail.python.org/mailman/listinfo/python-list
n 2.x)
And, in fact, a dictionary iterates its keys, so:
k1 = set(dict1)
works in 2.4, 2.5, 2.6, and 3.0
--Scott David Daniels
scott.dani...@acm.org
--
http://mail.python.org/mailman/listinfo/python-list
rvalues
print v
For extra credit, explain why values is better.
--Scott David Daniels
scott.dani...@acm.org
--
http://mail.python.org/mailman/listinfo/python-list
o from id to object, the whole idea of garbage
collection and reference counts would fly out the window, leading to
nasty crashes (or you might get to an object that is the re-used id of
an older object).
--Scott David Daniels
scott.dani...@acm.org
--
http://mail.python.org/mailman/listinfo/python-list
Bruno Desthuilliers wrote:
... Now improvements are always welcomes, and if you compare 1.5.2 with
2.5.1, you'll find out that the core developpers did improve Python's
perfs.
Cool, palindromic inverses as compatible versions!
--
http://mail.python.org/mailman/listinfo/python-list
g the DOS
Box on Windows.
Absolutely right. Vy the way, naming your "main" program file
something.pyw, rather than something.py is one of the ways ro do this.
--Scott David Daniels
scott.dani...@acm.org
--
http://mail.python.org/mailman/listinfo/python-list
could replace the __str__ function with:
def __str__(self):
return self.address or "NULL"
--Scott David Daniels
scott.dani...@acm.org
--
http://mail.python.org/mailman/listinfo/python-list
ot;))
root = math.sqrt(value)
print('root(%s) == %s' % (value, root))
I avoid using single-letter variables except where I know the types
from the name (so I use i, j, k, l, m, n as integers, s as string,
and w, x, y, and z I am a little looser with (but usually float or
complex).
--Scott David Daniels
scott.dani...@acm.org
--
http://mail.python.org/mailman/listinfo/python-list
specifically Numpy kind of answer is:
import numpy
a = numpy.array([0, 1, 2])
print a * 3
-Scott
--
http://mail.python.org/mailman/listinfo/python-list
y([1, 2, 3]) + numpy.array([2, 3, 4])
--Scott David Daniels
scott.dani...@acm.org
--
http://mail.python.org/mailman/listinfo/python-list
ing python
lists, you are stuck with extracting data element by element from
its Python language wrap.
--Scott David Daniels
scott.dani...@acm.org
--
http://mail.python.org/mailman/listinfo/python-list
n anyway.
Right, but why bother to do the conversion in C where you'll have to
fiddle with refcounts and error propogation? convert in python, and
go to the underlying data in C.
--Scott David Daniels
scott.dani...@acm.org
--
http://mail.python.org/mailman/listinfo/python-list
John Machin wrote:
On Dec 29, 5:01 pm, scsoce wrote:
I have a function return a reference,
Stop right there. You don't have (and can't have, in Python) a
function which returns a reference that acts like a pointer in C or C+
+. Please tell us what manual, tutorial, book, blog or Usenet postin
but each corresponding value is incorrectly the default of 0.
What am I doing wrong?
How is this code supposed to count?
--Scott David Daniels
scott.dani...@acm.org
--
http://mail.python.org/mailman/listinfo/python-list
how your TCP/IP packets leave your machine, there is no guarantee
they will reach the destination in the same clumps. It is the stream,
and not the packets, that is provided by TCP/IP.
--Scott David Daniels
scott.dani...@acm.org
--
http://mail.python.org/mailman/listinfo/python-list
David Lemper wrote:
... Python. Using version 3.0
# script23
from array import array
< see failed initialization attempts below >
tally = array('H',for i in range(75) : [0])
tally = array('H',[for i in range(75) : 0])
tally = array('H',range(75) : [0])
tally = array('H',range
;> p = Image.open('~/VPython.png')
>>> r, g, b = p.split()
>>> q = Image.merge('RGB', [b, r, g])
>>> q.save('~/VPython1.png')
Should be plenty fast.
Read the PIL docs before rolling your own solutions.
--Scott David Daniels
scott.dani...@acm.org
--
http://mail.python.org/mailman/listinfo/python-list
_time
then use things like:
print elapsed
print elapsed.seconds
...How do I get the 0.141000 out of that or any time object ?
On line docs are arcane to a novice.
Try this:
print dir(elapsed)
The answer should become obvious.
--Scott David Daniels
scott.dani...@ac
sking your question you might have found the answer.
Perhaps I am being too cranky this morning.
--Scott David Daniels
scott.dani...@acm.org
--
http://mail.python.org/mailman/listinfo/python-list
John Machin wrote:
On Jan 8, 6:23 am, Scott David Daniels wrote:
...some stuff perhaps too cranky...
Have you read the entire time module document? If so, which functions
in that module take strings as arguments? then even more cranky stuff...
Indeed. Be not cranky at clueless bludgers
.
(4) You could give us a clue about your operating environment.
(To wit: os, version, python version)
A printer is nothing Python has or controls, it is a standard thing for
a computer system, so details about your computing environment are
necessary in order to give you good
ave needed validation is in setting callbacks, since
the callback typically gets called asynchronously, and I have
trouble discovering why those things blew up. If I can, I manage
to try the callback once first, hoping for an early explosion.
--Scott David Daniels
scott.dani...@acm.org
--
http://mail.python.org/mailman/listinfo/python-list
by parameter %r.' % (order_by,))
if not:
raise ValueError('Bad order_by = %r (should be in %r).' % (
order_by, ['asc', 'desc']))
--Scott David Daniels
scott.dani...@acm.org
--
http://mail.python.org/mailman/listinfo/python-list
rchive by looking at the start of the file is that the zip file
format is meant to allow you to append a zip file to another file (such
as an executable) and treat the combination as an archive.
--Scott David Daniels
scott.dani...@acm.org
--
http://mail.python.org/mailman/listinfo/python-list
gh_bit((1<<587)-1)
587
By the way, I wrote my response before any replies had happened; it was
not a correction to your post.
--Scott David Daniels
[EMAIL PROTECTED]
--
http://mail.python.org/mailman/listinfo/python-list
'] = 20
>>> base['Nebraska']['Wabash']['Newville']['Math']['curr'] += 1
>>> base['Nebraska']['Wabash']['Newville']['Math']['curr']
1
>>> base['Nebraska']['Wabash']['Newville']['English']['curr']
0
--Scott David Daniels
[EMAIL PROTECTED]
--
http://mail.python.org/mailman/listinfo/python-list
=== end docpicture ===
Or similar. I'm sure people will cope, especially since it should be
relatively rare.
or you could even use:
'''
1234567890ABCDEF...
'''
A comment _not_ a docstring (only found by scanning the source).
which is ea
Stefan Behnel wrote:
You should take a look at Cython, which translates Python code to C.
Also take a gander at RPython in the PyPy project.
It is a restricted subset of Python on top of which they implement
Python.
--Scott David Daniels
[EMAIL PROTECTED]
--
http://mail.python.org/mailman
miss it. Each major version change (2.3.X -> 2.4.X,
2.4.X -> 2.5.X, ...) changes the Python VM and internals. There is no
way below Python source (.pyc, .pyo, or .pyd) to stay compatible. That
is why Python projects offer code in Python version-specific packages.
--Scott David Dan
in do_nets([['a', 'b'], ['c', 'd'], ['e', 'f'], ['a', 'g'],
['e', 'k'], ['c', 'u'], ['b', 'p']]):
print group
--Scott David Daniels
[EMAIL PROTECTED]
--
http://mail.python.org/mailman/listinfo/python-list
:
break
heapq.heappush(pending, command)
queue = Queue.Queue()
thread.thread.start_new_thread(queue)
queue.put((time.time() + dt, callable, args, {}))
...
--Scott David Daniels
[EMAIL PROTECTED]
--
http://mail.python.org/mailman/listinfo/python-list
Scott David Daniels wrote:
def time_server(commands):
'''Process all scheduled operations that arrive on queue commands'''
...
queue = Queue.Queue()
thread.thread.start_new_thread(queue)
> queue.put((time.time() + dt, callable, args, {}))
> ...
A
oing after, and I just had the None
in there so my tests could stop gracefully (in fact I printed
the leftover queue when I was testing).
--Scott David Daniels
[EMAIL PROTECTED]
--
http://mail.python.org/mailman/listinfo/python-list
D wrote:
Hello,
How can one exclude a directory (and all its subdirectories) when
running os.walk()?
Thanks,
Doug
for base, dirs, files in os.walk('wherever'):
if 'RCS' in dirs:
dirs.remove('RCS')
As described in the os.walk docs.
--Scott
#x27;
home, final = os.path.split(canonical(forbidden))
for base, dirs, files in os.walk('wherever'):
if final in dirs and home == canonical(base):
dirs.remove(final)
--Scott David Daniels
[EMAIL PROTECTED]
--
http://mail.python.org/mailman/listinfo/python-list
tif")
w, h = im.size
im.thumbnail((600, h * 600 // w),
Image.ANTIALIAS).save("tmp/sho20080901.png")
--Scott David Daniels
[EMAIL PROTECTED]
--
http://mail.python.org/mailman/listinfo/python-list
with:
@watch
def somefun(arg, defarg=1):
...
...
Finally record_* could write to a data structure (using bits like
function.__name__, and f.__module__, and possibly goodies from inspect).
Then you wrap your actual code start with something like:
try:
main(...)
finally:
--
oscilloscope traces shifting up and down.
If there wasn't a metal mask over the oscilloscope with marks where
the bits were, we'd have been in a world of hurt.
--Scott David Daniels
[EMAIL PROTECTED]
--
http://mail.python.org/mailman/listinfo/python-list
of what happens after SystemExit leaves the
__main__ module.
--Scott David Daniels
[EMAIL PROTECTED]
--
http://mail.python.org/mailman/listinfo/python-list
from.]
(2) give system name and version and python version info.
And finally (hoping it doesn't reward you too much for skipping steps):
Look in the time module documents for localtime, gmtime, and strftime.
--Scott David Daniels
[EMAIL PROTECTED]
--
http://mail.python.org/mailman/lis
Mark wrote:
Thanks I tested your solution and that works.
One of the things that didn't work was
for chunk in myfile.read(10):
info1, info2, info3 = struct.unpack('
this code python interprets as:
data = myfile.read(10)
for chunk in data:
.
--Scott David Dani
AEB wrote:
Hello, my supervisor has requested that I write a program to display
2D waves in 3D using Python. Basically I have a time series file that
has the heights of the wave over time steps, and I want to extrude
these waves lengthwise so that they appear in a 3D manor. I am not
very famili
ou
may get more.
--Scott David Daniels
[EMAIL PROTECTED]
--
http://mail.python.org/mailman/listinfo/python-list
ster per-repetition (blending in to your use-case):
import string
SEP = string.maketrans('abc \t', ' ')
...
parts = 'whatever, abalone dudes'.translate(SEP).split()
print parts
['wh', 'tever,', 'lone', 'dudes']
--Scott David Daniels
[EMAIL PROTECTED]
--
http://mail.python.org/mailman/listinfo/python-list
g in enumerate(args):
... print i, arg
...
>>> foo(1,2)
0 1
1 2
>>> foo((1,2)) # these parens are pretty important :)
0 (1, 2)
pedantically-grinning-ducktyping-and-running-ly yers,
I'll see your pedantry and raise you one:
>>> foo()
>>> foo
d live
on in a cache. For this (and similar caching reasons), what you want
to see is that memory doesn't grow in an unbounded way.
--Scott David Daniels
[EMAIL PROTECTED]
--
http://mail.python.org/mailman/listinfo/python-list
dle's improper use of the
format_warning and show_warning stuff turns the waning into an error.
--Scott David Daniels
[EMAIL PROTECTED]
--
http://mail.python.org/mailman/listinfo/python-list
nse, but in this case MATLAB seems easier and no
less readable. That said, I know better than for a newbie like me to
question syntax issues.
If you are using numpy, you may find found the following link useful:
http://www.scipy.org/NumPy_for_Matlab_Users
--Scott David Daniels
[EMAIL PR
elif issubclass(type(value), str):
# do the string logic
--Scott David Daniels
[EMAIL PROTECTED]
--
http://mail.python.org/mailman/listinfo/python-list
Error
except ValueError:
start = traceback.extract_tb(sys.exc_info()[2])[-1]
Start should show you where the program is being run from.
--Scott David Daniels
[EMAIL PROTECTED]
--
http://mail.python.org/mailman/listinfo/python-list
ding that you should (in such cases) put
a commented-out import at the top level (so you can look at the top of a
module's source and see what other modules it relies upon.
--Scott David Daniels
[EMAIL PROTECTED]
--
http://mail.python.org/mailman/listinfo/python-list
p(sorted(dic1.items()),
sorted(dic2.items()))
if p1 != p2)
>>> differs
{'h': (104, 13), 'e': (101, 12)}
--Scott David Daniels
[EMAIL PROTECTED]
--
http://mail.python.org/mailman/listinfo/python-list
n write something cool at least once, it will
encourage him to learn more.
Do you know about scratch (http://scratch.mit.edu/)
Actually, my son is 15, so Scratch might be too simplistic. PyGame
looks interesting. I'll play around with it tonight.
Look into VPython -- you can do 3-D _ea
s you, then MyParseError isn't a
ValueError and you shouldn't inherit from ValueError.
Just from the name, I'd look into making MyParseError inherit from
SyntaxError.
--Scott David Daniels
[EMAIL PROTECTED]
--
http://mail.python.org/mailman/listinfo/python-list
;t you are setting yourself
up to discover a pile of bugs that you don't understand.
--Scott David Daniels
[EMAIL PROTECTED]
--
http://mail.python.org/mailman/listinfo/python-list
quot;
that don't work that way (setattr knows about checking for the
exceptional cases). The "storage" can be removed with the "del"
statement. Try
del d.non_template
print d.non_template
del e.holder
print e.holder
--Scott David Daniels
[EMAIL PROTE
way to experiment
with things you think you get; try "corner cases" to make sure you
know what is going on.
--Scott David Daniels
[EMAIL PROTECTED]
--
http://mail.python.org/mailman/listinfo/python-list
he "sys.stdout" that p.py uses is different from that in the program
calling Popen. In fact, it could be using a different Python. The
situation is really similar to
p = subprocess.Popen([, 'aa'])
in that you have no way to "muck with the guts" of the subproces
[EMAIL PROTECTED] wrote:
...
so, it seems to me that if I would know how to write a file object,
then I could write one that prefixes each line, and that would be
fine, no? I don't see how this would necessitate waiting for p.py's
termination, or matter that it is a different process. I just do
. I'm not even sure that PIL
is the right library for that.
Any help/informations will be appreciate
Use PIL to fiddle the individual images, and reportlab to build
a pdf from the (now tweaked) images.
--Scott David Daniels
scott.dani...@acm.org
--
http://mail.python.org/mailman/listinfo/python-list
tributeError, ValueError), why: # Don't use bare except
print "Oops something didn't work: %s" % why
else:
do something 3
do something 4
...
do something 25
--Scott David Daniels
scott.dani...@acm.org
--
http://mail.python.org/mailman/listinfo/python-list
y this:
The simplest way to solve this for the moment is (re)defining
xreadlines:
def xreadlines(source):
for line in iter(src.readline, ''):
yield line
--Scott David Daniels
scott.dani...@acm.org
--
http://mail.python.org/mailman/listinfo/python-list
sut.date = temp
Note: each test should test 1 thing.
--Scott David Daniels
scott.dani...@acm.org
--
http://mail.python.org/mailman/listinfo/python-list
(needle) * [needle]
depending on the needed result (until values starts returning an
iterator).
--Scott David Daniels
scott.dani...@acm.org
--
http://mail.python.org/mailman/listinfo/python-list
le
in a "grab and modify" way.
Qt: simplest model, well-documented, until very recently not available
on Windows w/o a restrictive license or substantial cost.
--Scott David Daniels
scott.dani...@acm.org
--
http://mail.python.org/mailman/listinfo/python-list
t something like this:
import binascii
fd = open(filename, 'rb')
fd.seek(0x80)
x = fd.read(8)
print binascii.hexlify(x)
fd.close()
--Scott David Daniels
scott.dani...@acm.org
--
http://mail.python.org/mailman/listinfo/python-list
first
yield second
def random_crossing(population, probability=0.6):
'''This chooses random pairs from the population.
'''
shuffled = list(population) # make a copy
random.shuffle(shuffled) # mix it up
return list
e, choice)
yield candidates[first], candidates[second]
--Scott David Daniels
scott.dani...@acm.org
--
http://mail.python.org/mailman/listinfo/python-list
and more readable than
short-circuited operations.
How about:
b = None is not n != []
It is amazing to think about how rarely we consider is / is not as
a comparison operator. Also, and more reasonably, we often don't
consider "chaining" comparisons that are intransitive.
d] is None:
ad[field] = 'None'
if ni != ad['ni']:
if ni is UNSET:
ni = ad['ni']
else:
break
stack.append(ad)
--Scott David Daniels
scott.dani...@acm.org
--
http://mail.python.org/mailman/listinfo/python-list
Benjamin Peterson wrote:
On behalf of the Python development team and the Python community, I'm
happy to announce the first alpha release of Python 3.1.
Congratulations on the release.
I know 3.0 didn't have installers built for the alphas, will that be the
case for 3.1?
--Scott Dav
those of us not on the MS compiler upgrade train to
do a little alpha (and/or beta) testing as well.
--Scott David Daniels
scott.dani...@acm.org
--
http://mail.python.org/mailman/listinfo/python-list
iu2 wrote:
Here is the timer version. It works even more slowly, even with
PyScripter active: ...
I actually tried this one first. Due to the slow speed I changed to
looping inside the event.
I don't understand why it takes so long to move that square with
wx.Timer set to 1 ms interval. Perhaps
ion
without trying will have you skipping too many good ideas.
--Scott David Daniels
scott.dani...@acm.org
--
http://mail.python.org/mailman/listinfo/python-list
post this most effectively.
--Scott David Daniels
scott.dani...@acm.org
--
http://mail.python.org/mailman/listinfo/python-list
ms
to check out their behavior.
--Scott David Daniels
scott.dani...@acm.org
--
http://mail.python.org/mailman/listinfo/python-list
s, I prefer
single quotes unless doubles are needed). I solve the trailing
backslash problem as so:
sys.path.append(r'C:\DataFileTypes' '\\')
--Scott David Daniels
scott.dani...@acm.org
--
http://mail.python.org/mailman/listinfo/python-list
Tim Golden wrote:
Scott David Daniels wrote:
Tim Golden wrote:
... Anyhow, at the end I have a working Python 2.7a0 running
under Windows.
Do you mean 3.1a0? As far as I know, 2.7a0 requires the use
of the time machine, as it is expected to be 3 months out.
If you do get an installer built
t easily usable thing, and
provide a way to swap the commas and periods. The rest can be ponied
in by string processing.
--Scott David Daniels
scott.dani...@acm.org
--
http://mail.python.org/mailman/listinfo/python-list
while True:
time.sleep(.1)
counter *= 2
For that matter, it could do ... del counter ... and force a NameError
in your second loop.
--Scott David Daniels
scott.dani...@acm.org
--
http://mail.python.org/mailman/listinfo/python-list
ll parameters from a call'''
return _nargs, _kwargs
...
nargs, kwargs = eval('_args(%s)' % arglist
...
test(*nargs, **kwargs)
--Scott David Daniels
scott.dani...@acm.org
--
http://mail.python.org/mailman/listinfo/python-list
ably a mistake:
somefun(something, key(x)==5)
somefun(something, key(x)=5)
Right now a syntax error makes you look there, after your extension,
only test cases will show these problems.
--Scott David Daniels
scott.dani...@acm.org
--
http://mail.python.org/mailman/listinfo/python-list
e you had to print a printing character,
we used ASCII NULs (though I have seen rub-out used as well) to finish
the time delay needed. Since we needed eight (or was it twelve) chars
of delay, this driver substantially improved the print speed for our
listings.
--Scott David Daniels
scott.dan
ticle.php?story=20090310172906129
-Scott
--
http://mail.python.org/mailman/listinfo/python-list
higher priority
than the other operators.
> print(" %d, " " %d, buckle my shoe" % (1,2))
--Scott David Daniels
scott.dani...@acm.org
--
http://mail.python.org/mailman/listinfo/python-list
So, I see nobody has seen fit to make the obvious joke.
I will demonstrate my lack of restraint, by answering:
The way to add months to a date is to begin by
asking about your date's early childhood.
--Scott David Daniels
scott.dani...@acm.org
--
http://mail.python.org/mailman/lis
R. David Murray wrote:
...
Here is some example code that works:
out=open('temp', "wb")
out.write(b"BM")
def write_int(out, n):
bytesout=bytes(([n&255), (n>>8)&255, (n>>16)&255, (n>>24)&255])
out.write(bytesout)
write_int(out, 125)
or even:
import struct
sier, not a durable way to write queries.
query = """SELECT a.columna, a.columnb, a.iso, b.id, ...
FROM all AS a, other as b
WHERE a.name = LOWER(%s)
AND a.gid = b.id
AND b.class = 'A'
ORDER BY population DESC
LIMIT %s;"""
--Scot
is the same as X (parentheses are for grouping), to get
a singleton, you need (X,). 3 is just a 3 with a bunch
of meaningless parens around it. So, you want:
test_func(val=('val1',))
--Scott David Daniels
scott.dani...@acm.org
--
http://mail.python.org/mailman/listinfo/python-list
True
u'' == ''
True
Ah, you misunderstand the short-term expedient that 2.6 took.
Effectively, it simply said, bytes = str.
In 2.6:
>>> str is bytes
True
in 3.X:
>>> str is bytes
False
>>> b'' == ''
False
>>> type(b''), type('')
(, )
--Scott David Daniels
scott.dani...@acm.org
--
http://mail.python.org/mailman/listinfo/python-list
g):
'''A trap: never use 'def' as an arg name.
In which Doris gets her oats.
'''
return 3
>>> f(
And at this point pause a second, the hint will appear. I use
both this and "print(a.b.__doc__)" regularly for reminders of what
I have once read.
--Scott David Daniels
scott.dani...@acm.org
--
http://mail.python.org/mailman/listinfo/python-list
Look into time.strptime
--Scott David Daniels
scott.dani...@acm.org
--
http://mail.python.org/mailman/listinfo/python-list
1501 - 1600 of 2114 matches
Mail list logo