Re: why () is () and [] is [] work in other way?

2012-04-26 Thread Steven D'Aprano
On Wed, 25 Apr 2012 20:50:21 -0700, Adam Skutt wrote: > On Apr 25, 8:01 pm, Steven D'Aprano +comp.lang.pyt...@pearwood.info> wrote: >> On Wed, 25 Apr 2012 13:49:24 -0700, Adam Skutt wrote: >> > Though, maybe it's better to use a different keyword than 'is&#x

Re: why () is () and [] is [] work in other way?

2012-04-26 Thread Steven D'Aprano
other languages just like Python, C# and Java would be invented to fill those niches, and the functional-obsessed crowd would then complain that they wished those languages would be more like Python, C# and Java. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: why () is () and [] is [] work in other way?

2012-04-26 Thread Steven D'Aprano
On Thu, 26 Apr 2012 17:16:10 -0700, Adam Skutt wrote: > On Apr 26, 7:33 pm, Steven D'Aprano +comp.lang.pyt...@pearwood.info> wrote: >> On Thu, 26 Apr 2012 12:22:55 -0700, Adam Skutt wrote: >> > I often wonder what the world would be like if Python, C#, and Java >

Re: why () is () and [] is [] work in other way?

2012-04-27 Thread Steven D'Aprano
27;t be, to be fair. I disagree. Violating reflexivity has its uses. NANs are the classic example. Another example is if you redefine "==" to mean something other than "equals". If your class treats == as something other than equality, there is no need for a==a to necessarily return True. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: why () is () and [] is [] work in other way?

2012-04-27 Thread Steven D'Aprano
sentinel. You can break it by passing an object which compares equal to None but isn't actually None. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: why () is () and [] is [] work in other way?

2012-04-27 Thread Steven D'Aprano
. So "have the same genes" meets all your conditions for equality, but isn't equality: the three brothers are very different. Fred lost his arm in a car crash, Barney is a hopeless alcoholic, and George is forty years younger than his two brothers. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: syntax for code blocks

2012-04-27 Thread Steven D'Aprano
y) > > with res << func(arg1) << block_name << 'x, y': > print(x, y) I'm sorry, I don't see how this is a code block. Where is the code in the block, and how can you pass it to another object to execute it? -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: syntax for code blocks

2012-04-27 Thread Steven D'Aprano
On Fri, 27 Apr 2012 17:03:19 +0200, Kiuhnm wrote: > On 4/27/2012 16:09, Steven D'Aprano wrote: >> On Fri, 27 Apr 2012 13:24:35 +0200, Kiuhnm wrote: >> >>> I'd like to change the syntax of my module 'codeblocks' to make it >>> more pythonic. &

Borg identity [was Re: why () is () and [] is [] work in other way?]

2012-04-27 Thread Steven D'Aprano
entities. The Borg design pattern, for example, would be an excellent >> candidate for ID:identity being treated as many-to-one. > > How would inheritance work if I did that? You don't inherit from Borg instances, and instances inherit from their class the same as any other instance. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Direct vs indirect [was Re: why () is () and [] is [] work in other way?]

2012-04-27 Thread Steven D'Aprano
On Thu, 26 Apr 2012 04:42:36 -0700, Adam Skutt wrote: > On Apr 26, 5:10 am, Steven D'Aprano +comp.lang.pyt...@pearwood.info> wrote: >> But I was actually referring to something more fundamental than that. >> The statement "a is b" is a *direct* statement of iden

Python id() does not return an address [was Re: why () is () and [] is [] work in other way?]

2012-04-27 Thread Steven D'Aprano
On Thu, 26 Apr 2012 04:42:36 -0700, Adam Skutt wrote: > On Apr 26, 5:10 am, Steven D'Aprano +comp.lang.pyt...@pearwood.info> wrote: >> Solution to *what problem*? >> > This confusion that many people have over what 'is' does, including > yourself. I hav

Variables and values [was Re: why () is () and [] is [] work in other way?]

2012-04-27 Thread Steven D'Aprano
les of both incorrect and correct code demonstrating what you mean? (I know what distinction *I* would make, but I'm not sure if it is the same one you are making.) -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Borg identity [was Re: why () is () and [] is [] work in other way?]

2012-04-27 Thread Steven D'Aprano
spider, which is is a subtype of wolf spider but is completely eyeless. - Subclasses in Eiffel are not necessarily subtypes and may not be substitutable for superclasses. If it's good enough for Eiffel, it's good enough for my hypothetical Borg subclasses. You can always declare that Bertrand Meyer doesn't "understand OOP at all" too. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: hex to bin 16 bit word

2012-04-27 Thread Steven D'Aprano
;> struct.unpack('>h',b'\xC0\xA8') (-16216,) >>> n = int('0xC0A8', 16) >>> if n >= 0x: ... n -= 0x1 ... >>> n 49320 Should be -16216. Personally, I don't see why the OP doesn't just use struct.unpack to unpack a struct. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Learn Technical Writing from Unix Man in 10 Days

2012-04-28 Thread Steven D'Aprano
ect the documentation to define "except", "instead", "is", "to" and "the"? If you don't know what "install" and "remove" means, then you need an English dictionary, not a technical manual. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: syntax for code blocks

2012-05-01 Thread Steven D'Aprano
{'when_odd': lambda n: n-1, 'when_prime': lambda n: n**2 - 1, ...}) although I would discourage that unless they are *really* trivial. But for callbacks of any complexity, they will need to be tested, otherwise how do you know they do what you want them to do? Your code blocks make unit testing of the callbacks impossible, and for that reason the Pythonic way is better. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Trouble splitting strings with consecutive delimiters

2012-05-01 Thread Steven D'Aprano
#x27;, '', 'float', 'right'] > > Is there any way to avoid getting '' in my list without adding px; as a > delimiter? Probably. But why not do it the easy way? items = re.split(':|;|px', "width:150px;height:50px;float:right") items = filter(None, item) In Python 3, the second line will need to be list(filter(None, item)). -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: syntax for code blocks

2012-05-01 Thread Steven D'Aprano
On Tue, 01 May 2012 19:07:58 +0200, Kiuhnm wrote: > On 5/1/2012 17:11, Steven D'Aprano wrote: >>> My way >>> -- >>> >>> with func(some_args)<< ':dict': >>> with when_odd as 'n': >>> pas

Re: reading data file into a list

2012-05-02 Thread Steven D'Aprano
dy who doesn't know Python very well? Here's one way (untested but should work): import numpy f = open("my data file.txt", "r") contents = numpy.array([float(line) for line in f]) f.close() -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: numpy (matrix solver) - python vs. matlab

2012-05-02 Thread Steven D'Aprano
its of accuracy, as in your example, then the result is meaningless -- the accuracy will be 2-2 digits, or 0 -- *no* digits in the answer can be trusted to be accurate. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: most efficient way of populating a combobox (in maya)

2012-05-03 Thread Steven D'Aprano
the contents of os.listdir requires a large amount of effort. Just try it and see whether it performs well enough. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: syntax for code blocks

2012-05-03 Thread Steven D'Aprano
ou should take a close look at it because there *may* be a problem. > So far, pretty much everyone who has tried to engage you on this subject > on the list. I'm sorry we're not all ZOMGRUBYBLOCKS111 like the > commenters on your project page. Goddamit, did I miss a post somewhere? What the hell is this project people keep talking about? -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: numpy (matrix solver) - python vs. matlab

2012-05-03 Thread Steven D'Aprano
sult >>> looked good to me... So I don't understand what you're saying about 10 >>> = 1 or 2 digits. I think my problem was accurate enough, though I >>> don't know what error with 1e6 in condition number, I should expect. >>> How did you arrive at

Re: How do I run a python program from an internet address?

2012-05-07 Thread Steven D'Aprano
; > What would be the best way to figure out how to do this? Try googling "python web app how to". For example, the very first link found here: https://duckduckgo.com/html/?q=python%20web%20app%20how%20to is an introduction to making Python applications available to run over the Int

Open Source: you're doing it wrong - the Pyjamas hijack

2012-05-07 Thread Steven D'Aprano
of thing that gives open source a bad reputation. (The sad thing is, when closed source software developers do this sort of thing, it gets blamed on "bad apples"; when open source developers do it, it gets used as an indictment on the entire FOSS community.) -- Steven -- http

Re: __doc__+= """Detailed description"""

2012-05-10 Thread Steven D'Aprano
t seems to work, too. But is that a sound way to write python? Am I > relying on undocumented implementation details or am I safe? Are you referring to the part where you define a __doc__ string at the top of the module, and then add to it with __doc__ += "more text"? If not, it isn't clear to me what you mean. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: .py to .pyc

2012-05-13 Thread Steven D'Aprano
t 3.1. You can also use this: python -m compileall to produce .pyc files without waiting for them to be imported. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

ANNOUNCE: byteformat0.2a

2012-05-15 Thread Steven D'Aprano
[steve@ando ~]$ python -m byteformat --prefix=K 1000 12300 145000 1 KB 12.3 KB 145 KB byteformat understands all the relevant SI and IEC unit prefixes, and is released under the MIT licence. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Yet another "split string by spaces preserving single quotes" problem

2012-05-15 Thread Steven D'Aprano
have two problems *wink* > Any hints? Thanks in advance! >>> s = "This is a 'simple test':'string which' shows 'exactly my' problem" >>> import shlex >>> result = shlex.split(s, posix=True) >>> result [

Re: Difference between str.isdigit() and str.isdecimal() in Python 3

2012-05-16 Thread Steven D'Aprano
y> unicodedata.numeric(c) 0.2 py> c = '\u00B2' py> print(c) ² py> c.isdecimal(), c.isdigit(), c.isnumeric() (False, True, True) py> unicodedata.numeric(c) 2.0 -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Newbie questions on import & cmd line run

2012-05-16 Thread Steven D'Aprano
newbie00 source file reload(newbie00) # ... now the changes will show up but be warned that there are some traps to using reload(), so much so that in Python 3 it has been relegated to the "imp" (short for "import") module, where it is less tempting to newbies.

Re: Python and Tkinter by John E Grayson

2012-05-17 Thread Steven D'Aprano
ook is probably acceptable, in my opinion. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: str.isnumeric and Cuneiforms

2012-05-17 Thread Steven D'Aprano
that unicodedata is buggy, or perhaps just doesn't support the multilingual plane characters. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Binding first parameter of method to constant value

2012-05-18 Thread Steven D'Aprano
elf, *args: self._dispatcher('foometh', *args), self, self.__class__) ) setattr(self, 'barmeth', types.MethodType( lambda self, *args: self._dispatcher('barmeth', *args), self, self.__class__)

Plot a function with matplotlib?

2012-05-18 Thread Steven D'Aprano
like this: plot(lambda x: sin(x*pi), # function or expression to plot, start=0.0, end=2.0, ) and have step size taken either from some default, or better still, automatically calculated so one point is calculated per pixel. Is there a way to do this in iPython or matplotlib?

Doctest documentation?

2012-05-20 Thread Steven D'Aprano
e confirm that they are missing? -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: A question of style (finding item in list of tuples)

2012-05-21 Thread Steven D'Aprano
ot;???") > Assume the list > of choices is short enough that the cost of building a temporary dict on > each call is negligible. Negligible or not, why bother? Not that it really matters -- if you have a good reason for CHOICES to remain a list, still stick with the dict lookup rather

Namespace hack

2012-05-24 Thread Steven D'Aprano
raise TypeError('bad export') Namespace = type(func.__name__, (), ns) return Namespace() Have fun! -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Email Id Verification

2012-05-24 Thread Steven D'Aprano
f the mail server to decide whether email can be delivered, not yours. http://northernplanets.blogspot.com.au/2007/03/how-not-to-validate-email-addresses.html http://haacked.com/archive/2007/08/21/i-knew-how-to-validate-an-email-address-until-i.aspx http://haacked.com/archive/2007/08/26/don

Re: Dynamic comparison operators

2012-05-24 Thread Steven D'Aprano
that it is a code injection attack. To learn more, you can start here: http://cwe.mitre.org/top25/index.html Two of the top three most common vulnerabilities are code injection attacks, similar to the improper use of eval. Here is the "eval injection" vulnerability: http://cwe.mitr

Re: Email Id Verification

2012-05-24 Thread Steven D'Aprano
On Thu, 24 May 2012 18:35:21 -0700, Paul Rubin wrote: > Steven D'Aprano writes: >> Why do you want to write buggy code that makes your users hate your >> program? ... >> The only way to validate an email address is to ACTUALLY SEND AN EMAIL >> TO IT. > > Of

Re: Scoping Issues

2012-05-24 Thread Steven D'Aprano
return self.s Another is to use an extra level of indirection, and a mutable argument. Instead of rebinding the non-local, you simply modify it in place: def adder(): s = [0] def a(x): s[0] += x return s[0] return a -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Namespace hack

2012-05-24 Thread Steven D'Aprano
Pardon me for breaking threading, but Daniel's response is not available on my ISP's news server, and I only discovered it by accident. On Thu May 24 15:04:34 CEST 2012, Daniel Fetchinson wrote: > > On Thu, 24 May 2012 08:50:59 +, Steven D'Aprano wrote: > > From

Re: 2to3 for 2.7

2012-05-27 Thread Steven D'Aprano
ple_params ws_comma xreadlines plus "from __future__ import print", and see what breaks :) Also, don't forget future_builtins: http://docs.python.org/library/future_builtins.html Good luck, and if you do go ahead with this, please consider posting an update here, or writing a blo

Re: setup(**config); rookie

2012-05-28 Thread Steven D'Aprano
x27;: 5} somefunc(*args, **kwargs) is expanded to somefunc(1, 2, 3, x=4, y=5) -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: 2to3 inscrutable output

2012-05-28 Thread Steven D'Aprano
to be modified" actually means "Files that include something that a fixer cares about, whether or not it gets modified" (in this case, isinstance). -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Object cleanup

2012-05-30 Thread Steven D'Aprano
n't being garbage collected, you probably have cycles of objects with __del__ methods. Python's reference garbage collector can't delete objects in cycles, and the alternative garbage collector can't delete objects with __del__ methods. Try removing the __del__ methods, and see

Re: Adding to Python Decorator Library at wiki.python.org

2012-05-30 Thread Steven D'Aprano
n't blocking scripts; - try using a different browser. If it still doesn't work, then ask for help. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Object cleanup

2012-05-30 Thread Steven D'Aprano
t; k = K() py> x = k py> y = [1, 2, x, 3] py> z = {'spam': y} py> del k py> del x py> del y py> del z Goodbye cruel world! The destructor doesn't get called into the last reference is gone. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: issubclass(C, Mapping) not behaving as expected

2012-05-30 Thread Steven D'Aprano
ar for Mapping and MutableMapping are a bit unclear to me. But have you tried registering your class as a Mapping explicitly? -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: How to suppress exception printing to console?

2012-05-31 Thread Steven D'Aprano
are raising exceptions, your tests are broken. They should either raise expected exceptions, in which case the exception is a passing test, or they are failing tests, or they are bugs in your test code. Fix the failing tests and the bugs in the test code, don't hide them. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: CPython 2.7: Weakset data changing size during internal iteration

2012-06-01 Thread Steven D'Aprano
g are usually rare, you only notice it when there's a lot of data. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: CPython 2.7: Weakset data changing size during internal iteration

2012-06-03 Thread Steven D'Aprano
On Fri, 01 Jun 2012 20:24:30 -0700, Temia Eszteri wrote: > On 02 Jun 2012 03:05:01 GMT, Steven D'Aprano > wrote: > >>I doubt that very much. If you are using threads, it is more likely your >>code has a race condition where you are modifying a weak set at the sam

Re: Use a locally built Tk for Python?

2012-06-03 Thread Steven D'Aprano
then running "make clean", "make", "sudo make altinstall" again. (I used altinstall instead of install so as to avoid changing the system Python.) This was on a 32-bit Centos system, but I expect it should work just as well on a 64-bit Debian system. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: ./configure

2012-06-03 Thread Steven D'Aprano
/some/directory:/another/directory To replace the system path completely: export $PATH=/some/directory:/another/directory -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: file pointer array

2012-06-04 Thread Steven D'Aprano
ee that this will happen in a timely manner. Best practice is to close them manually once you are done. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

How do I get the constructor signature for built-in types?

2012-06-04 Thread Steven D'Aprano
ne 794, in getargspec getfullargspec(func) File "/usr/local/lib/python3.2/inspect.py", line 821, in getfullargspec raise TypeError('{!r} is not a Python function'.format(func)) TypeError: is not a Python function How do I programmatically get the argument spec of built-in types' __init__ or __new__ methods? -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Metaclass of a metaclass

2012-06-05 Thread Steven D'Aprano
>> >>> >>> class MyClass(metaclass=Meta): # And now try to use it. ... pass ... Traceback (most recent call last): File "", line 1, in TypeError: object.__new__() takes no parameters What am I doing wrong? -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: How to exec() a string like interactive python does?

2012-06-05 Thread Steven D'Aprano
> print a > 3 > > > Now within an application I'd like to achieve exactly this behaviour Before you reinvent the wheel, see the cmd and code modules. http://docs.python.org/library/cmd.html http://docs.python.org/library/code.html -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Passing ints to a function

2012-06-08 Thread Steven D'Aprano
r-loop: for L in (a, b, c): function(*L) -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: [newbie] Equivalent to PHP?

2012-06-13 Thread Steven D'Aprano
HP. http://me.veekun.com/blog/2012/04/09/php-a-fractal-of-bad-design/ and especially lack PHP's security vulnerabilities. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: [newbie] Equivalent to PHP?

2012-06-13 Thread Steven D'Aprano
you even consider reinventing the wheel? -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: [newbie] Equivalent to PHP?

2012-06-13 Thread Steven D'Aprano
On Thu, 14 Jun 2012 00:44:23 +0200, Gilles wrote: > On 13 Jun 2012 22:16:51 GMT, Steven D'Aprano > wrote: >>Surely the obvious answer is that a framework offers the benefit that >>you don't have to write the application from scratch. > > Yes, but between r

Re: Python 3.3.0a4, please add ru'...'

2012-06-16 Thread Steven D'Aprano
e-freeze is only days away, I strongly recommend that you also raise it here: http://mail.python.org/mailman/listinfo/python-dev -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Is that safe to use ramdom.random() for key to encrypt?

2012-06-16 Thread Steven D'Aprano
hing in between? Python's random module is not cryptographically strong, which means that it will probably take an organisation like the NSA, MI5, ASIO, Mossad, etc. about 10 or 20 minutes to crack your password. But your little sister will probably take a hundred million years to guess it. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Smart quote character replacement for those with deficient sed-fu.

2012-06-16 Thread Steven D'Aprano
state.com/recipes/langs/python/ -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Python 3.3.0a4, please add ru'...'

2012-06-17 Thread Steven D'Aprano
ten it will, but that can't be taken for granted. "A foolish consistency is the hobgoblin of little minds" - Ralph Waldo Emerson -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: lazy evaluation of a variable

2012-06-17 Thread Steven D'Aprano
n from the more conservative Python developers.) -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Is that safe to use ramdom.random() for key to encrypt?

2012-06-17 Thread Steven D'Aprano
before they did something about it. [1] And very likely a Facebook-like website that *was* Facebook. I reckon the odds are about 50:50 that FB would prefer to keep a breach secret than risk the bad publicity by fixing it. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Py3.3 unicode literal and input()

2012-06-18 Thread Steven D'Aprano
On Mon, 18 Jun 2012 01:19:32 -0700, jmfauth wrote: > What is input() supposed to return? Whatever you type. u'a' == 'a' > True This demonstrates that in Python 3.3, u'a' gives a string equal to 'a'. r1 = input(':') > :a Since you typed the letter a, r1 is the string "a" (a single ch

Re: Py3.3 unicode literal and input()

2012-06-18 Thread Steven D'Aprano
! Incorrect. You are assuming that Python 3 input eval's the input like Python 2 does. That is wrong. All you show is that the one-character string "a" is not equal to the four-character string "u'a'", which is hardly a surprise. You wouldn't expect the s

Re: A simple way to print few line stuck to the same position

2011-06-02 Thread Steven D'Aprano
:: %s\r' % (i, c)) sys.stdout.flush() time.sleep(0.2) -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Something is rotten in Denmark...

2011-06-02 Thread Steven D'Aprano
On Thu, 02 Jun 2011 10:55:49 -0500, harrismh777 wrote: > Steven D'Aprano wrote: >> What do you expect this code to do? >> >> a = 42 >> funcs = [(lambda x: x+a) for i in range(10)] funcs[0](1) > > I do see your point with this... truly... but it did get

Re: float("nan") in set or as key

2011-06-02 Thread Steven D'Aprano
On Fri, 03 Jun 2011 11:17:17 +1200, Gregory Ewing wrote: > Steven D'Aprano wrote: > >> def kronecker(x, y): >> if x == y: return 1 >> return 0 >> >> This will correctly consume NAN arguments. If either x or y is a NAN, >> it will return 0.

Re: float("nan") in set or as key

2011-06-02 Thread Steven D'Aprano
On Fri, 03 Jun 2011 14:35:52 +1000, Chris Angelico wrote: > On Fri, Jun 3, 2011 at 2:23 PM, Steven D'Aprano > wrote: >>> You can't get a valid result from data produced by an invalid >>> computation. Garbage in, garbage out. >> >> Of course yo

Re: Multiprocessing.connection magic

2011-06-03 Thread Steven D'Aprano
l you Matt?" http://www.youtube.com/watch?v=_f_p0CgPeyA -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: A simple way to print few line stuck to the same position

2011-06-03 Thread Steven D'Aprano
On Fri, 03 Jun 2011 19:00:22 +0800, TheSaint wrote: > Steven D'Aprano wrote: > >> def spinner(): >> chars = '|/-\\' > > Not exactly. > I'd like to show 4~6 line of report and refreshing periodically all of > them, avoiding to scroll

Re: how to avoid leading white spaces

2011-06-03 Thread Steven D'Aprano
part to Perl's over-reliance on them, there's a tendency among many coders (especially those coming from Perl) to abuse and/or misuse regexes; people react to that misuse by treating any use of regexes with suspicion. But they have their role to play as a tool in the programmers toolbox. Regarding their syntax, I'd like to point out that even Larry Wall is dissatisfied with regex culture in the Perl community: http://www.perl.com/pub/2002/06/04/apo5.html -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: how to avoid leading white spaces

2011-06-03 Thread Steven D'Aprano
rm "hard-wired string manipulation", but I don't understand what point you're making. I don't understand what you see as "hard-wired", or why you think source.startswith(prefix) is more hard-wired than re.match(prefix, source) [...] > Perhaps you stopped reading after seeing his "regular expression culture > is a mess" comment without trying to see what he meant by "culture" or > "mess"? Perhaps you are being over-sensitive and reading *far* too much into what I said. If regexes were more readable, as proposed by Wall, that would go a long way to reducing my suspicion of them. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: float("nan") in set or as key

2011-06-03 Thread Steven D'Aprano
On Sat, 04 Jun 2011 12:14:03 +1200, Gregory Ewing wrote: > Steven D'Aprano wrote: >> Fair point. Call it an extension of the Kronecker Delta to the reals >> then. > > That's called the Dirac delta function, and it's a bit different Yes, I'm familiar w

Re: float("nan") in set or as key

2011-06-03 Thread Steven D'Aprano
On Fri, 03 Jun 2011 13:27:00 -0700, Carl Banks wrote: > On Wednesday, June 1, 2011 5:53:26 PM UTC-7, Steven D'Aprano wrote: [...] >> On the contrary, it blows it out of the water and stomps its corpse >> into a stain on the ground. > > Really? I am claiming that,

Re: how to avoid leading white spaces

2011-06-03 Thread Steven D'Aprano
x27;t include function boolean arguments that merely swap between two different actions". -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: how to avoid leading white spaces

2011-06-03 Thread Steven D'Aprano
On Fri, 03 Jun 2011 22:30:59 -0400, Roy Smith wrote: > In article <4de992d7$0$29996$c3e8da3$54964...@news.astraweb.com>, > Steven D'Aprano wrote: > >> Of course, if you include both case-sensitive and insensitive tests in >> the same calculation, that's

Re: float("nan") in set or as key

2011-06-04 Thread Steven D'Aprano
On Fri, 03 Jun 2011 23:04:38 -0700, Ethan Furman wrote: > Steven D'Aprano wrote: >> NANs are not necessarily errors, they're hardly silent, and if you >> don't want NANs, the standard mandates that there be a way to turn them >> off. > > So how does o

Re: how to avoid leading white spaces

2011-06-04 Thread Steven D'Aprano
ow that they're more powerful than regexes, and it seems to me that they're also easier to read and learn. I suspect that the programming world would have been much better off if SNOBOL pattern matching had won the popularity battle against regexes. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Generator Frustration

2011-06-04 Thread Steven D'Aprano
for x in f(): yield x A nice piece of syntax that has been proposed for Python is "yield from", which will do the same thing, but you can't use that yet. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: how to avoid leading white spaces

2011-06-04 Thread Steven D'Aprano
On Sat, 04 Jun 2011 21:02:32 +0100, Nobody wrote: > On Sat, 04 Jun 2011 05:14:56 +0000, Steven D'Aprano wrote: > >> This fails to support non-ASCII letters, and you know quite well that >> having to spell out by hand regexes in both upper and lower (or mixed) >>

Re: float("nan") in set or as key

2011-06-04 Thread Steven D'Aprano
On Sat, 04 Jun 2011 16:49:40 -0500, Robert Kern wrote: > Steven is being a little hyperbolic. Python does not fully conform to > all of the details of the IEEE-754 specification, though it does conform > to most of them. I'm not sure that "most" is correct, but that

Re: float("nan") in set or as key

2011-06-05 Thread Steven D'Aprano
them, but that falls down once you leave > the scope of floating-point. It wouldn't have been within IEEE-754's > ambit to declare that comparing NaNs should return NaB (Not A Boolean). Of course it would have been. That's effectively what the standard actually does

Re: Standard Deviation One-liner

2011-06-05 Thread Steven D'Aprano
2) 0.7071067811865476 >>> s.send(5) 1.5275252316519465 >>> s.send(5) 1.4998 The non-running calculation of stdev gives this: >>> stats.stdev([3, 2, 5, 5]) 1.5 http://pypi.python.org/pypi/stats/ http://code.google.com/p/pycalcstats/ Be warned that the version on Google Code is unstable, and currently broken. Feedback is welcome! -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: float("nan") in set or as key

2011-06-05 Thread Steven D'Aprano
On Sun, 05 Jun 2011 19:15:02 +0100, Nobody wrote: > On Sun, 05 Jun 2011 07:21:10 +0000, Steven D'Aprano wrote: > >> Returning a sentinel meaning "an exceptional event occurred" is hardly >> unusual, even in Python. str.find() does is, as does re.search() and

Re: float("nan") in set or as key

2011-06-05 Thread Steven D'Aprano
y conforms to IEEE-754. The bottleneck now is not hardware, but languages that don't treat floating point maths correctly. http://www.cs.berkeley.edu/~wkahan/JAVAhurt.pdf (The article is seven years old now, but as far as I know, the criticisms still apply.) -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: float("nan") in set or as key

2011-06-05 Thread Steven D'Aprano
On Mon, 06 Jun 2011 14:11:03 +1000, Chris Angelico wrote: > On Mon, Jun 6, 2011 at 11:21 AM, Steven D'Aprano > wrote: >> The intended behaviour is operations on "quiet NANs" should return >> NANs, but operations on "signalling NANs" should cause

Re: how to avoid leading white spaces

2011-06-06 Thread Steven D'Aprano
of it. I won't say the only part. [...] >> If regexes were more readable, as proposed by Wall, that would go a >> long way to reducing my suspicion of them. > > I am delighted to read that you find the new syntax more acceptable. Perhaps I wasn't as clear as I could

Re: Lambda question

2011-06-06 Thread Steven D'Aprano
lly start by writing the documentation (a docstring and doctests) first. How else do you know what the function is supposed to do if you don't have it documented? By writing the documentation and examples before the code, I often discover that the API I first thought of was rubbish :

Re: float("nan") in set or as key

2011-06-06 Thread Steven D'Aprano
On Mon, 06 Jun 2011 23:14:15 +0100, Nobody wrote: > On Mon, 06 Jun 2011 00:55:18 +0000, Steven D'Aprano wrote: > >> And thus we come back full circle. Hundreds of words, and I'm still no >> closer to understanding why you think that "NAN == NAN" should be

Re: new string formatting with local variables

2011-06-06 Thread Steven D'Aprano
;__doc__': None, '__package__': None} >>> def f(**kwargs): ... print kwargs ... >>> >>> f(**vars()) Traceback (most recent call last): File "", line 1, in TypeError: f() keywords must be strings -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: GIL in alternative implementations

2011-06-07 Thread Steven D'Aprano
On Tue, 07 Jun 2011 01:03:55 -0300, Gabriel Genellina wrote: > En Sat, 28 May 2011 14:05:16 -0300, Steven D'Aprano > escribió: > >> On Sat, 28 May 2011 09:39:08 -0700, John Nagle wrote: >> >>> Python allows patching code while the code is executing. >&g

Re: how to inherit docstrings?

2011-06-09 Thread Steven D'Aprano
its" or "license" for more information. >>> class K(object): ... "foo" ... >>> K.__doc__ = 'bar' Traceback (most recent call last): File "", line 1, in ? TypeError: attribute '__doc__' of 'type' objects is not writable It's an unnecessary restriction, as far as I'm concerned, but an old one. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: how to inherit docstrings?

2011-06-10 Thread Steven D'Aprano
On Fri, 10 Jun 2011 07:33:34 +1000, Ben Finney wrote: > Steven D'Aprano writes: >> It's an unnecessary restriction, as far as I'm concerned, but an old >> one. > > Well, it's incompatible with the Python compiler I keep in my head. Have > these devel

<    11   12   13   14   15   16   17   18   19   20   >