Re: Reference

2014-03-05 Thread Steven D'Aprano
On Wed, 05 Mar 2014 22:23:46 +0200, Marko Rauhamaa wrote: > Steven D'Aprano : > >> There is no metaphysical implication from Python's "is" operator. If >> the operator had precisely the same behaviour, but was called "same", >> as in: >

Re: Working with the set of real numbers (was: Finding size of Variable)

2014-03-05 Thread Steven D'Aprano
On Wed, 05 Mar 2014 21:31:51 -0500, Roy Smith wrote: > In article <[email protected]>, > Steven D'Aprano wrote: > >> Physics is the fundamental science, at least according to the >> physicists, and Real Soon Now the

Re: Python programming

2014-03-05 Thread Steven D'Aprano
On Wed, 05 Mar 2014 20:19:56 -0800, Beowulf wrote: > Once you master one language it is easy to understand other. Depends on the languages. Learning Forth doesn't make it easier to learn Perl. Learning Pascal doesn't make Smalltalk easier. -- Steven -- https://mail.pytho

Re: NameError: name 'pyver' is not defined

2014-03-06 Thread Steven D'Aprano
accidentally running a script intended for Python2.6 under Python3.2 instead. execfile is removed from 3.2, so you need to either edit the script to update it for 3.2, or you need to make sure you are running it under 2.6. Do you need help with that? -- Steven -- https://mail.python.org/mailman/listinfo/python-list

Re: Assertions are bad, m'kay?

2014-03-07 Thread Steven D'Aprano
e just accepted as if they were correct, no questions asked. You should read this guy's blog post on when to use assert: http://import-that.dreamwidth.org/676.html It's pretty damn good, if I do say so myself... *whistles innocently* -- Steven D'Aprano http://import-that.dr

Re: Assertions are bad, m'kay?

2014-03-08 Thread Steven D'Aprano
On Fri, 07 Mar 2014 16:15:36 -0800, Dan Stromberg wrote: > On Fri, Mar 7, 2014 at 3:11 AM, Steven D'Aprano > wrote: > > >> Assertions are not bad! They're just misunderstood and abused. > >> You should read this guy's blog post on when to use asser

Re: How is unicode implemented behind the scenes?

2014-03-08 Thread Steven D'Aprano
use is much improved: Python has *many* strings (every function, method and class uses many strings in their implementation) and the memory savings can be considerable. Depending on your application and what you do with those strings, that may even lead to time savings as well as memory savings.

Re: Tuples and immutability

2014-03-09 Thread Steven D'Aprano
u say that whether list.append operates in place or creates a new list is an implementation detail? Whether str.upper() creates a new string or modifies the existing one in place? Mutability versus immutability is part of the interface, not implementation, not withstanding that

Re: Balanced trees

2014-03-09 Thread Steven D'Aprano
But when people are just talking informally in a hand-wavy manner, they usually say "O(foo)" when they actually mean "for typical data under typical conditions, the algorithm runs with a complexity of the order of foo". And that's perfectly okay, just like it's perfectly okay to describe the Earth as a sphere even though a pedant will call it a wrinkly asymmetrical oblate spheroid. -- Steven D'Aprano http://import-that.dreamwidth.org/ -- https://mail.python.org/mailman/listinfo/python-list

Re: Balanced trees

2014-03-09 Thread Steven D'Aprano
o "The Relativity Of Wrong": http://chem.tufts.edu/answersinscience/relativityofwrong.htm -- Steven D'Aprano http://import-that.dreamwidth.org/ -- https://mail.python.org/mailman/listinfo/python-list

Re: Balanced trees

2014-03-10 Thread Steven D'Aprano
On Mon, 10 Mar 2014 08:16:43 +0200, Marko Rauhamaa wrote: > Steven D'Aprano : > >> Proof: I create a hash table that accepts unsigned bytes as keys, where > > The O(f(n)) notation has no meaning when n is limited. It has obvious meaning: O(1) means that look-ups take c

Re: Tuples and immutability

2014-03-10 Thread Steven D'Aprano
On Mon, 10 Mar 2014 02:35:36 -0600, Ian Kelly wrote: > On Sun, Mar 9, 2014 at 8:37 PM, Steven D'Aprano > wrote: >> On Sun, 09 Mar 2014 17:42:42 -0600, Ian Kelly wrote: >> >>> On Sun, Mar 9, 2014 at 4:03 PM, Gregory Ewing >>> wrote: >> >

Testing interactive code using raw_input

2014-03-10 Thread Steven D'Aprano
some arguments, gathers some more values interactively, processes the lot, and then returns a result. With an automated test, I can provide the arguments, and check the result, but what are my options for *automatically* supplying input to raw_input? -- Steven -- https://mail.python.org

Re: Balanced trees

2014-03-10 Thread Steven D'Aprano
er has an amazing talent for pessimising code when they think they are optimising it. -- Steven D'Aprano http://import-that.dreamwidth.org/ -- https://mail.python.org/mailman/listinfo/python-list

Re: Balanced trees

2014-03-10 Thread Steven D'Aprano
anteed O(1) lookups, insertions and deletions. http://en.wikipedia.org/wiki/Perfect_hash_function -- Steven D'Aprano http://import-that.dreamwidth.org/ -- https://mail.python.org/mailman/listinfo/python-list

Re: Testing interactive code using raw_input

2014-03-11 Thread Steven D'Aprano
On Mon, 10 Mar 2014 17:57:19 +0100, Peter Otten wrote: > Steven D'Aprano wrote: >> what are my options for *automatically* supplying input to raw_input? > > https://pypi.python.org/pypi/mock > > In Python 3 this is part of the standard library: Nice! Thanks

Re: Tuples and immutability

2014-03-11 Thread Steven D'Aprano
look at the docs is because I always forget whether & is intersection and | is union, or the other way around. But having remembered which is which, going from & to &= was easy. > You mean set.intersection_update? The in-place set methods are not hard > to remember, because

Re: Tuples and immutability

2014-03-11 Thread Steven D'Aprano
case. Evaluating the right hand side may have side- effects that change what the left hand side evaluates to. This is not the case with the augmented assignment. -- Steven -- https://mail.python.org/mailman/listinfo/python-list

Re: Deep vs. shallow copy?

2014-03-12 Thread Steven D'Aprano
onvention that returning the special object None signals the intention to return nothing at all. Hence your example below: >>>> c = a.append(b) >>>> print c > None -- Steven D'Aprano http://import-that.dreamwidth.org/ -- https://mail.python.org/mailman/listinfo/python-list

Re: unittest weirdness

2014-03-12 Thread Steven D'Aprano
r it, but the only one I can find was apparently fixed more than a decade ago: http://bugs.python.org/issue451309 -- Steven D'Aprano http://import-that.dreamwidth.org/ -- https://mail.python.org/mailman/listinfo/python-list

Re: Tuples and immutability

2014-03-12 Thread Steven D'Aprano
On Tue, 11 Mar 2014 17:06:43 -0600, Ian Kelly wrote: > On Tue, Mar 11, 2014 at 10:46 AM, Steven D'Aprano > wrote: >>> There are a number of possible solutions. One possibility would be to >>> copy the Circle as an Ellipse and return the new object instead of >&

Re: unittest weirdness

2014-03-12 Thread Steven D'Aprano
gt; raise ValueError('invoices %r missing from batch' % > missing) Raising an exception directly inside the test function should only occur if the test function is buggy. As Terry has already suggested, this probably communicates your intention much better: self.assertEqual(missing, []) -- Steven D'Aprano http://import-that.dreamwidth.org/ -- https://mail.python.org/mailman/listinfo/python-list

Re: unittest weirdness

2014-03-12 Thread Steven D'Aprano
sumably will include Python running the tests). This at least will allow you to see whether or not memory is the concern. -- Steven D'Aprano http://import-that.dreamwidth.org/ -- https://mail.python.org/mailman/listinfo/python-list

Re: Deep vs. shallow copy?

2014-03-13 Thread Steven D'Aprano
On Thu, 13 Mar 2014 07:44:27 -0400, Roy Smith wrote: > In article <[email protected]>, > Steven D'Aprano wrote: > >> Because Python doesn't have true procedures > > What do you mean by "true procedure"? Are

Re: Deep vs. shallow copy?

2014-03-13 Thread Steven D'Aprano
On Thu, 13 Mar 2014 14:27:48 +0200, Marko Rauhamaa wrote: > Roy Smith : > >> Steven D'Aprano wrote: >> >>> Because Python doesn't have true procedures >> >> What do you mean by "true procedure"? Are you just talking about >> subr

Re: Balanced trees

2014-03-13 Thread Steven D'Aprano
keeping the two in sync, will be faster than a pure Python implementation of an AVL tree. But of course only testing it will make that clear. http://code.activestate.com/recipes/576693-ordered-dictionary-for-py24/ Modifying the above recipe to keep items in something other than insertion order

Re: Deep vs. shallow copy?

2014-03-13 Thread Steven D'Aprano
On Fri, 14 Mar 2014 10:55:44 +1100, Chris Angelico wrote: > On Fri, Mar 14, 2014 at 10:41 AM, Steven D'Aprano > wrote: >> Are you trolling again? >> >> I'm sure that you know quite well that Python doesn't have a procedure >> type. It uses a single

Re: Deep vs. shallow copy?

2014-03-13 Thread Steven D'Aprano
ive methods are not what people consider *returning* from a sub-routine. Unless they're trolling :-) -- Steven D'Aprano http://import-that.dreamwidth.org/ -- https://mail.python.org/mailman/listinfo/python-list

Re: Deep vs. shallow copy?

2014-03-13 Thread Steven D'Aprano
ction is intended to be called for it's side- effects (a procedure), it should return None. > Wear vanilla programmer hat: > The concept (Pascal) procedure is simulated by function-returning-None Yes, agreed on this one. -- Steven -- https://mail.python.org/mailman/listinfo/python-list

Re: Balanced trees

2014-03-13 Thread Steven D'Aprano
at the end of whatever other processing, > sorting is great. It's (still) O(nlogn), but it's got a terrific > constant. Exactly! -- Steven -- https://mail.python.org/mailman/listinfo/python-list

Re: Sharing: File Reader Generator with & w/o Policy

2014-03-15 Thread Steven D'Aprano
err_code: > print (err_code) > else: > line_count = 0 > while True: > linein = fh.readline() > if (linein!=''): > lineout = linein.strip('\n') > length = len(lineout) >

Re: Sharing: File Reader Generator with & w/o Policy

2014-03-16 Thread Steven D'Aprano
itemize, itemise] 2: determine the number or amount of; "Can you count the books on your shelf?"; "Count your change" [syn: count, number, enumerate, numerate] -- Steven D'Aprano http://import-that.dreamwidth.org/ -- https://mail.python.org/mailman/listinfo/python-list

Re: pkg_resources.DistributionNotFound: hiredis

2014-03-17 Thread Steven D'Aprano
t; Question blah blah blah? > Another question? See here for more details: http://en.wikipedia.org/wiki/Posting_style Thanks in advance, -- Steven -- https://mail.python.org/mailman/listinfo/python-list

Re: 'complex' function with string argument.

2014-03-17 Thread Steven D'Aprano
value=Num(n=2j))])' py> ast.dump(ast.parse("1+2j")) 'Module(body=[Expr(value=BinOp(left=Num(n=1), op=Add(), right=Num(n=2j)))])' and in recent versions, the peephole optimizer optimizes them: py> from dis import dis py> dis("1+2j") 1 0 LOAD_CONST 2 ((1+2j)) 3 RETURN_VALUE -- Steven -- https://mail.python.org/mailman/listinfo/python-list

Re: 'complex' function with string argument.

2014-03-17 Thread Steven D'Aprano
accept spaces around the + or -, as it already accepts leading and trailing spaces. But it's not a big deal. [...] > Also, philosophically, C ignores white space; python does not. C does not ignore whitespace. forwhile is not the same as for while The first is a valid identifier, the second is a syntax error. Oh somebody please tell me it's not a valid C expression! *wink* -- Steven -- https://mail.python.org/mailman/listinfo/python-list

Re: Question about Source Control

2014-03-18 Thread Steven D'Aprano
On Tue, 18 Mar 2014 17:47:51 +1100, Ben Finney wrote: > "Frank Millman" writes: > >> I feel that I have just not grasped the basics yet, so any assistance >> that puts me on the right path is appreciated. > > Here is “Hg Init”, a tutorial for Mercurial http://hginit.com/>. > > (“source control

Re: 'complex' function with string argument.

2014-03-18 Thread Steven D'Aprano
On Tue, 18 Mar 2014 08:04:44 +0100, Christian Gollwitzer wrote: > Am 15.03.14 17:26, schrieb Jayanth Koushik: >> This is regarding the inbuilt 'complex' function. The python docs say: >> "Note: When converting from a string, the string must not contain >> whitespace around the central + or - opera

Re: Question about Source Control

2014-03-18 Thread Steven D'Aprano
On Tue, 18 Mar 2014 19:08:17 +1100, Chris Angelico wrote: > On Tue, Mar 18, 2014 at 6:55 PM, Steven D'Aprano > wrote: >> I don't think that *version* control is the right model to describe >> what hg and git do, although it may be appropriate for subversion. hg >

Unexpected comparisons in dict lookup

2014-03-18 Thread Steven D'Aprano
htly different dict, with the collisions in a different order: py> e = {x: 100} py> e[100] = 200 comparing x with 100 py> e[y] = 300 comparing x with y comparing y with 100 comparing y with 100 -- Steven -- https://mail.python.org/mailman/listinfo/python-list

Re: Balanced trees

2014-03-18 Thread Steven D'Aprano
ehaviour negligible for any amount of data big enough to really matter. -- Steven -- https://mail.python.org/mailman/listinfo/python-list

Re: Balanced trees

2014-03-18 Thread Steven D'Aprano
t: graph the log of the time rather than time itself. -- Steven -- https://mail.python.org/mailman/listinfo/python-list

Re: Balanced trees

2014-03-19 Thread Steven D'Aprano
On Wed, 19 Mar 2014 10:49:33 +0200, Marko Rauhamaa wrote: > Steven D'Aprano : > >> If you are in a position to randomize the data before storing it in the >> tree, an unbalanced binary tree is a solid contender. > > Applications that can assume randomly distribute

Re: running python 2 vs 3

2014-03-20 Thread Steven D'Aprano
On Thu, 20 Mar 2014 22:30:57 +0200, Marko Rauhamaa wrote: > To avoid nausea, I write sys.stdout.write() in all Python3 code. Now that's funny. I-know-I-shouldn't-respond-to-obvious-trolling-but-I-can't-help-myself-ly yrs, -- Steven D'Aprano -- https://mail.pyth

Re: running python 2 vs 3

2014-03-20 Thread Steven D'Aprano
nt language. Or use a different name altogether: steve@orac:~$ alias snake=python steve@orac:~$ snake Python 2.6.6 (r266:84292, Dec 27 2010, 00:02:40) [GCC 4.4.5] on linux2 Type "help", "copyright", "credits" or "license" for more information. This has not

Re: running python 2 vs 3

2014-03-20 Thread Steven D'Aprano
scripts across a network of mixed Linux distros including some that are Arch-Linux, it's difficult to see exactly what pain they could be causing even in principle. -- Steven D'Aprano http://import-that.dreamwidth.org/ -- https://mail.python.org/mailman/listinfo/python-list

Re: running python 2 vs 3

2014-03-20 Thread Steven D'Aprano
worth the benefit. I was glad to be able to drop support for 2.3, 2.4, > and 2.5, and now only support 2.6-3.4 in coverage.py. Sounds like your experience agrees with mine. -- Steven D'Aprano http://import-that.dreamwidth.org/ -- https://mail.python.org/mailman/listinfo/python-list

Re: running python 2 vs 3

2014-03-20 Thread Steven D'Aprano
three different places ought to be managed by a function. Printing a newline at the end of a line of output is *incredibly* common. Any language which fails to provide a print-with-newline function is, frankly, sub-standard. -- Steven D'Aprano http://import-that.dreamwidth.org/ -- https://mail.python.org/mailman/listinfo/python-list

Re: running python 2 vs 3

2014-03-20 Thread Steven D'Aprano
use they didn't hard-code the version number. I haven't seen scripts broken because "env" has moved, but I guess that's only a matter of time. Frankly, hash-bang lines are a dirty hack, and like all dirty hacks, they work really well until they suddenly don't. -- Steven D'Aprano http://import-that.dreamwidth.org/ -- https://mail.python.org/mailman/listinfo/python-list

Re: Python - Caeser Cipher Not Giving Right Output

2014-03-20 Thread Steven D'Aprano
st: 30 + 40 % 26 => 30 + 14 => 54 What you probably want is to calculate the % last, not first. That means you need to perform the addition first. Use round brackets (parentheses) for that: (30 + 40) % 26 => 70 % 26 => 18 Does that help? -- Steven D'Aprano http://import-that.

Re: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list)

2014-03-21 Thread Steven D'Aprano
If x were a global, it would be astonishing. The fact that x comes from a closure instead makes it no less surprising. Unroll the loop, and the magic is obvious. Now I'm not sure precisely how Haskell implements this trick, but it suggests to me that it creates a different closure each time

Re: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list)

2014-03-22 Thread Steven D'Aprano
the body of a function created with lambda is limited to a single expression, not a block; - the function object created with lambda has a generic name. So unless the surprising behaviour about lambda that you're about to tell us about relates to one of those three things, I *guarantee* t

Re: Python MSI not installing, log file showing name of a Viatnemese communist revolutionary

2014-03-22 Thread Steven D'Aprano
The customers are the advertisers. [...] > If I were in charge of the software used for this list, I would replace > Mark with a custom addition to return mis-formated posts (more blank > lines than not) with instructions on how to fix them. But I am not. Wouldn't it be less obnox

Re: Python MSI not installing, log file showing name of a Viatnemese communist revolutionary

2014-03-22 Thread Steven D'Aprano
mp/io.txt') => # irb(main):002:0> f.read() => "hello" irb(main):003:0> f.read() => "" [steve@ando ~]$ lua Lua 5.1.4 Copyright (C) 1994-2008 Lua.org, PUC-Rio > fp = io.open('/tmp/io.txt', 'r') > print(fp:read("*all")) he

Re: Python MSI not installing, log file showing name of a Viatnemese communist revolutionary

2014-03-22 Thread Steven D'Aprano
On Sun, 23 Mar 2014 02:09:20 +1100, Chris Angelico wrote: > On Sun, Mar 23, 2014 at 1:50 AM, Steven D'Aprano > wrote: >> Line endings are terminators: they end the line. Whether you consider >> the terminator part of the line or not is a matter of opinion (is the >>

Re: Reading in cooked mode (was Re: Python MSI not installing, log file showing name of a Viatnemese communist revolutionary)

2014-03-23 Thread Steven D'Aprano
On Sun, 23 Mar 2014 12:37:43 +1100, Chris Angelico wrote: > On Sun, Mar 23, 2014 at 12:07 PM, Steven D'Aprano > wrote: >> On Sun, 23 Mar 2014 02:09:20 +1100, Chris Angelico wrote: >> >>> On Sun, Mar 23, 2014 at 1:50 AM, Steven D'Aprano >>> wrote: &

Re: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list)

2014-03-24 Thread Steven D'Aprano
On Mon, 24 Mar 2014 00:52:52 -0500, Mark H Harris wrote: > On 3/22/14 4:46 AM, Steven D'Aprano wrote: >> On Fri, 21 Mar 2014 23:51:38 -0500, Mark H Harris wrote: >> >>> Lambda is a problem, if only because it causes confusion. What's the >>> problem?

Re: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list)

2014-03-24 Thread Steven D'Aprano
ing_L Four lines of code to do what lambda lets you do in one. And people still insist that lambda is pointless. Maybe they're being paid by the line. > Or do you just shortcut the whole thing by inlining it? > > L.sort(key=lambda item:item[1].index) Exactly. -- Steven D'Aprano http://import-that.dreamwidth.org/ -- https://mail.python.org/mailman/listinfo/python-list

Re: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list)

2014-03-24 Thread Steven D'Aprano
O_USE_FOR_INDEXING_WHEN_SORTING_L = 1 # # key func used when sorting L, returns item's 1th elem index method # # #_get_oneth_element_index_to_use_as_keyfunc_when_sorting_L # # Steven D'Aprano # 2014-03-25 # 2014-03-25 # 1 # item to be sorted # index method of the oneth element # NameError # FIXME c

Re: String modifying error, trying to delete data in string

2014-03-24 Thread Steven D'Aprano
place method; you can use the re module to use regexes; you can slice them with some_string[start:end] syntax, etc. But it looks to me like you might be better off using a higher-level protocol rather than using socket. What sort of data are you expecting back? -- Steven D'Aprano

Re: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list)

2014-03-24 Thread Steven D'Aprano
t; > *ducks for cover* Ha ha, very funny :-P http://code.activestate.com/recipes/577676-dirt-simple-mapreduce/ -- Steven D'Aprano http://import-that.dreamwidth.org/ -- https://mail.python.org/mailman/listinfo/python-list

Re: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list)

2014-03-24 Thread Steven D'Aprano
On Mon, 24 Mar 2014 14:47:11 -0500, Mark H Harris wrote: > On 3/24/14 4:49 AM, Steven D'Aprano wrote: >> There's no doubt that lambda is less-often useful than is the def >> statement. But not only is it still useful, but there is a continual >> stream of people ask

Re: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list)

2014-03-24 Thread Steven D'Aprano
level? I'm pretty sure Joy and Factor should. Perhaps not Forth or Postscript. Some of these language may offer variable assignment, but using it is entirely optional. It's a convenience, nothing more. -- Steven -- https://mail.python.org/mailman/listinfo/python-list

Re: Time we switched to unicode? (was Explanation of this Python language feature?)

2014-03-24 Thread Steven D'Aprano
guous) symbols. Personally, I think that it would be good to start accepting, but not requiring, Unicode in programming languages. We can already write: from math import pi as π Perhaps we should be able to write: setA ⊂ setB -- Steven -- https://mail.python.org/mailman/listinfo/python-list

Re: Time we switched to unicode? (was Explanation of this Python language feature?)

2014-03-24 Thread Steven D'Aprano
get a © than typing "copyright". So, if applications could standardise on a single interface for at least the common Unicode characters [er, common for who? English speakers? Japanese people? Arabs? Dutch?] then things would be more like 1984 on a Mac... -- Steven -- https://mail.python.org/mailman/listinfo/python-list

Re: Time we switched to unicode? (was Explanation of this Python language feature?)

2014-03-24 Thread Steven D'Aprano
> >>> Π = pi That's the product operator. py> from unicodedata import name py> name('Π') 'GREEK CAPITAL LETTER PI' You want lower-case pi, π. -- Steven -- https://mail.python.org/mailman/listinfo/python-list

Re: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list)

2014-03-24 Thread Steven D'Aprano
complain that it does the wrong thing. If you have late binding, then people who want early binding will complain that it does the wrong thing. Even when they are the same people. And *none of this has anything to do with lambda*. Functions created with def exhibit the exact same behaviour. -- Steven -- https://mail.python.org/mailman/listinfo/python-list

Re: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list)

2014-03-24 Thread Steven D'Aprano
s. Nor is Python alone in spelling out lambda: Scheme and > Common Lisp spell it the same way. As far as I know the \ for λ is > unique to Haskell. At least they don't spell it "fun". -- Steven -- https://mail.python.org/mailman/listinfo/python-list

Re: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list)

2014-03-24 Thread Steven D'Aprano
aviour, and you replace the lambda with def, you will still be confused. You'll have gone from a nice, concise expression to a bulky statement, and be no better off. You'll be worse off. -- Steven -- https://mail.python.org/mailman/listinfo/python-list

Re: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list)

2014-03-24 Thread Steven D'Aprano
" greet() Would you expect to see "Hello Fred"? The problem here is that Python is consistent, but people *want* it to be inconsistent. When it doesn't magically read their mind, they get "confused" that it isn't working the way they "expected". -- Steven -- https://mail.python.org/mailman/listinfo/python-list

Re: Time we switched to unicode? (was Explanation of this Python language feature?)

2014-03-25 Thread Steven D'Aprano
On Mon, 24 Mar 2014 20:56:19 -0700, Rustom Mody wrote: > Paren vs tuples: why do we need to write (x,) not (x) You don't. You can write x, without the brackets: py> t = 23, py> type(t) It's the comma that makes tuples, not the brackets. -- Steven -- https://mail

Re: Time we switched to unicode? (was Explanation of this Python language feature?)

2014-03-25 Thread Steven D'Aprano
on you Chris! Don't you know the One True Way to write unambiguous dates is the ISO data format? 2014-03-25 -- Steven -- https://mail.python.org/mailman/listinfo/python-list

Re: Time we switched to unicode?

2014-03-25 Thread Steven D'Aprano
On Tue, 25 Mar 2014 19:23:45 +1100, Chris Angelico wrote: > I was trying to avoid nit-picking What, on comp.lang.python? What's wrong with you? :-) -- Steven -- https://mail.python.org/mailman/listinfo/python-list

Re: [newbie] confusion concerning fetching an element in a 2d-array

2014-03-25 Thread Steven D'Aprano
it? Firstly, convert your string read from a file into numbers, then build your array. Here's one way: py> values = [float(s) for s in data.split()] py> print values [1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0] py> array_lines = np.array(values) py> array_lines = a

Re: Time we switched to unicode? (was Explanation of this Python language feature?)

2014-03-25 Thread Steven D'Aprano
to borrow the symbols used too. I'd like to sum the squares of the integers from n=1 to 10. In the old Python, I'd write sum(n**2 for n in range(1, 11)), but with the brave new world of maths symbols, I'd like to write this: http://timmurphy.org/examples/summation_large.jpg How do I enter that, and what text editor should I use? -- Steven D'Aprano http://import-that.dreamwidth.org/ -- https://mail.python.org/mailman/listinfo/python-list

Re: Time we switched to unicode? (was Explanation of this Python language feature?)

2014-03-25 Thread Steven D'Aprano
than sets. I'm sure it is awfully impressive that mathematicians can derive the laws of integer maths starting only from the empty set ∅, but as far as programming goes that's not a very useful thing. Dicts are much more important, and they are much more commonly used. -- Steven

Re: Time we switched to unicode? (was Explanation of this Python language feature?)

2014-03-25 Thread Steven D'Aprano
on > Star Trek? 1986, when I last saw Star Trek IV. The Star Trek universe also predicts that money will be obsolete. How's that prediction working out? -- Steven D'Aprano http://import-that.dreamwidth.org/ -- https://mail.python.org/mailman/listinfo/python-list

Re: Time we switched to unicode? (was Explanation of this Python language feature?)

2014-03-25 Thread Steven D'Aprano
I can see the appeal of certain Unicode symbols, I really wouldn't like to have to deal with code that looks like this: x∫2*y+∬e**3∺z≹(x+1)≽y⋝w If I wanted line-noise, I know where to get Perl :-) -- Steven D'Aprano http://import-that.dreamwidth.org/ -- https://mail.python.org/mailman/listinfo/python-list

Re: Time we switched to unicode? (was Explanation of this Python language feature?)

2014-03-25 Thread Steven D'Aprano
ke Python. Of course one could *write* a Mathematica-like system in Python, and I expect that Sage may even have something like this (if it doesn't, it could) but one shouldn't hammer the specialised round peg of complex mathematical notation into the square peg of a general pu

Re: [newbie] confusion concerning fetching an element in a 2d-array

2014-03-25 Thread Steven D'Aprano
hat's your first job. Then identify the parts of code you want to take from my example and put it into your example. Good luck, and have fun! -- Steven D'Aprano http://import-that.dreamwidth.org/ -- https://mail.python.org/mailman/listinfo/python-list

Re: unicode as valid naming symbols

2014-03-25 Thread Steven D'Aprano
ke Lisp and Forth. You will note that they have a certain reputation for being, um, different, and although both went through periods of considerable popularity, both have faded in popularity since. While they have their strengths, and their defenders, nobody argues that they are readily

Re: Time we switched to unicode? (was Explanation of this Python language feature?)

2014-03-25 Thread Steven D'Aprano
On Tue, 25 Mar 2014 19:55:39 -0400, Terry Reedy wrote: > On 3/25/2014 11:18 AM, Steven D'Aprano wrote: > >> The thing is, we can't just create a ∑ function, because it doesn't >> work the way the summation operator works. The problem is that we would >> wa

Re: Time we switched to unicode?

2014-03-25 Thread Steven D'Aprano
. It's that second requirement -- specifically the "lossless" part -- that leads to such annoyances as µ and μ. -- Steven D'Aprano http://import-that.dreamwidth.org/ -- https://mail.python.org/mailman/listinfo/python-list

Delayed evaluation of expressions [was Re: Time we switched to unicode?]

2014-03-26 Thread Steven D'Aprano
On Wed, 26 Mar 2014 00:30:21 -0400, Terry Reedy wrote: > On 3/25/2014 8:12 PM, Steven D'Aprano wrote: >> On Tue, 25 Mar 2014 19:55:39 -0400, Terry Reedy wrote: >> >>> On 3/25/2014 11:18 AM, Steven D'Aprano wrote: >>> >>>> The thing is

Re: Dynamically reference variable in object

2014-03-26 Thread Steven D'Aprano
ther languages, such as Java, and occasionally creeps into even the Python docs. I've often ranted about this, and won't repeat it now, only point out that the preferred and most common terminology in Python circles is "attribute", or "instance attribute" if yo

Re: Delayed evaluation of expressions [was Re: Time we switched to unicode?]

2014-03-26 Thread Steven D'Aprano
ame as having that language feature. Beyond a certain minimum feature set, all languages are Turing complete, and so in one sense are of equivalent power. But they're not all of equal expressiveness. Python is awesome, it is very expressive, but there are certain things you can't write directly

Re: YADTR (Yet Another DateTime Rant)

2014-03-26 Thread Steven D'Aprano
positive or negative: we'll say "1 day and 6 hours from now" or "1 day and 6 hours ago". But when we specify the sign: py> divmod(-30, 24) (-2, 18) If an event happened 30 hours ago, it is correct to say that it occurred "18 hours after 2 days ago", but who talks that way? -- Steven D'Aprano http://import-that.dreamwidth.org/ -- https://mail.python.org/mailman/listinfo/python-list

Re: Delayed evaluation of expressions [was Re: Time we switched to unicode?]

2014-03-26 Thread Steven D'Aprano
s not evaluated unless the first is true.) Or they read the docs of the Sum function. Or both. > The article included > > real procedure Sum(k, l, u, ak) >value l, u; >integer k, l, u; >real ak; >comment k and ak are passed by name; &g

Re: regex line by line over file

2014-03-26 Thread Steven D'Aprano
of the file? I can't help you with the first. But the second: try running this: # line2 and pat as defined above filename = sys.argv[1] with open(filename) as f: for line in f: print(len(line), line==line2, repr(line)) print(repr(pat.match(line))) which will show you what you have and whether or not it matches what you think it has. I expect that the file contents is not what you think it is, because the regex is matching the sample line. Good luck! -- Steven -- https://mail.python.org/mailman/listinfo/python-list

Re: YADTR (Yet Another DateTime Rant)

2014-03-27 Thread Steven D'Aprano
levant: http://bugs.python.org/issue1569623 Alas, the discussion appears to have been on #python-dev, which (probably) means it is not archived anywhere. -- Steven D'Aprano http://import-that.dreamwidth.org/ -- https://mail.python.org/mailman/listinfo/python-list

Re: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list)

2014-03-27 Thread Steven D'Aprano
e difficulty typing √ in their source code, they certainly don't count! It's good enough that *you* have a solution to that problem, you can type alt-v, and anyone who can't simply doesn't matter. -- Steven D'Aprano http://import-that.dreamwidth.org/ -- https://mail.python.org/mailman/listinfo/python-list

Re: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list)

2014-03-27 Thread Steven D'Aprano
non-expert non-programmer programmers? Apart from wishful thinking, of course. -- Steven D'Aprano http://import-that.dreamwidth.org/ -- https://mail.python.org/mailman/listinfo/python-list

Re: YADTR (Yet Another DateTime Rant)

2014-03-28 Thread Steven D'Aprano
On Thu, 27 Mar 2014 20:29:17 -0400, Roy Smith wrote: > In article <[email protected]>, > Steven D'Aprano wrote: > >> On Thu, 27 Mar 2014 08:52:24 -0400, Roy Smith wrote: >> >> > In article , >> > Chris Angel

Re: YADTR (Yet Another DateTime Rant)

2014-03-28 Thread Steven D'Aprano
On Fri, 28 Mar 2014 08:30:11 -0400, Roy Smith wrote: > In article <[email protected]>, > Steven D'Aprano wrote: > >> > Yes. The whole idea of OOD is to decouple internal representation >> > from external behavior. >>

Re: To flatten a nested list was (Explanation of this Python language feature? [x for x in x for x in x]

2014-03-28 Thread Steven D'Aprano
ds py> L = [[1]]*10 py> with Stopwatch(): ... x = reduce(add, L) ... time taken: 41.344467 seconds -- Steven D'Aprano http://import-that.dreamwidth.org/ -- https://mail.python.org/mailman/listinfo/python-list

Re: Howto flaten a list of lists was (Explanation of this Python language feature)

2014-03-28 Thread Steven D'Aprano
Mark, please stop posting to the newsgroup comp.lang.python AND the mailing list [email protected]. They mirror each other. Your posts are not so important that we need to see everything twice. -- Steven D'Aprano http://import-that.dreamwidth.org/ -- https://mail.python.org/ma

Re: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list)

2014-03-28 Thread Steven D'Aprano
> than typing; *every* character would require holding down a good number > of keys. (Or you could go the other way and have exactly two keys: 1 and > 0. Press either 21 times to enter a single character.) http://like-a-boss.org/wp-content/uploads/2011/10/supercoder.jpg -- Steven

Re: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list)

2014-03-28 Thread Steven D'Aprano
t the keys appear. Shuffling the order that Latin letters ABC...Z appear on the keyboard is not in any way "the right idea" for entering non-Latin languages, nor does a Dvorak language help enter arbitrary Unicode characters. -- Steven D'Aprano http://import-that.dreamwidth.org/ -- https://mail.python.org/mailman/listinfo/python-list

Re: Keyboard standards

2014-03-29 Thread Steven D'Aprano
heir" own keytop too? geeze They're welcome to try. Without support from the operating system, what good do you think it will do? Apple used to have an Apple key. Later they changed it to ⌘ (Command), but everyone knows that ⌘ is only available on Apple keyboards. -- Steven

Re: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list)

2014-03-29 Thread Steven D'Aprano
On Fri, 28 Mar 2014 23:40:01 -0500, Mark H Harris wrote: > On 3/28/14 10:51 PM, Steven D'Aprano wrote: >> You are being patronising to the 94% of the world that is not from the >> USA. Do you honestly think that people all over the world have been >> using computers for

Re: checking if two things do not equal None

2014-03-29 Thread Steven D'Aprano
which are None? Nearly always when people test for == to None, they don't really mean it. They actually want to use an identity test. I'm going to assume the same holds here. if not (a is b is None): ... Or if you prefer: if a is not b is not None: ... -- Steven D'Aprano htt

<    62   63   64   65   66   67   68   69   70   71   >