James Stroud wrote:
It seems I need constructs like this all of the time
i = 0
while i len(somelist):
if oughta_pop_it(somelist[i]):
somelist.pop(i)
else:
i += 1
There has to be a better way...
somelist[:] = [ item for item in somelist if not oughta_pop_it(item) ]
Kent
--
rbt wrote:
rbt wrote:
This function is intended to remove unwanted files and dirs from
os.walk(). It will return correctly *IF* I leave the 'for fs in
fs_objects' statement out (basically leave out the entire purpose of
the function).
It's odd, when the program goes into that statment... even
rbt wrote:
## for fs in fs_objects:
##
##for f in fs[2]:
##if f in file_skip_list:
##print f
##fs[2].remove(f)
##
##for d in fs[1]:
##if d in dir_skip_list:
##print d
##
Grant Edwards wrote:
Is it true that a datetime object can convert itself into a
string, but not the other way around? IOW, there's no simple
way to take the output from str(d) and turn it back into d?
According to this thread, a patch has been checked in that adds strptime() to datetime. So
Chad Everett wrote:
Nope, I am trying to learn it on my own. I am using the book by Michael
Dawson.
You might be interested in the Python tutor mailing list which is
specifically intended for beginners.
http://mail.python.org/mailman/listinfo/tutor
Kent
--
Kent Johnson wrote:
You might be interested in the Python tutor mailing list which is
specifically intended for beginners.
http://mail.python.org/mailman/listinfo/tutor
Ah, I don't mean to imply that this list is unfriendly to beginners, or that you are not welcome
here! Just pointing out
Stefan Behnel wrote:
Hi!
This somewhat puzzles me:
Python 2.4 (#1, Feb 3 2005, 16:47:05)
[GCC 3.3.4 (pre 3.3.5 20040809)] on linux2
Type help, copyright, credits or license for more information.
. class test(object):
... def __init__(self):
... self.__call__ = self.__call1
... def
John Fabiani wrote:
Hi,
Since this is (sort of) my second request it must not be an easy solution.
Are there others using Python to connect MsSQL? At the moment I'd accept
even a windows solution - although, I'm looking for a Linux solution.
On Windows, you can use
Diez B. Roggisch wrote:
I know its easy (string.replace()) but why does UTF-16 do
it on its own then? Is that according to Unicode standard or just
Python convention?
BOM is microsoft-proprietary crap.
Uh, no. BOM is part of the Unicode standard. The intent is to allow consumers of Unicode text
Jive Dadson wrote:
I don't think I've quite got it.
The application I'm writing has some similarities to an interactive
shell. Like an interactive shell, it executes arbitrary code that it
receives from an input stream. When it gets an exception, it should
create an informative message,
Fredrik Lundh wrote:
Robert Kern wrote:
Fair enough. The only time I've seen it in dead-tree print was in Heinlein's _Time Enough For
Love_, unattributed to anyone else.
Amazon.com search inside the book finds no hits for malice in this book.
Is it possible to subclass cElementTree.Element? I tried
import cElementTree as et
class Elt(et.Element):
... pass
...
Traceback (most recent call last):
File stdin, line 1, in ?
TypeError: Error when calling the metaclass bases
cannot create 'builtin_function_or_method' instances
I
Bo Peng wrote:
Kent Johnson wrote:
You are still including the compile overhead in fun2. If you want to
see how fast the compiled code is you should take the definition of
myfun out of fun2:
I assumed that most of the time will be spent on N times execution of
myfunc.
Doh! Right.
Kent
--
http
Bo Peng wrote:
Dear list,
I have many dictionaries with the same set of keys and I would like to
write a function to calculate something based on these values. For
example, I have
a = {'x':1, 'y':2}
b = {'x':3, 'y':3}
def fun(dict):
dict['z'] = dict['x'] + dict['y']
fun(a) and fun(b) will set
Bo Peng wrote:
Yes. I thought of using exec or eval. If there are a dozen statements,
def fun(d):
exec 'z = x + y' in globals(), d
seems to be more readable than
def fun(d):
d['z'] = d['x'] + d['y']
But how severe will the performance penalty be?
You can precompile the string using compile(),
Bo Peng wrote:
Exec is slow since compiling the string and calls to globals() use a
lot of time. The last one is most elegant but __getattr__ and
__setattr__ are costly. The 'evil hack' solution is good since
accessing x and y takes no additional time.
Previous comparison was not completely
Daniel Bickett wrote:
|def reverse( self ):
|
|Return a reversed copy of string.
|
|string = [ x for x in self.__str__() ]
|string.reverse()
|return ''.join( string )
def reverse(self):
return self[::-1]
Kent
--
Benji99 wrote:
I've managed to load the html source I want into an object
called htmlsource using:
import urllib
sock = urllib.urlopen(URL Link)
htmlSource = sock.read()
sock.close()
I'm assuming that htmlSource is a string with \n at the end of
each line.
NOTE: I've become very accustomed
Klaus Neuner wrote:
Hello,
what is the fastest way to determine whether list l (with
len(l)3) contains a certain element?
If you can use a set or dict instead of a list this test will be much
faster.
Kent
--
http://mail.python.org/mailman/listinfo/python-list
[EMAIL PROTECTED] wrote:
Input is this:
SET1_S_W CHAR(1) NOT NULL,
SET2_S_W CHAR(1) NOT NULL,
SET3_S_W CHAR(1) NOT NULL,
SET4_S_W CHAR(1) NOT NULL,
;
.py says:
import re, string, sys
s_ora = re.compile('.*S_W.*')
lines = open(y.sql).readlines()
for i in range(len(lines)):
try:
if
Thomas Guettler wrote:
# No comma at the end:
mylist=[]
for i in range(511):
mylist.append(Spam)
or just
mylist = [Spam] * 511
Kent
print , .join(mylist)
Thomas
--
http://mail.python.org/mailman/listinfo/python-list
Jacob H wrote:
Hello list...
I'm developing an adventure game in Python (which of course is lots of
fun). One of the features is the ability to save games and restore the
saves later. I'm using the pickle module to implement this. Capturing
current program state and neatly replacing it later is
Nick Craig-Wood wrote:
Martin Häcker [EMAIL PROTECTED] wrote:
Now I thought, just overide the ctor of datetime so that year, month and
day are static and everything should work as far as I need it.
That is, it could work - though I seem to be unable to overide the ctor. :(
Its a bug!
Luis P. Mendes wrote:
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1
this is the xml document:
?xml version=1.0 encoding=utf-8?
string xmlns=http://www..;lt;DataSetgt;
~ lt;Ordergt;
~ lt;Customergt;439lt;/Customergt;
(... others ...)
~ lt;/Ordergt;
lt;/DataSetgt;/string
This is an
Irmen de Jong wrote:
Kent Johnson wrote:
[...]
This is an XML document containing a single tag, string, whose
content is text containing entity-escaped XML.
This is *not* an XML document containing tags DataSet, Order,
Customer, etc.
All the behaviour you are seeing is a consequence
Martin Häcker wrote:
Hi there,
I just tried to run this code and failed miserably - though I dunno
why. Could any of you please enlighten me why this doesn't work?
Here is a simpler test case. I'm mystified too:
from datetime import datetime
class time (datetime):
def __init__(self, hours=0,
Paul McGuire wrote:
Kent Johnson [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
Martin Häcker wrote:
Hi there,
I just tried to run this code and failed miserably - though I dunno
why. Could any of you please enlighten me why this doesn't work?
Here is a simpler test case. I'm mystified
simon.alexandre wrote:
Hi all,
I use csv module included in python 2.3. I use the writer and encouter the
following problem: in my output file (.csv) there is a duplication of the
end of line character, so when I open the csv file in Ms-Excel a blank line
is inserted between each data line.
From
[EMAIL PROTECTED] wrote:
Kent:
I don't think so. You have hacked an attribute with latin-1
characters in it, but you
haven't actually created an identifier.
No, I really created an identifier. For instance
I can create a global name in this way:
globals()[è]=1
globals()[è]
1
Maybe I'm splitting
Andrea Griffini wrote:
I've to admit that I also found strange that deleting the
first element from a list is not O(1) in python. My wild
guess was that the extra addition and normalization required
to have insertion in amortized O(1) and deletion in O(1) at
both ends of a random access sequence
Aahz wrote:
In article [EMAIL PROTECTED],
Tony Meyer [EMAIL PROTECTED] wrote:
I don't think I've seen such a statement before - the stuff I've seen
all indicates that one should be submitting proper LaTeX docs/patches.
If plain-text contributions are welcome, could this be added to the doc
about
Philippe C. Martin wrote:
menu.add_cascade(label=File, menu=filemenu)
filemenu.add_command(label=New, command=lambda: callback('New'))
filemenu.add_command(label=Open..., command=lambda:
Of course you could do this with named forwarding functions if you
prefer
I'm not sure what 'named forwarding
Philippe C. Martin wrote:
I have many menu items and would like them all to call the same method
-However, I need the method called to react differently depending on the
menu item selected. Since the menu command functions do not seem to
receive any type of event style object, is there some type
Alex Martelli wrote:
Roy Smith [EMAIL PROTECTED] wrote:
Stefan Axelsson [EMAIL PROTECTED] wrote:
Yes, ignoring most of the debate about static vs. dynamic typing, I've
also longed for 'use strict'.
You can use __slots__ to get the effect you're after. Well, sort of; it
only works for instance
Steve Holden wrote:
Just a little further background. The Python Software Foundation
recently awarded a grant to help to bring Jython into line with the
current CPython release.
Is information publicly available about this and other PSF grants? I don't see any announcement on
the PSF web site
Sean Blakey wrote:
On Wed, 22 Dec 2004 17:03:55 -0200, Gabriel Cosentino de Barros
[EMAIL PROTECTED] wrote:
On the Best GUI for small-scale accounting app? tread some people
mentioned jython. I went to read about it, but i was wondering if anyone has
any real project done with it and can give real
Tonino wrote:
thanks all for the info - and yes - speed is not really an issue and no
- it is not an implementation of a complete financial system - but
rather a small subset of a investment portfolio management system
developed by another company ...
What I am trying to achieve is to parse a
Robin Becker wrote:
Alex Martelli wrote:
.
By the way, if that's very important to you, you might enjoy Mozart
(http://www.mozart-oz.org/)
.very interesting, but it wants to make me install emacs. :(
Apparently you can also use oz with a compiler and runtime engine...see
Frans Englich wrote:
On Wednesday 15 December 2004 14:07, Diez B. Roggisch wrote:
In my use of getopt.getopt, I would like to make a certain parameter
mandatory. I know how to specify such that a parameter must have a value
if it's specified, but I also want to make the parameter itself
Markus Zeindl wrote:
I have got a string from the user, for example Hi!.
Now I get every character with a loop:
code
buffer =
for i in range(len(message)):
ch = message[i-1:i]
for ch in message:
...
is simpler and more idiomatic.
Kent
--
http://mail.python.org/mailman/listinfo/python-list
Keith Dart wrote:
try:
dict[a].append(b)
except KeyError:
dict[a] = [b]
or my favorite Python shortcut:
dict.setdefault(a, []).append(b)
Kent
--
http://mail.python.org/mailman/listinfo/python-list
Nick Coghlan wrote:
Simon Brunning wrote:
This work -
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/52295?
Only for old-style classes, though. If you inherit from object or
another builtin, that recipe fails.
Could you explain, please? I thought __getattr__ worked the same with new-
harrelson wrote:
I have a list of about 2500 html escape sequences (decimal) that I need
to convert to utf-8. Stuff like:
#48708;
#54665;
#44592;
#47196;
#48372;
#45244;
#44144;
#50640;
#50836;
#45236;
#47732;
#44552;
#51060;
#50620;
#47560;
#51648;
#51104;
Anyone know what the decimal is
Andy, this is a nice example. It prompted me to look at the docs for compiler.visitor. The docs are,
um, pretty bad. I'm going to attempt to clean them up a little. Would you mind if I include this
example?
Thanks,
Kent
Andy Gross wrote:
Here's a quick example that will pull out all functions
Jay O'Connor wrote:
The real question, I suppose, is what is a good technique to find what
modules and classes implement or refer to particular names
You might like to try ctags. I have had a good experience with it. It's not as automatic as I would
like - you have to build a cross-reference
Ishwor wrote:
s = 'hello'
m = s[:]
m is s
True
I discussed the *is* operator with some of the pythoners before as
well but it is somewhat different than what i intended it to do. The
LP2E by Mark David says -
m gets a *full top-level copy* of a sequence object- an object with
the same value but
Ishwor wrote:
On Sun, 05 Dec 2004 09:44:13 -0500, Kent Johnson [EMAIL PROTECTED] wrote:
This behaviour is due to the way strings are handled. In some cases strings are
'interned' which
lets the interpreter keep only a single copy of a string. If you try it with a
list you get a
different result
601 - 647 of 647 matches
Mail list logo