[Tutor] using quotes in IDLE

2007-12-13 Thread Jim Morcombe
A really dumb question...

When typing things into IDLE, how are quotes meant to work?

If I type"

employee.name = "Susan"

then IDLE ignores the last " and I get an error.

Jim
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Something I don't understand

2007-12-17 Thread Jim Morcombe
Below, "student_seats" is a list of the class "student".

Why does this code set every student.row to zero when there is only one 
student in the list with row > 5?
It still sets them all to zero if I change the test to ">200" when there are 
no student.rows > 200.
But if I change the test to "<1" then nothing gets set to zero.


Jim


class student:
 def __init__ (self, name, row, column):
 self.name = name
 self.row = row
 self.column = column



for student in student_seats:
print student.name, "row = ", student.row, "column = ", 
student.column
if student.row > 5:
student.row = 0
 print student.name, "row = ", student.row, "column = ", 
student.column

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Oops:

2007-12-17 Thread Jim Morcombe
I solved my last problem.  The data was string data and of course  '1' is > 5.

Now, if I take int(string) the code will work, except it crashes out when the 
data is null.  

student.row = int(student.row)
ValueError: invalid literal for int() with base 10: ''

What is the easiest and recomended way of turning the strings into numerics?

Jim
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Placing entire Application inside a class

2007-12-18 Thread Jim Morcombe
I have just read through "Creating a GUI in Python - by Dakota Lemaster"

In it, Dakota recomends placing the entire application within a class.

Why is this so?  Surely in many cases you end up with a constructor for the 
class that is cumbersome and complex?

Is this a recomended Python programming technique?

http://student-iat.ubalt.edu/sde/students/lemaster/COSC330/Final/sec4_AppClass.html


Why is this so?  Surely in many cases you end up with a constructor for the 
class that is cumbersome and complex?

Is this a recomended Python programming technique?

Jim
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] constants, flags or whatever

2007-12-19 Thread Jim Morcombe
In a program, I want to set some kind of variable or object to indicate what 
"mode" the program is currently in.
What is the most elegant way of doing this?

Jim
---
constant: moving = "m"
constant: inserting = "i"
constant:jumping = "j"
.
.
action = moving
.
.
.
if action == jumping:
jumpSomewhere()
elseif action == moving:
moveSomewhere()
elseif action == inserting:
insertSomething()

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] re-initialising shells

2007-12-20 Thread Jim Morcombe
I have had a couple of strange cases I don't understand.

I am using IDLE on Windows

My program imports some stuff from another file using the statement "from 
qwerty import *"

I have changed qwerty and saved it away.  I have then run my program (F5) and 
the program acts as if it is using an old version of qwerty.

I close down all my python windows, start it again and the changes are picked 
up.

What are the rules with "shells" and so on?

Jim
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Microsoft Access

2007-12-27 Thread Jim Morcombe
Are there any simple tutorials on using MS Access from Python?

Jim
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Microsoft Access

2007-12-27 Thread Jim Morcombe
This tutorial seems very specific to PythonWin IDE.  I haven't tried it, but it 
seems to imply that it uses stuff from PythonWin IDE that may not be available 
in IDLE.  Does PythonWin IDE come with any extras that aren't available in 
standard Python?

  - Original Message - 
  From: Darren Williams 
  To: Jim Morcombe ; tutor@python.org 
  Sent: Friday, December 28, 2007 11:12 AM
  Subject: Re: [Tutor] Microsoft Access


  Typing 'Using MS Access from Python' into Google returned a few results, one 
in particular - http://wwwmarkcarter.me.uk/computing/python/ado.html

  Hope that helps.
- Original Message - 
    From: Jim Morcombe 
To: python tutor mailing list 
Sent: Friday, December 28, 2007 1:38 AM
Subject: [Tutor] Microsoft Access


Are there any simple tutorials on using MS Access from Python?

Jim






___
Tutor maillist  -  Tutor@python.org
http://mail.pythonorg/mailman/listinfo/tutor
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Closing GUI program

2007-12-27 Thread Jim Morcombe
I have copied the following program.  When I run it, (By pressing F5 from 
IDLE), it displays the "Hello world" message.

When I close the window, the "Hello world" message disappears, but it seems 
that the program is still running, because when I close the shell, i get the 
message "The program is still running.  Do you want to kill it?"

How do I get the program to terminate when the window is closed?

Jim
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Closing GUI program

2007-12-27 Thread Jim Morcombe
Oops!  Here's the program:
---
from Tkinter import * 

root = Tk()
z = Label(root, text="Hello World!")
z.grid()
root.mainloop()
--

Jim

  - Original Message ----- 
  From: Jim Morcombe 
  To: python tutor mailing list 
  Sent: Friday, December 28, 2007 3:51 PM
  Subject: [Tutor] Closing GUI program


  I have copied the following program.  When I run it, (By pressing F5 from 
IDLE), it displays the "Hello world" message.

  When I close the window, the "Hello world" message disappears, but it seems 
that the program is still running, because when I close the shell, i get the 
message "The program is still running.  Do you want to kill it?"

  How do I get the program to terminate when the window is closed?

  Jim



--


  ___
  Tutor maillist  -  Tutor@python.org
  http://mail.python.org/mailman/listinfo/tutor
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] destroying windows

2008-06-30 Thread Jim Morcombe

I want to have a program that uses Tkinter to display a window.
If the user selects an option, then I want to destroy that window and 
then display a second window.
In turn, the user can select an option to change back to the first 
window and I want to destroy that window and then display the first again.


I have pasted my code below.  The window is successfully created.  
However, I can't figure out the correct way to destroy it.
In my first attempt, "window1" is not defined when I go to destroy it 
and I am not sure how to make "window1" global or what.


The error is displayed at the bottom of the program listing.

Jim
--

from Tkinter import *

class display_Colour_Selector_window():
   def __init__(self):
   window1 = Tk()
   window1.title("Colour Selector")

   menubar = Menu(window1)

   # create pulldown menus
   editmenu = Menu(menubar, tearoff=0)
   editmenu.add_command(label="Colour Selector", 
command=change_to_Colour_Selector)
   editmenu.add_command(label="Colour Picker", 
command=change_to_Colour_Picker)

   menubar.add_cascade(label="Edit", menu=editmenu)

# display the menu
   window1.config(menu=menubar)



class display_Colour_Picker_window():
   def __init__(self):

   # The second window will be used for the "Colour Picker" which
   # allows the User to pick colours from a colour map.
   window2 = Tk()
   window2.title("Colour Picker")


   menubar = Menu(window2)

  # create pulldown menus
   editmenu = Menu(menubar, tearoff=0)
   editmenu.add_command(label="Colour Selector", 
command=change_to_Colour_Selector)
   editmenu.add_command(label="Colour Picker", 
command=change_to_Colour_Picker)

   menubar.add_cascade(label="Edit", menu=editmenu)


   # display the menu
   window2.config(menu=menubar)



  



def change_to_Colour_Selector():
   display_Colour_Picker_window.window2.destroy
   display_Colour_Selector_window()

  
def change_to_Colour_Picker():

   display_Colour_Selector_window.window1.destroy
   display_Colour_Picker_window()

def hello():
   print "hello!"
  
##

# The program starts here#
##

display_Colour_Selector_window()

  


# To run this from IDLE, I will just comment out the mainloop()
# because IDLE is written in Tkinter and actually has its own mainloop()
# running, which thoroughly confuses my own program.
# mainloop()

---
The error:
IDLE 1.2.1   No Subprocess 
>>>
>>> Exception in Tkinter callback
Traceback (most recent call last):
 File "C:\Python25\lib\lib-tk\Tkinter.py", line 1403, in __call__
   return self.func(*args)
 File "D:/ComputerScienceProgramming/test.py", line 53, in 
change_to_Colour_Picker

   display_Colour_Selector_window.window1.destroy
AttributeError: class display_Colour_Selector_window has no attribute 
'window1'







___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] regular expressions

2008-08-05 Thread Jim Morcombe

Could someone please give me some help using the "re" module.

This works:

import re

text = "Jim is a good guy"

s2 = re.sub('Jim', 'Fred', text)
print s2

and I get "Fred is a good guy"
-
If I have:
text = "Bill Smith is nice"
how do I get rid of "Smith" and just have
"Bill is nice"

I tried
s2 = re.sub('Smith', '', text)
but it complained.

If I have:
text = "Jim likes a girl (Susan)"
and I want to get rid of "(Susan)", how do I do this.

First, the "(" seems to muck things up.
Second, how do I just use "re" to delete characters.  I tried using 
"sub", but it doesn't seem to like


Jim Morcombe




___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] names and variables

2008-08-20 Thread Jim Morcombe

I have an object called "myObject" with an attribute called "colour".

If  I type:
   print myObject.colour
then python prints:
red

Now, I have a variable "myAttribute" and set its value to "colour" by 
typing:

   myAttribute = "colour"

I want to have a line of code:  something like this:
   print myObject.myAttribute
and have Python interpret it as meaning "print myObject.colour" and 
hence print "red"



Can this be done?  If so, how?

Jim Morcombe



___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Calling Python Programs from Word, pdfs, etc

2008-09-04 Thread Jim Morcombe
I am thinking about some long term teaching aids, so I'm simply 
interested in whether these things can be done.  I don't need to know 
how yet.


1.  Is it possible to invoke a Python Program from some kind of link in 
a Word document, similar to the way a Java Applet is run from a Web 
Page.  Obviously I am thinking about a Windows enviroinment only.  (I 
guess I'm probably asking if an exe file can be launched from Winows)


2.  How about from a pdf document?

3.  I've never used any ebook creation software (and this is probably 
not the right place to ask) but does anyone have any experience with 
ebooks that launch Python Applications?


Jim



___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Simple physics simulations)

2008-09-14 Thread Jim Morcombe
I want to write a program that helps teach students how to draw ray 
diagrams for lenses and mirrors. 
Vpython seems to be used for a number of physics simulations, but may be 
overkill for my application.  Although there are a few 3D things I would 
like to do, most just involves drawing curves and simple objects, and 
allowing the User to do the same.


So the question - What is the best thing to use to draw and manipulate 
simple 2D objects in an application like this?


Jim Morcombe


___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Finding the IP address for your own PC

2008-10-12 Thread Jim Morcombe

Hopefully this is an easy one.

How do you get the IP address of the Windows PC that your Python program 
is running on?


Jim Morcombe




___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Multi-User file system

2008-11-01 Thread Jim Morcombe
I want to have a couple of files that can be updated simultaneously be 
several users.  I don't want to go to the effort of having the users set 
up a RDMS and would like to control everything from Python.  I am after 
something like shelve, but with record locking.  Is there such a thing?


Jim Morcombe


___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Multi-User file system

2008-11-01 Thread Jim Morcombe

Would pySQLite be a reasonable choice for this?

Jim Morcombe




Jim Morcombe wrote:
I want to have a couple of files that can be updated simultaneously be 
several users.  I don't want to go to the effort of having the users 
set up a RDMS and would like to control everything from Python.  I am 
after something like shelve, but with record locking.  Is there such a 
thing?


Jim Morcombe


___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor





___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Using Python to replace javascript

2008-11-06 Thread Jim Morcombe
Is there any way to write python code inside a HTML page instead of 
using Javascript?


Jim


___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] cgi scripts

2008-11-07 Thread Jim Morcombe
I want to print a list of the keys and their values passed to a cgi 
script by an HTML form.

I have tried this, but just seems to crash.

Any ideas?

Jim Morcombe


#!C:\python25\python.exe

import cgi, sys
# import cgitb; cgitb.enable()

#Send errors to browser
sys.stderr = sys.stdout

#Parse data from form
data = cgi.FieldStorage()

#Send response to browser
print "Content-type: text/html\n"
print "CGI Form Response\n"
print "This is the data passed to the cgi script"

print "These are the keys\n"
print ""
print for k in data.keys():
   print "key: ", k, "  value: ",  data[k]
  



___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] cgi scripts

2008-11-08 Thread Jim Morcombe

Bt "Crash", I mean the browser displays:


 Internal Server Error

The server encountered an internal error or misconfiguration and was 
unable to complete your request.



The code I sent before had a silly mistake in it.  Here is a better 
example of the things I am trying and failing at.
I can print a single key.  I can iterate over the keys, just printing 
out "hello" for each iteration.
But I can't figure out how to iterate over all the keys printing out 
somethinf sensible.


#!C:\python25\python.exe

import cgi, sys
# import cgitb; cgitb.enable()

#Send errors to browser
sys.stderr = sys.stdout

#Parse data from form
data = cgi.FieldStorage()

#Send response to browser
print "Content-type: text/html\n"
print "CGI Form Response\n"
print "This is the data passed to the cgi script"

# This next bit works and I can see a list of keys displayed in the browser
print "Version 4: data.keys()\n"
print ""
print data.keys()

# This next bit also works and I can see the value of the variable 
"JQuiz_q01_score"

print "-"
print "JQuiz_q01_score = ", data["JQuiz_q01_score"].value

# However, whenever I try to iterate over all the keys, I get the 
"Internal Server error"

print "-"
for k in data.keys():
   print ""data[k].key

#  I have also tried data[k]
#data.key[k]
#data[k].value
#  and many other random combinations.


___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] cgi scripts

2008-11-08 Thread Jim Morcombe

Thanks guys,

This works :)

field_list = '\n'
for field in data.keys():
   field_list = field_list + '%s : %s\n' % (field, 
data[field].value)

field_list = field_list + '\n'
print field_list

I think the problem wasn't in getting the keys and values, but I might 
have been producing illegal HTML code before.

I think I'd better brush up on my HTML skills.

Jim





Alan Gauld wrote:


"Jim Morcombe" <[EMAIL PROTECTED]> wrote

The code I sent before had a silly mistake in it.  Here is a better 
example of the things I am trying and failing at.


Look at what you are doing in the two examples

# This next bit also works and I can see the value of the variable 
print "JQuiz_q01_score = ", data["JQuiz_q01_score"].value


# However, whenever I try to iterate over all the keys, I get the 
print ""data[k].key


Can you see what you are doing differently whwen accessing
the data?

HTH,





___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] cgi scripts

2008-11-10 Thread Jim Morcombe
Actually, that's good to know.  I was thinking it was going to be pretty 
hard to debug if I couldn't tell the difference between HTML errors and 
Python errors.

I have been using
   import cgitb; cgitb.enable()

It seems to re-direct some of the errors to the browser, but obviously 
not all.


Jim



Don Jennings wrote:

Hi, Jim. Actually, improper HTML would cause a problem with the
browser and what it may or may not display. An "Internal Server Error"
does indicate that you had a problem with your code. I suggest
referring back to Alan's post again.

Take care,
Don


  



___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] cgi on novell/Appache

2008-12-02 Thread Jim Morcombe
I have a cgi script that I want to get running on an Apache server 
running under Novel.  I know absolutely nothing about novell.  I need to 
have the first line of the script point to the Python interpretter, but 
have no idea where it is.  (I don't have access to the server to play 
around on it.  I have to change the script, give it to the admin guy and 
let him load it.  He knows nothing about cgi, python, etc. )


What is the novel equivalent of "/usr/bin/python"?

Jim


___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor