[Tutor] making onthefly attributes persistent

2010-12-13 Thread Jojo Mwebaze
Hey Tutor

Assuming i have a class bank as below .

class bank(object):
   def __init__(self, bal=0):
   self.bal = bal
   def deposit(self, amount):
   self.bal+=amount
   print self.bal

I define a method debit - which i add to the class onthefly

def debit(self, amt):
   self.bal-=amt
   print self.bal

bank.debit = debit

myacct = bank()
myacct.deposit(1000) # prints 1000
myacct.debit(99) # print 901

#I can also add an attribute owner

myaccount.owner = 'jojo'

dir(myacct) # prints [ 'owner', 'bal', 'debit', 'deposit']


My problem is how to make the added attributes, 'owner' and 'debit'
persistent automatically

Saving the object using pickle for example does save 'owner' and 'debit'
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] The Template Pattern

2010-12-13 Thread Karim


Hello all,

I am seeking for information about the template pattern applied to python.
Could you explain some implementation or anything else? it would be helpful.

Regards
Thanks a lot
Karim
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Help with using the ctypes module

2010-12-13 Thread Sachin Kamboj
Hi All,


I was trying to use the ctypes module for a project. I was creating a 
dynamically allocated array of "max_entries" pairs and once the array was 
exhausted, I was creating a new array of size (1.5 * max_entries) and copying 
the contents from the old array to the new array. 


Unfortunately, when I try to access the contents of this new_array, I get a 
"NULL pointer access" exception. The corresponding C code seems to work 
perfectly. (See code below.)


I was wondering if I was missing something about the way the ctypes module 
works. Any help would be greatly appreciated. (Not sure if this is the 
appropriate mailing list for my question.)


/Thanks!


---


#!/usr/bin/env python


from ctypes import *
import math
import random




class PAIR(Structure):
_fields_ = [("a", c_long),
("b", c_long)]



class MY_ARR(Structure):
_fields_ = [("no_entries", c_longlong),
("max_entries", c_longlong),
("entries", POINTER(POINTER(PAIR)))
]


def extendArray(x):
print "Extending Array"
print "Before: %d/%d" % (x.no_entries, x.max_entries)
old_arr = x.entries

# Create a new array
new_max_entries = int(math.ceil(1.5 * x.max_entries))
x.entries = (POINTER(PAIR) * new_max_entries)()

# Copy the entries from the old array to the new array
for i in range(x.no_entries):
x.entries[i] = old_arr[i]

x.max_entries = new_max_entries
print "After: %d/%d" % (x.no_entries, x.max_entries)
return x


def printPair(x):
print x.contents.a, x.contents.b


def printArray(x):
print "Printing %d/%d Entries" % (x.no_entries, x.max_entries)
for i in range(x.no_entries):
printPair(x.entries[i])



if __name__ == "__main__":
x = MY_ARR(0, 10, (POINTER(PAIR) * 10)())
for i in range(100):
if x.no_entries == x.max_entries:
print "\n\nPrinting Before Extension"
printArray(x)

extendArray(x)


print "\n\nPrinting After Extension"
printArray(x)

my_pair = PAIR(i, random.randint(0, 100))
x.entries[x.no_entries] = pointer(my_pair)
x.no_entries += 1

printPair(x.entries[i])

printArray(x)


---
Now unfortunately, when I try to run this code, I am getting a "NULL pointer 
access" exception:


$ python TestExtension.py 
0 40
1 40
2 11
3 36
4 82
5 73
6 93
7 100
8 75
9 80




Printing Before Extension
Printing 10/10 Entries
0 40
1 40
2 11
3 36
4 82
5 73
6 93
7 100
8 75
9 80
Extending Array
Before: 10/10
After: 10/15




Printing After Extension
Printing 10/15 Entries
Traceback (most recent call last):
File "TestExtension.py", line 55, in 
printArray(x)
File "TestExtension.py", line 42, in printArray
printPair(x.entries[i])
File "TestExtension.py", line 37, in printPair
print x.contents.a, x.contents.b
ValueError: NULL pointer access


---


The corresponding C code works perfectly:


#include 
#include 
#include 


typedef struct {
long a;
long b;
} pair;


typedef struct {
long long no_entries;
long long max_entries;
pair **entries;
} my_arr;

my_arr *extend_array(my_arr *x) {
int i;
pair **old_entries = x->entries;
long long new_max_entries = ceil(1.5 * x->max_entries);

printf("Extending Array\n");
printf("Before: %lld/%lld\n", x->no_entries, x->max_entries);

x->entries = malloc(sizeof(pair *) * new_max_entries);
for (i = 0; i < 100; ++i) {
x->entries[i] = old_entries[i];
}
x->max_entries = new_max_entries;
free(old_entries);

printf("After: %lld/%lld\n", x->no_entries, x->max_entries);
return x;
}


void print_pair(pair *p) {
printf("%ld\t%ld\n", p->a, p->b);
}


void print_array(my_arr *x) {
int i;
printf("Printing %lld/%lld entries\n", x->no_entries, x->max_entries);
for (i = 0; i < x->no_entries; ++i) {
print_pair(x->entries[i]);
}
}


int main(int argc, char *argv[])
{
int i;
my_arr x = {
0, 
10,
malloc(sizeof(pair *) * 10)
};

for (i = 0; i < 100; ++i) {
if (x.no_entries == x.max_entries) {
extend_array(&x);
}
pair *my_pair = malloc(sizeof(pair));
my_pair->a = i;
my_pair->b = rand() % 100;

x.entries[x.no_entries++] = my_pair;
print_pair(x.entries[i]);
}
print_array(&x);
return 0;
}




___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Problem with "yaml load"

2010-12-13 Thread Sean Carolan
Hi folks:

I'm trying to define a short function that will import yaml data into
a python dictionary.  I am able to do this by dumping my data into a
temporary file and then importing it with yaml.load.  I would like to
see if I can eliminate the temporary file and import the data
directly.

This works fine:

import yaml
import os

def grabfacts():
''' This function grabs facter data and sucks it into a dictionary
called dataMap '''
os.system('facter --yaml > /tmp/sysdata.yaml')
f = open('/tmp/sysdata.yaml')
dataMap = yaml.load(f)
f.close()

Is there an easy way to do this without writing to a temporary file?
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Problem with "yaml load"

2010-12-13 Thread Wayne Werner
On Mon, Dec 13, 2010 at 11:08 AM, Sean Carolan  wrote:

> Hi folks:
>
> I'm trying to define a short function that will import yaml data into
> a python dictionary.  I am able to do this by dumping my data into a
> temporary file and then importing it with yaml.load.  I would like to
> see if I can eliminate the temporary file and import the data
> directly.
>
> This works fine:
>
> import yaml
> import os
>
> def grabfacts():
>''' This function grabs facter data and sucks it into a dictionary
>called dataMap '''
>os.system('facter --yaml > /tmp/sysdata.yaml')
>f = open('/tmp/sysdata.yaml')
>dataMap = yaml.load(f)
>f.close()
>
> Is there an easy way to do this without writing to a temporary file?


Presumably you could use something like subprocess and simply pipe stdout to
your program. I presume facter --yaml will produce output to stdout? It's
fairly trivial to read stdout using subprocess.

http://docs.python.org/library/subprocess.html

that should get you started.
HTH,
Wayne
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] gui coding

2010-12-13 Thread Rance Hall
When I learned FORTRAN years ago they didn't teach us OOP or what I
like to call Class based programming.

since then I've sort of always fallen back to be a procedural
programmer with lots of functions.

Python and the tkinter (Tkinter on Versions < 3) seem like a great way
to write cross platform GUI apps for small light duty apps.

I'm intrigued and want to learn but all the samples seem to be OOP or
class based.

I've tried to wrap my head around class based programming before and
it didn't take.  But it appears I'm going to have to try again as I
can not find any tkinter samples that use a procedural approach.  I'm
finding it very difficult to understand what I need to get from
tkinter because the classes are getting in the way and I'm not seeing
what I need to see.

Is there something about class based programming that GUI apps prefer
to work better in?

Does anyone have or know of a good tutorial or explanation of class
based coding that I could have a run at?

Thanks
Rance
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Writing to the terminal?

2010-12-13 Thread Roel Schroeven
Op 2010-12-12 22:33, Steven D'Aprano schreef:
> Terry Carroll wrote:
> 
>> import time
>> for t in range(10,0, -1):
>> print "%s \x0D" %t,
>> time.sleep(1)
>> print # get to next line
>> print "Done!"
> 
> Which operating system and terminal did you use?
> 
> In my experience, using print is not satisfactory, because the print 
> command buffers the output and doesn't actually print anything until 
> either a newline or you have a certain number of characters. So the 
> above will queue up the following string:
> 
> "10 \r9 \r8 \r7 \r6 \r5 \r4 \r3 \r2 \r1 \r\n"
> 
> before anything becomes visible, and of course that just looks like "1".

Instead of print, use sys.stdout.write():

import sys
import time
for t in range(10, 0, -1):
  sys.stdout.write('\r%s ' % t)
  time.sleep(1)
sys.stdout.write('\n')
sys.stdout.write('Done!')

-- 
The saddest aspect of life right now is that science gathers knowledge
faster than society gathers wisdom.
  -- Isaac Asimov

Roel Schroeven

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] gui coding

2010-12-13 Thread Wayne Werner
On Mon, Dec 13, 2010 at 11:51 AM, Rance Hall  wrote:

> When I learned FORTRAN years ago they didn't teach us OOP or what I
> like to call Class based programming.
>

That must have been a few years ago, then ;)


> since then I've sort of always fallen back to be a procedural
> programmer with lots of functions.
>

There's nothing really wrong with a lot of functions, and that also
highlights one of the great advantages of Python - you can still program
procedurally or using any other type of paradigm, more or less.


>
> Python and the tkinter (Tkinter on Versions < 3) seem like a great way
> to write cross platform GUI apps for small light duty apps.
>

Perfect, really. You can quickly throw a nice little GUI together with few
problems. And there are other people doing some rather
nice
things
with Tkinter.


> I've tried to wrap my head around class based programming before and
> it didn't take.  But it appears I'm going to have to try again as I
> can not find any tkinter samples that use a procedural approach.  I'm
> finding it very difficult to understand what I need to get from
> tkinter because the classes are getting in the way and I'm not seeing
> what I need to see.
>
> Is there something about class based programming that GUI apps prefer
> to work better in?


> Does anyone have or know of a good tutorial or explanation of class
> based coding that I could have a run at?


I'm not aware of any specific tutorials, but I'll try to answer your
question and give a bit of an explanation.

First, if you're used to writing plenty of functions, you're about halfway
to OOP. The only real difference between what you do already (using
functions) and using classes is on a conceptual level. Classes can be
defined as a collection of data and functions that operate on that data.

Think back to a program that you've written with several related functions.
Perhaps you wrote something with several records that you may have stored in
a list or array or some such. So you may write a function called
get_new_record() that gets data for a record, either from the user or
somewhere else. Then you might have an update_record() function that
modifies a given record. And perhaps even a delete_record(). You could think
for a few minutes and come up with the rudimentary functions, I'm sure.

Now, instead of thinking about them as either lists inside a list or a
series of data elements stored in a list, imagine those records really are
"things" - objects that can stand alone. And you can tell that record that
you want to modify it, or you want it displayed some certain way, or any
number of things. The hardest part about OOP is deciding how much
responsibility an object really should have. Anyhow, that's all OOP is -
just taking the related functions that you would normally write and sticking
them inside a class. So instead of:

['somename', 'somedata', 'anothername', 'more data', 'no name', '']

you could have

[record1, record2, record3]

which you could modify the __repr__/__string__ methods to print out however
you want.

If you haven't made the link yet, GUIs tend to be objects because it's just
easier to think of them that way. If you have a (real life) bottle, you can
open the lid, close the lid, put stuff in, take it out, or throw it in the
garbage. It's a lot easier to think of a text entry box as something you can
put text in, or get text out of, or .

It's a different way of thinking about programming that begins feeling
entirely natural because we, as humans, are used to talking about things
that can do stuff and we can do stuff with. You might have hedge clippers
that have certain attributes - number and sharpness of blades, for instance.
They also have a function that you can .open() them and .close() them. But
if you close them with something inside they will .cut() the object you
place inside the clippers.

Alan Gauld (frequent contributor of this list) has a tutorial on OOP at
http://alan-g.me.uk/ that has some pretty solid examples about class-based
programming.

Of course, this discussion wouldn't be complete without telling you that it
is quite possible (using Tkinter especially) to actually adhere to
procedural programming. You could do something like this:

import Tkinter as tk

def buttonclicked():
print "Yay, you clicked me!"

root = tk.Tk()
button = tk.Button(root, text='Click me!', command=buttonclicked)
button.pack()

root.mainloop()

If you're more comfortable with procedural programming you can certainly do
it that way, but you'll probably find it a lot easier to spend some time
getting used to the concept of OOP and writing your GUI programs in a
class-based fashion.

HTH,
Wayne
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Writing to the terminal?

2010-12-13 Thread Bill Allen
Alan,

Oh wow!   I was not aware of the WConio module.   That is exactly what I
have been needing!



Thanks,
Bill Allen



On Sun, Dec 12, 2010 at 6:49 PM, Alan Gauld wrote:

>
> "Modulok"  wrote
>
>  For more complex stuff, (think blue screens with little white boxes
>> you press spacebar to activate. Kind of like an OS installer) I would
>> look into the `curses` module in the standard library?
>>
>
> curses on Unix but its not in the std library for windows.
>
> I think there is a version you can download, and there are also
> libraries specifically for the PC terminal, one that I've used
> successfully being Wconio, based on the Borland Turbo-C
> console I/O package conio.h.
>
> Conio is on Sourceforge.
>
> HTH,
>
>
>
> --
> Alan Gauld
> Author of the Learn to Program web site
> http://www.alan-g.me.uk/
>
>
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Tab delimited question

2010-12-13 Thread Ben Ganzfried
I'm searching line by line for certain tags and then printing the tag
followed by the word immediately following the tag.

So for example, suppose I had the following line of text in a file:
"this   is  a   key test123 noisenoise  noise   noise   noise"

In this example, I would want to print "key test123" to a new file.
The rest of the words I would not want.

Here is my code so far:

def test(infile, outfile):
  for line in infile:
tagIndex = line.find("key")
start = tagIndex + 4
stop = line[start:].find("\t") -1
if tagIndex != -1:
print("start is: ", start)
print("stop is: ", stop)
print("spliced word is ", line[start: stop])

My question is the following: What is wrong w/ the variable 'stop'?
The index it gives me when I print out 'stop' is not even close to the
right number.  Furthermore, when I try to print out just the word
following the tag w/ the form: line[start: stop], it prints nothing
(it seems b/c my stop variable is incorrect).

I would greatly appreciate any help you have.  This is a much
simplified example from the script I'm actually writing, but I need to
figure out a way to eliminate the noise after the key and the word
immediately following it are found.

Thank you very much for any help you can provide.

Ben
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] making onthefly attributes persistent

2010-12-13 Thread Alan Gauld


"Jojo Mwebaze"  wrote


Assuming i have a class bank as below .

class bank(object):
  def __init__(self, bal=0):
  self.bal = bal
  def deposit(self, amount):
  self.bal+=amount
  print self.bal

I define a method debit - which i add to the class onthefly

bank.debit = debit

#I can also add an attribute owner

myaccount.owner = 'jojo'



My problem is how to make the added attributes, 'owner' and 'debit'
persistent automatically


If that's your only problem with this approach congratulations!
How does your orther code know when/if these dynamic
operations/data exist so as to use them? If they just assume
they exist then why not just add them in the definition. Even as 
nulls?


While Python allows you to dynamically add features to classes/objects
its not something I would recommend unless you have a really good
reason - not least because you bring upon yourself all sorts of 
problems!


If you are determined to do so you can make the objects persistent
using the approach I outline on my tutorial but adding a loop to cycle
over the contents of dir(). But you may find that recovering the
objects - especially if they have a mixed set of attribnutes - 
presents

even more problems...

IMHO This is a feature of python that should be considered unorthodox
and only to be used when no other approach will work!

HTH,


--
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Problem with "yaml load"

2010-12-13 Thread Sean Carolan
Yes, I tried using os.subprocess() but there was some sort of parsing
error.  I'll just stick with the temporary file for now; the
documentation seems to indicate that is how yaml.load should be used
anyway...



On Mon, Dec 13, 2010 at 11:43 AM, Wayne Werner  wrote:
> On Mon, Dec 13, 2010 at 11:08 AM, Sean Carolan  wrote:
>>
>> Hi folks:
>>
>> I'm trying to define a short function that will import yaml data into
>> a python dictionary.  I am able to do this by dumping my data into a
>> temporary file and then importing it with yaml.load.  I would like to
>> see if I can eliminate the temporary file and import the data
>> directly.
>>
>> This works fine:
>>
>> import yaml
>> import os
>>
>> def grabfacts():
>>    ''' This function grabs facter data and sucks it into a dictionary
>>    called dataMap '''
>>    os.system('facter --yaml > /tmp/sysdata.yaml')
>>    f = open('/tmp/sysdata.yaml')
>>    dataMap = yaml.load(f)
>>    f.close()
>>
>> Is there an easy way to do this without writing to a temporary file?
>
> Presumably you could use something like subprocess and simply pipe stdout to
> your program. I presume facter --yaml will produce output to stdout? It's
> fairly trivial to read stdout using subprocess.
> http://docs.python.org/library/subprocess.html
> that should get you started.
> HTH,
> Wayne
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] gui coding

2010-12-13 Thread Alan Gauld


"Rance Hall"  wrote


When I learned FORTRAN years ago they didn't teach us OOP or what I
like to call Class based programming.


One of the requirements of OOP is to be able to group data together
and from memory FORTRAN didn't have any such construct being
based primarily on arrays. I beliebve Fortran 95 had some kind of
limited OOP facilities but prior to that it was impossible. And my
experience on Fortran was in the 80's!

I'm intrigued and want to learn but all the samples seem to be OOP 
or

class based.


Try not to think of it as class based. Languages like Java tend to
emphasise the class but really you need to think about the actual
objects as the basis of the program. The class is just a template
from which to generate objects. Focussing on the classes as the
core item will lead to bad habits.


can not find any tkinter samples that use a procedural approach.


The GUI topic in my tutor does not use OOP till near the end.
It is extremely basic but it does show the basics needed to front
a CLI app with a GUI.


finding it very difficult to understand what I need to get from
tkinter because the classes are getting in the way and I'm not 
seeing

what I need to see.


Tkinter is, like most GUI toolkits heabvily based on objects itself.
But then, so is Python. Strings, files, lists etc are all objects in 
Python.

If you can use those you can use Tkinter.

Is there something about class based programming that GUI apps 
prefer

to work better in?


GUIs are conceptially made up of objects - buttons, menus, windows,
scroll bars etc. There is a very natural mapping from the visual 
objects

(widgets/controls) that you see on-screen and the code objects of the
toolkit. The whole ethos of OOP is that each object is like an 
independent

mini-program responding to events/messages from other objects.
GUI windows reflect that model - a dialog box acts like a mini app
within the parent app and sends data back to it...


Does anyone have or know of a good tutorial or explanation of class
based coding that I could have a run at?


Try my tutor. It has topics on both OOP and GUIs.
And before doing the GUI one also  read the event-driven topic because
GUIs are, without exception, event-driven frameworks. Most folks find
the shift to thinking in terms of events harder than the shift to 
objects.
But thinking in events makes objects more natural, so they are 
connected.


--
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Problem with "yaml load"

2010-12-13 Thread Alan Gauld


"Sean Carolan"  wrote


a python dictionary.  I am able to do this by dumping my data into a
temporary file and then importing it with yaml.load.  I would like 
to

see if I can eliminate the temporary file and import the data
directly.


You could use a stringIO buffer. It acts like an in-memory file.
Of course your data needs to fit in memory to use that!

HTH,

--
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Tab delimited question

2010-12-13 Thread Alan Gauld


"Ben Ganzfried"  wrote

def test(infile, outfile):
 for line in infile:
   tagIndex = line.find("key")
   start = tagIndex + 4
   stop = line[start:].find("\t") -1
   if tagIndex != -1:
   print("start is: ", start)
   print("stop is: ", stop)
   print("spliced word is ", line[start: stop])

My question is the following: What is wrong w/ the variable 'stop'?
The index it gives me when I print out 'stop' is not even close to 
the

right number.


Some clues would be good - like the programs output?
And its hard to tell where the \t characters are in an email,
so knowing what find is looking at would help too.


Furthermore, when I try to print out just the word
following the tag w/ the form: line[start: stop], it prints nothing
(it seems b/c my stop variable is incorrect).


If stop is wrong that seems likely. Is it possible there is a tab in
there that you didn't expect? Have you tried printing all the
character codes of all whitespace? Or replacing all tabs
with 'TAB' say?


HTH,



___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Tab delimited question

2010-12-13 Thread Joel Goldstick
On Mon, Dec 13, 2010 at 1:55 PM, Ben Ganzfried wrote:

> I'm searching line by line for certain tags and then printing the tag
> followed by the word immediately following the tag.
>
> So for example, suppose I had the following line of text in a file:
>


> mystring = "this   is  a   key test123 noisenoise  noise
> noise   noise"
>

you can get the words in a list with

mylist = mystring.split()

You can get the index of 'key' with

mylist.index('key')

So the next value is the one you want


Python 2.6.5 (r265:79063, Apr 16 2010, 13:09:56)
[GCC 4.4.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> s = "this   is  a   key test123 noisenoise  noise
noise   noise"
>>> a = s.split()
>>> a
['this', 'is', 'a', 'key', 'test123', 'noise', 'noise', 'noise', 'noise',
'noise']
>>> a.index('key')
3
>>> mystuff = a[a.index('key') + 1]
>>> mystuff
'test123'
>>>



>
> In this example, I would want to print "key test123" to a new file.
> The rest of the words I would not want.
>
> Here is my code so far:
>
> def test(infile, outfile):
>  for line in infile:
>tagIndex = line.find("key")
>start = tagIndex + 4
>stop = line[start:].find("\t") -1
>if tagIndex != -1:
>print("start is: ", start)
>print("stop is: ", stop)
>print("spliced word is ", line[start: stop])
>
> My question is the following: What is wrong w/ the variable 'stop'?
> The index it gives me when I print out 'stop' is not even close to the
> right number.  Furthermore, when I try to print out just the word
> following the tag w/ the form: line[start: stop], it prints nothing
> (it seems b/c my stop variable is incorrect).
>
> I would greatly appreciate any help you have.  This is a much
> simplified example from the script I'm actually writing, but I need to
> figure out a way to eliminate the noise after the key and the word
> immediately following it are found.
>
> Thank you very much for any help you can provide.
>
> Ben
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>



-- 
Joel Goldstick
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] gui coding

2010-12-13 Thread Wayne Werner
On Mon, Dec 13, 2010 at 2:08 PM, Alan Gauld wrote:

> 
>
>> Does anyone have or know of a good tutorial or explanation of class
>> based coding that I could have a run at?
>>
>
> Try my tutor. It has topics on both OOP and GUIs.
> And before doing the GUI one also  read the event-driven topic because
> GUIs are, without exception, event-driven frameworks. Most folks find
> the shift to thinking in terms of events harder than the shift to objects.
> But thinking in events makes objects more natural, so they are connected.


I think the thing that helped me most was in my assembly class where I
actually created an event-driven painting program using non-blocking calls
to check the keyboard, etc.

That may be part of why GUI programming was so easy for me to pick up (and
as an extension, threading).

-Wayne
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Tab delimited question

2010-12-13 Thread Martin A. Brown

Greetings Ben,

 : I'm searching line by line for certain tags and then printing the 
 : tag followed by the word immediately following the tag.

What you are describing is an awful lot like 'grep'.  But, of 
course, many different sorts of file searching resemble grep.

 : So for example, suppose I had the following line of text in a file:
 : "thisis  a   key test123 noisenoise  noise   noise   
noise"
 : 
 : In this example, I would want to print "key test123" to a new 
 : file. The rest of the words I would not want.
 : 
 : Here is my code so far:
 : 
 : def test(infile, outfile):
 :   for line in infile:
 : tagIndex = line.find("key")
 : start = tagIndex + 4
 : stop = line[start:].find("\t") -1
 : if tagIndex != -1:
 : print("start is: ", start)
 : print("stop is: ", stop)
 : print("spliced word is ", line[start: stop])

Your problem is that you are calculating the value for 'stop' from a 
subset of the 'line string (and then subtracting 1), though you want 
to be adding the value of 'start'.  Replace your above line which 
performs assignment on the stop variable with the following.

  stop = line[start:].find("\t") + start

 : My question is the following: What is wrong w/ the variable 
 : 'stop'? The index it gives me when I print out 'stop' is not even 
 : close to the right number.  Furthermore, when I try to print out 
 : just the word following the tag w/ the form: line[start: stop], 
 : it prints nothing (it seems b/c my stop variable is incorrect).

Now, think about why this is happening

You are calculating 'stop' based on a the substring of 'line'.  You 
use the 'start' offset to create a substring, in which you then 
search for a tab.  Then, you subtract 1 and try to use that to mean 
something in the original string 'line.  Finally, you are slicing 
incorrectly (well, that's just the issue of subtracting 1 when you 
shouldn't be), a not uncommon slicing problem (see this post for 
more detail [0]).

Finally, I have to wonder why are you doing so much of the work 
yourself, when 

 : I would greatly appreciate any help you have.  This is a much 
 : simplified example from the script I'm actually writing, but I 
 : need to figure out a way to eliminate the noise after the key and 
 : the word immediately following it are found.

I realize that your question was not like the above, but in your 
example, it seems that you don't know about the 'csv' module.  It's 
convenient, simple, easy to use and quite robust.  This should help 
you.  I don't know much about your data format, nor why you are 
searching, but let's assume that you are searching where you wish to 
match 'key' as the contents of an entire field.  If that's the case, 
then:

  import sys
  import csv

  def test(infile,outfile,sought):
  tsv = csv.reader(infile, delimiter='\t')
  for row in tsv:
  if sought in row:
  outfile.write(  '\t'.join( row ) + '\n' )

Now, how would you call this function?

  if __name__ == '__main__':
  test(sys.stdin, sys.stdout, sys.argv[1])

And, suppose you were at a command line, how would you call that?

  python tabbed-reader.py  < "$MYFILE" 'key'

OK, so the above function called 'test' is probably not quite what 
you had wanted, but you should be able to adapt it pretty readily.

Good luck,

-Martin

 [0] http://mail.python.org/pipermail/tutor/2010-December/080592.html

-- 
Martin A. Brown
http://linux-ip.net/
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Help with using the ctypes module

2010-12-13 Thread Luke Paireepinart
I confess I don't know a lot about C so I may be off base here... But it looks 
like your c func extendarray returns a pointer to the new extended array, but 
you are not capturing this pointer in your python when you call the c func. So 
the python code is pointing at  the old deallocated array.

Does that make sense and/or point you in the right direction?

-
Sent from a mobile device with a bad e-mail client.
-

On Dec 13, 2010, at 10:27 AM, Sachin Kamboj  wrote:

> Hi All,
> 
> I was trying to use the ctypes module for a project. I was creating a 
> dynamically allocated array of "max_entries" pairs and once the array was 
> exhausted, I was creating a new array of size (1.5 * max_entries) and copying 
> the contents from the old array to the new array. 
> 
> Unfortunately, when I try to access the contents of this new_array, I get a 
> "NULL pointer access" exception. The corresponding C code seems to work 
> perfectly. (See code below.)
> 
> I was wondering if I was missing something about the way the ctypes module 
> works. Any help would be greatly appreciated. (Not sure if this is the 
> appropriate mailing list for my question.)
> 
> /Thanks!
> 
> ---
> 
> #!/usr/bin/env python
> 
> from ctypes import *
> import math
> import random
> 
> 
> class PAIR(Structure):
> _fields_ = [("a", c_long),
> ("b", c_long)]
> 
> 
> class MY_ARR(Structure):
> _fields_ = [("no_entries", c_longlong),
> ("max_entries", c_longlong),
> ("entries", POINTER(POINTER(PAIR)))
> ]
> 
> def extendArray(x):
> print "Extending Array"
> print "Before: %d/%d" % (x.no_entries, x.max_entries)
> old_arr = x.entries
> 
> # Create a new array
> new_max_entries = int(math.ceil(1.5 * x.max_entries))
> x.entries = (POINTER(PAIR) * new_max_entries)()
> 
> # Copy the entries from the old array to the new array
> for i in range(x.no_entries):
> x.entries[i] = old_arr[i]
> 
> x.max_entries = new_max_entries
> print "After: %d/%d" % (x.no_entries, x.max_entries)
> return x
> 
> def printPair(x):
> print x.contents.a, x.contents.b
> 
> def printArray(x):
> print "Printing %d/%d Entries" % (x.no_entries, x.max_entries)
> for i in range(x.no_entries):
> printPair(x.entries[i])
> 
> 
> if __name__ == "__main__":
> x = MY_ARR(0, 10, (POINTER(PAIR) * 10)())
> for i in range(100):
> if x.no_entries == x.max_entries:
> print "\n\nPrinting Before Extension"
> printArray(x)
> 
> extendArray(x)
> 
> print "\n\nPrinting After Extension"
> printArray(x)
> 
> my_pair = PAIR(i, random.randint(0, 100))
> x.entries[x.no_entries] = pointer(my_pair)
> x.no_entries += 1
> 
> printPair(x.entries[i])
> 
> printArray(x)
> 
> ---
> Now unfortunately, when I try to run this code, I am getting a "NULL pointer 
> access" exception:
> 
> $ python TestExtension.py 
> 0 40
> 1 40
> 2 11
> 3 36
> 4 82
> 5 73
> 6 93
> 7 100
> 8 75
> 9 80
> 
> 
> Printing Before Extension
> Printing 10/10 Entries
> 0 40
> 1 40
> 2 11
> 3 36
> 4 82
> 5 73
> 6 93
> 7 100
> 8 75
> 9 80
> Extending Array
> Before: 10/10
> After: 10/15
> 
> 
> Printing After Extension
> Printing 10/15 Entries
> Traceback (most recent call last):
>   File "TestExtension.py", line 55, in 
> printArray(x)
>   File "TestExtension.py", line 42, in printArray
> printPair(x.entries[i])
>   File "TestExtension.py", line 37, in printPair
> print x.contents.a, x.contents.b
> ValueError: NULL pointer access
> 
> ---
> 
> The corresponding C code works perfectly:
> 
> #include 
> #include 
> #include 
> 
> typedef struct {
> long a;
> long b;
> } pair;
> 
> typedef struct {
> long long no_entries;
> long long max_entries;
> pair **entries;
> } my_arr;
> 
> my_arr *extend_array(my_arr *x) {
> int i;
> pair **old_entries = x->entries;
> long long new_max_entries = ceil(1.5 * x->max_entries);
> 
> printf("Extending Array\n");
> printf("Before: %lld/%lld\n", x->no_entries, x->max_entries);
> 
> x->entries = malloc(sizeof(pair *) * new_max_entries);
> for (i = 0; i < 100; ++i) {
> x->entries[i] = old_entries[i];
> }
> x->max_entries = new_max_entries;
> free(old_entries);
> 
> printf("After: %lld/%lld\n", x->no_entries, x->max_entries);
> return x;
> }
> 
> void print_pair(pair *p) {
> printf("%ld\t%ld\n", p->a, p->b);
> }
> 
> void print_array(my_arr *x) {
> int i;
> printf("Printing %lld/%lld entries\n", x->no_entries, x->max_entries);
> for (i = 0; i < x->no_entries; ++i) {
> print_pair(x->entries[i]);
> }
> }
> 
> int main(int argc, char *argv[])
> {
> int i;
> my_arr x = {
> 0, 
> 1

Re: [Tutor] The Template Pattern

2010-12-13 Thread Steven D'Aprano

Karim wrote:


Hello all,

I am seeking for information about the template pattern applied to python.
Could you explain some implementation or anything else? it would be 
helpful.


Design patterns are means to an end, not an end in themselves. You 
shouldn't say "I want to use the template pattern", you should say "I 
want to solve this problem, what solution is appropriate?" and then only 
use the template pattern if it is appropriate.


In any case, the template design pattern is one of the simpler design 
patterns. Here's an example, adapted from Wikipedia's article on the 
Template Method Pattern:



class AbstractGame:
"""An abstract class that is common to several games in which
players play against the others, but only one is playing at a
given time.
"""
def __init__(self, *args, **kwargs):
if self.__class__ is AbstractGame:
raise TypeError('abstract class cannot be instantiated')

def playOneGame(self, playersCount):
self.playersCount = playersCount
self.initializeGame()
j = 0
while not self.endOfGame():
self.makePlay(j)
j = (j + 1) % self.playersCount
self.printWinner()

def initializeGame(self):
raise TypeError('abstract method must be overridden')

def endOfGame(self):
raise TypeError('abstract method must be overridden')

def makePlay(self, player_num):
raise TypeError('abstract method must be overridden')

def printWinner(self):
raise TypeError('abstract method must be overridden')


Now to create concrete (non-abstract) games, you subclass AbstractGame 
and override the abstract methods.


class Chess(AbstractGame):
def initializeGame(self):
# Put the pieces on the board.
...

def makePlay(player):
# Process a turn for the player
...

etc.




--
Steven
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] making onthefly attributes persistent

2010-12-13 Thread Jojo Mwebaze
On Mon, Dec 13, 2010 at 8:44 PM, Alan Gauld wrote:

>
> "Jojo Mwebaze"  wrote
>
>  Assuming i have a class bank as below .
>>
>> class bank(object):
>>  def __init__(self, bal=0):
>>  self.bal = bal
>>  def deposit(self, amount):
>>  self.bal+=amount
>>  print self.bal
>>
>> I define a method debit - which i add to the class onthefly
>>
>> bank.debit = debit
>>
>>
>> #I can also add an attribute owner
>>
>> myaccount.owner = 'jojo'
>>
>
>  My problem is how to make the added attributes, 'owner' and 'debit'
>> persistent automatically
>>
>
> If that's your only problem with this approach congratulations!
> How does your orther code know when/if these dynamic
> operations/data exist so as to use them? If they just assume
> they exist then why not just add them in the definition. Even as nulls?
>
> While Python allows you to dynamically add features to classes/objects
> its not something I would recommend unless you have a really good
> reason - not least because you bring upon yourself all sorts of problems!
>
> If you are determined to do so you can make the objects persistent
> using the approach I outline on my tutorial but adding a loop to cycle
> over the contents of dir(). But you may find that recovering the
> objects - especially if they have a mixed set of attribnutes - presents
> even more problems...
>
> IMHO This is a feature of python that should be considered unorthodox
> and only to be used when no other approach will work!
>
> HTH,
>
>
>

Thanks Allan for the feedback, the idea is to write a method like store() on
the object, that probably looks up all these changes and commits them into
the database.

Please let me know where to find approach you propose in your tutorial. I
read your tutorial when i was just initiated to python, a reference would be
helpful to help me find the soln without hustle.

Cheers





> --
> Alan Gauld
> Author of the Learn to Program web site
> http://www.alan-g.me.uk/
>
>
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] The Template Pattern

2010-12-13 Thread Karim

On 12/13/2010 11:47 PM, Steven D'Aprano wrote:

Karim wrote:


Hello all,

I am seeking for information about the template pattern applied to 
python.
Could you explain some implementation or anything else? it would be 
helpful.


Design patterns are means to an end, not an end in themselves. You 
shouldn't say "I want to use the template pattern", you should say "I 
want to solve this problem, what solution is appropriate?" and then 
only use the template pattern if it is appropriate.




Steven, thank you for answering ;o)

I don't want to use this pattern absolutely. But I discussed this topic 
with a C++ programmer.
He wanted to translate part of C++ code in python that implements this 
pattern in C++.
I already have implemented a Strategy pattern in python to read 
different file format into

my database and generate different output format file like the code below:

class Input(object):
"""The basic Input class, leaving out the details of the algorithm."""
def __init__( self, strategy ):
self.strategy = strategy
self.lastRead = None

def read(self, filePath):
"""Load into database memory an input file.
@arg: filePath - string - The input file path.
@return: The created database object.
"""
self.lastRead = self.strategy.read()
return self.lastRead


class InputStrategy( object ):
"""This InputStrategy class is an abstract interface to various
read strategy objects.
"""
def read(self, filePath):
"""Abstract method to load into database memory an input file.
@arg: filePath - string - The input file path.
@return: The created database object.
"""
raise NotImplementedError

By the way, I use NotImplementedError in my abstract method of the 
abstract class. You are using TypeError exception.

Is there a general rule for that? NotImplementedError is ok?

I knew from Java experience that template method pattern is only a kind 
of particular case of Stategy where you delegate
parts of algorithm by abstract methods overriding. Indeed the base class 
implements some common features and let

derived classes implement particular parts by polymorphism.
Now with your example, I don't understand why he had problems to 
implement from C++ ?

Or perhaps is he mixing it with C++ feature template  ?!

In any case, the template design pattern is one of the simpler design 
patterns. Here's an example, adapted from Wikipedia's article on the 
Template Method Pattern:



class AbstractGame:
"""An abstract class that is common to several games in which
players play against the others, but only one is playing at a
given time.
"""
def __init__(self, *args, **kwargs):
if self.__class__ is AbstractGame:
raise TypeError('abstract class cannot be instantiated')

def playOneGame(self, playersCount):
self.playersCount = playersCount
self.initializeGame()
j = 0
while not self.endOfGame():
self.makePlay(j)
j = (j + 1) % self.playersCount
self.printWinner()

def initializeGame(self):
raise TypeError('abstract method must be overridden')

def endOfGame(self):
raise TypeError('abstract method must be overridden')

def makePlay(self, player_num):
raise TypeError('abstract method must be overridden')

def printWinner(self):
raise TypeError('abstract method must be overridden')


Now to create concrete (non-abstract) games, you subclass AbstractGame 
and override the abstract methods.


class Chess(AbstractGame):
def initializeGame(self):
# Put the pieces on the board.
...

def makePlay(player):
# Process a turn for the player
...

etc.



One more Thanks for you example Steven!
Regards
Karim
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] making onthefly attributes persistent

2010-12-13 Thread ALAN GAULD
The OOP topic in my tutor has a section on persisting objects 
by writing them to a text file. The basic principle being that 
each subclass only persists the attributes that it adds and 
relies on the superclass to persist itself.

In this case you would have to do someting like get the save() 
method to return the list of attributes persisted. Then the bottom 
subclass could see what all the superclasses had saved and 
only save any new attributes not in that list. 

The trick is unwinding that when you come to restore your 
objects. You will need to store the data as name/value pairs so 
that you can read the dynamic attributes, then use setattr() 
or similar to create them dynamically again. The problem is 
how do you know that nobody has created a subclass below 
the bottom level?!" So that leaves you trying to read the entire 
list of attributes in at once at the top level and restore them
which breaks the concept of objects only knowing about their 
own data...

Its all a bit messy, it is so much easier if you don't use 
dynamic attributes.

 Alan Gauld
Author of the Learn To Program website
http://www.alan-g.me.uk/



>
>From: Jojo Mwebaze 
>To: Alan Gauld 
>Cc: tutor@python.org
>Sent: Monday, 13 December, 2010 22:50:49
>Subject: Re: [Tutor] making onthefly attributes persistent
>
>
>
>
>On Mon, Dec 13, 2010 at 8:44 PM, Alan Gauld  wrote:
>
>
>>"Jojo Mwebaze"  wrote
>>
>>
>>Assuming i have a class bank as below .
>>>
>>>class bank(object):
>>> def __init__(self, bal=0):
>>> self.bal = bal
>>> def deposit(self, amount):
>>> self.bal+=amount
>>> print self.bal
>>>
>>>I define a method debit - which i add to the class onthefly
>>>
>>>
bank.debit = debit
>>>
>>>
>>>#I can also add an attribute owner
>>>
>>>myaccount.owner = 'jojo'
>>>
>
>My problem is how to make the added attributes, 'owner' and 'debit'
>>persistent automatically
>>

If that's your only problem with this approach congratulations!
>How does your orther code know when/if these dynamic
>operations/data exist so as to use them? If they just assume
>they exist then why not just add them in the definition. Even as nulls?
>
>While Python allows you to dynamically add features to classes/objects
>its not something I would recommend unless you have a really good
>reason - not least because you bring upon yourself all sorts of problems!
>
>If you are determined to do so you can make the objects persistent
>using the approach I outline on my tutorial but adding a loop to cycle
>over the contents of dir(). But you may find that recovering the
>objects - especially if they have a mixed set of attribnutes - presents
>even more problems...
>
>IMHO This is a feature of python that should be considered unorthodox
>and only to be used when no other approach will work!
>
>HTH,
>
>
>


Thanks Allan for the feedback, the idea is to write a method like store() on 
the 
object, that probably  looks up all these changes and commits them into the 
database.

Please let me know where to find approach you propose in your tutorial. I read 
your tutorial when i was just initiated to python, a reference would be helpful 
to help me find the soln without hustle.

Cheers



 
-- 
>Alan Gauld
>Author of the Learn to Program web site
>http://www.alan-g.me.uk/
>
>
>___
>Tutor maillist  -  Tutor@python.org
>To unsubscribe or change subscription options:
>http://mail.python.org/mailman/listinfo/tutor
>
>___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Writing to the terminal?

2010-12-13 Thread Bill Allen
Anyone know how to get WConio.putch() to properly put out a box drawing
character to the screen in the while at a cmd prompt?   The code page is
437, but it when I tell it to put out 188, for example, it get a 1/4
character instead of the box drawing character.

I am using WConio.putch(188)

I have it WConio through the whole 0 thru 256 range
import WConio
for i in range(0,257):
 WConio.putch(i)

and get:

♫☼►◄↕‼¶§▬↨↑↓→←∟↔▲▼
!"#$%&'()*+,-./0123456789:;<=>?...@abcdefghijklmnopqrstuvwxyz[\]^_`abcdefghijklmnopqrstuvwxyz{|}~⌂??
?? 
¡¢£☼¥▌§"cª«¬-r_°±²3'µ¶·,1º»¼½_¿ÄÅÆÇEÉEEDÑÖxOUUUÜY_ßàáâaäåæçèéêëìíîïdñòóôoö÷oùúûüy_ÿA

However if at the cmd prompt, out side of Python, I give it an Alt-188 I get
the correct  ╝

Where am I going wrong?

Thanks,
Bill Allen




On Mon, Dec 13, 2010 at 12:53 PM, Bill Allen  wrote:

> Alan,
>
> Oh wow!   I was not aware of the WConio module.   That is exactly what I
> have been needing!
>
>
>
> Thanks,
> Bill Allen
>
>
>
>
> On Sun, Dec 12, 2010 at 6:49 PM, Alan Gauld wrote:
>
>>
>> "Modulok"  wrote
>>
>>  For more complex stuff, (think blue screens with little white boxes
>>> you press spacebar to activate. Kind of like an OS installer) I would
>>> look into the `curses` module in the standard library?
>>>
>>
>> curses on Unix but its not in the std library for windows.
>>
>> I think there is a version you can download, and there are also
>> libraries specifically for the PC terminal, one that I've used
>> successfully being Wconio, based on the Borland Turbo-C
>> console I/O package conio.h.
>>
>> Conio is on Sourceforge.
>>
>> HTH,
>>
>>
>>
>> --
>> Alan Gauld
>> Author of the Learn to Program web site
>> http://www.alan-g.me.uk/
>>
>>
>> ___
>> Tutor maillist  -  Tutor@python.org
>> To unsubscribe or change subscription options:
>> http://mail.python.org/mailman/listinfo/tutor
>>
>
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Writing to the terminal?

2010-12-13 Thread ALAN GAULD
I'm no expert, but you probably need to tell Python which character set to use.


 Alan Gauld
Author of the Learn To Program website
http://www.alan-g.me.uk/



>
>From: Bill Allen 
>To: Alan Gauld 
>Cc: *tutor python 
>Sent: Tuesday, 14 December, 2010 1:08:05
>Subject: Re: [Tutor] Writing to the terminal?
>
>Anyone know how to get WConio.putch() to properly put out a box drawing 
>character to the screen in the while at a cmd prompt?   The code page is 437, 
>but it when I tell it to put out 188, for example, it get a 1/4 character 
>instead of the box drawing character.   
>
>
>I am using WConio.putch(188)
>
>I have it WConio through the whole 0 thru 256 range 
>import WConio
>for i in range(0,257):
> WConio.putch(i)
>
>and get:
>
>♫☼►◄↕‼¶§▬↨↑↓→←∟↔▲▼ 
>!"#$%&'()*+,-./0123456789:;<=>?...@abcdefghijklmnopqrstuvwxyz[\]^_`abcdefghijklmnopqrstuvwxyz{|}~⌂??
>
>?? 
>¡¢£☼¥▌§"cª«¬-r_°±²3'µ¶·,1º»¼½_¿ÄÅÆÇEÉEEDÑÖxOUUUÜY_ßàáâaäåæçèéêëìíîïdñòóôoö÷oùúûüy_ÿA
>
>
>However if at the cmd prompt, out side of Python, I give it an Alt-188 I get 
>the 
>correct  ╝
>
>Where am I going wrong?   
>
>Thanks,
>Bill Allen
>
>
>
>
>
>On Mon, Dec 13, 2010 at 12:53 PM, Bill Allen  wrote:
>
>Alan,
>>
>>Oh wow!   I was not aware of the WConio module.   That is exactly what I have 
>>been needing!
>>
>>
>>
>>Thanks,
>>Bill Allen
>>
>>
>>
>>
>>
>>On Sun, Dec 12, 2010 at 6:49 PM, Alan Gauld  wrote:
>>
>>
>>>"Modulok"  wrote
>>>
>>>
>>>For more complex stuff, (think blue screens with little white boxes
you press spacebar to activate. Kind of like an OS installer) I would
look into the `curses` module in the standard library?

>>
curses on Unix but its not in the std library for windows.
>>>
>>>I think there is a version you can download, and there are also
>>>libraries specifically for the PC terminal, one that I've used
>>>successfully being Wconio, based on the Borland Turbo-C
>>>console I/O package conio.h.
>>>
>>>Conio is on Sourceforge.
>>>
>>>HTH,
>>>
>>>
>>>
>>>-- 
>>>Alan Gauld
>>>Author of the Learn to Program web site
>>>http://www.alan-g.me.uk/
>>>
>>>
>>>___
>>>
>>>Tutor maillist  -  Tutor@python.org
>>>To unsubscribe or change subscription options:
>>>http://mail.python.org/mailman/listinfo/tutor
>>>
>>
>___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor