delayed in case spam is
never called, it can go in __init__ instead.
As a matter of fact, I have an object that is usually not called during
it's modules use, so I put in __getattr__. Sped the modules load time
back up to pert near instantaneous. :)
~Ethan~
--
http://mail.python.org/ma
Steven D'Aprano wrote:
On Fri, 02 Apr 2010 12:39:16 -0700, Patrick Maupin wrote:
On Apr 2, 2:38 pm, Ethan Furman wrote:
[...]
Sounds like a personal preference issue, rather than a necessary /
unnecessary issue -- after all, if you call that function a thousand
times, only once is
uired to support Python 2.
The more I learn of 3, the more I love it. Many improvements in
simplicity and elegance.
At any rate, what I have is below. My (very limited) initial tests are
working fine. super() appears to work as is.
Feedback appreciated!
~Etha
Steven D'Aprano wrote:
On Fri, 02 Apr 2010 19:48:59 -0700, Ethan Furman wrote:
The heuristic I use is, if I expect the try block to raise an exception
more than about one time in ten, I change to an explicit test. In this
case, since the exception should only be raised once, and then
The dbf package does not yet support index files. Normal indexes won't
be too hard to add in, but I have been unable to find the algorithms
used to create/work with compact index files.
Does anybody know where I might find those?
~Ethan~ (author of said package)
--
http://mail.python.o
ue)
Does this still happen with the latest code? (Not yet on PyPI for those
following along -- hope to get a new package released this week.)
~Ethan~
--
http://mail.python.org/mailman/listinfo/python-list
yError:
> raise CommandError("Unknown command")
>
> # Include the context
> try:
> command_dict[command]()
> except KeyError:
> raise with CommandError("Unknown command")
~Ethan~
--
http://mail.python.org/mailman/listinfo/python-list
n exc is raised.
http://www.python.org/dev/peps/pep-3134/
~Ethan~
--
http://mail.python.org/mailman/listinfo/python-list
uld be for itself?
(My apologies if this question only reveals my own ignorance.)
~Ethan~
--
http://mail.python.org/mailman/listinfo/python-list
ement in
> iterable?
No, it hit's return instead.
> And would your second suggestion throw an exception after normal
> processing of all elements in the interator?
Looks like the second solution doesn't process the entire iterable, just
it's first element.
~Ethan~
--
http://mail.python.org/mailman/listinfo/python-list
oesn't fix the unwanted nesting of exceptions problem.
~Ethan~
--
http://mail.python.org/mailman/listinfo/python-list
Ethan Furman wrote:
Please don't top-post.
Rob Richardson wrote:
-Original Message-
I missed the start of this discussion but there are two simpler ways:
def func(iterable):
for x in iterable:
print(x)
return
raise ValueError("... empty iterable&q
Ethan Furman wrote:
Arnaud Delobelle wrote:
I missed the start of this discussion but there are two simpler ways:
def func(iterable):
for x in iterable:
print(x)
return
raise ValueError("... empty iterable")
For the immediate case this is a cool solutio
er, I may drop
support for the other.
Don't currently need/use stats, but B seems clearer to me.
~Ethan~
--
http://mail.python.org/mailman/listinfo/python-list
Hope this helps!
~Ethan~
--
http://mail.python.org/mailman/listinfo/python-list
So I just got an e-mail from O'Reilly and their School of Technology
about a Python Certification course... anybody have any experience with
this?
It also says Steve Holden is involved -- is this True? (Steve?)
~Ethan~
PS
Can you tell I've been programming? ;)
--
http://mail.
Tim Arnold wrote:
"Ethan Furman" wrote in message
news:mailman.4.1292379995.6505.python-l...@python.org...
kj wrote:
The one thing I don't like about this strategy is that the tracebacks
of exceptions raised during the execution of __pre_spam include one
unwanted stack level (
ter putting the functional method in place, a run that took
about 16 minutes using the old exec method ran two (2!) seconds faster.
Great learning experience, for both the function method (which I
prefer), and the need for profiling.
~Ethan~
--
http://mail.python.org/mailman/listinfo/python-list
a 25%
discount promotional.
~Ethan~
--
http://mail.python.org/mailman/listinfo/python-list
Arnaud Delobelle wrote:
Ethan Furman writes:
...I timed exec vs function, and found the function style to be about
200% faster...
So it finished before it started?
Hmmm
Let me check my calculator...
.
.
.
Ah! Okay, that was 200x faster. :) I think -- it was a few months ago
Bad2()
elif yet_another_bad_condition:
raise Bad3()
do_some_useful_stuff
# no need to return 'good' code -- success means no problems
~Ethan~
--
http://mail.python.org/mailman/listinfo/python-list
ondition was set to cond2.
The exitCode no longer needs to be checked inside the function, because
there is no chance of do_some_useful_stuff running if any of the
conditions are False.
Hope this helps.
~Ethan~
--
http://mail.python.org/mailman/listinfo/python-list
applied. ... Splitting an empty string or a string consisting of just
whitespace returns an empty list.
Note the bit in the second paragraph.
Here's my code snippet:
Python 2.5.4 (r254:67916, Dec 23 2008, 15:10:54) [MSC v.1310 32 bit
(Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
--> test = ''
--> test.split()
[]
--> test.split(' ')
['']
--> test.split(',')
['']
--> test.split(None)
[]
Hope this helps!
~Ethan~
--
http://mail.python.org/mailman/listinfo/python-list
-> n - m
CloseFraction(-3, 4)
--> n + m
CloseFraction(15, 4)
--> n.real
CloseFraction(3, 2)
--> n.imag
0 # this is an int
Hope this helps!
~Ethan~
--
http://mail.python.org/mailman/listinfo/python-list
apping, even though none of the bases of
dict is either Mapping or a subclass of Mapping. Great.
I suspect this is another abstraction leak
My take on abstraction leaks is when the underlying actuality shows
through in a non-ignorable way -- so I ask again, how is this
discrepancy making it so you can't ignore it?
~Ethan~
--
http://mail.python.org/mailman/listinfo/python-list
pposed to custom object, I don't think the traceback should be monkied
with -- either use a decorator to keep the traceback short, or give the
_pre_func name a good name and don't worry about it. I know when I see
a traceback, I start at the bottom and only work my way up if I need to.
~Ethan~
--
http://mail.python.org/mailman/listinfo/python-list
ing
information that could be crucial for debugging.
+100
~Ethan~
--
http://mail.python.org/mailman/listinfo/python-list
Steven D'Aprano wrote:
On Sat, 25 Dec 2010 09:17:27 -0500, Robert Kern wrote:
On 12/24/10 5:14 PM, Ethan Furman wrote:
There are also times when I change the exception being raised to match
what python expects from that type of object -- for example, from
WhatEverException to KeyError
are back to passing errors in-band,
pretty much completely defeating the point of have an out-of-band channel.
~Ethan~
--
http://mail.python.org/mailman/listinfo/python-list
the user one level of traceback was that high a priority to me,
I would make the validation be either a decorator, or have the
validation *be* the main routine, and the *real work* routine be the
private one.
~Ethan~
--
http://mail.python.org/mailman/listinfo/python-list
Steven D'Aprano wrote:
On Sun, 26 Dec 2010 09:15:32 -0800, Ethan Furman wrote:
Steven D'Aprano wrote:
Right. But I have thought of a clever trick to get the result KJ was
asking for, with the minimum of boilerplate code. Instead of this:
def _pre_spam(args):
if cond
u have any information that would help me, I would be very grateful!
~Ethan~
*http://pypi.python.org/pypi/dbf/0.88.16
--
http://mail.python.org/mailman/listinfo/python-list
e file would have been, not in the
__pycache__ directory (it'll be considered stale otherwise).
Typo?
According to PEP 3147 a standalone *.pyc *should* (not should not) be
put in the same directory where the source file would have been.
~Ethan~
--
http://mail.python.org/mailman/listinfo/python-list
by the name of "ranting rick", and you're suggesting that
instead of talking he rolls up his sleeves and does something.
I suspect you're barking into the wind...
To borrow from Dilbert*, perhaps rr is more of an idea rat.
~Ethan~
*http://www.dilbert.com/strips/comic/1994-12-17/
Octavian Rasnita wrote:
From: "rantingrick"
WxPython versus Tkinter (A code battle to the death!)
by Rick Johnson.
[...]
Octavian,
Please do not repost rr's crap in its entirety, or you'll find yourself
added to many killfiles -- just like he is.
~Ethan~
--
ht
Mark Roseman wrote:
I don't object and in fact commend you for advocating for accessibility.
I do feel you are not acknowledging and fully respecting that others may
be in situations where accessibility may not be the primary concern.
Well said.
~Ethan~
--
http://mail.python.org/ma
! So you want to steal our code to fix yours? Why am I not surprised?
~Ethan~
--
http://mail.python.org/mailman/listinfo/python-list
-plonk-
--
http://mail.python.org/mailman/listinfo/python-list
case
The problem as you've described it so far is best solved by having a
single process accessing the CSV reader object in memory. If that
doesn't suit your use case, you'll need to explain why not.
In other words, why can't you use Python 2.7 to accept input and
? ;)
~Ethan~
--
http://mail.python.org/mailman/listinfo/python-list
as an example) might just fool my signature check.
When you signature check, do you mean counting the number of arguments,
or actually checking argument types?
~Ethan~
--
http://mail.python.org/mailman/listinfo/python-list
bool(statement) is True: >, or
< if bool(statement): >, or, simplest,
< if statement: >
As to return False if statement equals
true, look at the function name. It is testing to see if it is a lie,
and if it is true, then it's not a lie.
Your
x27; or 'x'... although, when posting sample code to c.l.py I do
try to use 'self' to avoid possible confusion. :)
~Ethan~
--
http://mail.python.org/mailman/listinfo/python-list
e as the programmer, it's all going to be interpreted
anyway. And the other email equating to C's argv, etc. - now I get it.
Careful about the names you make-up -- to aid yourself and others you
don't want to have dozen's of different names that all basically mean
'thi
Gerald Britton wrote:
I'd like to know how (perhaps with the inspect module) I can tell if I
am running in a context manager.
What's your use-case?
~Ethan~
--
http://mail.python.org/mailman/listinfo/python-list
:/temp\control.FPT
Or is there an option I'm missing so backslashes are not returned by
stdlib functions?
~Ethan~
--
http://mail.python.org/mailman/listinfo/python-list
atically sorted into folders, having [python-list] in the subject
line would be incredibly redundant. Also, it's a waste of horizontal space.
I believe you could use a mail preprocessor, like Fetchmail or Procmail,
to modify your e-mails before you receive them, though.
Good luck!
~Ethan~
z in sorted(freq):
print z, freq[z]
-
Numeric/Float field types are returned as python floats*, so there may
be slight discrepancies between the stored value and the returned value.
Hope this helps.
~Ethan~
*Unless created with zero decimal places, in which case they are
returned as python integers.
--
http://mail.python.org/mailman/listinfo/python-list
decimals before converting
to a string, etc.
Or use recursion!
>>> def num_digits(n):
...if n == 0:
... return 0
...else:
... return num_digits(n//10) + 1
...
>>> num_digits(1)
1
>>> num_digits(0)
0
0 is still one digit. ;)
~Ethan~
--
http://mail.python.org/mailman/listinfo/python-list
Jason Swails wrote:
On Wed, Feb 9, 2011 at 8:16 PM, Ethan Furman wrote:
while n: is plenty readable. n is either something or nothing, and
something evaluates to True, nothing to False.
Sure it's readable. But then you have to make sure that the loop will
eventually take n down
be 3 :)
fList = ["Two()","Three()"]
for func in fList:
func
This is not calling func (no () at the end), and in fact doesn't do
anything if called as a script besides evaluate func -- it's a string,
but not being assigned anywhere, so unless you are running
parameter to judge.
I strongly disagree. Code readability is one of the most important issues.
~Ethan~
--
http://mail.python.org/mailman/listinfo/python-list
hould work?
Please. Experiment and read the manual.
~Ethan~
--
http://mail.python.org/mailman/listinfo/python-list
Ethan Furman wrote:
Steven D'Aprano wrote:
On Fri, 02 Apr 2010 19:48:59 -0700, Ethan Furman wrote:
The heuristic I use is, if I expect the try block to raise an exception
more than about one time in ten, I change to an explicit test. In this
case, since the exception should only be r
break
source = ''.join([line[lead_space:] for line in source])
print('\n' + source)
intermed_result = {}
final_result = PropertyObj()
exec(source, func.__globals__, intermed_result)
for key, value in intermed_result.items():
setattr(final_result, key, value)
return final_result
8<--
Hope this helps!
~Ethan~
--
http://mail.python.org/mailman/listinfo/python-list
here are *both* .py & .pyw...
Python 2.5.4 (r254:67916, Dec 23 2008, 15:10:54) [MSC v.1310 32 bit
(Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
--> open ("xxx.pyw", "w").write ("print ('hello')")
--> open ("xxx.py", "w").write ("print ('good-bye')")
--> import xxx
good-bye
~Ethan~
--
http://mail.python.org/mailman/listinfo/python-list
;t mean you should
write those commands manually, even if you can. It's perfectly ok to
write the program in Python instead.
Stefan
And it's even more perfectly okay to use Python when it's the best tool
for the job, and re when *it's* the best tool for the job.
~Etha
There's no RightAnswer(tm), just our best guess as to what is the most
useful behavior for the most number of people.
+1 QOTW
--
http://mail.python.org/mailman/listinfo/python-list
it once your brain starts working pythonically.
~Ethan~
--
http://mail.python.org/mailman/listinfo/python-list
figure it
out from the different (nested) braces at the 'right' location. For me,
at least, it's much easier to get that information from the already
indented Python code, as opposed to indenting (and double-checking the
indents) on the braces language.
~Ethan~
--
http://mail.py
the compiling/linking/generating himself, thus saving his customers the
effort.
You're a smart man, Steven, surely you could have figured that out? ;)
~Ethan~
--
http://mail.python.org/mailman/listinfo/python-list
s that all subsequent generations of derivative works have
the freedom to access all previous derivative works.
Just because you have the code for the _current_ version of something,
doesn't mean you have the code for that something three versions ago...
after all, it may have been modified.
available
under a proprietary licence that you (or your client) was unwilling to
use? Lucky you!
Steven, did you actually read what he wrote? If you did, why would you
say something so stupid?
~Ethan~
--
http://mail.python.org/mailman/listinfo/python-list
constructor (__init__):
a_dog = dog('Ralph', 'big', RED)
this_app = myapp()
fred = contact('Fred Flinstone','f...@flinstone.gv','active','exemplary')
Hope this helps.
~Ethan~
--
http://mail.python.org/mailman/listinfo/python-list
ly Pat has defended himself quite well,
while being very reasonable, and has said at least twice (more, I'm
sure) that the choice of license is up to the author, and that there are
good reasons for choosing any of the free licenses (including the GPL).
~Ethan~
--
http://mail.python.org/m
does not, but maybe the *shell* does, or so i thought. i just
wanted to dump the code for the function in a file, after i tested in
the shell...
Take a look at ipython -- it has many enhancements: ipython.scipy.org
~Ethan~
--
http://mail.python.org/mailman/listinfo/python-list
errals for new work. It really is practical to sell
free software.
This doesn't make sense to me, but I'm willing to learn -- how do you do
this in practice? Are you really selling the software, or rather
selling things like setup, support, new code (or time to code), etc?
~Ethan~
--
http://mail.python.org/mailman/listinfo/python-list
self.x=self.letter[x]
>>> afoo = foo('b')
>>> afoo.x
2
>>> afoo.A
1
>>> afoo.letter['a']
1
>>> afoo.letter.items()
[('a', 1), ('c', 3), ('b', 2)]
Do you expect afoo.letter[x] to always be afoo.x? Becaus
Vincent Davis wrote:
On Tue, May 18, 2010 at 2:41 PM, Ethan Furman <mailto:et...@stoneleaf.us>> wrote:
Do you expect afoo.letter[x] to always be afoo.x? Because they aren't:
>>> afoo.A = 9
>>> afoo.letter['a']
1
What you are
calculation of inst.xy
I don't what to have self.xy calculated before it is called.
My current favorite method:
def __getattr__(self, name):
if name != 'xy':
raise AttributeError("%s not found" % name)
self.xy = self.x + self.y
return
Ethan Furman wrote:
Vincent Davis wrote:
Lets say I have class foo(object):
def __init__(self, x, y):
self.x=x
self.y=y
def xplusy(self):
self.xy = x+y
^ this needs to be self.x + self.y
inst = foo(1,2)
inst.xy # no value, but I what
ll keyword arguments that
Battleship doesn't directly support will be passed through to Craft.
~Ethan~
--
http://mail.python.org/mailman/listinfo/python-list
code can apply the key function to the record (implicit, as in method 1
above) or the calling code can do it (explicit, as in method 2 above).
I'm leaning towards method 1, even though the key function is then
called behind the scenes, because I think it makes the calling code cleaner.
Op
Ethan Furman wrote:
Let's say I have two tables:
Okay, let's say I have three tables instead. ;p
--
http://mail.python.org/mailman/listinfo/python-list
D'Arcy J.M. Cain wrote:
On Thu, 27 May 2010 12:45:58 -0700
Ethan Furman wrote:
Let's say I have two tables:
CatLoversDogLovers
--- ---
| name | age | | name
True. Were Tcl removed from the equation, then some feautures would
have to be re-implemented in Python.
So what functionality is available from Tk alone? From the very cursory
glance at the source files (mostly the readmes), it seems pretty
entwined with Tcl.
~Ethan~
--
http://mail.py
_function
before you can do the same in 2.6. Not sure, but I seem to recall some
very slight differences between the __future__ version of print and the
actual version in 3.x (although, with my memory, it could easily be one
of the other __future__ items).
~Ethan~
--
http://mail.python.org/mailman/listinfo/python-list
that
they may not be there on other platforms, though.
~Ethan~
P.S.
Now that I think about it, actually installing them is optional...
--
http://mail.python.org/mailman/listinfo/python-list
f you're running any
kind of desktop at all.
*Alert* Potentially dumb question following: On the MS Windows
platform, Gtk is not required, just win32?
~Ethan~
--
http://mail.python.org/mailman/listinfo/python-list
whatever of the info object.
Hope this helps!
~Ethan~
--
http://mail.python.org/mailman/listinfo/python-list
Stephen Hansen wrote:
Another thing you can look at is QT/PyQT. If you're doing GPL'd
software, that might be a very good solution for you-- you can design
your whole app in the beautiful QTDesigner, and the .ui files can be
used in any language with a QT binding, PyQT included. But you gotta be
Ethan Furman wrote:
Anthony Papillion wrote:
Someone helped me with some code yesterday and I'm trying to
understand it. The way they wrote it was
subjects = (info[2] for info in items)
Perhaps I'm not truly understanding what this does. Does this do
anything different than if I
appreciated!
~Ethan~
--
http://mail.python.org/mailman/listinfo/python-list
leall -f ." whenever you edit a file and before testing.
I thought python (well, cpython, at least) didn't use .pyc files for the
main script?
~Ethan~
--
http://mail.python.org/mailman/listinfo/python-list
lkcl wrote:
oh look - there's a common theme, there: "web technology equals
useless" :)
this is getting sufficiently ridiculous, i thought it best to
summarise the discussions of the past few days, from the perspective
of four-year-olds:
AH hahahahahahahahahahahaha
--
http://mail.python.org
a shortcut for:
import
= .
There should also be a third line:
del
~Ethan~
--
http://mail.python.org/mailman/listinfo/python-list
Stephen Hansen wrote:
On 6/17/10 10:01 AM, Ethan Furman wrote:
Stephen Hansen wrote:
On 6/17/10 9:12 AM, pyt...@bdurham.com wrote:
Now, this is all IMHO: the style guide does not define any 'guidelines'
on this, except that its okay to use "from ... import ..." to
ting that may change, don't call it a constant and name
it accordingly.
~Ethan~
--
http://mail.python.org/mailman/listinfo/python-list
e Lanaro said in that same thread:
> else take a book that covers python 2.x syntax
Cut-and-pasting-ly yours,
~Ethan~
--
http://mail.python.org/mailman/listinfo/python-list
Deadly Dirk wrote:
On Thu, 17 Jun 2010 12:18:33 -0700, Ethan Furman wrote:
Deadly Dirk wrote:
On Thu, 17 Jun 2010 13:48:45 -0400, J. Cliff Dyer wrote:
super gives you an instantiated version of the super class, which
means that you don't have to explicitly send self to any methods you
!
Is there a good web-site / tutorial / book / etc that you would
recommend for getting a good handle on Tk 8.5?
~Ethan~
--
http://mail.python.org/mailman/listinfo/python-list
ror: class test has no attribute 'a'
Looks pretty simple to me...
~Ethan~
--
http://mail.python.org/mailman/listinfo/python-list
Sneaky Wombat wrote:
Why is python turning \x0a into a \n ?
In [120]: h='\x0a\xa8\x19\x0b'
In [121]: h
Out[121]: '\n\xa8\x19\x0b'
I don't want this to happen, can I prevent it?
'\x0a' == '\n'
--
http://mail.python.org/mailman/listinfo/python-list
will always write to the
innermost scope. In contrast, local variables both read and write in the
innermost scope. Likewise, global variables read and write to the global
namespace.
Doesn't the nonlocal keyword make variables in outer scopes writable?
~Ethan~
--
http://mail.python.org/ma
Also, since it is easier, why not drop the harder one, setattr()?
Because setattr and friends are needed when the variable names are
constructed dynamically.
~Ethan~
--
http://mail.python.org/mailman/listinfo/python-list
ate needs, patterns of thought, etc.
~Ethan~
--
http://mail.python.org/mailman/listinfo/python-list
Stephen Hansen wrote:
On 6/29/10 10:01 AM, Ethan Furman wrote:
In the glossary section it states:
nested scope
The ability to refer to a variable in an enclosing definition. For
instance, a function defined inside another function can refer to
variables in the outer function. Note that
nti-hammer sentiment' to suggest another
tool, like pliers or a jackhammer.
I took the time to learn REs about a year ago. It was well worth it,
even though I've only used REs a handful of times since, because when
you need them there is no good substitute. But when you don't, there
are plenty. ;)
~Ethan~
--
http://mail.python.org/mailman/listinfo/python-list
ng my wrist for that
operation.
Quite cheap and simple, and I've thereby had no recurrence of injury for
the past 3 years.
I'll have to give the left-handed mouse a try... hmmm -- not too bad so far.
I also switched over to the Dvorak keyboard layout. Made a world of
differ
Aahz wrote:
In article ,
Ethan Furman wrote:
Stephen Hansen wrote:
On 6/29/10 10:01 AM, Ethan Furman wrote:
In the glossary section it states:
nested scope
The ability to refer to a variable in an enclosing definition. For
instance, a function defined inside another function can refer to
1601 - 1700 of 1941 matches
Mail list logo