Re: [Tutor] hardware specs from python on OSX

2006-11-08 Thread Alan Gauld

"Yi Qiang" <[EMAIL PROTECTED]> wrote
> I am trying to get some basic information about the computer's
> hardware specs in OSX in python.  In linux I can get most of what I
> need from the /proc filesystem.  Is there an equivalent in OSX?

OSX is just BSD Unix so most things will be available in /proc.
What happens when you try it?

> not, where else can I get information about the system from?  I need
> CPU model, # of cpus, cpu speed, physical memory, etc.

But I'm not sure if that specific info is available.

The NSProcessInfo class also provides a lot of information,
but mainly about the OS version etc, but it might have CPU
details too, check the docs...

HTH,

Alan G. 


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


[Tutor] Help needed to install SOAPpy

2006-11-08 Thread Asrarahmed Kadri
Hi Folks,I want to install the SOAPpy module on my windows box. I have python2.4.3Can you help me with the steps and the URL from where can I get thedownload..??TIA.
Regards,Asrarahmed 
 
 
-- To HIM you shall return. 
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Help needed to install SOAPpy

2006-11-08 Thread Christopher Arndt
Asrarahmed Kadri schrieb:
> I want to install the SOAPpy module on my windows box. I have python
> 2.4.3
> 
> Can you help me with the steps and the URL from where can I get the
> download..??

What have you tried so far? Did you google for "SOAPpy download"?
Are you experiencing any problems?

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


[Tutor] module mx.DateTime

2006-11-08 Thread Antonios Katsikadamos
hi all folks. i am running python2.4 on suse linux and i would like to install the module mx.DateTime. does anyone know how i can install it?thanks for any help,Antonios 


Sponsored Link
Mortgage rates near 39yr lows. $420,000 Mortgage for $1,399/mo - Calculate new house payment___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] hardware specs from python on OSX

2006-11-08 Thread Jordan Greenberg
Yi Qiang wrote:
> Hi,
> I am trying to get some basic information about the computer's
> hardware specs in OSX in python.  In linux I can get most of what I
> need from the /proc filesystem.  Is there an equivalent in OSX?  If
> not, where else can I get information about the system from?  I need
> CPU model, # of cpus, cpu speed, physical memory, etc.
> 
> Thanks,
> Yi

Somewhat unsurprisingly, a quick google for "python system information
osx" turned up this recipe in the ActiveState cookbook:
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/303063
which should help.
Looking into the sysctl command might also be useful.

HTH, keep in mind that I'm *NOT* a Mac guy, at all.
Jordan
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] My attempt...Re: Help needed to install SOAPpy

2006-11-08 Thread Asrarahmed Kadri
Here is what I did. 
I searched through Google and found this URL:  http://pywebsvcs.sourceforge.net/soappy.txt . Here it is mentioned that to install teh soappy, there are two modules that need to be installed before we can successfully install teh soappy module. the fist one is pyxml and the other one is fpconst.

I installed the pyxml module, but the link for installing fpconst is not working.
 
Any idea.
 
BEst Regards,
Asrarahmed 
On 11/8/06, Christopher Arndt <[EMAIL PROTECTED]
> wrote: 
Asrarahmed Kadri schrieb:> I want to install the SOAPpy module on my windows box. I have python
> 2.4.3>> Can you help me with the steps and the URL from where can I get the> download..??What have you tried so far? Did you google for "SOAPpy download"?Are you experiencing any problems? 
Chris___Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor -- To HIM you shall return. 
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Help me with installing Soappymodule

2006-11-08 Thread Kent Johnson
Asrarahmed Kadri wrote:
> 
> Hi Folks,
>  
> I want to install SOAPpy module. As stated on 
> http://pywebsvcs.sourceforge.net/soappy.txt, there are two modules that 
> should be installed prior to installing SOAPpy. One in pyXML and the 
> other is fpconst. I installed pyXML from the URL stated on teh above 
> website.
> But the URL for fpconst download is not valid.
>  
> Any idea as to where can I get the module .

Try this one:
http://cheeseshop.python.org/pypi/fpconst/0.7.2

Kent

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


Re: [Tutor] module mx.DateTime

2006-11-08 Thread Christopher Arndt
Antonios Katsikadamos schrieb:
> hi all folks. i am running python2.4 on suse linux and i would like to
> install the module mx.DateTime. does anyone know how i can install it?

If you want to install it from the source code, you need a C compiler and the
Python development package. I don't know exactly, how these packages are called
on suse, but I expect something like "gcc" and "python-devel" or "python-dev".
Then it's the usual unpacking and "python setup.py install".

But probably suse already has rpm packages for mxDateTime. Probably it is
called something like egenix-mxdatetime or egenix-extensions.

Do you have any specific need for mx.DateTime? Nowadays you can do almost
everything you can do with mx.DateTime with the standard library module
"datetime" and "dateutil" from http://labix.org/python-dateutil

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


[Tutor] Can I run multiple python versions on the same machine.. I plan to install Python Enthought Edition

2006-11-08 Thread Asrarahmed Kadri
Hi Folks,
 
Just a quick advice of using Python Enthought Edition along with ActiveState Python.
 
TIA.
 
Regards,
Asrarahmed-- To HIM you shall return. 
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] My attempt...Re: Help needed to install SOAPpy

2006-11-08 Thread tomd
http://www.warnes.net/rwndown

or if that link doesn't work for you, just google it.

-- 
Regards, Tom
http://www.vscripts.net/

on Wed, 8 Nov 2006 11:08:46 +, you wrote:
> I installed the pyxml module, but the link for installing fpconst is not 
> working.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] First real script

2006-11-08 Thread Carlos
Hi Again,

Luke, I left it this way now:

x = A_List[i-1]
y = A_List[i]
z = A_List[(i+1) % A_Len]

Probably the other way is shorter but right now I feel comfortable as it 
is now :-[ , Danny had already mentioned this method before, but it 
didn't sink properly until now. And yes I need it to wrap around because 
if not the behavior changes, at least it happened in my tests.

Now I'm tring to make it possible to choose which rule to use, my first 
idea was:

R_30 = [0,0,0,1,1,1,1,0]
R_110 = [0,1,1,0,1,1,1,0]
R = R_110
rule = {
  (1, 1, 1) : R[0],
  (1, 1, 0) : R[1],
  (1, 0, 1) : R[2],
  (1, 0, 0) : R[3],
  (0, 1, 1) : R[4],
  (0, 1, 0) : R[5],
  (0, 0, 1) : R[6],
  (0, 0, 0) : R[7],
}

I believe that in this way all possible rules could be defined by a 
list. The problem is that I'm going to need 256 lists. What would be 
real nice is to input a number, lets say 30 and have it converted to 
binary notation so it would look like 1110, then add enough zeros to the 
left and end up with 0001110, and finally convert this to a list than 
can be referenced in the dictionary. Here is the code:

#This is a hacked version of 'tobinary' from:
#http://gnosis.python-hosting.com/voting-project/OVC-Demo2/att-0020/convert.py

def tobinary(dec):
"""Convert a decimal number to binary.

Parameters:
dec: The decimal number
"""
   
bin = []
while dec > 0:
bit = int(dec % 2)
bin.insert(0, bit)
dec = (dec - bit)/2
print bin

##This area formats a Bin number between 0 and 255
##so it conforms with CA rules formatting
   
b_len = len(bin)
print 'b_len: ', b_len
while b_len < 8:
bin[0:0] = [0]
b_len = len(bin)
print bin
   

tobinary(30)

Is this a good way to proceed?

Alan, about going 3D, I agree a normal 2D list will do, but I'm really 
afraid of the list wrapping, this time squared (or is it cubed?). I'm 
going to need rules for center, corner and border cells. I'm afraid...

Thanks  a lot,
Carlos
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] python Error: IndentationError: expected an indented block.

2006-11-08 Thread Antonios Katsikadamos
hi all. I am using python 2.4. I have to run an older python code and when i run it i get the following message  IndentationError: expected an indented block.  1)what does this mean? 2)how can i overcome this problem   Thanks for any advice.  kind regards,  Antonios 


Sponsored Link
Free Uniden 5.8GHz Phone System with Packet8 Internet Phone Service___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Unable to run a simple client server code in in SOAPpy... Help me

2006-11-08 Thread Asrarahmed Kadri
 
Hi,
 
I have successfully installed the SOAPpy module. The version is 0.11.6
 
I am trying to run simple test program for server and cliet. The script for server is executing without any error; but the client script is giving me the error as below. 
TRACEBACK:
 
C:\project stuff-programs>python client.pyTraceback (most recent call last):  File "client.py", line 4, in ?    print server.hello()  File "C:\Python24\Lib\site-packages\SOAPpy\Client.py", line 453, in __call__
    return self.__r_call(*args, **kw)  File "C:\Python24\Lib\site-packages\SOAPpy\Client.py", line 475, in __r_call    self.__hd, self.__ma)  File "C:\Python24\Lib\site-packages\SOAPpy\Client.py", line 347, in __call
    config = self.config)  File "C:\Python24\Lib\site-packages\SOAPpy\Client.py", line 187, in call    r.endheaders()  File "C:\Python24\lib\httplib.py", line 798, in endheaders    self._send_output()
  File "C:\Python24\lib\httplib.py", line 679, in _send_output    self.send(msg)  File "C:\Python24\lib\httplib.py", line 646, in send    self.connect()  File "C:\Python24\lib\httplib.py", line 630, in connect
    raise socket.error, msgsocket.error: (10061, 'Connection refused') 
 
#server.py
import SOAPpy
def hello():    return "Hello World"
    server = SOAP.SOAPServer(("localhost", 23000))    server.registerFunction(hello)    server.serve_forever()
# client.py

import SOAPpy
server = SOAPpy.SOAPProxy("http://localhost:23000/")print server.hello()
TIA.
 
 
Best Regards,
Asrarahmed
-- To HIM you shall return. 
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Unable to run a simple client server code in in SOAPpy... Help me

2006-11-08 Thread Luke Paireepinart
Asrarahmed Kadri wrote:
>  
> 
>
> socket.error: (10061, 'Connection refused')
Sounds like your firewall is blocking communication on this port.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] python Error: IndentationError: expected an indented block.

2006-11-08 Thread Kent Johnson
Antonios Katsikadamos wrote:
> hi all. I am using python 2.4. I have to run an older python code and 
> when i run it i get the following message
> 
> IndentationError: expected an indented block.
> 
> 1)what does this mean?
> 2)how can i overcome this problem

Python uses indentation to delimit blocks, for example an if statement 
will be followed by an indented block:

if a < b:
   print 'a is less than b'

One way you can get this error is if you mix tabs and spaces for the 
indent character. Common usage is to use four spaces for an indent. 
Check that your code is consistent in its use of tabs or spaces.

It's also possible that you are just missing a character or two.

Posting actual code and the full error message including the traceback 
might help, though whitespace problems might be hidden in email.

Kent

> 
> 
> Thanks for any advice.
> 
> kind regards,
> 
> Antonios
> 
> 
> Sponsored Link
> 
> Free Uniden 5.8GHz Phone System with Packet8 Internet Phone Service 
> 
> 
> 
> 
> 
> ___
> 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] python error: IndentationError: expected an indented block

2006-11-08 Thread Antonios Katsikadamos
hi all. I try to run an old python code and i get the following messageFile "/home/antonis/db/access.py", line 119    def DoCsubnet1 (action, subject, target, args): # DoC servers net  ^IndentationError: expected an indented block1) and I don't know what causes it. I would be grate full if you could give me a tip.2) how can i overcome it? Can i use the keyword pass?Kind regards,Antonios 


Want to start your own business? Learn how on Yahoo! Small Business.___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] python Error:IndentationError: expected an indented block

2006-11-08 Thread Antonios Katsikadamos
hi all. I try to run an old python code and i get the following message  File "/home/antonis/db/access.py", line 119     def DoCsubnet1 (action, subject, target, args): # DoC servers net   ^ IndentationError: expected an indented block  1) and I don't know what causes it. I would be grate full if you could give me a tip.  2) how can i overcome it? Can i use the keyword pass?and if how ccan i use it   Kind regards,  Antonios 


Sponsored Link
Degrees online in as fast as 1 Yr - MBA, Bachelor's, Master's, Associate - Click now to apply___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] python error: IndentationError: expected an indented block

2006-11-08 Thread Kent Johnson
Antonios Katsikadamos wrote:
> hi all. I try to run an old python code and i get the following message
> 
> File "/home/antonis/db/access.py", line 119
> def DoCsubnet1 (action, subject, target, args): # DoC 
> servers net
>   ^
> IndentationError: expected an indented block
> 
> 1) and I don't know what causes it. I would be grate full if you could 
> give me a tip.

Please show the code at line 119. It is expecting the line you show to 
be indented more than it is.
> 
> 2) how can i overcome it? Can i use the keyword pass?
> 
> 
> Kind regards,
> 
> Antonios
> 
> 
> Want to start your own business? Learn how on Yahoo! Small Business. 
> 
> 
> 
> 
> 
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor


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


Re: [Tutor] Encoding and XML troubles

2006-11-08 Thread William O'Higgins Witteman
Thanks for the help thusfar.  To recap - when parsing XML, ElementTree
is barfing on extended characters.

1. Yes, most XML is written by monkeys, or the programs written by such
monkeys - tough beans, I cannot make my input XML any cleaner without
pre-processing - I am not generating it.

2. The documentation suggests that the default encoding of ElementTree is
US-ASCII, which is not going to be sufficient.  My XML is explicitly
setting its encoding to 8859-1, and the XML is actually well-formed(!).

3. I muddied the waters by talking about Python code listing encoding,
sorry.

EXAMPLES:

Vanilla (this works fine):
#!/usr/bin/python

from elementtree import ElementTree as etree

eg = """redblue"""

xml = etree.fromstring(eg)

If I change the example string to this:
redblué

I get the following error:
xml.parsers.expat.ExpatError: not well-formed (invalid token): line 1,
column 32)

Okay, the default encoding for my program (and thus my example string) 
is US-ASCII, so I'll use 8859-1 instead, adding this line:
# coding: iso-8859-1

I get the same error.  Just for laughs I'll change the encoding to
utf-8.  Oops, I get the same error.

Has anyone had any luck getting ElementTree to deal with extended
characters?  If not, has anyone got a suggestion for how to pre-process
the text in the XML so it won't barf?  Thanks.
-- 

yours,

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


Re: [Tutor] python Error:IndentationError: expected an indented block

2006-11-08 Thread Waving Brain
Use the "pass" keyword like this:


def DoCsubnet1 (action, subject, target, args): # DoC servers net
pass




On 11/8/06, Antonios Katsikadamos <[EMAIL PROTECTED]> wrote:
> hi all. I try to run an old python code and i get the following message
>
>  File "/home/antonis/db/access.py", line 119
>  def DoCsubnet1 (action, subject, target, args): # DoC
> servers net
>^
>  IndentationError: expected an indented block
>
>  1) and I don't know what causes it. I would be grate full if you could give
> me a tip.
>
>  2) how can i overcome it? Can i use the keyword pass?and if how ccan i use
> it
>
>
>  Kind regards,
>
>  Antonios
>
>  
> Sponsored Link
>
>  Degrees online in as fast as 1 Yr - MBA, Bachelor's, Master's, Associate -
> Click now to apply
>
>
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
>
>
>
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Encoding and XML troubles

2006-11-08 Thread Danny Yoo

Vanilla (this works fine):
#!/usr/bin/python

from elementtree import ElementTree as etree

eg = """redblue"""

xml = etree.fromstring(eg)

If I change the example string to this:
redblu�

I get the following error:
xml.parsers.expat.ExpatError: not well-formed (invalid token): line 1,
column 32)



According to:

http://mail.python.org/pipermail/xml-sig/2006-May/011513.html

the XML content must declare itself what encoding it uses.  For example:

#

text = """
\xed\x95\x98\xeb\xa3\xa8\xeb\x8f\x99\xec\x95\x88 
IDLE\xea\xb0\x80\xec\xa7\x80\xea\xb3\xa0 \xeb\x86\x80\xea\xb8\xb0

"""
#

Note that the encoding declaration must be on the top of the document.


Then it's ok to use fromstring() on it:

##

doc = elementtree.ElementTree.fromstring(text)
doc.text

u'\ud558\ub8e8\ub3d9\uc548\nIDLE\uac00\uc9c0\uace0 \ub180\uae30'
##

If I use the wrong encoding declaration, or if I'm missing the declaration 
altogether, then yes, I see the same errors that you seen.



Okay, the default encoding for my program (and thus my example string) 
is US-ASCII, so I'll use 8859-1 instead, adding this line: # coding: 
iso-8859-1


I get the same error.  Just for laughs I'll change the encoding to 
utf-8.  Oops, I get the same error.



The XML encoding has to be explicitely described as part of the XML 
document text.  It's the difference between:


###

text = 'redblu\xe9'
import elementtree.ElementTree
elementtree.ElementTree.fromstring(text)

Traceback (most recent call last):
  File "", line 1, in ?
  File "/usr/lib/python2.4/site-packages/elementtree/ElementTree.py", line 
960, in XML

parser.feed(text)
  File "/usr/lib/python2.4/site-packages/elementtree/ElementTree.py", line 
1242, in feed

self._parser.Parse(data, 0)
xml.parsers.expat.ExpatError: not well-formed (invalid token): line 1, 
column 32

##

and:

##

text = '''

... redblu\xe9'''

doc = elementtree.ElementTree.fromstring(text)

##

which does work.

If you're dealing with XML content, make sure that your XML documents have 
that encoding declaration, or else you're bound to run into these kinds of 
errors.


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


Re: [Tutor] python Error:IndentationError: expected an indented block

2006-11-08 Thread Alan Gauld

"Antonios Katsikadamos" <[EMAIL PROTECTED]> wrote

> hi all. I try to run an old python code and i get the following 
> message
>
> File "/home/antonis/db/access.py", line 119
> def DoCsubnet1 (action, subject, target, args): # 
> DoC servers net
>   ^
> IndentationError: expected an indented block
>
> 1) and I don't know what causes it. I would be grate full if you 
> could give me a tip.
>
> 2) how can i overcome it? Can i use the keyword pass?and if how ccan 
> i use it

Please don't just keep posting the same question over and over.

Kent has already explained what an indentation error is
and asked you to post the actual code plus the error message.

We cannot give you any more help with the data you have
given us. We need to see the code to work out what is wrong.

If the code file is very long then send, say, 10 lines before and
after the line that the error is reported on.

Alan G. 


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


[Tutor] Please help to resolve this...

2006-11-08 Thread Asrarahmed Kadri
Hi,
 
I have successfully installed the SOAPpy module. The version is 0.11.6
 
I am trying to run simple test program for server and cliet. The script for server is executing without any error; but the client script is giving me the error as below. 
TRACEBACK:
 
C:\project stuff-programs>python client.pyTraceback (most recent call last):  File "client.py", line 4, in ?    print server.hello()  File "C:\Python24\Lib\site-packages\SOAPpy\Client.py", line 453, in __call__ 
    return self.__r_call(*args, **kw)  File "C:\Python24\Lib\site-packages\SOAPpy\Client.py", line 475, in __r_call    self.__hd, self.__ma)  File "C:\Python24\Lib\site-packages\SOAPpy\Client.py", line 347, in __call 
    config = self.config)  File "C:\Python24\Lib\site-packages\SOAPpy\Client.py", line 187, in call    r.endheaders()  File "C:\Python24\lib\httplib.py", line 798, in endheaders    self._send_output() 
  File "C:\Python24\lib\httplib.py", line 679, in _send_output    self.send(msg)  File "C:\Python24\lib\httplib.py", line 646, in send    self.connect()  File "C:\Python24\lib\httplib.py", line 630, in connect 
    raise socket.error, msgsocket.error: (10061, 'Connection refused') 
 
#server.py
import SOAPpy
def hello():    return "Hello World"
    server = SOAP.SOAPServer(("localhost", 23000))    server.registerFunction(hello)    server.serve_forever()
# client.py

import SOAPpy
server = SOAPpy.SOAPProxy("http://localhost:23000/")print server.hello()

TIA.
 
 
Best Regards,
Asrarahmed-- To HIM you shall return. 
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Please help to resolve this...

2006-11-08 Thread Andreas Kostyrka
* Asrarahmed Kadri <[EMAIL PROTECTED]> [061108 19:51]:
> Hi,
> 
> I have successfully installed the SOAPpy module. The version is 0.11.6
> 
> I am trying to run simple test program for server and cliet. The script for
> server is executing without any error; but the client script is giving me

Well, the error means that nothing is listening on port 23000 on localhost. 
Firewall?

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


Re: [Tutor] Please help to resolve this...

2006-11-08 Thread Luke Paireepinart
Asrarahmed Kadri wrote:
> Hi,
Asrarahmed:
You posted this exact question only 4 hours ago.
Reposting questions this quickly is an abuse of the mailing list, as far 
as I'm concerned.
If you don't wait at _minimum_ a full day, preferably at least 2, for an 
answer, it just irritates
people and makes it less likely for you to get an answer.
People may completely disregard this question now, just as a matter of 
principle,
so that they don't give you the idea that reposting is appreciated.
Not mad or anything, just informing you.

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


Re: [Tutor] Please help to resolve this...

2006-11-08 Thread Danny Yoo
> *#server.py*
> import SOAPpy
>
>
> def hello():
>   return "Hello World"
>
>   server = SOAP.SOAPServer(("localhost", 23000))
>   server.registerFunction(hello)
>   server.serve_forever()

Hi Asrarahmed,

I also want to reiterate what Luke said: it does get a little irritating 
if we see the same question repeated.  Try reading:

 http://catb.org/esr/faqs/smart-questions.html

to get a better feel for what kind of things help us answer your questions 
better.


Have you tried running server.py?  There's a glaring error in it. (Hint: 
SOAP != SOAPpy)

I know it might sound silly, but just to make sure you understand: the 
server must be up and running before you try contacting it with the 
client.

Also, you may want to reconsider SOAPpy: we've had previous discussion 
where it was apparent SOAPpy is a dead project:

 http://mail.python.org/pipermail/tutor/2006-November/050530.html
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Please help to resolve this...

2006-11-08 Thread Danny Yoo
>> def hello():
>>   return "Hello World"
>>
>>   server = SOAP.SOAPServer(("localhost", 23000))
>>   server.registerFunction(hello)
>>   server.serve_forever()
>
> Have you tried running server.py?  There's a glaring error in it. (Hint: SOAP 
> != SOAPpy)


Actually, there's a much more glaring error in it.  Note the early exit 
from 'return "hello world".  The program is escaping out too quickly.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Questions about PIL

2006-11-08 Thread Chris Hengge
I'm trying to figure out how to compare im1 to im2 and recognize the difference. I dont care what the difference is... something likeif im1 is not im2: print "Not same"I've tried im.tostring
() but that doesn't ever enter the loop either. ***Second question is this:Is there a way to divide the screen so I only grab maybe the lower right 200x200 pixels or some such?
Or possibly a way to seperate the image into a grid so I could just take the grid I wanted?Thanks!
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Questions about PIL

2006-11-08 Thread Luke Paireepinart
Chris Hengge wrote:
> I'm trying to figure out how to compare im1 to im2 and recognize the 
> difference. I dont care what the difference is...
>
> something like
>
> if im1 is not im2:
>  print "Not same"
Hey, Chris.
I'm supposing here that you are checking if the images are _visually_ 
different,
not if they are different objects or files.

Remember when we were talking about the VNC?
Specifically, the line
diff = ImageChops.difference(self.prevscr,self.currscr)
that I sent to you?

To sum it up, in the ImageChops module,
(which comes with PIL)
there's a function called difference that returns a list with the 
different pixel values for each coordinate of the image.

I would suggest the following course of action:
1) Check if the file format is the same.  If it's a PNG vs a JPG vs a 
BMP or whatever, the compression routines
will have an effect on the image, so your difference test won't work.
2) Check if the resolution is the same.  If one's 640X480 and the 
other's 800X600, you're going to have a difference.
3) do the following ( or something equivalent):
from ImageChops import difference
alist = difference(image1,image2)
a = [b for b in alist.getdata() if b != (0,0,0)]
if len(a) != 0:
print "Not the same"
>
> I've tried im.tostring () but that doesn't ever enter the loop either.
I have no idea what 'that doesn't ever enter the loop' means.
>
> ***
> Second question is this:
> Is there a way to divide the screen so I only grab maybe the lower 
> right 200x200 pixels or some such?
> Or possibly a way to seperate the image into a grid so I could just 
> take the grid I wanted?
You're referring to when you're using ImageGrab.grab() I assume,
but you should have said this.  It's better to be explicit than 
implicit, after all :)

Yes, it's possible to grab only part of the screen.
ImageGrab.grab(), if you read the help information on it,
says that it takes a bbox argument with a default value of none.
so override this value with your own bounding box.
I.E. ImageGrab.grab((0,0,200,200)) will grab a square from the 
upper-left corner of the screen.

Separating the image into a grid would also be quite easy.
If you have an Image instance, just use its crop method to get the area 
you want.
example:
import Image
im = Image.open('test.bmp')
im.crop((0,0,200,200)).save('test.bmp')

Should overwrite the old image with a new one.

Also, note that the code:
ImageGrab.grab().crop((0,0,200,200))
is equivalent to
ImageGrab.grab((0,0,200,200))

In other words,
the ImageGrab always takes  a screenshot of the entire working area.
so if you're expecting this bounding-box to speed anything up, it won't.

HTH,
-Luke

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

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


Re: [Tutor] Questions about PIL

2006-11-08 Thread Danny Yoo


On Wed, 8 Nov 2006, Chris Hengge wrote:

> I'm trying to figure out how to compare im1 to im2 and recognize the
> difference. I dont care what the difference is...
>
> something like
>
> if im1 is not im2:
>print "Not same"

Do not use 'is' here.  It is not doing any kind of equality testing at 
all.  We had a discussion about 'is' just a few days ago:

 http://mail.python.org/pipermail/tutor/2006-November/050680.html

According to:

 http://www.pythonware.com/library/pil/handbook/image.htm

the im.getdata() function looks interesting.


> I've tried im.tostring() but that doesn't ever enter the loop either.

This should have worked.  I'm not sure if you tried comparing 
two strings using 'is' or not.

> Second question is this:
> Is there a way to divide the screen so I only grab maybe the lower right
> 200x200 pixels or some such?
> Or possibly a way to seperate the image into a grid so I could just take the
> grid I wanted?

im.transform() from the documentation link above looks relevant.  Is that 
what you're looking for?
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Questions about PIL

2006-11-08 Thread Chris Hengge
Thanks for the detailed examples again Luke. Sorry I wasn't more clear with my implimentation. The loop I was refering to was the one in the start of my post but using im.tostring() instead. I saw an example to make a webcam motion detector that used tostring(), but couldn't get the program to see a difference.
As for just capturing a section of the screen. I'm not looking to make faster captures, so I think your sample was on the ball. Your example however wasn't quite what I had in mind when I was thinking up the question and again I take fault for this. I was thinking more of a way to create quadrants of the screenshot. (Or any number of area's) that I could independantly interact with. I know this isn't a CPU friendly task, but just humor me please =P
On 11/8/06, Luke Paireepinart <[EMAIL PROTECTED]> wrote:
Chris Hengge wrote:> I'm trying to figure out how to compare im1 to im2 and recognize the> difference. I dont care what the difference is...>> something like>> if im1 is not im2:
>  print "Not same"Hey, Chris.I'm supposing here that you are checking if the images are _visually_different,not if they are different objects or files.Remember when we were talking about the VNC?
Specifically, the linediff = ImageChops.difference(self.prevscr,self.currscr)that I sent to you?To sum it up, in the ImageChops module,(which comes with PIL)there's a function called difference that returns a list with the
different pixel values for each coordinate of the image.I would suggest the following course of action:1) Check if the file format is the same.  If it's a PNG vs a JPG vs aBMP or whatever, the compression routines
will have an effect on the image, so your difference test won't work.2) Check if the resolution is the same.  If one's 640X480 and theother's 800X600, you're going to have a difference.3) do the following ( or something equivalent):
from ImageChops import differencealist = difference(image1,image2)a = [b for b in alist.getdata() if b != (0,0,0)]if len(a) != 0:print "Not the same">> I've tried im.tostring
 () but that doesn't ever enter the loop either.I have no idea what 'that doesn't ever enter the loop' means.>> ***
> Second question is this:> Is there a way to divide the screen so I only grab maybe the lower> right 200x200 pixels or some such?> Or possibly a way to seperate the image into a grid so I could just
> take the grid I wanted?You're referring to when you're using ImageGrab.grab() I assume,but you should have said this.  It's better to be explicit thanimplicit, after all :)Yes, it's possible to grab only part of the screen.
ImageGrab.grab(), if you read the help information on it,says that it takes a bbox argument with a default value of none.so override this value with your own bounding box.I.E. ImageGrab.grab((0,0,200,200)) will grab a square from the
upper-left corner of the screen.Separating the image into a grid would also be quite easy.If you have an Image instance, just use its crop method to get the areayou want.example:import Image
im = Image.open('test.bmp')im.crop((0,0,200,200)).save('test.bmp')Should overwrite the old image with a new one.Also, note that the code:ImageGrab.grab().crop((0,0,200,200))is equivalent to
ImageGrab.grab((0,0,200,200))In other words,the ImageGrab always takes  a screenshot of the entire working area.so if you're expecting this bounding-box to speed anything up, it won't.HTH,-Luke
> Thanks!> >> ___> Tutor maillist  -  
Tutor@python.org> http://mail.python.org/mailman/listinfo/tutor>
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Questions about PIL

2006-11-08 Thread Chris Hengge
I tried the .tostring again, seems to be working using != instead of is not... Thanks for that thread link, very helpful. I'll look more into im.transform and see what I can come up with. I'm not sure I fully understand what it does, but I'm reading it as I'll remove the wanted section of im and trash the rest. I'm more-so looking for a way to maybe divide an image into quantrants for individual manipulation without having to split and rebuild the image. 
My goal with these two features is I'd like to create a way to compare an image for changes based on an area of the image, rather then the entire image. Lets use the quadrants for example (mental code). 1,2
3,4^ this is how the quad appears on the image (upper left, upper right, etc...)for space in quad:    if newpic[space].tostring() != oldpic[space].tostring():   oldpic[space] = newpic[space]
    else :   # Dont really care because this [space] isn't important.    On 11/8/06, Danny Yoo <
[EMAIL PROTECTED]> wrote:On Wed, 8 Nov 2006, Chris Hengge wrote:
> I'm trying to figure out how to compare im1 to im2 and recognize the> difference. I dont care what the difference is...>> something like>> if im1 is not im2:>print "Not same"
Do not use 'is' here.  It is not doing any kind of equality testing atall.  We had a discussion about 'is' just a few days ago: 
http://mail.python.org/pipermail/tutor/2006-November/050680.htmlAccording to: http://www.pythonware.com/library/pil/handbook/image.htm
the im.getdata() function looks interesting.> I've tried im.tostring() but that doesn't ever enter the loop either.This should have worked.  I'm not sure if you tried comparingtwo strings using 'is' or not.
> Second question is this:> Is there a way to divide the screen so I only grab maybe the lower right> 200x200 pixels or some such?> Or possibly a way to seperate the image into a grid so I could just take the
> grid I wanted?im.transform() from the documentation link above looks relevant.  Is thatwhat you're looking for?
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Drawing simple graphics objects

2006-11-08 Thread Kristinn Didriksson

Hello,
This is one of the questions in Python Programming by Zelle. Ch 5, #1b.
The problem calls for the program to create a new square at the mouse  
click instead of moving the square as in the previous problem.
I have tried various ways to tackle the problem with no success. Any  
help would be greatly be appreciated.


This is the code that works for the previous example and moved the  
square at the mouse click:

--
# Modify the example in the book to program to draw a square instead  
of a circle.

# Interactive graphics program to draw a square

from graphics import *

def main():

win = GraphWin()
shape = Rectangle(Point(50,50), Point(20,20))
shape.setOutline("red")
shape.setFill("red")
shape.draw(win)
for i in range(10):
p = win.getMouse()
c = shape.getCenter()
dx = p.getX() - c.getX()
dy = p.getY() - c.getY()
shape.move(dx,dy)
win.close()
main()

#This one worked without too much trouble. All I had to do was change  
the object to be

# drawn to a square!
--
This is the mess i got myself into with the next problem. Please note  
that I initially tried to move the shape.draw(win) object to the  
beginning of the loop and I got an error that said:

Traceback (most recent call last):
  File "/Users/krissd/Desktop/python/code_zelle/chapter5/1a.py",  
line 21, in 

main()
  File "/Users/krissd/Desktop/python/code_zelle/chapter5/1a.py",  
line 14, in main

shape.draw(win)
  File "/Users/krissd/Desktop/python/code_zelle/chapter5/ 
graphics.py", line 280, in draw

if self.canvas: raise GraphicsError, OBJ_ALREADY_DRAWN
graphics.GraphicsError: ('O', 'b', 'j', 'e', 'c', 't', ' ', 'c', 'u',  
'r', 'r', 'e', 'n', 't', 'l', 'y', ' ', 'd', 'r', 'a', 'w', 'n')

230-152:~/Desktop/python/code_zelle/chapter5 krissd$

Second program:
This one draws squares, but not of the same dimensions as the first  
and not with the center at the mouse click.

-
# Modify the example in the book to program to draw a square instead  
of a circle.

# Additionally, have a new square drawn each time the mouse is clicked.

from graphics import *

def main():

win = GraphWin()
shape = Rectangle(Point(50,50), Point(20,20))
shape.setOutline("red")
shape.setFill("red")
shape.draw(win)
for i in range(10): gui
p = win.getMouse()
c = shape.getCenter()
dx = p.getX() # - c.getX()
dy = p.getY() # - c.getY()
shape = Rectangle(Point(dx,dx),Point(dy,dy))
shape.setOutline("red")
shape.setFill("red")
shape.draw(win)
win.close()
main()

#This is turning out trickier than I thought!
# I have gotten close.  It redraws the square, but not with the same  
dimensions

# at a different location determined by the mouse click.
# I am barking up the wrong tree with this effort


I have attached the graphics package that is used in the program for  
reference.# graphics.py
"""Simple object oriented graphics library

The library is designed to make it very easy for novice programmers to
experiment with computer graphics in an object oriented fashion. It is
written by John Zelle for use with the book "Python Programming: An
Introduction to Computer Science" (Franklin, Beedle & Associates).

LICENSE: This is open-source software released under the terms of the
GPL (http://www.gnu.org/licenses/gpl.html).

PLATFORMS: The package is a wrapper around Tkinter and should run on
any platform where Tkinter is available.

INSTALLATION: Put this file somewhere where Python can see it.

OVERVIEW: There are two kinds of objects in the library. The GraphWin
class implements a window where drawing can be done, and various
GraphicsObjects are provided that can be drawn into a GraphWin. As a
simple example, here is a complete program to draw a circle of radius
10 centered in a 100x100 window:


from graphics import *

def main():
win = GraphWin("My Circle", 100, 100)
c = Circle(Point(50,50), 10)
c.draw(win)

main()

GraphWin objects support coordinate transformation through the
setCoords method and pointer-based input through getMouse.

The library provides the following graphical objects:
Point
Line
Circle
Oval
Rectangle
Polygon
Text
Entry (for text-based input)
Image

Various attributes of graphical objects can be set such as
outline-color, fill-color and line-width. Graphical objects also
support moving and hiding for animation effects.

DOCUMENTATION: For complete documentation, see Chapter 5 of "Python
Programming: An Introduction to Computer Science" by John Zelle,
published by Franklin, Beedle & Ass

Re: [Tutor] Questions about PIL

2006-11-08 Thread Chris Hengge
alist = difference(image1,image2)a = [b for b in alist.getdata() if b != (0,0,0)]if len(a) != 0:    print "Not the same"is much slower then (9x)if im1.tostring() != im2.tostring()   print "something changed!"
This loop itself is fairly slow by itself though.. I'm going to try and see if there is a faster way. On 11/8/06, Luke Paireepinart <
[EMAIL PROTECTED]> wrote:Chris Hengge wrote:> I'm trying to figure out how to compare im1 to im2 and recognize the
> difference. I dont care what the difference is...>> something like>> if im1 is not im2:>  print "Not same"Hey, Chris.I'm supposing here that you are checking if the images are _visually_
different,not if they are different objects or files.Remember when we were talking about the VNC?Specifically, the linediff = ImageChops.difference(self.prevscr,self.currscr)that I sent to you?
To sum it up, in the ImageChops module,(which comes with PIL)there's a function called difference that returns a list with thedifferent pixel values for each coordinate of the image.I would suggest the following course of action:
1) Check if the file format is the same.  If it's a PNG vs a JPG vs aBMP or whatever, the compression routineswill have an effect on the image, so your difference test won't work.2) Check if the resolution is the same.  If one's 640X480 and the
other's 800X600, you're going to have a difference.3) do the following ( or something equivalent):from ImageChops import differencealist = difference(image1,image2)a = [b for b in alist.getdata() if b != (0,0,0)]
if len(a) != 0:print "Not the same">> I've tried im.tostring () but that doesn't ever enter the loop either.I have no idea what 'that doesn't ever enter the loop' means.>
> ***> Second question is this:> Is there a way to divide the screen so I only grab maybe the lower> right 200x200 pixels or some such?
> Or possibly a way to seperate the image into a grid so I could just> take the grid I wanted?You're referring to when you're using ImageGrab.grab() I assume,but you should have said this.  It's better to be explicit than
implicit, after all :)Yes, it's possible to grab only part of the screen.ImageGrab.grab(), if you read the help information on it,says that it takes a bbox argument with a default value of none.so override this value with your own bounding box.
I.E. ImageGrab.grab((0,0,200,200)) will grab a square from theupper-left corner of the screen.Separating the image into a grid would also be quite easy.If you have an Image instance, just use its crop method to get the area
you want.example:import Imageim = Image.open('test.bmp')im.crop((0,0,200,200)).save('test.bmp')Should overwrite the old image with a new one.Also, note that the code:ImageGrab.grab().crop((0,0,200,200))
is equivalent toImageGrab.grab((0,0,200,200))In other words,the ImageGrab always takes  a screenshot of the entire working area.so if you're expecting this bounding-box to speed anything up, it won't.
HTH,-Luke> Thanks!> >> ___> Tutor maillist  -  
Tutor@python.org> http://mail.python.org/mailman/listinfo/tutor>
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Questions about PIL

2006-11-08 Thread Luke Paireepinart
Chris Hengge wrote:
> alist = difference(image1,image2)
> a = [b for b in alist.getdata() if b != (0,0,0)]
> if len(a) != 0:
>print "Not the same"
>
> is much slower then (9x)
>
> if im1.tostring() != im2.tostring()
>print "something changed!"
>
> This loop itself is fairly slow by itself though.. I'm going to try 
> and see if there is a faster way.
Chris,
are you sure you know what a loop is?
The only loop here is in the list comprehension.
'if' is not a loop.
'for' and 'while' are.
In computer science, it's important to be clear in your use of terminology.

It makes sense that my example was slow.
I didn't really think to try converting them to strings.

Any time you're trying to compare pixel values, it's going to take a while,
cause remember, a 1024X768 image has 786,432 different pixels.
I think your tostring comparison may be your best bet.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Questions about PIL

2006-11-08 Thread Luke Paireepinart
Chris Hengge wrote:
> Thanks for the detailed examples again Luke. Sorry I wasn't more clear 
> with my implimentation. The loop I was refering to was the one in the 
> start of my post but using im.tostring() instead. I saw an example to 
> make a webcam motion detector that used tostring(), but couldn't get 
> the program to see a difference.
I'm glad the examples helped.
See my other response about your use of the term 'loop.'
>
> As for just capturing a section of the screen. I'm not looking to make 
> faster captures, so I think your sample was on the ball. Your example 
> however wasn't quite what I had in mind when I was thinking up the 
> question and again I take fault for this. I was thinking more of a way 
> to create quadrants of the screenshot. (Or any number of area's) that 
> I could independantly interact with. I know this isn't a CPU friendly 
> task, but just humor me please =P 
Once again, you're not being explicit enough in explaining what you're 
trying to do.
Specifically, your sentence "(Or any number of area's) that I could 
independently interact with"
How are you trying to interact with them?
Do you want them split into actual separate image files, into separate 
image objects, or what?
The crop method I showed you will do any kind of splitting you want,
you just have to think through what exactly you need to crop in any 
given situation.
For example,
(pseudocode)

width = 1024/2
height = 768/2
image = load_image('imagename')
quad1 = image.crop((0,0,width,height))
quad2 = image.crop((width,0,width,height))
quad3 = image.crop((0,height,width,height))
quad4 = image.crop((width,height,width,height))

note that width and height are the w/h of the quadrants, not of the 
image itself.
since there are 4 quadrants (get it? quad = 4 ;)
each width/height would be original_image_ * (.5)

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