Re: [Tutor] Very basic Python question

2009-06-26 Thread Daniel Sato
Oh, I thought that you could install multiple instances of Python. I recall
reading somewhere that they advised installing the latest stable version b/c
the one that comes with Apple is often out-dated (as it is whatever version
existed when the your particular model came out).



On Fri, Jun 26, 2009 at 10:16 PM, Luke Paireepinart
wrote:

> Daniel Sato wrote:
>
>> Hi,
>>
>> Let me preface this by saying that I purchased O'Reilly's "Learn Python"
>> yesterday and have no programming experience (I am a photographer by trade)
>> except for a semester of what I think was BASIC on some old apple back in
>> elementary school (circa 1992).
>>
>> I am not sure what details are relevant, so I will try and include as much
>> as possible.  I have a MacBook Pro running Mac OSX 10.5.6.  I recently dl'ed
>> MacPython 2.5, which installed Python 2.5.4 on my system.
>> When I am in the terminal, I can run a module by typing python
>> fullpath/to/script.py
>>
>> However, when I enter Python from the terminal, by typing python, I can no
>> longer import items in this way unless the .py file is in my user folder
>> /Users/Me.  How can I change my settings so that I can import .py files from
>> a separate directory such as /Users/Me/Documents/PyMods?
>>
>
> Hi Daniel,
> You should try uninstalling MacPython.  Macintosh computers come with
> Python preinstalled and you should try to use that version instead.
>  Probably what happened was that, when installing the other version of
> Python, you messed up some of the references for the paths of libraries and
> such.
>
> If that doesn't work, look for an article on upgrading Python on a mac, it
> should detail how to fix anything that breaks when you install MacPython.
> Good luck, and let us know if you have any other problems!
>
>


-- 
Daniel Sato
http://www.danielsato.com
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Very basic Python question

2009-06-26 Thread Luke Paireepinart

Daniel Sato wrote:

Hi,

Let me preface this by saying that I purchased O'Reilly's "Learn 
Python" yesterday and have no programming experience (I am a 
photographer by trade) except for a semester of what I think was BASIC 
on some old apple back in elementary school (circa 1992).


I am not sure what details are relevant, so I will try and include as 
much as possible.  I have a MacBook Pro running Mac OSX 10.5.6.  I 
recently dl'ed MacPython 2.5, which installed Python 2.5.4 on my system. 

When I am in the terminal, I can run a module by typing python 
fullpath/to/script.py


However, when I enter Python from the terminal, by typing python, I 
can no longer import items in this way unless the .py file is in my 
user folder /Users/Me.  How can I change my settings so that I can 
import .py files from a separate directory such as 
/Users/Me/Documents/PyMods?


Hi Daniel,
You should try uninstalling MacPython.  Macintosh computers come with 
Python preinstalled and you should try to use that version instead.  
Probably what happened was that, when installing the other version of 
Python, you messed up some of the references for the paths of libraries 
and such.


If that doesn't work, look for an article on upgrading Python on a mac, 
it should detail how to fix anything that breaks when you install MacPython.

Good luck, and let us know if you have any other problems!

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


[Tutor] Very basic Python question

2009-06-26 Thread Daniel Sato
Hi,

Let me preface this by saying that I purchased O'Reilly's "Learn Python"
yesterday and have no programming experience (I am a photographer by trade)
except for a semester of what I think was BASIC on some old apple back in
elementary school (circa 1992).

I am not sure what details are relevant, so I will try and include as much
as possible.  I have a MacBook Pro running Mac OSX 10.5.6.  I recently dl'ed
MacPython 2.5, which installed Python 2.5.4 on my system.

When I am in the terminal, I can run a module by typing python
fullpath/to/script.py

However, when I enter Python from the terminal, by typing python, I can no
longer import items in this way unless the .py file is in my user folder
/Users/Me.  How can I change my settings so that I can import .py files from
a separate directory such as /Users/Me/Documents/PyMods?

Thank you.

-daniel sato

-- 
Daniel Sato
http://www.danielsato.com
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] DOMForm

2009-06-26 Thread Pete Froslie
Hi, so I've been using Mechanize as suggested to me through tutor to access
web forms and fill them out.. I've found some success though I wish there to
be more documentation than docstrings.. as I am new to python and not
incredibly experienced with code.

I am able to fill forms and submit them in situations such as a
'search-submit' form on a blog.  *My problem is evident when I approach a
form that appears to be linked to a javascript -- I am unable to
submit*(essentially click on the button).. I assume this is because
python does not
handle javascript.  I am now looking at DOMForm as a solution, but am unsure
as to weather or not this is correct..

An example of the form I would like to access looks like this:
*
*
*








***

#the is more like the above I'm leaving out before the standard form
entry html such as the following:

td align="Left" class="LabelCell">Enter
e-mail address of recipient



**


The python code I've put together looks like this:

*import ClientForm
import urllib2
request = 
urllib2.Request("http://www.qinetiq-nacareers.com/qinetiq/jobboard/SendToFriend.aspx?__JobID=*C2B68228BC44075E";)
response = urllib2.urlopen(request)
forms = ClientForm.ParseResponse(response, backwards_compat=False)
response.close()

form = forms[0]
print form

form["Email_To"] = "pfros...@gmail.com"
form["Email_From"] = "pfros...@gmail.com"
form["SenderName"] = "Patrick"
form["Comments"] = "this job looks great"

request2 = form.click("Send")

print form
control = form.find_control("Email_To", type="text")
print control.name, control.value, control.type
print request
print request2*


i've tried a few other options, but essentially feel my trouble boils
down to thos issue with java..

*Thank you so much!-- I appologoze if this post is formatted a little
too confusing-- kind of getting use to communicating about pythono..
*
*
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] array and int

2009-06-26 Thread Kent Johnson
On Fri, Jun 26, 2009 at 2:28 PM, Dinesh B
Vadhia wrote:
> Say, you create an array['i'] for signed integers (which take a minimum 2
> bytes).  A calculation results in an integer that is larger than the range
> of an 'i'.  Normally, Python will convert an 'i' to a 4-byte 'l' integer.
> But, does the same apply for an array ie. does Python dynamically adjust
> from array['i'] to array['l'']?

No. It's easy enough to try:
In [1]: import array

In [2]: a = array.array('i')

In [3]: a.itemsize
Out[3]: 4

In [5]: a.append(1)

In [6]: a
Out[6]: array('i', [1])

In [7]: x = 2**33

In [8]: x
Out[8]: 8589934592L

In [9]: a[0] = x
---
OverflowError Traceback (most recent call last)

C:\Project\Mango\ in ()

OverflowError: long int too large to convert to int

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


[Tutor] array and int

2009-06-26 Thread Dinesh B Vadhia
Say, you create an array['i'] for signed integers (which take a minimum 2 
bytes).  A calculation results in an integer that is larger than the range of 
an 'i'.  Normally, Python will convert an 'i' to a 4-byte 'l' integer.  But, 
does the same apply for an array ie. does Python dynamically adjust from 
array['i'] to array['l'']?

Before anyone suggests it, I would be using Numpy for arrays but there isn't a 
64-bit version available under Windows that works.

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


Re: [Tutor] newton's method for system of nonlinear equations

2009-06-26 Thread Skipper Seabold
On Fri, Jun 26, 2009 at 6:54 AM,  wrote:
> Hi,
> I am trying to write a program in python that solves a system of nonlinear
> equations using newton's method. I don't know what I am doing wrong.
> Please help
>
> from scipy import*
>
> x = array([0.0,0.0,0.0])
> n=len(x)
> tol= 0.1
> N=30
>
> k=1
> while k <= N:
>    def f(x):
>        f= zeros((len(x)),float)
>        f[0][k]= x[0][k]**2 + x[1][k]-37
>        f[1][k]=x[0][k]- x[1][k]**2- 5
>        f[2][k]= x[0][k] + x[1][k]+ x[2][k]- 3
>        return f[k]
>        def J(x):
>            J= zeros((n,n),float)
>            for i in range(n):
>                ei=zeros(n,float)
>                ei[i]=1.0
>                J[:i]=(f(x[k]+tol*ei)-f(x[k]))/tol
>                return J
>
>        y[k] = -(J.I)*f[k]
>        x[k+1]=x[k]+y[k]
>
> if sqrt(dot(f0,f0)/len(x)) < tol: print x
> else:
>    k=k+1
>
> print 'Too many iterations'
>
>

You might want to have a look at scipy.optimize


If you have more (somewhat) SciPy related questions, you might want to
ask them on the SciPy mailing list.  It's very active.


Cheers,

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


Re: [Tutor] newton's method for system of nonlinear equations

2009-06-26 Thread Dave Angel

kgotlele...@galmail.co.za wrote:



Hi,
I am trying to write a program in python that solves a system of nonlinear
equations using newton's method. I don't know what I am doing wrong.
Please help

  
First thing wrong is posting two messages in the mailing list in rapid 
succession (7 minutes) with same content and different titles.  Not the 
best way to get sympathy.
Next:  paste your error log, or if there is none, show the results and 
explain how they differ from what you wanted.  Also show versions of 
both Python and the scipy library you're importing.
Third:  you have lots of obvious things wrong with the code itself, but 
it's usually best to start fixing it where the error message points;  
I'm not familiar with scipi, but I'll try to give you a few pointers anyway.
Fourth:  you use the "import *" form, which is generally frowned upon 
for all but trivial scripts.  It pollutes the global namespace, and 
possibly masks built-in functions and variables.
Fifth:  your names aren't very mnemonic, so somebody not familiar with 
the code has to spend longer just guessing what things are for.


Now for specifics in the code:

from scipy import*

x = array([0.0,0.0,0.0])
n=len(x)
tol= 0.1
N=30

k=1
while k <= N:
  

Nowhere in this loop do you modify k or N, so it'll never terminate.

def f(x):
  
Defining a function inside a loop is seldom useful, and not a technique 
for beginners.  In fact, a beginner should expect all functions to be at 
module level (left margin), and all methods to be at class level (one 
indent in).  Besides, you never call it or the nested function J.

f= zeros((len(x)),float)
  
It's bad form to re-use the function name as a local within the 
function.  It works, but probably contributes to your confusion below.

f[0][k]= x[0][k]**2 + x[1][k]-37
f[1][k]=x[0][k]- x[1][k]**2- 5
f[2][k]= x[0][k] + x[1][k]+ x[2][k]- 3
return f[k]
def J(x):
  

This definition is never reached, so the code is dead.

J= zeros((n,n),float)
for i in range(n):
ei=zeros(n,float)
ei[i]=1.0
J[:i]=(f(x[k]+tol*ei)-f(x[k]))/tol
return J

y[k] = -(J.I)*f[k]
  
Here, you're misusing J and f.  If you're trying to call those 
functions, your syntax is way-off.  But if you're trying to use the 
local variables by those names, realize that the local J is not in scope.

x[k+1]=x[k]+y[k]
  
You'll never get to these next lines, because the previous while loop 
never terminates.  Perhaps an indentation problem?

if sqrt(dot(f0,f0)/len(x)) < tol: print x
else:
k=k+1
  

Not much point in incrementing a loop variable outside the loop.

print 'Too many iterations'


  


There are other things to ask, such as whether you intended to quit 
after printing x.  But the fix for that depends on other things you'll 
fix first.



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


Re: [Tutor] newton's method for system of nonlinear equations

2009-06-26 Thread A.T.Hofkamp

kgotlele...@galmail.co.za wrote:

Hi,
I am trying to write a program in python that solves a system of nonlinear
equations using newton's method. I don't know what I am doing wrong.

> Please help

In general, it helps for both you and us if you show what happens when you run 
the program, and how that is not according to your expectations.


In this case, you just say "I don't know what I am doing wrong".
We can look at the code and see what will happen when one executes it, but we 
don't know how that is wrong for you.



from scipy import*


Many readers here (including self) don't know much about numerical stuff, so 
if that's your problem, maybe posting at a scipy related list may be more useful.



x = array([0.0,0.0,0.0])
n=len(x)
tol= 0.1
N=30

k=1
while k <= N:
def f(x):
f= zeros((len(x)),float)
f[0][k]= x[0][k]**2 + x[1][k]-37
f[1][k]=x[0][k]- x[1][k]**2- 5
f[2][k]= x[0][k] + x[1][k]+ x[2][k]- 3
return f[k]
def J(x):
J= zeros((n,n),float)
for i in range(n):
ei=zeros(n,float)
ei[i]=1.0
J[:i]=(f(x[k]+tol*ei)-f(x[k]))/tol
return J

y[k] = -(J.I)*f[k]
x[k+1]=x[k]+y[k]


You have a while loop, and inside the loop you define a function called 'f'.
Can you explain what you think should happen here?



if sqrt(dot(f0,f0)/len(x)) < tol: print x


f0 is never defined above, so you will get an 'undefined identifier f0' error 
here.

What is f0 supposed to be?
(if you intended to call 'f' here, type 'f(0)' instead of 'f0')
(Calling f probably makes sense only if the 'if' statement is inside the 
'while' loop. See also below.)



else:
k=k+1


The 'if' statement is after the 'while' loop. Incrementing k here does not 
make much sense here.

Maybe you meant the 'if' inside the 'while'?
If so, indent the statement accordingly (same amount as the "def f(x):" line).


Albert

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


Re: [Tutor] Hi,

2009-06-26 Thread bob gailer

Kgotlelelo Legodi wrote:

Hi,
I am trying to write a program in python that solves a system of 
nonlinear equations using newton's method. I don't know what I am 
doing wrong. Please help


Mostly what you are "doing wrong" is failing to tell us why you think 
there is a problem! What results are you expecting and what are you getting?


 
from scipy import*
 
x = array([0.0,0.0,0.0])

n=len(x)
tol= 0.1
N=30
 
k=1

while k <= N:
def f(x):
f= zeros((len(x)),float)
f[0][k]= x[0][k]**2 + x[1][k]-37
f[1][k]=x[0][k]- x[1][k]**2- 5
f[2][k]= x[0][k] + x[1][k]+ x[2][k]- 3
return f[k]
def J(x):
J= zeros((n,n),float)
for i in range(n):
ei=zeros(n,float)
ei[i]=1.0
J[:i]=(f(x[k]+tol*ei)-f(x[k]))/tol
return J
 
y[k] = -(J.I)*f[k]

x[k+1]=x[k]+y[k]
 
if sqrt(dot(f0,f0)/len(x)) < tol: print x

else:
k=k+1
 
print 'Too many iterations'






--
Bob Gailer
Chapel Hill NC
919-636-4239
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] (no subject)

2009-06-26 Thread Kent Johnson
On Fri, Jun 26, 2009 at 6:29 AM, Febin Ameer Ahsen wrote:
> how to implement diff command showing  difference in box

Here are some examples of using difflib to list differences:
http://blog.doughellmann.com/2007/10/pymotw-difflib.html
http://personalpages.tds.net/~kent37/blog/arch_m1_2004_06.html#e47

What kind of box do you want to show them in? A window? For that you
need to use a GUI framework such as Tkinter.

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


Re: [Tutor] creating a dict-like class - asigning variables... this one may take some thought ; )

2009-06-26 Thread John [H2O]

Thanks everyone, all of this feedback is valuable! 

-- 
View this message in context: 
http://www.nabble.com/creating-a-dict-like-class---asigning-variables...-this-one-may-take-some-thought--%29-tp23759398p24218879.html
Sent from the Python - tutor mailing list archive at Nabble.com.

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


[Tutor] Hi,

2009-06-26 Thread Kgotlelelo Legodi
Hi,
I am trying to write a program in python that solves a system of nonlinear 
equations using newton's method. I don't know what I am doing wrong. Please help
 
from scipy import*
 
x = array([0.0,0.0,0.0])
n=len(x)
tol= 0.1
N=30
 
k=1
while k <= N:
def f(x):
f= zeros((len(x)),float)
f[0][k]= x[0][k]**2 + x[1][k]-37
f[1][k]=x[0][k]- x[1][k]**2- 5
f[2][k]= x[0][k] + x[1][k]+ x[2][k]- 3
return f[k]
def J(x):
J= zeros((n,n),float)
for i in range(n):
ei=zeros(n,float)
ei[i]=1.0
J[:i]=(f(x[k]+tol*ei)-f(x[k]))/tol
return J
 
y[k] = -(J.I)*f[k]
x[k+1]=x[k]+y[k]
 
if sqrt(dot(f0,f0)/len(x)) < tol: print x
else:
k=k+1
 
print 'Too many iterations'

-- 
This message is subject to the CSIR's copyright terms and conditions, e-mail 
legal notice, and implemented Open Document Format (ODF) standard. 
The full disclaimer details can be found at 
http://www.csir.co.za/disclaimer.html.

This message has been scanned for viruses and dangerous content by MailScanner, 
and is believed to be clean.  MailScanner thanks Transtec Computers for their 
support.

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


[Tutor] newton's method for system of nonlinear equations

2009-06-26 Thread kgotlelelok
Hi,
I am trying to write a program in python that solves a system of nonlinear
equations using newton's method. I don't know what I am doing wrong.
Please help

from scipy import*

x = array([0.0,0.0,0.0])
n=len(x)
tol= 0.1
N=30

k=1
while k <= N:
def f(x):
f= zeros((len(x)),float)
f[0][k]= x[0][k]**2 + x[1][k]-37
f[1][k]=x[0][k]- x[1][k]**2- 5
f[2][k]= x[0][k] + x[1][k]+ x[2][k]- 3
return f[k]
def J(x):
J= zeros((n,n),float)
for i in range(n):
ei=zeros(n,float)
ei[i]=1.0
J[:i]=(f(x[k]+tol*ei)-f(x[k]))/tol
return J

y[k] = -(J.I)*f[k]
x[k+1]=x[k]+y[k]

if sqrt(dot(f0,f0)/len(x)) < tol: print x
else:
k=k+1

print 'Too many iterations'


-
This email was sent using SquirrelMail.
   "Webmail for nuts!"
http://squirrelmail.org/

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


[Tutor] difflib (was: (no subject))

2009-06-26 Thread A.T.Hofkamp

Febin Ameer Ahsen wrote:

how to implement diff command showing  difference in box


Don't implement diff yourself, use the difflib module instead.


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


[Tutor] (no subject)

2009-06-26 Thread Febin Ameer Ahsen
how to implement diff command showing  difference in box





  ICC World Twenty20 England '09 exclusively on YAHOO! CRICKET 
http://cricket.yahoo.com___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor