[Tutor] Very Newbie
Hey to the tutors. I am a newbie of course about the only background is some old qbasic and very little c and perl. I have been wanting to write my own Web Server Program and when I saw a few times mentioned around python about it I am starting to check into it. If the is anyone who has done such a thing or can oint me in the best direction for learning about it please respond. Thanks in Advance signature.asc Description: Digital signature ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Very Newbie
Hi, > I have been wanting to write > my own Web Server Program and when I saw a few times mentioned around > python about it I am starting to check into it. Take a look at the BaseHTTPServer[0] and the SimpleHTTPServer[1], both come with Python. [0] http://docs.python.org/lib/lib.html [1] http://docs.python.org/lib/module-SimpleHTTPServer.html -- pub 1024D/6EBDA359 1999-09-20 Lutz Horn <[EMAIL PROTECTED]> 438D 31FC 9300 CED0 1CDE A19D CD0F 9CA2 6EBD A359 http://purl.oclc.org/NET/lutz.horn DSL Komplett von GMX +++ Supergünstig und stressfrei einsteigen! AKTION "Kein Einrichtungspreis" nutzen: http://www.gmx.net/de/go/dsl ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Looking for a Pythonic way to pass variable number of lists to zip()
On Mon, 21 Mar 2005 22:51:31 -0800, Sean Perry <[EMAIL PROTECTED]> wrote: > Tony Cappellini wrote: > > well, I would have said "apply(zip, (l1, l2, l3, ...))" but apply has > been deprecated in 2.3. > > So how about this? > > arg_list = [] > # fill up arg_list > zipped = zip(*arg_list) > I met a similar question. what if one has L = [[1,2],[3,4]], K = [100, 200] How to 'zip' a List like [[1,2,100], [3,4,200]]? -- With best wishes! Shidai ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] OT - SQL methodology.
Liam Clarke wrote: Hi, This is a SQL query for the advanced db gurus among you (I'm looking at Kent...) Uh oh, you're in trouble if you think I'm an "advanced db guru" :-) After I've run an insert statement, should I get the new primary key (it's autoincrementing) by using PySQLite's cursor.lastrowid in a select statement, or is there a more SQLish way to do this? AFAIK there is no standard SQL way to do this, it is database-dependent. Python DB-API provides a portable interface using lastrowid; I would use that. You don't have to do another select, lastrowid is an attribute of the cursor itself. It calls the SQLite function sqlite_last_insert_rowid(). In the SQL books I've got, they always seem to have an optional select statement on the end of inserts/updates, and I was thinking maybe I could do it that way also, but I can't figure out a logical way of putting 'select primary_key from foo where primary_key value > every other primary_key value' Use cursor.lastrowid, that's what it is for. Kent ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Very Newbie
Terry Johnson wrote: Hey to the tutors. I am a newbie of course about the only background is some old qbasic and very little c and perl. I have been wanting to write my own Web Server Program and when I saw a few times mentioned around python about it I am starting to check into it. If the is anyone who has done such a thing or can oint me in the best direction for learning about it please respond. Thanks in Advance There are many options for doing this. For a very simple server you might look at the standard library modules mentioned by Lutz; there is also a CGIHTTPServer module. You can also write CGI programs in Python for use with another web server such as Apache. Basic information about writing CGI's in Python is here: http://www.python.org/topics/web/basic-cgi.html Beyond that, the options multiply. This web page lists many of them: http://www.python.org/moin/WebProgramming Snakelets is one that is oriented toward ease of learning. Quixote, CherryPy and Twisted are probably the most popular. If you give us some more information we might be able to help you narrow down the options a little. Is this just for fun and learning or will it be a production site eventually? Do you want to create dynamic content or just serve static web pages? Ultimately though the selection is a matter of finding an alternative you are comfortable with. Kent ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Looking for a Pythonic way to pass variable number of lists to zip()
Shidai Liu wrote: On Mon, 21 Mar 2005 22:51:31 -0800, Sean Perry <[EMAIL PROTECTED]> wrote: arg_list = [] # fill up arg_list zipped = zip(*arg_list) I met a similar question. what if one has L = [[1,2],[3,4]], K = [100, 200] What do you want to do with these lists? How to 'zip' a List like [[1,2,100], [3,4,200]]? >>> zip(*[[1,2,100], [3,4,200]]) [(1, 3), (2, 4), (100, 200)] If that's not what you mean, please give an example of the input *and results* you want. Kent ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Visual Python from Active State
Hi, I would like to get comments on Pros/Cons of using Visual Python. On another note, I have created a couple of MS Access databases for my work. At a recent conference, a lot of people have expressed an interest in using these as products for their own use. I am looking for ways to code a mechanism to have license keys for evaluation (30day/60day trial, and fully licensed version, etc.). I would like to use this opportunity to jump into using Python as the development platform if possible. Most of the work I do is in the MS Office Professional. regards, Ramkumar ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Python cgi doesn't get data from html form as expected
I have recently started doing cgi in Python and have run into a problem. I have an html form which has various widgets which accept data. I also have this in that html file: formdata.py runs but doesn't seem to contain the data from the form. I'm not sure of the format for the for with regard to FieldStorage btw. Here is the contents of formdata.py: #! /usr/bin/python import cgitb, os, sys cgitb.enable() import cgi print "Content-Type: text/html\n\n" print "" form = cgi.FieldStorage() for each in form: print "each" print form['fname'].value, form['lname'].value #print "address:", form['addr'].value() print "" -- ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Python cgi doesn't get data from html form as expected
I haven't done too much web stuff (or much of anything) with python, but I looked into your question a bit (researching other's problems may help me avoid them =)). A quick search brought up this page which seems to have information which may help you. http://gnosis.cx/publish/programming/feature_5min_python.html Hope that helps. Best Regards, Michael Lasky On Tue, 2005-03-22 at 14:02 +, Vicki Stanfield wrote: > I have recently started doing cgi in Python and have run into a problem. I > have an html form which has various widgets which accept data. I also have > this in that html file: > > > > formdata.py runs but doesn't seem to contain the data from the form. I'm > not sure of the format for the for with regard to FieldStorage btw. Here > is the contents of formdata.py: > > > #! /usr/bin/python > import cgitb, os, sys > cgitb.enable() > > import cgi > > print "Content-Type: text/html\n\n" > print "" > form = cgi.FieldStorage() > for each in form: > print "each" > print form['fname'].value, form['lname'].value > #print "address:", form['addr'].value() > print "" > -- > > ___ > 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 cgi doesn't get data from html form as expected
> I haven't done too much web stuff (or much of anything) with python, but > I looked into your question a bit (researching other's problems may help > me avoid them =)). A quick search brought up this page which seems to > have information which may help you. > > http://gnosis.cx/publish/programming/feature_5min_python.html > > Hope that helps. > Best Regards, > Michael Lasky I don't see anything in that page that changes what I am doing. I can get rid of everything that has to do with retrieving data from cgi-FieldStorage, and the code executes fine although I get a blank page. I have revised the code somewhat, but the initial problem of cgi.FieldStorage being empty is still there. I don't get an error now, just an empty page. Here is the revised code: #! /usr/bin/python print "Content-Type: text/html\n\n" print print "\n\n" import cgitb, os, sys cgitb.enable() sys.strerr = sys.stdout import cgi form = cgi.FieldStorage() field_list = '\n' for field in form.keys(): field_list = field_list + '%s\n' % field field_list = field_list + '\n' print field_list print "\n\n" ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Python cgi doesn't get data from html form as expected
Vicki Stanfield wrote: I don't see anything in that page that changes what I am doing. I can get rid of everything that has to do with retrieving data from cgi-FieldStorage, and the code executes fine although I get a blank page. I have revised the code somewhat, but the initial problem of cgi.FieldStorage being empty is still there. I don't get an error now, just an empty page. Here is the revised code: #! /usr/bin/python print "Content-Type: text/html\n\n" print print "\n\n" import cgitb, os, sys cgitb.enable() sys.strerr = sys.stdout import cgi form = cgi.FieldStorage() field_list = '\n' for field in form.keys(): field_list = field_list + '%s\n' % field field_list = field_list + '\n' print field_list print "\n\n" Please post the HTML for the form you are submitting and the HTML from a View Source on the result. Kent ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Looking for a Pythonic way to pass variable
On Tuesday, Mar 22, 2005, at 05:01 America/Chicago, [EMAIL PROTECTED] wrote: I met a similar question. what if one has L = [[1,2],[3,4]], K = [100, 200] How to 'zip' a List like [[1,2,100], [3,4,200]]? I would do something like: ### for i in range(len(L)): L[i].append(K[i]) ### /c ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] primes - sieve of odds
Hi Gregor, I had done the same thing. I also noted that assigning (or inserting) an element into a list is faster than creating a new list: l.insert(0,2) is faster than l = [2]+l. ### def sieve (maximum): if maximum < 2: return [] limit = int(maximum**0.5) nums = range(1,maximum+1,2) nums[0] = None for p in nums: if p: if p > limit: break nums[(p*p)//2::p] = [False]*(1+(maximum//p- p)//2) nums[0] = 2 return filter(None, nums) ### /c Hi Sean! Thanks for your measurements. In the meantime I did another amendment, leaving out the even numbers from the sieve. It goes like this: def sieve(maximum): nums = range(3, maximum+1, 2) for p in nums: if p: if p*p > maximum: break start = (p*p-2)//2 nums[start::p] = [False]*(1+((maximum-3)//2-start)//p) return [2] + filter(None, nums) Perhaps not very elegant. But approximately twice as fast as the former version. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Looking for a Pythonic way to pass variable
C Smith wrote: On Tuesday, Mar 22, 2005, at 05:01 America/Chicago, [EMAIL PROTECTED] wrote: I met a similar question. what if one has L = [[1,2],[3,4]], K = [100, 200] How to 'zip' a List like [[1,2,100], [3,4,200]]? I would do something like: ### for i in range(len(L)): L[i].append(K[i]) ### Oh, the light goes on :-) Thanks C Smith! Here is another way: >>> L = [[1,2],[3,4]] >>> K = [100, 200] >>> [ x+[y] for x, y in zip(L, K) ] [[1, 2, 100], [3, 4, 200]] Note C Smith's approach modifies L to include the items in K; my approach makes a new list. Kent ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] OT - SQL methodolgy
> > In the SQL books I've got, they always seem to have an optional select > > statement on the end of inserts/updates, and I was thinking maybe I > > could do it that way also, but I can't figure out a logical way of > > putting > > > > 'select primary_key from foo where primary_key value > every other > > primary_key value' > > > > select max(primary_key) from foo? select max will NOT work reliably when you have concurrent database inserts. You could obtain the number from someone else's insert. You need to use the function provided by the RDBMS that is tied to your connection/cursor so that you retrieve the primary_key that was assigned to *your* record. (I understood your request to be looking for the primary_key auto-assigned to your insert statement) -- Lloyd Kvam Venix Corp ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Python cgi doesn't get data from html form as expected
> Please post the HTML for the form you are submitting and the HTML from a > View Source on the result. > > Kent Sorry to have bothered the list. I figured out the answer (sort of). I had parse the HTML code through an XHTML parser which removed all the name= leaving id= only. That doesn't work with the cgi.FieldStorage function. I still don't know how to do it with XHTML which doesn't evidently support the name= at all. So, html it is. Thanks, Vicki ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] CGI script to create an XML document from an HTML form
Hi, I'm just starting to get my feet wet with Python. I'm trying to write a CGI script to create an XML document using input from a web form. The created document would be a MODS record[1], so I already have a Schema for it. I think I could make it work if I just feed the input into a long string as variables, then write that out to a new document, but I'd like to start investigating some of Python's XML modules because that's a sexier solution and I'll probably be doing more work in XML in the future. I've been looking around at various resources such as the Python/XML Howto[2], some of the articles by Uche Ogbuji[3], and elsewhere, and frankly I'm a little overwhelmed by the many seemingly overlapping methods. Which one would the wise tutors recommend for my situation? gabe [1] http://www.loc.gov/standards/mods/ [2] http://pyxml.sourceforge.net/topics/howto/xml-howto.html [3] http://www.xml.com/pub/au/84 ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Looking for a Pythonic way to pass variable
On Tue, 22 Mar 2005 13:30:09 -0500, Kent Johnson <[EMAIL PROTECTED]> wrote: > C Smith wrote: > > > > On Tuesday, Mar 22, 2005, at 05:01 America/Chicago, > > [EMAIL PROTECTED] wrote: > > > >> I met a similar question. > >> what if one has L = [[1,2],[3,4]], K = [100, 200] > >> How to 'zip' a List like [[1,2,100], [3,4,200]]? > >> > > I would do something like: > > > > ### > > for i in range(len(L)): > > L[i].append(K[i]) > > ### > > Oh, the light goes on :-) Thanks C Smith! > > Here is another way: > >>> L = [[1,2],[3,4]] > >>> K = [100, 200] > >>> [ x+[y] for x, y in zip(L, K) ] > [[1, 2, 100], [3, 4, 200]] > > Note C Smith's approach modifies L to include the items in K; my approach > makes a new list. Just for kicks - if you don't mind if the 100 and 200 appear first instead of last, and conversion of your inner lists to tuples, then: >>> L = [[1,2], [3,4]] >>> K = [100, 200] >>> zip(K, *L) [(100, 1, 3), (200, 2, 4)] works, and looks a little nicer. Also, to modify the list in-place with a listcomp, you could use: >>> L = [[1,2], [3,4]] >>> K = [100, 200] >>> [x.append(y) for x, y in zip(L, K)] [None, None] >>> L [[1, 2, 100], [3, 4, 200]] And, to create a new list in the format you originally asked for, we can modify the first trick I showed you: >>> L = [[1,2], [3,4]] >>> K = [100, 200] >>> [[b,c,a] for a,b,c in zip(K, *L)] [[1, 3, 100], [2, 4, 200]] which I think is pretty cool, if a little obtuse. Peace Bill Mill bill.mill at gmail.com ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Looking for a Pythonic way to pass variable number of lists to zip()
> well, I would have said "apply(zip, (l1, l2, l3, ...))" but apply has > been deprecated in 2.3. Hi Sean, Sorry for straying away from the original poster's question, but do you know why apply() is being deprecated? This is new to me! ... ok, I see some discussion on it: http://mail.python.org/pipermail/python-bugs-list/2004-October/025450.html And I now see the reference to it in the "Code Migration and Modernization" PEP 290: http://www.python.org/peps/pep-0290.html#replace-apply-with-a-direct-function-call Wow, this is somewhat of a shock to me, that the syntactic sugar approach is the preferred approach to "apply" in Python. Ok, thanks for letting me know. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] CGI script to create an XML document from an HTML form
Gabriel Farrell wrote: I've been looking around at various resources such as the Python/XML Howto[2], some of the articles by Uche Ogbuji[3], and elsewhere, and frankly I'm a little overwhelmed by the many seemingly overlapping methods. Which one would the wise tutors recommend for my situation? I'm a fan of ElementTree for XML work. It is kind of bare-bones but what is there is very easy to use. The main thing I miss is full XPath support. http://effbot.org/zone/element.htm Kent ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Looking for a Pythonic way to pass variable
On Tue, 22 Mar 2005 15:27:02 -0500, Bill Mill <[EMAIL PROTECTED]> wrote: > >>> zip(K, *L) > [(100, 1, 3), (200, 2, 4)] Any idea why zip(*L, K) fails? -- With best wishes! Shidai ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] print command
On Mon, 21 Mar 2005 05:57:28 -0500 Kent Johnson <[EMAIL PROTECTED]> wrote: > Shitiz Bansal wrote: > > Now this is so basic, i am feeling sheepish asking > > about it. > > I am outputting to the terminal, how do i use a print > > command without making it jump no newline after > > execution, which is the default behaviour in python. > > To clarify: > > > > print 1 > > print 2 > > print 3 > > > > I want output to be > > > > 123 > > You can suppress the newline by ending the print statement with a comma, but > you will still get the > space: > > print 1, > print 2, > print 3 > > will print > 1 2 3 > > You can get full control of the output by using sys.stdout.write() instead of > print. Note the > arguments to write() must be strings: > > import sys > sys.stdout.write(str(1)) > sys.stdout.write(str(2)) > sys.stdout.write(str(3)) > sys.stdout.write('\n') > > Or you can accumulate the values into a list and print the list as Lutz has > suggested: > > l = [] > l.append(1) > l.append(2) > l.append(3) > print ''.join(map(str, l)) > > where map(str, l) generates a list of strings by applying str() to each > element of l: > >>> map(str, l) > ['1', '2', '3'] > > and ''.join() takes the resulting list and concatenates it into a single > string with individual > elements separated by the empty string ''. > > Kent > > ___ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor why make it difficult? ;) print 1, print '\b'+str(2), print '\b'+str(3) '\b' is the escape character for backspace. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Looking for a Pythonic way to pass variable
Shidai Liu wrote: On Tue, 22 Mar 2005 15:27:02 -0500, Bill Mill <[EMAIL PROTECTED]> wrote: zip(K, *L) [(100, 1, 3), (200, 2, 4)] Any idea why zip(*L, K) fails? I believe the *'ed item needs to be the last argument. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] iterating through large dictionary
Hi, I'm trying to print out all the attributes of a user account in active directory. I got a script from: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/303348/index_txt Now I'd like it to print pretty. What I have now is: import win32com,win32com.client def ad_dict(ldap_path,value_required=1): attr_dict={} adobj=win32com.client.GetObject(ldap_path) schema_obj=win32com.client.GetObject(adobj.schema) for i in schema_obj.MandatoryProperties: value=getattr(adobj,i) if value_required and value==None: continue attr_dict[i]=value for i in schema_obj.OptionalProperties: value=getattr(adobj,i) if value_required and value==None: continue attr_dict[i]=value return attr_dict user='LDAP://cn=Wardlaw\, Jeff,OU=IS Department,OU=IT department,DC=acpdom,DC=acp,DC=edu' for k, v in ad_dict(user): print "%s=%s" % (k, v) I get the following error when I try this: D:\Python24>ad-attr.py Traceback (most recent call last): File "D:\Python24\ad-attr.py", line 32, in ? for k, v in ad_dict(user): ValueError: too many values to unpack Thanks! -- --Jeff ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Fwd: Math Question
-- Forwarded message -- From: gerardo arnaez <[EMAIL PROTECTED]> Date: Tue, 22 Mar 2005 13:33:04 -0800 Subject: Math Question To: tutor@python.org This is a resend, but I change the subject so I can track this better, please excuse duplicate -- Forwarded message -- From: gerardo arnaez <[EMAIL PROTECTED]> Date: Tue, 22 Mar 2005 13:32:23 -0800 Subject: Re: Tutor Digest, Vol 13, Issue 65 To: tutor@python.org Hello, Im a newbie python user, love the way it "just makes sense" but Im also a working doctor and have been thinking about coumadin and how to dose it. I am not sure where to ask this, so I am going to ask on this list for two reasons 1. I intend to use python to prototype it. 2. There must some serious math dudes on this list or at least know enough math to let me know what I am talking about or point me in the right direction. The question is, When I adjust coumadin doses I normal have to use whole or half pills of the medicien the patient already has. Fer Instance, if a pt takes 5mg of coumadin a day, that's 35mg of coumadin week and suppose I do a test that says thye are not taking enough coumadin and to increase the dose by 10%, ie add another 3.5mg but have it split evenly over the week or at least every other day. normall, I would say ok Take 5mg coumadine everty but on mon and thurs day take 7.5mg (Note the patient only has 5mg tabs, which they can split to make dose adjust my 2.5) My question is, How would I solve this using math instead of geustimating it. What kind of math am I talking about here? If this is the wrong list, please point in the right direction. i've tried googlie for help, but I dont know enough to even formulate it into a a search expression Thanks all G On Tue, 22 Mar 2005 19:30:17 +0100 (CET), [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: > Send Tutor mailing list submissions to >tutor@python.org > > To subscribe or unsubscribe via the World Wide Web, visit >http://mail.python.org/mailman/listinfo/tutor > or, via email, send a message with subject or body 'help' to >[EMAIL PROTECTED] > > You can reach the person managing the list at >[EMAIL PROTECTED] > > When replying, please edit your Subject line so it is more specific > than "Re: Contents of Tutor digest..." > > Today's Topics: > > 1. Re: OT - SQL methodology. (Kent Johnson) > 2. Re: Very Newbie (Kent Johnson) > 3. Re: Looking for a Pythonic way to pass variable number of > lists to zip() (Kent Johnson) > 4. Visual Python from Active State ([EMAIL PROTECTED]) > 5. Python cgi doesn't get data from html form as expected > (Vicki Stanfield) > 6. Re: Python cgi doesn't get data from html form as expected > (Michael Lasky) > 7. Re: Python cgi doesn't get data from html form as expected > (Vicki Stanfield) > 8. Re: Python cgi doesn't get data from html form as expected > (Kent Johnson) > 9. Re: Looking for a Pythonic way to pass variable (C Smith) > 10. Re: primes - sieve of odds (C Smith) > 11. Re: Looking for a Pythonic way to pass variable (Kent Johnson) > > -- > > Message: 1 > Date: Tue, 22 Mar 2005 06:00:16 -0500 > From: Kent Johnson <[EMAIL PROTECTED]> > Subject: Re: [Tutor] OT - SQL methodology. > Cc: Tutor Tutor > Message-ID: <[EMAIL PROTECTED]> > Content-Type: text/plain; charset=ISO-8859-1; format=flowed > > Liam Clarke wrote: > > Hi, > > > > This is a SQL query for the advanced db gurus among you (I'm looking at > > Kent...) > > Uh oh, you're in trouble if you think I'm an "advanced db guru" :-) > > > > After I've run an insert statement, should I get the new primary key > > (it's autoincrementing) by using PySQLite's cursor.lastrowid in a > > select statement, or is there a more SQLish way to do this? > > AFAIK there is no standard SQL way to do this, it is database-dependent. > Python DB-API provides a > portable interface using lastrowid; I would use that. > > You don't have to do another select, lastrowid is an attribute of the cursor > itself. It calls the > SQLite function sqlite_last_insert_rowid(). > > > In the SQL books I've got, they always seem to have an optional select > > statement on the end of inserts/updates, and I was thinking maybe I > > could do it that way also, but I can't figure out a logical way of > > putting > > > > 'select primary_key from foo where primary_key value > every other > > primary_key value' > > Use cursor.lastrowid, that's what it is for. > > Kent > > -- > > Message: 2 > Date: Tue, 22 Mar 2005 06:09:03 -0500 > From: Kent Johnson <[EMAIL PROTECTED]> > Subject: Re: [Tutor] Very Newbie > Cc: tutor@python.org > Message-ID: <[EMAIL PROTECTED]> > Content-Type: text/plain; charset=ISO-8859-1; format=flowed > > Terry Johnson wrote: > > Hey to the tutors. I am a newbie of course about the only background is > > some old qbasic and very little c and perl. I have been wa
[Tutor] Re: Tutor Digest, Vol 13, Issue 65
Hello, Im a newbie python user, love the way it "just makes sense" but Im also a working doctor and have been thinking about coumadin and how to dose it. I am not sure where to ask this, so I am going to ask on this list for two reasons 1. I intend to use python to prototype it. 2. There must some serious math dudes on this list or at least know enough math to let me know what I am talking about or point me in the right direction. The question is, When I adjust coumadin doses I normal have to use whole or half pills of the medicien the patient already has. Fer Instance, if a pt takes 5mg of coumadin a day, that's 35mg of coumadin week and suppose I do a test that says thye are not taking enough coumadin and to increase the dose by 10%, ie add another 3.5mg but have it split evenly over the week or at least every other day. normall, I would say ok Take 5mg coumadine everty but on mon and thurs day take 7.5mg (Note the patient only has 5mg tabs, which they can split to make dose adjust my 2.5) My question is, How would I solve this using math instead of geustimating it. What kind of math am I talking about here? If this is the wrong list, please point in the right direction. i've tried googlie for help, but I dont know enough to even formulate it into a a search expression Thanks all G On Tue, 22 Mar 2005 19:30:17 +0100 (CET), [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: > Send Tutor mailing list submissions to >tutor@python.org > > To subscribe or unsubscribe via the World Wide Web, visit >http://mail.python.org/mailman/listinfo/tutor > or, via email, send a message with subject or body 'help' to >[EMAIL PROTECTED] > > You can reach the person managing the list at >[EMAIL PROTECTED] > > When replying, please edit your Subject line so it is more specific > than "Re: Contents of Tutor digest..." > > Today's Topics: > > 1. Re: OT - SQL methodology. (Kent Johnson) > 2. Re: Very Newbie (Kent Johnson) > 3. Re: Looking for a Pythonic way to pass variable number of > lists to zip() (Kent Johnson) > 4. Visual Python from Active State ([EMAIL PROTECTED]) > 5. Python cgi doesn't get data from html form as expected > (Vicki Stanfield) > 6. Re: Python cgi doesn't get data from html form as expected > (Michael Lasky) > 7. Re: Python cgi doesn't get data from html form as expected > (Vicki Stanfield) > 8. Re: Python cgi doesn't get data from html form as expected > (Kent Johnson) > 9. Re: Looking for a Pythonic way to pass variable (C Smith) > 10. Re: primes - sieve of odds (C Smith) > 11. Re: Looking for a Pythonic way to pass variable (Kent Johnson) > > -- > > Message: 1 > Date: Tue, 22 Mar 2005 06:00:16 -0500 > From: Kent Johnson <[EMAIL PROTECTED]> > Subject: Re: [Tutor] OT - SQL methodology. > Cc: Tutor Tutor > Message-ID: <[EMAIL PROTECTED]> > Content-Type: text/plain; charset=ISO-8859-1; format=flowed > > Liam Clarke wrote: > > Hi, > > > > This is a SQL query for the advanced db gurus among you (I'm looking at > > Kent...) > > Uh oh, you're in trouble if you think I'm an "advanced db guru" :-) > > > > After I've run an insert statement, should I get the new primary key > > (it's autoincrementing) by using PySQLite's cursor.lastrowid in a > > select statement, or is there a more SQLish way to do this? > > AFAIK there is no standard SQL way to do this, it is database-dependent. > Python DB-API provides a > portable interface using lastrowid; I would use that. > > You don't have to do another select, lastrowid is an attribute of the cursor > itself. It calls the > SQLite function sqlite_last_insert_rowid(). > > > In the SQL books I've got, they always seem to have an optional select > > statement on the end of inserts/updates, and I was thinking maybe I > > could do it that way also, but I can't figure out a logical way of > > putting > > > > 'select primary_key from foo where primary_key value > every other > > primary_key value' > > Use cursor.lastrowid, that's what it is for. > > Kent > > -- > > Message: 2 > Date: Tue, 22 Mar 2005 06:09:03 -0500 > From: Kent Johnson <[EMAIL PROTECTED]> > Subject: Re: [Tutor] Very Newbie > Cc: tutor@python.org > Message-ID: <[EMAIL PROTECTED]> > Content-Type: text/plain; charset=ISO-8859-1; format=flowed > > Terry Johnson wrote: > > Hey to the tutors. I am a newbie of course about the only background is > > some old qbasic and very little c and perl. I have been wanting to write > > my own Web Server Program and when I saw a few times mentioned around > > python about it I am starting to check into it. If the is anyone who has > > done such a thing or can oint me in the best direction for learning > > about it please respond. Thanks in Advance > > There are many options for doing this. For a very simple server you might > look at the standard > library modules mentioned by Lutz;
[Tutor] Math Question
This is a resend, but I change the subject so I can track this better, please excuse duplicate -- Forwarded message -- From: gerardo arnaez <[EMAIL PROTECTED]> Date: Tue, 22 Mar 2005 13:32:23 -0800 Subject: Re: Tutor Digest, Vol 13, Issue 65 To: tutor@python.org Hello, Im a newbie python user, love the way it "just makes sense" but Im also a working doctor and have been thinking about coumadin and how to dose it. I am not sure where to ask this, so I am going to ask on this list for two reasons 1. I intend to use python to prototype it. 2. There must some serious math dudes on this list or at least know enough math to let me know what I am talking about or point me in the right direction. The question is, When I adjust coumadin doses I normal have to use whole or half pills of the medicien the patient already has. Fer Instance, if a pt takes 5mg of coumadin a day, that's 35mg of coumadin week and suppose I do a test that says thye are not taking enough coumadin and to increase the dose by 10%, ie add another 3.5mg but have it split evenly over the week or at least every other day. normall, I would say ok Take 5mg coumadine everty but on mon and thurs day take 7.5mg (Note the patient only has 5mg tabs, which they can split to make dose adjust my 2.5) My question is, How would I solve this using math instead of geustimating it. What kind of math am I talking about here? If this is the wrong list, please point in the right direction. i've tried googlie for help, but I dont know enough to even formulate it into a a search expression Thanks all G On Tue, 22 Mar 2005 19:30:17 +0100 (CET), [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: > Send Tutor mailing list submissions to >tutor@python.org > > To subscribe or unsubscribe via the World Wide Web, visit >http://mail.python.org/mailman/listinfo/tutor > or, via email, send a message with subject or body 'help' to >[EMAIL PROTECTED] > > You can reach the person managing the list at >[EMAIL PROTECTED] > > When replying, please edit your Subject line so it is more specific > than "Re: Contents of Tutor digest..." > > Today's Topics: > > 1. Re: OT - SQL methodology. (Kent Johnson) > 2. Re: Very Newbie (Kent Johnson) > 3. Re: Looking for a Pythonic way to pass variable number of > lists to zip() (Kent Johnson) > 4. Visual Python from Active State ([EMAIL PROTECTED]) > 5. Python cgi doesn't get data from html form as expected > (Vicki Stanfield) > 6. Re: Python cgi doesn't get data from html form as expected > (Michael Lasky) > 7. Re: Python cgi doesn't get data from html form as expected > (Vicki Stanfield) > 8. Re: Python cgi doesn't get data from html form as expected > (Kent Johnson) > 9. Re: Looking for a Pythonic way to pass variable (C Smith) > 10. Re: primes - sieve of odds (C Smith) > 11. Re: Looking for a Pythonic way to pass variable (Kent Johnson) > > -- > > Message: 1 > Date: Tue, 22 Mar 2005 06:00:16 -0500 > From: Kent Johnson <[EMAIL PROTECTED]> > Subject: Re: [Tutor] OT - SQL methodology. > Cc: Tutor Tutor > Message-ID: <[EMAIL PROTECTED]> > Content-Type: text/plain; charset=ISO-8859-1; format=flowed > > Liam Clarke wrote: > > Hi, > > > > This is a SQL query for the advanced db gurus among you (I'm looking at > > Kent...) > > Uh oh, you're in trouble if you think I'm an "advanced db guru" :-) > > > > After I've run an insert statement, should I get the new primary key > > (it's autoincrementing) by using PySQLite's cursor.lastrowid in a > > select statement, or is there a more SQLish way to do this? > > AFAIK there is no standard SQL way to do this, it is database-dependent. > Python DB-API provides a > portable interface using lastrowid; I would use that. > > You don't have to do another select, lastrowid is an attribute of the cursor > itself. It calls the > SQLite function sqlite_last_insert_rowid(). > > > In the SQL books I've got, they always seem to have an optional select > > statement on the end of inserts/updates, and I was thinking maybe I > > could do it that way also, but I can't figure out a logical way of > > putting > > > > 'select primary_key from foo where primary_key value > every other > > primary_key value' > > Use cursor.lastrowid, that's what it is for. > > Kent > > -- > > Message: 2 > Date: Tue, 22 Mar 2005 06:09:03 -0500 > From: Kent Johnson <[EMAIL PROTECTED]> > Subject: Re: [Tutor] Very Newbie > Cc: tutor@python.org > Message-ID: <[EMAIL PROTECTED]> > Content-Type: text/plain; charset=ISO-8859-1; format=flowed > > Terry Johnson wrote: > > Hey to the tutors. I am a newbie of course about the only background is > > some old qbasic and very little c and perl. I have been wanting to write > > my own Web Server Program and when I saw a few times mentioned around > > python about it I am starting to check into it. If the is anyone who
[Tutor] Apology
I apologize to the group for the dupes and not cutting the extended tail of my previous messages ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
RE: [Tutor] iterating through large dictionary
> -Original Message- > From: [EMAIL PROTECTED] > [mailto:[EMAIL PROTECTED] On Behalf Of jeff > > Hi, Hey Jeff, > I'm trying to print out all the attributes of a user account in active > directory. I got a script from: > http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/303348 > /index_txt Hhhmm... I have some code that does basically the same thing, sans the printing. Mine looks up the user based on the sAMAccountName instead of the distinguishedName, though. > Now I'd like it to print pretty. [SNIP function] > user='LDAP://cn=Wardlaw\, Jeff,OU=IS Department,OU=IT > department,DC=acpdom,DC=acp,DC=edu' > for k, v in ad_dict(user): > print "%s=%s" % (k, v) > > I get the following error when I try this: > > D:\Python24>ad-attr.py > Traceback (most recent call last): > File "D:\Python24\ad-attr.py", line 32, in ? > for k, v in ad_dict(user): > ValueError: too many values to unpack Try this instead ... I think it should help: for k,v in ad_dict(user).items(): HTH, Christian http://www.dowski.com ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] iterating through large dictionary
On Tue, 22 Mar 2005 15:47:19 -0600, Christian Wyglendowski <[EMAIL PROTECTED]> wrote: > > -Original Message- > > From: [EMAIL PROTECTED] > > [mailto:[EMAIL PROTECTED] On Behalf Of jeff > > > > Hi, > > Hey Jeff, > > > I'm trying to print out all the attributes of a user account in active > > directory. I got a script from: > > http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/303348 > > /index_txt > > Hhhmm... I have some code that does basically the same thing, sans the > printing. Mine looks up the user based on the sAMAccountName instead of > the distinguishedName, though. > > > Now I'd like it to print pretty. > > [SNIP function] > > > user='LDAP://cn=Wardlaw\, Jeff,OU=IS Department,OU=IT > > department,DC=acpdom,DC=acp,DC=edu' > > for k, v in ad_dict(user): > > print "%s=%s" % (k, v) > > > > I get the following error when I try this: > > > > D:\Python24>ad-attr.py > > Traceback (most recent call last): > > File "D:\Python24\ad-attr.py", line 32, in ? > > for k, v in ad_dict(user): > > ValueError: too many values to unpack > > Try this instead ... I think it should help: > > > > for k,v in ad_dict(user).items(): > > yup, that was it. now i've got to make it pretty. -- --Jeff ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] iterating through large dictionary
D:\Python24>ad-attr.py Traceback (most recent call last): File "D:\Python24\ad-attr.py", line 32, in ? for k, v in ad_dict(user): ValueError: too many values to unpack Try this instead ... I think it should help: for k,v in ad_dict(user).items(): in 2.3 and newer, the preferred function is 'iteritems()' instead of 'items()'. Faster, less mem use, etc. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Apology
gerardo arnaez wrote: I apologize to the group for the dupes and not cutting the extended tail of my previous messages apology accepted. Your penance is to rewrite one of your python programs in Perl. (-: ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] OT - SQL methodolgy
Hi Lloyd, it's a SQLite database, with only one app connecting, so I'm not worried about concurrency right here, ( I think SQLite locks when you connect anyway), but it's always good to get pointers on best practise. Thanks to all. On Tue, 22 Mar 2005 14:10:24 -0500, Lloyd Kvam <[EMAIL PROTECTED]> wrote: > > > In the SQL books I've got, they always seem to have an optional > select > > > statement on the end of inserts/updates, and I was thinking maybe I > > > could do it that way also, but I can't figure out a logical way of > > > putting > > > > > > 'select primary_key from foo where primary_key value > every other > > > primary_key value' > > > > > > > select max(primary_key) from foo? > > select max will NOT work reliably when you have concurrent database > inserts. You could obtain the number from someone else's insert. > > You need to use the function provided by the RDBMS that is tied to your > connection/cursor so that you retrieve the primary_key that was assigned > to *your* record. > > (I understood your request to be looking for the primary_key > auto-assigned to your insert statement) > > -- > Lloyd Kvam > Venix Corp > > ___ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor > -- 'There is only one basic human right, and that is to do as you damn well please. And with it comes the only basic human duty, to take the consequences. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Livewires Help
Does python tutor cover livewires w.s help? ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Fwd: Math Question
OK, No fancy math here, so thee might be a cleaner way, but here is how I'd do it. > (Note the patient only has 5mg tabs, which they can split to make dose > adjust my 2.5) OK< so we are dealing with a unit size of 2.5mg. Convert the total dosage into 2.5mg units. 35mg = 35/2.5 = 14 units Divide the number of units by the number of days using integer division: divmod(14,7) -> 2,0 that tells us you need 2 units per day and no adjustment Add 10% => 14 + 1.4 = 15.4 units. YOu must decide to either round up or down, lets say you round up to 16 units divide the doze as before divmod(16,7) -> 2,2 that says 2 units per day and on 2 days an extra unit. (Which was your guestimate) If you rounded down to 15 divmoid(15,7) -> 2,1 which is 2 units/day and 1 day with an extra unit. > How would I solve this using math instead of geustimating it. > What kind of math am I talking about here? integer math with a hint of quantum techniques thrown in If the above didn't make sense just shout and we can explain in more detail. Alan G Author of the Learn to Program web tutor http://www.freenetpages.co.uk/hp/alan.gauld ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] .readlines() condensing multiple lines
Unless I'm mistaken .readlines() is supposed to return a list, where each index is a line from the file that was handed to it. Well I'm finding that it's putting more than one line of my file into a single list entry, and separating them with \r. Surely there's a way to have a one to one correlation between len(list) and the lines in the file the list was derived from...? ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] What does Python gain by having immutable types?
A friend recently asked my this didn't modify his original string variable s1="this is a string" s1.replace("is a", "is a short") "this is a short string" print s1 "this is a string" After showing him to change it to this s1 = s1.replace("is a", "is a short") print s1 "this is a short string" He then asked Why is it that the sort operation modfies the original list variable? l1=[] l1.append(3) l1.append(44) l1.append(1) l1.append(22) l1 [3, 44, 1, 22] l1.sort() l1 [1, 3, 22, 44] I don't know, but I think it has something to do with strings being immutable, whiles lists are mutable. So, other than the non-informative answer " because that's how the language was written" are there any other reasons how Python benefits from immutable types? Does it really matter if s1 is a different object, so long as it contains the expected modified string? The list variable is the same object, and contains the sorted list, so why bother with the complexity of immutable types at all? ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] What does Python gain by having immutable types?
Tony C wrote: The list variable is the same object, and contains the sorted list, so why bother with the complexity of immutable types at all? * only immutable objects can be dictionary keys * specifically immutable strings are a performance optimization ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Fwd: Math Question
On Tue, 22 Mar 2005 22:59:00 -, Alan Gauld <[EMAIL PROTECTED]> wrote: > OK, No fancy math here, so thee might be a cleaner way, but here > is how I'd do it. > Yikes. Thanks for insight and solving it, Btw, I bought your book a while ago and it was the first that explained classes to me in a a a way I got it, by explaining exactly what *self* stood for in all the examples. All the other books just went on, and never even thought of explaining leaving me for months in a dizzy on what the heck *self* meant in making classes Thanks for that and the help here > > (Note the patient only has 5mg tabs, which they can split to make > dose > > adjust my 2.5) > > OK< so we are dealing with a unit size of 2.5mg. Convert the total > dosage into 2.5mg units. 35mg = 35/2.5 = 14 units > > Divide the number of units by the number of days using integer > division: > > divmod(14,7) -> 2,0 > > that tells us you need 2 units per day and no adjustment > > Add 10% => 14 + 1.4 = 15.4 units. YOu must decide to either > round up or down, lets say you round up to 16 units > > divide the doze as before > > divmod(16,7) -> 2,2 > > that says 2 units per day and on 2 days an extra unit. > (Which was your guestimate) > > If you rounded down to 15 > > divmoid(15,7) -> 2,1 > > which is 2 units/day and 1 day with an extra unit. > > > How would I solve this using math instead of geustimating it. > > What kind of math am I talking about here? > > integer math with a hint of quantum techniques thrown in > > If the above didn't make sense just shout and we can explain > in more detail. > > Alan G > Author of the Learn to Program web tutor > http://www.freenetpages.co.uk/hp/alan.gauld > > ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] .readlines() condensing multiple lines
>From the docs - In addition to the standard fopen() values mode may be 'U' or 'rU'. If Python is built with universal newline support (the default) the file is opened as a text file, but lines may be terminated by any of '\n', the Unix end-of-line convention, '\r', the Macintosh convention or '\r\n', the Windows convention. All of these external representations are seen as '\n' by the Python program. If Python is built without universal newline support mode 'U' is the same as normal text mode. Note that file objects so opened also have an attribute called newlines which has a value of None (if no newlines have yet been seen), '\n', '\r', '\r\n', or a tuple containing all the newline types seen. So, try x = file(myFile, 'rU').readlines() Or try: x = file(myFile, 'rU') for line in x: #do stuff Let us know how that goes. Regards, Liam Clarke PS Worse come to worse, you could always do - x = file(myFile, 'r').read() listX = x.split('\r') On Tue, 22 Mar 2005 17:10:43 -0800, Mike Hall <[EMAIL PROTECTED]> wrote: > Unless I'm mistaken .readlines() is supposed to return a list, where > each index is a line from the file that was handed to it. Well I'm > finding that it's putting more than one line of my file into a single > list entry, and separating them with \r. Surely there's a way to have a > one to one correlation between len(list) and the lines in the file the > list was derived from...? > > ___ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor > -- 'There is only one basic human right, and that is to do as you damn well please. And with it comes the only basic human duty, to take the consequences. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Livewires Help
[EMAIL PROTECTED] wrote: Does python tutor cover livewires w.s help? We will try to answer any questions except direct homework questions. Do you have a specific question or problem? Kent ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] .readlines() condensing multiple lines
Liam Clarke wrote: Worse come to worse, you could always do - x = file(myFile, 'r').read() listX = x.split('\r') This will leave the \n in the strings. Reading with universal newlines is a better solution. Kent ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] .readlines() condensing multiple lines
Oh right, From his email, I got the impression he was getting a list like - [[abc\rdef\rghi\r]] On Wed, 23 Mar 2005 00:12:12 -0500, Kent Johnson <[EMAIL PROTECTED]> wrote: > Liam Clarke wrote: > > Worse come to worse, you could always do - > > x = file(myFile, 'r').read() > > listX = x.split('\r') > > This will leave the \n in the strings. Reading with universal newlines is a > better solution. > > Kent > > ___ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor > -- 'There is only one basic human right, and that is to do as you damn well please. And with it comes the only basic human duty, to take the consequences. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor