Re: Parsing a dictionary from a format string

2011-06-20 Thread Hans Mulder
On 20/06/11 20:14:46, Tim Johnson wrote: Currently using python 2.6, but am serving some systems that have older versions of python (no earlier than. Question 1: With what version of python was str.format() first implemented? That was 2.6, according to the online docs. Take a look at the

Re: search through this list's email archives

2011-06-23 Thread Hans Mulder
On 23/06/11 18:11:32, Cathy James wrote: I looked through this forum's archives, but I can't find a way to search for a topic through the archive. Am I missing something? One way to search the past contributions to this forum is to go to http://groups.google.com/advanced_search and specify

Re: all() is slow?

2011-11-09 Thread Hans Mulder
On 9/11/11 02:30:48, Chris Rebert wrote: Burn him! Witch! Witch! Burn him! His code turned me into a newt! -- Sent nailed to a coconut carried by swallow. Is that a European swallow or an African swallow? -- HansM -- http://mail.python.org/mailman/listinfo/python-list

Re: How to insert my own module in front of site eggs?

2011-11-18 Thread Hans Mulder
On 18/11/11 03:58:46, alex23 wrote: On Nov 18, 11:36 am, Roy Smithr...@panix.com wrote: What if the first import of a module is happening inside some code you don't have access to? No import will happen until you import something. That would be the case if you use the '-S' command line

Re: Reading twice from STDIN

2011-12-01 Thread Hans Mulder
On 2/12/11 03:46:10, Dan Stromberg wrote: You can read piped data from sys.stdin normally. Then if you want something from the user, at least on most *ix's, you would open /dev/tty and get user input from there. 'Not sure about OS/X. Reading from /dev/tty works fine on OS/X. -- HansM --

Re: Reading twice from STDIN

2011-12-02 Thread Hans Mulder
On 2/12/11 10:09:17, janedenone wrote: I had tried sys.stdin = open('/dev/tty', 'r') That seems to work for me. This code: import sys if sys.version_info.major == 2: input = raw_input for tp in enumerate(sys.stdin): print(%d: %s % tp) sys.stdin = open('/dev/tty', 'r') answer =

Re: Single key press

2011-12-06 Thread Hans Mulder
On 6/12/11 09:48:39, Steven D'Aprano wrote: On Tue, 06 Dec 2011 10:19:55 +0430, Sergi Pasoev wrote: Hi. I wonder if it is realistic to get a single key press in Python without ncurses or any similar library. In single key press I mean something like j and k in Gnu less program, you press the

Re: Obtaining user information

2011-12-09 Thread Hans Mulder
On 10/12/11 02:44:48, Tim Chase wrote: Currently I can get the currently-logged-in-userid via getpass.getuser() which would yield something like tchase. Is there a cross-platform way to get the full username (such as from the GECOS field of /etc/passed or via something like NetUserGetInfo on

Re: Elementwise -//- first release -//- Element-wise (vectorized) function, method and operator support for iterables in python.

2011-12-21 Thread Hans Mulder
On 21/12/11 01:03:26, Ian Kelly wrote: As type conversion functions, bool(x) and int(x) should *always* return bools and ints respectively (or raise an exception), no matter what you pass in for x. That doesn't always happen in 2.x: type(int(1e42)) type 'long' This was fixed in 3.0. --

Re: Why does this launch an infinite loop of new processes?

2011-12-22 Thread Hans Mulder
On 21/12/11 21:11:03, Andrew Berg wrote: On 12/21/2011 1:29 PM, Ethan Furman wrote: Anything that runs at import time should be protected by the `if __name__ == '__main__'` idiom as the children will import the __main__ module. So the child imports the parent and runs the spawn code again?

Re: Pythonification of the asterisk-based collection packing/unpacking syntax

2011-12-22 Thread Hans Mulder
On 22/12/11 14:12:57, Steven D'Aprano wrote: On Thu, 22 Dec 2011 06:49:16 -0500, Neal Becker wrote: I agree with the OP that the current syntax is confusing. The issue is, the meaning of * is context-dependent. Here you are complaining about an operator being confusing because it is

Re: Installing pypi package twice

2012-02-01 Thread Hans Mulder
On 1/02/12 07:04:31, Jason Friedman wrote: My system's default python is 2.6.5. I have also installed python3.2 at /opt/python. I installed a pypi package for 2.6.5 with: $ tar xzf package.tar.gz $ cd package $ python setup.py build $ sudo python setup.py install How can I also install this

Re: Queue cleanup

2010-08-29 Thread Hans Mulder
Steven D'Aprano wrote: On Sat, 28 Aug 2010 00:33:10 -0700, Paul Rubin wrote: If you drop the last reference to a complex structure, it could take quite a long time to free all the components. By contrast there are provably real-time tracing gc schemes, including some parallelizeable ones.

Re: Cross Compiling Python for ARM

2010-09-15 Thread Hans Mulder
Thomas Jollans wrote: On Tuesday 14 September 2010, it occurred to Neil Benn to exclaim: # ./python -sh: ./python: not found I'm guessing either there is no file ./python, or /bin/sh is fundamentally broken. or ./python is a symlink to a file that does not exist, or ./python is a

Re: About __class__ of an int literal

2010-09-28 Thread Hans Mulder
Tim Golden wrote: On 28/09/2010 10:27, AlexWalk wrote: In python 3.1.2(I'm using windows edition, 32bit), accessing __class__ of an int literal will raise a SyntaxException, while other literals will not. For example. 1.__class__ is an error, while 1.1.__class__ runs ok. I searched the

Re: Popen Question

2010-11-08 Thread Hans Mulder
Ian wrote: On Nov 8, 2:43 am, m...@distorted.org.uk (Mark Wooding) wrote: I don’t know what happens to the extra arguments, but they just seem to be ignored if -c is specified. The argument to -c is taken as a shell script; the remaining arguments are made available as positional parameters to

Re: Wait for a keypress before continuing?

2011-08-17 Thread Hans Mulder
On 17/08/11 10:03:00, peter wrote: Is there an equivalent to msvcrt for Linux users? I haven't found one, and have resorted to some very clumsy code which turns off keyboard excho then reads stdin. Seems such an obvious thing to want to do I am surprised there is not a standard library module

Re: relative speed of incremention syntaxes (or i=i+1 VS i+=1)

2011-08-21 Thread Hans Mulder
On 21/08/11 19:14:19, Irmen de Jong wrote: What the precise difference (semantics and speed) is between the BINARY_ADD and INPLACE_ADD opcodes, I dunno. Look in the Python source code or maybe someone knows it from memory :-) There is a clear difference in semantics: BINARY_ADD always

Re: how to format long if conditions

2011-08-27 Thread Hans Mulder
On 27/08/11 09:08:20, Arnaud Delobelle wrote: I'm wondering what advice you have about formatting if statements with long conditions (I always format my code to80 colums) Here's an example taken from something I'm writing at the moment and how I've formatted it: if (isinstance(left,

Re: how to format long if conditions

2011-08-27 Thread Hans Mulder
On 27/08/11 11:05:25, Steven D'Aprano wrote: Hans Mulder wrote: [...] It may look ugly, but it's very clear where the condition part ends and the 'then' part begins. Immediately after the colon, surely? On the next line, actually :-) The point is, that this layout makes it very clear

Re: how to format long if conditions

2011-08-27 Thread Hans Mulder
On 27/08/11 17:16:51, Colin J. Williams wrote: What about: cond= isinstance(left, PyCompare) and isinstance(right, PyCompare) and left.complist[-1] is right.complist[0] py_and= PyCompare(left.complist + right.complist[1:])if cond else: py_and = PyBooleanAnd(left, right) Colin

Re: killing a script

2011-08-30 Thread Hans Mulder
On 30/08/11 06:13:41, Steven D'Aprano wrote: On Tue, 30 Aug 2011 08:53 am Arnaud Delobelle wrote: [...] Yes, but if I am not mistaken, that will require me to put a line or two after each os.system call. That's almost like whack-a-mole at the code level rather than the Control-C level. OK, not

Re: Can't use subprocess.Popen() after os.chroot() - why?

2011-09-04 Thread Hans Mulder
On 4/09/11 17:25:48, Alain Ketterlin wrote: Erikerik.william...@gmail.com writes: import os from subprocess import Popen, PIPE os.chroot(/tmp/my_chroot) p = Popen(/bin/date, stdin=PIPE, stdout=PIPE, stderr=PIPE) stdout_val, stderr_val = p.communicate() print stdout_val but the Popen call is

Re: One line command line filter

2011-09-06 Thread Hans Mulder
On 6/09/11 01:18:37, Steven D'Aprano wrote: Terry Reedy wrote: The doc says -ccommand Execute the Python code in command. command can be one or more statements separated by newlines, However, I have no idea how to put newlines into a command-line string. I imagine that it depends on the

Re: Python marks an instance of my class undefined

2011-09-06 Thread Hans Mulder
On 6/09/11 16:18:32, Laszlo Nagy wrote: On 2011-09-06 15:42, Kayode Odeyemi wrote: I was able to get this solved by calling class like this: from core.fleet import Fleet f = Fleet() Thanks to a thread from the list titled TypeError: 'module' object is not callable Or you can also do this:

Re: killing a script

2011-09-09 Thread Hans Mulder
On 9/09/11 11:07:24, Steven D'Aprano wrote: Sure enough, I now have to hit Ctrl-C repeatedly, once per invocation of script.py. While script.py is running, it receives the Ctrl-C, the calling process does not. You misinterpret what you are seeing: the calling process *does* receive the ctrl-C,

Re: Python without a tty

2011-09-29 Thread Hans Mulder
On 29/09/11 11:21:16, Steven D'Aprano wrote: I have a Python script which I would like to test without a tty attached to the process. I could run it as a cron job, but is there an easier way? There is module on Pypi called python-daemon; it implements PEP-3143. This module detaches the process

Re: Python without a tty

2011-09-29 Thread Hans Mulder
On 29/09/11 12:52:22, Steven D'Aprano wrote: [steve@sylar ~]$ python -c import sys,os; print os.isatty(sys.stdout.fileno()) True If I run the same Python command (without the setsid) as a cron job, I get False emailed to me. That's the effect I'm looking for. In that case, all you need to

Re: regexp compilation error

2011-09-30 Thread Hans Mulder
On 30/09/11 11:10:48, Ovidiu Deac wrote: I have the following regexp which fails to compile. Can somebody explain why? re.compile(r^(?: [^y]* )*, re.X) [...] sre_constants.error: nothing to repeat Is this a bug or a feature? A feature: the message explains why this pattern is not allowed.

Re: Python without a tty

2011-09-30 Thread Hans Mulder
On 30/09/11 20:34:37, RJB wrote: You could try the old UNIX nohup ... technique for running a process in the background (the) with no HangUP if you log out: $ nohup python -c import sys,os; print os.isatty(sys.stdout.fileno()) appending output to nohup.out $ cat nohup.out False But that is

Re: Python without a tty

2011-10-02 Thread Hans Mulder
On 3/10/11 06:37:43, Steven D'Aprano wrote: On Fri, 30 Sep 2011 21:09:54 +0100, Nobody wrote: On Thu, 29 Sep 2011 11:53:12 +0200, Alain Ketterlin wrote: I have a Python script which I would like to test without a tty attached to the process. I could run it as a cron job, but is there an

Re: Python without a tty

2011-10-03 Thread Hans Mulder
On 3/10/11 08:10:57, Hegedüs, Ervin wrote: hello, On Mon, Oct 03, 2011 at 04:37:43AM +, Steven D'Aprano wrote: I wanted to ensure that it would do the right thing when run without a tty, such as from a cron job. If you fork() your process, then it will also loose the tty... Errhm, I

Re: compare range objects

2011-10-20 Thread Hans Mulder
On 20/10/11 18:22:04, Westley Martínez wrote: On Thu, Oct 20, 2011 at 06:19:40AM -0700, Yingjie Lan wrote: Hi, Is it possible to test if two range objects contain the same sequence of integers by the following algorithm in Python 3.2? 1. standardize the ending bound by letting it be the

Re: Problem using execvp

2011-10-27 Thread Hans Mulder
On 27/10/11 10:57:55, faucheuse wrote: I'm trying to launch my python program with another process name than python.exe. Which version of Python are you using? Which version of which operating system? In order to do that I'm trying to use the os.execvp function : os.execvp(./Launch.py,

Re: Missing something obvious with python-requests

2013-01-04 Thread Hans Mulder
On 4/01/13 03:56:47, Chris Angelico wrote: On Fri, Jan 4, 2013 at 5:53 AM, Ray Cote rgac...@appropriatesolutions.com wrote: proxies = { 'https': '192.168.24.25:8443', 'http': '192.168.24.25:8443', } a = requests.get('http://google.com/', proxies=proxies) When I look at the proxy

Re: Numpy outlier removal

2013-01-06 Thread Hans Mulder
On 6/01/13 20:44:08, Joseph L. Casale wrote: I have a dataset that consists of a dict with text descriptions and values that are integers. If required, I collect the values into a list and create a numpy array running it through a simple routine: data[abs(data - mean(data)) m * std(data)]

Re: help

2013-01-11 Thread Hans Mulder
On 10/01/13 19:35:40, kwakukwat...@gmail.com wrote: pls this is a code to show the pay of two people.bt I want each of to be able to get a different money when they enter their user name,and to use it for about six people. database = [ ['Mac'], ['Sam'], ] pay1 = 1000 pay2 =

Re: please i need explanation

2013-01-11 Thread Hans Mulder
On 11/01/13 16:35:10, kwakukwat...@gmail.com wrote: def factorial(n): if n2: return 1 f = 1 while n= 2: f *= n f -= 1 U think this line should have been: n -= 1 return f Hope this helps, -- HansM --

Re: urllib2 FTP Weirdness

2013-01-23 Thread Hans Mulder
On 24/01/13 00:58:04, Chris Angelico wrote: On Thu, Jan 24, 2013 at 7:07 AM, Nick Cash nick.c...@npcinternational.com wrote: Python 2.7.3 on linux This has me fairly stumped. It looks like urllib2.urlopen(ftp://some.ftp.site/path;).read() will either immediately return '' or hang

Re: using split for a string : error

2013-01-25 Thread Hans Mulder
On 25/01/13 15:04:02, Neil Cerutti wrote: On 2013-01-25, Oscar Benjamin oscar.j.benja...@gmail.com wrote: On 24 January 2013 11:35, Chris Angelico ros...@gmail.com wrote: It's usually fine to have int() complain about any non-numerics in the string, but I must confess, I do sometimes yearn

[issue16450] test_missing_localfile masks problems in urlopen

2012-11-10 Thread Hans Mulder
New submission from Hans Mulder: Due to a misconfiguration, urllib.thishost() raises an IOError on my laptop. This causes urllib.urlopen to raise an exception. A flaw in test_missing_localfile causes this exception to not be reported. The problem happens at line 230-235: try

<    1   2   3