Re: how to reuse class deinitions?

2006-10-01 Thread Scott David Daniels
get use of them in python programs like: from sdd.goodidea import File ... ... or (actually my current style): from sdd import goodidea ... ... --Scott David Daniels [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list

Re: commands.getstatusoutput result is not command line exit value!!!

2006-10-02 Thread Scott David Daniels
f a sixteen-bit > value. You will notice that 3072 == 2 * 256. For the rest of us playing along at home, there is a typo there: The preceding line should read: > value. You will notice that 3072 == 12 * 256. --Scott David Daniels [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list

Re: Raw strings and escaping

2006-10-03 Thread Scott David Daniels
rom being rawstring. It gives people bad intuitions to refer to some strings as "raw" when what you really mean is that the notation you are using is a "raw" notation for a perfectly normal string. --Scott David Daniels [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list

Re: What's going on here?

2006-11-22 Thread Scott David Daniels
>>> class B(object): pass >>>> a = B() >>>> a.spam = 1 >>>> > > What is subclassing adding to the class here? Why can't I assign to > attributes of an instance of object? object itself doesn't have a __dict__ slot, so that very s

Re: Abelson and Python

2006-11-23 Thread Scott David Daniels
dly-to-translation-in-a-statically-typed-language way. Besides, if you can freely use "eval" and "exec", how hard is a pure python language interpreter? --Scott David Daniels [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list

Re: Local variables persist in functions?

2006-11-25 Thread Scott David Daniels
for chunk in chunky(somedata, size): ... for size in range(1, 30): print size, list(chunky('abcdefghijklmnopqrstuvwxyz', size)) --Scott David Daniels [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list

Pending: A Mixin class for testing

2006-11-26 Thread Scott David Daniels
Hacked(Pending, SomeTrickyClass): _pending = sample_value_generator() TempHold, SomeTrickyClass = SomeTrickyClass, Hacked try: finally: SomeTrickyClass = TempHold --Scott David Daniels [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo

Re: funcs without () like print

2006-12-07 Thread Scott David Daniels
t;self-calling- functions," you should change your wishes. If, however, you are talking solely about the interactive prompt and ease of typing, you might want to check out ipython (find via your favorite search tool). Its flexibility may well be to your taste. --Scott David Daniels [EMAIL

Re: binary input and memory address passing

2006-12-12 Thread Scott David Daniels
ython 2.2 and 2.3 installer, but the sources are there for you to compile (in which case you might toss a package back to me, and I'll put it up). If you look it over and have questions, let me know. --Scott David Daniels [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list

Re: Class and instance question

2006-12-17 Thread Scott David Daniels
_new__(class_): instance = object.__new__(class_) instance.a = 1 return instance You might have figured more of this out with: >>> t = T() >>> print repr(t) >>> newt = NewT() >>> print repr(newt) >>> T.a >>> t.a --Scott David Daniels [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list

Re: catching exceptions

2006-12-18 Thread Scott David Daniels
trvalue) raise # re-raise the exception that got us here. ... --Scott David Daniels [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list

Re: Splitting lines from a database query

2006-12-26 Thread Scott David Daniels
ou intend to get the newsgroup to write your code for you. Come back with your efforts and any problems you have with them. --Scott David Daniels [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list

Re: Splitting lines from a database query

2006-12-26 Thread Scott David Daniels
a list and loop to do the null checking, > and it still stops when (I think) it hits a blank value: > TypeError: cannot concatenate 'str' and 'NoneType' objects What's the data and program that does that? --Scott David Daniels [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list

Re: Noobie: Open file -> read characters & multiply

2006-12-26 Thread Scott David Daniels
his code uses a while != "" loop and doesn't look > pythony (it looks too 'c'). Not that there's anything wrong with that! > > Any help is really appreciated. for line in AP_file: print >>decoded_File, '%s.%04d' % divmod(int(line[:8],

Re: How to suppress the output of an external module ?

2006-12-26 Thread Scott David Daniels
another so you can use it again after the function is done (a system call). Next do the raw open (which should get the available channel), and the C stdout stuff is successfully redirected. Once done w/ your function, close your new stdout and copy the channel back. --Scott David Daniels [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list

Re: Some basic newbie questions...

2006-12-28 Thread Scott David Daniels
def __init__(self): self.guns = [Gun(), Gun()] def getShellsLeft(self): numShells = 0 for aGun in self.guns: numShells += aGun.shells return numShells theBizmark = Battleship() print theBizmark.getShellsLeft() > In the abo

Re: Some basic newbie questions...

2006-12-28 Thread Scott David Daniels
ot;sum" primitive ... def getShellsLeft(self): return sum([aGun.shells for aGun in self.guns]) ... For Python 2.4 or later: # allows generator expressions ... def getShellsLeft(self): return sum(aGun.shells for aGun in self.guns) ... --Scott David Daniels [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list

Re: How to suppress the output of an external module ?

2006-12-30 Thread Scott David Daniels
MRAB wrote: > Scott David Daniels wrote: >> [EMAIL PROTECTED] wrote: > In Windows the null device is, strictly speaking, "nul" or "nul:", not > "nul.txt", but the latter appears to work too. Although I find the windows design and reasoning to be a mist

Re: how to find the longst element list of lists

2007-01-07 Thread Scott David Daniels
["a", "b"], ["a", "b", "c", "d"]] You can find the longest with: maxlength, maxlist = max((len(lst), lst) for lst in list_of_lists) or (for those pre-2.5 people): maxlength, maxlist = max([(len(lst), lst) for lst in list_of_lists]) --Scott David Daniels [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list

Re: Match First Sequence in Regular Expression?

2006-01-27 Thread Scott David Daniels
uot;xaaayz123aaabab", "xyz123babaaabab", "xyz123aabbaaab", "xaaayz123abab"] [re.search(pattern, case) is not None for case in cases] [True, True, True, False, False, False] --Scott David Daniels [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list

Re: beta.python.org content

2006-01-27 Thread Scott David Daniels
_not_ Paragraph 3 in "Why Python": Some people uppose because Python ... I'd prefer the word "suppose." and later in that paragraph, I'd change: ... extensions that provide compact numerical solutions to: ... extensions that provide compact high-speed n

Re: 2-dimensional data structures

2006-01-27 Thread Scott David Daniels
r column in range(1,10): for row in range(1,10): grid[column, row] = None ... valueInCellOfGrid = grid[col, row] grid[col, row] = 9 ... --Scott David Daniels [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list

Re: How do I dynamically create functions without lambda?

2006-01-27 Thread Scott David Daniels
s callable, just as you know "type"s are callable. Seeing that it is class partial, you can (if you are nosey), see what the arguments already provided are (so you could get a nicer print). For example, adding a method to partial: def __repr__(self): return 'partial(%r, *%r, **%r)' % (self.fn, self.args, self.kw) > Something like perhaps? Is there any way for a > class to customise the type representation? -- -Scott David Daniels [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list

Re: [IDE] - The Dynamic Opportunity - ActiveState Komodo IDE / Open Source

2006-01-28 Thread Scott David Daniels
Ilias Lazaridis wrote: > As a first step, a free personal edition (non-commercial and academic > use) would help to spread the Komodo IDE within the communities. Yeah, and ActiveState makes up the loss in income on volume, eh? I've got no problem paying for good work. -- -Scott Da

Re: writing large files quickly

2006-01-28 Thread Scott David Daniels
icant difference. The nice thing is that file size grew over time, so (for a while) I could run on the machine with other users. By the last block of tapes I was sitting alone in the machine room at 3:00 AM on Sat mornings afraid to so much as fire up an editor. -- -Scott David Daniels [EMAIL P

Re: Efficient Find and Replace

2006-01-28 Thread Scott David Daniels
ition = lst.index(X, position + 1) except ValueError: pass # finally could not find X I mention this only because people always seem to forget than index allows you to specify a start (and/or stop) position w/in the list. --Scott David Daniels [EMAIL PROTECTED] -- http://mail

Re: General Type Checks (int, str, tuple, etc.)

2006-01-28 Thread Scott David Daniels
write your old language in Python. --Scott David Daniels [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list

Re: beta.python.org content

2006-01-28 Thread Scott David Daniels
Terry Hancock wrote: > On Fri, 27 Jan 2006 13:44:19 -0800 > Scott David Daniels <[EMAIL PROTECTED]> wrote: >> Paragraph 3 in "Why Python": >> and later in that paragraph, I'd change: >> ... extensions that provide compact numerical >> s

Re: StringIO proposal: add __iadd__

2006-01-29 Thread Scott David Daniels
ickle/pypickle and StringIO/pyStringIO How about something like a package py for all such python-coded modules so you use py.StringIO (which I hope gets renamed to stringio in the Py3K shift). -- -Scott David Daniels [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list

Re: Help saving output onto a text file

2006-01-29 Thread Scott David Daniels
t. finally: results.close() Captured "standard" output: import sys former, sys.stdout = sys.stdout, open('myname.txt', 'w') try: print 'This goes out.' print 'Similarly, this is the next line.'

Re: instance references?

2006-01-30 Thread Scott David Daniels
drawables[id(self)] = self -- -Scott David Daniels [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list

Re: instance references?

2006-01-31 Thread Scott David Daniels
Scott David Daniels wrote: > Alex Martelli wrote: (in effect) >>aptbase.drawables = weakref.WeakValueDictionary() >> then in each __init__ >>aptbase.drawables[len(aptbase.drawables)] = self >> then in show: >>for o in aptbase.drawables.values(): >&g

Re: Compiling

2006-02-03 Thread Scott David Daniels
f the code -- no simple translation would be much faster than the CPython implementation. By the way, be careful about your tone. It sounds like brick-throwing in this generally friendly newsgroup. --Scott David Daniels [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list

Re: MySQLdb question... using table name as arg

2006-02-03 Thread Scott David Daniels
for table_name in 'first', 'second', 'third', 'fourth': def perform(query, args): return cursor.execute( table_name.join(query.split('')), args) perform('UPDATE SET col1 = %s, col2 = %s&#x

Re: fairly large webapp: from Java to Python. experiences?

2006-02-04 Thread Scott David Daniels
r than Python will run the same thing, but in Python you may race five algorithms and keep the fastest. Using programmer resources effectively is Python's secret sauce. --Scott David Daniels [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list

Re: re.search slashes

2006-02-04 Thread Scott David Daniels
doesn't. Any tips? Give us examples that should work and that should not (test cases), and the proper results of those tests. Don't make people trying to help you guess about anything you know. --Scott David Daniels [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list

Re: Recursive function going infinite and I can't see why.

2006-02-04 Thread Scott David Daniels
ich subtree to choose. Because I am a clueless American, so I don't know if Piñero is a common name or not. Are you perhaps related to the playwright? --Scott David Daniels [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list

Re: re.search slashes

2006-02-04 Thread Scott David Daniels
pyluke wrote: > Scott David Daniels wrote: >> pyluke wrote: >>> I... want to find lines with ... "\[" but not instances of "\\[" >> >> If you are parsing with regular expressions, you are running a marathon. >> If you are doing regular expres

Re: Does Python support a peek like method for its file objects?

2006-02-05 Thread Scott David Daniels
self.pushback(data) return data --Scott David Daniels [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list

Re: OO conventions

2006-02-06 Thread Scott David Daniels
Fredrik Lundh wrote: > Nicola Musatti wrote: >> What is important to me is to keep your get_initial_data() function >> outside Klass if it's task is non trivial, e.g. it has to interact with >> the OS or a DB. > > why ? In order to simplify testing. --Scot

Re: critique my code, please

2006-02-06 Thread Scott David Daniels
d a new simulation control object''' self.epoch = epoch self.iter_per_epoch = iter_per_epoch self.epoch_per_display = epoch_per_display self.seed = seed self.keep_epochs = keep_epochs self.save_input = save_input ... More some other time. --Scott David Daniels [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list

Re: Hi reliability files, writing,reading and maintaining

2006-02-07 Thread Scott David Daniels
suggest you consider using a DB for your application. I do note that some of the most modern operating systems are trying to provide "log-structured file systems," which may help with the durability of file writes. I understand there is an attempt even to provide transactional interactions

Re: UnboundMethodType and MethodType

2006-02-08 Thread Scott David Daniels
id(8**7) True >>> a, b = 7**8, 8**7 >>> id(a) == id(b) # this time there are other references to a and b False If you wanted to test the original code for identity match: >>> B.bar is B().bar False is the appropriate test (the 'is' test holds the identities through the comparison). By the by, this is tricky stuff, nobody should expect to understand it thoroughly without both study and testing. --Scott David Daniels [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list

Re: Question about idioms for clearing a list

2006-02-08 Thread Scott David Daniels
Magnus Lycka wrote: >... I sometimes come across things that I once new but had forgotten. I'm sorry, and I mean no offense, _but_ I think _new_ there is a lovely typo. :-) I stopped, corrected it in my head, proceeded, and then I backed up, put it back and laughed out loud. --Sco

Re: module with __call__ defined is not callable?

2006-02-08 Thread Scott David Daniels
__call__(self): return 'Text' Now the SomeClass object (which is a subclass of object) has an attribute named "__call__". Should that define how the expression SomeClass() is evaluated? Should that return the string 'Text' or create a new instance of SomeClass? --Scott David Daniels [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list

Re: breadth first search

2006-02-08 Thread Scott David Daniels
then discard it." -- not good style. Also, it is good style to then call somefile.close() after you are done with the file. --Scott David Daniels [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list

Re: Mixing custom __setattr__ method and properties in new style classes

2006-02-08 Thread Scott David Daniels
lf): return self._tree.text def _deltext(self): self._tree.text = '' text = property(_gettext, _settext, _deltext, 'text property') d = Demo() d.text = 'my text' print repr(d.text) del d.text print repr(d.text) --Scott David Daniels [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list

Re: UnboundMethodType and MethodType

2006-02-08 Thread Scott David Daniels
Kirk McDonald wrote: > Scott David Daniels wrote: > > You know what? That makes perfect sense. Thank you. Thanks a lot for mentioning this. I do try to help out, and sometimes it feels like talking to the wind. A thanks every now and then is greatly appreciated. Just for fun, you

Re: still a valid book?

2006-02-08 Thread Scott David Daniels
te near the modern edge, and the changes you will have to learn are not that great. People are still running code written under 1.5.2, so 2.3 is really quite modern. --Scott David Daniels [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list

Re: module with __call__ defined is not callable?

2006-02-09 Thread Scott David Daniels
class__ = FunnyType def __repr__(self): print 'Lucky_%s' % id(self) OK, now: v = SomeClass(please=True) print v works, but v = SomeClass() doesn't, nor does: v = SomeClass(please=False) Think aboutwhat this code should do before running it

Re: Using ioctl

2006-02-09 Thread Scott David Daniels
don't have an idea "except *what*"). Fairly normal practice is to wait for a failure (or try to instigate one) _without_ the try: ... except: ..., and then use the one you get. Or, you could go for IOError, which sounds right to me. remember your current "except:" is catch

Re: Unable to get PIL to load jpeg images

2006-02-09 Thread Scott David Daniels
velop" jpeg, but really for those who "develop programs" -- that is run compilers and linkers. If you need to compile and link a program that uses one of these libraries, you need the "developer library." Even if the only sense in which you are a developer is that you

Re: ordered sets operations on lists..

2006-02-10 Thread Scott David Daniels
) > returns [3, 5]) However: intersection = set(list1) & set(list2) [element for element in list1 if element in intersection] or [element for element in list2 if element in intersection] Give you the result you'd like. --Scott David Daniels [EMAIL PROTECTED] --

Re: Legality of using Fonts

2006-02-10 Thread Scott David Daniels
it in a paint program to Typically you don't "own" a font, but you have a license to use it. You need to read the license to figure out what you are allowed to do with it. --Scott David Daniels [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list

Re: is there a better way?

2006-02-10 Thread Scott David Daniels
except ValueError: result = list(data) Or you could simply: try: data = data[: data.index(oh)] except ValueError: pass and data will be either the sublist you want or the original list. -- -Scott David Daniels [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list

Re: is there a better way?

2006-02-10 Thread Scott David Daniels
Scott David Daniels wrote: > [EMAIL PROTECTED] wrote: >> Problem: >> >> You have a list of unknown length, such as this: list = >> [X,X,X,O,O,O,O]. You want to extract all and only the X's. You know >> the X's are all up front and you know that the it

Re: How to check...

2006-02-12 Thread Scott David Daniels
Lad wrote: > Hello, > How can I check that a string does NOT contain NON English characters? > Thanks > L. > If all you care about is ASCII vs. non-ASCII, you could use: ord(max(string)) < 128 -- -Scott David Daniels [EMAIL PROTECTED] -- http://mail.python.org/mailm

Re: Newbie

2006-02-14 Thread Scott David Daniels
the whole previous message, we have google groups (or other archives). This is not your email, but a public board that others will later search for answers. --Scott David Daniels [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list

Re: how to break a for loop?

2006-02-20 Thread Scott David Daniels
ate(coefs): > if coef == 0: > del coefs[i] > else: > break for index, coef in enumerate(coefs): if coef: if index: del coefs[: index] break --Scott David Daniels [EMAIL PROT

Re: Question about struct.unpack

2006-02-22 Thread Scott David Daniels
ze 46) in C takes no more room. the alignment to the end shows up in a C sizeof. data = struct.pack('30sdic', 'John Q. Public', 57123.25, 43, 'M') nomz, taille, age, plop = struct.unpack('30sdic', data) nom = nomz.rstrip('\0') --Scott David Daniels [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list

Re: except clause not catching IndexError

2006-02-22 Thread Scott David Daniels
ion and OS. > any ideas? As above, but to test my theory: ... except Exception, e: print 'caught %r: %r (IndexError is %r)' % ( e, e.__class__, IndexError) --Scott David Daniels [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list

Re: Question about struct.unpack

2006-02-22 Thread Scott David Daniels
27;) >>>> nom > 'Dupont\x00\x80\xbf\xff\xf70\x8f\xe0u\xa4\x00\x00.8\xfe\xfe\xfe\xff\x80\x80\x80\x80' Sorry, I thought you had NUL-filled data. For NUL terminated data: nom = nomz[: nomz.index('\0')] --Scott David Daniels [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list

Re: What's up with this code?

2006-02-22 Thread Scott David Daniels
fs) longer = reversed(other.coefs) if len(self.coefs) > len(other.coefs): shorter, longer = longer, shorter # insure shorter first coefs = [c1+c2 for c1,c2 in it.izip(shorter, longer)] if len(self.coefs) == len(other.coefs): whil

Re: What's up with this code?

2006-02-23 Thread Scott David Daniels
#x27;s intuition is great WRT performance, and you'd be shocked at the number of hours people spend speeding up a chunk of code that cannot possibly substantially affect an applications performance. --Scott David Daniels [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list

Re: why don't many test frameworks support file-output?

2006-02-24 Thread Scott David Daniels
o conform to your personal idea of "best practices," then hire them and tell them to do it your way. --Scott David Daniels [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list

Re: make a class instance from a string ?

2006-02-24 Thread Scott David Daniels
ou can re-implement your code without being tightly coupled to your I/O formats. If you still want to use the name I'd go with: globals()[classname]() over eval, but it is your code. Here's a danger to think about: Suppose your source of class names has: '__import__(

Re: time.sleep(1) sometimes runs for 200 seconds under windows

2006-02-24 Thread Scott David Daniels
time.gmtime(oldtime)), time.strftime('%Y_%m_%d_%Hh_%Mm_%Ss', time.gmtime(newtime))) to see if you get time running backwards as well. --Scott David Daniels [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list

Re: chrtohex

2006-02-24 Thread Scott David Daniels
.org/~esr/faqs/smart-questions.html --Scott David Daniels [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list

Re: Path (graph) shower utility

2006-02-25 Thread Scott David Daniels
have seen a new one quite recently. Perhaps that one was: Yapgvb, a Python wrapper around the AT&T's graph layout library Graphviz. URL: http://yapgvb.sourceforge.net --Scott David Daniels [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list

Re: Memory allocation in for loops

2006-02-26 Thread Scott David Daniels
Your other questions were correctly answered elsewhere --Scott David Daniels [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list

Re: making 'utf-8' default codec

2006-02-27 Thread Scott David Daniels
wever, you could wrap an output destination with an encoder and get the effect you want. import sys, codecs sys.stdout, _held = (codecs.getwriter('utf-8')(sys.stdout), sys.stdout) --Scott David Daniels [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list

Re: ls files --> list packer

2006-02-27 Thread Scott David Daniels
When you acquire a language with JIT, you miss the subtleties of the language. You will be doomed to writing the same kinds of programs in every language you touch ("writing Fortran in Algol" is what we used to call it). I've worked on code that was Java-in-Python, and it was frustrat

Re: sort one list using the values from another list

2006-02-27 Thread Scott David Daniels
)) >> assert len(d) == len(s1) >> sorted(d) >> s1[:] = d.values() Dictionaries are not ordered, the "sorted" line does nothing except produce a sorted list of the dictionary's keys which is ignored. > This probably should be: > > def psort

Re: asynchat network send problems

2006-03-02 Thread Scott David Daniels
the path, and delays may happen at any packet boundary (including those boundaries created by the network). You need to do something like "sendall" and your receiver needs to know when it needs to wait for more data (as a matter of protocol design). -- -Scott David Daniels [EMAIL PROTECTED

Re: white space in expressions and argument lists

2006-03-02 Thread Scott David Daniels
to: foo = 'bar' something = 42 azimov= 3 which makes code differences hard to read. --Scott David Daniels [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list

Re: in need of some sorting help

2006-03-03 Thread Scott David Daniels
.sort(key=os.path.dirname) Learn to have your skin itch when you see: ... lambda name:(name) And yes, I concede that it _is_ useful in your .lower expression. It's not that lambda is bad, rather that it seems to encourages this 'lambda x:f(x)' stuff. --Scott David Daniels [E

Re: ODBC module and strange date reference <...>

2006-03-03 Thread Scott David Daniels
first month to cover what we spent on the license for the two years we used it (then the company died). --Scott David Daniels [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list

Re: How much does Python optimize?

2006-03-03 Thread Scott David Daniels
the meantime your code will read just fine. If you are in trouble now, your code reads much more like: for i in range(10): ... The general rule is make the code clear, measure if its too slow, and "don't worry, be happy (yagni)." --Scott David Daniels [EMAIL PRO

Re: white space in expressions and argument lists

2006-03-03 Thread Scott David Daniels
ges that use significant whitespace; you might miss a re-blocking change while suppressing the hassles from the extra "prettifying" spaces. --Scott David Daniels [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list

Re: Does '#hash' mean anything in IDLE?

2006-03-03 Thread Scott David Daniels
r_hash(word): return "".join(sorted(word)) sorted takes an iterable, and strings are iterables. --Scott David Daniels [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list

Re: Does '#hash' mean anything in IDLE?

2006-03-03 Thread Scott David Daniels
Paul Rubin wrote: > Scott David Daniels <[EMAIL PROTECTED]> writes: >> And, for 2.4 or later: >> >> def letter_hash(word): >> return "".join(sorted(word)) >> >> sorted takes an iterable, and strings are iterables. > > I do

Re: How to except the unexpected?

2006-03-05 Thread Scott David Daniels
nough. If not (if you run a real risk of multiple threads accessing the log simultaneously), have a queue of log messages that you feed to a single logging thread. -- -Scott David Daniels [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list

Re: lists: += vs. .append() & oddness with scope of variables

2006-03-05 Thread Scott David Daniels
e append method is not an assignment. > > The solution here is simply to use 'global a' to tell the compiler that you > meant to assign the the global variable rather than creating a new local > variable. As Duncan knows but forgot to mention, eric.append(spam) doesn't wr

Re: copying a tuple to a list..

2006-03-06 Thread Scott David Daniels
[EMAIL PROTECTED] wrote: > i have a result tuple from a MySQLdb call that would like to change in > place.. What you probably want: source = (1, 2, 'three') wanted = list(source) --Scott David Daniels [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list

Re: Can't get compression in Python zip script.

2005-05-02 Thread Scott David Daniels
ipfile.ZIP_DEFLATED, and (later) zipfile.ZIP_BZIP2. This way you can catch an exception when using an unimplemented compression format as you retrieve the compression code, rather than waiting to get into the midst of compression / decompression before getting a failure. --Scott David Daniels [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list

Re: problem in the compiler ?

2005-05-03 Thread Scott David Daniels
ing to help you do any work you cannot do yourself. Imagine yourself browsing the newsgroup and trying to decide whether to spend some time trying to help someone with a problem. Would _you_ want to spend time trying to guess what the code was with the problem as well as what the problem was, or woul

Re: cgi "print statement" in multithreaded enviroment?

2005-05-03 Thread Scott David Daniels
lf): return self.files.pop(thread.get_ident()) def write(self, data): self.files.get(thread.get_ident(), self.original).write(data) except KeyError: self sys.stdout = ThreadSpecificFile(sys.stdout) --Scott D

Re: problem in the compiler ?

2005-05-03 Thread Scott David Daniels
tton Cereals was pressed. mButton Rice was pressed. Selection: ('Rice',) cButton Male was pressed. Selection: ('Male',) cButton Female was pressed. Selection: ('Male', 'Female') Button Both was pressed. Demo constructed I suspect you are either not running the code you think you are running, or you are not really telling us what code you are running. You are trying to simplify for exposition, and in the process hiding the issue. By the way, none of this code runs the Tkinter mainloop (which would probably be a good idea). I would suggest running something like this at the end: if __name__ == '__main__' : import Tkinter # MyClass() # print 'MyClass constructed' Demo(None) print 'Demo constructed' Tkinter.mainloop() --Scott David Daniels [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list

Re: sorting list and then return the index of the sorted item

2005-05-03 Thread Scott David Daniels
.__getitem__) Make a list of indices, and says the sort key is "over there" to sorted. --Scott David Daniels [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list

Re: Read / Write image file

2005-05-04 Thread Scott David Daniels
e systems used a line count (leaving no end-of-line string), and so on It is a good idea to provide an indication of whether a file is binary or text to the file system; the clue could guide compression information. -Scott David Daniels [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list

Re: annonymous functions -- how to

2005-05-06 Thread Scott David Daniels
ns of values. A sample definition and use of the anonymous keyword follows: def anonymous(text): return 'modified ' + text print 'Sample', anonymous('words') --Scott David Daniels (with his tongue jammed firmly in his cheek) [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list

Re: Reference to self not passed to member function

2005-05-06 Thread Scott David Daniels
ass carol(object): ...def __init__(self, **kwargs): ...for name, method in kwargs.items(): ...setattr(self, name, ... new.instancemethod(method, self, carol)) This should behave as you prefer. --Scott David Daniels [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list

Re: Advice needed on __del__

2005-05-09 Thread Scott David Daniels
ight work is to keep a weakref to Evil in Evil_twin. Upon refresh, you could check if the weakref has gone stale. Is that good enough? --Scott David Daniels [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list

Re: Advice needed on __del__

2005-05-10 Thread Scott David Daniels
André Roberge wrote: > Scott David Daniels wrote: > >> André Roberge wrote: >> >>> ... Each time I refresh the screen, I could >>> force that call, then check to see if Evil has been >>> destroyed by Python, which would give me the information >

Re: Need a little parse help

2005-05-10 Thread Scott David Daniels
Alex Nordhus wrote: ... > for ln in inputfile.readlines(): > words = string.split(ln) > if len(words) >= 2: > # print (words[1]) Try: print >>outputfile, words[1] --Scott David Daniels [EMAIL PROTECTED] -- http://mail.python.org/ma

Re: Unique Elements in a List

2005-05-12 Thread Scott David Daniels
) time to read the problem. --Scott David Daniels [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list

Re: Quick Reference from module doc strings.

2005-05-15 Thread Scott David Daniels
uiltin types and any user-defined subtypes. > Thanks, I don't need the isinstance(), type works here just as well. But the isinstance version is better than the type(...) in ... version. --Scott David Daniels [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list

Re: Quick Reference from module doc strings.

2005-05-16 Thread Scott David Daniels
or name in sorted(namelist, key=str.lower): print >>dest, name from cStringIO import StringIO def textnames(namelist): hold = StringIO() printnames(namelist, hold) return hold.getvalue() --Scott David Daniels [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list

Re: query progress bar

2005-05-17 Thread Scott David Daniels
ber in wxPython) > while waiting for the result (like the rotating circle in firefox) The one extra thing you might want to do, if your application gets regular use, is show elapsed time. The user will come to know how long it should take, while your application probably won't get an

Re: Quick Reference from module doc strings.

2005-05-17 Thread Scott David Daniels
one as the print destination), rather than printing the result of calling the string function. I just did the StringIO thing to show you that printing as you go needn't mean you cannot get the string value without duplicating code. --Scott David Daniels [EMAIL PROTECTED] -- http://mail.python.org/ma

<    7   8   9   10   11   12   13   14   15   16   >