then the 'if ...' might be slightly faster,
even though the exception-based route is more Pythonic.
Jeff Shannon
Technician/Programmer
Credit International
--
http://mail.python.org/mailman/listinfo/python-list
on body rather than
burying that manipulation somewhere in the argument list. Personally
I'd call this a wash, though I expect that others will disagree with
me. ;) And whatever the merits of this particular case, similar cases
may not be so easy to avoid in this fashion...
Jeff Shannon
Technician/Programmer
Credit International
--
http://mail.python.org/mailman/listinfo/python-list
7;s version works on strings (and unicode objects) because they
lack an __iter__() method, even though they follow the (older)
sequence protocol.
Jeff Shannon
Technician/Programmer
Credit International
--
http://mail.python.org/mailman/listinfo/python-list
maybe even a new process or thread...
d = a + e(3)
I see this as simply a combination of both of the aforementioned
concepts -- argument control plus moment-of-evaluation control.
Jeff Shannon
Technician/Programmer
Credit International
--
http://mail.python.org/mailman/listinfo/python-list
troubleshoot a bit more effectively.
Jeff Shannon
Technician/Programmer
Credit International
--
http://mail.python.org/mailman/listinfo/python-list
ctive mode, and since you didn't
give it a script to run, it simply started, found nothing to do, and
then terminated itself.
You need to run idle.pyw, *not* pythonw.exe. The idle.pyw script runs
inside the pythonw.exe interpreter, but the latter can't do anything
without instruc
anted (2), perhaps function calls are first in the
queue for syntactic sugar.
Huh? How much simpler of syntax do you want for calling a function?
I'm not sure what you'd want as "sugar" instead of funcname().
Jeff Shannon
Technician/Programmer
Credit International
--
http://mail.python.org/mailman/listinfo/python-list
but shrewd risk-taking -- if you take a
one-in-three chance of making a tenfold return on investment, then 66%
of the time you'll lose but if you hit those odds just once,
you'll come out way ahead.)
Jeff Shannon
Technician/Programmer
Credit International
--
http://mail.python.org/mailman/listinfo/python-list
Jonathan Fine wrote:
Jeff Shannon wrote:
Jonathan Fine wrote:
Giudo has suggested adding optional static typing to Python.
(I hope suggested is the correct word.)
http://www.artima.com/weblogs/viewpost.jsp?thread=85551
An example of the syntax he proposes is:
> def f(this:that=ot
) in L2]
I suppose that your version has the virtue that, if the sortkey value
is equal, items retain the order that they were in the original list,
whereas my version will sort them into an essentially arbitrary order.
Is there anything else that I'm missing here?
Jeff Shannon
Technician/Pr
attempt to *encourage* hardworking
programmers to share in a public commons, by ensuring that what's
donated to the commons remains in the commons.
Jeff Shannon
Technician/Programmer
Credit International
--
http://mail.python.org/mailman/listinfo/python-list
special cases aren't special enough
to break the rules".
Jeff Shannon
Technician/Programmer
Credit International
--
http://mail.python.org/mailman/listinfo/python-list
many open variables to consider. One can't control for all
of them in experiments (what few experiments are practical in social
sciences, anyhow), and they make any anecdotal evidence hazy enough to
be suspect.
Jeff Shannon
Technician/Programmer
Credit International
--
http://mail.python.or
Paul Rubin wrote:
Jeff Shannon <[EMAIL PROTECTED]> writes:
It seems to me that in other, less-dynamic languages, lambdas are
significantly different from functions in that lambdas can be created
at runtime.
What languages are those, where you can create anonymous functions
at runtime, b
Paul Rubin wrote:
Jeff Shannon <[EMAIL PROTECTED]> writes:
Note that the so-called 'viral' nature of GPL code only applies to
*modifications you make* to the GPL software.
Well, only under an unusually broad notion of "modification".
True enough. It can be difficul
duct in which your code is linked together with LGPL'ed
code does *not* require that your code also be (L)GPL'ed. Changes to
the core library must still be released under (L)GPL, but application
code which merely *uses* the library does not. (I've forgotten, now,
exactly how LGPL d
Alex Martelli wrote:
Jeff Shannon <[EMAIL PROTECTED]> wrote:
Note that the so-called 'viral' nature of GPL code only applies to
*modifications you make* to the GPL software. The *only* way in which
your code can be 'infected' by the GPL is if you copy GPL source.
a questionable usage is an error or
not. Better to have that done by a developer tool (pychecker) than
through runtime checks every time the program is used.
Jeff Shannon
Technician/Programmer
Credit International
--
http://mail.python.org/mailman/listinfo/python-list
Nick Coghlan wrote:
Jeff Shannon wrote:
I suppose that your version has the virtue that, if the sortkey value
is equal, items retain the order that they were in the original list,
whereas my version will sort them into an essentially arbitrary order.
Is there anything else that I'm mi
quot;integers".
With all due respect to Richard Feynman, I'd have thought that
"counting numbers" would be non-negative integers, rather than the
full set of integers... which, I suppose, just goes to show how
perilous it can be to make up new, "more natural" terms
ry rat, at least, map/lambda was always a
nasty puzzle for me and difficult to sort out. But when list comps
were introduced, after reading just a sentence or two on how they
worked, they were completely clear and understandable -- much more so
than map/lambda after many months of exposure
enough
that lambda would be undesireable if not impossible, or they're simple
and numerous (e.g. calling a function with different parameters) such
that it's easy to write a factory function that returns closures
rather than feed the parameter in with a lambda.
Jeff Sha
de of someone who wants to write Visual Basic as
filtered through Java and Perl... If I want mental gymnastics when
reading code, I'd use Lisp (or Forth). (These are both great
languages, and mental gymnastics would probably do me good, but I
wouldn't want it as part of my day-t
mutate it. Since it's the same object,
it doesn't matter where the mutation happened. But in rebind(), we're
moving the somedict label to a *new* dict object. Now d and somedict
no longer point to the same object, and when the function ends the
object pointed to by so
command shell open. Edit, save,
alt-tab to command shell, uparrow-enter to run program... not as
convenient as a toolbar button or hotkey, but it works.
Jeff Shannon
Technician/Programmer
Credit International
--
http://mail.python.org/mailman/listinfo/python-list
Jon Perez wrote:
... or why 'Perl monkey' is an oft-heard term whereas 'Python
monkey' just doesn't seem to be appropriate?
That's just because pythons are more likely to *eat* a monkey than to
be one :)
Jeff Shannon
Technician/Programmer
Credit Internati
;cc"):
return extToMimeDict["cpp"]
If the intent of this is to catch .cc files, it's easy to add an extra
entry into the dict to map '.cc' to the same string as '.cpp'.
Jeff Shannon
Technician/Programmer
Credit International
--
http://mail.python.org/mailman/listinfo/python-list
nd) to map/lambda than it is to a list comprehension. In this case,
at least the code block is visually self-contained in a way that
lambdas are not, but I still have to do more mental work to visualize
the overall results than I need with list comps.
Jeff Shannon
Technician/Programmer
Credit Int
acking) and use exceptions to
indicate error status. Changing the value of a parameter is a
side-effect that complicates reading and debugging code, so Python
provides (and encourages) more straightforward ways of doing things.
Jeff Shannon
Technician/Programmer
Credit International
--
http://mai
your nested function would have
access to the outer namespace via normal nested scopes, so I'm really
not seeing what the gain is...
(Then again, I haven't been following the whole using/where thread,
because I don't have that much free time and the initial postings
failed to c
Antoon Pardon wrote:
Op 2005-01-12, Jeff Shannon schreef <[EMAIL PROTECTED]>:
It's also rather less necessary to use references in Python than it is
in C et. al.
You use nothing but references in Python, that is the reason why
if you assign a mutable to a new name and modify the obj
dicts are unordered, the ordering of the literal
(or of a set of statements adding to the dict) doesn't matter.
Jeff Shannon
Technician/Programmer
Credit International
--
http://mail.python.org/mailman/listinfo/python-list
B now.
And besides, for long-term archiving purposes, I'd expect that zip et
al on a character-stream would provide significantly better
compression than a 4:1 packed format, and that zipping the packed
format wouldn't be all that much more efficient than zipping the
character stream
is simpler. (For a large
file, chunking it might be necessary, though...)
Jeff Shannon
Technician/Programmer
Credit International
--
http://mail.python.org/mailman/listinfo/python-list
s
s = func(s)
This seems to be a way to go, but it becomes messy if i hand over
lots of parameters and expect some more return functions.
This has the advantage of being explicit about s being (potentially)
changed. References, in the way that you mean them, are even messier
in the case of nume
for RNA sequences as well as DNA
sequences, you've got at least a fifth base to represent, which means
you need at least three bits per base, which means only two bases per
byte (or else base-encodings split across byte-boundaries) That
gets ugly real fast.)
Jeff Shannon
Tec
ings get too bad here, I'd
like to have somewhere pleasant to emigrate to. ;)
Jeff Shannon
Technician/Programmer
Credit International
--
http://mail.python.org/mailman/listinfo/python-list
a more-detailed matching, you might look into finding an algorithm
to determine the "distance" between two strings and using that to
score possible matches.
Jeff Shannon
Technician/Programmer
Credit International
--
http://mail.python.org/mailman/listinfo/python-list
anageable level.
To rephrase this a bit more succinctly ;) there's a big difference
between having no practical way to prevent something, and actually
encouraging it.
Jeff Shannon
Technician/Programmer
Credit International
--
http://mail.python.org/mailman/listinfo/python-list
ol over the circumstances in
which your Singleton will be created and/or retrieved, and it also
makes it trivial to replace the Singleton with some other pattern
(such as, e.g., a Flyweight or Borg object) should the need to
refactor arise.
Jeff Shannon
Technician/Programmer
Credit International
--
uch closer to the "completely flat" side of things.
It's not "... as nested (or as flat) as you have to be and no
more", it's "... as nested as you have to be and no more, but if you
need significant nesting, you might want to re-examine your design". ;)
Jeff Shannon
Technician/Programmer
Credit International
--
http://mail.python.org/mailman/listinfo/python-list
ore robust (and
readable) fashion.
Jeff Shannon
Technician/Programmer
Credit International
--
http://mail.python.org/mailman/listinfo/python-list
ot;a:b:c".split(':')
>>> o = LineObj(*l)
>>> o.__dict__
{'a': 'a', 'c': 'c', 'b': 'b', 'e': None, 'd': None}
>>>
This is a bit more likely to be meaningful, in that there's
mory allocation, and for
a reasonable tuple the size of the memory required is not going to
significantly affect the allocation time.
Jeff Shannon
Technician/Programmer
Credit International
--
http://mail.python.org/mailman/listinfo/python-list
cripts, you'll probably have the same security issues I mentioned for
Python. Unless you really need that level of features, you may be
better off designing your own limited language. Check into the docs
for pyparsing for a starter...
Jeff Shannon
Technician/Programmer
Credit Internatio
e in a master dictionary keyed by id -- in other words,
simply replace the tuples in my previous example with a dict like what
you've got here. You could also create a simple class to hold each
item, rather than using small dicts. (You'd probably still want to
store class instances in a master dict keyed by id.)
Generally, any time your problem is to use one piece of information to
retrieve another piece (or set) of information, dictionaries are very
likely to be the best approach.
Jeff Shannon
Technician/Programmer
Credit International
--
http://mail.python.org/mailman/listinfo/python-list
ng the identifiers made it so
that you felt the need to add a comment indicating what they were
identifying, I'd say that yes, the long words *are* helpful. ;)
Comments are good, but self-documenting code is even better.
Jeff Shannon
Technician/Programmer
Credit International
--
http://mail
his purely abstract philosophy?
Jeff Shannon
Technician/Programmer
Credit International
--
http://mail.python.org/mailman/listinfo/python-list
n letting them script it in Python is a perfectly valid
(and probably quite desirable) approach.
Jeff Shannon
Technician/Programmer
Credit International
--
http://mail.python.org/mailman/listinfo/python-list
one of Python's RAD tools (Boa
Constructor, or maybe PythonCard, as examples) you'd be able to get
very nice results.
Jeff Shannon
Technician/Programmer
Credit International
--
http://mail.python.org/mailman/listinfo/python-list
#x27;t
be too horrible on resources/management, and that he shouldn't be so
afraid to try something new...
Jeff Shannon
Technician/Programmer
Credit International
--
http://mail.python.org/mailman/listinfo/python-list
h requires complex inheritance trees. In Python, an
object is whatever type it acts like -- behavior is more important
than declared type, so there's no value to having a huge assortment of
potential types. Deep inheritance trees only happen when people are
migrating from Java. ;)
Jeff
odes of expression, different
ways of approaching the same problem. That's *why* we have so many
different programming languages -- because no single approach is the
best one for all problems, and knowing multiple approaches helps you
to use your favored approach more effectively.
J
John Machin wrote:
Jeff Shannon wrote:
[...] If each record is CRLF terminated, then
you can get one record at a time simply by iterating over the file
("for line in open('myfile.dat'): ..."). You can have a dictionary
classes or factory functions, one for each record type
), then you can give D's
__init__() a B parameter that defaults to None.
Jeff Shannon
Technician/Programmer
Credit International
--
http://mail.python.org/mailman/listinfo/python-list
John Machin wrote:
Jeff Shannon wrote:
[...] For ~10 or fewer types whose spec
doesn't change, hand-coding the conversion would probably be quicker
and/or more straightforward than writing a spec-parser as you
suggest.
I didn't suggest writing a "spec-parser". No (mechanical)
te, and you have the
very essence of object-oriented programming.
(What you describe here *is* object-oriented programming, you're just
trying to avoid the 'class' statement and use module-objects where
'traditional' OO would use class instances.)
Jeff Shannon
Techn
just for this!
Normally it's a large round button, with perhaps a green backlight.
Press the button and hold it in for about 3 seconds, and the rest of
your code/writing will be ignored just as it should be.
Jeff Shannon
Technician/Programmer
Credit International
--
http://mail.python.o
our GUI widgets directly
from the worker (i/o) thread -- very few GUI toolkits are threadsafe,
so you need to make all GUI calls from a single thread.
Jeff Shannon
Technician/Programmer
Credit International
--
http://mail.python.org/mailman/listinfo/python-list
me size for your
test is a reflection of buffering. The next question is, which
provides the most *conceptual* simplicity? (The answer to that one, I
think, depends on how your brain happens to see things...)
Jeff Shannon
Technician/Programmer
Credit International
--
http://mail.python.org/mailman/listinfo/python-list
Christian Dieterich wrote:
On Dé Céadaoin, Ean 26, 2005, at 17:09 America/Chicago, Jeff Shannon wrote:
You could try making D a container for B instead of a subclass:
Thank you for the solution. I'll need to have a closer look at it.
However it seems like the decision whether to do
Christian Dieterich wrote:
On Déardaoin, Ean 27, 2005, at 14:05 America/Chicago, Jeff Shannon wrote:
the descriptor approach does. In either case, the calculation happens
as soon as someone requests D.size ...
Agreed. The calculation happens as soon as someone requests D.size. So
far so good
flamesrock wrote:
I should also mention that I'm using
version 2.0.1 (schools retro solaris machines :( )
At home (version 2.3.4) it prints out 'True' for the above code block.
That would explain it -- as /F mentioned previously, the special case
for None was added in 2.1
be an issue in the vast majority of cases, but I'm naturally
curious :)
Disk access should be buffered, possibly both at the C-runtime level
and at the file-iterator level (though I couldn't swear to that). I'm
sure that the C-level buffering happens, though.
Jeff Shannon
Technic
for item in lst:
if item is True: return True
if item is False: answer = False
return answer
But yeah, the original, straightforward way is probably enough clearer
that I wouldn't bother with anything else unless lists might be long
enough for performance to matter.
Je
Jeremy Bowers wrote:
On Fri, 04 Feb 2005 16:44:48 -0500, Daniel Bickett wrote:
[ False , False , True , None ]
False would be returned upon inspection of the first index, even
though True was in fact in the list. The same is true of the code of
Jeremy Bowers, Steve Juranich, and Jeff Shannon. As
ating dictionaries that'll be passed into functions, create class
instances.
class MyClass(object):
def __init__(self, **kwargs):
for key, val in kwargs:
setattr(self, key, val)
def fun(self):
self.z = self.y + self.x
a = MyClass(x=1, y=2)
a.fun()
print a.z
Je
rpreter and
try fiddling with things. You've got a lot of subexpressions there;
pick some values and try each subexpression, one at a time, and take a
look at what you get.
I bet that it won't take you long to figure out why you're not getting
the result you expect.
J
.
After it, on step (3) you can safely and peacefully add new PowerOfGenerator
variable.
You can also get all places where said variable exists by using grep,
or your editor's search feature. I don't see how a var declaration
gains you anything over 'grep PowerOfGenerator *.py
losed during program
shutdown if it hasn't happened before then.
Jeff Shannon
Technician/Programmer
Credit International
--
http://mail.python.org/mailman/listinfo/python-list
on a single installation medium would be a tricky
edge case. I suspect it *could* be done in a GPL-acceptable way, but
one would need to take care about it.)
Of course, this is only my own personal interpretation and opinion --
IANAL, TINLA, YMMV, etc, etc.
Jeff Shannon
Technician/Program
real security, because malicious
code can still get to __builtins__ from almost any object...)
Jeff Shannon
Technician/Programmer
Credit International
--
http://mail.python.org/mailman/listinfo/python-list
the exec'ed statement actually
sees, as well as what happens with the results. (But as I mentioned
before, there is no real security here if you're exec'ing arbitrary
code -- there's no sandboxing involved, and the exec'ed string *can*
use that __builtins__ reference (among other things) to do all sorts
of malicious stuff.)
Jeff Shannon
Technician/Programmer
Credit International
--
http://mail.python.org/mailman/listinfo/python-list
may (as just one of many examples) be much
better off with something more like:
for i in range(n)[::-1]:
func(n)
The '[::-1]' iterates over the range in a reverse (decreasing)
direction; this may or may not be necessary depending on the
circumstances.
Jeff Shannon
Technician/
Courageous wrote:
*checks self to see if self is wearing rose colored glasses*
assert(self.glasses.color != 'rose')
;)
Jeff Shannon
Technician/Programmer
Credit International
--
http://mail.python.org/mailman/listinfo/python-list
Dennis Lee Bieber wrote:
On Wed, 09 Feb 2005 18:10:40 -0800, Jeff Shannon <[EMAIL PROTECTED]>
declaimed the following in comp.lang.python:
for i in range(n)[::-1]:
func(n)
Shouldn't that be
func(i)
(the loop index?)
You're right, that's what I *
--
def pr(self):
print self.var
---
(Though frankly I don't see the advantage of having this tiny function
in a separate file to begin with...)
Jeff Shannon
Technician/Programmer
Credit International
--
http://mail.python.org/mailman/listinfo/python-list
the interval [0...4)
(including 0 but not including 4).
Modulus is useful for all sorts of periodic behavior.
Jeff Shannon
Technician/Programmer
Credit International
--
http://mail.python.org/mailman/listinfo/python-list
Dennis Lee Bieber wrote:
On Thu, 10 Feb 2005 09:36:42 -0800, Jeff Shannon <[EMAIL PROTECTED]>
declaimed the following in comp.lang.python:
And as Peter Hansen points out, none of the Python versions leave n in
the same state that the C loop does, so that's one more way in whic
not* take that opportunity to
purge things like GOTO.
Jeff Shannon
Technician/Programmer
Credit International
--
http://mail.python.org/mailman/listinfo/python-list
act) matches to his
"requirements". Instead of saying "Hey, someone's done half my work
for me -- great!", he's saying "Hey, why haven't you done the rest of
my work!"
Jeff Shannon
Technician/Programmer
Credit International
--
http://mail.python.org/mailman/listinfo/python-list
eed -- it looks like this worked perfectly to me, so the issue is
in what's expected. :)
Jeff Shannon
Technician/Programmer
Credit International
--
http://mail.python.org/mailman/listinfo/python-list
ot;Interpretation is irrelevant. Logic is irrelevant. You will be
assimilated."
Jeff Shannon
Technician/Programmer
Credit International
--
http://mail.python.org/mailman/listinfo/python-list
names do that nicely. What do you see as the harm of using it?)
Jeff Shannon
Technician/Programmer
Credit International
--
http://mail.python.org/mailman/listinfo/python-list
Bruno Desthuilliers wrote:
Jeff Shannon a écrit :
If running a console app from Explorer, the console will close as soon
as the app terminates. Using raw_input() at the end of the app means
that it won't close until the user hits Enter.
So why dont you just open the console before runnin
x27;t ever (normally) be cleaned up while they're still in use, but
during program shutdown refcounting necessarily ceases to apply.
The closest that would happen in C++, I believe, would manifest itself
as memory leaks and/or access of already-freed memory.
Jeff Shannon
Technician/Programmer
Credi
u insist on using an OS that's been obsolete for a decade or
more. ;)
Jeff Shannon
Technician/Programmer
Credit International
--
http://mail.python.org/mailman/listinfo/python-list
name to this
new function, it's simply calling itself.
Jeff Shannon
Technician/Programmer
Credit International
--
http://mail.python.org/mailman/listinfo/python-list
se, one could ensure that unicode.join() used unicode() and
str.join() used str(), but I can conceive of the possibility of
wanting to use a plain-string separator to join a list that might
include unicode strings. Whether this is a realistic use-case is, of
course, a completely different quest
do more command-line checking than
this...)
Jeff Shannon
Technician/Programmer
Credit International
--
http://mail.python.org/mailman/listinfo/python-list
__() is not a C++/Java destructor. Trying to make it
into one is unlikely to give an overal benefit.
Jeff Shannon
Technician/Programmer
Credit International
--
http://mail.python.org/mailman/listinfo/python-list
27;t
actually looked at it, but EasyGui (recently mentioned here; google
should help you find it) may meet your needs and be simpler to use.
Jeff Shannon
Technician/Programmer
Credit International
--
http://mail.python.org/mailman/listinfo/python-list
e), then str() will throw an exception.
The Effbot mentioned a join() implementation that would be smart
enough to do the right thing in this case, but it's not as simple as
just implicitly calling str().
Jeff Shannon
Technician/Programmer
Credit International
--
http://mail.python.org/mailman/listinfo/python-list
eep using that word. I do not think that it means
what you think it means."
Jeff Shannon
--
http://mail.python.org/mailman/listinfo/python-list
se a timer to do this; just have it fire periodically every
second or so, rather than only after several minutes.)
Jeff Shannon
--
http://mail.python.org/mailman/listinfo/python-list
questionable.
There *are* similar-but-not-compatible libraries for DOS... or perhaps
I should say *were*, because I have no idea where one might find such
a thing now. (Though I presume that Google would be the best starting
place.) One would then need to find/create a Python wrapper for th
our
server changing status without your client taking direct action.
I really think that you *do* want to do fairly frequent status checks
with your server. The cost is small, and the gains in responsiveness
and robustness are potentially very significant.
Jeff Shannon
--
http://mail.python.org/mailman/listinfo/python-list
rgs, **kwargs)
if s != 'OK':
raise NotOK((s,r))
return r
return wrapped
I believe that this will be semantically almost equivalent, but
conceptually slightly simpler.
Jeff Shannon
--
http://mail.python.org/mailman/listinfo/python-list
Christopher J. Bottaro wrote:
Jeff Shannon wrote:
Python's __del__() is not a C++/Java destructor.
Learn something new everyday... What is it then? Excuse my ignorance, but
what are you suppose to do if your object needs to clean up when its no
longer used (like close open file handles
module-level reference "var". No variables are
actually created in the execution of "global var".
Jeff Shannon
--
http://mail.python.org/mailman/listinfo/python-list
1 - 100 of 174 matches
Mail list logo