Re: [Tutor] creating a subclass from superclass without __init__

2012-08-24 Thread eryksun
On Fri, Aug 24, 2012 at 4:03 PM, Matt Gregory wrote: > > There are two classes of interest in GDAL - a Dataset which typically > describes a geospatial raster file and Band which described a single band > from the Dataset. gdal.Band just raises an AttributeError within __init__, > but a gdal.Band

Re: [Tutor] creating a subclass from superclass without __init__

2012-08-24 Thread Steven D'Aprano
On 25/08/12 06:03, Matt Gregory wrote: There are two classes of interest in GDAL - a Dataset which typically describes a geospatial raster file and Band which described a single band from the Dataset. gdal.Band just raises an AttributeError within __init__, but a gdal.Band instance can be creat

Re: [Tutor] 2.7.3 'CalledProcessError' error....why?

2012-08-24 Thread Ray Jones
On 08/24/2012 04:14 PM, Emile van Sebille wrote: > On 8/24/2012 3:36 PM Ray Jones said... >> My code: >> >>try: >> subprocess.check_call(['ping', '-w1', ip]) >>except CalledProcessError: >> print 'System', ip, 'is not responding. Exiting' >> sys.exit(4) >>else: return

Re: [Tutor] 2.7.3 'CalledProcessError' error....why?

2012-08-24 Thread Emile van Sebille
On 8/24/2012 3:36 PM Ray Jones said... My code: try: subprocess.check_call(['ping', '-w1', ip]) except CalledProcessError: print 'System', ip, 'is not responding. Exiting' sys.exit(4) else: return None The result: Traceback (most recent call last): File "./testin

[Tutor] 2.7.3 'CalledProcessError' error....why?

2012-08-24 Thread Ray Jones
My code: try: subprocess.check_call(['ping', '-w1', ip]) except CalledProcessError: print 'System', ip, 'is not responding. Exiting' sys.exit(4) else: return None The result: Traceback (most recent call last): File "./testing.py", line 222, in main() File "./testin

Re: [Tutor] creating a subclass from superclass without __init__

2012-08-24 Thread Matt Gregory
On 8/24/2012 12:01 PM, Steven D'Aprano wrote: That's not a use-case. A use-case is a real-world problem that you are trying to solve. You have skipped the problem and jumped straight to what you think is the solution: "create a subclass which can't be instantiated directly". I can't imagine any

Re: [Tutor] how to split/partition a string on keywords?

2012-08-24 Thread eryksun
On Fri, Aug 24, 2012 at 1:30 PM, Jared Nielsen wrote: > > But if I run the following: > > > #!/usr/bin/python > > text = raw_input("Enter text: ") > > text.replace("and", "\nand") > text.replace("or", "\nor") > > print text > > I get the text as it was entered. > Is there a way to replace text in

Re: [Tutor] creating a subclass from superclass without __init__

2012-08-24 Thread Steven D'Aprano
On 25/08/12 04:22, Matt Gregory wrote: Is it possible to create a subclass of a superclass that doesn't have an __init__ and is only created through another class. Here is an example of what isn't working: class Spam(object): def __new__(cls, *args): return super(Spam, cls).__new__(c

[Tutor] creating a subclass from superclass without __init__

2012-08-24 Thread Matt Gregory
Is it possible to create a subclass of a superclass that doesn't have an __init__ and is only created through another class. Here is an example of what isn't working: class Spam(object): def __new__(cls, *args): return super(Spam, cls).__new__(cls, args) def __init__(self):

Re: [Tutor] how to split/partition a string on keywords?

2012-08-24 Thread Peter Otten
Jared Nielsen wrote: > I implemented eryksun's suggestion and used the replace() method. > But, playing around with it, what I discovered is that it won't store the > change. > For example, when the input text is, "Ham and cheese or chicken and > waffles": > > #!/usr/bin/python > > text = raw_in

Re: [Tutor] how to split/partition a string on keywords?

2012-08-24 Thread Jared Nielsen
Thanks everyone. As I'm learning programming what I find most interesting is that there's always more than one way to solve a problem. I implemented eryksun's suggestion and used the replace() method. But, playing around with it, what I discovered is that it won't store the change. For example, wh

Re: [Tutor] better way to write this code

2012-08-24 Thread Norman Khine
thank you for the detailed replies, i will try to update the code and post it when done On Fri, Aug 24, 2012 at 1:36 PM, eryksun wrote: > On Fri, Aug 24, 2012 at 8:11 AM, Peter Otten <__pete...@web.de> wrote: > > > > for index, name, fixer in fixers: > > item = event[index] >

Re: [Tutor] better way to write this code

2012-08-24 Thread eryksun
On Fri, Aug 24, 2012 at 8:11 AM, Peter Otten <__pete...@web.de> wrote: > > for index, name, fixer in fixers: > item = event[index] @Norman I forgot to mention this. You should index the event instead of iterating over it. I suppose each event has a name in index 12, so you shou

Re: [Tutor] better way to write this code

2012-08-24 Thread eryksun
On Thu, Aug 23, 2012 at 2:33 PM, Norman Khine wrote: > > import operator, json > from BeautifulSoup import BeautifulSoup If you have the source of TABLE_CONTENT, why don't you soup that instead? Otherwise, nevermind. > combos={0: 'id', > 2: 'country', > 3: 'type', > 5: 'lat', > 6: 'lon', > 12: '

Re: [Tutor] better way to write this code

2012-08-24 Thread Peter Otten
Norman Khine wrote: > I have this code (http://pastie.org/4575790) which pulls data from a list > and then modifies some of the values such as the 'yield' entry, which has > entries like: > > 21 > 15 > ≤ 1000 > ≤ 20 > 2.2 - 30 > > so that they are cleaned up. > can the code be improved furth

Re: [Tutor] Error message...

2012-08-24 Thread David
On 24/08/2012, Victoria Homsy wrote: > > However, this does not work - I get another error message. > Could somebody advise what I'm doing wrong here? Thank you. 1) You are not carefully reading the entire error message. 2) You are not allowing us to do it either. Some other things too, probably

Re: [Tutor] better way to write this code

2012-08-24 Thread Norman Khine
ok, thanks On Fri, Aug 24, 2012 at 1:00 AM, Dave Angel wrote: > On 08/23/2012 02:33 PM, Norman Khine wrote: > > Hello, > > I have this code (http://pastie.org/4575790) which pulls data from a > list > > and then modifies some of the values such as the 'yield' entry, which has > > entries like:

Re: [Tutor] Python working with Bash....arrrggggh!

2012-08-24 Thread Steven D'Aprano
On 24/08/12 17:05, Ray Jones wrote: On 08/24/2012 12:02 AM, Steven D'Aprano wrote: On 24/08/12 16:27, Ray Jones wrote: I am forever confused, however, on which methods can be found where. I just spent quarter of an hour searching in sys,* os.*, and shutil.*. for a 'kill' command that I knew I

Re: [Tutor] Python working with Bash....arrrggggh!

2012-08-24 Thread Mark Lawrence
On 24/08/2012 08:02, Steven D'Aprano wrote: On 24/08/12 16:27, Ray Jones wrote: I am forever confused, however, on which methods can be found where. I just spent quarter of an hour searching in sys,* os.*, and shutil.*. for a 'kill' command that I knew I'd seen beforeI found it hidden in su

Re: [Tutor] pickle problems

2012-08-24 Thread Richard D. Moores
Case Van Horsen wrote the following to me about gmpy2.is_prime. I post it with his permission. Dick Moores The summary: gmpy2.is_prime() just provides direct access to the underlying library (GMP or MPIR) function. Depending on the library and version, the behavior is subtly different. With the

Re: [Tutor] Python working with Bash....arrrggggh!

2012-08-24 Thread Ray Jones
On 08/24/2012 12:02 AM, Steven D'Aprano wrote: > On 24/08/12 16:27, Ray Jones wrote: > >> I am forever confused, however, on which methods can be found where. I >> just spent quarter of an hour searching in sys,* os.*, and shutil.*. for >> a 'kill' command that I knew I'd seen beforeI found it

Re: [Tutor] Python working with Bash....arrrggggh!

2012-08-24 Thread Steven D'Aprano
On 24/08/12 16:27, Ray Jones wrote: I am forever confused, however, on which methods can be found where. I just spent quarter of an hour searching in sys,* os.*, and shutil.*. for a 'kill' command that I knew I'd seen beforeI found it hidden in subprocess.Popen. Arrrgggh. These various impor