Re: duck typing assert‏

2012-11-08 Thread Steven D'Aprano
On Thu, 08 Nov 2012 23:44:54 -0500, Terry Reedy wrote: > On 11/8/2012 6:40 PM, Steven D'Aprano wrote: [...] >> IFoo.bar # returns a computed property > > Assuming IFoo is a class and bar is a property attribute of the class, > IFoo.bar is the property object itself, not t

Re: Multi-dimensional list initialization

2012-11-08 Thread Steven D'Aprano
On Fri, 09 Nov 2012 17:07:09 +1100, Chris Angelico wrote: > On Fri, Nov 9, 2012 at 12:39 PM, Mark Lawrence > wrote: >> On 07/11/2012 01:55, Steven D'Aprano wrote: >>> >>> >>> Who knows? Who cares? Nobody does: >>> >>> n -= n >>

Re: Obnoxious postings from Google Groups

2012-11-09 Thread Steven D'Aprano
On Fri, 09 Nov 2012 10:49:41 +0100, Hans Mulder wrote: > On 6/11/12 23:50:59, Steven D'Aprano wrote: >> On Tue, 06 Nov 2012 17:16:44 +, Prasad, Ramit wrote: >> >>>> To enter the newline, I typed Ctrl-Q to tell bash to treat the next >>>> character

Re: int.__init__ incompatible in Python 3.3

2012-11-09 Thread Steven D'Aprano
ot;, line 3, in __init__ TypeError: object.__init__() takes no parameters It is apparently an oversight, or a bug, that it ever worked in older versions. > Note that even though I derive from an immutable class, the resulting > class is not formally immutable. Maybe exactly that is the th

Re: duck typing assert

2012-11-09 Thread Steven D'Aprano
On Thu, 08 Nov 2012 18:00:58 -0700, Ian Kelly wrote: > On Thu, Nov 8, 2012 at 4:33 PM, Steven D'Aprano > wrote: >> On Thu, 08 Nov 2012 20:34:58 +0300, Andriy Kornatskyy wrote: >> >>> People who come from strongly typed languages that offer interfaces >>

Re: Is there a simpler way to modify all arguments in a function before using the arguments?

2012-11-09 Thread Steven D'Aprano
If you need named parameters: def someComputation(aa, bb, cc, dd, ee, ff, gg, hh): aa, bb, cc, dd, ee, ff, gg, hh = [arg.replace("_", "") for arg in (aa. bb, cc, dd, ee, ff, gg, hh)] ... -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: skip Trackback error for ftp checking

2012-11-09 Thread Steven D'Aprano
On Fri, 09 Nov 2012 20:51:47 -0800, moonhkt wrote: > HI All > > How to skip Trackback warning/error when input ftp address is not > correct or reject ? The same way you would skip any other error when you do something wrong: catch the exception. -- Steven -- http://mail.python

Re: Obnoxious postings from Google Groups

2012-11-09 Thread Steven D'Aprano
On Fri, 09 Nov 2012 12:34:27 +0100, Hans Mulder wrote: > On 7/11/12 01:13:47, Steven D'Aprano wrote: >> Hit the J key, and the event includes character "j". Hit Shift-J, and >> character "J" is sent. Hit Ctrl-J, and the character sent is the A

Re: Format specification mini-language for list joining

2012-11-10 Thread Steven D'Aprano
, cryptic mini-language? If you're worried about code re-use, write a simple helper function: def format_items(format, items): template = '{0:%s}' % format return ', '.join(template.format(item) for item in items) out = 'Temperatures: {0} Celsius'.format( format_items('.1f, temps) ) -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: A gnarly little python loop

2012-11-10 Thread Steven D'Aprano
page = 1 r = ["placeholder"] while r: r = api.GetSearch(term="foo", page=page) process_all(tweets) # does nothing if r is empty page += 1 Another way would be to use a for list for the outer loop. for page in xrange(1, sys.maxint): r = api.GetSearch(term

Re: Method default argument whose type is the class not yet defined

2012-11-10 Thread Steven D'Aprano
tion which, according to your tastes, may count as more or less ugly: inject the default value into the method: class Point: def distance(self, other=None): # None is a placeholder delta = self - other return math.sqrt(delta.x ** 2 + delta.y ** 2) Point.distance.__defaults__ = (Point(),) # In Python 2, use: # Point.distance.__func__.func_defaults = (Point(),) -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Method default argument whose type is the class not yet defined

2012-11-11 Thread Steven D'Aprano
. In two dimensions, you can define the dot product of two vectors to give a scalar; in three dimensions you have a dot product and a vector product. Since vectors are equivalent to points, and points are equivalent to complex numbers, one could define a vector operation equivalent to complex multiplication. There is a natural geometric interpretation of this multiplication: it is a scaling + rotation. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: List comprehension for testing **params

2012-11-11 Thread Steven D'Aprano
esting things which "can't possibly fail". But of course, since what can't go wrong does, you sometimes still want to test things. If you've ever written something like: if condition: process() else: # this cannot happen, but just in case! print "something unexpected went wrong!" that's a perfect candidate for an assertion: assert condition, "something unexpected went wrong!" process() -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: List comprehension for testing **params

2012-11-11 Thread Steven D'Aprano
27;s a Python 3 feature. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Method default argument whose type is the class not yet defined

2012-11-11 Thread Steven D'Aprano
e "zero velocity" relative to which all other velocities are measured. Electric fields are relative to the vacuum far from any electric charges. And so on. I quote: "The angular momentum L of a particle about a given origin is defined as: L = r × p where r is the position vector of the particle relative to the origin, p is the linear momentum of the particle, and × denotes the cross product." http://en.wikipedia.org/wiki/Angular_momentum Is there some part of "about a given origin" which needs additional explanation? -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: List comprehension for testing **params

2012-11-11 Thread Steven D'Aprano
On Sun, 11 Nov 2012 18:21:32 -0600, Tim Chase wrote: > On 11/11/12 17:18, Steven D'Aprano wrote: >> but that leaves you with the next two problems: >> >> 2) Fixing the assert still leaves you with the wrong exception. You >> wouldn't raise a ZeroDivision

Re: f python?

2012-11-12 Thread Steven D'Aprano
On Mon, 12 Nov 2012 17:37:50 -0500, Dave Angel wrote: > On 11/12/2012 05:07 PM, Beekeeper2020 wrote: [...] >> Python eventually will die once troll troll troll troll troll... > In case anybody is tempted to respond to this troll message, Like you did? Without trimming? :-P

Re: stackoverflow quote on Python

2012-11-12 Thread Steven D'Aprano
literals; * new metaclass syntax; * classic classes are gone; * automatic delegation doesn't work for __dunder__ methods; * backticks `x` gone; among others. Are these "significant" differences? Well, maybe. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Getting module path string from a class instance

2012-11-12 Thread Steven D'Aprano
ither pull that string apart: py> s = repr(Pool) py> start = s.find("'") py> end = s.rfind("'") py> s[start+1:end] 'multiprocessing.pool.Pool' or you can construct it yourself: py> Pool.__module__ + '.' + Pool.__name__ 'multiprocessing.pool.Pool' -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Getting module path string from a class instance

2012-11-13 Thread Steven D'Aprano
On Tue, 13 Nov 2012 07:54:32 +, Some Developer wrote: > On 13/11/2012 07:19, Steven D'Aprano wrote: >> On Tue, 13 Nov 2012 06:38:31 +, Some Developer wrote: >> >>> I'm trying to find a way to get a string of the module path of a >>> class. >&

Re: Error messages from format()

2012-11-13 Thread Steven D'Aprano
itutions, {0} and {1}. Each substitution has a format spec following the colon: {0:^9o} and {1:9x} But the format function only takes a single "object to be substituted", and so doesn't take a brace substitution. Instead, it just takes the format spec part: py> format(25, &#

Re: Error messages from format()

2012-11-13 Thread Steven D'Aprano
On Tue, 13 Nov 2012 15:24:53 -0500, Colin J. Williams wrote: > On 13/11/2012 1:38 PM, Steven D'Aprano wrote: >> On Tue, 13 Nov 2012 10:08:59 -0500, Colin J. Williams wrote: >> >>> Is there some way to get more informative error messages from the >>> built

Re: Simple Question regarding running .py program

2012-11-14 Thread Steven D'Aprano
7;ve noticed that some those most vocal against GG have > also been very vocal about this group being inclusive. I call bullshit. If you are going to accuse people of being "very vocal" against minorities, you damn well better have some evidence to back up your claim. And if you don't, I would expect a public apology for that slur. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Simple Question regarding running .py program

2012-11-14 Thread Steven D'Aprano
On Wed, 14 Nov 2012 23:07:53 +, Steven D'Aprano wrote: > On Wed, 14 Nov 2012 10:20:13 -0800, rurpy wrote: [...] > [...] >> As an aside, I've noticed that some those most vocal against GG have >> also been very vocal about this group being inclusive. > > I

Re: debugging in eclipse

2012-11-15 Thread Steven D'Aprano
ake sure something is running is to add "assert 0". > > ``1/0`` is shorter. ;-) It is also guaranteed to run, unlike assert. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Lazy Attribute

2012-11-16 Thread Steven D'Aprano
descriptive. EVERYTHING accessed used dot notation obj.thing is an attribute. What makes your "attribute" different from ordinary attributes, properties, dynamic attributes calculated with __getattr__, methods, etc? -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Lazy Attribute

2012-11-16 Thread Steven D'Aprano
ookup, not the lazy attribute itself. This won't do: obj.__class__.attr.refresh() because it won't know which instance to invalidate, although this could work: obj.__class__.attr.refresh(obj) # but it's ugly I'm very vaguely leaning towards this as the least-worst solutio

Re: debugging in eclipse

2012-11-16 Thread Steven D'Aprano
On Thu, 15 Nov 2012 17:10:27 -0800, alex23 wrote: > On Nov 16, 3:05 am, Steven D'Aprano [email protected]> wrote: >> > ``1/0`` is shorter.  ;-) >> >> It is also guaranteed to run, unlike assert. > > Only if they actively pass the co

StandardError in Python 2 -> 3

2012-11-16 Thread Steven D'Aprano
+-- TypeError +-- ValueError +-- Warning Note that StandardError is gone. Does anyone use StandardError in their own code? In Python 2, I normally inherit from StandardError rather than Exception. Should I stop and just inherit from Exception in both 2 and 3? -- Steven -- http

Catching exceptions from Python 2.4 to 3.x

2012-11-16 Thread Steven D'Aprano
() except Exception as err: process(err) But in 2.4 and 2.5 "as err" gives me a SyntaxError, and I have to write: try: something() except Exception, err: process(err) Is there some other trick to grab the current exception from inside an except block? -- Steve

Re: Catching exceptions from Python 2.4 to 3.x

2012-11-17 Thread Steven D'Aprano
On Sat, 17 Nov 2012 14:26:43 +1100, Cameron Simpson wrote: > On 17Nov2012 03:12, Steven D'Aprano > wrote: > | Is there some other trick to grab the current exception from inside an > | except block? > > sys.exc_info ? Thanks, that is just what I was looking for.

Re: module trace and counts

2012-11-17 Thread Steven D'Aprano
not mind-readers and have no idea what you have done and what total you have got. Please explain your question. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Python Script for Colorizing Traceroute Output (apologies for top-post)

2012-11-17 Thread Steven D'Aprano
bly even invalidate the entire licence. Licence proliferation hurts us all. Just say No. http://en.wikipedia.org/wiki/License_proliferation -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: module trace and counts

2012-11-17 Thread Steven D'Aprano
On Sat, 17 Nov 2012 13:37:23 -0500, Dave Angel wrote: > On 11/17/2012 12:25 PM, rh wrote: >> Is it for or range that is executed 8000 times when I for i in >> range(3,8000,2): > Nothing is executed 8000 times. I figure it at 3998 times. Off by one. py> len(range(3, 8000,

Re: Python Interview Questions

2012-11-18 Thread Steven D'Aprano
x27;verbose']: print('sending email...') send_email_to(address['fred'], "Subject: Hello") Use a set when you want to represent a collection of items and the order is not important: failed = {'fred', 'tom', 'sally'} # set literal syntax in Python 3 only # use set(['fred', 'tom', 'sally']) in Python 2 if 'george' in failed: print('George, you have failed!') -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Point of idle curiosity

2012-11-18 Thread Steven D'Aprano
On Sun, 18 Nov 2012 22:45:43 +1100, Chris Angelico wrote: > (if you'll forgive the pun) > > Is IDLE named after Eric of that name, or is it pure coincidence? Well, IDLE is an IDE. The L doesn't seem to mean anything, so it's plausible that it is named after Eric Idl

Re: Python Interview Questions

2012-11-18 Thread Steven D'Aprano
On Sun, 18 Nov 2012 08:53:25 -0500, Roy Smith wrote: > In article <[email protected]>, > Steven D'Aprano wrote: > >> Use a list when you want a list of items that should all be treated the >> same way [...] or when you need

Re: Python Interview Questions

2012-11-18 Thread Steven D'Aprano
eld separator: ./prattle.py ! 873 ! select ! selection = self.do_callback(cb, response) ./prattle.py ! 787 ! do_callback ! raise callback But there's really nothing you can do about the immutability. There isn't any meaningful reason why you might want to take a complete stack trace and add or delete lines from it. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Python Interview Questions

2012-11-18 Thread Steven D'Aprano
On Sun, 18 Nov 2012 21:09:36 -0500, Roy Smith wrote: > In article <[email protected]>, > Steven D'Aprano wrote: > > >> > The stack that's returned is a list. It's inherently a list, per the >> > classic d

Re: Python Interview Questions

2012-11-19 Thread Steven D'Aprano
On Mon, 19 Nov 2012 09:30:54 -0500, Roy Smith wrote: > In article <[email protected]>, > Steven D'Aprano wrote: > >> I see. It wasn't clear from your earlier description that the items had >> been post-processed from

Re: Python Interview Questions

2012-11-19 Thread Steven D'Aprano
n that your stack trace example is such an example. As I earlier said: [quote] But I can't think of any meaningful, non-contrived example where I might want an actual mutable list of values as a dict key. [end quote] and I still can't. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Splitting a line while keeping quoted items together

2012-11-19 Thread Steven D'Aprano
Try shlex.split. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: re.search when used within an if/else fails

2012-11-19 Thread Steven D'Aprano
On Tue, 20 Nov 2012 01:24:54 +, Steven D'Aprano wrote: > Your code is mangled to the point of unreadability. Ah, never mind, that's *my* fault, not yours. Or rather, my news reader software. Sorry about the noise. The rest of my post still stands: - simplify your example to

Re: re.search when used within an if/else fails

2012-11-19 Thread Steven D'Aprano
7;t actually have an `else` clause, which might explain why it doesn't get executed. By the way, you should not write "if something == None", always use "if something is None" or "is not None". Technically, there are some exceptions but if you have to ask what they are, you don't need to know *wink* -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Linux compatibility

2012-11-19 Thread Steven D'Aprano
installing from source, use "make altinstall" instead of "make install" to ensure that it doesn't overwrite the system Python. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Yet another Python textbook

2012-11-20 Thread Steven D'Aprano
tributor >> becomes automatically a co-author. >> >> Best regards, >> >> Pavel >> >> > You are writing it for something called “NCLab”, not for the general > public, and that sucks. I don't see why you say that it sucks. Why do you care if a free, useful Python text book drives some eyeballs to a website? -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: 10 sec poll - please reply!

2012-11-20 Thread Steven D'Aprano
ully-qualified name, or not, as they prefer. I don't know the name of your module, since your website is down, but let's say it's called "automata": # Option 1 import automata automata.type("Hello World") # Option 2 from automata import type type("Hello Worl

Re: 10 sec poll - please reply!

2012-11-20 Thread Steven D'Aprano
function was correct. It automates typing, so you should call it "type" or (for those paranoid about shadowing the built-in, "type_str". -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: 10 sec poll - please reply!

2012-11-20 Thread Steven D'Aprano
gt; > Just to add one more to the pot, Vim uses "feedkeys()" for a similar > purpose. What does it feed to the keys? Hypercard and other XTalk languages use "type" to simulate typing. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: 10 sec poll - please reply!

2012-11-20 Thread Steven D'Aprano
liberate* shadowing is not. We're all consenting adults here, if somebody calls "from module import type", and shadows the builtin type, that's their right to shoot themselves in the foot. Or not, as the case may be. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Web Frameworks Excessive Complexity

2012-11-20 Thread Steven D'Aprano
e over LOC -- if the CC is radically high or low for the LOC, that is valuable to know. > LoC is much simpler, easier to understand, and > easier to correct than CC. Well, sure, but do you really think Perl one-liners are the paragon of bug-free code we ought to be aiming for? *wink* -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Getting a seeded value from a list

2012-11-20 Thread Steven D'Aprano
s level before. seed = pick_a_new_seed_somehow() levels[name] = seed map = make_map(name, seed) # whatever arguments needed redraw(map) -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: 10 sec poll - please reply!

2012-11-20 Thread Steven D'Aprano
only two hard problems in Computer Science: cache invalidation and naming things." -- Phil Karlton -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Web Frameworks Excessive Complexity

2012-11-21 Thread Steven D'Aprano
instead of: > > def bletch(x,y): > if mode=="foo": return x+y*2 > if mode=="bar": return x*4+y > if mode=="quux": return x+math.sin(y) return x > > Okay, this is a stupid contrived example, but tell me which of those > you'd rather w

Re: Yet another Python textbook

2012-11-21 Thread Steven D'Aprano
essed with the idea that Python is destroying Unicode for the benefit of the Americans. It's quite sad really. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Inconsistent behaviour os str.find/str.index when providing optional parameters

2012-11-22 Thread Steven D'Aprano
> The docstring does not describe this edge case, so I think it could be > improved. If the first sentence(being an index in S) is kept, than it > shouldn't say that start and end are treated as in slice notation, > because that's actually not true. +1 I think that you are right that the documentation needs to be improved. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Spam source (Re: Horror Horror Horror!!!!!)

2012-11-22 Thread Steven D'Aprano
org as well as posting to the newsgroup. The newsgroup is already automatically mirrored by the mailing list, and vice versa, so by CCing all you do is needlessly, and annoyingly, duplicate your message. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Yet another Python textbook

2012-11-22 Thread Steven D'Aprano
The built-in format() function is the public API for calling the dunder method __format__. So normally you would write: format(value, spec) instead of value.__format__(spec). -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: method that can be called from a class and also from an instance

2012-11-22 Thread Steven D'Aprano
staticmethod nor ordinary instance methods do the job, but my custom dualmethod does. http://code.activestate.com/recipes/577030/ -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: 10 sec poll - please reply!

2012-11-22 Thread Steven D'Aprano
g it should > feel like giving instructions to a human being looking over their > shoulder at a screen. In a word processor, I might say "Type Ctrl-A Ctrl-X to cut all the text from the document." rather than "Press Ctrl-A. Now press Ctrl-X." > We really quite like t

Re: method that can be called from a class and also from an instance

2012-11-23 Thread Steven D'Aprano
On Fri, 23 Nov 2012 09:52:25 +0100, Peter Otten wrote: > Steven D'Aprano wrote: >> http://code.activestate.com/recipes/577030/ > > Am I reading that right that you don't invoke method() as > MyClass.method()? No. I give an example and explicitly state: Yo

Re: 10 sec poll - please reply!

2012-11-23 Thread Steven D'Aprano
e, repeated three times, can I do this? press("""\tA \tB \tC """) Or do I have to do this? press(CTRL + 'i') enter('A') press(CTRL + 'i') enter('B') press(CTRL + 'i') enter('C') Speaking of ente

Re: Is it bad style to override the built-in function `type`?

2012-11-24 Thread Steven D'Aprano
A couple of days ago I said: [quote] If it were possible to be confused by the two types, e.g. if they took the same arguments but did radically different things, then I would accept that it was too dangerous/confusing to re-use the name. Reasonable fears about shadowing and confusion are, well, reasonable. [end quote] Your proposal to use "write" is exactly the sort of reasonable confusion that I was talking about. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: How to pass class instance to a method?

2012-11-25 Thread Steven D'Aprano
- is an instance of known class I do not understand what you are saying here. Please try to explain more carefully. [1] You cannot lie about the type of an instance, but sometimes you can actually change its type. Use this feature with care, since it rarely is useful. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: How to get a "screen" length of a multibyte string?

2012-11-25 Thread Steven D'Aprano
rs include N, Na, H, and A (when not in East Asian context). [end quote] from unicodedata import east_asian_width def columns(s, eastasian_context=True): if eastasian_context: wide = 'WFA' else: wide = 'WF' return sum(2 if east_asian_width(c) in wide else 1 for c in s) ought to do it for all but the most sophisticated text layout applications. For those needing much more sophistication, see here: http://www.cl.cam.ac.uk/~mgk25/ucs/wcwidth.c -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: only .exe

2012-11-25 Thread Steven D'Aprano
ost. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: How to pass class instance to a method?

2012-11-26 Thread Steven D'Aprano
d be weakly typed and operate on any type at all. Since there are no type restrictions defined, the body cannot enforce those type restrictions. But that's clearly not true. Please, everybody, before replying to this thread, please read this: http://cdsmith.wordpress.com/2011/01/09/an-old-art

Python dictionaries are awesome

2012-11-26 Thread Steven D'Aprano
- OOPS, you just introduced a bug. What’s the problem? The dictionary. [end quote] -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: How to pass class instance to a method?

2012-11-26 Thread Steven D'Aprano
On Mon, 26 Nov 2012 22:14:59 -0500, Dave Angel wrote: > On 11/26/2012 05:18 PM, Steven D'Aprano wrote: >> On Mon, 26 Nov 2012 16:58:47 -0500, Dave Angel wrote: >> >>> In a statically typed language, the valid types are directly implied >>> by the funct

Re: deepcopy questions

2012-11-27 Thread Steven D'Aprano
entation for deepcopy seriously lacking? http://docs.python.org/3/library/copy.html There's no mention of the additional arguments memo and _nil, and while the docs say to pass the memo dictionary to __deepcopy__ it doesn't document any restrictions on this memo, how to initialise it, or under what circumstances you would pass anything but an empty dict. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: How to create an executable from python script in windows

2012-11-27 Thread Steven D'Aprano
in creating windows executable. Thanks in advance Would you like us to guess what the error is? I love guessing games! My guess is... "File not found". You need to give the right name for the file. Am I close? If my guess was wrong, you need to tell us what the error is.

Re: re.search when used within an if/else fails

2012-11-28 Thread Steven D'Aprano
hon: [steve@ando ~]$ python -m tabnanny Usage: /usr/local/lib/python2.7/tabnanny.py [-v] file_or_directory ... -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: re.search when used within an if/else fails

2012-11-28 Thread Steven D'Aprano
be nice if Python honoured a directive setting indent style to spaces or indents, as it honours source code encoding lines: # -*- indent: -*- Where could be one of: space[s]Only accept spaces in indentation tab[s] Only accept tabs in indentation mixed Accept "mixed" tabs and spaces, but only if consistent with mixed the default for backward compatibility. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Any Python trainers/tutors in Toronto?

2012-12-01 Thread Steven D'Aprano
Are there any Python programmers in the Toronto area interested in some informal, very short-term, paid Python tutoring? Please contact me off-list for details if you are interested. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Weird exception handling behavior -- late evaluation in except clause

2012-12-02 Thread Steven D'Aprano
bals(): ... return TypeError ... x = None ... return NameError ... py> for i in range(3): ... try: ... print(x + 1) ... except pick_an_exception() as err: ... print("Caught", err) ... Caught name 'x' is not defined Caught unsupported oper

Re: Python Noob Question.

2012-12-02 Thread Steven D'Aprano
ature data from, what makes you think we would have any better idea? This is a Python forum, not a "Windows programs that give temperature data" forum. I recommend you start by doing some research into how to read the temperature data, including the name of the program. Once you h

Re: loops

2012-12-02 Thread Steven D'Aprano
o use Python 3, where this is no longer an issue, or to replace "input" with "raw_input": py> again = raw_input('Roll again? (y = yes): ') Roll again? (y = yes): y py> again 'y' > This same loop structure appears in many places in this book

Re: Weird exception handling behavior -- late evaluation in except clause

2012-12-02 Thread Steven D'Aprano
On Mon, 03 Dec 2012 16:24:50 +1100, Chris Angelico wrote: > On Mon, Dec 3, 2012 at 8:31 AM, Steven D'Aprano > wrote: >> Consider this piece of legal Python code: >> >> Err = None >> if condition(x) > 100: >> Err = OneException >> elif a

Re: Puzzling error msg.

2012-12-03 Thread Steven D'Aprano
e thing is silly. The right way to test booleans for their boolean value is just: if found_0 or found_1: "flag == True" is the same as "flag". -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Conversion of List of Tuples

2012-12-03 Thread Steven D'Aprano
lang.python, and mirrored on other places including gmane and various web sites. Neither email nor Usenet include "counters", so you will have to explain what you are talking about. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: scope, function, mutable

2012-12-04 Thread Steven D'Aprano
e global list known as "t" create a new list: [44] + a slice of x bind this new list to name "x" modify in place item 3 of the new list known as "x" So in this case you have to in-place modifications. The first occurs while the name "x" still refers to the or

Re: Good use for itertools.dropwhile and itertools.takewhile

2012-12-04 Thread Steven D'Aprano
Ian, For the sanity of those of us reading this via Usenet using the Pan newsreader, could you please turn off HTML emailing? It's very distracting. Thanks, Steven On Tue, 04 Dec 2012 12:37:38 -0700, Ian Kelly wrote: [...] > On Tue, > Dec 4, 2012 at 11:48 AM, Alexander Bl

Re: why does dead code costs time?

2012-12-05 Thread Steven D'Aprano
STORE_FAST 0 (x) 12 SET_LINENO 3 15 LOAD_GLOBAL 1 (None) 18 RETURN_VALUE 19 LOAD_CONST 0 (None) 22 RETURN_VALUE >>> None = 42 >>> h() 42 Now that None is a keyword, it should always be a LOAD_CONST. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: why does dead code costs time?

2012-12-05 Thread Steven D'Aprano
On Wed, 05 Dec 2012 17:34:57 +, Steven D'Aprano wrote: > I believe that's a leftover from > early Python days when None was not a keyword and could be reassigned. Oops! Wrong copy and paste! Here's a simpler version: [steve@ando ~]$ python1.5 Python 1.5.2 (#1, Aug 27

Re: Confused compare function :)

2012-12-05 Thread Steven D'Aprano
t;Total not found with in the distributor: %s" % tnf Ah-ha! It means "Total Not Found"! I shouldn't have to read all the way to the end of the code to discover this. Instead of "tnf", you should count the total number of SKUs, and count how many times you call Update_SQL. Then you can report: Total records inspected: 754 Total records updated: 392 (or whatever the values are). Simplify and clean up your code, and then it will be easier to find and fix the problems in it. Good luck! -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Confused compare function :)

2012-12-05 Thread Steven D'Aprano
wonder if the code is meant to calculate the new price: newprice = round(dprice)*1.10 # dprice is the price in the CSV file! or perhaps it is meant to be: newprice = int(round(dprice*1.10)) That seems likely. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Confused compare function :)

2012-12-05 Thread Steven D'Aprano
pt tk.TclError: > pass > > Is there a problem with either of the above? If so, what should I do > instead? They're fine. Never, ever say that people should never, ever do something. *cough* -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: question about importing a package

2012-12-05 Thread Steven D'Aprano
ple.py: # 1 from sub_one.foo import in_foo from sub_one.bar import in_bar # 2 from sub_one import * in_foo = foo.in_foo in_bar = bar.in_foo Or you could turn to sub_one.__init__ and do this: # 3 __all__ = ['in_foo', 'in_bar'] from foo import in_foo from bar import in_bar or any combination of the above. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: UnicodeDecodeError: 'utf-8' codec can't decode byte 0x89 in position 0: invalid start byte

2012-12-06 Thread Steven D'Aprano
base64 img = fin.read() # read the binary data of the PNG file data = base64.encodebytes(img) # turn the binary image into text cursor.execute("INSERT INTO Images SET Data='%s'" % \ mdb.escape_string(data)) and see what that does. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Confused compare function :)

2012-12-06 Thread Steven D'Aprano
+= int(s) except ValueError: pass # Not a number, ignore it. Why would you want to log that? It's not an error, it is working as designed. I hate software that logs every little thing that happens, so that you cannot tell what's important and what isn't. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Confused compare function :)

2012-12-06 Thread Steven D'Aprano
On Thu, 06 Dec 2012 13:51:29 +, Neil Cerutti wrote: > On 2012-12-06, Steven D'Aprano > wrote: >> total = 0 >> for s in list_of_strings: >> try: >> total += int(s) >> except ValueError: >> pass # Not a number, ignore it.

Re: A question about readability

2012-12-07 Thread Steven D'Aprano
you prefer a clearer solution? Thanks in advance, It's perfectly fine for such a simple script. It is readable and explicit. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Confused compare function :)

2012-12-07 Thread Steven D'Aprano
x = mydict[key] # fails with KeyError How could this happen? In the fraction of a second between checking whether the key exists and actually looking up the key, another thread could delete it! This is a classic race condition, also known as a Time Of Check To Time Of Use bug. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Confused compare function :)

2012-12-08 Thread Steven D'Aprano
.path.exists(filename): try: f = open(filename) except (IOError, OSError): handle_missing_file() else: handle_missing_file() But in that case, what's the point of the initial check? -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: The Zen of Zope, by Alex Clark

2012-12-09 Thread Steven D'Aprano
On Sun, 09 Dec 2012 20:13:43 -0500, Alex Clark wrote: >>>> import other > The Zen of Zope, by Alex Clark I expect that I would find that hilarious if I knew anything about Zope :) -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: About open file for Read

2012-12-10 Thread Steven D'Aprano
objects If you have read it, and the answer is still not clear, then please tell us so we can improve the documentation. `for line in open(file, "r"):` does not read the entire file into memory at once, it iterates over the file reading one line at a time. -- Steven -- http:

Re: date-time comparison, aware vs naive

2012-12-10 Thread Steven D'Aprano
eing 'aware' and the user-input date-time being 'naive'. "Aware" of what? -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: strptime - dates formatted differently on different computers

2012-12-10 Thread Steven D'Aprano
%y') time.struct_time(tm_year=2013, tm_mon=12, tm_mday=11, tm_hour=0, tm_min=0, tm_sec=0, tm_wday=6, tm_yday=346, tm_isdst=-1) -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: ANNOUNCE: Thesaurus - a recursive dictionary subclass using attributes

2012-12-11 Thread Steven D'Aprano
DivisionError: float division py> py> "%(a.test)s" % d # Lies about the problem. Traceback (most recent call last): File "", line 1, in File "", line 29, in __getitem__ KeyError: 'a.test [1]' One more comment: > # I like to create a master global object called 'g'. > # No more 'global' statements for me. > g = thes() This is not a good thing. Encouraging the use of globals is a bad thing. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: strptime - dates formatted differently on different computers

2012-12-11 Thread Steven D'Aprano
rse. The question is not "will it parse", but will it parse CORRECTLY? What will it parse 11/12/10 as, and how do you know that is the intended date? -- Steven -- http://mail.python.org/mailman/listinfo/python-list

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