ncement request to the
HOWTO, explaining that continuation my be required in this
context. Am I missing anything obvious?
--
Neil Cerutti
--
http://mail.python.org/mailman/listinfo/python-list
On 2009-11-23, Terry Reedy wrote:
> Neil Cerutti wrote:
>> Unfortunately, the new "nested" with statement (which I also read
>> about today) forces me into this anti-idiom. When replacing an
>> appearance of contextlib.nested with the 3K with statement, I
>&g
On 2009-11-24, Antoine Pitrou wrote:
> It tries to evaluate the op of the stack (here nonevar) in a
> boolean context (which theoretically involves calling
> __nonzero__ on the type)
...or __bool__ in Py3K.
--
Neil Cerutti
--
http://mail.python.org/mailman/listinfo/python-list
excluding strings, since for these there is ''.join()).
reduce, or functools.reduce in Python 3.1.
>>> functools.reduce(operator.add, ((1, 2), (5, 6)))
(1, 2, 5, 6)
--
Neil Cerutti
"It's not fun to build walls. But it's even less fun to live
without walls in
#x27; (which defaults to 0).
>
> What part of that suggested to you that sum might not be polymorphic?
> Sure, it says numbers (which should be changed, in my opinion), but it
> doesn't specify what sort of numbers -- ints, floats, or custom types
> that have an __add__ method.
W
obsolete caused me a lot more
trouble than switching from 2.5 to 3.1.
Past advice in this forum has been that as long as you don't
depend on libraries that don't yet support Python 3, you can
probably switch over and not need to look back.
--
Neil Cerutti
--
http://mail.python.org/mailman/listinfo/python-list
but as a Vim user I can't partake.
--
Neil Cerutti
--
http://mail.python.org/mailman/listinfo/python-list
se syntax has non-trivial benefits. It makes a
macro system feasible.
--
Neil Cerutti
--
http://mail.python.org/mailman/listinfo/python-list
can be a
good idea. Python provides inheritance and the NotImplmented
exception to help with that. Duck-typing is another popular
approach.
--
Neil Cerutti
--
http://mail.python.org/mailman/listinfo/python-list
e.g.,
et.find('{{0}}ab/{{0}}cd'.format(XMLNS), et al, I can use
find(et, 'ab/cd').
Is there a better ElemenTree based approach I'm missing out on?
And on the other hand, am I circumventing something important, or
inviting bad limitations of some kind?
--
Neil Cerutti
--
http://mail.python.org/mailman/listinfo/python-list
ever possible while serializing. For debugging, try using
.dump instead. Hopefully that makes the error obvious.
--
Neil Cerutti
--
http://mail.python.org/mailman/listinfo/python-list
On 2011-01-31, Daniel Stender wrote:
> Hi guys,
>
> we are trying to convert a Sanskrit dictionary which is in a
> "homegrown" XML format into dict(d), the input file goes like
> this:
xml.etree.ElementTree will parse your file and return it as a
hierarchy of dict-like E
ars* of education and I'll be ready
for summing things in Python. ;)
--
Neil Cerutti
--
http://mail.python.org/mailman/listinfo/python-list
pretty trivial
to convert his Pascal to Python, and you'll get to basic parsing
in no time. URL:http://compilers.iecc.com/crenshaw/
--
Neil Cerutti
--
http://mail.python.org/mailman/listinfo/python-list
s under the hood, and possibly be very confused.
I don't agree with that. If a person is trying to ski using
pieces of wood that they carved themselves, I don't expect them
to be surprised that the skis they buy are made out of similar
materials.
--
Neil Cerutti
--
http://mail.python.org/mailman/listinfo/python-list
On 2010-04-11, Steven D'Aprano
wrote:
> On Sat, 10 Apr 2010 10:11:07 -0700, Patrick Maupin wrote:
>> On Apr 10, 11:35??am, Neil Cerutti wrote:
>>> On 2010-04-10, Patrick Maupin wrote:
>>> > as Pyparsing". ??Which is all well and good, except then the
hese substrings in
> my txt file;
>
> now I don't know how to continue. What is the best way to locate some
> string in a file and output them (with print command or in another
> file)?
grep
Or: show your work.
--
Neil Cerutti
--
http://mail.python.org/mailman/listinfo/python-list
e
of your Chevrolet.
> The point is, what you're suggesting doesn't save work at all
> as you've shown it. There are other ways to do the same thing,
> for virtually no work at all.
Don't put big text dumps in your program. Problem solved!
--
Neil Cerutti
*** Your child was
(Intel)] on
win32
Type "help", "copyright", "credits" or "license" for more information.
>>> funs = [lambda: x for x in range(5)]
>>> [f() for f in funs]
[4, 4, 4, 4, 4]
--
Neil Cerutti
*** Your child was bitten by a Bat-Lizard. ***
--
http://mail.python.org/mailman/listinfo/python-list
d, try filter and enumerate.
>>> b = [a for a,b in filter(lambda x: x[1]==3, enumerate(a))]
>>> b
[1, 2]
--
Neil Cerutti
*** Your child was bitten by a Bat-Lizard. ***
--
http://mail.python.org/mailman/listinfo/python-list
m in enumerate(a) if item == 3 ]
That form of list comprehension is preferable to my use of filter
posted elsewhere, but it didn't occur to me. Oops!
--
Neil Cerutti
*** Your child was bitten by a Bat-Lizard. ***
--
http://mail.python.org/mailman/listinfo/python-list
r solutions
> than the ones I'm using ATM.
> The first annoyance is when I want to specialize a property in a
> subclass.
See:
URI:http://infinitesque.net/articles/2005/enhancing%20Python%27s%20property.xhtml
--
Neil Cerutti
*** You found a dead moose-rat. You sell the hide for
.reader( csvfile, dialect )
Use:
csvfile = csv.reader(csvfile, dialect=dialect)
dialect is a keyword argument.
> if csv.Sniffer().has_header( sample ): #if there is a header
> colnames = csvfile.next() # label columns from first line
> datalist = list( csvfile ) # append
On 2010-06-03, Neil Cerutti wrote:
> Do you really need to use the Sniffer? You'll probably be better
> off...
...defining your own dialect based on what you know to be the
file format.
--
Neil Cerutti
--
http://mail.python.org/mailman/listinfo/python-list
that
> line
Is it possible your data is ill-formed in that case? If it's
lacking a line-end, I don't know what should happen.
--
Neil Cerutti
--
http://mail.python.org/mailman/listinfo/python-list
;ll be up
to you to program the recognition logic. Do you have a heuristic
in mind?
You will be better off converting tabbed files to be tabless,
which is pretty easy in vim.
:set expandtab
:set tabstop=N
:retab
N should be whatever value makes the file look right, usually 4
or 8.
--
Neil Cerut
What's the best way to do the inverse operation of the .join
function?
--
Neil Cerutti
--
http://mail.python.org/mailman/listinfo/python-list
On 2010-06-17, Ian Kelly wrote:
> On Thu, Jun 17, 2010 at 11:45 AM, Neil Cerutti
> wrote:
>> What's the best way to do the inverse operation of the .join
>> function?
>
> Use the str.split method?
split is perfect except for what happens with an empty strin
On 2010-06-17, Robert Kern wrote:
> On 6/17/10 2:08 PM, Neil Cerutti wrote:
>> On 2010-06-17, Ian Kelly wrote:
>>> On Thu, Jun 17, 2010 at 11:45 AM, Neil Cerutti
>>> wrote:
>>>> What's the best way to do the inverse operation of the .join
>
On 2010-06-18, Steven D'Aprano wrote:
> On Thu, 17 Jun 2010 20:03:42 +0000, Neil Cerutti wrote:
>> I'm currently using the following without problems, while
>> reading a data file. One of the fields is a comma separated
>> list, and may be empty.
>
sv.reader([rec['code1']]))
> ['1', '2', '3']
>>>> next(csv.reader([rec['code2']]))
> []
Slick!
--
Neil Cerutti
--
http://mail.python.org/mailman/listinfo/python-list
rare that I know the best operations for each bit of
data and how best to bundle that data until after a program is
functional. It is lucky my programs are relatively small. ;)
--
Neil Cerutti
--
http://mail.python.org/mailman/listinfo/python-list
lly odd example of a similar name clash, create a tab
separated values file with a header line starting with ID (I get
lots of them in my work), and then open it with Excel (I don't
know which version has the most bizarre error message).
--
Neil Cerutti
--
http://mail.python.org/mailman/listinfo/python-list
t myObject.size is involved
> in calculations, then the oofun is created to behave like
> similar numpy.array attribute.
Telling them, "Don't do that," is a good solution in Python.
--
Neil Cerutti
--
http://mail.python.org/mailman/listinfo/python-list
o back to Python 2.6?
--
Neil Cerutti
--
http://mail.python.org/mailman/listinfo/python-list
On 2010-07-21, Tim Golden wrote:
> On 21/07/2010 2:15 PM, Neil Cerutti wrote:
>> A quick web search yielded no current support for the ODBC
>> interface for Python 3.
>>
>> I'd like to get a simple "tracer bullet" up and running ASAP. I
>> need to c
On 2010-07-23, Jim wrote:
> How can I calculate how much time is between now and the next
> 2:30 am? Naturally I want the system to worry about leap
> years, etc.
You need the datetime module. Specifically, a datetime and
timedelta object.
--
Neil Cerutti
--
http://mail.python.or
blem is that the nodeValue stored in the variable 'name' is not "AB"
> (what i want) but instead it is a string that has length of 8 and it seems
> it include the tabs and/or other things.
> How can i get the string "AB" without the other stuff?
Check out the strip member function.
name = r.childNodes[0].nodeValue.strip()
--
Neil Cerutti
--
http://mail.python.org/mailman/listinfo/python-list
Every tme the tests ran, you'd get a new email containing the
results.
--
Neil Cerutti
--
http://mail.python.org/mailman/listinfo/python-list
On 2010-07-28, Jonathan Hartley wrote:
> And Neil Cerutti, I think I'll just email the whole source tree
> to myself, and have a script that scans my inbox, unzips source
> trees and runs their tests. Much nicer. :-)
Don't forget to clear the screen, though. That ties the who
st)
> for i in range(0,self.newPassengers):
> self.passengerList.append(self.passengerWaitQ.pop())
> self.goUp()
Does your program call checkQueue?
--
Neil Cerutti
--
http://mail.python.org/mailman/listinfo/python-list
On 2010-08-12, Dave Angel wrote:
> For puzzles:
>
> http://projecteuler.net
...if you like math problems.
> http://www.pythonchallenge.com
...if you like fooling around with PIL, graphics and bytes.
--
Neil Cerutti
--
http://mail.python.org/mailman/listinfo/python-list
to it if they
> aren't used to it already.
I think the main reason zero-based indexing is chosen in higher
level languages is the following useful property:
x[n:m] + x[m:len(x)] == x
--
Neil Cerutti
--
http://mail.python.org/mailman/listinfo/python-list
On 2010-08-15, John Nagle wrote:
> In retrospect, C's "pointer=array" concept was a terrible
> mistake.
C arrays are not pointers.
--
Neil Cerutti
--
http://mail.python.org/mailman/listinfo/python-list
27;, '%m%d%Y')
The other cases are when indentation levels get the best of me,
but I'm too lazy to refactor.
--
Neil Cerutti
--
http://mail.python.org/mailman/listinfo/python-list
On 2010-08-17, Stefan Schwarzer wrote:
> Hi Neil,
>
> On 2010-08-17 14:42, Neil Cerutti wrote:
>> Looking through my code, the split-up lines almost always
>> include string literals or elimination of meaningless
>> temporary variables, e.g.:
>>
>>
'
>
> If you have backslashes in strings, you might want to use "raw
> strings". Instead of "c:\\Users\\ZDoor" you'd write
> r"c:\Users\ZDoor" (notice the r in front of the string).
That's good general advice. But in the specific case of file
paths, using '/' as the separator is supported, and somewhat
preferable.
--
Neil Cerutti
--
http://mail.python.org/mailman/listinfo/python-list
ed not obscure the meaning, and may
even improve it, *if* the names of the new functions are good.
--
Neil Cerutti
--
http://mail.python.org/mailman/listinfo/python-list
7;m
converting one known format (the one in the XML) to another
required format (the one required by another program). There's no
need to guess the format.
--
Neil Cerutti
--
http://mail.python.org/mailman/listinfo/python-list
> obtain the proper offset.
Because they know deep down they wouldn't win anything.
--
Neil Cerutti
--
http://mail.python.org/mailman/listinfo/python-list
gt; There was a fling a while ago with typesetting code in
> proportional spaced type. I think some of the "Effective C++"
> series from Addison-Wesley did that. Yuck.
It's probably influenced by The C++ Programming Language.
Stroustrup likes it.
--
Neil Cerutti
--
http://mail.python.org/mailman/listinfo/python-list
guments clear.
find is just a small wrapper around Element.find calls, inserting
the namespace.
--
Neil Cerutti
--
http://mail.python.org/mailman/listinfo/python-list
oop-style iteration. However, Scheme does tail-call
optimization, I believe, which is slightly more general.
--
Neil Cerutti
--
http://mail.python.org/mailman/listinfo/python-list
On 2010-08-21, Steven D'Aprano wrote:
> There is room in the world for programming languages aimed at
> non- programmers (although HC is an extreme case), but not all
> languages should prefer the intuition of non-programmers over
> other values.
Extremer: Inform 7.
--
Neil
p.
def fibi(n):
if n < 2:
return 1
else:
fibminus2 = 1
fibminus1 = 1
i = 2
while i < n:
fibminus2, fibminus1 = fibminus1, fibminus2 + fibminus1
i += 1
return fibminus2 + fibminus1
It's interesting that the
rticle about this
>> subject? I imagine that it has a concise name.
>>
> It's called the "Big O notation".
The web version of the book "Data Structures and Algorithms with
Object-Oriented Design Patterns in Python" contains a an
explanation in the chapter
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
king with -u option.
--
Neil Cerutti
--
http://mail.python.org/mailman/listinfo/python-list
t;
> By default, Python opens stdin in buffered text mode in which
> '\x1A' marks the end 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 mod
ass 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 wrote:
> On 2010-10-18,
> 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
ad 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
t; ...
> ...
> yCoordinate += 1
_The Practice of Programming_ has this right. In general 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
ented in your module, should 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
n years ago puts around the time of Python 2.1. 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 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/python-list
lems, which I
think is quite nice. possessive,is_palindrom, pig_latin, and so
forth might make good Python exercises, too.
--
Neil Cerutti
--
http://mail.python.org/mailman/listinfo/python-list
s in
columns is just as bad.
Code should be utilitarian rather than ornate, Shaker rather than
Victorian.
--
Neil Cerutti
--
http://mail.python.org/mailman/listinfo/python-list
ine.
The handsome ':' terminator of if/elif/if statements allows us to
omit a newline, conserving vertical space. This improves the
readability 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
lly. Auto-indent 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 wrote:
> On 2010-11-04, Neil Cerutti wrote:
>> On 2010-11-04, D'Arcy J.M. Cain wrote:
>>>> * Not being able to write an auto-indenter, ever, because it
>>>> is by design theoretically impossible: Annoying.
>>>
>>
g a list. Just do
>
> with open(r'c:\test.txt') as f:
>for l in f:
>print int(l)
>
> As long as you just have digits and whitespace then that's fine
> - int() will do as you want.
Keep in mind that a file that a text file that doesn't end with
a newline isn't 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
t;, MainWindow.ColorsHighlightedList),
("selected", "select", MainWindow.ColorsSelectedList)]
Moreover, I jump the gun early on tables like this.
styles = [csv.reader(open("styles.csv", newlines=''))]
Maybe too early. ;)
--
Neil Cerutti
--
http://mail.python.org/mailman/listinfo/python-list
On 2010-11-07, Lawrence D'Oliveiro 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
>> r
ave different settings,
>> and they will see different indentations for your code
>
> That's exactly the point -- each person can decide what level
> of indentation they prefer to look at.
That ideal works only if you are disciplined to never mix tabs
and spaces. "Wrapped"
tten 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
>> used.
>
> I use it a lot ;-)
Me too. I wrote a script once to convert all my .cfg files to
JSON at one point while trying out a switch from Python to Go,
but never made the changeover.
--
Neil Cerutti
--
https://mail.python.org/mailman/listinfo/python-list
mn-names portion of an INSERT statement.
quoted_val, = c.execute("SELECT quote(?);", (val,)).fetchone()
--
Neil Cerutti
--
https://mail.python.org/mailman/listinfo/python-list
On 2017-04-03, Jay Braun wrote:
> I hear people say it like the plural of "panda", and others as
> "panduss". Is there a correct way?
I think it is pronounced like the regular word. The second a is
schwa in both the singular and plural.
--
Neil Cerutti
--
https
that
concentrates on functional programming with immutable state if
you haven't done it before. The book that worked for me was
Simply Scheme https://people.eecs.berkeley.edu/~bh/ss-toc2.html,
but that's sorta ancient history now and I'm sure there's lots
more options out there.
--
ands from different levels of abstraction, e.g., only call
'commit' directly if you called 'begin' directly.
--
Neil Cerutti
--
https://mail.python.org/mailman/listinfo/python-list
On 2017-06-02, Dennis Lee Bieber wrote:
>
> A bit of a long free-association rambling...
>
> On Fri, 2 Jun 2017 12:07:45 + (UTC), Neil Cerutti
> declaimed the following:
>>You're probably not expected to interleave transaction control
>>commands from
at the
> module, connection and cursor levels.
You get autocommit with sqlite3 by setting isolation_level=None
on the connection object.
https://docs.python.org/2/library/sqlite3.html#sqlite3-controlling-transactions
--
Neil Cerutti
--
https://mail.python.org/mailman/listinfo/python-list
this point, after only one bad experience trying to
work around my choice of container.
--
Neil Cerutti
--
https://mail.python.org/mailman/listinfo/python-list
nd illuminate dark corners
of both my own skill and Python's features.
An Excel spreadsheet that represents a table of data is fairly
simple to map onto a Python dict. One nearly codeless way is to
export it from Excel as a csv file and then read it with
csv.DictReader.
--
Neil Cerutti
--
https://mail.python.org/mailman/listinfo/python-list
ect that has the methods that should only be
> called for active connections. That way it's not possible to do
> things out of sequence.
It's like a bidirectional iterator in C++, except in reverse it's
random access. An iterator that can't easily be modeled with a
generato
s separate
API's that allow you to regard those bytes as either plain old
bytes, or as a sequence of runes (not-necessarily normalized
codepoints). If your bytes strings aren't in UTF-8, then Go Away.
https://blog.golang.org/strings
--
Neil Cerutti
--
https://mail.python.org/mailman/listinfo/python-list
33) / 2
You could also calculate it with a combination of sum and range
builtins, as others have hinted, and if it's homework that's
probably a good idea.
--
Neil Cerutti
--
https://mail.python.org/mailman/listinfo/python-list
1101 - 1188 of 1188 matches
Mail list logo