Re: [Tutor] Advise...

2005-01-26 Thread TJ
What is the function? 3*x*x What is the minimum? 2 What is the maximum? 5 117.000435 Which, considering that it is supposed to be exactly 117, It's darn good. Unfortunately, it also takes about 10 seconds to do all that. Any suggestions? Any advice? TIA Jacob Schmidt Jacob, You can get better acc

Re: [Tutor] Should this be a list comprehension or something?

2005-01-26 Thread Karl Pflästerer
On 26 Jan 2005, [EMAIL PROTECTED] wrote: > The following Python code works correctly; but I can't help but wonder if > my for loop is better implemented as something else: a list comprehension > or something else more Pythonic. [Code] > > > w1 = Water(50,0) > w2 = Water(50,

Re: [Tutor] Advise...

2005-01-26 Thread Kent Johnson
There was a discussion about this same question (in the context of graphing a user-supplied function) just a few weeks ago. My suggestion was to use exec to create a real function object that you can call directly; you can read it here: http://mail.python.org/pipermail/tutor/2005-January/034696.h

Re: [Tutor] sorting a 2 gb file- i shrunk it and turned it around

2005-01-26 Thread Kent Johnson
My guess is that your file is small enough that Danny's two-pass approach will work. You might even be able to do it in one pass. If you have enough RAM, here is a sketch of a one-pass solution: # This will map each result to a list of queries that contain that result results= {} # Iterate the fi

Re: [Tutor] Advise...

2005-01-26 Thread Bill Kranec
There has been alot of talk on this list about using list comprehensions lately, and this could be one of those useful places. While I don't have time to experiment with real code, I would suggest changing your function to look like: steps = [ min_x + i*delta_x for i in range(steps) ] totalare

[Tutor] Unique Items in Lists

2005-01-26 Thread Srinivas Iyyer
Hi, I am a new member to this group and relatively to python. I have a list with 4 columns and column1 elements are unique. I wanted to extract unique elements in column3 and and place the other elements of the column along with unique elements in column 4 as a tab delim text. Table: col1

Re: [Tutor] Advise...

2005-01-26 Thread Danny Yoo
On Wed, 26 Jan 2005, Bill Kranec wrote: > There has been alot of talk on this list about using list comprehensions > lately, and this could be one of those useful places. While I don't > have time to experiment with real code, I would suggest changing your > function to look like: > > steps = [

Re: [Tutor] Advise...

2005-01-26 Thread Danny Yoo
> > There has been alot of talk on this list about using list comprehensions > > lately, and this could be one of those useful places. While I don't > > have time to experiment with real code, I would suggest changing your > > function to look like: > > > > steps = [ min_x + i*delta_x for i in r

Re: [Tutor] Read file line by line

2005-01-26 Thread Alan Gauld
> 1. Why does the assignment-and-test in one line not allowed in Python? > For example, while ((content = fd.readline()) != ""): Because Guido didn't write it that way? ;-) And that may have been because it is such a common source of bugs. So common in fact that many compilers now offer to emit a

Re: [Tutor] ascii encoding

2005-01-26 Thread Alan Gauld
> Whether or not it's positive or negative depends on which side of GMT/UTC > you are, of course :) Note that the result in is seconds, too: Which is insane since timezones have nothing to do with time offsets. Especially at the second level! Oh well, nothing is perfect! Alan G. (Feeling picky

Re: [Tutor] Should this be a list comprehension or something?

2005-01-26 Thread Alan Gauld
Personally no I don;t think it should be a comprehension. LCs are for building lists, although they sometimes are abused for other things, but you do not appear to be building a list per se. The for loop is clearer IMHO. > Here's my code: > > class Water: > def __init__(

Re: [Tutor] Class within class, or...?

2005-01-26 Thread Alan Gauld
class Reader: def __init__(self, filePath=""): self.dataA=SchemaA() self.dataB=SchemaB() ... class SchemaA(): class SchemaB(): You probaly should put the Schema definitions before the Reader definition. Otherwise what you suggest is absolutely the norm for O

Re: [Tutor] Unique Items in Lists

2005-01-26 Thread Danny Yoo
On Wed, 26 Jan 2005, Srinivas Iyyer wrote: > I have a list with 4 columns and column1 elements are unique. I wanted > to extract unique elements in column3 and and place the other elements > of the column along with unique elements in column 4 as a tab delim > text. > > Table: > > col1col2

Re: [Tutor] Advise...

2005-01-26 Thread Alan Gauld
> If the user must be able to enter in the function, then it would be better > to evaluate this once and turn it into some sort of function that you can > call inside the loop (it's the eval that is so expensive). How to do that > depends a lot on how complex the possible functions can be (if they

[Tutor] Convert string to variable name

2005-01-26 Thread Tony Giunta
Hello tutors, This is something I've been trying to figure out for some time. Is there a way in Python to take a string [say something from a raw_input] and make that string a variable name? I want to to this so that I can create class instances on-the-fly, using a user-entered string as the ins

Re: [Tutor] Advise...

2005-01-26 Thread Jacob S.
Thanks everyone! Kent started the suggestion of making a code object, but everyone else seems to have worked their way to it. Beautiful! I only have to call exec once, and it cuts down time considerably. Here is the new code. Jacob Schmidt Please remind me if I've forgotten anything. ### Start #

Re: [Tutor] Convert string to variable name

2005-01-26 Thread Danny Yoo
On Wed, 26 Jan 2005, Tony Giunta wrote: > This is something I've been trying to figure out for some time. Is > there a way in Python to take a string [say something from a raw_input] > and make that string a variable name? Hi Tony, Conceptually, yes: you can collect all those on-the-fly vari

Re: [Tutor] Unique Items in Lists

2005-01-26 Thread Jacob S.
col2_set = sets.Set(col2) how can I get a uniq elements that repeated several times: for item in range(len(list)): for k in range(len(list)): if item == k: if list[item] != k[list]: print item First off, this would never work. You are iterating over the s

Re: [Tutor] Convert string to variable name

2005-01-26 Thread Tony Giunta
On Wed, 26 Jan 2005 17:11:59 -0800 (PST), Danny Yoo <[EMAIL PROTECTED]> wrote: > > > On Wed, 26 Jan 2005, Tony Giunta wrote: > > We can use exec() to create dynamic variable names, but it's almost always > a bad idea. Dynamic variable names make it very difficult to isolate > where variables a

[Tutor] New to Python

2005-01-26 Thread Jason White
Greetings all, I'm new to python and thought I'd pop in here for advice. I've done object oriented design and programmed in perl, java, c++, basic, etc. I haven't done a lot of development, mostly just glorified oject-oriented scripts. I'm curious about good tutorial websites and books to buy.   I

Re: [Tutor] New to Python

2005-01-26 Thread Max Noel
On Jan 27, 2005, at 02:09, Jason White wrote: I'm curious about good tutorial websites and books to buy. I learned Python (well, the basics thereof -- enough to do useful stuff on my summer job, anyway ^^) in an afternoon using the official tutorial that's found somewhere on http://www.python.or

RE: [Tutor] New to Python

2005-01-26 Thread Tony Meyer
[Jason White] >> I'm curious about good tutorial websites and books to buy. [Max Noel] > I learned Python (well, the basics thereof -- enough to do useful > stuff on my summer job, anyway ^^) in an afternoon using the official > tutorial that's found somewhere on http://www.python.org/. It's ver

Re: [Tutor] New to Python

2005-01-26 Thread Jay Loden
I also recommend the book "Dive Into Python" - it gets awesome reviews, and the book is under Creative Commons license, so it's free to download and distribute. http://diveintopython.org I also have the book "Core Python Programming" which is pretty good, and has a nice way of leaping right

[Tutor] Preffered way to search posix filesystem

2005-01-26 Thread Miles Stevenson
I would like to search filesystem structures using globs on Posix systems from within Python. I don't see an obvious method to do this with in the standard modules. What is the preferred way of doing this? Should I just use the find command or is there a good module out there for searching? Tha

Re: [Tutor] New to Python

2005-01-26 Thread Chad Crabtree
I too once had trouble remembering (and finding) the name of this library so here it is. http://www.tizmoi.net/watsup/intro.html I have not used it but the documentation by example, seemed to me to be approachable. Tony Meyer wrote: >There's a Python library for controlling Windows in this sort

Re: [Tutor] Preffered way to search posix filesystem

2005-01-26 Thread Chad Crabtree
Try the os module. I think this should probably get you there. http://docs.python.org/lib/module-os.html Miles Stevenson wrote: >I would like to search filesystem structures using globs on Posix systems from >within Python. I don't see an obvious method to do this with in the standard >modules

Re: [Tutor] Unique Items in Lists

2005-01-26 Thread Srinivas Iyyer
Dear Jacob, thank you for your suggestion. however, i think my question was not clear. what i meant to ask in my previous question was, how to know which elements repeated and how many times they were repeated. while my question was flying, i did a small test: took a list: >>> a [1, 1, 2, 3, 4,

Re: [Tutor] Unique Items in Lists

2005-01-26 Thread Chad Crabtree
Ok. I think I understand and I happen to be up at 1:30 my time so here is the solution as I understand the problem. This is a very common problem and has a fairly easy solution. You can then take adict.keys() which returns a list of unique elements. Good Luck import random l=[random.randra

[Tutor] Cluster algorithms

2005-01-26 Thread kumar s
Hi: I am still trying to learn the OOPs side of python. however, things/circumstances dont seems to stop until I finish my practise and attaing higher understanding. may be, i am being pushed by circumstances into the stream and i am being tested if I can swim efficiently while I struggle with ba

Re: [Tutor] Unique Items in Lists

2005-01-26 Thread Brian van den Broek
Srinivas Iyyer said unto the world upon 2005-01-27 01:17: Dear Jacob, thank you for your suggestion. however, i think my question was not clear. what i meant to ask in my previous question was, how to know which elements repeated and how many times they were repeated. while my question was flying

Re: [Tutor] Should this be a list comprehension or something?

2005-01-26 Thread Sean Perry
Terry Carroll wrote: > My goal here is not efficiency of the code, but efficiency in my Python thinking; so I'll be thinking, for example, "ah, this should be a list comprehension" instead of a knee-jerk reaction to use a for loop. as Alan says, list comprehensions, like map should be used to ge

Re: [Tutor] Should this be a list comprehension or something?

2005-01-26 Thread Brian van den Broek
Sean Perry said unto the world upon 2005-01-27 02:13: And now, for the pedant in me. I would recommend against naming functions with initial capital letters. In many languages, this implies a new type (like your Water class). so CombineWater should be combineWater. Do you mean implies by the domin