Re: [Python-ideas] Unicode stdin/stdout

2013-11-18 Thread random832
On Mon, Nov 18, 2013, at 7:33, Robin Becker wrote: > UTF-8 stuff This doesn't really solve the issue I was referring to, which is that windows _console_ (i.e. not redirected file or pipe) I/O can only support unicode via wide character (UTF-16) I/O with a special function, not via using byte-based

Unicode stdin/stdout (was: Re: python 3.3 repr)

2013-11-15 Thread random832
Of course, the real solution to this issue is to replace sys.stdout on windows with an object that can handle Unicode directly with the WriteConsoleW function - the problem there is that it will break code that expects to be able to use sys.stdout.buffer for binary I/O. I also wasn't able to get th

Re: 'isimmutable' and 'ImmutableNester'

2013-11-12 Thread random832
On Tue, Nov 12, 2013, at 4:39, Frank-Rene Schäfer wrote: > > All you've done is proven that you can subvert things. By fiddling > > with __hash__, __eq__, and so on, you can make sets and dicts behave > > very oddly. Means nothing. > > To the contrary, it means everything about what 'isimmutable'

Re: 'isimmutable' and 'ImmutableNester'

2013-11-11 Thread random832
> A built-in function 'isimmutable()' shall tell efficiently whether the > object > of concern is mutable or not. What's the benefit over attempting to hash() the object? copy.deepcopy already has special case for int, string, and tuples (including tuples that do and do not have mutable members)

Re: [Python-ideas] os.path.join

2013-11-04 Thread random832
On Mon, Nov 4, 2013, at 11:07, Chris Angelico wrote: > Then os.path.join is probably the wrong tool for the job. Do you want > to collapse "/foo/bar" + "../quux" into "/foo/quux"? That rewrites the > first. If not, don't use a function that does that. Try simple string > concatenation instead. >>>

Re: getpeername() on stdin?

2013-11-01 Thread random832
On Thu, Oct 31, 2013, at 21:12, Nobody wrote: > On Thu, 31 Oct 2013 12:16:23 -0400, Roy Smith wrote: > > > I want to do getpeername() on stdin. I know I can do this by wrapping a > > socket object around stdin, with > > > > s = socket.fromfd(sys.stdin.fileno(), family, type) > > > > but that re

Re: Python3 doc, operator reflection

2013-10-28 Thread random832
On Mon, Oct 28, 2013, at 8:00, Johannes Bauer wrote: > Hi group, > > in http://docs.python.org/3/reference/datamodel.html#customization the > doc reads: > > > There are no swapped-argument versions of these methods (to be used when > > the left argument does not support the operation but the r

Re: Reading From stdin After Command Line Redirection

2013-10-23 Thread random832
On Wed, Oct 23, 2013, at 16:52, Chris Angelico wrote: > There are times when this is correct behaviour - like asking for > passwords (SSH and sudo work like this). Less (or pagers generally, or an interactive text editor that allows creating a file from standard input) would be another example of

Re: python -c commands on windows.

2013-10-21 Thread random832
On Mon, Oct 21, 2013, at 16:47, Terry Reedy wrote: > Manual says "-c > Execute the Python code in command. command can be one or more > statements separated by newlines, with significant leading whitespace as > in normal module code." > > In Windows Command Prompt I get: > C:\Programs\Pyth

Re: Sexism in the Ruby community: how does the Python community manage it?

2013-10-16 Thread random832
On Wed, Oct 16, 2013, at 23:13, Owen Jacobson wrote: > > * therapist - yeah, It passes as a double meaning - but still. Or a single meaning. Who's to say the person who wrote the module even had any idea it could be read otherwise? > > * shag Something to do with carpet? > > * db_nazi See belo

Re: Code golf challenge: XKCD 936 passwords

2013-10-09 Thread random832
On Tue, Oct 8, 2013, at 18:27, Rob Day wrote: > On 08/10/13 07:17, Chris Angelico wrote: > > Who's up for some fun? Implement an XKCD-936-compliant password > > generator in Python 3, in less code than this: > > > > print(*__import__("random").sample(open("/usr/share/dict/words").read().split("\n")

Re: converting letters to numbers

2013-10-08 Thread random832
On Tue, Oct 8, 2013, at 11:44, kjaku...@gmail.com wrote: > def add(c1, c2): > ans = '' This only makes sense if your answer is going to be multiple characters. > for i in c1 + c2: This line concatenates the strings together. > ans += chrord(i)-65))%26) + 65) The way you are

Re: Code golf challenge: XKCD 936 passwords

2013-10-08 Thread random832
On Tue, Oct 8, 2013, at 2:45, sprucebond...@gmail.com wrote: > On Monday, October 7, 2013 8:17:21 PM UTC-10, Chris Angelico wrote: > > print(*__import__("random").sample(open("/usr/share/dict/words").read().split("\n"),4)) > > # 87 > > import random as r > print(*r.sample(open("/usr/share/dict/wo

Re: converting letters to numbers

2013-10-08 Thread random832
On Tue, Oct 8, 2013, at 10:28, kjaku...@gmail.com wrote: > I have to define a function add(c1, c2), where c1 and c2 are capital > letters; the return value should be the sum (obtained by converting the > letters to numbers, adding mod 26, then converting back to a capital > letter). > > All I hav

Re: Tail recursion to while iteration in 2 easy steps

2013-10-07 Thread random832
On Sat, Oct 5, 2013, at 3:39, Antoon Pardon wrote: > What does this mean? > > Does it mean that a naive implementation would arbitrarily mess up > stack traces and he wasn't interested in investigating more > sophisticated implementations? > > Does it mean he just didn't like the idea a stack tra

Re: Tail recursion to while iteration in 2 easy steps

2013-10-07 Thread random832
On Mon, Oct 7, 2013, at 13:15, Alain Ketterlin wrote: > That's fine. My point was: you can't at the same time have full > dynamicity *and* procedural optimizations (like tail call opt). > Everybody should be clear about the trade-off. Let's be clear about what optimizations we are talking about. T

Re: Tail recursion to while iteration in 2 easy steps

2013-10-03 Thread random832
On Wed, Oct 2, 2013, at 22:34, Steven D'Aprano wrote: > You are both assuming that LOAD_CONST will re-use the same tuple > (1, 2, 3) in multiple places. But that's not the case, as a simple test > will show you: >>> def f(): ... return (1, 2, 3) >>> f() is f() True It does, in fact, re-use it

Re: Tail recursion to while iteration in 2 easy steps

2013-10-03 Thread random832
On Wed, Oct 2, 2013, at 21:46, MRAB wrote: > > The difference is that a tuple can be reused, so it makes sense for the > > comiler to produce it as a const. (Much like the interning of small > > integers) The list, however, would always have to be copied from the > > compile-time object. So that

Re: Tail recursion to while iteration in 2 easy steps

2013-10-03 Thread random832
On Wed, Oct 2, 2013, at 17:33, Terry Reedy wrote: > 5. Conversion of apparent recursion to iteration assumes that the > function really is intended to be recursive. This assumption is the > basis for replacing the recursive call with assignment and an implied > internal goto. The programmer can

Re: Tail recursion to while iteration in 2 easy steps

2013-10-02 Thread random832
On Wed, Oct 2, 2013, at 9:32, Steven D'Aprano wrote: > Python is not as aggressively functional as (say) Haskell, but it is > surely an exaggeration to suggest that the failure to include tail call > optimization means that Python "rejects" functional programming styles. > You can still write yo

Re: Tail recursion to while iteration in 2 easy steps

2013-10-02 Thread random832
On Tue, Oct 1, 2013, at 17:30, Terry Reedy wrote: > Part of the reason that Python does not do tail call optimization is > that turning tail recursion into while iteration is almost trivial, once > you know the secret of the two easy steps. Here it is. That should be a reason it _does_ do it - s

Re: Help with python functions?

2013-10-01 Thread random832
On Tue, Oct 1, 2013, at 13:53, kjaku...@gmail.com wrote: > I ended up with these. I know they're only like half right... > I was wondering if any of you had to do this, what would you end up with? > > # Question 1.a > def temp(T, from_unit, to_unit): Assuming this is temperature conversion. You s

Re: class implementation

2013-09-30 Thread random832
On Mon, Sep 30, 2013, at 17:28, Ned Batchelder wrote: > On 9/30/13 3:34 PM, Dave Angel wrote: > > Python doesn't actually have variables, but the things it documents as > > variables are local names within a method. Those are not visible > > outside of the method, regardless of whether you're in a

Bug tracker breaks when given a username with an uppercase letter

2013-09-19 Thread random832
Registration appears to succeed, but does not allow login, and I can't tell if email confirmation worked or not. I was able to register by changing it to lowercase, but I had to guess what was happening. -- https://mail.python.org/mailman/listinfo/python-list

Re: Stripping characters from windows clipboard with win32clipboard from excel

2013-09-19 Thread random832
On Wed, Sep 18, 2013, at 16:13, Dave Angel wrote: > So is the bug in Excel, in Windows, or in the Python library? Somebody > is falling down on the job; if Windows defines the string as ending at > the first null, then the Python interface should use that when defining > the text defined with CF_

Re: Stripping characters from windows clipboard with win32clipboard from excel

2013-09-18 Thread random832
On Fri, Sep 13, 2013, at 12:09, random...@fastmail.us wrote: > Anyway, to match behavior found in other applications when pasting from > the clipboard, I would suggest using: > > if s.contains('\0'): s = s[:s.index('\0')] > > Which will also remove non-null bytes after the first null (but if the

Re: Is %z broken for return values of time.gmtime()?

2013-09-17 Thread random832
On Mon, Sep 16, 2013, at 16:55, Michael Schwarz wrote: > On 2013-W38-1, at 19:56, random...@fastmail.us wrote: > > > On Mon, Sep 16, 2013, at 9:15, Michael Schwarz wrote: > >> According to the documentation of time.gmtime(), it returns a struct_time > >> in UTC, but %z is replaced by +0100, which

Re: Is %z broken for return values of time.gmtime()?

2013-09-16 Thread random832
On Mon, Sep 16, 2013, at 9:15, Michael Schwarz wrote: > According to the documentation of time.gmtime(), it returns a struct_time > in UTC, but %z is replaced by +0100, which is the UTC offset of my OS’s > time zone without DST, but DST is currently in effect here (but was not > at the timestamp pa

Re: Stripping characters from windows clipboard with win32clipboard from excel

2013-09-13 Thread random832
On Fri, Sep 13, 2013, at 10:38, stephen.bou...@gmail.com wrote: > > Hm, that gives me a "Type str doesn't support the buffer API" message. > > Aha, I need to use str(s, encoding='utf8').rstrip('\0'). It's not a solution to your problem, but why aren't you using CF_UNICODETEXT, particularly if you

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

2013-09-10 Thread random832
On Mon, Sep 9, 2013, at 10:28, wxjmfa...@gmail.com wrote: *time performance differences* > > Comment: Such differences never happen with utf. Why is this bad? Keeping in mind that otherwise they would all be almost as slow as the UCS-4 case. > >>> sys.getsizeof('a') > 26 > >>> sys.getsizeof('€')

Re: a gift function and a question

2013-09-10 Thread random832
On Tue, Sep 10, 2013, at 3:01, Steven D'Aprano wrote: > def integerToPersian(number): > """Convert positive integers to Persian. > > >>> integerToPersian(3455) > '۳۴۵۵' > > Does not support negative numbers. > """ > digit_map = dict(zip('0123456789', '۰۱۲۳۴۵۶۷۸۹')) > d

Re: a gift function and a question

2013-09-09 Thread random832
On Mon, Sep 9, 2013, at 16:10, Mohsen Pahlevanzadeh wrote: > My question is , do you have reverse of this function? persianToInteger? The int constructor is able to handle different forms of decimal numerals directly: >>> int('\u06f3\u06f4\u06f5\u06f5') 3455 -- https://mail.python.org/mailman/li

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

2013-09-09 Thread random832
On Mon, Sep 9, 2013, at 15:03, Ian Kelly wrote: > Do you mean that it breaks when overwriting Python string object buffers, > or when overwriting arbitrary C strings either received from C code or > created with create_unicode_buffer? > > If the former, I think that is to be expected since ctypes

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

2013-09-09 Thread random832
On Fri, Sep 6, 2013, at 13:04, Chris Angelico wrote: > On Sat, Sep 7, 2013 at 2:59 AM, wrote: > > Incidentally, how does all this interact with ctypes unicode_buffers, > > which slice as strings and must be UTF-16 on windows? This was fine > > pre-FSR when unicode objects were UTF-16, but I'm not

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

2013-09-06 Thread random832
On Fri, Sep 6, 2013, at 11:46, Piet van Oostrum wrote: > The FSR does not split unicode in chuncks. It does not create problems > and therefore it doesn't have to solve this. > > The FSR simply stores a Unicode string as an array[*] of ints (the > Unicode code points of the characters of the stri

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

2013-09-06 Thread random832
On Thu, Sep 5, 2013, at 23:33, Tim Roberts wrote: > random...@fastmail.us wrote: > > > >Of course, in 99% of situations where you can use a windows pathname in > >Python, you are free to use it with a forward slash instead of a > >backslash. > > This is actually worth repeating, because it's not w

Re: How to exit a cgi file after a download

2013-09-04 Thread random832
On Wed, Sep 4, 2013, at 12:49, Ferrous Cranus wrote: > Without closing it, the client can download > again and forever if they choose to because > the cgi window is open and the link is still > active. Why is this a problem? They usually won't want to, and if they do want to (for example if th

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

2013-09-03 Thread random832
On Tue, Sep 3, 2013, at 6:31, Tim Chase wrote: > I'd contend that the two primary purposes of raw strings (this is > starting to sound like a Spanish Inquisition sketch) are regexes and > DOS/Win32 file path literals. And I hit this trailing-backslash case > all the time, as Vim's path-completion

Re: Unable to redirect the subprocess CMD.exe to txt file. Please help !!!

2013-09-03 Thread random832
On Tue, Sep 3, 2013, at 9:54, Venkatesh wrote: > Hello comp.lang.python Group, > > I am trying to invoke a subprocess in Python as below > > import sys > import time > import os > import subprocess > DETACHED_PROCESS = 0x0008 > > path = r'C:\Windows\System32\cmd.exe /k ping www.google.com

Re: How to execute command on remote windows machine

2013-09-03 Thread random832
indows machine on remote > windows machine ? The taskkill command actually has an option for this: /S. I don't know what mechanism it uses or what you would have to do to give yourself permission to use it. -- Random832 -- https://mail.python.org/mailman/listinfo/python-list

Re: String splitting with exceptions

2013-08-28 Thread random832
On Wed, Aug 28, 2013, at 12:44, John Levine wrote: > I have a crufty old DNS provisioning system that I'm rewriting and I > hope improving in python. (It's based on tinydns if you know what > that is.) > > The record formats are, in the worst case, like this: > > foo.[DOM]::[IP6::4361:6368:6574]

Re: python3 integer division debugging

2013-08-28 Thread random832
On Wed, Aug 28, 2013, at 11:15, Neal Becker wrote: > The change in integer division seems to be the most insidious source of > silent > errors in porting code from python2 - since it changes the behaviour or > valid > code silently. > > I wish the interpreter had an instrumented mode to detect a

Re: How come StopIteration.__base__ is not BaseException?

2013-08-26 Thread random832
On Mon, Aug 26, 2013, at 15:37, Marco Buttu wrote: > Since StopIteration is not an error, how come does it inherit directly > from Exception and not from BaseException? The reason KeyboardInterrupt and SystemExit inherit from BaseException is because you often want them to escape (allowing the pr

Re: Getting request's source site

2013-08-26 Thread random832
On Mon, Aug 26, 2013, at 11:03, Guy Tamir wrote: > Thanks for reply, > In what cases will i have this header? In practice, you'll usually have it, except in cases where the user has bookmarked your site, typed/pasted the URL directly, had it opened by an external program, or taken action to block

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

2013-08-24 Thread random832
On Sat, Aug 24, 2013, at 12:47, David M. Cotter wrote: > > What _are_ you using? > i have scripts in a file, that i am invoking into my embedded python > within a C++ program. there is no terminal involved. the "print" > statement has been redirected (via sys.stdout) to my custom print class, >

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

2013-08-24 Thread random832
On Sat, Aug 24, 2013, at 2:45, David M. Cotter wrote: > > you need to use u" ... " delimiters for Unicode, otherwise the results you > > get are completely arbitrary and depend on the encoding of your terminal. > okay, well, i'm on a mac, and not using "terminal" at all. but if i > were, it woul

Re: Running a command line program and reading the result as it runs

2013-08-23 Thread random832
On Fri, Aug 23, 2013, at 7:14, Peter Otten wrote: > The following works on my linux system: > > instream = iter(p.stdout.readline, "") > > for line in instream: > print line.rstrip() > > I don't have Windows available to test, but if it works there, too, the > problem is the interna

Re: Basic Python Query

2013-08-22 Thread random832
On Thu, Aug 22, 2013, at 18:22, Dennis Lee Bieber wrote: > Well... The main thing to understand is that this particular "forum" is > NOT JUST a mailing-list. It is cross-linked with the Usenet > comp.lang.python news-group (and that, unfortunately, is cross-linked to > Google-Groups). And to

Re: Basic Python Query

2013-08-22 Thread random832
On Thu, Aug 22, 2013, at 9:45, Ned Batchelder wrote: > So that I understand what's going on, what's the bad thing that happens > with a multi-part message? I would have thought that mail readers would > choose the preferred part, or is it something to do with the message > quoting? The bad thi

Re: Raw_input with readline in a daemon thread makes terminal text disappear

2013-08-21 Thread random832
On Wed, Aug 21, 2013, at 12:42, David M. Welch wrote: > Hi all, > > This is an old thread, but I'm having the same behavior in my terminal > when > I run some code but kill the process in the terminal (Ctrl-C). The code > has > two prime suspects (from a simple google search): > 1. Creates ssh p

Re: PEPs should be included with the documentation download

2013-08-21 Thread random832
On Wed, Aug 21, 2013, at 14:15, Jerry Hill wrote: > Personally, the only PEPs I've used as reference material as PEP 8 > (the Python Style Guide), and PEP 249 (the Python Database API > Specification v2.0). If I recall correctly, one of the database > adapters I used basically said that they were

Re: PEPs should be included with the documentation download

2013-08-21 Thread random832
On Wed, Aug 21, 2013, at 13:32, Chris Angelico wrote: > On Wed, Aug 21, 2013 at 3:14 PM, Aseem Bansal > wrote: > > Currently the documentation download includes a lot of things but PEPs are > > not its part. I wanted to suggest that PEPs should be included in the > > download. They are very much

Re: Encapsulation unpythonic?

2013-08-21 Thread random832
to be notified when its name changes, and so have a name property. The subclass may want to use a variable called _name for some other purpose. (maybe "name" isn't the best example). Examples often look pathological when you simplify out the bit that makes them make sense. -- Random8

Re: How to I do this in Python ?

2013-08-16 Thread random832
On Fri, Aug 16, 2013, at 7:47, Roy Smith wrote: > There is no need to shell out to dd just to do this. All dd is doing > for you is seeking to the offset you specify and closing the file. You > can do that entirely in Python code. > > http://docs.python.org/2.7/library/stdtypes.html#file.seek

Re: .split() Qeustion

2013-08-14 Thread random832
On Wed, Aug 14, 2013, at 10:32, wxjmfa...@gmail.com wrote: > I'm always and still be suprised by the number of hard coded > '\n' one can find in Python code when the portable (here > win) > > >>> os.linesep > '\r\n' > > exists. Because high-level code isn't supposed to use the os module directly

Re: back with more issues

2013-08-12 Thread random832
On Mon, Aug 12, 2013, at 10:56, Rotwang wrote: > No! A function should have *four* well-defined pieces: what are its > parameters, what does it do, what are its side-effects, what does it > return, and an almost fanatical devotion to the Pope [etc.] To be fair, I can't think of what "what does i

Re: Python3 Multiprocessing

2013-08-09 Thread random832
On Fri, Aug 9, 2013, at 16:43, Devyn Collier Johnson wrote: > Thanks MRAB! That is easy. I always (incorrectly) thought the join() > command got two threads and made them one. I did not know it made the > script wait for the threads. What you're missing is the fact that the main thread [i.e. the

<    3   4   5   6   7   8