Re: How come StopIteration.__base__ is not BaseException?

2013-08-27 Thread Steven D'Aprano
an unexpected error occurred') log_unhandled_exception(e) emergency_shutdown() sys.exit(1) except (KeyboardInterrupt, SysExit): # User wants to exit. clean_exit() sys.exit(0) Which except clause would you expect an unhandled StopIteration to fall under? The unex

Re: Missing something on exception handling in Python 3

2013-08-27 Thread Steven D'Aprano
st accept that 3.1 and 3.2 users will see double tracebacks :-( All the more reason to encourage people to go straight to 3.3 or better and skip 3.1 and 3.2 :-) -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Getting request's source site

2013-08-27 Thread Steven D'Aprano
low. Need a hand disposing of a body? Yeah, there are legitimate reasons for this, I'll help if I can. Forcing visitors to your website to set the Referer header? Nope, no way. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: New VPS Provider needed

2013-08-27 Thread Steven D'Aprano
ovider doesnt set thign u[ cprrectly. >> >> Perhaps he's also having problems with a faulty keyboard. > > Just a faulty key actuator, I think. Nothing unusual in this world. Guys, PLEASE stop baiting Nikos with snide remarks. It makes this a very unpleasant environment, and s

Re: New VPS Provider needed

2013-08-27 Thread Steven D'Aprano
#x27;t, they won't. That is the way things are, so just accept it. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: [error] [client 178.59.111.223] (2)No such file or directory: exec of

2013-08-27 Thread Steven D'Aprano
html template > page = file.replace( path, '' ) > > So chnage it to what? What do you think you need to change it to? Pick one: 1) bytes 2) an integer 3) a string 4) a list of floats 5) something else -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: New VPS Provider needed

2013-08-27 Thread Steven D'Aprano
t don't presume that we are your friends and care about your troubles. We all have troubles of our own. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: can't get utf8 / unicode strings from embedded python

2013-08-27 Thread Steven D'Aprano
here else? What could *possibly* go wrong by relying on code working by accident like this? -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: New VPS Provider needed

2013-08-28 Thread Steven D'Aprano
On Wed, 28 Aug 2013 09:19:40 +0200, Antoon Pardon wrote: > Op 27-08-13 18:18, Steven D'Aprano schreef: >> On Wed, 28 Aug 2013 00:41:17 +1000, Chris Angelico wrote: >> >>> On Wed, Aug 28, 2013 at 12:25 AM, Grant Edwards >>> wrote: >>>> On 2

Re: can't get utf8 / unicode strings from embedded python

2013-08-28 Thread Steven D'Aprano
hat advice, not just the people here but essentially the entire Python development community responsible for adding Unicode strings to the language. Can you blame me for feeling that your reply seemed rather arrogant? In any case, I'm glad you responded with a little more restraint th

Re: [error] [client 178.59.111.223] (2)No such file or directory: exec of

2013-08-28 Thread Steven D'Aprano
On Wed, 28 Aug 2013 01:46:01 -0700, Ferrous Cranus wrote: > Τη Τρίτη, 27 Αυγούστου 2013 8:07:52 μ.μ. UTC+3, ο χρήστης Steven > D'Aprano έγραψε: >> Hint: you can use >> "print(type(page), file=open('path/to/some/file', 'w'))" >> >>

Re: [error] [client 178.59.111.223] (2)No such file or directory: exec of

2013-08-28 Thread Steven D'Aprano
On Wed, 28 Aug 2013 03:43:08 -0700, Ferrous Cranus wrote: > but i cannot see the error_log because of constant scrolling of error > output. Then don't use "tail -F", use "less". Or try "tail -s 60 -F" which will update only every 60 seconds. --

Re: Why is str(None) == 'None' and not an empty string?

2013-08-28 Thread Steven D'Aprano
ore correct? Would you expect str([]) or str(0.0) or str({}) to also give an empty string? I can't see any reason for str(None) to return the empty string. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: [error] [client 178.59.111.223] (2)No such file or directory: exec of

2013-08-28 Thread Steven D'Aprano
lot of useful looking hits. Google on "what user does apache run as" and do your research. This is off-topic though. This is not a "beginner's guide to apache" forum, if you can't solve this problem yourself you'll have to take it elsewhere. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: [error] [client 178.59.111.223] (2)No such file or directory: exec of

2013-08-28 Thread Steven D'Aprano
y create a writable directory and write to that. I expect that there are security implications of having a directories writable to the webserver user, but temporarily creating one for a quick debugging aid should be okay. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: [error] [client 178.59.111.223] (2)No such file or directory: exec of

2013-08-28 Thread Steven D'Aprano
you bother to read the error before asking for help? Variable 'e' is not defined. Perhaps you should define it? -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Interface and duck typing woes

2013-08-28 Thread Steven D'Aprano
the pythonic way to deal with it? Am I worrying too > much ;-)? Yes :-) Except in the (rare?) case that you aren't worrying enough, in which case you can check hasattr and callable up front, or do whatever other tests you feel the need to check. It depends on the specific code you are writing. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: [error] [client 178.59.111.223] (2)No such file or directory: exec of

2013-08-28 Thread Steven D'Aprano
e out permissions > related issues. Perhaps. But Nikos is reporting that his log file shows entries from all the other websites on the server, which doesn't sound good to me. Surely any decent, competent web server company would be able to ensure that each customer sees only their own l

Re: Interface and duck typing woes

2013-08-28 Thread Steven D'Aprano
old-article-i-wrote/ Anyone who hasn't already done so, you should read the whole article. It's about static versus dynamic typing, testing, proving correctness, and how they all fit in together. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: semicolon at end of python's statements

2013-08-28 Thread Steven D'Aprano
x27;s about the same as writing this: x = 1 pass y = 2 pass z = x**2 + y**2 pass print z pass except you save three keystrokes per LOC. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: [error] [client 178.59.111.223] (2)No such file or directory: exec of

2013-08-28 Thread Steven D'Aprano
; and 'bytes' Do you see a pattern yet? What do you think will happen if you run this? b'bytes%s' % 'string' Try it and see for yourself. Now look at the error message you are getting. Is it the same error message? Do you think that perhaps it has the same cause? How do you think you might solve this problem? Hint: if you have a data item that is type A, and you need it to be type B, you need to convert from A to B. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Interface and duck typing woes

2013-08-29 Thread Steven D'Aprano
n birds: if isinstance(Duck, bird): self.birds.append(bird) def quack_all(self): for bird in self.birds: bird.quack() class Duck: def __init__(self, name): self.name = name def quack(self): print "%s quacks" % self.name -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Why is str(None) == 'None' and not an empty string?

2013-08-29 Thread Steven D'Aprano
don't doubt that it wouldn't be occasionally convenient to map None to '' rather than 'None', I think it would be surprising and, indeed, dangerous if it happened by default, since it would encourage people to build up SQL query strings by concatenation, as in the Original Poster's example. (And thank you for picking up on that.) -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Is there a function that applies list of functions to a value?

2013-08-29 Thread Steven D'Aprano
of arguments given is 2**31-1. Python may not actually have that limitation, in which case you would need to define additional functions. Or... you would have to come up with an implementation which doesn't hard- code the number of functions used. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Is there a function that applies list of functions to a value?

2013-08-29 Thread Steven D'Aprano
to names just as I assign anonymous ints and anonymous lists to names :-) I say "directly" because this of course is allowed: funcs = [lambda x: x+1, lambda x: x*2, lambda x: x**3] for func in func: ... and *much* better than having to predefine plusOne, timesTwo, powerThree

Re: Interface and duck typing woes

2013-08-29 Thread Steven D'Aprano
one of the motivating use- cases for function annotations in Python 3 is to allow such things. http://www.python.org/dev/peps/pep-3107/ (Function annotations are perhaps the best Python feature that nobody uses.) -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Why is str(None) == 'None' and not an empty string?

2013-08-29 Thread Steven D'Aprano
On Fri, 30 Aug 2013 01:57:45 +, Steven D'Aprano wrote: > So while I don't doubt that it wouldn't be occasionally convenient to > map None to '' rather than 'None', I think it would be surprising and, > indeed, dangerous if it happened by default, s

Re: semicolon at end of python's statements

2013-08-30 Thread Steven D'Aprano
o get around this, I often declare a generator. But I still find it a > bit awkward to have to look up the definition elsewhere, and to waste > lines over something so simple. No need to look up a definition elsewhere, you can put the generator right next to the loop: gen = (spam for spam in

Re: Interface and duck typing woes

2013-08-30 Thread Steven D'Aprano
On Fri, 30 Aug 2013 06:35:47 -0400, Roy Smith wrote: > In article <[email protected]>, > Steven D'Aprano wrote: > >> These days, it would be relatively simple to implement pre- and post- >> condition checking using decorators,

Re: python script to gather file links into textfile

2013-08-30 Thread Steven D'Aprano
me if you are interested. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Encapsulation unpythonic?

2013-08-30 Thread Steven D'Aprano
ules, classes...) or whether you have to write one big amorphous unstructured program where every chunk of code can reach inside other chunks of code. Nor does dynamic type have to do with information hiding. You can have a private member of a class regardless of whether that member has a si

Re: print function and unwanted trailing space

2013-08-31 Thread Steven D'Aprano
> print() The last space is exactly the same as you get in Python 2. But really, who cares about an extra invisible space? In non-interactive mode, the two are exactly the same (ignoring the extra print() call outside the loop), but even at the interactive interpreter, I'd like to see the code where an extra space makes a real difference. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: UnicodeDecodeError issue

2013-08-31 Thread Steven D'Aprano
call to cur.execute in the code snippet you show above? > But 'host' defaults to an ip address if it cannot resolve the hostname. > Why the errro says its undefined? Because it is is undefined. Python is not lying to you. If Python tells you there is an error, BELIEVE IT. Res

Re: Encapsulation unpythonic?

2013-08-31 Thread Steven D'Aprano
languages built on top of the JVM, such as OpenXION and Cobra. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: print function and unwanted trailing space

2013-08-31 Thread Steven D'Aprano
On Sat, 31 Aug 2013 14:59:17 +0200, candide wrote: > Le 31/08/2013 13:16, Steven D'Aprano a écrit : > > >> Of course it does. Have you actually tried it? > > > Of course I did, redirecting the output to a file in order to spot an > eventually trailing space.

Re: UnicodeDecodeError issue

2013-08-31 Thread Steven D'Aprano
t' is undefined. Because you haven't defined it BEFORE you try to use it. There is no point defining it AFTER you use it, the error has already occurred. You have to make the coffee before you drink it: # This fails too drink(coffee) coffee = make_coffee() # This doesn'

Re: How do I process this using Python?

2013-08-31 Thread Steven D'Aprano
print the wrong results, or does it raise an exception? If so, please copy and paste the entire traceback, do not simplify it, summarise it, or retype it from memory. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Best practice for generalizing and documenting each method's behaviour

2013-08-31 Thread Steven D'Aprano
ant project with 80 other people and millions of lines of code, perhaps it would be worth learning UML for parts of the design. But for a one-man project with only thousands of lines of code? I doubt it. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Encapsulation unpythonic?

2013-09-01 Thread Steven D'Aprano
t > to. Unlike Java or C++ who would tend to do exactly the contrary > (enforces it strictly, and (possibly?) allow you to discard it at times > with a few jiffies (or not? I don't know)) Java and C++ allow you to declare members as public, so it is *not true* that calling methods is the only way to change members. If you accept Steve Holden's (wrong) definition above, Java and C++ don't have encapsulation either. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: UnicodeDecodeError issue

2013-09-01 Thread Steven D'Aprano
t;> >> Code: >> >> UnicodeDecodeError('utf-8', b'\xb6\xe3\xed\xf9\xf3\xf4\xef >> >> \xfc\xed\xef\xec\xe1 \xf3\xf5\xf3\xf4\xde\xec\xe1\xf4\xef\xf2', 0, 1, >> >> 'invalid start byte') >> >> >> >> >

Re: Encapsulation unpythonic?

2013-09-01 Thread Steven D'Aprano
cally* correct that Python has getters and setters under the hood, that's not quite what the discussion here is about. But I'm sure you realise that :-) -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Encapsulation unpythonic?

2013-09-01 Thread Steven D'Aprano
treats it as a convention. (At least for pure-Python code.) But notice that they are differences of degree, not kind. Java encourages information hiding in classes, but does not prohibit you from making members public, and using reflection you can break into classes and get access to anything; Python allows information hiding, but trusts the programmer to honour "private" names, and reflection is such a fundamental part of Python that we don't even call it that. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: semicolon at end of python's statements

2013-09-02 Thread Steven D'Aprano
On Sun, 01 Sep 2013 21:58:15 +0200, Antoon Pardon wrote: > Op 31-08-13 02:09, Steven D'Aprano schreef: >> Adding a fourth option: >> >> for spam in sequence if predicate(spam): >> process(spam) >> >> saves absolutely nothing except a line and

Re: A Pragmatic Case for Static Typing

2013-09-02 Thread Steven D'Aprano
een distant parts of your code. If func() changes from returning int to MyInt, everything that calls func now needs to be modified to accept MyInt, no matter how similar MyInt is to int. You have to make changes just to satisfy the compiler. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: semicolon at end of python's statements

2013-09-02 Thread Steven D'Aprano
27;t completely gone. > we wouldn't now be > discussing the pro and cons of loop comprehension because we could have > just layed out the code so that it illustrated our intention of a loop > comprehension. Which the current syntax is perfectly fine at doing. -- Steven -- ht

Re: semicolon at end of python's statements

2013-09-02 Thread Steven D'Aprano
On Mon, 02 Sep 2013 20:14:40 +1000, Chris Angelico wrote: > On Mon, Sep 2, 2013 at 7:52 PM, Steven D'Aprano > wrote: >> Instead, we would have spent 100 times as much time and energy debating >> the One True Indentation Scheme, akin to the brace wars that went on

Re: user interfaces python3.x

2013-09-02 Thread Steven D'Aprano
google that for you: https://duckduckgo.com/?q=kivy+tutorial Are those links satisfactory? -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: How to split with "\" character, and licence copyleft mirror of ©

2013-09-02 Thread Steven D'Aprano
= r'\'[:] # and more ^ SyntaxError: EOL while scanning string literal So the real bug is with the parser. It is likely that nobody noticed this bug in the first place because the current behaviour doesn't matter for regexes, which is the primary purpose of raw strings. You can't end a regex with an unescaped backslash, so r'abc\'' is an illegal regex and it doesn't matter if you can't create it. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: user interfaces python3.x

2013-09-02 Thread Steven D'Aprano
, you would have found the tutorials you were asking about. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: How to execute command on remote windows machine

2013-09-02 Thread Steven D'Aprano
RPC, imagine if random people on the internet could shut down whichever processes they like on your machine. But having said that, there are a number of excellent RPC libraries for Python. Here are two I have (briefly) used: http://pythonhosted.org/Pyro4/ https://pypi.python.org/pypi/rpyc --

Re: UnicodeDecodeError issue

2013-09-03 Thread Steven D'Aprano
ed the Greek alphabet, although now they use Cyrillic. Some Albanian dialects still use the Greek alphabet, as do a couple of Turkic languages from the Balkans. See the Wikipedia entry on the Greek alphabet for more. -- Steven -- https://mail.python.org/mailman/listinfo/python-list

Re: PyPi Module Removal

2013-09-03 Thread Steven D'Aprano
ems to be confusing ~1000 users a > month, while not providing any significant functionality. Ah, Unix users. Who else would imagine that the way to install something called "wxPython" was to use "install wx"? :-) -- Steven -- https://mail.python.org/mailman/listinfo/python-list

Re: how to detect comment in source code file ?

2013-09-04 Thread Steven D'Aprano
re strings it sees, so one can nest pseudo-comments like this: do_this() """ do_that() do_something() # Make the widget work correctly. ''' for x in range(5): do_something_else() ''' do_something_different() """ In the above, every

Re: Find out where a class is used throughout a program.

2013-09-04 Thread Steven D'Aprano
Mac system, you can use external tools. At the shell (not the Python shell, the operating system's shell) enter: cd directory/where/my/source/code/lives grep *.py MyClassName or similar. Windows may have a similar tool, but I don't know what it is. -- Steven -- https://mail.python.org/mailman/listinfo/python-list

Re: UnicodeDecodeError issue

2013-09-04 Thread Steven D'Aprano
thing about Python syntax, nor should it. Technically, it's not ASCII, since ASCII only knows about bytes \x00 through \x7F (decimal 0 through 127). That's why it isn't correct to describe Python bytes strings as "ASCII strings". They're byte strings that happen to be displayed as ASCII-plus-other-stuff. -- Steven -- https://mail.python.org/mailman/listinfo/python-list

Re: UnicodeDecodeError issue

2013-09-04 Thread Steven D'Aprano
On Thu, 05 Sep 2013 13:59:17 +1000, Chris Angelico wrote: > On Thu, Sep 5, 2013 at 1:07 PM, Steven D'Aprano > wrote: >> Technically, it's not ASCII, since ASCII only knows about bytes \x00 >> through \x7F (decimal 0 through 127). That's why it isn't correct

Re: Beginner's guide to Python

2013-09-05 Thread Steven D'Aprano
as much a valid way to use multiple cores as "use threads" might be in another language, and by some accounts, better than threads. Or you can use IronPython or Jython, neither of which have the GIL. Or use Stackless: http://entitycrisis.blogspot.com.au/2009/06/stackless-vs-gil-its-draw.html -- Steven -- https://mail.python.org/mailman/listinfo/python-list

Re: Cannot form correctly the FORM part of the header when sending mail

2013-09-05 Thread Steven D'Aprano
8 + (2 % 5) 10 Even though these examples are with ints, not strings, the precedence is the same. Go back to your code. Read your code. Does it look closer to this: 8 + 2 % 5 or this? (8 + 2) % 5 Can you solve this problem now? -- Steven -- https://mail.python.org/mailman/listinfo/python-list

Re: Importing Definitions

2013-09-05 Thread Steven D'Aprano
e your code confusing. Shame on you Chris :-) Don't teach newbies to set their head on fire before teaching them where the fire extinguisher is. Azureaus, don't use the form "from module import *" unless you really need to, and as a beginner, you almost never really need t

Re: Cannot form correctly the FORM part of the header when sending mail

2013-09-05 Thread Steven D'Aprano
@superhost.gr [~]# > > but all of the needed args are within MESSAGE. Cant it take it from > there? Obviously not. If it could, it would. -- Steven -- https://mail.python.org/mailman/listinfo/python-list

Re: Could someone please paraphrase this statement about variables and functions in Python?

2013-09-05 Thread Steven D'Aprano
ent set of local variables. > Even as a professional programmer, I'm not really able to follow this. > It seems self-contradictory, amgiguous, and incomplete. It's not really any of those things. I'd call it pretentious, unnecessarily jargon-filled for a tutorial, and (in the case of the call- by-value comment) not just unhelpful but actively harmful. -- Steven -- https://mail.python.org/mailman/listinfo/python-list

Re: Cannot form correctly the FORM part of the header when sending mail

2013-09-05 Thread Steven D'Aprano
On Thu, 05 Sep 2013 18:59:42 +0300, Ferrous Cranus wrote: > but tell me please mailx and senmail are 2 differnt MTAs or mailx makes > use of sendmail MTA? Nikos, I know you can write English better than that. Are you deliberately trying to look less intelligent? -- Steven --

Re: Newbie question related to Boolean in Python

2013-09-05 Thread Steven D'Aprano
he bear moves away from the door, and `bear_moved` will be set to True. At that point, the *entire* if...elif...else block is finished, execution will jump to the end of the loop, and the next loop will begin. The second time through the loop, the user is prompted for a command again. If the us

Re: PEP8 79 char max

2013-09-05 Thread Steven D'Aprano
eware: > You might actually learn something about advertising while you are there > also. :) I don't need to ask them for a business card, since I have a nice collection of them. Most of them have < 40 characters per line. A few have < 60 characters on the longest line. None of them come ev

Re: PEP8 79 char max

2013-09-05 Thread Steven D'Aprano
t out. How is an import that occurs when the code is *run* supposed to make a difference to the way the code is *written*? -- Steven -- https://mail.python.org/mailman/listinfo/python-list

Re: Chardet, file, ... and the Flexible String Representation

2013-09-06 Thread Steven D'Aprano
ot; possible coding schme. That at least is correct. > The Flexible String Representation has conceptually to face the same > problem. No it doesn't. -- Steven -- https://mail.python.org/mailman/listinfo/python-list

Re: how to trouble shoot - RuntimeError: Open Failed

2013-09-06 Thread Steven D'Aprano
. That will do to start. If you still need help, please copy and paste the entire traceback. Also, demonstrating a *minimal* amount of code that causes this error will help. Although this is written for Java programmers, the same principles apply to Python code too: http://sscce.org/ -- S

Confessions of a terrible programmer

2013-09-06 Thread Steven D'Aprano
Not specifically about Python, but still relevant: http://blog.kickin-the-darkness.com/2007/09/confessions-of-terrible-programmer.html -- Steven -- https://mail.python.org/mailman/listinfo/python-list

Re: Confessions of a terrible programmer

2013-09-06 Thread Steven D'Aprano
On Fri, 06 Sep 2013 13:17:20 -0400, Joel Goldstick wrote: > On Fri, Sep 6, 2013 at 12:56 PM, Steven D'Aprano > wrote: >> Not specifically about Python, but still relevant: >> >> http://blog.kickin-the-darkness.com/2007/09/confessions-of-terrible- programmer.html

Re: Can I trust downloading Python?

2013-09-08 Thread Steven D'Aprano
y.com/story/news/politics/2013/06/16/snowden-whistleblower-nsa-officials-roundtable/2428809/ And if you think it's just the NSA, you *really* haven't been paying attention. From 2005: http://www.noplacetohide.net/ -- Steven -- https://mail.python.org/mailman/listinfo/python-list

Re: Weighted choices

2013-09-09 Thread Steven D'Aprano
how small the weights are, and so the probability of getting set(apple, pear, banana, orange, kiwi) is exactly 1, even if there are ten million apples to choose from and only one orange. A more important question is, should the selection be done with or without replacement? That is, after selecting by chance an apple, does that mean there is one fewer apple to select next time, and hence the weight need to be slightly reduced? Or is the apple returned to the pool, and the weights remain unchanged? -- Steven -- https://mail.python.org/mailman/listinfo/python-list

Re: Can I trust downloading Python?

2013-09-09 Thread Steven D'Aprano
olved in building gcc, enough people have inspected each individual component that we can be reasonably confident that it is okay. > If you can't trust any code you didn't write yourself, You trust yourself? You sheeple! The truly cautious man doesn't even trust himself. You might be an unconscious sleeper agent. Haven't you watched The Running Man? (Ha ha only serious.) -- Steven -- https://mail.python.org/mailman/listinfo/python-list

Re: Monitor key presses in Python?

2013-09-09 Thread Steven D'Aprano
. > Also, is there a way to create a callback in Python? The answer to your question as you ask it is "Yes, naturally." Callback is short for *callback function* and describes the *purpose* of the function, not how you write it or what it does. But a better answer is, "A callback t

Re: Can I trust downloading Python?

2013-09-09 Thread Steven D'Aprano
orld. Stuxnet anyone? [1] I say "so-called", because far too often the people who are supposed to be upholding the law are actually breaking the law with impunity. -- Steven -- https://mail.python.org/mailman/listinfo/python-list

Re: Chardet, file, ... and the Flexible String Representation

2013-09-09 Thread Steven D'Aprano
ore memory than non-ASCII users. Even if it means everyone is worse off, he is utterly opposed to giving ASCII users any benefit. Of course, he neglects to consider that *every single Python user* is an ASCII user, since most strings in Python are pure ASCII. Names of builtins, standard l

Language design

2013-09-09 Thread Steven D'Aprano
hod resolution rules as regular methods, they bypass the instance and go straight to the type, at least for new-style classes. -- Steven -- https://mail.python.org/mailman/listinfo/python-list

Re: a gift function and a question

2013-09-10 Thread Steven D'Aprano
ntegerToPersian(number): """Convert positive integers to Persian. >>> integerToPersian(3455) '۳۴۵۵' Does not support negative numbers. """ digit_map = dict(zip('0123456789', '۰۱۲۳۴۵۶۷۸۹')) digit

Re: a gift function and a question

2013-09-10 Thread Steven D'Aprano
On Tue, 10 Sep 2013 07:01:20 +, Steven D'Aprano wrote: > On Tue, 10 Sep 2013 00:40:59 +0430, Mohsen Pahlevanzadeh wrote: >> My question is , do you have reverse of this function? >> persianToInteger? > > The Python built-in int function already supports that: >

Re: Can I trust downloading Python?

2013-09-10 Thread Steven D'Aprano
On Tue, 10 Sep 2013 10:45:16 +0100, Oscar Benjamin wrote: > On 10 September 2013 01:06, Steven D'Aprano > wrote: [rant about executing code over the internet] > You could have also mentioned pip/PyPI in that. 'pip install X' > downloads and runs arbitrary code fro

Re: Language design

2013-09-10 Thread Steven D'Aprano
y> open('aß', 'w').write("hello\n") 6 py> open(b'a\xc3\x9f', 'r').read() 'hello\n' -- Steven -- https://mail.python.org/mailman/listinfo/python-list

Re: Dealing with Lists

2013-09-10 Thread Steven D'Aprano
print item which gives us this: py> print_nested_list(['head', 'neck', 'arms', 'legs']) head |_> neck |_> arms |_> legs as requested. -- Steven -- https://mail.python.org/mailman/listinfo/python-list

Re: Dealing with Lists

2013-09-10 Thread Steven D'Aprano
On Wed, 11 Sep 2013 02:24:44 +, Dave Angel wrote: > On 10/9/2013 22:14, Steven D'Aprano wrote: > >> On Tue, 10 Sep 2013 14:08:45 -0700, stas poritskiy wrote: >> >>> Greetings to all! >>> >>> i ran into a little logic problem and tryin

Re: Language design

2013-09-11 Thread Steven D'Aprano
should be direct, hashable values, > not hidden in a variable name. I don't even understand what you are talking about here. "[reference] variables"? What does that mean? Dict keys are direct, hashable values, and I have no idea what you mean by "hidden in a variable name". -- Steven -- https://mail.python.org/mailman/listinfo/python-list

Re: Language design

2013-09-11 Thread Steven D'Aprano
operator protocol yourself. Namely, if the operator special method returns NotImplemented, you're supposed to reverse the operands and try again. -- Steven -- https://mail.python.org/mailman/listinfo/python-list

Re: why syntax change in lambda

2013-09-11 Thread Steven D'Aprano
d), e): pass In Python 3, the parser appears to disallow any extra parentheses inside the parameter list, even if strictly speaking they don't do anything: py> def f(a, b, (c), d, e): File "", line 1 def f(a, b, (c), d, e): ^ SyntaxError: invalid syntax -- Steven -- https://mail.python.org/mailman/listinfo/python-list

Re: Language design

2013-09-11 Thread Steven D'Aprano
s at least plausible that the file contains text. Whether that text is meaningful is another story. You might wish to allow Cf and possibly even Co (format and private-use), depending on the application. -- Steven -- https://mail.python.org/mailman/listinfo/python-list

Re: Language design

2013-09-11 Thread Steven D'Aprano
On Wed, 11 Sep 2013 22:43:20 -0400, Roy Smith wrote: > In article <[email protected]>, > Steven D'Aprano wrote: > >> just 3 bits if you only cared about decimal digits. > > That's a neat trick. Well obviously it'

Re: Language design

2013-09-11 Thread Steven D'Aprano
set is by calling set(), the same >> as str(), int(), list(), float(), tuple(), dict(), ... > > Blah, blah. Let me know when you got everyone migrated over to > Python.v3. What does this have to do with Python 3? It works fine in Python 2. >>> 4?) It allowed >>>

Re: Stripping characters from windows clipboard with win32clipboard from excel

2013-09-12 Thread Steven D'Aprano
the letters, use 'utf-16le'. The existence of three oh-so-very-slightly different versions of UTF-16 is why it is a sub-optimal encoding, and it is oh-so-bloody-typical that Microsoft screwed it up for everyone by picking it as their default implementation. If they had sensibly used UTF-8, you wouldn't be having this problem. Of course, it is possible I've misdiagnosed your problem. I've had to guess a lot because you didn't show us what you actually did to get the results you say you got. -- Steven -- https://mail.python.org/mailman/listinfo/python-list

Re: Language design

2013-09-12 Thread Steven D'Aprano
s higher priority than dicts, but frankly I doubt it. It's much more common to want an empty dict than an empty set, at least in my experience. >>>> And the obvious way to form an empty set is by calling set(), the >>>> same as str(), int(), list(), float(), tuple(), dict(), ... >>> >>> Blah, blah. Let me know when you got everyone migrated over to >>> Python.v3. >> >> What does this have to do with Python 3? It works fine in Python 2. > > I mean, you're suggestions are coming from a "believer", not someone > wanting to understand the limitations of python or whether v3 has > succeeded at achieving its potential. "not someone wanting to understand the limitations of python..." -- are you aware that I started this thread? -- Steven -- https://mail.python.org/mailman/listinfo/python-list

Re: Language design

2013-09-13 Thread Steven D'Aprano
On Fri, 13 Sep 2013 09:04:06 +0200, Antoon Pardon wrote: > Op 10-09-13 12:20, Chris Angelico schreef: >> On Tue, Sep 10, 2013 at 4:09 PM, Steven D'Aprano >> wrote: >>> What design mistakes, traps or gotchas do you think Python has? >>> Gotchas are not nece

Re: Python GUI?

2013-09-13 Thread Steven D'Aprano
programming and find > something else to do with my life. What on earth are you talking about? If you like cutting trees down with an axe, the existence of chainsaws doesn't stop you from still using an axe. If you don't like GUI app builders, don't use one. -- Steven -- ht

Re: new to python

2013-09-13 Thread Steven D'Aprano
of the code is a bit old and not necessarily "best practice" any more, but it is still good code. -- Steven -- https://mail.python.org/mailman/listinfo/python-list

Re: PEP-442 - Python 3.4 and finalizations (__del__)

2013-09-14 Thread Steven D'Aprano
from B()') ... >>> b = B() In A.__init__() In B.__init__() >>> del b >>> >>> >>> import gc >>> gc.collect() Goodbye from B() Goodbye from A() 4 >>> Does that answer your question? -- Steven -- https://mail.python.org/mailman/listinfo/python-list

Re: Tryign to send mail via a python script by using the local MTA

2013-09-15 Thread Steven D'Aprano
Exception as e: > print( "sendmail => ", date, repr( sys.exc_info() ) ) > > sys.exit(0) -- Steven -- https://mail.python.org/mailman/listinfo/python-list

Re: import problem

2013-09-15 Thread Steven D'Aprano
is small, but one day it will be big and will need to be a package with dozens of modules", that doesn't matter. Don't write the code you think you will need in five years. Write the code you need now. Google "YAGNI" for more. I am sorry that I cannot just give you a simple one-line fix for your error. As far as I can see, the fix is to re-design the package so that it is flatter, with fewer imports, and avoid the recursive import. Good luck! -- Steven -- https://mail.python.org/mailman/listinfo/python-list

Re: Tryign to send mail via a python script by using the local MTA

2013-09-16 Thread Steven D'Aprano
ame or the real ip this way since both > values will be not true. Are you planning on sending spam? Or some other criminal activity? I cannot fathom for the life of me a legitimate reason for your website to use a fake IP address and hostname when sending email. -- Steven -- https://mail.

Re: How do I calculate a mean with python?

2013-09-16 Thread Steven D'Aprano
esum = sum(List) once, and thecount = len(List) once. Once you've done that, please write back with your new code, because I think there will be some more improvements to be made. -- Steven -- https://mail.python.org/mailman/listinfo/python-list

Re: Qt connect and first connect or unicode

2013-09-17 Thread Steven D'Aprano
27;), 'bought_price': 23} What result where you expecting? If I remember correctly, Qt strings are mutable unicode strings, so 'name' is associated with an empty Qt string. If they are mutable, that means that once the dict is set: {'name': QString(u'contents of text field'), ...} if the text field changes, so will the string. Is that what is happening? (Or perhaps I have mis-remembered about Qt strings.) You have two callbacks that appear to set the "name" key in the dict. Perhaps one of them is setting it to an empty value. -- Steven -- https://mail.python.org/mailman/listinfo/python-list

Re: Having both if() and for() statements in one liner

2013-09-17 Thread Steven D'Aprano
On Tue, 17 Sep 2013 18:54:51 +, Dave Angel wrote: > for times in range(0, 5 if person=="George" else 0): Oh that is evil. Truly evil. Thank you, I will treasure that piece of code forever. -- Steven -- https://mail.python.org/mailman/listinfo/python-list

<    66   67   68   69   70   71   72   73   74   75   >