[Tutor] small floating point number problem

2006-02-07 Thread Smith
I just ran into a curious behavior with small floating points, trying to find the limits of them on my machine (XP). Does anyone know why the '0.0' is showing up for one case below but not for the other? According to my tests, the smallest representable float on my machine is much smaller than 1

Re: [Tutor] cannonical matrix representation?

2006-02-10 Thread Smith
| 3. cannonical matrix representation? (Mike Cheponis) | | What's the best way to represent a matrix M with 4 dimensions, such | as M[x][y][z][t] where each element in the sparse matrix could be a | simple number, or could be an executable Python function snipped that | returns a value when that

[Tutor] nice()

2006-02-12 Thread Smith
I've been thinking about a function that was recently proposed at python-dev named 'areclose'. It is a function that is meant to tell whether two (or possible more) numbers are close to each other. It is a function similar to one that exists in Numeric. One such implementation is   def arec

Re: [Tutor] nice()

2006-02-13 Thread Smith
ists, however, and so having it handy would be nice. | From: Greg Ewing <[EMAIL PROTECTED]> | Smith wrote: | || When teaching some programming to total newbies, a common || frustration is how to explain why a==b is False when a and b are || floats computed by different routes wh

[Tutor] *args consumption

2006-03-10 Thread Smith
I see that one way to use *arg in a function is to simply pass them on to another function that perhaps will unpack the arguments: ### def pass_along(func, *args): return func(*args) def adder(x,y): return x+y def suber(x,y): return x-y print pass_along(adder,1,2) print pass_along(su

Re: [Tutor] problems with numbers in my python code

2006-03-11 Thread Smith
| From: sjw28 | | Basically, I have a code with is almost finished but I've having | difficultly | with the last stage of the process. I have a program that gets assigns | different words with a different value via looking them up in a | dictionary: | | eg if THE is in the writing, it assigns

Re: [Tutor] *args consumption

2006-03-12 Thread Smith
Danny Yoo wrote: || Am I missing some other usage where you wouldn't want to unpack the || *arg? If not, would the following "behind the scenes" behavior be || possible/preferred? || || ### || def foo(*arg): || pass || ### || || automatically does this || || ### || def foo(*arg): || if l

Re: [Tutor] *args consumption

2006-03-13 Thread Smith
| From: "Anna Ravenscroft" | Subject: Re: [Tutor] *args consumption | To: "Kent Johnson" | | Thanks for a great example of what decorators are good for. DITTO! I've been wondering when those would be useful, and having a need in hand, I'm likely to learn it now. Thanks for explaining the useage

Re: [Tutor] Splitting a string into n-sized bytes

2006-03-14 Thread Smith
| From: "Steve Nelson" | | Further to my previous puzzling, I've been working out the best way to | chop a string up into n-sized words: | I think the follow use of groupby is from Raymond Hettinger from ASPN recipes. The batch() function will return an iterable to you in user-definable sized

Re: [Tutor] [BULK] Tutor Digest, Vol 25, Issue 57

2006-03-23 Thread Smith
| 7. Re: efficient method to search between two lists (Srinivas Iyyer) | for i in list_b: | ... co = i.split('\t')[2] | ... items = da.get(co) ^ -| | Are you sure that all co's are in da? One other thing that occurs t

Re: [Tutor] efficient method to search between two lists

2006-03-24 Thread Smith
Srinivas Iyyer wrote: | for i in list_b: | ... co = i.split('\t')[2] | ... items = da.get(co) ^ -| | Are you sure that all co's are in da? One other thing that occurs to me from looking at your dictionary approach is

[Tutor] Help - server health check reporter

2010-09-30 Thread Russell Smith
Hey guys, I’m trying to put together a script using urllib2, smtplib and stripogram/html2text which will use a healthcheck url, read the response after loading it and then email me the results without any unwanted html tags. I was able to do that but, when I get a timeout on one of the servers t

Re: [Tutor] WRITING XLS FROM OS.WALK()

2010-10-09 Thread Jed Smith
ble brain with respect to file handling. You might investigate the csv module that Python offers [1], and use it to write CSV. Excel can import that very easily. Hell, simply writing a list of filenames delimited by \n might be importable into Excel. [1]: http://docs.python.org/library/cs

Re: [Tutor] Ide To use? Other extras to install?

2010-10-11 Thread Jed Smith
you recommend me to install? (plug ins, libraries, etc) IPython. Very, very IPython. -- Jed Smith j...@jedsmith.org ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] Fw: Installing Pyserial for Python27 on Win 7

2010-11-22 Thread John Smith
On 11/22/2010 6:18 PM, Emile van Sebille wrote: On 11/22/2010 3:05 PM John Smith said... Hi, Emile - Install from sources? What is that? see http://pyserial.sourceforge.net/pyserial.html#installation the From Source section. I'm not sure what else may be required but it should help

[Tutor] Python 3 and tkinter Radiobuttons

2009-10-08 Thread bob smith
Hi. I’m using Tkinter to create a new Radiobutton in Python 3. However, when I create the button, it starts off looking selected instead of unselected (though it behaves correctly like an unselected Radiobutton). So this means when I create a group of Radiobuttons they all look selected when

Re: [Tutor] Python 3 and tkinter Radiobuttons

2009-10-10 Thread bob smith
te: Thu, 8 Oct 2009 20:43:21 -0400 > Subject: Re: [Tutor] Python 3 and tkinter Radiobuttons > From: ken...@tds.net > To: bobsmith...@hotmail.com > CC: tutor@python.org > > On Thu, Oct 8, 2009 at 6:04 PM, bob smith wrote: > > Hi. I’m using Tkinter to create a new Radiobutton in

Re: [Tutor] Python 3 and tkinter Radiobuttons

2009-10-11 Thread bob smith
> To: tutor@python.org > From: alan.ga...@btinternet.com > Date: Sun, 11 Oct 2009 19:32:20 +0100 > Subject: Re: [Tutor] Python 3 and tkinter Radiobuttons > > > "Kent Johnson" wrote > > > Without the v.set() it starts with no button selected. With v.set() it > > starts with one button selecte

[Tutor] Re: Printing two elements in a list

2004-12-19 Thread C Smith
Jacob S. wrote: Would this work for you? a = ['Name = stuff','CGTATAGCTAGCTA','Name = stuff','CGATATGCCGGCTA'] for index,thing in enumerate(a): if "Name=" in thing: del a[index] I know, that it might be slow, but I thought that maybe it would hold its own because it doesn't have to imp

RE: [Tutor] Control flow

2005-01-28 Thread Smith, Jeff
One way out of the top level is to call sys.exit(1) -Original Message- From: Orri Ganel [mailto:[EMAIL PROTECTED] Sent: Friday, January 28, 2005 4:26 PM To: Gilbert Tsang; Tutor@python.org Subject: Re: [Tutor] Control flow Gilbert Tsang wrote: > Hi there, I have this logic that

[Tutor] Matching with beginning of the line in the character set

2005-02-01 Thread Smith, Jeff
I want to match a string which is preceeded by a space or occurs at the beginning of the line. I also don't want to catch the preceeding character as a group. I have found both of the following to work re.compile('(?:^|\s)string') re.compile('(?:\A|\s)string') But would prefer to

RE: [Tutor] Matching with beginning of the line in the character set

2005-02-01 Thread Smith, Jeff
Kent Johnson [mailto:[EMAIL PROTECTED] Sent: Tuesday, February 01, 2005 1:15 PM Cc: Tutor@python.org Subject: Re: [Tutor] Matching with beginning of the line in the character set Smith, Jeff wrote: > I want to match a string which is preceeded by a space or occurs at > the beginning of the li

RE: [Tutor] Are you allowed to shoot camels? [kinda OT]

2005-02-03 Thread Smith, Jeff
Title: Message Nicholas,   Well put.  I come from a physics FORTRAN background and when I decided to learn C and start using it I heard the same arguments: it's too hard to read.   It's a silly argument to use against a language.  It's like an English-only speaker claiming he won't learn Gr

RE: [Tutor] Are you allowed to shoot camels? [kinda OT]

2005-02-03 Thread Smith, Jeff
ations. Jeff -Original Message- From: Jacob S. [mailto:[EMAIL PROTECTED] Sent: Thursday, February 03, 2005 4:40 PM To: Smith, Jeff; [EMAIL PROTECTED]; tutor@python.org Subject: Re: [Tutor] Are you allowed to shoot camels? [kinda OT] MessageI hate to be a spoiled sport and do exactly w

RE: [Tutor] Are you allowed to shoot camels? [kinda OT]

2005-02-03 Thread Smith, Jeff
--- From: Alan Gauld [mailto:[EMAIL PROTECTED] Sent: Thursday, February 03, 2005 5:14 PM To: [EMAIL PROTECTED]; Smith, Jeff Cc: tutor@python.org; [EMAIL PROTECTED] Subject: Re: [Tutor] Are you allowed to shoot camels? [kinda OT] > > For the non-Perl people here, let me defend Perl by saying it is

RE: [Tutor] Are you allowed to shoot camels? [kinda OT]

2005-02-03 Thread Smith, Jeff
Who knows, maybe it's a left-brain, right-brain thing. And it wouldn't be the first time I was told my brain was "wired differently" from the general public. Just ask my wife :-) Jeff -Original Message- From: Alan Gauld [mailto:[EMAIL PROTECTED] Sent: Thursday,

RE: [Tutor] Are you allowed to shoot camels? [kinda OT]

2005-02-04 Thread Smith, Jeff
they should be removed from the language. I also like Perl's unless statement but really prefer VBs DO/WHILE/UNTIL/LOOP constuct. Nothing beats it for clarity of expression. Jeff -Original Message- From: Alan Gauld [mailto:[EMAIL PROTECTED] Sent: Thursday, February 03, 2005

RE: [Tutor] Are you allowed to shoot camels? [kinda OT]

2005-02-04 Thread Smith, Jeff
with Pascal and decided it was too terse :-) PROCEDURE myfun Became PROCEDURE myfun BODY IS (or something similar, it's been years...err, decades) Jeff -Original Message- From: Alan Gauld [mailto:[EMAIL PROTECTED] Sent: Thursday, February 03, 2005 6:31 PM To: Smith, Jeff; [EMAIL PROT

RE: [Tutor] Re: Are you allowed to shoot camels? [kinda OT]

2005-02-04 Thread Smith, Jeff
Roel, That was well put. Too many people complain about certain language features because of the way they are abused independent of whether or not they have any value when used properly. In that case it's throwing the baby out with the bath-water...and won't achieve anything since bad programmer

RE: [Tutor] Are you allowed to shoot camels? [kinda OT]

2005-02-04 Thread Smith, Jeff
x27;a' : do_this_function, 'b' : do_that_function, 'c' : do_that_function, 'd' : do_pass_function } ftable.get(var, do_default_function)() Ugh! -Original Message- From: Alan Gauld [mailto:[EMAIL PROTECTED] Sent: Friday, Februar

RE: [Tutor] Are you allowed to shoot camels? [kinda OT]

2005-02-04 Thread Smith, Jeff
l for us to be anything but generous and kind with each other. I guess this is a hot topic. :^) Marilyn On Fri, 4 Feb 2005, Smith, Jeff wrote: > Now who's joking? Are you saying that > > switch var: > case 'a': > print 'a' >

RE: [Tutor] Are you allowed to shoot camels? [kinda OT]

2005-02-07 Thread Smith, Jeff
ftable.get(var, lambda: print 'default case')() File "C:\scratch\Script1.py", line 2 ftable = { 'a' : lambda: print 'a', ^ SyntaxError: invalid syntax Jeff -Original Message- From: Alan Gauld [mailto:[EMAIL PR

RE: [Tutor] Are you allowed to shoot camels? [kinda OT]

2005-02-07 Thread Smith, Jeff
That's kinda what I thought but a couple of people suggested that I used lambdas to make it clearer that I figured I was doing something wrong... Jeff -Original Message- From: Bob Gailer [mailto:[EMAIL PROTECTED] Sent: Monday, February 07, 2005 9:48 AM To: Smith, Jeff; tutor@pytho

RE: [Tutor] Are you allowed to shoot camels? [kinda OT]

2005-02-07 Thread Smith, Jeff
Gailer [mailto:[EMAIL PROTECTED] Sent: Monday, February 07, 2005 10:10 AM To: Smith, Jeff; tutor@python.org Subject: RE: [Tutor] Are you allowed to shoot camels? [kinda OT] At 07:43 AM 2/7/2005, Smith, Jeff wrote: >That's kinda what I thought but a couple of people suggested that I &

RE: [Tutor] manipulating a file

2005-02-07 Thread Smith, Jeff
-Original Message- From: Alan Gauld [mailto:[EMAIL PROTECTED] Sent: Monday, February 07, 2005 2:49 PM To: Reed L. O'Brien; tutor@python.org Subject: Re: [Tutor] manipulating a file >You should add a newline character otherwise you will just >get one enormously long line! > >

RE: [Tutor] Are you allowed to shoot camels? [kinda OT]

2005-02-07 Thread Smith, Jeff
a: p} print ftable.get(var, lambda: 'default case')() And what you get is: That's hardly a pass :-) Jeff -Original Message- From: Alan Gauld [mailto:[EMAIL PROTECTED] Sent: Monday, February 07, 2005 3:06 PM To: Smith, Jeff; Bob Gailer; tutor@python.org Subject: Re: [Tutor]

RE: [Tutor] Are you allowed to shoot camels? [kinda OT]

2005-02-08 Thread Smith, Jeff
Alan, That's no good. You still get something printed out. In this case: None Jeff -Original Message- From: Alan Gauld [mailto:[EMAIL PROTECTED] Sent: Monday, February 07, 2005 6:15 PM To: Smith, Jeff; Bob Gailer; tutor@python.org Subject: Re: [Tutor] Are you allowed to

RE: [Tutor] Are you allowed to shoot camels? [kinda OT]

2005-02-08 Thread Smith, Jeff
Jeff, It looks like that finally is the simplest expression of the original switch statement: import sys def p(): pass ftable = { 'a' : lambda: sys.stdout.write('a\n'), 'b' : lambda: sys.stdout.write('b or c\n'), 'c' : lambda: sys.stdout.write('b or c\n'), 'd'

RE: [Tutor] Are you allowed to shoot camels? [kinda OT]

2005-02-08 Thread Smith, Jeff
EMAIL PROTECTED] Sent: Tuesday, February 08, 2005 1:24 PM To: Smith, Jeff; Bob Gailer; tutor@python.org Subject: Re: [Tutor] Are you allowed to shoot camels? [kinda OT] > That's no good. You still get something printed out. In this case: > > None Of course, silly me, p will retur

[Tutor] Perl Symbology (was: Are you allowed to shoot camels?)

2005-02-10 Thread Smith, Jeff
To all those who talked about hating the symbology in Perl and the suggestion that it should be removed from a later version. I just remembered what you get for that symbology that I really do like about Perl: variable interpolation in strings: C: sprintf(newstr,"%s %d %f",s,n,r); Becomes a litt

RE: [Tutor] Re: Perl Symbology

2005-02-10 Thread Smith, Jeff
Abel, No, you don't have to escape them all. Perl treats single and double quotes differently. Single-quoted strings don't do interpolation and double-quoted strings do. Jeff -Original Message- From: Abel Daniel [mailto:[EMAIL PROTECTED] Sent: Thursday, February 10, 2005 12:23 PM To

[Tutor] Simple question on creating a filter

2005-02-11 Thread Smith, Jeff
I'm sorry to both with such a simple question but I've looked in the normal places and don't see the quick and dirty answer I know must exist. I want to write a simple line selection filter that could be used like: filter < file In Perl I would do: while (<>) { print if line meets selec

RE: [Tutor] Simple question on creating a filter

2005-02-11 Thread Smith, Jeff
t, I've had the same problem with Perl but because of my newbie status I assumed I was doin' something wrong :-) -Original Message- From: Bill Mill [mailto:[EMAIL PROTECTED] Sent: Friday, February 11, 2005 9:38 AM To: Smith, Jeff Cc: tutor@python.org Subject: Re: [Tutor] Simple q

[Tutor] Precompiling to bytecode

2005-02-24 Thread Smith, Jeff
I notice that python only pre-compiles imported modules and not the main script. The only way I seem to be able to get this to happen is to run python -c "import mainscript" Am I missing something? Thanks, Jeff ___ Tutor maillist - Tutor@python.org

RE: [Tutor] sys.argv[1: ] help

2005-02-28 Thread Smith, Jeff
Richard, I have no problems running your example. It would be helpful in the future ot let us know which version and variant of Python you are running. I am using the canonical (as oppose to ActiveState) Python 2.4. >From the command prompt, type assoc .py and you should see .py=Python.File

RE: [Tutor] gensuitemodule?

2005-02-28 Thread Smith, Jeff
http://www.python.org/doc/2.3.5/mac/module-gensuitemodule.html -Original Message- From: Mike Hall [mailto:[EMAIL PROTECTED] Sent: Friday, February 25, 2005 7:19 PM To: tutor@python.org Subject: [Tutor] gensuitemodule? I'm seeing it used in a Python/Applescript tutorial, though am unclea

[Tutor] working with new classes

2005-03-08 Thread C Smith
Hello, After learning about the new class behavior, I am trying to implement a circular type list where, for example, you can compare the nth value to the "(n+1)th" value without worrying about going past the end of the list. (An old approach might be to create a function that converts a given

Re: [Tutor] working with new classes

2005-03-09 Thread C Smith
Thanks to Sean and Kent for replies. I found a site that provided some good examples, too, at http://www.cafepy.com/articles/python_attributes_and_methods/ ch03s02.html Here's a blurb from the title page: wep page excerpt Shalabh Chaturvedi Copyright © 2004 Shalabh Chaturvedi This book

Re: [Tutor] help

2005-03-13 Thread C Smith
On Sunday, Mar 13, 2005, at 05:01 America/Chicago, [EMAIL PROTECTED] wrote: if this is not a program please teach me what is a program and what i need to know to write them and if this is a program teach me how to write better programs i can use outside of the python shell... OK, how about this

Re: [Tutor] creating a tab delimited filename

2005-03-15 Thread C Smith
On Tuesday, Mar 15, 2005, at 05:01 America/Chicago, [EMAIL PROTECTED] wrote: how am i going to change the filename automaticaly? for example: #every 5 minutes, i am going to create a file based on the data above for i in range(100) output_file = file('c:/output' +.join(i) +'.txt

Re: [Tutor] creating a tab delimited filename

2005-03-16 Thread C Smith
Hi Jacob, Watch out with your code, ### if i==1000: i=0 else: i=i+1 ### Since this test is done after you have stored your data you are actually going to store 1001 pieces of data. i starts at 0 you store 0 you do your test and i is incremented {that's set 1} i is 1 you store

Re: [Tutor] primes

2005-03-17 Thread C Smith
On Thursday, Mar 17, 2005, at 17:49 America/Chicago, [EMAIL PROTECTED] wrote: On my system, it took 415 seconds to generate a list of primes < 50,000 using range, but only 386 seconds if I use the same code, but with xrange instead. If you only calculate y up to sqrt(x) you will see a dramatic

Re: [Tutor] Looking for a Pythonic way to pass variable

2005-03-22 Thread C Smith
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 _

Re: [Tutor] primes - sieve of odds

2005-03-22 Thread C Smith
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+

Re: [Tutor] primes - sieve of odds

2005-03-23 Thread C Smith
On Wednesday, Mar 23, 2005, at 04:00 America/Chicago, [EMAIL PROTECTED] wrote: Now it would be fine to have an *equally fast* infinite prime number generator. Has anybody any suggestions? I think when you add the condition of it being an infinite generator, you are changing the rules and can't e

Re: [Tutor] primes - sieve of odds

2005-03-23 Thread C Smith
Now it would be fine to have an *equally fast* infinite prime number generator. Has anybody any suggestions? [cut] What follows is an attempt based on the previous tutor-evolved sieve that extends the range in which to find the next prime by a factor of 2 over the last known prime. A similar alg

RE: [Tutor] a shorter way to write this

2005-03-25 Thread Smith, Jeff
For all the talk of Python only having one way to do something which is why it's so much better than Perl, I've counted about 10 ways to do this :-) Jeff -Original Message- From: Sean Perry [mailto:[EMAIL PROTECTED] Sent: Friday, March 25, 2005 2:20 PM To: Tutor Tutor Subject: Re: [Tutor

Re: [Tutor] Float precision untrustworthy~~~

2005-03-29 Thread C Smith
On Monday, Mar 28, 2005, at 22:11 America/Chicago, [EMAIL PROTECTED] wrote: [cut] the mere fact that floats are difficult to check with equality has bitten me more than anything I've met yet in python. [cut] I understand what you are talking about, but I tend toward just making it one of the thin

[Tutor] Re: If elif not working in comparison

2005-03-29 Thread C Smith
> gerardo arnaez wrote: > >> On Mon, 28 Mar 2005 09:27:11 -0500, orbitz >> wrote: >> >>> Floats are inherintly inprecise. So if thigns arn't working like you >>> expect don't be surprised if 0.15, 0.12, and 0.1 are closer to the same >>> number than you think. >> >> >> >> Are you telling me tha

Re: [Tutor] Math Question

2005-03-29 Thread C Smith
On Tuesday, Mar 22, 2005, at 15:34 America/Chicago, [EMAIL PROTECTED] wrote: 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

RE: [Tutor] If elif not working in comparison

2005-03-29 Thread Smith, Jeff
Brian van den Broek wrote: > Sean Perry said unto the world upon 2005-03-29 03:48: > >> Kent Johnson wrote: >> Not without using round. Have *NO* faith in floating points. This is especially true when you are creating the decimals via division and the like. >>> >>> Can you be

Re: [Tutor] I am puzzled - help needed

2005-03-31 Thread C Smith
I need to rewrite the high_low.py program (see below) to use the last two digits of time at that moment to be the "random number". Be sure you understand what format the time number has and that you understand the problem statement. Here are two time values: 1112306463.0 1112306463.01 Do you se

Re: [Tutor] Re: If elif not working in comparison

2005-04-04 Thread Christopher Smith
On Monday, Apr 4, 2005, at 05:01 America/Chicago, [EMAIL PROTECTED] wrote: Would I used an if else: construction to determine where the INR value lay and decide what precentage to increase it by? Yes, that seems to be the right way to do that. The caveat is that when you are using boolean tests

Re: [Tutor] one line code

2005-04-04 Thread C Smith
From: "Alan Gauld" <[EMAIL PROTECTED]> With other words I'd like to tell Python: Convert into a float if possible, otherwise append anyway. [ (type(x) == type(5) and float(x) or x) for x in mylist ] This is a perfect opportunity to give the reminder that the conversion functions are also types tha

Re: [Tutor] str.split and quotes

2005-04-06 Thread C Smith
I wish it would leave the stuff in quotes in tact: If you first split on your delimiter (which must have a matching one) you will obtain a list in which every odd position contains a string that was quoted. Step through the result and split the ones that are not quoted ones but don't do anythin

[Tutor] flatten

2005-04-07 Thread C Smith
After posting the suggestion about splitting a string that contained a quoted string, I looked back at my (at least I think it’s mine) flatten routine and didn’t see anything like it at ASPN. Before I would post it there, does anyone see any problems with this non-recursive approach? I know

Re: [Tutor] str.split and quotes

2005-04-08 Thread C Smith
Tony wrote: With Python 2.4 I get these results (all imports are factored out, all givethe same result except for CSV which strips the "s) with timeit.py: Just a note here in terms of results.  Although the results are all the same and they work for the case where there is single quoted phrase wit

Re: [Tutor] Flatten

2005-04-11 Thread C Smith
Sorry for the delay in answering. Bill Mill wrote: [cut] 1) you should special-case dictionaries: > >> x = [1, 2, [3, 4, 5, [[6, 7], 8]], 'abc', 9, [10, 11], {'test': 12}] > >> flatten(x) > >> x [1, 2, 3, 4, 5, 6, 7, 8, 'abc', 9, 10, 11, 'test'] OK, now it only handles lists and tuples 2) What's

Re: [Tutor] Sorting of files based on filesize

2005-04-11 Thread C Smith
--request for a method of sorting disk files based on size so as to fill backup disks-- You may want to check out the karp.py routine posted at http://aspn.activestate.com/ASPN/Mail/Message/python-Tutor/749797 Right now it is coded to split N numbers into 2 groups that have sums as nearly identi

RE: [Tutor] Craps, eternal loop (Joseph Q.)

2005-04-14 Thread Smith, Jeff
-Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Joseph Quigley Sent: Wednesday, April 13, 2005 6:57 PM To: tutor@python.org Subject: [Tutor] Craps, eternal loop (Joseph Q.) >I get an eternal loop on this game that I don't want and can't figure out >how t

Re: [Tutor] high score lists

2005-04-14 Thread Chris Smith
On Thursday, Apr 14, 2005, D. Hartley wrote: and a question about sorting (either way): I am trying it out with a list of tuples right now. The first problem I ran into is that when i sort it (scorelist.sort(reverse=True)), it sorts by the person's name (the first entry), and not by the score.

Re: [Tutor] high score lists

2005-04-14 Thread Chris Smith
On Thursday, Apr 14, 2005, I wrote: which gives 200 Nina 20 Ben 2 Raj oops, copy and paste error...should be: 200 Nina 20 Ben 2 Raj ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] high score lists

2005-04-15 Thread Chris Smith
On Friday, Apr 15, 2005, at 14:31 America/Chicago, [EMAIL PROTECTED] wrote: So I'm sure that's probably way too much information for most of you!! But my remaining questions are these: 1. what is/where can i get the "pickle" module for storing/saving changes to the high score list? 2. tabs/aligni

Re: [Tutor] high score lists

2005-04-15 Thread Chris Smith
On Friday, Apr 15, 2005, at 20:40 America/Chicago, Jacob S. - [EMAIL PROTECTED] wrote: Great. len is a function though. Why use a second layer of function when len is a function in itself? l = ['d','sea','bee'] l.sort(key=len) l ['d', 'bee', 'sea'] LOL :-) Oooh, that's nice! OK, instead of w

Re: [Tutor] high score lists

2005-04-15 Thread Chris Smith
On Friday, Apr 15, 2005, at 18:46 America/Chicago, [EMAIL PROTECTED] wrote: I did look at your example about using the longest number, but I couldnt really understand all of the code, and ended up deciding to arrange it so that the two columns were left-aligned: it looked like it would align them

[Tutor] Of fish and foul...(aka the Perl require command)

2005-04-18 Thread Smith, Jeff
Is there a Python equivalent to the Perl require 5.6.0 Which enforces a minimum interpreter version? Is there a good Python for Perl Programmers book? It thought O'Reilly had one but I couldn't find it. Was this particular question in the book you recommend? Thanks, Jeff _

[Tutor] snippets helps

2005-04-18 Thread Chris Smith
In a recent post, I believe it was D Hawksworth that noted, So I imported it, asked the shell window for 'help' (egad, technical jargon!) and did a search on python, same result. None of my beginners' tutorials have anything about pickle, unfortunately (very frustrating!) Does anyone know if there

[Tutor] import problem

2005-04-18 Thread Chris Smith
I sent the following to the mac-sig without reply (except for an autoresponder telling me that a person was out of the office :-)). Is there anyone with a mac that could test this code in the IDE to see if you have the same problems? (I don't have problems running it through the 2.4 version of

RE: [Tutor] Of fish and foul...(aka the Perl require command)

2005-04-19 Thread Smith, Jeff
Thanks, That does the trick. Rather than make a function, I'm likely to just do: if sys.version_info[:3] < (X,Y,Z): raise RuntimeError Jeff -Original Message- From: Max Noel [mailto:[EMAIL PROTECTED] Sent: Monday, April 18, 2005 3:34 PM To: Smith, Jeff Cc: tutor@py

[Tutor] A simple Perl to Python regex xlation question

2005-04-20 Thread Smith, Jeff
What's the quickest (and most Pythonic) way to do the following Perlism: $str = s/d+/d/; (i.e. collapsing multiple occurrences of the letter 'd' to just one) Thanks, Jeff ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/lis

[Tutor] Weird import problem with PythonIDE on Mac (was 'import problem')

2005-04-20 Thread Chris Smith
On Tuesday, Apr 19, 2005, Lee Cullens wrote: I assume you mean PythonIDE for Python 2.3 (I usually use 2.4 and WingIDE). Here it is (indents screwed up with var font): HTH, Lee C import timeit def y1(): print ’y1 executed’ def y2(): print ’y2 executed’ for f in [y1,y2]: n

[Tutor] Re: Weird import problem with PythonIDE on Mac (was 'import problem')

2005-04-21 Thread Chris Smith
### def y1(): pass def foo(): from __main__ import y1 pass foo() ### Here is a version of the code, stripped of the timeit code. The above segment exhibits the same symptoms as the previously submitted one. Even though I am running this as "__main__" it behaves as though it is not _

Re: [Tutor] Weird import problem with PythonIDE on Mac (was 'import problem')

2005-04-21 Thread Chris Smith
From: Kent Johnson Is it possible that the script is not running as __main__? Add print __name__ to the script and see what it says... It says '__main__'. Here is the end of the output after printing vars() if that helps: '__file__': '/Users/csmith/Desktop/misc python/timeit eg.py', 't': , 'y1'

[Tutor] Re: [Pythonmac-SIG] Weird import problem with PythonIDE on Mac (was 'import problem')

2005-04-22 Thread Chris Smith
On Friday, Apr 22, 2005, at 03:52 America/Chicago, Just van Rossum - [EMAIL PROTECTED] wrote: Importing __main__ is a very silly thing to do anyway, if you ask me. All comments from you, Bob, and Jack have been *very* helpful. I think I understand better what is going on. What's got me scratch

Re: [Tutor] CLS?

2005-04-25 Thread Chris Smith
I have this in my misc library. It was my last attempt at unifying the cls function snippets that I got when I asked about this question some time ago (check the ASPN tutor archives for 'cls'). After adding "darwin" to the test for the system (instead of just 'mac') I got it to work from a sc

[Tutor] Re: Weird import problem with PythonIDE on Mac (was 'import problem')

2005-04-25 Thread Chris Smith
On Friday, Apr 22, 2005, at 10:00 America/Chicago, Max Noel wrote: Do you have a suggestion as to what can I give a module so it has enough information to execute a function that resides in __main__? Here is a visual of what is going on: --__main__ def y1(): pass import foo foo.run(string

RE: [Tutor] design questions: pythonic approach to ostriches

2005-04-25 Thread Smith, Jeff
This is an excellent observation and points to the real problem with the original question. The problem is that the base class has more features than some of the classes that will be dervied from it which is usually just plain wrong. Think about it in the abstract. The Bird class makes the state

RE: [Tutor] Re: design questions: pythonic appraoch to ostriches

2005-04-25 Thread Smith, Jeff
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Greg T >>Think about it in the abstract. The Bird class makes >>the statement: >>all >>birds fly. Then you want to turn around and define a >>Bird that >>doesn't. >>Even doing >> >>def fly: >> pass >> >>makes no sense since what

[Tutor] Re: input()

2005-04-29 Thread Chris Smith
On Friday, Apr 29, 2005, at 09:48 America/Chicago, [EMAIL PROTECTED] wrote: Hello and thanks in advance. I am trying to prompt the user for some input. I need three values from the user so,I used input() like so; Matrix = input("Matrix=") error=input("error=") alpha= input("alpha=") us

[Tutor] tokenize row numbering

2005-04-29 Thread Chris Smith
I got over my intimidation with tokenize and learned to use it to strip comments from code files. In the process, I learned that the tuples that it returns for the position in the code of various tokens is 1-based in the row rather than 0-based, so the tuple pair (3,1),(3,2) would be the start

[Tutor] enumerate offset?

2005-04-29 Thread Chris Smith
Does anybody else ever run into the case of using enumerate on a slice but then wish that the original list indices were being returned instead of the ones starting at zero? I would like to see an offset argument that could be used with enumerate: ### l=range(5) for i,li in enumerate(l[3:]):

[Tutor] Re: input() : part two

2005-04-30 Thread Chris Smith
I found a work around for the terminal it appears that the message in the input("message") was being assigned to the next variable making Matrix=error=alpha It's good to see that you got this working. Just a couple notes: 1) Regarding your comment above, it just *looks* like it was doing an ass

Re: [Tutor] tokenize row numbering

2005-05-03 Thread Chris Smith
> From: Andrei >> ### >> # line 1 according to tokenize tuple >> # line 2 >> a=b #line 3 >> ### >> >> Does anyone have an idea of *why* the rows/physical lines of code >> beginning their count at 1 instead of 0? In order to process the code >> I > > The snippet above shows that numbering begins

Re: [Tutor] No Need to press Enter

2005-05-04 Thread Chris Smith
> From: Joseph Quigley > What is the secret to have the user press the "Q" key, and the program > exits without pressing the "Enter" key? > Or the "Control" and "Q" keys to exit? > For the Macintosh, would the same command/s for "Control Q" keys be the > same as the "Apple Q" key? > I see that Di

[Tutor] XML to Python

2005-05-05 Thread Smith, Jeff
I'm able to use the built in XML parser to effect "normal" XML parsing usage but frequently, I'm not doing anything to complicated and would simply like to translate the XML file into a more "Pythonic" structure. What's the best way to do this? Something from the standard libraries would be pr

Re: [Tutor] Python challenges

2005-05-06 Thread Chris Smith
On Thursday, May 5, 2005, at 19:33 America/Chicago, [EMAIL PROTECTED] wrote: > Anyone have a gentle hint, or pointer to another 'beginner' tutorial > to regular expressions? > > Thanks! I dont want to get stuck here in the riddles! > How about counting how many times each character is used and

Re: [Tutor] Python challenges

2005-05-06 Thread Chris Smith
> >> Anyone have a gentle hint, or pointer to another 'beginner' tutorial >> to regular expressions? >> >> Thanks! I dont want to get stuck here in the riddles! >> > > How about counting how many times each character is used and look for > the ones that are used infrequently (like only once). Dict

Re: [Tutor] elegant way to turn list into string

2005-05-07 Thread Chris Smith
> while x < 26: > new_alph = alph[1:] + alph[:1] > print new_alph > print "\n" > x += 1 > > But this has the drawback of not progressing with my > newly create alphabet, it just returns: > abcdefghijklmnopqrstuvwxyz The reason that new_alph never changes is that you are calculating

Re: [Tutor] Tutor Digest, Vol 15, Issue 21 (python.org: trusted sender for your account)

2005-05-09 Thread Chris Smith
On Monday, May 9, 2005, at 15:45 America/Chicago, [EMAIL PROTECTED] wrote: > Actually, perhaps this is something you guys would know about! In your > own learning python (or as you watched others learn, if you're one of > the resident experts), have you come across some good challenges for > pyt

Re: [Tutor] Python Challenge - Riddle 2

2005-05-09 Thread Chris Smith
> Am I looking for something like this - > > XXXjXXX? or something like XjXX or XXjX? The former: 3 on each side. Exactly 3. BTW , you can check your understanding by saving the image you get from riddle 6, compressing it with zlib, filtering out all but string.letters and looking for the same

  1   2   3   4   5   >