Re: [Tutor] Little problem with math module

2008-04-21 Thread Alan Gauld

"Tiago Katcipis" <[EMAIL PROTECTED]> wrote 

> def newton_divergente(x): 
>  return math.pow(x, 1.0/3.0)
> 
> but when x = -20 it returns this error
> 
> return math.pow(x, 1.0/3.0)
> ValueError: math domain error
> 
> but why is that? is it impossible to calculate -20 ^ (1/3) ?

It may be your use of the pow() function:

>>> pow(20, 0.333)
2.7144173455393048
>>> pow(-20, 0.333)
Traceback (most recent call last):
  File "", line 1, in 
ValueError: negative number cannot be raised to a fractional power
>>> -20**0.333
-2.7144173455393048
>>>

So the exponentiation operator seems happy but pow isn't.

Very strange and potentially a bug in pow()? 
Unless someone knows a reason for it?

-- 
Alan Gauld
Author of the Learn to Program web site
http://www.freenetpages.co.uk/hp/alan.gauld



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


[Tutor] Python WSDL Generation Tools

2008-04-21 Thread ryan d'mello
Hi all,

I am using SOAPpy for generating web services .I have also written a client
in python for accessing that web service ,and it works fine.Now when i try
to make a java client to access the web service created in python ,the java
client ask me for a wsdl file which is not present .

So i want to know if there is any way in which i can generate the wsdl file
from existing python module.

thanks in advance.any help will be appreciated.

regards.

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


Re: [Tutor] Little problem with math module

2008-04-21 Thread joe gallo
On Mon, Apr 21, 2008 at 12:07 AM, Alan Gauld <[EMAIL PROTECTED]>
wrote:

>
> >>> pow(20, 0.333)
> 2.7144173455393048
> >>> pow(-20, 0.333)
> Traceback (most recent call last):
>  File "", line 1, in 
> ValueError: negative number cannot be raised to a fractional power
> >>> -20**0.333
> -2.7144173455393048
> >>>
>
> So the exponentiation operator seems happy but pow isn't.
>
> Very strange and potentially a bug in pow()?
> Unless someone knows a reason for it?



I think you're confusing the order of operations.

math.pow(-20, (1.0/3.0)) and -20**(1.0/3.0) are not equivalent

Whereas, as john mentioned, -20**(1.0/3.0) is actually -(20**(1.0/3.0)),
math.pow(-20, (1.0/3.0)) is (-20)**(1.0/3.0)

The behavior of ** is appropriate since
http://docs.python.org/ref/summary.html shows that exponentiation has higher
precedence over positive, negative.

Also, I found this from http://www.python.org/download/releases/2.0/:

*Raise ZeroDivisionError when raising zero to a negative number, e.g. 0.0 **
> -2.0. Note that math.pow is unrelated to the builtin power operator and the
> result of math.pow(0.0, -2.0) will vary by platform. On Linux, it raises a
> ValueError.*


which is related to why some people would get nan and others a ValueError.

And, just to clarify (although i doubt there was any confusion over it),
-20**(1/3) = -1 * (20**0) = -1 due to integer division magic.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Python WSDL Generation Tools

2008-04-21 Thread Kent Johnson
ryan d'mello wrote:
> Hi all,
>  
> I am using SOAPpy for generating web services .I have also written a 
> client in python for accessing that web service ,and it works fine.Now 
> when i try to make a java client to access the web service created in 
> python ,the java client ask me for a wsdl file which is not present .
>  
> So i want to know if there is any way in which i can generate the wsdl 
> file from existing python module.

I found this:
http://osdir.com/ml/python.pywebsvcs.general/2006-07/msg00015.html

I seems to require that you specify parameter types in the docstrings to 
the methods you expose.

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


[Tutor] HTML Parsing

2008-04-21 Thread Stephen Nelson-Smith
Hi,

I want to write a little script that parses an apache mod_status page.

I want it to return simple the number of page requests a second and
the number of connections.

It seems this is very complicated... I can do it in a shell one-liner:

curl 10.1.2.201/server-status 2>&1 | grep -i request | grep dt | {
IFS='> ' read _ rps _; IFS='> ' read _ currRequests _ _ _ _
idleWorkers _; echo $rps $currRequests $idleWorkers   ; }

But that's horrid.

So is:

$ eval `printf '3 requests currently being processed, 17 idle
workers\n 2.82 requests/sec - 28.1 kB/second - 10.0
kB/request\n' | sed -nr '// { N;
s@([0-9]*)[^,]*,([0-9]*).*([0-9.]*)[EMAIL PROTECTED]((\1+\2));[EMAIL 
PROTECTED];
}'`
$ echo "workers: $workers reqs/secs $requests"
workers: 20 reqs/sec 2.82

The page looks like this:



Apache Status

Apache Server Status for 10.1.2.201

Server Version: Apache/2.0.46 (Red Hat)
Server Built: Aug  1 2006 09:25:45

Current Time: Monday, 21-Apr-2008 14:29:44 BST
Restart Time: Monday, 21-Apr-2008 13:32:46 BST
Parent Server Generation: 0
Server uptime:  56 minutes 58 seconds
Total accesses: 10661 - Total Traffic: 101.5 MB
CPU Usage: u6.03 s2.15 cu0 cs0 - .239% CPU load
3.12 requests/sec - 30.4 kB/second - 9.7 kB/request
9 requests currently being processed, 11 idle workers


How can/should I do this?

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


Re: [Tutor] HTML Parsing

2008-04-21 Thread Stephen Nelson-Smith
On 4/21/08, Andreas Kostyrka <[EMAIL PROTECTED]> wrote:
> As usual there are a number of ways.
>
>  But I basically see two steps here:
>
>  1.) capture all dt elements. If you want to stick with the standard
>  library, htmllib would be the module. Else you can use e.g.
>  BeautifulSoup or something comparable.

I want to stick with standard library.

How do you capture  elements?

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


Re: [Tutor] HTML Parsing

2008-04-21 Thread Andreas Kostyrka
As usual there are a number of ways.

But I basically see two steps here:

1.) capture all dt elements. If you want to stick with the standard
library, htmllib would be the module. Else you can use e.g.
BeautifulSoup or something comparable.

2.) Check all dt contents either via regex, or with a .startswith and
string manipulations.

Andreas

Am Montag, den 21.04.2008, 13:35 +0100 schrieb Stephen Nelson-Smith:
> Hi,
> 
> I want to write a little script that parses an apache mod_status page.
> 
> I want it to return simple the number of page requests a second and
> the number of connections.
> 
> It seems this is very complicated... I can do it in a shell one-liner:
> 
> curl 10.1.2.201/server-status 2>&1 | grep -i request | grep dt | {
> IFS='> ' read _ rps _; IFS='> ' read _ currRequests _ _ _ _
> idleWorkers _; echo $rps $currRequests $idleWorkers   ; }
> 
> But that's horrid.
> 
> So is:
> 
> $ eval `printf '3 requests currently being processed, 17 idle
> workers\n 2.82 requests/sec - 28.1 kB/second - 10.0
> kB/request\n' | sed -nr '// { N;
> s@([0-9]*)[^,]*,([0-9]*).*([0-9.]*)[EMAIL PROTECTED]((\1+\2));[EMAIL 
> PROTECTED];
> }'`
> $ echo "workers: $workers reqs/secs $requests"
> workers: 20 reqs/sec 2.82
> 
> The page looks like this:
> 
> 
> 
> Apache Status
> 
> Apache Server Status for 10.1.2.201
> 
> Server Version: Apache/2.0.46 (Red Hat)
> Server Built: Aug  1 2006 09:25:45
> 
> Current Time: Monday, 21-Apr-2008 14:29:44 BST
> Restart Time: Monday, 21-Apr-2008 13:32:46 BST
> Parent Server Generation: 0
> Server uptime:  56 minutes 58 seconds
> Total accesses: 10661 - Total Traffic: 101.5 MB
> CPU Usage: u6.03 s2.15 cu0 cs0 - .239% CPU load
> 3.12 requests/sec - 30.4 kB/second - 9.7 kB/request
> 9 requests currently being processed, 11 idle workers
> 
> 
> How can/should I do this?
> 
> S.
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor


signature.asc
Description: Dies ist ein digital signierter Nachrichtenteil
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] HTML Parsing

2008-04-21 Thread Andreas Kostyrka
Just from memory, you need to subclass the HTMLParser class, and provide
start_dt and end_dt methods, plus one to capture the text inbetween.

Read the docs on htmllib (www.python.org | Documentation | module docs),
and see if you can manage if not, come back with questions ;)

Andreas

Am Montag, den 21.04.2008, 14:40 +0100 schrieb Stephen Nelson-Smith:
> On 4/21/08, Andreas Kostyrka <[EMAIL PROTECTED]> wrote:
> > As usual there are a number of ways.
> >
> >  But I basically see two steps here:
> >
> >  1.) capture all dt elements. If you want to stick with the standard
> >  library, htmllib would be the module. Else you can use e.g.
> >  BeautifulSoup or something comparable.
> 
> I want to stick with standard library.
> 
> How do you capture  elements?
> 
> S.


signature.asc
Description: Dies ist ein digital signierter Nachrichtenteil
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Computing factorial...

2008-04-21 Thread kinuthia muchane
Hi,

I wanted to calculate the factorial of a given number without using
recursion. I came up with the following code, although it is not very
elegant it works. 

def factorial(*args):
 
 product = args[0]
 for item in args[1:]:
 product *= item
 return product
 
number = int(raw_input('Enter value of number to compute factorial  '))
seq = range(1,number + 1)

if number <= 0:
  print -1

else:
 print factorial(*seq)  

When I change that code a bit to (In fact, this is what I started with,
it almost drove me crazy trying to figure out what was wrong!) :

def factorial(*args):
 
 temp = args[0]
 for item in args[1:]:
 product = temp * item
 return product
 
number = int(raw_input('Enter value of number to compute factorial  '))
seq = range(1,number + 1)

if number <= 0:
  print -1

else:
 print factorial(*seq)  

... it just echoes back the number you were prompted to enter.
My confusion is, aren't the variables 'temp' and 'product' storing the
same value ie "args[0]". So why would they return different values, the
one with "temp" giving a wrong answer?

Thanks!

Kinuthia...



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


Re: [Tutor] Little problem with math module

2008-04-21 Thread Dick Moores
At 07:40 PM 4/20/2008, John Fouhy wrote:
>If you're going to be working with complex numbers, you might be
>better off looking at scipy or some other module that provides more
>mathematical grunt.

Try mpMath ()

With version 0.7:

 >>> from mpmath import power, mpf
 >>> print power(-20,(1.0/3.0))
(1.35720880829745 + 2.3507546124512j)

Or, to a precision of, say, 43:

 >>> mp.dps = 43
 >>> print power(-20,(1.0/3.0))
(1.357208808297453347178047801626363199806658 + 
2.350754612451197324056065041655768179779947j)

Dick Moores



UliPad <>: http://code.google.com/p/ulipad/ 

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


Re: [Tutor] Computing factorial...

2008-04-21 Thread bob gailer
kinuthia muchane wrote:
> Hi,
>
> I wanted to calculate the factorial of a given number without using
> recursion. I came up with the following code, although it is not very
> elegant it works. 
>
> def factorial(*args):
>  
>  product = args[0]
>  for item in args[1:]:
>  product *= item
>  return product
>  
> number = int(raw_input('Enter value of number to compute factorial  '))
> seq = range(1,number + 1)
>
> if number <= 0:
>   print -1
>
> else:
>  print factorial(*seq)  
>
> When I change that code a bit to (In fact, this is what I started with,
> it almost drove me crazy trying to figure out what was wrong!) :
>
> def factorial(*args):
>  
>  temp = args[0]
>  for item in args[1:]:
>  product = temp * item
>  return product
>  
> number = int(raw_input('Enter value of number to compute factorial  '))
> seq = range(1,number + 1)
>
> if number <= 0:
>   print -1
>
> else:
>  print factorial(*seq)  
>
> ... it just echoes back the number you were prompted to enter.
> My confusion is, aren't the variables 'temp' and 'product' storing the
> same value ie "args[0]". So why would they return different values, the
> one with "temp" giving a wrong answer?
>
>   
The program never changes temp. So temp will always be 1.

Is that not obvious? Or are you expecting that product and temp both 
refer to the same object? Which would be true if the object were a 
mutable such as a list or a dict or a class instance. But is NOT the 
case for immutables such as numbers and strings.


-- 
Bob Gailer
919-636-4239 Chapel Hill, NC

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


Re: [Tutor] HTML Parsing

2008-04-21 Thread bob gailer
Stephen Nelson-Smith wrote:
> Hi,
>
> I want to write a little script that parses an apache mod_status page.
>
> I want it to return simple the number of page requests a second and
> the number of connections.
>
> It seems this is very complicated... I can do it in a shell one-liner:
>
> curl 10.1.2.201/server-status 2>&1 | grep -i request | grep dt | {
> IFS='> ' read _ rps _; IFS='> ' read _ currRequests _ _ _ _
> idleWorkers _; echo $rps $currRequests $idleWorkers   ; }
>
> But that's horrid.
>
> So is:
>
> $ eval `printf '3 requests currently being processed, 17 idle
> workers\n 2.82 requests/sec - 28.1 kB/second - 10.0
> kB/request\n' | sed -nr '// { N;
> s@([0-9]*)[^,]*,([0-9]*).*([0-9.]*)[EMAIL PROTECTED]((\1+\2));[EMAIL 
> PROTECTED];
> }'`
> $ echo "workers: $workers reqs/secs $requests"
> workers: 20 reqs/sec 2.82
>
> The page looks like this:
>
> 
> 
> Apache Status
> 
> Apache Server Status for 10.1.2.201
>
> Server Version: Apache/2.0.46 (Red Hat)
> Server Built: Aug  1 2006 09:25:45
> 
> Current Time: Monday, 21-Apr-2008 14:29:44 BST
> Restart Time: Monday, 21-Apr-2008 13:32:46 BST
> Parent Server Generation: 0
> Server uptime:  56 minutes 58 seconds
> Total accesses: 10661 - Total Traffic: 101.5 MB
> CPU Usage: u6.03 s2.15 cu0 cs0 - .239% CPU load
> 3.12 requests/sec - 30.4 kB/second - 9.7 kB/request
> 9 requests currently being processed, 11 idle workers
> 
>
> How can/should I do this?
>
> S.
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
>
>   
I don't know how you get the page HTML, but let's assume each line is in 
an iterable, named html. It seems very straightforward to code:

for lineno, line in enumerate(html):
  x = line.find("requests/sec")
  if x >= 0:
no_requests_sec = line[3:x]
break
for lineno, line in enumerate(html[lineno+1:]):
  x = line.find("requests currently being processed")
  if x >= 0:
no_connections = line[3:x]

That makes certain assumptions about the file format, such as the 
matching text and knowing that connections follows requests/sec, and 
does not assume that connections is the first line after requests/sec.


-- 
Bob Gailer
919-636-4239 Chapel Hill, NC

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


Re: [Tutor] Hoping to benefit from someone's experience...

2008-04-21 Thread Hansen, Mike
 

> -Original Message-
> From: [EMAIL PROTECTED] 
> [mailto:[EMAIL PROTECTED] On Behalf Of Marc Tompkins
> Sent: Saturday, April 19, 2008 1:46 PM
> To: tutor@python.org
> Subject: Re: [Tutor] Hoping to benefit from someone's experience...
> 

> 
> As you might expect, most of the time is spent in Word.  It 
> would probably be faster if I set Visible = False, but for 
> some reason the macro fails (silently) when I do that, so I 
> just minimize Word instead to cut down on screen refreshes.  
> Also, drive U is a Samba share, so there's network latency to 
> take into account.  Even so, 10,231 files took less than 15 
> minutes to convert, which I can live with.
> 

This isn't Python related, but it might help those who do Word macros.

I think you can use Applications.ScreenUpdating = False at the beginning
of your macro. The macro will run a bit faster. It's essentially hiding
all the updating to the document(s). You should set it back at the end
of your macro: Application.ScreenUpdating = True.

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


Re: [Tutor] HTML Parsing

2008-04-21 Thread linuxian iandsd
Another horrid solution


> #!/usr/bin/python
> # line number does not change so we use that

# the data we're looking for does not have a (unique) close tag (htmllib
> )
>
> import re, urllib2
> file=urllib2.urlopen('http://10.1.2.201/server-status')
> n=0
> for line in file:
>  n=n+1
>  if n==16:
>   print re.sub('requests.*','',line)[4:].strip()
>  elif n==17:
>   print re.sub('requests.*','',line)[4:].strip()
>
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Little problem with math module

2008-04-21 Thread Dick Moores
At 08:17 AM 4/21/2008, Dick Moores wrote:
>At 07:40 PM 4/20/2008, John Fouhy wrote:
> >If you're going to be working with complex numbers, you might be
> >better off looking at scipy or some other module that provides more
> >mathematical grunt.
>
>Try mpMath ()
>
>With version 0.7:
>
>  >>> from mpmath import power, mpf
>  >>> print power(-20,(1.0/3.0))
>(1.35720880829745 + 2.3507546124512j)

I needn't have imported mpf
 >>> from mpmath import power
 >>> print power(-20,(1.0/3.0))
(1.35720880829745 + 2.3507546124512j)

Dick


>Or, to a precision of, say, 43:
>
>  >>> mp.dps = 43
>  >>> print power(-20,(1.0/3.0))
>(1.357208808297453347178047801626363199806658 +
>2.350754612451197324056065041655768179779947j)
>
>Dick Moores


UliPad <>: http://code.google.com/p/ulipad/ 

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


Re: [Tutor] HTML Parsing

2008-04-21 Thread bob gailer
Stephen Nelson-Smith wrote:
> Hi,
>
>   
>>  for lineno, line in enumerate(html):
>> 
>
> -Epython2.2hasnoenumerate()
>
>   
I used enumerate for a marginal (unproven) performance enhancement.
> Can we code around this?
for lineno in range(len(html)):
  x = html[lineno].find("requests/sec")
  if x >= 0:
no_requests_sec = html[lineno].[3:x]
   break
for lineno in range(lineno, len(html)):
  x = html[lineno].find("requests currently being processed")
  if x >= 0:
no_connections = html[lineno][3:x]
break

-- 
Bob Gailer
919-636-4239 Chapel Hill, NC

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


Re: [Tutor] Hoping to benefit from someone's experience...

2008-04-21 Thread Jeff Younker

On Apr 15, 2008, at 11:33 PM, Alan Gauld wrote:

> Have you considered driving Word instead of OOo?
> That way you leave the documents in their original format
> and make the mods using COM from Python.

I've used this approach before, and I whole heartedly suggest
that you look into it.  The Win32 extensions for Python make
talking to office applications via COM nearly effortless.

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


Re: [Tutor] HTML Parsing

2008-04-21 Thread Stephen Nelson-Smith
Hi,

>  for lineno, line in enumerate(html):

-Epython2.2hasnoenumerate()

Can we code around this?

>   x = line.find("requests/sec")
>   if x >= 0:
>no_requests_sec = line[3:x]
>break
>  for lineno, line in enumerate(html[lineno+1:]):
>   x = line.find("requests currently being processed")
>   if x >= 0:
>no_connections = line[3:x]

That all looks ok.

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


Re: [Tutor] HTML Parsing

2008-04-21 Thread Jeff Younker
On Apr 21, 2008, at 6:40 AM, Stephen Nelson-Smith wrote:

> On 4/21/08, Andreas Kostyrka <[EMAIL PROTECTED]> wrote:
> I want to stick with standard library.
>
> How do you capture  elements?


from xml.etree import ElementTree

document = """


   foo and bar
 
 
foo
bar
 

"""

dt_elements = ElementTree.XML(document).findall('dt')

-jeff

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


Re: [Tutor] Little problem with math module

2008-04-21 Thread ALAN GAULD
On Mon, Apr 21, 2008 at 12:07 AM, Alan Gauld <[EMAIL PROTECTED]> wrote:


>>> pow(-20, 0.333)
Traceback (most recent call last):
 File "", line 1, in 
ValueError: negative number cannot be raised to a fractional power
>>> -20**0.333
-2.7144173455393048
>>>

I think you're confusing the order of operations.

math.pow(-20, (1.0/3.0)) and -20**(1.0/3.0) are not equivalent

Whereas, as john mentioned, -20**(1.0/3.0) is actually -(20**(1.0/3.0)), 
math.pow(-20, (1.0/3.0)) is (-20)**(1.0/3.0)

Yes, quite correct, I posted my reply before the others had 
posted theirs although it showed up afterwards(at least on gmane)

> exponentiation has higher precedence over positive, negative.

Yep, I hadn't realized that, although it does make sense when you think about 
it :-)

> Note that math.pow is unrelated to the builtin power operator 
> and the result of math.pow(0.0, -2.0) will vary by platform. 

This is interesting, I had assumed that pow simply called **.
Does anyone know why they made it different?

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


Re: [Tutor] HTML Parsing

2008-04-21 Thread Andreas Kostyrka
If you have a correct XML document. In practice this is rather a big IF.

Andreas

Am Montag, den 21.04.2008, 10:35 -0700 schrieb Jeff Younker:
> On Apr 21, 2008, at 6:40 AM, Stephen Nelson-Smith wrote:
> 
> > On 4/21/08, Andreas Kostyrka <[EMAIL PROTECTED]> wrote:
> > I want to stick with standard library.
> >
> > How do you capture  elements?
> 
> 
> from xml.etree import ElementTree
> 
> document = """
> 
> 
>foo and bar
>  
>  
> foo
> bar
>  
> 
> """
> 
> dt_elements = ElementTree.XML(document).findall('dt')
> 
> -jeff


signature.asc
Description: Dies ist ein digital signierter Nachrichtenteil
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Little problem with math module

2008-04-21 Thread Tiago Katcipis
i will change the subject but this one is interessenting.

i have this test code

import funcoes
import bissecao
import falsa_posicao
import falsa_posicaom
import newton_simples
import math

INTERVALO = [0,1]
ERRO_DET = math.pow(10, -16)
ITER = funcoes.calcular_num_iteracoes(INTERVALO[0], INTERVALO[1], ERRO_DET)

print 'Por bissecao: '
print 'Numero de iteracoes necessarios = ', ITER
resultado, erro = bissecao.obter_alpha(INTERVALO,
funcoes.convergente_simples, ERRO_DET, ITER)
print 'Alpha = ', resultado
print 'Erro = ', erro
print ''


and i have this function on bissecao

import math
import funcoes

def obter_alpha(intervalo, funcao, erro_passado = 0.0, limite = 20):

  a = intervalo[0]
  b = intervalo[1]
  fa = funcao(a)
  fb = funcao(b)
  erro = erro_passado * 10.0
  contador = 0
  xm = 0.0
 
  if( (fa * fb) < 0 ):
   
while(contador < limite):
  contador += 1
  xm = (a + b) / 2.0
  fm = funcao(xm)
 
  if(fm == 0):
return xm, 0.0
 
  if( (fm * fa) < 0.0):
b = xm
  else:
a = xm
   
  erro = funcoes.calcular_erro(a, b)
 
  if(erro < erro_passado):
return xm, erro
 
  print 'Iteracao ', contador, ' alpha = ', xm
  print 'Erro ', contador, ' = ', erro
 
   
return xm, erro
 
  else:
print 'Funcao nao eh continua'
 
 

my problem is, INSIDE the funcion...the variable erro is correct, but
when i return it to the test...and the test prints itcomes out 0.0.
Its disturbing...i didnt found a way of solving this.

the out of the test is like this

Erro  50  =  1.50914019446e-15
Iteracao  51  alpha =  0.588532743982
Erro  51  =  7.54570097231e-16
Alpha =  0.588532743982
Erro =  0.0

it would print more things but it is desnecessary, inside the function
erro has a value like 7.54570097231e-16, but when it is returned it goes
out like 0.0. What can i do to prevent this from happening?

the whole thing is at
https://svn.inf.ufsc.br/katcipis/python/trunk/Funcoes/src/

just log as user "guest" without a password

ALAN GAULD escreveu:
> On Mon, Apr 21, 2008 at 12:07 AM, Alan Gauld
> <[EMAIL PROTECTED] > wrote:
>
>
> >>> pow(-20, 0.333)
> Traceback (most recent call last):
>  File "", line 1, in 
> ValueError: negative number cannot be raised to a fractional power
> >>> -20**0.333
> -2.7144173455393048
> >>>
>
> I think you're confusing the order of operations.
>
> math.pow(-20, (1.0/3.0)) and -20**(1.0/3.0) are not equivalent
>
> Whereas, as john mentioned, -20**(1.0/3.0) is actually
> -(20**(1.0/3.0)), math.pow(-20, (1.0/3.0)) is (-20)**(1.0/3.0)
>
> Yes, quite correct, I posted my reply before the others had
> posted theirs although it showed up afterwards(at least on gmane)
>  
> > exponentiation has higher precedence over positive, negative.
>  
> Yep, I hadn't realized that, although it does make sense when you
> think about it :-)
>
> /> Note that math.pow is unrelated to the builtin power operator /
> /> and the result of math.pow(0.0, -2.0) will vary by platform. /
>  
> /This is interesting, I had assumed that pow simply called **./
> Does anyone know why they made it different?
>  
> Alan G.
> 
>
> ___
> 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] HTML Parsing

2008-04-21 Thread Andreas Kostyrka
eeck.

Not that I advocate parsing files by line, but if you need to do it:

lines = list(file)[16:]

or

lines_iter = iter(file)
zip(lines_iter, xrange(16))
for line in lines_iter:

Andreas

Am Montag, den 21.04.2008, 14:42 + schrieb linuxian iandsd:
> Another horrid solution 
>  
> #!/usr/bin/python
> # line number does not change so we use that
> # the data we're looking for does not have a (unique) close
> tag (htmllib )
> 
> import re, urllib2
> file=urllib2.urlopen('http://10.1.2.201/server-status')
> n=0
> for line in file:
>  n=n+1
>  if n==16:
>   print re.sub('requests.*','',line)[4:].strip()
>  elif n==17:
>   print re.sub('requests.*','',line)[4:].strip()
> 


signature.asc
Description: Dies ist ein digital signierter Nachrichtenteil
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Arguments ina separate file

2008-04-21 Thread Sanhita Mallick
Hi.

I have a big list of arguments, which I would like to
keep in a  separate file. How do I pass arguments that
are in a  separate file?

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


Re: [Tutor] Arguments ina separate file

2008-04-21 Thread Tim Michelsen
> I have a big list of arguments, which I would like to
> keep in a  separate file. How do I pass arguments that
> are in a  separate file?
do you mean like setting?

do something like this
write them in the file myargs.py


import myargs

call_my_function(myargs.argument1, myargs.argument2)

see also my recent thread on settings called
"setting program configuration for all files and modules of a program"

Regards,
Timmie

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


Re: [Tutor] Arguments ina separate file

2008-04-21 Thread linuxian iandsd
>
> import myargs


this one is clever
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] HTML Parsing

2008-04-21 Thread Kent Johnson

Stephen Nelson-Smith wrote:

Hi,

I want to write a little script that parses an apache mod_status page.

I want it to return simple the number of page requests a second and
the number of connections.



The page looks like this:



Apache Status

Apache Server Status for 10.1.2.201

Server Version: Apache/2.0.46 (Red Hat)
Server Built: Aug  1 2006 09:25:45

Current Time: Monday, 21-Apr-2008 14:29:44 BST
Restart Time: Monday, 21-Apr-2008 13:32:46 BST
Parent Server Generation: 0
Server uptime:  56 minutes 58 seconds
Total accesses: 10661 - Total Traffic: 101.5 MB
CPU Usage: u6.03 s2.15 cu0 cs0 - .239% CPU load
3.12 requests/sec - 30.4 kB/second - 9.7 kB/request
9 requests currently being processed, 11 idle workers


How can/should I do this?


For data this predictable, simple regex matching will probably work fine.

If 'data' is the above text, then this seems to get what you want:

In [17]: import re
In [18]: re.search(r'[\d.]+ requests/sec', data).group()
Out[18]: '3.12 requests/sec'
In [19]: re.search(r'\d+ requests currently being processed', data).group()
Out[19]: '9 requests currently being processed'

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


[Tutor] Why next vs. __next__ ?

2008-04-21 Thread python
Is there a reason why generators have a special method named "next" vs.
"__next__"?

All other Python's special names have the double underscore
prefix/suffix.
http://docs.python.org/ref/specialnames.html

Are there other special names like "next" that don't have the double
underscore delimiters?

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


Re: [Tutor] Hoping to benefit from someone's experience...

2008-04-21 Thread Michael Langford
Office VBA is pretty much the same objects as the Office COM object.
You use the same for both, so probably can do it in python very close to the
same speed as vba

   --Michael

On Wed, Apr 16, 2008 at 1:48 PM, Marc Tompkins <[EMAIL PROTECTED]>
wrote:

> Again with the forgetting to cc the list...
> On Tue, Apr 15, 2008 at 11:33 PM, Alan Gauld <[EMAIL PROTECTED]>
> wrote:
>
> > Alternatively learn enough VBScript to do it all in Word itself
>
>
> That's exactly what I'm doing now.  After mentioning in a previous email
> that formatting is important, I took a closer look at the documents that OO
> had converted... and they weren't as good as I thought at first.  No
> disgrace to OO; the fact that anybody outside of Microsoft has ever managed
> to make even a little bit of sense out of the .doc format is a testimony to
> human ingenuity and stubbornness - but it's just not good enough.  So,
> despite my enthusiasm for Python and the fact that VBScript repulses me, I
> think I need to start fresh and do it the Redmond way.  If I were building
> something for long-term use rather than a one-time conversion, I would
> figure out how to drive Word from Python, but under the circumstances I'll
> hack something quick and dirty in VBS.  (Does anyone remember VBA?)
>
>
>
> It's funny - years ago I used to use Visual Studio and _enjoy_ it.  I'm
> spoiled now, I guess.  By the way, there was a recent XKCD that I liked:
> http://xkcd.com/409/
>
>
> --
> www.fsrtechnologies.com
> ___
> 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] When to use % vs. locale.format()?

2008-04-21 Thread python
Are there any best practices guidelines that discuss when one should use
% vs. locale.format?

The locale.format() seems closer to the new new Python 3.0
print-as-a-function vs. statement ... with the added benefit of
localized output.

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


Re: [Tutor] Little problem with math module

2008-04-21 Thread tiger12506

my problem is, INSIDE the funcion...the variable erro is correct, but
when i return it to the test...and the test prints itcomes out 0.0.
Its disturbing...i didnt found a way of solving this.


err is defined in the function so it thinks it's a local variable. You can 
set it to change only the global variable by putting


global err

as the line right after your function def. 
___

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


Re: [Tutor] Why next vs. __next__ ?

2008-04-21 Thread Kent Johnson

[EMAIL PROTECTED] wrote:

Is there a reason why generators have a special method named "next" vs.
"__next__"?

All other Python's special names have the double underscore
prefix/suffix.
http://docs.python.org/ref/specialnames.html


It's actually considered a mistake.

The original rationale is spelled out in PEP 234 - see the Resolved 
Issues section:

http://www.python.org/dev/peps/pep-0234/

It is being renamed to __next__() in Python 3.0 and there will be a 
builtin next() method that calls it. Instead of iterator.next() you will 
call next(iterator).

http://www.python.org/dev/peps/pep-3114/

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


Re: [Tutor] When to use % vs. locale.format()?

2008-04-21 Thread Kent Johnson

[EMAIL PROTECTED] wrote:

Are there any best practices guidelines that discuss when one should use
% vs. locale.format?


You might want to try comp.lang.python if you don't get an answer here.

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


Re: [Tutor] Why next vs. __next__ ?

2008-04-21 Thread tiger12506

It's actually considered a mistake.

The original rationale is spelled out in PEP 234 - see the Resolved Issues 
section:

http://www.python.org/dev/peps/pep-0234/

It is being renamed to __next__() in Python 3.0 and there will be a 
builtin next() method that calls it. Instead of iterator.next() you will


It's not a method if it's global to the namespace. Or so I've been told. A 
built-in function.



call next(iterator).
http://www.python.org/dev/peps/pep-3114/




Which makes a lot more sense because then it follows the convention of:

int(MyObject) == MyObject.__int__()
str(MyObject) == MyObject.__str__()
float(MyObject) == MyObject.__float__()

etc. like all of the other special method names 
___

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


Re: [Tutor] Little problem with math module

2008-04-21 Thread Kent Johnson

tiger12506 wrote:

my problem is, INSIDE the funcion...the variable erro is correct, but
when i return it to the test...and the test prints itcomes out 0.0.
Its disturbing...i didnt found a way of solving this.


err is defined in the function so it thinks it's a local variable.


My reading is that erro is returned from the function and assigned to a 
'new' erro at the point of call.


 You

can set it to change only the global variable by putting

global err

as the line right after your function def. 


No, because the caller is in a different module.

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


Re: [Tutor] Little problem with math module

2008-04-21 Thread tiger12506
Hmm. I didn't read particularly closely, but it seemed that there were two 
different versions going on. The first examples more like what he wanted to 
happen, and the last example what he tried and didn't get to work. Since 
it's in a different module he can get around it by using global erro and 
then using modulename.erro when he uses the actual value.



- Original Message - 
From: "Kent Johnson" <[EMAIL PROTECTED]>

Cc: 
Sent: Monday, April 21, 2008 9:33 PM
Subject: Re: [Tutor] Little problem with math module



tiger12506 wrote:

my problem is, INSIDE the funcion...the variable erro is correct, but
when i return it to the test...and the test prints itcomes out 0.0.
Its disturbing...i didnt found a way of solving this.


err is defined in the function so it thinks it's a local variable.


My reading is that erro is returned from the function and assigned to a 
'new' erro at the point of call.


 You

can set it to change only the global variable by putting

global err

as the line right after your function def.


No, because the caller is in a different module.

Kent
___
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] Python WSDL Generation Tools

2008-04-21 Thread wesley chun
> I am using SOAPpy for generating web services .I have also written a client
> in python for accessing that web service ,and it works fine.Now when i try
> to make a java client to access the web service created in python ,the java
> client ask me for a wsdl file which is not present .
>
> So i want to know if there is any way in which i can generate the wsdl file
> from existing python module.


yes, it appears that such a file is supposed to be available via the
server.  i'm using SOAPpy as well but only for client stuff.  when i
connect, i use an invocation like this:

proxy = 
SOAPpy.WSDL.Proxy("https://customer...com/public/SOAP%20Gateway%20files/hsan.wsdl";)

anyway, you may wish to start looking at various places such as:
http://www.diveintopython.org/soap_web_services/wsdl.html
http://www.diveintopython.org/soap_web_services/introspection.html
http://pywebsvcs.sourceforge.net/apidocs/wstools/
http://pywebsvcs.sourceforge.net/apidocs/SOAPpy/

hope this helps, and let us know what worked for you!
-- wesley
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
"Core Python Programming", Prentice Hall, (c)2007,2001
 http://corepython.com

wesley.j.chun :: wescpy-at-gmail.com
python training and technical consulting
cyberweb.consulting : silicon valley, ca
http://cyberwebconsulting.com
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor