Re: [Tutor] Functional Derivatives

2009-04-20 Thread Chris Fuller
His problem was composing four functions, each with a small error. The first two applications work well enough, but there is a about a percent error in the third composition. The big source of error is f(x+h)-f(x). Subtracting two floating point numbers that are nearly equal is a known source

Re: [Tutor] Webpy vs Django

2009-04-20 Thread vishwajeet singh
Thanks for your answer but can you give me reasons for same. On Tue, Apr 21, 2009 at 2:38 AM, Tim Michelsen wrote: > I can recommend you web2py: > http://www.web2py.com/ > > It has been designed for didactical needs and has a low learning curve. > > Look at the manual extarct for an idea: > Free

Re: [Tutor] Reading from files problem

2009-04-20 Thread Chris Castillo
this worked for me fine. #Author - Chris Castillo #Created 4/19/09 #Program 6 import time #Open and read text file with student information gradesfile = open("grades.dat", "r") time_acc = time.asctime() #Ask user for student ID to lookup student information sought_id = raw_input("Please enter a

Re: [Tutor] Functional Derivatives

2009-04-20 Thread Kent Johnson
On Mon, Apr 20, 2009 at 7:53 PM, Matt wrote: > I'm trying to calculate the derivative of a function in Python like so: > > def D5(func,h=1e-5): >     ""' Return derivative of function func''' >     def df(x):    return (func(x+h)-func(x))/h >    df.__name__ = func.__name__ + '_dx' >     return df

Re: [Tutor] Functional Derivatives

2009-04-20 Thread Chris Fuller
You should look up "numerical methods" or similar. There are ways of rearranging your calculations to minimize the loss of precision. You could also try a numerical/scientific library like GMP (for integers or rational numbers). I don't know of any (Python) library for extended precision fl

[Tutor] Functional Derivatives

2009-04-20 Thread Matt
I'm trying to calculate the derivative of a function in Python like so: def D5(func,h=1e-5):     ""' Return derivative of function func'''     def df(x):return (func(x+h)-func(x))/h df.__name__ = func.__name__ + '_dx'     return df However, I run into the problem of limited float precisio

Re: [Tutor] Looping

2009-04-20 Thread Paul McGuire
> > xrange was a kludge to improve on range's memory efficiency > but it is a horrible name that obscures the code. > > Also it does not exist in v3 so if you use it you will need to change > the code for v3. It is as well to be as consistent with v3 as possible > IMHO > > Alan G I have felt th

Re: [Tutor] String Encoding problem

2009-04-20 Thread Strax-Haber, Matthew (LARC-D320)
I've solved the problem by passing on the work of deciding when to commit to client code. This isn't ideal but it will do what is necessary and unfortunately I don't have any more time to dedicate to this. I hate not being able to find a reasonable workaround :/. -- ~Matthew Strax-Haber National

Re: [Tutor] String Encoding problem

2009-04-20 Thread Kent Johnson
Can you give us a simple description of what you are trying to do? And if you can post in plain text instead of HTML that would be helpful. Maybe this will give you some ideas - you can trap the control-D and do your cleanup: http://openbookproject.net/pybiblio/tips/wilson/simpleExceptions.php Ke

Re: [Tutor] String Encoding problem

2009-04-20 Thread Strax-Haber, Matthew (LARC-D320)
Sorry about that. Hopefully this is better: In operator: def __init__(self, path, saveDB=True, cleanUp=True): '''Constructor''' ## Calculate filesystem paths self.WORK_DIR= path + '.tmp' DB_PATH= path + '.xml' self.SAVE_DB= saveDB## finish(): Delete unnecessa

Re: [Tutor] Looping

2009-04-20 Thread Alan Gauld
"Matt" wrote As an aside, why use range rather than xrange? I was under the impression that xrange is a generator and therefore more memory efficient. xrange was a kludge to improve on range's memory efficiency but it is a horrible name that obscures the code. Also it does not exist in v3 s

Re: [Tutor] Sending a disconnect after openssl s_client command?

2009-04-20 Thread Kayvan Sarikhani
On Mon, Apr 20, 2009 at 1:17 PM, Martin Walsh wrote: > from subprocess import Popen, PIPE > > openssl_cmd = 'openssl s_client -ssl2 -connect somewebsitename:443' > openssl = Popen( > openssl_cmd, shell=True, stdout=PIPE, stderr=PIPE, stdin=PIPE > ) > stdout, stderr = openssl.communicate('GET /')

Re: [Tutor] Webpy vs Django

2009-04-20 Thread Tim Michelsen
I can recommend you web2py: http://www.web2py.com/ It has been designed for didactical needs and has a low learning curve. Look at the manual extarct for an idea: Free manual chapters - http://mdp.cti.depaul.edu/examples/static/web2py_manual_cut.pdf or check the docs: http://www.web2py.com/ex

Re: [Tutor] String Encoding problem

2009-04-20 Thread Martin Walsh
Forwarding to the list. Matt, perhaps you can repost in plain text, my mail client seems to have mangled your source ... Strax-Haber, Matthew (LARC-D320) wrote: >> *From: *Martin Walsh >> >> The environment available to __del__ methods during program termination >> is wonky, and apparently not ve

Re: [Tutor] String Encoding problem

2009-04-20 Thread Kent Johnson
On Mon, Apr 20, 2009 at 10:46 AM, Matt wrote: > Running this interactively, if you finish off with 'del db', it exits fine > and creates a skeleton xml file called 'db.xml' with text ''. > However, if you instead CTRL-D, it throws at exception while quitting and > then leaves an empty 'db.xml' whi

Re: [Tutor] String Encoding problem

2009-04-20 Thread Martin Walsh
Matt wrote: > Hey everyone, > > I'm hoping someone here can help me solve an odd problem (bug?). I'm > having trouble with string encoding, object deletion, and the xml.etree > library. If this isn't the right list to be posting this question, > please let me know. I'm new to Python and don't know

Re: [Tutor] py-editdist

2009-04-20 Thread عماد نوفل
On Mon, Apr 20, 2009 at 2:13 PM, ALAN GAULD wrote: > I mean you need a source installation not a binary one, it is looking for > python.h > which is one of the C header files in the Python source code. > > Alan Gauld > Author of the Learn To Program website > http://www.alan-g.me.uk/ > > > ---

Re: [Tutor] py-editdist

2009-04-20 Thread ALAN GAULD
I mean you need a source installation not a binary one, it is looking for python.h which is one of the C header files in the Python source code. Alan Gauld Author of the Learn To Program website http://www.alan-g.me.uk/ From: Emad Nawfal (عماد نوفل) To: Al

Re: [Tutor] String Encoding problem

2009-04-20 Thread Strax-Haber, Matthew (LARC-D320)
> From: spir > Date: Mon, 20 Apr 2009 12:22:59 -0500 > To: Python Tutor > Subject: Re: [Tutor] String Encoding problem > > Le Mon, 20 Apr 2009 10:46:47 -0400, > Matt s'exprima ainsi: > >> Hey everyone, >> >> I'm hoping someone here can help me solve an odd prob

Re: [Tutor] py-editdist

2009-04-20 Thread عماد نوفل
2009/4/20 Alan Gauld > > "Emad Nawfal (عماد نوفل)" wrote > > e...@emad-desktop:~/Desktop/py-editdist-0.3$ python setup.py build >> running build >> gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall >> editdist.c:22:20: error: Python.h: No such file or directory >> > > Looks like y

Re: [Tutor] Looping

2009-04-20 Thread W W
On Mon, Apr 20, 2009 at 12:34 PM, Matt > wrote: > Thank you. Func is in fact a call to an external non-python program. =] > Therefore, the loop must actually be mindlessly done. My question, however, > has been answered. > As an aside, why use range rather than xrange? I was under the impression

Re: [Tutor] parse text for paragraghs/sections

2009-04-20 Thread spir
Le Mon, 20 Apr 2009 09:07:01 -0700, "Dinesh B Vadhia" s'exprima ainsi: > t = """abc DEF ghi jkl MNO pqr""" > > ... pickup all text between the tags and and replace with > another piece of text. > > I tried > > t = re.sub(r"\[A-Za-z0-9]\", "DBV", t) > > ... but it doesn't work. You need:

Re: [Tutor] parse text for paragraghs/sections

2009-04-20 Thread Alan Gauld
"Dinesh B Vadhia" wrote in ... pickup all text between the tags and and replace with another piece of text. How do you do this with re? Preferably you don't, use an HTML parser. It is both easier and more reliable since it is almost impossible to handle all HTML constructs reliably usin

Re: [Tutor] Looping

2009-04-20 Thread Matt
Thank you. Func is in fact a call to an external non-python program. =] Therefore, the loop must actually be mindlessly done. My question, however, has been answered. As an aside, why use range rather than xrange? I was under the impression that xrange is a generator and therefore more memory effic

Re: [Tutor] py-editdist

2009-04-20 Thread Alan Gauld
"Emad Nawfal (عماد نوفل)" wrote e...@emad-desktop:~/Desktop/py-editdist-0.3$ python setup.py build running build gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall editdist.c:22:20: error: Python.h: No such file or directory Looks like you need the Python source code installed,

Re: [Tutor] Looping

2009-04-20 Thread Alan Gauld
"Matt" wrote Let's say I want to run func 10 times Is there a more pythonic way to do it than this: for i in xrange(10): func() Yes, use range() rather than xrange :-) But more seriously, as others have pointed out, if func() is well written then calling it ten times will have no e

Re: [Tutor] String Encoding problem

2009-04-20 Thread spir
Le Mon, 20 Apr 2009 10:46:47 -0400, Matt s'exprima ainsi: > Hey everyone, > > I'm hoping someone here can help me solve an odd problem (bug?). I'm having > trouble with string encoding, object deletion, and the xml.etree library. If > this isn't the right list to be posting this question, please

Re: [Tutor] Sending a disconnect after openssl s_client command?

2009-04-20 Thread Martin Walsh
Kayvan Sarikhani wrote: > Tutors, > > I'm working on a script to verify whether a particular website > supports SSLv2 via the following: > > --- BEGIN --- > #!/usr/bin/python > import os, re > > checkssl_out = open('checkssl.txt','w') > > website = 'somewebsitename' > sslv2 = 'Protocol : SSL

Re: [Tutor] Looping

2009-04-20 Thread spir
Le Mon, 20 Apr 2009 17:26:30 +0200, "A.T.Hofkamp" s'exprima ainsi: > Matt wrote: > > Hey everyone, > > > > First post to this list. I hope I'm doing it right. > > > > Let's say I want to run func 10 times Is there a more pythonic way to do > > it than this: for i in xrange(10): > > func() > >

[Tutor] py-editdist

2009-04-20 Thread عماد نوفل
Hi Tutors, I tried to install this edit distance module but failed: http://www.mindrot.org/projects/py-editdist/ I'm running Ubuntu Linux. The error message is below. Your help appreciated e...@emad-desktop:~/Desktop/py-editdist-0.3$ python setup.py build running build running build_ext building

[Tutor] parse text for paragraghs/sections

2009-04-20 Thread Dinesh B Vadhia
Hi! I want to parse text and pickup sections. For example, from the text: t = """abc DEF ghi jkl MNO pqr""" ... pickup all text between the tags and and replace with another piece of text. I tried t = re.sub(r"\[A-Za-z0-9]\", "DBV", t) ... but it doesn't work. How do you do this with

Re: [Tutor] Looping

2009-04-20 Thread A.T.Hofkamp
Matt wrote: Hey everyone, First post to this list. I hope I'm doing it right. Let's say I want to run func 10 times Is there a more pythonic way to do it than this: for i in xrange(10): func() no, that looks fine for your requirement. What may be a bit weird here is the requirement to run

Re: [Tutor] Looping

2009-04-20 Thread W W
On Mon, Apr 20, 2009 at 8:48 AM, Matt > wrote: > Hey everyone, > > First post to this list. I hope I'm doing it right. > > Let's say I want to run func 10 times Is there a more pythonic way to do it > than this: > for i in xrange(10): > func() AFAIK that's the most pythonic way to do it... and

[Tutor] String Encoding problem

2009-04-20 Thread Matt
Hey everyone, I'm hoping someone here can help me solve an odd problem (bug?). I'm having trouble with string encoding, object deletion, and the xml.etree library. If this isn't the right list to be posting this question, please let me know. I'm new to Python and don't know of any other "help me"

[Tutor] Looping

2009-04-20 Thread Matt
Hey everyone, First post to this list. I hope I'm doing it right. Let's say I want to run func 10 times Is there a more pythonic way to do it than this: for i in xrange(10): func() Thanks. ___ Tutor maillist - Tutor@python.org http://mail.python.org

Re: [Tutor] Webpy vs Django

2009-04-20 Thread vishwajeet singh
Thanks for your elaborate reply. On Mon, Apr 20, 2009 at 12:47 AM, Scott SA wrote: > On Apr 19, 2009, at 4:52 AM, vishwajeet singh wrote: > > This is not to flame any war; I just wanted to know the key features to >> consider among the two web frame works. >> >> What advantage and disadvantages

Re: [Tutor] vars()

2009-04-20 Thread Padmanaban Ganesan
Hello Denis, Please find more details , Use cases about the Built-in in the following book under the *Chapter 9* - Oops, Creating modules. *Book Name :* Python Programming for the Absolute Beginner *Author:* Michael Dawson Ta, Paddy 2009/4/20 spir > Hello, > > Just discovered vars(). Looking

Re: [Tutor] Reading from files problem

2009-04-20 Thread Alan Gauld
"Scott SA" wrote May have been a bad assumption on my part as I envisioned pickling a dict. and that just got too complicated. A pickled dict? That would be a shelve mebbe? PS. My email is acting up, did my prev. message actually make it to the list? Yes, I saw it just after sending m

[Tutor] vars()

2009-04-20 Thread spir
Hello, Just discovered vars(). Looking for the reasons and use cases that led to introduce this builtin. But could not find any reference. Any pointer/clue? Denis PS: same about all() and any() -- but here I found some literature... in french: fr.wikipedia.org/wiki/Python_(langage) -- la v

Re: [Tutor] Reading from files problem

2009-04-20 Thread Scott SA
On Apr 20, 2009, at 12:59 AM, Alan Gauld wrote: You might want to store the data in a dictionary keyed by ID number? I had thought of suggesting this, but it appeared that the OP was going to re-iterate the file each time he wished to query the CSV. May have been a bad assumption on my par

Re: [Tutor] Reading from files problem

2009-04-20 Thread spir
Le Mon, 20 Apr 2009 07:59:15 +0100, "Alan Gauld" s'exprima ainsi: > So I'd change the structure to be like this(pseudo code) > > students = dict() # empty dict > for line in gradesfile: > line = line.split(',') > s = Student() > s.id = line[0] > s.lastname = line[1] > etc...

Re: [Tutor] Reading from files problem

2009-04-20 Thread spir
Le Mon, 20 Apr 2009 07:59:15 +0100, "Alan Gauld" s'exprima ainsi: > > #Open and read text file > > > > gradesfile = open("grades.dat", "r" > > for lines in gradesfile: > >lines = lines.split(",") > >identifier = lines[0] > >lastname = lines[1] > >firstname = lines[2] > >major

Re: [Tutor] Reading from files problem

2009-04-20 Thread Alan Gauld
"Chris Castillo" wrote I am trying to open a text file and read multiple lines containing the following: 745777686,Alam,Gaus,CIS,15,30,25,15,5,31,15,48,70,97 888209279,Anderson,Judy,Math Ed,14,30,30,13,11,30,16,18,58,72 You could use the CSV module for this, although a basic for loop is fin