[Tutor] using os module on windows

2008-02-20 Thread Timmie
Dear list,
I have some problems using the os module on windows. I kindly ask you do give me
advice why os.remove and os.shutil fail here:

### using remove

## 
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import shutil
import os

## config ##
source = 'C:/my/local/directory'
dest = 'Z:/my/network/drive'
## start action
#os.remove(dest)

## error output
Traceback (most recent call last):
  File "test_os_on_win", line 14, in 
os.remove(dest)
WindowsError: [Error 5] Zugriff verweigert: 'Z:/my/network/drive'



 using shutil


 
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import shutil
import os

## config ##
source = 'C:/my/local/directory'
dest = 'Z:/my/network/drive'
## start action

shutil.copytree(source, dest)




Traceback (most recent call last):
  File "test_os_on_win", line 17, in 
shutil.copytree(source, dest)
  File "C:\python\lib\shutil.py", line 110, in copytree
os.makedirs(dst)
  File "C:\python\lib\os.py", line 172, in makedirs
mkdir(name, mode)
WindowsError: [Error 183] Eine Datei kann nicht erstellt werden, wenn sie
bereits vorhanden ist: 'Z:/my/network/drive'

Thanks in advance an dkind regards,
Timmie

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


Re: [Tutor] using os module on windows

2008-02-20 Thread Kent Johnson
Timmie wrote:

> ## config ##
> source = 'C:/my/local/directory'
> dest = 'Z:/my/network/drive'
> ## start action
> #os.remove(dest)
> 
> ## error output
> Traceback (most recent call last):
>   File "test_os_on_win", line 14, in 
> os.remove(dest)
> WindowsError: [Error 5] Zugriff verweigert: 'Z:/my/network/drive'

os.remove() removes files, is Z:/my/network/drive a file or a directory?
os.rmdir() removes *empty* directories IIRC.
shutir.rmtree() will remove an entire directory tree and the files in it.

> #!/usr/bin/env python
> # -*- coding: utf-8 -*-
> import shutil
> import os
> 
> ## config ##
> source = 'C:/my/local/directory'
> dest = 'Z:/my/network/drive'
> ## start action
> 
> shutil.copytree(source, dest)
> 
> Traceback (most recent call last):
>   File "test_os_on_win", line 17, in 
> shutil.copytree(source, dest)
>   File "C:\python\lib\shutil.py", line 110, in copytree
> os.makedirs(dst)
>   File "C:\python\lib\os.py", line 172, in makedirs
> mkdir(name, mode)
> WindowsError: [Error 183] Eine Datei kann nicht erstellt werden, wenn sie
> bereits vorhanden ist: 'Z:/my/network/drive'

The destination path should not already exist, it should end with the 
directory you want to create. Did you read the docs for copytree()? They 
say, "The destination directory, named by dst, must not already exist; 
it will be created as well as missing parent directories."

Try shutil.copytree(source, os.path.join(dest, 'copy_of_c'))

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


Re: [Tutor] Silly question: Modifying code while the script is running

2008-02-20 Thread Luke Paireepinart
Scott Wolcott wrote:
> Okay, I've got this ircbot that i wrote in python, and while we were 
> all making Terminator jokes, it occurred to me that it would actually 
> be reletively easy to have redqueen (that's the bot) write code into 
> another file. Then you just have to specify the file and import the 
> code and run it. It sounds possible, but there are a couple of things 
> i'm not sure how to do.
If you have your script write properly-formatted python to a .py file, 
you can just import() the script it writes, and reload() it whenever you 
make changes.  imported scripts are automatically executed.  (I assume 
on reload they are also, but you should check this.)
This is considered taboo unless it's very necessary, but I hope you have 
fun anyway.
Let me know how it goes.
HTH,
-Luke

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


Re: [Tutor] using os module on windows

2008-02-20 Thread Timmie
Thanks for your reply!

> The destination path should not already exist, it should end with the 
> directory you want to create. Did you read the docs for copytree()? They 
> say, "The destination directory, named by dst, must not already exist; 
> it will be created as well as missing parent directories."
Which command do you recommend if the destination already exists?
I'd like to overwrite or sychronise a local with a remote directory and
therefore the destinations files already exist.

Regards,
Timmie

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


Re: [Tutor] How to deal with a thread that doesn't terminate

2008-02-20 Thread Tony Cappellini
Thanks Michael.



On Feb 19, 2008 11:23 PM, Michael Langford <[EMAIL PROTECTED]> wrote:
> Instead of using a thread, you could see if you could use a second
> process. For instance, the following would work on windows (and is
> killable).
>
> import subprocess
> import win32api
>
> class SpawnController(object):
> def __init__(self,cmd):
> self.cmdline = cmd
>
> def start(self):
> self.process = subprocess.Popen([self.cmdline])
>
> def stop(self):
> win32api.TerminateProcess(int(self.process._handle), -1
>
>--michael
>
>
> On Feb 19, 2008 4:53 PM, Tony Cappellini <[EMAIL PROTECTED]> wrote:
> > When I executing a program external to the main program in a thread,
> > and that thread hangs, can the thread be terminated?
> > How does one handle this situation?
> > ___
> > Tutor maillist  -  Tutor@python.org
> > http://mail.python.org/mailman/listinfo/tutor
> >
>
>
>
> --
> Michael Langford
> Phone: 404-386-0495
> Consulting: http://www.RowdyLabs.com
>
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] DATA TYPES

2008-02-20 Thread Toby
As I understand it python is not a strongly typed language so no declaration
of variables is necessary.  My question is this:

If I use a variable in a program that stores certain numbers and I'm porting
it to say ... java where I must first declare the variables before I use
them how do I find out what type to give that variable, specifically is
there a way to identify the type of a variable used in a python program for
reference?

What I'm saying is if I have used a certain variable to hold literally
dozens of different values and I BELIEVE them all to be integers but I'm not
entirely sure that I have not stumbled into the float realm is there a way
to have python list all variables contained in a program and tell me what
type it has internally stored them as?  I realize I could trudge through the
entire 1000 lines and check all the variables and see what values I have
assigned them one at a time but I'm wondering if there is an easier way to
get that data?


Thanks

Toby

-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf
Of [EMAIL PROTECTED]
Sent: Wednesday, February 20, 2008 1:23 AM
To: tutor@python.org
Subject: Tutor Digest, Vol 48, Issue 48

Send Tutor mailing list submissions to
tutor@python.org

To subscribe or unsubscribe via the World Wide Web, visit
http://mail.python.org/mailman/listinfo/tutor
or, via email, send a message with subject or body 'help' to
[EMAIL PROTECTED]

You can reach the person managing the list at
[EMAIL PROTECTED]

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Tutor digest..."


Today's Topics:

   1. Re: reading webpage (Kent Johnson)
   2. Re: Change mouse cursor position (bob gailer)
   3. Re: Change mouse cursor position (Flaper87)
   4. Re: Change mouse cursor position (bob gailer)
   5. Re: Change mouse cursor position (Michael Langford)
   6. How to deal with a thread that doesn't terminate (Tony Cappellini)
   7. Re: How to deal with a thread that doesn't terminate (bob gailer)
   8. Re: How to deal with a thread that doesn't terminate
  (Tony Cappellini)
   9. Re: How to deal with a thread that doesn't terminate (bob gailer)
  10. Re: How to deal with a thread that doesn't terminate (John Fouhy)
  11. Re: Putting the Output of Help to a File (Justin Ezequiel)
  12. Re: How to deal with a thread that doesn't terminate
  (Michael Langford)


--

Message: 1
Date: Tue, 19 Feb 2008 07:46:48 -0500
From: Kent Johnson <[EMAIL PROTECTED]>
Subject: Re: [Tutor] reading webpage
To: "Guess?!?" <[EMAIL PROTECTED]>
Cc: tutor@python.org
Message-ID: <[EMAIL PROTECTED]>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed

Guess?!? wrote:
> Hi Kent,
>  
> Broken machine gives
>  
> IDLE 1.2.1 
>  >>> import urllib
>  >>> print urllib.getproxies()
> {'http': 'http://proxy-address:port' }
>  >>>
>  
> correct machine gives empty dictionary ... { }

Well that is the problem. Now you have to fix it. The proxy comes either 
from the environment variable HTTP_PROXY or from the Windows registry, I 
think it is the proxyServer value of the key 
Software\Microsoft\Windows\CurrentVersion\Internet Settings
but I'm not on Windows and this is no longer a Python question so that 
is as far as I will take it.

Kent


--

Message: 2
Date: Tue, 19 Feb 2008 08:56:50 -0500
From: bob gailer <[EMAIL PROTECTED]>
Subject: Re: [Tutor] Change mouse cursor position
To: Flaper87 <[EMAIL PROTECTED]>
Cc: Tutor@python.org
Message-ID: <[EMAIL PROTECTED]>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed

Flaper87 wrote:
> Hey Guys!!!
>
> is it possible to change the mouse position by passing it the coords?
>
> I'm developing an application that needs to be able to change the 
> cursor's possition.
We need more information. Is this a GUI application? If so which GUI 
software? Or are you trying to control the mouse in another application?
>
> O.S. Linux Debian Sid
> Python: 2.4=<
-- 
Bob Gailer
919-636-4239 Chapel Hill, NC



--

Message: 3
Date: Tue, 19 Feb 2008 16:48:11 +0100
From: Flaper87 <[EMAIL PROTECTED]>
Subject: Re: [Tutor] Change mouse cursor position
To: "bob gailer" <[EMAIL PROTECTED]>
Cc: Tutor@python.org
Message-ID:
<[EMAIL PROTECTED]>
Content-Type: text/plain; charset="iso-8859-1"

it is not a GUI application, i need to be able to change the cursor position
if an event happens.


2008/2/19, bob gailer <[EMAIL PROTECTED]>:
>
> Flaper87 wrote:
> > Hey Guys!!!
> >
> > is it possible to change the mouse position by passing it the coords?
> >
> > I'm developing an application that needs to be able to change the
> > cursor's possition.
> We need more information. Is this a GUI application? If so which GUI
> software? Or are you trying to control the mouse in another application?
> >
> > O.S. Linux Debian Sid

Re: [Tutor] using os module on windows

2008-02-20 Thread Kent Johnson
Timmie wrote:
> Which command do you recommend if the destination already exists?
> I'd like to overwrite or sychronise a local with a remote directory and
> therefore the destinations files already exist.

Delete, then copy. Or use rsync instead of Python...

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


Re: [Tutor] results not quite 100 percent yet

2008-02-20 Thread bhaaluu
As far as I can see, these routines give me the results
I'm looking for. I get a distribution of four negative numbers,
four positive integers in the range 10 to 110, and nothing
is placed in room 6 or room 11:

#!/usr/bin/python

import random

#print "\n"*30

table= [[ 0, 2, 0, 0, 0, 0, 0],# 1
[ 1, 3, 3, 0, 0, 0, 0],# 2
[ 2, 0, 5, 2, 0, 0, 0],# 3
[ 0, 5, 0, 0, 0, 0, 0],# 4
[ 4, 0, 0, 3,15,13, 0],# 5
[ 0, 0, 1, 0, 0, 0, 0],# 6
[ 0, 8, 0, 0, 0, 0, 0],# 7
[ 7,10, 0, 0, 0, 0, 0],# 8
[ 0,19, 0, 0, 0, 8, 0],# 9
[ 8, 0,11, 0, 0, 0, 0],   # 10
[ 0, 0,10, 0, 0, 0, 0],   # 11
[ 0, 0, 0,13, 0, 0, 0],   # 12
[ 0, 0,12, 0, 5, 0, 0],   # 13
[ 0,15,17, 0, 0, 0, 0],   # 14
[14, 0, 0, 0, 0, 5, 0],   # 15
[17, 0,19, 0, 0, 0, 0],   # 16
[18,16, 0,14, 0, 0, 0],   # 17
[ 0,17, 0, 0, 0, 0, 0],   # 18
[ 9, 0, 0,16, 0, 0, 0]]   # 19

# Distribute the treasure
J = 0
while J <= 3:
T = int(random.random()*19)+1
if T == 6:
continue
if T == 11:
continue
if T == 13:
continue
if table[T-1][6] != 0:
continue
b = range(10,110)
treasure = random.choice(b)
table[T-1][6] = treasure
J += 1

# Place androids/aliens in rooms
J = 4
while J > 0:
T = int(random.random()*19)+1
if T == 6:
continue
if T == 11:
continue
if T == 13:
continue
if table[T-1][6] != 0:
continue
table[T-1][6] = -J
J -= 1

#print dir(table)
for i in range(0,19):
print ("%3d" % table[i][6]), "Rm#",i+1

I simply threw away all the previous attempts that weren't
quite 100% and started over. The final test will be to put
these routines in the old games, and see how they work.
-- 
b h a a l u u at g m a i l dot c o m
"You assist an evil system most effectively by obeying its
orders and decrees. An evil system never deserves such
allegiance.  Allegiance to it means partaking of the evil.
A good person will resist an evil system with his or her
whole soul." [Mahatma Gandhi]
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] DATA TYPES

2008-02-20 Thread Kent Johnson
Toby wrote:
> As I understand it python is not a strongly typed language so no declaration
> of variables is necessary.

Actually Python has strong, dynamic typing but I guess that is a 
discussion for another thread.

> If I use a variable in a program that stores certain numbers and I'm porting
> it to say ... java

Do you know about Jython? Maybe you don't have to port it.

> where I must first declare the variables before I use
> them how do I find out what type to give that variable, specifically is
> there a way to identify the type of a variable used in a python program for
> reference?

Not easily.

> What I'm saying is if I have used a certain variable to hold literally
> dozens of different values and I BELIEVE them all to be integers but I'm not
> entirely sure that I have not stumbled into the float realm is there a way
> to have python list all variables contained in a program and tell me what
> type it has internally stored them as?  I realize I could trudge through the
> entire 1000 lines and check all the variables and see what values I have
> assigned them one at a time but I'm wondering if there is an easier way to
> get that data?

I guess this is possible in principle at least using sys.settrace():
http://docs.python.org/lib/debugger-hooks.html#debugger-hooks

For example CodeInvestigator gathers the information you want, though it 
doesn't present it in the fashion you want. You could look at how they 
do it...the trace module is another example.
http://codeinvestigator.googlepages.com/main
http://docs.python.org/lib/trace-api.html

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


Re: [Tutor] DATA TYPES

2008-02-20 Thread Michael Langford
On Wed, Feb 20, 2008 at 12:41 PM, Toby <[EMAIL PROTECTED]> wrote:
> I have used a certain variable to hold literally
>  dozens of different values and I BELIEVE them all to be integers but I'm not
>  entirely sure that I have not stumbled into the float realm is there a way
>  to have python list all variables contained in a program and tell me what
>  type it has internally stored them as?

fyi, it sounds like you did something bad here. Reusing variables to
stand in for several different things, in general, a bad idea. It is
very confusing to humans (including you, later on). You should try to
keep names alive for a short a distance as possible (there is a metric
for this, called span, which you should try to minimize. There are
tools that help you practice this).

Now Kent can probably testify to as to if this is a good idea (he
knows a lot more about these python innards than I do),  but you can
print out the type of the local variables at the end of your
functions.

i.e.:

for var in locals().copy():
print "varname: %s type: %s" (var,type(var))

After you've done that, you can see what type is referred to by each
name at the end of the function, then with some unit tests you should
be able to tell if you temporarily changed to a different data type in
the middle. If nothing else, you should be able to write the unit
tests in jython/cpython compatable code so you don't have to write
them twice. Or you can absolutely litter your code with this loop and
go through the output for lines that are wrong.

   --Michael

-- 
Michael Langford
Phone: 404-386-0495
Consulting: http://www.RowdyLabs.com
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] DATA TYPES

2008-02-20 Thread Kent Johnson
Michael Langford wrote:
>you can
> print out the type of the local variables at the end of your
> functions.
> 
> i.e.:
> 
> for var in locals().copy():
> print "varname: %s type: %s" (var,type(var))

I was thinking more or less along the same lines, but
- you don't need the copy()
- locals is a dict mapping names to values, so something like
   for name, value in locals().iteritems():
 print "varname: %s type: %s" (name,type(value))
would work better
- Since the OP is trying to find cases where the same variable is 
assigned different types, presumably in a single scope, checking just at 
the end of a function won't help.

> After you've done that, you can see what type is referred to by each
> name at the end of the function, then with some unit tests you should
> be able to tell if you temporarily changed to a different data type in
> the middle. If nothing else, you should be able to write the unit
> tests in jython/cpython compatable code so you don't have to write
> them twice. 

Not sure how you would do that with unit tests?

> Or you can absolutely litter your code with this loop and
> go through the output for lines that are wrong.

That is basically what you could do with settrace(). Rather than 
printing a bunch of output, perhaps maintaining a dict that maps name to 
a set of types would work. settrace() notifies it's target when a scope 
is entered or exited so you could monitor values in each scope 
separately. It gets tricky though, with things like this:
def square(x):
   return x*x

square(1)# x is an integer
square(1+1j) # x is a complex number

or
def foo():
   for i in range(3):
 print i # integer
   for j in range 3:
 i = j/2.0 # different type in a different block but same scope
 print i # float, is this an error?

Bottom line: if you can define clearly what you want, there is probably 
a way to get it with settrace() and locals() but it is not a simple problem.

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


Re: [Tutor] How to deal with a thread that doesn't terminate

2008-02-20 Thread Tiger12506
Similar to the TerminateProcess function in win32api, there is the 
TerminateThread function which you can use if you know the handle of the 
thread, but it seems that you can only get the thread handle if you are 
calling from that thread, or if you were the one who created it (and saved 
the return of CreateThread).  You can get the thread handle with 
GetCurrentThread. (these are all win32api functions)


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


Re: [Tutor] DATA TYPES

2008-02-20 Thread Tiger12506
> As I understand it python is not a strongly typed language so no 
> declaration
> of variables is necessary.  My question is this:
>
> If I use a variable in a program that stores certain numbers and I'm 
> porting
> it to say ... java where I must first declare the variables before I use
> them how do I find out what type to give that variable, specifically is
> there a way to identify the type of a variable used in a python program 
> for
> reference?
>
> What I'm saying is if I have used a certain variable to hold literally
> dozens of different values and I BELIEVE them all to be integers but I'm 
> not
> entirely sure that I have not stumbled into the float realm is there a way
> to have python list all variables contained in a program and tell me what
> type it has internally stored them as?  I realize I could trudge through 
> the
> entire 1000 lines and check all the variables and see what values I have
> assigned them one at a time but I'm wondering if there is an easier way to
> get that data?
import copy

di = copy.copy(globals())
for y, z in di.iteritems():
  print y, "is of type: ",type(z)


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


Re: [Tutor] DATA TYPES

2008-02-20 Thread Tiger12506
> I was thinking more or less along the same lines, but
> - you don't need the copy()

Hehehe, did you try it Kent?

> - locals is a dict mapping names to values, so something like
>   for name, value in locals().iteritems():
> print "varname: %s type: %s" (name,type(value))

And this returns

Traceback (most recent call last):
  File "C:\Documents and Settings\Jacob\Desktop\diction.py", line 2, in 

print "varname: %s type: %s" (name,type(value))
TypeError: 'str' object is not callable

Which is not what I expected!
Until I realized that you are missing the % sign in between the print string 
and the tuple of values to interpolate

Then it returns this:
varname: __builtins__ type: 

Traceback (most recent call last):
  File "C:\Documents and Settings\Jacob\Desktop\diction.py", line 1, in 

for name, value in locals().iteritems():
RuntimeError: dictionary changed size during iteration

The .copy() is necessary. 

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


Re: [Tutor] DATA TYPES

2008-02-20 Thread Kent Johnson
Tiger12506 wrote:

> Hehehe, did you try it Kent?

Obviously not :-)

> Which is not what I expected!
> Until I realized that you are missing the % sign in between the print string 
> and the tuple of values to interpolate

Blame that one on Michael, I copied from him :-)

> Then it returns this:
> varname: __builtins__ type: 
> 
> Traceback (most recent call last):
>   File "C:\Documents and Settings\Jacob\Desktop\diction.py", line 1, in 
> 
> for name, value in locals().iteritems():
> RuntimeError: dictionary changed size during iteration
> 
> The .copy() is necessary. 

Ok. Or use locals().items() which implicitly copies by making a list of 
key, value pairs.

Though I suspect a robust solution will involve inspecting the stack 
frame passed to a sys.settrace() callback, not looking at locals() 
directly...

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


Re: [Tutor] results not quite 100 percent yet

2008-02-20 Thread Tiger12506
> As far as I can see, these routines give me the results
> I'm looking for. I get a distribution of four negative numbers,
> four positive integers in the range 10 to 110, and nothing
> is placed in room 6 or room 11:

I'll throw a couple of thoughts out there since I know that you appreciate 
to see many points of view.

> #!/usr/bin/python
>
> import random
>
> #print "\n"*30
>
> table= [[ 0, 2, 0, 0, 0, 0, 0],# 1
>[ 1, 3, 3, 0, 0, 0, 0],# 2
>[ 2, 0, 5, 2, 0, 0, 0],# 3
>[ 0, 5, 0, 0, 0, 0, 0],# 4
>[ 4, 0, 0, 3,15,13, 0],# 5
>[ 0, 0, 1, 0, 0, 0, 0],# 6
>[ 0, 8, 0, 0, 0, 0, 0],# 7
>[ 7,10, 0, 0, 0, 0, 0],# 8
>[ 0,19, 0, 0, 0, 8, 0],# 9
>[ 8, 0,11, 0, 0, 0, 0],   # 10
>[ 0, 0,10, 0, 0, 0, 0],   # 11
>[ 0, 0, 0,13, 0, 0, 0],   # 12
>[ 0, 0,12, 0, 5, 0, 0],   # 13
>[ 0,15,17, 0, 0, 0, 0],   # 14
>[14, 0, 0, 0, 0, 5, 0],   # 15
>[17, 0,19, 0, 0, 0, 0],   # 16
>[18,16, 0,14, 0, 0, 0],   # 17
>[ 0,17, 0, 0, 0, 0, 0],   # 18
>[ 9, 0, 0,16, 0, 0, 0]]   # 19

Hard-coded. That means you have to change the program to change the game. It 
would not be difficult to store this/read it in from a file, making the same 
program suddenly handle an infinite number of games. (well not infinite, but 
at least 19*7*2147483647)

> # Distribute the treasure
> J = 0
> while J <= 3:
>T = int(random.random()*19)+1
>if T == 6:
>continue
>if T == 11:
>continue
>if T == 13:
>continue
>if table[T-1][6] != 0:
>continue
>b = range(10,110)
>treasure = random.choice(b)
>table[T-1][6] = treasure
>J += 1
>
> # Place androids/aliens in rooms
> J = 4
> while J > 0:
>T = int(random.random()*19)+1
>if T == 6:
>continue
>if T == 11:
>continue
>if T == 13:
>continue
>if table[T-1][6] != 0:
>continue
>table[T-1][6] = -J
>J -= 1

Those two block of code above are SO similar that sure they can be combined 
into one, or at least the first parts of them.

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


Re: [Tutor] designing POOP

2008-02-20 Thread Alan Gauld
"Michael Langford" <[EMAIL PROTECTED]> wrote

> I'm firmly with Kent here: OO programming is not about simulation.

Wooah!
I'm partly on board here and do agree the noun/verb thing is
a gross simplification. But it does work and is how probably
the majority of OOP programmers started out - in the 80's
and 90's at least. Certainly when I started on OOP around 1984
it was the de-facto introduction. And it is a still an effective
way to identify objects if you aren't sure where to start.

But it is not a good way to model software, with that I
agree. But OOP is still about suimulation. A lot of OOP
code - especially on very large scale projects is as close
a simulation as possible to the real world problem as
you can get. If you are going to work on 5-10 million lines
of code you had better organise it according to some
tangible model you can understand or you will have
problems. Performance and efficiency come a long way
behind comprehensibility at that scale. But on more
"normal" projects, say 100K-1 million lines then other
factors come to the fore, and flexibility of design is one
big area where OOP techniques can help.


Unfortunately there seeems to be a lobby at work in OO
these days (indeed in software engineering generally) that
has forgotten about large scale stuff and treats the entire
subject as if it were exclusively about small scale projects.
This is unfortunate because software engineering was
"invented" to tackle the large scale problems not the
small, and this view also fails to recognise the very different
approaches needed to cover both bases. Here in the
Python community we rarely need to think big, I don't
know of any really large projects being done in Python.
But it is important to remember that topics like OOP
cover all areas.


> are not modeling real world items. You are making code easier to
> maintain and making parts of code that have to do with one another 
> be
> near one another.

That's true of any design technique regardless of whether
it is OOP or procedural or even of it's not software at all.
However it's not somerthing that will help a beginner see
objects in their code, especially since the resultant
objects are often of the highly abstract or large grained
variety.

> If you spend all your time trying to make your objects into real 
> world
> things you're actually doing simulation, not programming. As a 
> person
> who's actually done simulation, I'll state that 's not really a 
> great
> way to structure code. You spend a lot of time arguing about highly
> abstract responsibilities of each object in your system, as well as
> how much it will actually model the real world. Neither one is
> especially helpful,

This bit I do agree with. Model the real world to get a feel for
the problem at hand, model the real world as an aid to identifying
potential objects, model the real world while it helps solve the
problem. But don't be a slave to it, you are writing a program to
solve a problem not to model the world. Never forget which is
the tool and which the result.

But OTOH most of the programs I build or design are simulations,
whether of a call centre, a manufacturing plant, a banking system
or a local council, an airport traffic control system or a telephone
switch - and the software invariably reflects that structure.
It does not however model every feature of a PBX, lathe, teller etc
It reflects the attributes of those objects that relate to the 
problem.

> programing. The Why of OO programming today is: To make code more
> maintainable/usable and to group and to use data in such a way the
> human mind can easily grasp all the abstract data types that a 
> program
> operates on.

And the latter point is one area where modelling based on real
world entities can be a big plus. But based on them, not slavishly
reproducing them.

> OO programing came from simulation people. They used a language
> (Simula) to do simulation. It allowed each object to have behavior
> linked to its type.

And it is still used today within the simulation community.
We have a fairly active Simula group at work doingnetwork
analyses.

> Other people saw this (Smalltalk), then copied the system (which 
> they
> were incidentally using to build Smalltalk at first), but not to
> simulate real world objects,

Quite a lot of the early Smalltalk stuff did indeed copy real
world objects but they also saw the potential in modelling
virtual objects like the UI elements. They were using Smalltalk
to teach/experiment with young children by that time and the
correspondence between real objects - like pens - and
computing devices was a beneficial side effect.

> When Bjarne Stroustrup made C++, he copied some of the ideas in 
> order
> to make a better type system, where the functions that operated on a

Yes, although he was actually using the tool to build a simulation.
That's why he started with Simula...

> "Object-oriented programming is programming using inheritance.


I never agreed with Bjarne on tha

Re: [Tutor] DATA TYPES

2008-02-20 Thread Michael Langford
>  - Since the OP is trying to find cases where the same variable is
>  assigned different types, presumably in a single scope, checking just at
>  the end of a function won't help.

This is a starting point to get the type for the variables when you
start the port, before you run the unit tests.

>  > After you've done that, you can see what type is referred to by each
>  > name at the end of the function, then with some unit tests you should
>  > be able to tell if you temporarily changed to a different data type in
>  > the middle. If nothing else, you should be able to write the unit
>  > tests in jython/cpython compatable code so you don't have to write
>  > them twice.
>
>  Not sure how you would do that with unit tests?

You write unit tests for each of your functions that test their input
and output. Presumably, if you used a float somewhere in the middle
there, when you don't use the float in the java implementation, you'll
get a different answer. If you don't get a different answer,
presumably it didn't matter, or your tests don't provide good enough
coverage of the number space. By writing the unit tests in
cPython/Jython compatible code, you'll be able to run the same tests
on both sets of functions and verify you've completed your port.

   ==Michael

PS: Sorry about the missing %, it was there when I ran the code. Don't
know where it went.

-- 
Michael Langford
Phone: 404-386-0495
Consulting: http://www.RowdyLabs.com
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor