Re: Short-circuit Logic

2013-05-28 Thread Steven D'Aprano
ine 1, in ZeroDivisionError: float division by zero So as you can see, testing for "zero" by comparing to machine epsilon does not save you from Zero Division errors. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Short-circuit Logic

2013-05-28 Thread Steven D'Aprano
returns False, but x actually isn't zero? Built-in floats only, if you subclass you can do anything you like: class Cheating(float): def __eq__(self, other): return False -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Short-circuit Logic

2013-05-28 Thread Steven D'Aprano
On Tue, 28 May 2013 15:14:03 +, Grant Edwards wrote: > On 2013-05-28, Steven D'Aprano > wrote: >> On Tue, 28 May 2013 01:39:09 -0700, Ahmed Abdulshafy wrote: >> >>> He just said that the way to test for zero equality is x == 0, and I >>> mea

Re: IndentationError: expected an indented block but it's there

2013-05-28 Thread Steven D'Aprano
python -m tabnanny to convert indentation to all spaces. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Supporting both 2.x and 3.x in one code base [was Re: Python #ifdef]

2013-05-28 Thread Steven D'Aprano
2.3 through 3.3 in one code base. That is, frankly, astonishing.) Nobody *likes* to have to support really old versions missing the cool syntax that you want to use, but nobody says that you should even try. 3.x doesn't change that. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Short-circuit Logic

2013-05-29 Thread Steven D'Aprano
On Wed, 29 May 2013 10:50:47 -0600, Ian Kelly wrote: > On Wed, May 29, 2013 at 8:33 AM, rusi wrote: >> 0.0 == 0.0 implies 5.4 == 5.4 >> is not a true statement is what (I think) Steven is saying. 0 (or if >> you prefer 0.0) is special and is treated specially. > >

Re: detect key conflict in a JSON file

2013-05-29 Thread Steven D'Aprano
On Wed, 29 May 2013 11:20:59 -0400, Roy Smith wrote: >> How to process (read) YAML files in Python? > > Take a look at http://pyyaml.org/ Beware that pyaml suffers from the same issue as pickle, namely that it can execute arbitrary code when reading untrusted data. -- Ste

Re: Short-circuit Logic

2013-05-29 Thread Steven D'Aprano
On Wed, 29 May 2013 07:27:40 -0700, Ahmed Abdulshafy wrote: > On Tuesday, May 28, 2013 3:48:17 PM UTC+2, Steven D'Aprano wrote: >> On Mon, 27 May 2013 13:11:28 -0700, Ahmed Abdulshafy wrote: >> >> >> >> > That may be true for integers, but for floats,

Re: Short-circuit Logic

2013-05-29 Thread Steven D'Aprano
sion. To force it to do so, use the unary + operator.) -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Short-circuit Logic

2013-05-29 Thread Steven D'Aprano
s to watch out for. > http://xkcd.com/1047/ Nice! -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: How clean/elegant is Python's syntax?

2013-05-29 Thread Steven D'Aprano
e case of VB and VFP, they aren't bothered by such issues because they're used to closed-source, proprietary programming where you use what you are given and like it. In the open-source world, if you don't like what you are given, you find something else, and if you can't find it, you make it yourself. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Getting a callable for any value?

2013-05-29 Thread Steven D'Aprano
;m not sure why you care about the repr of the "AnythingFactory" object. You stuff it directly into the defaultdict, where you are very unlikely to need to inspect it. You only ever see the defaultdicts they return, and they already have a nice repr. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Short-circuit Logic

2013-05-30 Thread Steven D'Aprano
es to C-doubles, which Python floats are. Another subtlety: small-but-positive numbers are millions of ULP away from small-but-negative numbers. Also, there are issues to do with +0.0 and -0.0, NANs and the INFs. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Short-circuit Logic

2013-05-30 Thread Steven D'Aprano
flects a fundamental difficulty with floating point types. As a general rule, "defensive coding" does not extend to the idea of defending against mistakes in your code. The compiler, linter or unit tests are supposed to do that. Occasionally, I will code defensively when initialising tedious data sets: prefixes = ['y', 'z', 'a', 'f', 'p', 'n', 'µ', 'm', 'k', 'M', 'G', 'T', 'P', 'E', 'Z', 'Y'] assert len(prefixes) == 16 but that's about as far as I go. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Short-circuit Logic

2013-05-30 Thread Steven D'Aprano
On Thu, 30 May 2013 16:40:52 +, Steven D'Aprano wrote: > On Fri, 31 May 2013 01:56:09 +1000, Chris Angelico wrote: >> You're assuming you can casually hit Ctrl-C to stop an infinite loop, >> meaning that it's trivial. It's not. Not everything lets you

Re: How clean/elegant is Python's syntax?

2013-05-30 Thread Steven D'Aprano
50% a philosophy: * pass arguments to functions, and return results, rather than getting and setting state from a variable. This is a good strategy: it makes it easier to reason about the code, easier to document, easier to test, and makes it practical to use it in threaded code. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Python and GIL

2013-05-30 Thread Steven D'Aprano
ontrol it. Python controls it. You only need to release the GIL when writing C extensions. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Short-circuit Logic

2013-05-30 Thread Steven D'Aprano
is not commutative. (Absolute error, on the other hand, is commutative.) As I said, any form of "approximate equality" has gotchas. But this gotcha is simple to overcome: abs(a -b) < eps*max(abs(a), abs(b)) (Knuth's "approximately equal to" which you give.)

Re: Short-circuit Logic

2013-05-31 Thread Steven D'Aprano
. Given the simple definition of relative error under discussion, the commutative law does not hold. The mere fact that it does not hold is no big deal. It doesn't hold for many comparison operators. Nor does the transitive law hold, even using absolute epsilon: eps = 0.5 a = 1.1 b = 1.5 c = 1.9 then a ≈ b, and b ≈ c, but a ≉ c. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Short-circuit Logic

2013-05-31 Thread Steven D'Aprano
On Fri, 31 May 2013 17:09:01 +1000, Chris Angelico wrote: > On Fri, May 31, 2013 at 3:13 PM, Steven D'Aprano > wrote: >> What makes you think that the commutative law is relevant here? >> >> > Equality should be commutative. If a == b, then b == a. Also, it&#x

Re: Getting Error can't find '__main__' module in 'X'

2013-06-02 Thread Steven D'Aprano
hown us these details, we might be able to help you, or at least come back to you with more questions. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: PyWart: The problem with "print"

2013-06-02 Thread Steven D'Aprano
resolve that function > named "print" is tied to the global and local switches named > "__GLOBAL_DEBUG__" and "__LOCAL_DEBUG__". To prevent any cognitive > dissonance it may be desirable to introduce a new function called > "debugprint". That's not what cognitive dissonance means. The word you are looking for is "confusion". Cognitive dissonance is the mental stress and anguish a person feels when deep down they know that they are the best, most intelligent, most expert Python programmer on the planet, better even than Python's creator, and yet every time they open their mouth to tell the world how Python gets it wrong and how to fix it, they just get shot down in flames. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: PyWart: The problem with "print"

2013-06-02 Thread Steven D'Aprano
On Sun, 02 Jun 2013 11:09:12 -0700, Rick Johnson wrote: > Maybe you don't care about destroying someone's CPU, however, i do! And yet here you are, destroying millions of people's CPUs by sending them email or usenet messages filled with garbage. -- Steven -- http://mail.

Re: Changing filenames from Greeklish => Greek (subprocess complain)

2013-06-02 Thread Steven D'Aprano
ontaining these files in a file browser that supports UTF-8, do you see any file names containing Mojibake? http://en.wikipedia.org/wiki/Mojibake Fix those file names, and hopefully the problem will go away. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Interactive interpreter hooks

2013-06-03 Thread Steven D'Aprano
exception. Is there a way to hook into the interactive interpreter *before* it is evaluated? That is, if I type "len([])" at the prompt and hit ENTER, I want a hook that runs before len([]) is evaluated to 0, so that I get the string "len([])". -- Steven -- http://mai

Re: PyWart: The problem with "print"

2013-06-03 Thread Steven D'Aprano
ciency. It's 2013, not 1975, and computers have more than 32K of RAM and the slowest CPU on the market is a million times faster than the ones that took us to the moon, and quite frankly I have no sympathy for the view that CPU cycles are so precious that we mustn't waste them. If t

Re: Changing filenames from Greeklish => Greek (subprocess complain)

2013-06-03 Thread Steven D'Aprano
(Note: this post is sent using UTF-8. If anyone reading this sees mojibake, please make sure your email or news client is set to use UTF-8.) On Mon, 03 Jun 2013 05:54:30 -0700, rusi wrote: > On Jun 3, 2:12 pm, Νικόλαος Κούρας wrote: >> You are right Steven, i just renames the file

Re: Changing filenames from Greeklish => Greek (subprocess complain)

2013-06-03 Thread Steven D'Aprano
On Mon, 03 Jun 2013 02:12:31 -0700, Νικόλαος Κούρας wrote: > Τη Δευτέρα, 3 Ιουνίου 2013 9:46:46 π.μ. UTC+3, ο χρήστης Steven D'Aprano > έγραψε: > >> If I am right, the solution is to fix the file names to ensure that >> they are all valid UTF-8 names. If you vie

Re: Changing filenames from Greeklish => Greek (subprocess complain)

2013-06-03 Thread Steven D'Aprano
n the file says: import cgi, re, os, sys, socket, datetime, pymysql, locale but there is no pymysql module available. Fix that problem, and then we can look at the next problem. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: PyWart: The problem with "print"

2013-06-03 Thread Steven D'Aprano
uld never, ever do, under pain of maybe having to learn something, is actually check the documentation of an unfamiliar library or function before making assumptions of what it will return. If you follow this advice, you too can enjoy the benefits of writing buggy code. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Bools and explicitness [was Re: PyWart: The problem with "print"]

2013-06-03 Thread Steven D'Aprano
On Mon, 03 Jun 2013 18:37:24 -0700, Rick Johnson wrote: > On Sunday, June 2, 2013 1:58:30 PM UTC-5, Steven D'Aprano wrote: >> On Sun, 02 Jun 2013 10:04:00 -0700, Rick Johnson wrote: >> > A "wise programmer" may think he's solved the problem by writing a

Re: Changing filenames from Greeklish => Greek (subprocess complain)

2013-06-03 Thread Steven D'Aprano
On Mon, 03 Jun 2013 21:35:13 -0700, rusi wrote: > On Jun 4, 3:37 am, Steven D'Aprano [email protected]> wrote: >> (Note: this post is sent using UTF-8. If anyone reading this sees >> mojibake, please make sure your email or news client is set to use >>

Re: Changing filenames from Greeklish => Greek (subprocess complain)

2013-06-04 Thread Steven D'Aprano
you want to see soemhtign else > please ask me to show you Steven. If all else fails, you could just rename the troublesome file and hopefully the problem will go away: mv *Ο.mp3 1.mp3 mv 1.mp3 Eυχή του Ιησού.mp3 -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Beginner question

2013-06-04 Thread Steven D'Aprano
dict(one=1, two=2) py> dict(zip('abcd', range(4)), x=23, y=42, z=999) {'a': 0, 'c': 2, 'b': 1, 'd': 3, 'y': 42, 'x': 23, 'z': 999} Try doing that with {} alone! -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Beginner question

2013-06-04 Thread Steven D'Aprano
then call eval(): s = "dict(%s=0, %s=1)" % (a, b) d = eval(s) but that's slow and inconvenient and dangerous if your data is untrusted. So in this specific case, you should stick to the {} method. [1] Technically it's a type, not a function, but the difference makes no difference here. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: PyWart: The problem with "print"

2013-06-04 Thread Steven D'Aprano
er_effect -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Bools and explicitness [was Re: PyWart: The problem with "print"]

2013-06-04 Thread Steven D'Aprano
type check which is completely opposite in intent to duck-typing. (There's no short name for this -- it's not quite static typing, because it happens at runtime and isn't enforced by the language.) It's almost like Rick declares that he's a great supporter

Re: Changing filenames from Greeklish => Greek (subprocess complain)

2013-06-04 Thread Steven D'Aprano
raceback (most recent call last): File "", line 1, in UnicodeDecodeError: 'utf-8' codec can't decode byte 0xcd in position 0: invalid continuation byte Somehow, I don't know how because I didn't see it happen, you have one or more files in that directory wh

Re: Changing filenames from Greeklish => Greek (subprocess complain)

2013-06-04 Thread Steven D'Aprano
to guess the encoding that a bunch of bytes came from. If your bytes look like 0x48 0x65 0x6c 0x6c 0x6f 0x20 0x77 0x6f 0x72 0x6c 0x64 0x21 (ASCII "Hello World!") then you might *guess* that the encoding is ASCII, or UTF-8, or Latin-1. But in general, you can't go from the bytes to the encoding. Encodings are out-of-band information. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Changing filenames from Greeklish => Greek (subprocess complain)

2013-06-04 Thread Steven D'Aprano
On Tue, 04 Jun 2013 08:47:01 +, Steven D'Aprano wrote: > Please run these commands, and show what result they give: > > alias ls > > printf %q\\n *.mp3 > > ls -b *.mp3 Do you have an answer for this yet? Better still, change the last two commands to thi

Re: Bools and explicitness [was Re: PyWart: The problem with "print"]

2013-06-05 Thread Steven D'Aprano
dynamic type system makes different trade-offs. And of course, type errors are such a vanishingly small subset of all the possible errors that might be made that, frankly, the difference in code quality between those with static typing and those without is essentially indistinguishable. There's no evidence that code written in static typed languages is less buggy than code written in dynamic languages. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Bools and explicitness [was Re: PyWart: The problem with "print"]

2013-06-05 Thread Steven D'Aprano
t you take advantage of it? Python currently has no standard way of doing such automated type tests, and probably won't ever get one. A static typed language gives you those tests for free, but in many languages at the cost that you probably end up spending more time fighting to satisfy th

Re: I just wrote my first Python program a guessing game and it exits with an error I get this.

2013-06-05 Thread Steven D'Aprano
t you should not be using input(), but raw_input() instead. Replace every call to input() to raw_input() instead, and this specific problem will go away. It may reveal other bugs, but that's programming for you. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Apache and suexec issue that wont let me run my python script

2013-06-05 Thread Steven D'Aprano
o see what causes the breakage. * If you change something, and it breaks, undo the change, then experiment outside of your live system to try to understand and fix the issue. As for everyone else, please try to be polite and helpful, or don't reply at all. Thank you. -- Steven -- http:/

Re: Bools and explicitness [was Re: PyWart: The problem with "print"]

2013-06-06 Thread Steven D'Aprano
On Thu, 06 Jun 2013 12:29:44 +1000, Chris Angelico wrote: > On Thu, Jun 6, 2013 at 11:56 AM, Steven D'Aprano > wrote: >> On Wed, 05 Jun 2013 14:59:31 -0700, Russ P. wrote: >>> As for Python, my experience with it is that, as your application >>> grows, you st

Speeding up Python

2013-06-06 Thread Steven D'Aprano
Comparing CPython, PyPy, SciPy, Parakeet and Numba for writing image filters: http://www.phi-node.com/2013/06/faster-morphological-image-filters-in.html -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Changing filenames from Greeklish => Greek (subprocess complain)

2013-06-06 Thread Steven D'Aprano
On Tue, 04 Jun 2013 02:00:43 -0700, Νικόλαος Κούρας wrote: > Τη Τρίτη, 4 Ιουνίου 2013 11:47:01 π.μ. UTC+3, ο χρήστης Steven D'Aprano > έγραψε: > >> Please run these commands, and show what result they give: [...] > [email protected] [~/www/data/apps]# alias ls > ali

Re: Changing filenames from Greeklish => Greek (subprocess complain)

2013-06-06 Thread Steven D'Aprano
then use file names as strings. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Changing filenames from Greeklish => Greek (subprocess complain)

2013-06-06 Thread Steven D'Aprano
me simple examples of the same syntax error: a = b + c) x = y * z) alist.sort()) assert 1+1 == 2) Can you see the common factor? Each of those lines will give the same syntax error as your line. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Changing filenames from Greeklish => Greek (subprocess complain)

2013-06-06 Thread Steven D'Aprano
On Thu, 06 Jun 2013 11:46:20 -0700, Νικόλαος Κούρας wrote: > Τη Πέμπτη, 6 Ιουνίου 2013 3:44:52 μ.μ. UTC+3, ο χρήστης Steven D'Aprano > έγραψε: > >> py> s = '999-Eυχή-του-Ιησού' >> py> bytes_as_utf8 = s.encode('utf-8') >> py> t

Re: Beginner question

2013-06-06 Thread Steven D'Aprano
ython 1.x, dict *actually was a function*, just like len() or ord(), and the type/class system was radically different. But that's ancient history now.) -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Bools and explicitness [was Re: PyWart: The problem with "print"]

2013-06-06 Thread Steven D'Aprano
and on strings 15 py> len(b'\x23') # and on bytes 1 py> len(set(range(2))) # and on sets 2 py> len(frozenset(range(4))) # and on frozensets 4 py> len(range(1000)) # and on range objects 1000 Looks pretty polymorphic to me. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Changing filenames from Greeklish => Greek (subprocess complain)

2013-06-07 Thread Steven D'Aprano
But in the old Windows *Russian* charset, ISO-8859-5, the byte 0xE1 means a completely different character, CYRILLIC SMALL LETTER ES: py> b'\xE1'.decode('ISO-8859-5') 'с' (don't be fooled that this looks like the English c, it is not the same). In Unicode, 'α' is always codepoint 0x3B1 (decimal 945): py> ord('α') 945 but before you can store that on a disk, or as a file name, it needs to be converted to bytes, and which bytes you get depends on which encoding you use: py> 'α'.encode('utf-8') b'\xce\xb1' py> 'α'.encode('utf-16be') b'\x03\xb1' py> 'α'.encode('utf-32be') b'\x00\x00\x03\xb1' -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Python Game Development?

2013-06-07 Thread Steven D'Aprano
On Fri, 07 Jun 2013 09:28:09 -0700, Eam onn wrote: > Do you know of any tutorial for PyGame? Preferably a video tutorial but > any tutorial at all is fine! I can't seem to find any, even on > pygame.org!!! https://duckduckgo.com/html/?q=pygame+tutorial -- Steven -- http://m

Re: Idiomatic Python for incrementing pairs

2013-06-07 Thread Steven D'Aprano
ing fast vector libraries like numpy. Just use numpy arrays instead of lists, and + instead of the add helper function, and Bob's yer uncle. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Changing filenames from Greeklish => Greek (subprocess complain)

2013-06-08 Thread Steven D'Aprano
On Fri, 07 Jun 2013 23:49:17 -0700, Νικόλαος Κούρας wrote: [...] > Oh iam very sorry. > Oh my God i cant beleive i missed a colon *again*: > > I have corrected this: [snip code] Stop posting your code after every trivial edit!!! -- Steven -- http://mail.python.org/mailman/lis

Re: Changing filenames from Greeklish => Greek (subprocess complain)

2013-06-08 Thread Steven D'Aprano
s if we never reached the break. raise ValueError('unable to clean filename %r'%pathname_as_bytes) -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Changing filenames from Greeklish => Greek (subprocess complain)

2013-06-08 Thread Steven D'Aprano
> ' int a', a variable with name 'a' of type integer. 'char a', a > variable with name 'a' of type char > > So taken form above example(the closest i could think of), the way i > understand them is: > > A 'string' can be of (unicode's or ascii's) type and that type needs a > way (thats a charset) to store this string into the hdd as a sequense of > bytes? Correct. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Re-using copyrighted code

2013-06-08 Thread Steven D'Aprano
fixed, not infringements to pursue for profit.) Give credit to where you are copying the code from, and use a licence that is compatible. Don't try to give away rights that they don't give away, don't try to hold rights that they give away, and you're already 90% of the way t

Re: Changing filenames from Greeklish => Greek (subprocess complain)

2013-06-08 Thread Steven D'Aprano
n Unicode was first invented, there was only 65 thousand characters, and a fixed 16 bits was all you needed. But it was soon learned that 65 thousand was not enough (there are more than 65,000 Asian characters alone!) and so UTF-16 developed the trick with surrogate pairs to cover the extras. [...

Re: Changing filenames from Greeklish => Greek (subprocess complain)

2013-06-08 Thread Steven D'Aprano
> And also is there a deiffrence between "encoding" and "compressing" ? Of course. They are totally unrelated. > Isnt the latter useing some form of encoding to take a string or bytes > to make hold less space on disk? Correct, except forget about "encoding". It's not relevant (except, maybe, in a mathematical sense) and will just confuse you. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Changing filenames from Greeklish => Greek (subprocess complain)

2013-06-09 Thread Steven D'Aprano
Copy and paste the results back here please. > Is it the assert that fail? Do we have some logic error someplace i dont > see? Please read the error message. Does it say AssertionError? If it says AssertionError, then the assert has failed. If it says something else, the code failed before the assert can run. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Changing filenames from Greeklish => Greek (subprocess complain)

2013-06-09 Thread Steven D'Aprano
On Sun, 09 Jun 2013 10:55:43 +0200, Lele Gaifax wrote: > Steven D'Aprano writes: > >> On Sat, 08 Jun 2013 22:09:57 -0700, nagia.retsina wrote: >> >>> chr('A') would give me the mapping of this char, the number 65 while >>> ord(65) would outpu

Re: Changing filenames from Greeklish => Greek (subprocess complain)

2013-06-09 Thread Steven D'Aprano
On Sun, 09 Jun 2013 02:00:46 -0700, Νικόλαος Κούρας wrote: > Steven wrote: >>> Since 1 byte can hold up to 256 chars, why not utf-8 use 1-byte for >>> values up to 256? > >>Because then how do you tell when you need one byte, and when you need >>two? If y

Re: Changing filenames from Greeklish => Greek (subprocess complain)

2013-06-09 Thread Steven D'Aprano
last): File "", line 1, in AssertionError > printing a greek Unicode string in the error with ASCII > as the output encoding (default when not a tty IIRC). An interesting thought. How would we test that? -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Changing filenames from Greeklish => Greek (subprocess complain)

2013-06-09 Thread Steven D'Aprano
get an exception. Suppose that you are encoding from French to German: qui -> die (both words mean "who" in English) Now if you get confused, and decode the word 'die' by looking it up in an English-To-French dictionary, instead of German-To-French, you get: die -> mour

Re: Re-using copyrighted code

2013-06-09 Thread Steven D'Aprano
cit rights to modification granted. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Re-using copyrighted code

2013-06-09 Thread Steven D'Aprano
Well this is where one must make a distinction with fair-use -- if I > re-publish my modifications then the code is still subject to the terms > by the original author. If I make a copy for myself and run the problem > for personal, non-commercial use, then I am in the domain of fair use

Re: Re-using copyrighted code

2013-06-09 Thread Steven D'Aprano
us. There has never been a time where copyright only applies to secret works that aren't published. The HMS Pinafore issue -- and similarly for the works of Mark Twain, and any other British author who had work published in the US -- was that their copyright in Britain was not recognised, or legally enforceable, in the USA. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Re-using copyrighted code

2013-06-09 Thread Steven D'Aprano
the law actually enforces. But bringing it back to the original topic, I believe that the philosophy of FOSS is that we should try our best to honour the intentions of the writer, not to find some legal loophole that permits us to copy his or her work against their wishes. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Encoding questions (continuation)

2013-06-10 Thread Steven D'Aprano
bother to read them and just ask the same question again. And again. And again. > ps. i tried to post a reply to the thread i opend via thunderbird mail > client, but not as a reply to somne other reply but as new mail send to > python list. > because of that a new thread will be opened. How can i tell thunderbird > to reply to the original thread and not start a new one? By replying to an email in that thread. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Sorting a set works, sorting a dictionary fails ?

2013-06-10 Thread Steven D'Aprano
, 'Ιανουάριος':1} print("==Values==") for x in sorted(months.values()): print(x) print("==Keys==") for x in sorted(months.keys()): print(x) prints: ==Values== 1 2 ==Keys== Ιανουάριος Φεβρουάριος -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Changing filenames from Greeklish => Greek (subprocess complain)

2013-06-10 Thread Steven D'Aprano
On Mon, 10 Jun 2013 00:10:38 -0700, nagia.retsina wrote: > Τη Κυριακή, 9 Ιουνίου 2013 3:31:44 μ.μ. UTC+3, ο χρήστης Steven D'Aprano > έγραψε: > >> py> c = 'α' >> py> ord(c) >> 945 > > The number 945 is the characters 'α' ordinal v

Re: Re-using copyrighted code

2013-06-10 Thread Steven D'Aprano
On Mon, 10 Jun 2013 08:42:07 +0200, Malte Forkel wrote: > Am 10.06.2013 07:31, schrieb Steven D'Aprano: >> >> But bringing it back to the original topic, I believe that the >> philosophy of FOSS is that we should try our best to honour the >> intentions of th

Re: "Don't rebind built-in names*" - it confuses readers

2013-06-10 Thread Steven D'Aprano
never choose a variable name that >> is a keyword. > > Btw, shouldn't it be illegal anyway? Most compilers don't let you do > use a keyword as a variable name list is not a keyword. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: "Don't rebind built-in names*" - it confuses readers

2013-06-10 Thread Steven D'Aprano
d have > been clearer to both me and Idle. Correct. The downside of editors that colourise text is that sometimes they colourise it wrong. In this case, how is the editor supposed to know that list no longer refers to the built-in list? This is yet another good argument for being cautious about shadowing built-ins. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: "Don't rebind built-in names*" - it confuses readers

2013-06-10 Thread Steven D'Aprano
used "foo" as a local variable stopped working? [1] For some value of "foo". -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: "Don't rebind built-in names*" - it confuses readers

2013-06-10 Thread Steven D'Aprano
hem too. A good programmer[1] will weigh up the pros and cons of "use the most readable, descriptive name for the variable" versus "shadow a global or built-in with the same name" and decide on the merits of the specific case in question -- should I use a less-appropriate name ("mylist", blah) in the interest of not confusing some readers, or the right name but risk shadowing a name in a higher scope? Python takes a very hands-off approach to this. Other languages are more in-your-face. There is room in the world for both philosophies. [1] In my opinion of good *wink* -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: "Don't rebind built-in names*" - it confuses readers

2013-06-11 Thread Steven D'Aprano
f that causes the built-in to be inaccessible within that function. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: "Don't rebind built-in names*" - it confuses readers

2013-06-11 Thread Steven D'Aprano
On Tue, 11 Jun 2013 08:22:19 -0700, Rick Johnson wrote: > On Monday, June 10, 2013 9:56:43 PM UTC-5, Steven D'Aprano wrote: >> On Mon, 10 Jun 2013 20:14:55 -0400, Terry Jan Reedy wrote: >> > Reading further, one sees that the function works with two lists, a

Re: Receing a form variable as a list instead of as a string

2013-06-11 Thread Steven D'Aprano
questing more than one item. else: # The user is requesting only one item. [end quote] Read the rest of the docs. Don't ask any more questions until you have read them. Then, if anything is still unclear, you can point to a section of the docs and say "I don't understand this". -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Turnign greek-iso filenames => utf-8 iso

2013-06-12 Thread Steven D'Aprano
Seens the encoding precedure successfully turned all the filenames from > greek-iso to utf-8 without failing, why woul it still be encoding issues > when it comes to execute? Because the problems are unrelated. Just because you fix one bug, doesn't mean all the other bugs magically disappear.

Re: Turnign greek-iso filenames => utf-8 iso

2013-06-12 Thread Steven D'Aprano
tf-8') # Check the presence of a file against the database # and insert if it doesn't exist cur.execute('SELECT url FROM files WHERE url = %s', filename) data = cur.fetchone() -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Turnign greek-iso filenames => utf-8 iso

2013-06-12 Thread Steven D'Aprano
On Wed, 12 Jun 2013 12:00:38 +0300, Νικόλαος Κούρας wrote: > On 12/6/2013 11:31 πμ, Steven D'Aprano wrote: >> On Wed, 12 Jun 2013 08:02:24 +, Νικόλαος Κούρας wrote: >>> and the output is just Pacman.exe as seen in >>> >>> http://superhost.gr/

Re: A few questiosn about encoding

2013-06-12 Thread Steven D'Aprano
14 bits: 00 01 10 11 [...] 10 11 you will see that there are only 32767 (2**15-1) such values. You can't fit 1114111 characters with just 32767 values. -- Steven -- http://mail.python.org/mai

Re: Turnign greek-iso filenames => utf-8 iso

2013-06-12 Thread Steven D'Aprano
On Wed, 12 Jun 2013 12:24:24 +0300, Νικόλαος Κούρας wrote: > On 12/6/2013 12:17 μμ, Steven D'Aprano wrote: >> On Wed, 12 Jun 2013 12:00:38 +0300, Νικόλαος Κούρας wrote: >> >>> On 12/6/2013 11:31 πμ, Steven D'Aprano wrote: >>>> On Wed, 12

Re: A few questiosn about encoding

2013-06-12 Thread Steven D'Aprano
mation in previous emails to answer this question on your own, but here it is again: Open an interactive Python session, and run this code: c = ord(16474) len(c.encode('utf-8')) That will tell you how many bytes are used for that example. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Turnign greek-iso filenames => utf-8 iso

2013-06-12 Thread Steven D'Aprano
other stream of >> questions along the lines of "How do I do it?". > > hi. I loopet rope aroung and jumped, but bruise happen and erron do the > death. > > Pls heelp! > > Nikos Oh god I shouldn't laugh but that is funny. Still not cool though. Please stop. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Turnign greek-iso filenames => utf-8 iso

2013-06-12 Thread Steven D'Aprano
On Wed, 12 Jun 2013 15:42:07 +0100, Mark Lawrence wrote: > On 12/06/2013 13:42, Νικόλαος Κούρας wrote: >> >> Something you want me to try? > > I'd suggest suicide Mark, not cool. Seriously not cool. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: "Don't rebind built-in names*" - it confuses readers

2013-06-12 Thread Steven D'Aprano
ction Just to make things complicated :-) -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: "Don't rebind built-in names*" - it confuses readers

2013-06-12 Thread Steven D'Aprano
;five" py> int 'five' py> del int py> int("42") 42 Or: py> int = "five" py> int 'five' py> type(5)("42") 42 Or: py> int = "five" py> import builtins # Use __builtin__ in Python 2. py> builtins.int("42") 42 -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: "Don't rebind built-in names*" - it confuses readers

2013-06-12 Thread Steven D'Aprano
recent call last): File "", line 1, in TypeError: 'str' object is not callable py> builtins.int = type(5) py> int("42") 42 It may not be quite so simple to recover from *all* such monkey-patches, but you can always exit Python, edit your code, and start it up again. It's not like you've patched the actual compiler. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: "Don't rebind built-in names*" - it confuses readers

2013-06-12 Thread Steven D'Aprano
example, the re module defines a function compile, which shadows the built-in compile, but: - the re module doesn't use the built-in compile - other modules normally use the fully-qualified re.compile so, in practice, there is no conflict. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: A few questiosn about encoding

2013-06-12 Thread Steven D'Aprano
ence your byte-string is not valid UTF-32: py> b = b'\xFF'*8 py> b.decode('UTF-32') Traceback (most recent call last): File "", line 1, in UnicodeDecodeError: 'utf32' codec can't decode bytes in position 0-3: codepoint not in range(0x11) -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: A certainl part of an if() structure never gets executed.

2013-06-12 Thread Steven D'Aprano
he first object is falsey, and the second object is truthy, so it is returned 0 or [] or "foo" => the first two objects are falsey, so the third is returned The "and" operator works in a similar fashion. Experiment with it and see how it works for yourself. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: A few questiosn about encoding

2013-06-13 Thread Steven D'Aprano
On Thu, 13 Jun 2013 09:09:19 +0300, Νικόλαος Κούρας wrote: > On 13/6/2013 3:13 πμ, Steven D'Aprano wrote: >> Open an interactive Python session, and run this code: >> >> c = ord(16474) >> len(c.encode('utf-8')) >> >> >> That will

Re: A few questiosn about encoding

2013-06-13 Thread Steven D'Aprano
ng showing what the int would look like in a different base: py> hex(16474) '0x405a' Notice that the return value of bin, oct and hex are all strings. If they were ints, then they would display in decimal, defeating the purpose! -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Python biases [was Re: My son wants me to teach him Python]

2013-06-13 Thread Steven D'Aprano
, but actively (if unconsciously) fought against. As someone immersed in that culture, and therefore at risk of being unaware of my biases, I am *very* curious as to what you think they are, and what strengths of Python you think I might be missing. -- Steven -- http://mail.python.org/m

Re: A certainl part of an if() structure never gets executed.

2013-06-13 Thread Steven D'Aprano
rself. You have a Python interactive interpreter. Try things, and see what they do. Read the documentation. THEN, and ONLY after you have done these things, should you ask for help. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: My son wants me to teach him Python

2013-06-13 Thread Steven D'Aprano
p beginner > a lot (this one is very nice, not just magnified editor). I consider IDEs to be an attractive nuisance. It's like learning to be a chef by putting food in a microwave and pushing the pre-set buttons. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

<    1   2   3   4   5   6   7   8   9   10   >