.
Arguably, it should not be.
But that's the sole purpose of the is operator. You either expose
those details, or you don't have an is operator at all.
--
Neil Cerutti
--
http://mail.python.org/mailman/listinfo/python-list
On 2011-05-05, Roy Smith r...@panix.com wrote:
Of course, C++ lets you go off the deep end with abominations
like references to pointers. Come to think of it, C++ let's
you go off the deep end in so many ways...
But you can do some really cool stuff in the deep end.
--
Neil Cerutti
--
http
automatically
dereference themselves.
--
Neil Cerutti
--
http://mail.python.org/mailman/listinfo/python-list
(an interface class containing a pointer to an
implementation) with template classes to create type-safe
polymorphic types with specializable, decoupled implementations.
A Python programmer just feels depressed that anyone could have a
need for such innovations, though. ;)
--
Neil Cerutti
--
http
switch to .format you'll probably reap some benefit.
--
Neil Cerutti
--
http://mail.python.org/mailman/listinfo/python-list
://www.pythonware.com/products/pil/.
The technique is necessary in The Python Challenge, for example.
URL:http://www.pythonchallenge.com/
--
Neil Cerutti
--
http://mail.python.org/mailman/listinfo/python-list
its author.
--
Neil Cerutti
--
http://mail.python.org/mailman/listinfo/python-list
by a bad comment.
Perhaps better:
def foo():
raise IndexError()
--
Neil Cerutti
--
http://mail.python.org/mailman/listinfo/python-list
, when they're sufficent, are usually more
efficient.
Perl integrated regular expressions, while Python relegated them
to a library.
There are thus a large class of problems that are best solve with
regular expressions in Perl, but str methods in Python.
--
Neil Cerutti
--
http://mail.python.org
to making it my last
resort.
--
Neil Cerutti
--
http://mail.python.org/mailman/listinfo/python-list
were not used when they would have simplified the code,
then I have seen regexes used when a string method or two
would have done the same thing.
Can you find an example or invent one? I simply don't remember
such problems coming up, but I admit it's possible.
--
Neil Cerutti
--
http
On 2011-06-06, ru...@yahoo.com ru...@yahoo.com wrote:
On 06/03/2011 02:49 PM, Neil Cerutti wrote:
Can you find an example or invent one? I simply don't remember
such problems coming up, but I admit it's possible.
Sure, the response to the OP of this thread.
Here's a recap, along with two
On 2011-06-06, Ian Kelly ian.g.ke...@gmail.com wrote:
On Mon, Jun 6, 2011 at 10:08 AM, Neil Cerutti ne...@norwich.edu wrote:
import re
print(re solution)
with open(data.txt) as f:
? ?for line in f:
? ? ? ?fixed = re.sub(r(TABLE='\S+)\s+', r\1', line)
? ? ? ?print(fixed, end='')
print(non
to be there.
--
Neil Cerutti
--
http://mail.python.org/mailman/listinfo/python-list
of:
Traceback (most recent call last):
File bar.py, line 123, in foo
build_rpms()
The stack trace would read:
Traceback (most recent call last):
File bar.py, line 123, in foo(1, [2])
build_rpms()
This would save a lot of debugging time!
Use pdb.
--
Neil
On 2011-06-07, Dun Peal dunpea...@gmail.com wrote:
On Jun 7, 1:23?pm, Neil Cerutti ne...@norwich.edu wrote:
Use pdb.
Neil, thanks for the tip; `pdb` is indeed a great debugging
tool.
Still, it doesn't obviate the need for arguments in the stack
trace. For example:
1) Arguments in stack
. It decouples deciphering the meaning of the
data from emitting the data, which is more robust and expansable.
The amount of ingenuity required is less, though. ;)
--
Neil Cerutti
--
http://mail.python.org/mailman/listinfo/python-list
statement for an example of what it might
look like in Python. Except you'd get it without labeled break or
the fallthrough statement. Would you still want to use it?
--
Neil Cerutti
--
https://mail.python.org/mailman/listinfo/python-list
of
the called function.
Am I oversimplifying?
--
Neil Cerutti
--
https://mail.python.org/mailman/listinfo/python-list
underestimated how much
we like to use our programming languages as non-RPN calculators.
--
Neil Cerutti
--
https://mail.python.org/mailman/listinfo/python-list
.
--
Neil Cerutti
--
https://mail.python.org/mailman/listinfo/python-list
is a draw. Go's tools are pretty awesome, and are
scheduled for improvements.
If you can get by with its built in types (or simple aggregates
of them) it feels quite expressive.
--
Neil Cerutti
--
https://mail.python.org/mailman/listinfo/python-list
manageable that the ones I
used in Python ...
C could provide more friendly general purpose containers in its
library, but doesn't. There are some good free ones: glib, for
example.
Cython provides a really nice in-between level.
--
Neil Cerutti
--
https://mail.python.org/mailman/listinfo/python
buttons below far making changes to them.
--
Neil Cerutti
--
http://mail.python.org/mailman/listinfo/python-list
data['2']
print data['3']
print data['4']
[...]
--
Neil Cerutti
This room is an illusion and is a trap devisut by Satan. Go
ahead and dauntlessly! Make rapid progres!
--Ghosts 'n Goblins
--
http://mail.python.org/mailman/listinfo/python-list
in fields})
for record in reader:
# Change a few fields
# [...]
writer.writerow(record)
--
Neil Cerutti
This room is an illusion and is a trap devisut by Satan. Go
ahead and dauntlessly! Make rapid progres!
--Ghosts 'n Goblins
--
http://mail.python.org/mailman
On 2011-11-21, Neil Cerutti ne...@norwich.edu wrote:
On 2011-11-21, ray r...@aarden.us wrote:
Is there a way to capture the keys outside of the for loop so
when the for loop is entered, only data is extracted?
I have sometimes done the following type of thing, since
DictReader doesn't offer
) as the_next_file:
...
My Python 3.0 is rusty, so sorry if I messed that up.
--
Neil Cerutti
--
http://mail.python.org/mailman/listinfo/python-list
conspiracy
interpretation of Python's lambda expressions. They were added
but grudgingingly, made weak on purpose to discourage their use.
--
Neil Cerutti
This room is an illusion and is a trap devisut by Satan. Go
ahead and dauntlessly! Make rapid progres!
--Ghosts 'n Goblins
--
http
On 2011-11-28, Gregory Ewing greg.ew...@canterbury.ac.nz wrote:
Neil Cerutti wrote:
I've always held with the anti-functional style conspiracy
interpretation of Python's lambda expressions. They were added
but grudgingingly, made weak on purpose to discourage their
use.
Seems to me
.
The resultant refactored programs are much easier to test, read
and maintain.
TLDR: Called-only-once functions like main are useful as
documentation, hooks for testing, and for unraveling a snarl of
global variables.
--
Neil Cerutti
--
http://mail.python.org/mailman/listinfo/python-list
On 2011-12-07, Terry Reedy tjre...@udel.edu wrote:
It does not pretend that surrounding statements with
parentheses turns them into expressions.
;-)
I like being in a sexpression. Aww YEH!
--
(Neil Cerutti)
--
http://mail.python.org/mailman/listinfo/python-list
(sys.argv[0]).
--
Neil Cerutti
--
http://mail.python.org/mailman/listinfo/python-list
point for learning
pointers, though since you already know C that won't do you as
much good.
--
Neil Cerutti
--
http://mail.python.org/mailman/listinfo/python-list
and be
pretty happy with the results.
--
Neil Cerutti
--
http://mail.python.org/mailman/listinfo/python-list
On 2011-12-21, Grant Edwards invalid@invalid.invalid wrote:
On 2011-12-21, Neil Cerutti ne...@norwich.edu wrote:
On 2011-12-20, Paul Rubin no.email@nospam.invalid wrote:
Grant Edwards invalid@invalid.invalid writes:
Oops. I should have mentioned this is for embedded systems
programming so
other language. ;)
--
Neil Cerutti
--
http://mail.python.org/mailman/listinfo/python-list
On 2011-12-23, Neil Cerutti ne...@norwich.edu wrote:
Is the misfeature that Python doesn't evaluate the default
argument expression every time you call the function? What
would be the harm if it did?
...you know, assuming it wouldn't break existing code. ;)
--
Neil Cerutti
--
http
claiming
multiple inheritence was a bug and asking it to be removed.
Both of these could arguably be called misfeaures, but not
bugs.
Is the misfeature that Python doesn't evaluate the default
argument expression every time you call the function? What would
be the harm if it did?
--
Neil Cerutti
On 2011-12-23, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote:
On Fri, 23 Dec 2011 13:13:38 +, Neil Cerutti wrote:
On 2011-12-23, Neil Cerutti ne...@norwich.edu wrote:
Is the misfeature that Python doesn't evaluate the default
argument expression every time you call
the name lookups.
...
outfil_write = outfil.write
append_newline = {}\n.format
...
outfil_write(append_newline(t))
...
--
Neil Cerutti
--
http://mail.python.org/mailman/listinfo/python-list
On 2012-01-03, Stefan Krah stefan-use...@bytereef.org wrote:
Neil Cerutti ne...@norwich.edu wrote:
In the real-world telco benchmark for _decimal, replacing the
single line
outfil.write(%s\n % t)
with
outfil.write({}\n.format(t))
adds 23% to the runtime. I think
On 2012-01-03, Neil Cerutti ne...@norwich.edu wrote:
On 2012-01-03, Stefan Krah stefan-use...@bytereef.org wrote:
Neil Cerutti ne...@norwich.edu wrote:
In the real-world telco benchmark for _decimal, replacing the
single line
outfil.write(%s\n % t)
with
outfil.write
, but only
once. The C++ implementation starts to smell sort of like
Python. ;)
--
Neil Cerutti
--
http://mail.python.org/mailman/listinfo/python-list
, best of 3: 0.965 usec per loop
C:\WINDOWSpython -m timeit -n 100 -s n=7.92 '{}'.format(n)
100 loops, best of 3: 1.17 usec per loop
--
Neil Cerutti
--
http://mail.python.org/mailman/listinfo/python-list
, then it should be challenged. The possible broken-nose
of a questioner is a small price to pay for the education of the
peanut gallery.
If a questioner does not wish to defend what they are doing, he
or she has that right, of course.
--
Neil Cerutti
--
http://mail.python.org/mailman/listinfo/python-list
generator in an object with __enter__
and __exit__ methods for you.
--
Neil Cerutti
--
http://mail.python.org/mailman/listinfo/python-list
=, operator+, and operator+=
in C++ you'll know how and why they are different. A C++
programmer would be wondering how either can work on immutable
objects, and that's where Python's magical rebinding semantics
come into play.
--
Neil Cerutti
--
http://mail.python.org/mailman/listinfo/python-list
Python or Pike.
(With apologies to Larry Wall)
Were one inclined to troll a bit, one might be tempted to claim
that using C++ is prima facie evidence of not understanding
C++.
Not that I would ever claim something inflamitory like that...
On the Python newsgroup, it's funny. ;)
--
Neil Cerutti
On 2012-01-13, Evan Driscoll edrisc...@wisc.edu wrote:
On 01/13/2012 10:54 AM, Neil Cerutti wrote:
If you've ever implemented operator=, operator+, and operator+=
in C++ you'll know how and why they are different.
At the same time, you'd also know that that implementing them
in such a way
presented, the latter two leave
very strong coupling between the code in your separate files.
This makes working with the files independently impractical.
Stick with mixin classes and pay heed to the Law of Demeter if
you want to de-couple them enough to work on independently.
--
Neil Cerutti
--
http
insist on
QUANTIFYING a QUANTIFIER, simply use any number of legal
QUANTIFIERS. I think XYZ is VERY easy or I think XYZ is
SOMEWHAT easy or I think XYZ is difficult.
I remind you of http://orwell.ru/library/essays/politics/english/e_polit
--
Neil Cerutti
--
http://mail.python.org/mailman
pronunciation of Beauchamp created a minor incident
at Yeoman of the Guard auditions this weekend.
--
Neil Cerutti
--
http://mail.python.org/mailman/listinfo/python-list
On 2012-01-30, Chris Angelico ros...@gmail.com wrote:
On Mon, Jan 30, 2012 at 11:12 PM, Neil Cerutti ne...@norwich.edu wrote:
The British pronunciation of Beauchamp created a minor incident
at Yeoman of the Guard auditions this weekend.
What about Sir Richard Chumley, the Left Tenant
'
i = n - len(seq)
while i n:
yield seq[i]
i += 1
if __name__ == __main__:
import doctest
doctest.testmod()
If you have merely an iterable instead of a sequence, then look
to some of the other clever stuff already posted.
--
Neil Cerutti
--
http://mail.python.org
, slicker,
more proper, pythonic ways to do this.
I think you've found an excellent way to do it.
--
Neil Cerutti
--
http://mail.python.org/mailman/listinfo/python-list
of characters you'd like to be able to
put back.
--
Neil Cerutti
--
http://mail.python.org/mailman/listinfo/python-list
and that constant will ALWAYS be larger!
What's the point of that?
The only time I've naively pined for such a thing is when
misapplying C idioms for finding a minimum value.
Python provides an excellent min implementation to use instead.
--
Neil Cerutti
--
http://mail.python.org/mailman/listinfo/python-list
do. A truncated string with a maxlength of INFINITY is just a
string.
--
Neil Cerutti
--
http://mail.python.org/mailman/listinfo/python-list
and then decode, rather than try to encode a
non-encoded str.
--
Neil Cerutti
--
http://mail.python.org/mailman/listinfo/python-list
for jobs have to delete them.
--
Neil Cerutti
--
http://mail.python.org/mailman/listinfo/python-list
the seemingly random way in which we apply articles to our
nouns.
--
Neil Cerutti
--
http://mail.python.org/mailman/listinfo/python-list
instructions. A sequence of
instructions is an algorithm, program or routine. You may have
heard of them :)
A grammarian always uses complete sentence before a colon, even
when introducing a list.
--
Neil Cerutti
--
http://mail.python.org/mailman/listinfo/python-list
the grammatical rules used by
people in real life. You know the ones: linguists. My mistake.
I am not pedantic. You are wrong.
--
Neil Cerutti
--
http://mail.python.org/mailman/listinfo/python-list
On 2012-03-16, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote:
On Fri, 16 Mar 2012 17:53:24 +, Neil Cerutti wrote:
On 2012-03-16, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info
wrote:
Ah, perhaps you're talking about *prescriptivist* grammarians, who
insist on applying
On 2012-03-17, Terry Reedy tjre...@udel.edu wrote:
On 3/16/2012 9:08 AM, Neil Cerutti wrote:
A grammarian always uses complete sentence before a colon, even
when introducing a list.
The Chicago Manual of Style*, 13th edition, says The colon is
used to mark a discontinuity of grammatical
On 2012-03-19, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote:
On Mon, 19 Mar 2012 11:26:10 +, Neil Cerutti wrote:
[...]
*A major style guide for general American writing and
publication: used by some as the 'Bible'.
Thanks for the discussion and corrections. My apologies
seconds.
This message brought to you by the Debugging is Mostly
Comprehending Old Code and Testing Council.
--
Neil Cerutti
--
http://mail.python.org/mailman/listinfo/python-list
to work. It may be a simple case of just different
aspects the exact same type being being highlighted in each
definition.
--
Neil Cerutti
--
http://mail.python.org/mailman/listinfo/python-list
hypothetical implementation doesn't mean I can never say
anything about it.
I am in a similar situation viz a viz my wife's undergarments.
--
Neil Cerutti
--
http://mail.python.org/mailman/listinfo/python-list
7.
--
Neil Cerutti
--
http://mail.python.org/mailman/listinfo/python-list
i n:
fibminus2, fibminus1 = fibminus1, fibminus2 + fibminus1
i += 1
return fibminus2 + fibminus1
It's interesting that the loop iterative solution is, for me,
harder to think up without doing the tail-recursive one first.
--
Neil Cerutti
--
http
.
The web version of the book Data Structures and Algorithms with
Object-Oriented Design Patterns in Python contains a an
explanation in the chapters Algorithm Analysis and Asymptotic
Notation.
http://www.brpreiss.com/books/opus7/
--
Neil Cerutti
--
http://mail.python.org/mailman/listinfo/python
(record_re, m.group(6), flags=re.M | re.S)
for record in parse_file('45.txt'):
print(record)
--
Neil Cerutti
--
http://mail.python.org/mailman/listinfo/python-list
. Try invoking with -u option.
--
Neil Cerutti
--
http://mail.python.org/mailman/listinfo/python-list
of the text. Try adding the -u option
(unbuffered) to Python's command line:
pythonw.exe -u main.pyw
To expound a bit, using a windows-only module you can switch the
mode of stdin.
import sys
import msvcrt
msvcrt.setmode(sys.stdin.fileno(), os.O_BINARY)
--
Neil Cerutti
--
http
:
Class A:
Class B:
x = 2
or
Class A:
Class B:
def __init__(self):
self.x = 2
--
Neil Cerutti
--
http://mail.python.org/mailman/listinfo/python-list
On 2010-10-18, Neil Cerutti ne...@norwich.edu wrote:
On 2010-10-18, f...@slick.airforce-one.org f...@slick.airforce-one.org
wrote:
Hello.
I have a class A that contains two classes B and C:
class A:
class B:
self.x = 2
class C:
Is there a way to access the x defined in B
to cirrhossis of the dictionary.
Here's another idea:
for k in [k for k, v in d.items() if v is None]:
del d[k]
--
Neil Cerutti
--
http://mail.python.org/mailman/listinfo/python-list
the
bigger the scope of a variable, the longer and more descriptive
should be its name. In a small scope, a big name is mostly noise.
--
Neil Cerutti
--
http://mail.python.org/mailman/listinfo/python-list
be included.
Beginner mistakes like, define a class to model birds, and, #
increment the total, are worse than empty space.
--
Neil Cerutti
--
http://mail.python.org/mailman/listinfo/python-list
. Your books are
indeed useless.
Python's documentation contains an excellent summary of new
features and changes dating back to Python 2.0.
http://docs.python.org/py3k/whatsnew/index.html
--
Neil Cerutti
--
http://mail.python.org/mailman/listinfo/python-list
On 2010-11-01, Martin v. Loewis mar...@v.loewis.de wrote:
i.e. avoid the backslash for multi-line conditions altogether
(in fact, I can't think any situation where I would use the
backslash).
The horrible-to-nest with statement.
--
Neil Cerutti
--
http://mail.python.org/mailman/listinfo
,is_palindrom, pig_latin, and so
forth might make good Python exercises, too.
--
Neil Cerutti
--
http://mail.python.org/mailman/listinfo/python-list
than
Victorian.
--
Neil Cerutti
--
http://mail.python.org/mailman/listinfo/python-list
of certain constructs.
if x: print(x)
elif y: print(y)
else: print()
versus
if x
print(x)
elif y
print(y)
else
print()
Beauty-is-in-the-eye-of-the-BDFLly-yours,
--
Neil Cerutti
--
http://mail.python.org/mailman/listinfo/python-list
is fairly easy in
Python. Auto-dedent is the impossible part.
--
Neil Cerutti
--
http://mail.python.org/mailman/listinfo/python-list
On 2010-11-04, Grant Edwards inva...@invalid.invalid wrote:
On 2010-11-04, Neil Cerutti ne...@norwich.edu wrote:
On 2010-11-04, D'Arcy J.M. Cain da...@druid.net wrote:
* Not being able to write an auto-indenter, ever, because it
is by design theoretically impossible: Annoying.
Right
strictly legal. You can expect problems, or at
least warnings, with other tools with such files.
--
Neil Cerutti
--
http://mail.python.org/mailman/listinfo/python-list
. ;)
--
Neil Cerutti
--
http://mail.python.org/mailman/listinfo/python-list
On 2010-11-07, Lawrence D'Oliveiro l...@geek-central.gen.new_zealand wrote:
In message 8jftftfel...@mid.individual.net, Neil Cerutti wrote:
The handsome ':' terminator of if/elif/if statements allows us to
omit a newline, conserving vertical space. This improves the
readability of certain
.
--
Neil Cerutti
--
http://mail.python.org/mailman/listinfo/python-list
in Python.
The determined Real Programmer can write Fortran programs in
any language.
They probably won't run quite as as fast, though.
--
Neil Cerutti
--
http://mail.python.org/mailman/listinfo/python-list
it, but as a Vim user I can't partake.
--
Neil Cerutti
--
http://mail.python.org/mailman/listinfo/python-list
with the
Chaotic Neutrals.
--
Neil Cerutti
--
http://mail.python.org/mailman/listinfo/python-list
, not in lisps.
In Common Lisp you have:
CL-USER (union '(a b c) '(b c d))
(A B C D)
CL-USER (intersection '(a b c) '(b c d))
(C B)
What's the rationale for providing them? Are the definitions
obvious for collections that a not sets?
--
Neil Cerutti
--
http://mail.python.org/mailman/listinfo/python
#
# and ornate is a huge time-waster if#
# you let it get the best of you. #
##-**-##-**-##-**-##-**-##-**-##-**-##-**-##-**-##
--
Neil Cerutti
--
http://mail.python.org/mailman/listinfo/python-list
in programming?!
Under the assumption that leading white space is important for
code formatting, but that all alignment after that is
unimportant. Peek at Stroustrup's writing for examples. It really
doesn't take much time at all to get used to it.
--
Neil Cerutti
--
http://mail.python.org/mailman
On 2011-07-22, Ian Kelly ian.g.ke...@gmail.com wrote:
On Fri, Jul 22, 2011 at 6:59 AM, Neil Cerutti ne...@norwich.edu wrote:
Under the assumption that leading white space is important for
code formatting, but that all alignment after that is
unimportant.
...unless you're trying to adhere
On 2011-07-22, John Gordon gor...@panix.com wrote:
In 98u00kfnf...@mid.individual.net Neil Cerutti ne...@norwich.edu writes:
You can fit much more code per unit of horizontal space with a
proportionally spaced font. As a result, that issue, while
valid, is significantly reduced.
Is it? I
901 - 1000 of 1188 matches
Mail list logo