I am a newbie for python and try to understand class Inheritance.

2011-10-14 Thread aaabbb16
Test.py #!/usr/bin/python from my_lib import my_function class my_class(my_function.name): def __initial__(self, name); pass def test(): print "this is a test" If __name__ == '__maim__': my_class.main() --- my_lib.py class

Re: Can I search a list for a range of values?

2011-10-14 Thread Westley Martínez
On Fri, Oct 14, 2011 at 05:01:04PM -0600, Ian Kelly wrote: > On Fri, Oct 14, 2011 at 4:30 PM, Tim Chase > wrote: > > On 10/14/11 17:20, Chris Angelico wrote: > >> > >> Try a list comprehension: > >> > > a = [2,4,5,6,3,9,10,34,39,59,20,15,13,14] > > [i for i in a if i>=10 if i<=20] > >> > >

Re: How to test if object is an integer?

2011-10-14 Thread Terry Reedy
On 10/14/2011 9:51 PM, Ben Finney wrote: Terry Reedy writes: On 10/14/2011 9:05 PM, Chris Angelico wrote: That tests if the object is already an int; the OP asked if a string contains an integer. The misleading subject line did not. It should have been "How to test if a string contains an

Re: How to generate error when argument are not supplied and there is no explicit defults (in optparse)?

2011-10-14 Thread Miki Tebeka
Don't specify it as an option, but as an argument. If you're on a new version of python, you should probably use argparse. -- http://mail.python.org/mailman/listinfo/python-list

Re: Reading a file into a data structure....

2011-10-14 Thread Chris Rebert
On Fri, Oct 14, 2011 at 7:59 PM, MrPink wrote: > This is what I have been able to accomplish: > > def isInt(s): >    try: >        i = int(s) >        return True >    except ValueError: >        return False > > f = open("powerball.txt", "r") > lines = f.readlines() > f.close() > > dDrawings = {}

Re: Reading a file into a data structure....

2011-10-14 Thread Chris Angelico
On Sat, Oct 15, 2011 at 1:59 PM, MrPink wrote: > def isInt(s): >    try: >        i = int(s) >        return True >    except ValueError: >        return False > > f = open("powerball.txt", "r") > lines = f.readlines() > f.close() > > dDrawings = {} > for line in lines: >    if isInt(line[0]): >  

Re: Language Enhancement Idea to help with multi-processing (your opinions please)

2011-10-14 Thread Chris Angelico
On Sat, Oct 15, 2011 at 1:15 PM, Chris Rebert wrote: > On Fri, Oct 14, 2011 at 6:23 PM, alex23 wrote: >> Well sure, but imaginary syntax can do _anything_. That doesn't mean >> it's possible within CPython. > > But it's The Future now! Where are my jetpack and `dwim` statement, > dammit?!  :-) I

Re: Reading a file into a data structure....

2011-10-14 Thread MrPink
This is what I have been able to accomplish: def isInt(s): try: i = int(s) return True except ValueError: return False f = open("powerball.txt", "r") lines = f.readlines() f.close() dDrawings = {} for line in lines: if isInt(line[0]): t = line.split()

Re: Python library for generating SQL queries [selects, alters, inserts and commits]

2011-10-14 Thread alex23
Tim Chase wrote: > I'm not sure it can entirely be chalked up to not looking hard > enough. It's explicitly cited in the feature list: Raw SQL statement mapping SQLA's object relational query facilities can accommodate raw SQL statements as well as plain result sets, and object instances can be

Re: Language Enhancement Idea to help with multi-processing (your opinions please)

2011-10-14 Thread alex23
On Oct 15, 12:32 pm, alex23 wrote: > from functools import partial You can ignore this, sorry, leftover from earlier code :) -- http://mail.python.org/mailman/listinfo/python-list

Re: Language Enhancement Idea to help with multi-processing (your opinions please)

2011-10-14 Thread alex23
On Oct 13, 10:35 pm, "Martin P. Hellwig" wrote: > def do_something(): >      a = 4 >      b = 2 >      c = 1 >      ooo: >          a += 1 >          b += 2 >          c += 3 >      print(a, b, c) > > What I would expect to happen that all statements within the ooo block > may be executed out > of

Re: Language Enhancement Idea to help with multi-processing (your opinions please)

2011-10-14 Thread Chris Rebert
On Fri, Oct 14, 2011 at 6:23 PM, alex23 wrote: > On Oct 14, 4:56 pm, Carl Banks wrote: >> But you can see that, fully realized, syntax like that can do much more >> than can be done with library code. > > Well sure, but imaginary syntax can do _anything_. That doesn't mean > it's possible within

Re: Language Enhancement Idea to help with multi-processing (your opinions please)

2011-10-14 Thread Ben Finney
alex23 writes: > On Oct 14, 4:56 pm, Carl Banks wrote: > > But you can see that, fully realized, syntax like that can do much more > > than can be done with library code. > > Well sure, but imaginary syntax can do _anything_. That doesn't mean > it's possible within CPython. +1 QotW -- \

Re: How to test if object is an integer?

2011-10-14 Thread Ben Finney
Terry Reedy writes: > On 10/14/2011 9:05 PM, Chris Angelico wrote: > > That tests if the object is already an int; the OP asked if a string > > contains an integer. > > The misleading subject line did not. It should have been "How to test > if a string contains an integer?" Which would still be

Re: Language Enhancement Idea to help with multi-processing (your opinions please)

2011-10-14 Thread alex23
On Oct 14, 4:56 pm, Carl Banks wrote: > But you can see that, fully realized, syntax like that can do much more > than can be done with library code. Well sure, but imaginary syntax can do _anything_. That doesn't mean it's possible within CPython. -- http://mail.python.org/mailman/listinfo/pyt

Re: How to test if object is an integer?

2011-10-14 Thread Terry Reedy
On 10/14/2011 9:05 PM, Chris Angelico wrote: 2011/10/15 惜悯: retrun True if type(i) is int else False That tests if the object is already an int; the OP asked if a string contains an integer. The misleading subject line did not. It should have been "How to test if a string contains an integer

Re: How to test if object is an integer?

2011-10-14 Thread Chris Rebert
On Fri, Oct 14, 2011 at 6:05 PM, Chris Angelico wrote: > 2011/10/15 惜悯 : >> retrun True if type(i) is int else False > > That tests if the object is already an int; the OP asked if a string > contains an integer. Additionally: * the if-then-else there is unnecessary since `type(i) is int` already

Re: How to test if object is an integer?

2011-10-14 Thread Chris Angelico
2011/10/15 惜悯 : > retrun True if type(i) is int else False That tests if the object is already an int; the OP asked if a string contains an integer. ChrisA -- http://mail.python.org/mailman/listinfo/python-list

Re: How to test if object is an integer?

2011-10-14 Thread 惜悯
retrun True if type(i) is int else False -- Original -- From: "Chris Angelico"; Date: Sat, Oct 15, 2011 08:55 AM To: "python-list"; Subject: Re: How to test if object is an integer? On Sat, Oct 15, 2011 at 10:44 AM, MrPink wrote: > Is there a function i

Re: Opportunity missed by Python ?

2011-10-14 Thread alex23
On Oct 13, 8:07 pm, Chris Angelico wrote: > Python, as I found out to my detriment, is practically impossible to > sandbox effectively. The latest version of PyPy introduces a prototype sandbox: http://pypy.org/features.html#sandboxing It'll be interesting to see how effective this is. -- http

Re: How to test if object is an integer?

2011-10-14 Thread Chris Angelico
On Sat, Oct 15, 2011 at 10:44 AM, MrPink wrote: > Is there a function in Python that can be used to test if the value in > a string is an integer?  I had to make one up for myself and it looks > like this: > > def isInt(s): >    try: >        i = int(s) >        return True >    except ValueError:

How to test if object is an integer?

2011-10-14 Thread MrPink
Is there a function in Python that can be used to test if the value in a string is an integer? I had to make one up for myself and it looks like this: def isInt(s): try: i = int(s) return True except ValueError: return False -- http://mail.python.org/mailman/list

Re: Can I search a list for a range of values?

2011-10-14 Thread Chris Angelico
On Sat, Oct 15, 2011 at 9:58 AM, Ian Kelly wrote: > At least in Python, there is no way that "and" could be a bitwise and > either, since it cannot be overloaded. Like I said, cross-language safety-net. Sure it's not an issue here, but when I write code in multiple languages, it's less embarrassi

Re: Can I search a list for a range of values?

2011-10-14 Thread Ian Kelly
On Fri, Oct 14, 2011 at 5:36 PM, Troy S wrote: > Can something like this be done with dictionarys? > > For example, these are the keys in the dictionary from the call: dict.keys() > > ['20110601', '20110604', '20110608', '20110611', '20110615', > '20110618', '20110622', '20110625', '20110629', '20

Re: Can I search a list for a range of values?

2011-10-14 Thread Tim Chase
On 10/14/11 18:36, Troy S wrote: Can something like this be done with dictionarys? For example, these are the keys in the dictionary from the call: dict.keys() ['20110601', '20110604', '20110608', '20110611', '20110615', '20110618', '20110622', '20110625', '20110629', '20110702', '20110706','20

Re: Can I search a list for a range of values?

2011-10-14 Thread Troy S
Can something like this be done with dictionarys? For example, these are the keys in the dictionary from the call: dict.keys() ['20110601', '20110604', '20110608', '20110611', '20110615', '20110618', '20110622', '20110625', '20110629', '20110702', '20110706','20110709', '20110713', '20110716', '2

Re: Can I search a list for a range of values?

2011-10-14 Thread Ian Kelly
On Fri, Oct 14, 2011 at 5:24 PM, Tim Chase wrote: > Depending on your historical programming-language baggage, "i" is usually > either an index or integer data, and since the source was a list of > integers, "i" didn't seem inappropriate.  Same for other common data-types: > >  [f for f in (1.1, 2

Re: Can I search a list for a range of values?

2011-10-14 Thread Tim Chase
On 10/14/11 18:01, Ian Kelly wrote: On Fri, Oct 14, 2011 at 4:30 PM, Tim Chase or even more clearly: [i for i in a if 10<= i<= 20] As long as we're nitpicking, I'll point out that "i" is an inappropriate variable name here, since it is normally used to denote indices, not data. That's why I

Re: Can I search a list for a range of values?

2011-10-14 Thread Ian Kelly
On Fri, Oct 14, 2011 at 4:30 PM, Tim Chase wrote: > On 10/14/11 17:20, Chris Angelico wrote: >> >> Try a list comprehension: >> > a = [2,4,5,6,3,9,10,34,39,59,20,15,13,14] > [i for i in a if i>=10 if i<=20] >> >> [10, 20, 15, 13, 14] > > The double-if is new to me.  I thought it was an err

Re: Can I search a list for a range of values?

2011-10-14 Thread Ian Kelly
On Fri, Oct 14, 2011 at 4:48 PM, Chris Angelico wrote: > On Sat, Oct 15, 2011 at 9:30 AM, Tim Chase > wrote: >> The double-if is new to me.  I thought it was an error when I first saw it, >> but it seems to be legit syntax (or at least one that 2.7 tolerates, >> intentionally or otherwise...).  I

Re: Re-raise different exception with original stack trace

2011-10-14 Thread MRAB
On 14/10/2011 22:30, Prasad, Ramit wrote: Hi all, Hopefully you guys can help me with my problem. Basically I have a UI program that can "save" information. The UI passes the save to the controller and the controller saves a file and does some post processing. If saving the file fails, I want

Re: Can I search a list for a range of values?

2011-10-14 Thread Chris Angelico
On Sat, Oct 15, 2011 at 9:30 AM, Tim Chase wrote: > The double-if is new to me.  I thought it was an error when I first saw it, > but it seems to be legit syntax (or at least one that 2.7 tolerates, > intentionally or otherwise...).  I think I'd make it clearer with either > > Yeah, it's legal be

Re: Can I search a list for a range of values?

2011-10-14 Thread Tim Chase
On 10/14/11 17:20, Chris Angelico wrote: Try a list comprehension: a = [2,4,5,6,3,9,10,34,39,59,20,15,13,14] [i for i in a if i>=10 if i<=20] [10, 20, 15, 13, 14] The double-if is new to me. I thought it was an error when I first saw it, but it seems to be legit syntax (or at least one th

Re: Can I search a list for a range of values?

2011-10-14 Thread Ian Kelly
On Fri, Oct 14, 2011 at 4:10 PM, MrPink wrote: > I have a list like so: > > a = [2,4,5,6,3,9,10,34,39,59,20,15,13,14] > > I would like to get a subset from the list with value between 10 and > 20 (inclusive). > > b = [10,13,15,14,20] > > Is there a way to do this with a list or other data type? U

Re: Can I search a list for a range of values?

2011-10-14 Thread Chris Angelico
On Sat, Oct 15, 2011 at 9:10 AM, MrPink wrote: > I have a list like so: > > a = [2,4,5,6,3,9,10,34,39,59,20,15,13,14] > > I would like to get a subset from the list with value between 10 and > 20 (inclusive). > > b = [10,13,15,14,20] > > Is there a way to do this with a list or other data type? T

Can I search a list for a range of values?

2011-10-14 Thread MrPink
I have a list like so: a = [2,4,5,6,3,9,10,34,39,59,20,15,13,14] I would like to get a subset from the list with value between 10 and 20 (inclusive). b = [10,13,15,14,20] Is there a way to do this with a list or other data type? Thanks, -- http://mail.python.org/mailman/listinfo/python-list

Re-raise different exception with original stack trace

2011-10-14 Thread Prasad, Ramit
Hi all, Hopefully you guys can help me with my problem. Basically I have a UI program that can "save" information. The UI passes the save to the controller and the controller saves a file and does some post processing. If saving the file fails, I want to handle the error differently than if the

Re: [NUMPY] "ValueError: total size of new array must be unchanged" just on Windows

2011-10-14 Thread MRAB
On 14/10/2011 21:55, Paolo Zaffino wrote: Nobody can help me? Others have already tried to help you. What is the shape and size of 'matrix' before, and what are the values of 'a', 'b' and 'c'? Print them in the ones which work (GNU/Linux and Mac OS) and the one which doesn't (Windows). Do the

RE: [NUMPY] "ValueError: total size of new array must be unchanged" just on Windows

2011-10-14 Thread Prasad, Ramit
From: python-list-bounces+ramit.prasad=jpmorgan@python.org [mailto:python-list-bounces+ramit.prasad=jpmorgan@python.org] On Behalf Of Paolo Zaffino Sent: Friday, October 14, 2011 3:55 PM To: python-list@python.org Subject: Re: [NUMPY] "ValueError: total size of new array must be unchanged

How to generate error when argument are not supplied and there is no explicit defults (in optparse)?

2011-10-14 Thread Peng Yu
Hi, The following code doesn't give me error, even I don't specify the value of filename from the command line arguments. filename gets 'None'. I checked the manual, but I don't see a way to let OptionParser fail if an argument's value (which has no default explicitly specified) is not specified.

Re: [NUMPY] "ValueError: total size of new array must be unchanged" just on Windows

2011-10-14 Thread Paolo Zaffino
Nobody can help me? 2011/10/12 Paolo Zaffino > I wrote a function thaht works on a 3D matrix. > As first thing I have an array and I want reshape it into a 3D matrix (for > further manipulations). > For this reason I wrote in a row: > > matrix=matrix.reshape(a, b, c).T > > It work fine on GNU/

Re: .py and .pyc files in read-only directory

2011-10-14 Thread Terry
Thanks, that's very useful. And it explains why Python Math wants to rewrite the .pyc files: imp.get_magic() returns (null) whereas on my Mac where I compiled them, get_magic() returns '\x03\xf3\r\n'. Now I just have to figure out why I'm getting nothing useful from get_magic(). I assume this w

Re: .py and .pyc files in read-only directory

2011-10-14 Thread Ian Kelly
On Fri, Oct 14, 2011 at 1:31 PM, Chris Rebert wrote: > On Fri, Oct 14, 2011 at 11:04 AM, Terry wrote: >> I'm having a problem with my iPhone/iPad app, Python Math, a Python >> 2.7 interpreter. All the Python modules are delivered in what Apple >> calls the app bundle. They are in a read-only dire

Re: .py and .pyc files in read-only directory

2011-10-14 Thread Chris Rebert
On Fri, Oct 14, 2011 at 11:04 AM, Terry wrote: > I'm having a problem with my iPhone/iPad app, Python Math, a Python > 2.7 interpreter. All the Python modules are delivered in what Apple > calls the app bundle. They are in a read-only directory. This means > that Python cannot write .pyc files to

Re: Language Enhancement Idea to help with multi-processing (your opinions please)

2011-10-14 Thread Westley Martínez
On Thu, Oct 13, 2011 at 11:56:20PM -0700, Carl Banks wrote: > On Thursday, October 13, 2011 7:16:37 PM UTC-7, Steven D'Aprano wrote: > > > What I would expect to happen that all statements within the ooo block > > > may be executed out > > > of order. The block itself waits till all statements are

Re: Fwd: os.statvfs bug or my incompetence ?

2011-10-14 Thread Paul Rubin
Terry Reedy writes: >> os.statvfs('/') >> *OSError: [Errno 0] Error: '/'* >> >> # python --version >> Python 2.6.2 > > 2.6.2 is a few years old. If there is a bug, it might have been fixed > by 2.6.6 released a year ago, or 2.7.2 just a few months ago. os.statvfs('/') works fine or me on Pyt

.py and .pyc files in read-only directory

2011-10-14 Thread Terry
I'm having a problem with my iPhone/iPad app, Python Math, a Python 2.7 interpreter. All the Python modules are delivered in what Apple calls the app bundle. They are in a read-only directory. This means that Python cannot write .pyc files to that directory. (I get a deny write error when doing thi

Re: Language Enhancement Idea to help with multi-processing (your opinions please)

2011-10-14 Thread Steven D'Aprano
Carl Banks wrote: > On Thursday, October 13, 2011 7:16:37 PM UTC-7, Steven D'Aprano wrote: >> > What I would expect to happen that all statements within the ooo block >> > may be executed out >> > of order. The block itself waits till all statements are returned >> > before continuing. >> >> Why

Re: Implement comparison operators for range objects

2011-10-14 Thread Mark Dickinson
On Oct 12, 8:24 pm, Ian Kelly wrote: > On Wed, Oct 12, 2011 at 11:51 AM, MRAB wrote: > >> Aside: > > >> I'm astonished to see that range objects have a count method! What's the > >> purpose of that? Any value's count will either be 0 or 1, and a more > >> appropriate test would be `value in range

Re: 1/2 evaluates to 0

2011-10-14 Thread 88888 dihedral
How about fractions to be computed in hundreds or even thousands of digits in precision? OK, just write programs to compute PI and the Euler number in hundreds or even thousands of digits to test various kind of programming languages. This is a sophomore school home work for gifted kid

RE: Opportunity missed by Python ?

2011-10-14 Thread Prasad, Ramit
>As long as there are tools to translate scripts or source code between the two >languages. More new evolved powerful programming >languages arenot problems >at all for experienced programmers. More often than not, these conversion utilities are a source of terrible code. They are good for get

Re: Graph editor

2011-10-14 Thread duncan smith
On 14/10/11 08:45, Libra wrote: Hi, I would like to build a simple graph editor, allowing me to add nodes and edges via the mouse, along with the possibility to edit it (delete/ move nodes and edges, double click on object to pop-up a form where I can insert object related info, and so forth) and

Re: Fwd: os.statvfs bug or my incompetence ?

2011-10-14 Thread Terry Reedy
On 10/14/2011 4:19 AM, Peter G. Marczis wrote: import os os.statvfs('/') ... os.statvfs('/') *OSError: [Errno 0] Error: '/'* # python --version Python 2.6.2 # arch mips64 os.stat works fine. 2.6.2 is a few years old. If there is a bug, it might have been fixed by 2.6.6 released a year ag

Re: Something works in Python but not in cgi.

2011-10-14 Thread Miki Tebeka
The working directory of the webserver is probably not the one of the script. You should specify full path to the file. One way to do it is: from os.path import dirname, join filename = join(dirname(__file__), 'gri30.cti') HTH -- Miki Tebeka http://pythonwise.blogspot.com -- http:

Something works in Python but not in cgi.

2011-10-14 Thread atalu...@gmail.com
Hi, I need to make work a programm on the Web. I make tests like Hello World and also with GET and it works good. The problem comes in the line gas = importPhase("gri30.cti") The computer don´t find the file "gri30.cti"(this file was not in workspace), then I put it in the same folder and the prog

Re: argparse zero-length switch

2011-10-14 Thread Ben Finney
Carl Banks writes: > I have a use case where some users would have to enter a section name > on the command line almost every time, whereas other users (the ones > using only one section) will never have to enter the section name. Sounds like a typical case where you want an option that takes an

Fwd: os.statvfs bug or my incompetence ?

2011-10-14 Thread Peter G. Marczis
 Hi list, I'm happy to join to this nice mail list. At my company we use python to handle system administration tasks. I found the next problem during my work: test.py: # cat test.py #!/usr/bin/python import os os.statvfs('/') r

Graph editor

2011-10-14 Thread Libra
Hi, I would like to build a simple graph editor, allowing me to add nodes and edges via the mouse, along with the possibility to edit it (delete/ move nodes and edges, double click on object to pop-up a form where I can insert object related info, and so forth) and bind edges to nodes (that is, whe

Re: argparse zero-length switch

2011-10-14 Thread Peter Otten
Carl Banks wrote: > Is it possible to specify a zero-length switch? Here's what I mean. > > I have a use case where some users would have to enter a section name on > the command line almost every time, whereas other users (the ones using > only one section) will never have to enter the section

Re: Language Enhancement Idea to help with multi-processing (your opinions please)

2011-10-14 Thread Carl Banks
On Thursday, October 13, 2011 5:35:30 AM UTC-7, Martin P. Hellwig wrote: > What I would expect to happen that all statements within the ooo block > may be executed out > of order. The block itself waits till all statements are returned before > continuing. > > What do you think? The statement i

Re: Language Enhancement Idea to help with multi-processing (your opinions please)

2011-10-14 Thread Carl Banks
On Thursday, October 13, 2011 7:16:37 PM UTC-7, Steven D'Aprano wrote: > > What I would expect to happen that all statements within the ooo block > > may be executed out > > of order. The block itself waits till all statements are returned before > > continuing. > > Why do you think this needs to