Re: Lambda question

2011-06-04 Thread Mel
']) if 'e' else []+['dud'] which evaluates to []+['dud']+['e'] because the if...else finally takes the second branch since the x value is now an empty string. I've left the list additions undone .. tracing the actual data objects would show plain lists. One of the disadvantages of lambdas is that you can't stick trace printouts into them to clarify what's happening. Rewriting the thing as a plain def function would be instructive. Mel. -- http://mail.python.org/mailman/listinfo/python-list

Re: Dynamic Zero Padding.

2011-06-07 Thread Mel
rt a variable into the format > specification to achieve the desirable padding. > > I would be much obliged if someone can give me some tips on how to > achieve a variably pad a number. :) ('%%0%dd' % (pads,)) % (n,) Probably be good to wrap it in a function. It looks k

Re: How to form a dict out of a string by doing regex ?

2011-06-15 Thread Mel
d sequence ## 3: the rest of data ## so use str.split and str.match to pull out the individual arguments, ## and lastly data = match.group (3) This is all from memory. I might have got some details wrong in recognizer. Mel. -- http://mail.python.org/mailman/listinfo/python-list

Re: What's the best way to write this base class?

2011-06-18 Thread Mel
icense" for more information. >>> class Character (object): ... health = 50 ... def __init__ (self, name): ... self.name = name ... print self.name, self.health ... >>> Character ('Eunice') Eunice 50 where the class attribute is used until it's overridden in the instance. Mel. -- http://mail.python.org/mailman/listinfo/python-list

Re: What's the best way to write this base class?

2011-06-20 Thread Mel
hem into the standard game config files. AFAIK you are stuck with the attributes the game is programmed for. I've seen no way to create a new dimension for the game -- Conversation, for instance, with currently unknown attributes like vocabulary or tone. Mel. -- http://mail.python.org/mailman/listinfo/python-list

Re: How can I speed up a script that iterates over a large range (600 billion)?

2011-06-21 Thread Mel
watch. factors.py works, as does yours, by testing for small factors first, but it divides them out as it goes, so it tends to do its work on smallish numbers. And since the smallest factors are taken out as soon as possible, they have to be the prime ones. Good hunting, Mel. -- http://mail.python.org/mailman/listinfo/python-list

Re: Handling import errors

2011-06-21 Thread Mel
X_NOPERM', 'EX_NOUSER', 'EX_OK', 'EX_OSERR', 'EX_OSFILE', 'EX_PROTOCOL', 'EX_SOFTWARE', 'EX_TEMPFAIL', 'EX_UNAVAILABLE', 'EX_USAGE', 'F_OK', 'NGROUPS_MAX', 'O_APPEND', 'O_ASYNC', 'O_CREAT', 'O_DIRECT', 'O_DIRECTORY', 'O_DSYNC', 'O_EXCL', 'O_LARGEFILE', 'O_NDELAY', 'O_NOATIME', 'O_NOCTTY', 'O_NOFOLLOW', 'O_NONBLOCK etc. Mel. -- http://mail.python.org/mailman/listinfo/python-list

Re: sorry, possibly too much info. was: Re: How can I speed up a script that iterates over a large range (600 billion)?

2011-06-21 Thread Mel
in this case, 20) would be an easy way of finding which numbers > to test. These are almost "trick questions" in a way, because of the math behind them. If the question were "What is the tallest high-school student in Scranton, PA?" then searching a population for the property would be the only way to go. BUT you can also build up the answer knowing the factorization of all the numbers up to 20. Mel. -- http://mail.python.org/mailman/listinfo/python-list

Re: writable iterators?

2011-06-22 Thread Mel
uot;, > it would be *disastrous* if iterables worked that way. I can't imagine > how many bugs would occur from people reassigning to the loop variable, > forgetting that it had a side-effect of also reassigning to the iterable. > Fortunately, Python is not that badly designed. And for an iterator like def things(): yield 1 yield 11 yield 4 yield 9 I don't know what it could even mean. Mel. -- http://mail.python.org/mailman/listinfo/python-list

Re: Significant figures calculation

2011-06-28 Thread Mel
one sig fig or two? > > Two. > >> (Just vaguely curious. Also curious as to >> whether a zero sig figures value is ever useful.) > > Yes. They're order of magnitude estimates. 1 x 10^6 has one > significant figure. 10^6 has zero. By convention, nobody eve

Re: Significant figures calculation

2011-06-28 Thread Mel
Erik Max Francis wrote: > Mel wrote: >> Erik Max Francis wrote: >> >>> Chris Angelico wrote: >>>> On Tue, Jun 28, 2011 at 12:56 PM, Steven D'Aprano >>>> wrote: >>>>> Zero sig figure: 0 >>> That's not really zero

Re: Implicit initialization is EXCELLENT

2011-07-05 Thread Mel
s have Create methods, for filling in various attributes in "two-step construction". I'm not sure why, because it works so well to just supply all the details when the class is called and an instance is constructed. Maybe there's some C++ strategy that's being supported there. Mel. -- http://mail.python.org/mailman/listinfo/python-list

Re: Implicit initialization is EXCELLENT

2011-07-06 Thread Mel
Ian Kelly wrote: > On Wed, Jul 6, 2011 at 12:49 AM, Ulrich Eckhardt > wrote: >> Mel wrote: >>> In wx, many of the window classes have Create methods, for filling in >>> various attributes in "two-step construction". I'm not sure why, >>> b

Re: Does hashlib support a file mode?

2011-07-06 Thread Mel
once; that is when the def statement is executed. Later on, when file_to_hash gets called, the value of m is either used as is, as the default parameter, or is replaced for the duration of the call by another object supplied by the caller. Mel. -- http://mail.python.org/mailman/listinfo/python-list

Re: more advanced learning resources (code structure, fundamentals)

2011-07-07 Thread Mel
to assign a fresh message handler to a new input message. Docs are via the Python Global Module Index, source is in some directory like /usr/lib/python2.6/SocketServer.py , .../BaseHTTPServer.py , etc. Mel. -- http://mail.python.org/mailman/listinfo/python-list

Re: None versus MISSING sentinel -- request for design feedback

2011-07-15 Thread Mel
ny help, I think (some of?) the database interface packages already do just that, returning None when they find NULL fields. Mel. -- http://mail.python.org/mailman/listinfo/python-list

Re: Tabs -vs- Spaces: Tabs should have won.

2011-07-17 Thread Mel
roid/subscribe?hl=en_US>, <mailto:python-for- android+subscr...@googlegroups.com> . Tends to be pretty detail-oriented. Mel. -- http://mail.python.org/mailman/listinfo/python-list

Re: Tabs -vs- Spaces: Tabs should have won.

2011-07-17 Thread Mel
roid/subscribe?hl=en_US>, <mailto:python-for- android+subscr...@googlegroups.com> . Tends to be pretty detail-oriented. Mel. -- http://mail.python.org/mailman/listinfo/python-list

Re: I am fed up with Python GUI toolkits...

2011-07-20 Thread Mel
you intend to re-use the Dialog object, it's not a memory leak. Mel. -- http://mail.python.org/mailman/listinfo/python-list

Re: Observations on the three pillars of Python execution

2011-08-05 Thread Mel
__class__ __delattr__ __doc__ __format__ __getattribute__ __hash__ __init__ __iter__ __name__ __new__ __reduce__ __reduce_ex__ __repr__ __setattr__ __sizeof__ __str__ __subclasshook__ close gi_code gi_frame gi_running next send throw in the form of the gi_code attribute. No idea what it's for, although no reason to believe it shouldn't be there. (Very interesting demo you gave of primitive object creation. I' awed.) Mel. -- http://mail.python.org/mailman/listinfo/python-list

Re: pairwise combination of two lists

2011-08-17 Thread Mel
3, Apr 16 2010, 13:09:56) [GCC 4.4.3] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import itertools >>> li1 = ['a', 'b'] >>> li2 = ['1', '2'] >>> map (lambda (x,y):x+y, list (itertools.product (li1, li2))) ['a1', 'a2', 'b1', 'b2'] Mel. -- http://mail.python.org/mailman/listinfo/python-list

Re: pairwise combination of two lists

2011-08-17 Thread Mel
Mel wrote: > Yingjie Lin wrote: >> I have two lists: >> >> li1 = ['a', 'b'] >> li2 = ['1', '2'] >> >> and I wish to obtain a list like this >> >> li3 = ['a1', 'a2', 'b1',

Re: try... except with unknown error types

2011-08-19 Thread Mel
mentError, or StandardError will detect the exception -- with increasing levels of generality. Mel. -- http://mail.python.org/mailman/listinfo/python-list

Re: is there any principle when writing python function

2011-08-23 Thread Mel
too big. If it's too big, factoring it into sub-steps and making functions of some of those sub-steps is the fix. Mel. -- http://mail.python.org/mailman/listinfo/python-list

Re: Mastering Python... Best Resources?

2011-08-26 Thread Mel
would be the O.P.'s job. Mel. -- http://mail.python.org/mailman/listinfo/python-list

Re: Python fails on math

2011-02-24 Thread Mel
eed that level of precision just to gather all > the students into the auditorium? You would think so, but darned if some of them don't wind up in a *different* *auditorium*! Mel. -- http://mail.python.org/mailman/listinfo/python-list

Re: ImSim: Image Similarity

2011-03-05 Thread Mel
mage_rank.py bears2.jpg *.jpg bears2.jpg bears2.jpg0.00 bears3.jpg 15.37 bears1.jpg 19.20 sky1.jpg 23.20 sky2.jpg 23.37 ff1.jpg 25.30 lake1.jpg 26.38 water1.jpg 26.98 ff2.jpg 28.43 roses1.jpg 32.01 I'd vaguely wanted to do something like this for a while, but I never dug far enough into PIL to even get started. An additional kind of ranking that takes colour into account would also be good -- that's the first one I never did. Cheers, Mel. -- http://mail.python.org/mailman/listinfo/python-list

Re: ImSim: Image Similarity

2011-03-05 Thread Mel
ubes the complexity of the answer. Might be too complicated to know what to do with an answer like that. Mel. -- http://mail.python.org/mailman/listinfo/python-list

Re: my computer is allergic to pickles

2011-03-07 Thread Mel
s an argument and moved the `for v in ...` inside the function.) > Would a database in a file have any advantages over a file made > by marshal or shelve? Depends. An sqlite3 database file is usable by programs not written in Python. > I'm more worried about the fact that a python

Re: ImSim: Image Similarity

2011-03-07 Thread Mel
-- a lot of blue sky at sunny mid-day; > -- a bit of light white clouds in the sky; > > In short, > the notion of similarity can be speculated about just endlessly. Exactly. That's the kind of similarity I would call valid. That's what my algorithms, if I ever finis

Re: Coding and Decoding in Python

2011-03-17 Thread Mel
d) [ ... ] '_qinf_force32' : 0x > } I handled this problem in a kind of cheap, nasty way with (untested) for k, v in QCam_Info.items(): QCam_Info[v] = k Then the dictionary lookups work both ways. Mel. -- http://mail.python.org/mailman/listinfo/python-list

Re: PEP for module naming conventions

2011-03-17 Thread Mel
in more than, say, one underscore. That way, nice descriptive application module names like 'analyzer_tool_utils' and such would always be safe to use. Mel. -- http://mail.python.org/mailman/listinfo/python-list

Re: Bounds checking

2011-03-18 Thread Mel
get(attribute, lambda x: True)(value): raise ValueError ('error out of bound') or define a subclass of ValueError just for this purpose. On error, the program will stop just as dead, but you'll get a trace. Mel. -- http://mail.python.org/mailman/listinfo/python-list

Re: Guido rethinking removal of cmp from sort method

2011-03-24 Thread Mel
here any reason why cmp being a useful > argument of sort should indicate that __cmp__ should be retained in > classes. I would have thought that the upper limit of cost of supporting cmp= and key= would be two different internal front-ends to the internal internal sort. Mel. -- http://mail.python.org/mailman/listinfo/python-list

Re: send function keys to a legacy DOS program

2011-03-29 Thread Mel
gt; F2: 0xBC > F7: 0xC1 True. The key-release codes are the key-press codes (the "key numbers") but with the high-order bit set. Mel. -- http://mail.python.org/mailman/listinfo/python-list

Re: TypeError: iterable argument required

2011-04-04 Thread Mel
> the error message i posted. > > So its not that the if condition is wrong but something happens with > the form variable 'mail' . My wild guess is that the trouble is in `if "@" in mail` . You can only test somthing `in` something if the second thing i

Re: is python 3 better than python 2?

2011-04-05 Thread Mel
odd Unicode character sets is going to be foreign,) and generally internationalized data processing. Mel. -- http://mail.python.org/mailman/listinfo/python-list

Re: [OT] Free software versus software idea patents

2011-04-07 Thread Mel
Do you have an example of this wasteful litigation? > > You have to be kidding, right? Check *any* of the sites I listed > above and read about it... software idea patent litigation is a business > now worth billions of dollars per year. One of the premier sites: http://www

Re: Argument of the bool function

2011-04-08 Thread Mel
th something else: Python 2.6.5 (r265:79063, Apr 16 2010, 13:09:56) [GCC 4.4.3] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> bool(y=5) Traceback (most recent call last): File "", line 1, in TypeError: 'y' is an invalid keyword argument for this function Mel. -- http://mail.python.org/mailman/listinfo/python-list

Re: Argument of the bool function

2011-04-10 Thread Mel
ge is good when you can get it, especially for abstract things like that. I can sort of guess that `dir` was perhaps coded in C for speed and doesn't spend time looking for complicated argument lists. Python is a pragmatic language, so all the rules come pre-broken. Mel. -- http://mai

Re: Feature suggestion -- return if true

2011-04-12 Thread Mel
ne: return "right", tree_node.right where adding the "left" and "right" markers makes the return? feature impossible to use. The proposed feature reminds me of the `zod` function (was that the actual name?) that returned 0 rather than bringing on a Ze

Re: List comprehension vs filter()

2011-04-20 Thread Mel
I guess this means that a function's > default arguments are evaluated in the parent context, but the body is > evaluated in its own context? The operation of calling a function has to evaluate arguments provided in the caller's namespace and assign them to variables in the called

Re: dictionary size changed during iteration

2011-04-20 Thread Mel
gt; k is d.keys() > False > > So what is wrong with this iterator? Why am I getting this error message? `ukeys` isn't a different dictionary from `self.updates.keys` I'ts merely another name referring to the same dict object. I think ukeys = dict (self.updates.keys) would do what you want. Mel. -- http://mail.python.org/mailman/listinfo/python-list

Re: dictionary size changed during iteration

2011-04-20 Thread Mel
Mel wrote: > Laszlo Nagy wrote: > `ukeys` isn't a different dictionary from `self.updates.keys` I'ts merely > another name referring to the same dict object. I think > > ukeys = dict (self.updates.keys) > > would do what you want. Sorry. Belay that.

Re: learnpython.org - an online interactive Python tutorial

2011-04-22 Thread Mel
erl needs two completely different kinds of comparison -- one that works as though its operands are numbers, and one that works as though they're strings. Surprises to the programmer who picks the wrong one. Mel. -- http://mail.python.org/mailman/listinfo/python-list

Re: Input() in Python3

2011-04-22 Thread Mel
ignored Exception RuntimeError: 'maximum recursion depth exceeded while calling a Python object' in ignored Error in sys.excepthook: RuntimeError: maximum recursion depth exceeded Original exception was: Traceback (most recent call last): File "", line 1, in RuntimeError: maximum recursion depth exceeded while calling a Python object >>> Mel. -- http://mail.python.org/mailman/listinfo/python-list

Re: Input() in Python3

2011-04-25 Thread Mel
Westley Martínez wrote: > On Fri, Apr 22, 2011 at 10:08:20AM -0400, Mel wrote: [ ... ] >> But sys.exit() doesn't return a string. My fave is >> >> Python 2.6.5 (r265:79063, Apr 16 2010, 13:09:56) >> [GCC 4.4.3] on linux2 >> Type "help", "co

Re: What other languages use the same data model as Python?

2011-05-03 Thread Mel
identify_call (my_list) >>> my_list ["If you can see this, you don't have call-by-value"] so it's neither call-by-value nor call-by-reference as (e.g.) C or PL/I programming would have it (don't know about Simula, so I am off topic, actually.) It's not so wrong to think of Python's parameter handling as ordinary assignments from outer namespaces to an inner namespace. Mel. -- http://mail.python.org/mailman/listinfo/python-list

Re: Why do directly imported variables behave differently than those attached to imported module?

2011-05-03 Thread Mel
assignment works by rebinding. The two different bindings in foo.__dict__ and globals() get bound to different integer objects. Note too the possible use of `globals()['foo'].__dict__['var'] . (Hope there are no typos in this post.) Mel. -- http://mail.python.org/mailman/listinfo/python-list

Re: What other languages use the same data model as Python?

2011-05-05 Thread Mel
rouble testing among float(5), int(5), Decimal(5) ... Mel. -- http://mail.python.org/mailman/listinfo/python-list

Re: What other languages use the same data model as Python?

2011-05-05 Thread Mel
d avoided FORTRAN's troubles the same way. Your function could corrupt *a* 4, but it wouldn't corrupt the *only* 4. Mel. -- http://mail.python.org/mailman/listinfo/python-list

Re: What other languages use the same data model as Python?

2011-05-05 Thread Mel
Steven D'Aprano wrote: > Some day, we'll be using quantum computers without memory addresses, [ ... ] it will still be possible to > represent data indirectly via *some* mechanism. :) Cool! Pass-by-coincidence! And Python 3 already has dibs on the 'nonlocal' keywor

Re: What other languages use the same data model as Python?

2011-05-09 Thread Mel
roubles of its own; I never took it through the knock-down drag-out disarticulation that would show what the problems were. Mel. -- http://mail.python.org/mailman/listinfo/python-list

Re: Obtaining a full path name from file

2011-05-24 Thread Mel
"copyright", "credits" or "license" for more information. >>> f = open ('xyzzy.txt') >>> f.name 'xyzzy.txt' >>> import os >>> os.getcwd() '/home/mwilson' >>> os.chdir('sandbox') >>> f.name 'xyzzy.txt' If you open a file and don't get a full path from os.path.abspath right away, the name in the file instance can get out-of-date. Mel. -- http://mail.python.org/mailman/listinfo/python-list

Re: bug in str.startswith() and str.endswith()

2011-05-26 Thread Mel
a tuple of suffixes to look for. With > optional start, test beginning at that position. With optional end, stop > comparing at that position. > > Any reason this is not a bug? It's a wart at the very least. The same thing happened in Python2 with range and xrange; there seemed no way to explicitly pass "default" arguments. Mel. -- http://mail.python.org/mailman/listinfo/python-list

Re: bug in str.startswith() and str.endswith()

2011-05-27 Thread Mel
do_some_things() result = range (start, stop, span) # range doesn't(/didn't) accept this return result Tne answer in that case was to take *args as the parameter to wrapped_range and count arguments to distinguish between the different calls to range. Mel. -- http://mail.python.org/mailman/listinfo/python-list

Re: Python's super() considered super!

2011-05-27 Thread Mel
users get at the internals, but things like this make it worthwhile. Mel. -- http://mail.python.org/mailman/listinfo/python-list

Re: scope of function parameters

2011-05-29 Thread Mel
again when main prints the object it knows as `a`. Python doesn't pass parameters by handing around copies that can be thought of as local or global. Python passes parameters by binding objects to names in the callee's namespace. In your program the list known as `a` in main is identically the same list as the one known as `c` in fnc2, and what happens happens. Mel. -- http://mail.python.org/mailman/listinfo/python-list

Re: Doctest failing

2011-09-10 Thread Mel
_main__": > _test() > > All tests are failing even though I am getting the correct output on > the first two tests. And the last test still gives me "Of" instead of > "of" > > Any help is appreciated. I don't know about doctest -- I suspect it wants a structured docstring to specify the tests -- but this if title_split[0] in small_words: new_title.append(word.title()) can't be what you want. Mel. -- http://mail.python.org/mailman/listinfo/python-list

Re: Context manager with class methods

2011-09-22 Thread Mel
("__enter__") @classmethod def __exit__(cls, exc_type, exc_value, traceback): print("__exit__") class With (object): __metaclass__ = MetaWith with With: pass Mel. -- http://mail.python.org/mailman/listinfo/python-list

Re: Context manager with class methods

2011-09-22 Thread Mel
Mel wrote: > This seems to work: > > > > class MetaWith (type): > @classmethod > def __enter__(cls): > print("__enter__") > > @classmethod > def __exit__(cls, exc_type, exc_value, traceback): > print("__exi

Re: Generating equally-spaced floats with least rounding error

2011-09-24 Thread Mel
done this with ints (usually in small embedded systems) I've always preferred low_limit + (total_width * i) / intervals since it does the rounding on the biggest numbers where proportional error will be least, and it's guaranteed to hit the low_limit and high_limit exactly (as exactly as they can be represented, anyway.) Mel. -- http://mail.python.org/mailman/listinfo/python-list

Re: Wrote a new library - Comments and suggestions please!

2011-09-27 Thread Mel
you might want that, whatever it was, to happen. I see that kind of documentation way too often. By comparison, even this <https://www.ubersoft.net/comic/hd/2011/09/losing- sight-big-picture> might seem good. At least they try. "Does things to the stuff. By default, the mos

Re: Usefulness of the "not in" operator

2011-10-08 Thread Mel
s the obvious way to do it. > > > "If the key is not in the ignition, you won't be able to start the car." > > "If not the key is in the ignition, you won't be able to start the car." > > > Who like that second one speaks? :) "If th

RE: Problem with a wx notebook

2011-10-20 Thread Mel
ough. In my own code, I usually define a separate class descended from wx.Panel to create a page3 instance with its own sizers, then create one of those with a a wx.Notebook instance as a parent, and add it to the notebook: def _new_capture_page (self): new_trace = TraceWindow (self.tracebook) self.tracebook.AddPage (new_trace, 'Capture %d' % (self.capture_serial,), select=True) return new_trace Hope this helps, Mel. -- http://mail.python.org/mailman/listinfo/python-list

Re: How to isolate a constant?

2011-10-25 Thread Mel
', 'a', ' ', 's', > 't', 'r', 'i', 'n', 'g']" >>>> Well, as things stand, there's a way to get whichever result you need. The `list` constructor builds a single list from a single iterable. The list literal enclosed by `[`, `]` makes a list containing a bunch of items. Strings being iterable introduces a wrinkle, but `list('abcde')` doesn't create `['abcde']` just as `list(1)` doesn't create `[1]`. Mel. -- http://mail.python.org/mailman/listinfo/python-list

Re: How do I Color a QTableView row in PyQt4

2007-03-02 Thread Mel
the background color that way? An example or a link to easy to understand documentation on changing a row color for an object based on QTableView using QSqlQueryModel as a model would be greatly appreciated. I'm still a bit confused in Qt4. Mel -- http://mail.python.org/mailman/listinfo/python-list

How do I Color a QTableView row in PyQt4

2007-02-28 Thread Mel
Code *** Column 18 in the table shows a number from 1 to 3. I would like to change the color of the row based on the value in column 18 but I have not been able to find any resources that show me how. Can anyone lend a hand? Thanks, Mel -- http://mail.python.org/mailman/listinfo/python-list

Re: How do I Color a QTableView row in PyQt4

2007-03-01 Thread Mel
On Feb 28, 5:08 pm, David Boddie <[EMAIL PROTECTED]> wrote: > On Wednesday 28 February 2007 18:55, Mel wrote: > > > > > I am currently porting an SQL centered Visual Basic application to run > > on Linux, Python, and Qt4. Currently I am stumped on changing row >

Re: Recursive loading trouble for immutables

2007-11-25 Thread Mel
operty that the caller would never want to put it in a self-referencing sequence. I'll have to check this out today to see. Mel. -- http://mail.python.org/mailman/listinfo/python-list

Re: Recursive loading trouble for immutables

2007-11-25 Thread Mel
Mel wrote: > rekkufa wrote: [ ... ] >> How to load >> data that specifies immutables that recursively reference >> themselves. > I can imagine a C function that might do it. [ ... ] Here's something that works, in the sense of creating a tuple containing a self

Re: basic if stuff- testing ranges

2007-11-25 Thread Mel
Donn Ingle wrote: > Sheesh, I've been going spare trying to find how to do this short-hand: > if 0 > x < 20: print "within" > > So that x must be > 0 and < 20. > > I usually do: > if x > 0 and x < 20: print "within" > > Wha

Re: Unexpected behavior when initializing class

2007-11-28 Thread Mel
(or maybe test explicitly for None, but you get the idea.) Do test explicitly for None. Otherwise, if you do a = [] x = ThatClass (a) it will so happen that x.values will be an empty list, but it won't be the same list as a. Mel. -- http://mail.python.org/mailman/listinfo/python-list

Re: [OT] minimalist web server

2007-12-01 Thread Mel
I -*- '''$Id$ ''' from BaseHTTPServer import HTTPServer from SimpleHTTPServer import SimpleRequestHandler handler = HTTPServer (('', 8000), SimpleRequestHandler) handler.handle_forever() Mel. -- http://mail.python.org/mailman/listinfo/python-list

Re: String formatting with %s

2007-12-02 Thread Mel
Donn Ingle wrote: > Now, is there something quick like: >>>> s = "%s/2 and %s/1" % ( "A", "B" ) >>>> print s > B and A > > ? GNU glibc printf accepts a format string: printf ("%2$s and %1$s", "A&qu

Re: Escaping the semicolon?

2007-12-04 Thread Mel
uot; or "license" for more information. >>> s = '123;abc' >>> b = s.replace(';', '\;') >>> b '123\\;abc' >>> len(b) 8 The length suggests that there's only one backslash in the string. Mel.

Re: About Rational Number (PEP 239/PEP 240)

2007-12-16 Thread Mel
le instances, if I could find the source. Mel. And with any > rational data type worth the name, you simply should never get anything > as unintuitive as this: > >>>> from __future__ import division >>>> 4/10 + 2/10 == 6/10 > False > > > -- http://mail.python.org/mailman/listinfo/python-list

Re: List problem

2007-12-16 Thread Mel
6*[[]] > >>> a > [[], [], [], [], [], []] > >>> a[2].append(1) > >>> a > [[1], [1], [1], [1], [1], [1]] > >>> What you've done is equivalent to x = [] a = [x, x, x, x, x, x] del x An idiom for what you want is a = [[] for y in xrange (6)] which will popu

Re: exception message output problem

2007-12-22 Thread Mel
str(a,b,c) the function-calling operator () takes over, and the commas are considered as argument separators. In str ((a,b,c)) the inner parens present a single tuple-expression to the function-calling operator. Just like a+b/c as against (a+b)/c but with esoteric overloading of (

Re: __init__ explanation please

2008-01-14 Thread Mel
", "copyright", "credits" or "license" for more information. >>> class AClass (object): ... def __init__ (self): ... self.a = 4 ... >>> a = AClass() >>> a.a 4 >>> a.a = 5 >>> a.a 5 >>> a.__init__() >>> a.a 4 Cheers, Mel. -- http://mail.python.org/mailman/listinfo/python-list

Re: no pass-values calling?

2008-01-16 Thread Mel
alent is x=123 sub test() global x x=456 test() print x Python assignment works by binding an object with a name in a namespace. I suspect that perl does something similar, and the differences are in the rules about which namespace to use. Mel. -- http://mail.python.org/mailman/listinfo/python-list

Re: assigning values in python and perl

2008-01-16 Thread Mel
st [4,5,6]. Exiting test, the local namespace is thrown away. You could change your program a bit to clarify what's going on: def test(x): print "x=", x x = [4,5,6] print "x=", x a=[1,2,3] test(a) print "a=", a Cheers, Mel -- http://mail.python.org/mailman/listinfo/python-list

Re: "Code Friendly" Blog?

2008-01-17 Thread Mel
ef getDir(fullPath): > dirName, fileName = os.path.split(fullPath) > return dirName > That won't help the escape problem, though it will preserve vital Python whitespace. HTML has to be interpreting '<' characters to recognize the ''. Mel. -- http://mail.python.org/mailman/listinfo/python-list

Re: Just for fun: Countdown numbers game solver

2008-01-20 Thread Mel
hich is slightly less elegant). Can anyone do better? I found that postfix notation made it easy to run up all the possible expressions based on permutations of the available numbers. Don't know where my source code is ... have to look. Mel. -- http://mail.python.org/mailman/listinfo/python-list

Re: problem with 'global'

2008-01-20 Thread Mel
lobal is not an executable statement, and isn't affected by being subordinate to an if statement. In a.py the function has been primed to define a in the global namespace. In b.py, not. Docs do describe global as a "directive to the parser", even though it's lumped in with

Re: problem with 'global'

2008-01-21 Thread Mel
Duncan Booth wrote: > Mel <[EMAIL PROTECTED]> wrote: > >> oyster wrote: >>> why the following 2 prg give different results? a.py is ok, but b.py >>> is 'undefiend a' >>> I am using Python 2.5.1 (r251:54863, Apr 18 2007, 08:51:08) [MSC &g

Re: read files

2008-01-21 Thread Mel
e = fd.readline() is a statement, not an expression, and it can't be put into an if statement like that. The most idiomatic way is probably fd = open ("/etc/sysctl.conf") for line in fd: print line Mel. -- http://mail.python.org/mailman/listinfo/python-list

Re: refcount

2008-01-29 Thread Mel
(temporary) >> reference as an argument to getrefcount(). > Are there any cases when it wouldn't? Well, as long as the object is named "object" in sys.getrefcount's namespace, there's at least that one reference to it... Mel. -- http://mail.python.org/mailman/listinfo/python-list

Re: extending Python - passing nested lists

2008-01-29 Thread Mel
n->C and C->Python conversions. But if Numpy isn't fast enough, then any Python at all in the solution might be too much. Perhaps keeping your values in a file and reading them into the C programs will work. Mel. -- http://mail.python.org/mailman/listinfo/python-list

Re: Is it explicitly specified?

2008-02-03 Thread Mel
detect an explicit call with > nullable_value==sentinel -- the reason being, I submit, that there is no > use case for such code. The code above works on the assumption that the value named sentinel is completely out-of-band, and no user has any reason to use the sentinel object in a call. An example up-thread uses a uniquely-constructed instance of object for this. I kind of like defining a class, because I get a docstring to explain what's going on. Mel. -- http://mail.python.org/mailman/listinfo/python-list

Re: type, object hierarchy?

2008-02-04 Thread Mel
7stud wrote: > On Feb 3, 10:28 pm, 7stud <[EMAIL PROTECTED]> wrote: >> From the docs: >> >> issubclass(class, classinfo) >> Return true if class is a subclass (direct or indirect) of classinfo. > > > print issubclass(Dog, object) #True > print issubclass(type, object) #True > print issubclass(D

Re: Globals or objects?

2008-02-21 Thread Mel
ed-value membership base would import thisyear, and pass thisyear.memberpath when creating the CSV reader object. Etc. Mel. -- http://mail.python.org/mailman/listinfo/python-list

Re: How about adding rational fraction to Python?

2008-02-24 Thread Mel
denominators would settle out pretty quickly. In general mathematics, not. I think that might be the point. Mel. -- http://mail.python.org/mailman/listinfo/python-list

Re: float / rounding question

2008-02-25 Thread Mel
01 >>> print celciusToFahrenheit (12) 53.6 The straight value display from the interpreter pursues precision to the bitter end, doing its formatting with the repr function. print uses str formatting for a more expected result. Mel. -- http://mail.python.org/mailman/listinfo/python-list

Re: Web site for comparing languages syntax

2008-02-25 Thread Mel
h I don't know about wikimedia. Mel. -- http://mail.python.org/mailman/listinfo/python-list

Re: sqlite3 adaptors mystery

2008-03-01 Thread Mel
ach tuple is being converted for display by repr, so the strings are shown as unicode, which is what they are internally. Change the print to for (field,) in cur.fetchall(): print field and you'll see your plain-text strings. Mel. -- http://mail.python.org/mailman/listinfo/python-list

Re: sqlite3 adaptors mystery

2008-03-02 Thread Mel
ctly this -- that > I would get back bool values not strings. > > Sorry for not being clear in the first run. Sorry about the misunderstanding. It seems you want db = sqlite3.connect("test.db", detect_types=sqlite3.PARSE_DECLTYPES) After this, the print shows False True Mel. -- http://mail.python.org/mailman/listinfo/python-list

Re: What c.l.py's opinions about Soft Exception?

2008-03-09 Thread Mel
'apologize' around something that's so irreparable. I'd try for this effect by creating a class of objects with well-defined callbacks. Mel. -- http://mail.python.org/mailman/listinfo/python-list

Re: List Combinations

2008-03-12 Thread Mel
Gerdus van Zyl wrote: > I have a list that looks like this: > [['3'], ['9', '1'], ['5'], ['4'], ['2', '5', '8']] > > how can I get all the combinations thereof that looks like as follows: > 3,9,5,4,2 > 3,1,5,4,2 > 3,9,5,4,5 > 3,1,5,4,5 > etc. > > Thank You, > Gerdus What they said, or, if you wa

Re: getattr(foo, 'foobar') not the same as foo.foobar?

2008-03-13 Thread Mel
It's still bound, in a way, to sys.stdout. I'm assuming that a different example could create an attribute of f that's a bound method of some other object entirely. I've verified that f.write('howdy') prints 'howdy' on standard output. Mel. -- http://mail.python.org/mailman/listinfo/python-list

  1   2   3   4   >