Re: [Tutor] Shadowrun programs

2005-01-18 Thread Sean Perry
Jack Cruzan wrote: I am on the other coast but I too am looking for a group to play Shadowrun with. With at least three people interested think we could either -- 1) Port or create a python based SRCG (useless python still has a challenge for a collaberative effort.) 2) Make a SR rpg (I was think

Re: [Tutor] Clash of the Titans and Mundane Matters

2005-01-20 Thread Sean Perry
Michael Powe wrote: Clash of the Titans snip constructor discussions Pilgrim is pedantically correct but Alan's comment matches how most of us think about it. Mundane Matters I'm having a hard time with classes in python, but it's coming slowly. One thing that I think is general

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-27 Thread Sean Perry
Brian van den Broek wrote: 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

Re: [Tutor] rounding

2005-01-30 Thread Sean Perry
Kim Branson wrote: -BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Hi all, heres a quick one for you, I have a series of data that I am using dictionaries to build histograms for. I'd like to round the data to the nearest 10, i.e if the value is 15.34 should we round down to 10? and conversely rou

Re: [Tutor] Dividing 1 by another number ?

2005-01-30 Thread Sean Perry
Tony Meyer wrote: Dividing two integers will give you an integer (truncated) result: If you want '1/2' to give you 0.5 (throughout your script), you can do: from __future__ import division Notice that '//' (with or without the from __future__ import) will give you the integer result. or more simply

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

2005-02-02 Thread Sean Perry
Liam Clarke wrote: 4) WHAT IS WITH THE STUPID SYMBOLS EVERYWHERE LARRY??!! I'm not referring to the $ & @, I can see how they could be useful, although with a list - @dude = (1, 2, 3), to obtain the 2nd value I would expect $d = @dude[1], not $d = $dude[1], that's counterintuitive also. (I am a

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

2005-02-03 Thread Sean Perry
[EMAIL PROTECTED] wrote: Btw, I'm skeptical that the code below does what you want it to do. :-) that was kind of my point. In python I just type the obvious and it works. In Perl I have to muck with references, slashes, arrows and the like. Every time I have had to write a nested datastructu

Re: [Tutor] Ogg Tag Module recommendations

2005-02-03 Thread Sean Perry
Miles Stevenson wrote: Can anyone recommend to me a Python module to work with ID3v2 tags in Ogg Vorbis files? I tried using the EyeD3 module, but it only supports mp3 right now, and I couldn't get the pyid3tag module to work reliably, or I'm just not understanding the documentation. I just nee

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

2005-02-03 Thread Sean Perry
Jeff Shannon wrote: However, Python doesn't need lambdas to be able to write in a functional style. Functions are first-class objects and can be passed around quite easily, and IIRC Python's list comprehensions were borrowed (though probably with notable modification) from Haskell. Note, it is

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

2005-02-04 Thread Sean Perry
Alan Gauld wrote: Sean, what book/tutor are you using for Haskell? I learned it from "The Haskell School of Expression" which was OK but very graphics focused, I'd be interested in recommended second source on Haskell. as with Max I am reading Haskell: Craft of Functional Programming. I am abou

Re: [Tutor] help with HTMLParseError

2005-02-18 Thread Sean Perry
Peter Kim wrote: I'm using HTMLParser.py to parse XHTML and invalid tag is throwing an exception. How do I handle this? 1. Below is the faulty markup. Notice the missing >. Both Firefox and IE6 correct automatically but HTMLParser is less forgiving. My code has to be able to treat this graceful

Re: [Tutor] SubClassing

2005-02-24 Thread Sean Perry
Ismael Garrido wrote: Hello My code is like this: class Parent: def __init__(self, bunch, of, variables): self.bunch, self.of, self.variables = bunch, of, variables class Son(Parent): def __init__(self, bunch, of, variables, new): self.bunch, self.of, self.variables, self.new = bu

Re: [Tutor] SubClassing

2005-02-25 Thread Sean Perry
Ismael Garrido wrote: Sean Perry wrote: yep. call 'Parent.__init__(this, that)' then do 'self.new = new' def __init__(self, this, that, new): Parent.__init__(this, that) self.new = new Thanks. Though it should be: def __init__(self, this, that, new): Parent.__ini

Re: [Tutor] reading from stdin

2005-03-01 Thread Sean Perry
Nick Lunt wrote: The way I did this was to use sys.stdin.readlines() to get the output from the pipe. Here is the program: [code] import sys, glob args = sys.stdin.readlines() # found on the net pat = sys.argv[1] for i in args: if (i.find(pat) != -1): print i, [/code] My que

Re: [Tutor] reading from stdin

2005-03-01 Thread Sean Perry
[EMAIL PROTECTED] wrote: If I do: $ ./produce.py | ./read.py I get nothing for ten seconds, then I get the numbers 0 through 9, one per line. What am I missing? From the python man page: -u Force stdin, stdout and stderr to be totally unbuffered. On systems where it matters, also put stdin, st

Re: [Tutor] slow html generation code

2005-03-02 Thread Sean Perry
Luis N wrote: This code seems a little slow, is there anything in particular that jumps out as being not quite right. The idea is that a file is opened that contains path names to other files, that are appended and outputed into a directory of choice. I plan to move this off the filesystem into a d

Re: [Tutor] regular expression question

2005-03-08 Thread Sean Perry
Mike Hall wrote: I'd like to get a match for a position in a string preceded by a specified word (let's call it "Dog"), unless that spot in the string (after "Dog") is directly followed by a specific word(let's say "Cat"), in which case I want my match to occur directly after "Cat", and not "Dog

Re: [Tutor] regular expression question

2005-03-08 Thread Sean Perry
Mike Hall wrote: First, thanks for the response. Using your re: my_re = re.compile(r'(dog)(cat)?') ...I seem to simply be matching the pattern "Dog". Example: >>> str1 = "The dog chased the car" >>> str2 = "The dog cat parade was under way" >>> x1 = re.compile(r'(dog)(cat)?') >>> rep1 = x1.su

Re: [Tutor] working with new classes

2005-03-09 Thread Sean Perry
C Smith wrote: ### class Ring(list): def __init__(self, l): self[:] = l self._zero = 0 def turn(self, incr=1): self._zero+=incr def __getitem__(self, i): return self[(i-self._zero)%len(self)] l=Ring(range(10)) print l l.turn(5) print l#same a

Re: [Tutor] Whats so good about OOP ?

2005-03-12 Thread Sean Perry
Brian van den Broek wrote: 1) Namespace issues With procedural (or imperative -- don't know which is the right terms for non-OOP code which employs functions) code, you can have issues caused by namespaces. Just yesterday, someone on the main python list/newsgroup had code something like: procedura

Re: [Tutor] Whats so good about OOP ?

2005-03-12 Thread Sean Perry
Mark Kels wrote: Hi list ! I want to know whats so great in OOP... I have learned some of it, but I don't understand why everybody like it so much... Can anyone give me an example for a task that could be done only with OOP or will be much simpler to do with it ? Thanks in advance. Other commenters

Re: [Tutor] primes

2005-03-17 Thread Sean Perry
Danny Yoo wrote: Here is one that's traduced... er... adapted from material from the classic textbook "Structure and Interpretation of Computer Programs": ## from itertools import ifilter, count def notDivisibleBy(n): ... def f(x): ... return x % n != 0 ... return f ... def siev

Re: [Tutor] primes

2005-03-18 Thread Sean Perry
Pierre Barbier de Reuille wrote: def sieve( max ): max_val = int( sqrt( max ) ) s = Set(xrange( 4, max, 2 )) for i in xrange( 3, max_val, 2 ): s.update( xrange( 2*i, max, i ) ) return [ i for i in xrange( 2, max ) if i not in s ] just for grins, here is the same (mostly) code in haskell

Re: [Tutor] Prepend to a list?

2005-03-19 Thread Sean Perry
Jay Loden wrote: How can I prepend something to a list? I thought that I could do list.prepend() since you can do list.append() but apparently not. Any way to add something to a list at the beginning, or do I just have to make a new list? >>> a = [] help(a.insert) insert(...) L.i

Re: [Tutor] Why is this not an error?

2005-03-20 Thread Sean Perry
Hameed U. Khan wrote: This else is the part of the for loop. And the statements in this else will be executed if your for loop will complete all of its iterations. if you want this else with 'if' statement then remove the for loop. for instance: looking_for = 11 for i in range(0,10): if i ==

Re: [Tutor] primes (generator)

2005-03-20 Thread Sean Perry
Gregor Lingl wrote: The following variation of your sieve, using extended slice assignment seems to be sgnificantly faster. Try it out, if you like. Here are the numbers: Primes 1 - 1,000,000 timing: extendedSliceSieve: 0.708388 seconds listPrimes: 0.998758 seconds karlSi

Re: [Tutor] Filtering a String

2005-03-20 Thread Sean Perry
Matt Williams wrote: Dear List, I'm trying to filter a file, to get rid of some characters I don't want in it. I've got the "Python Cookbook", which handily seems to do what I want, but: a) doesn't quite and b) I don't understand it I'm trying to use the string.maketrans() and string.translate().

Re: [Tutor] import statements in functions?

2005-03-21 Thread Sean Perry
Marcus Goldfish wrote: Is there a convention to be considered for deciding if import statements should be included in a function body? For example, which of these two module layouts would be preferable: imports are cached. So once it is imported, it stays imported. The reason I consider the secon

Re: [Tutor] OT - SQL methodology.

2005-03-21 Thread Sean Perry
Liam Clarke wrote: Hi, This is a SQL query for the advanced db gurus among you (I'm looking at Kent...) 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

Re: [Tutor] Looking for a Pythonic way to pass variable number of lists to zip()

2005-03-21 Thread Sean Perry
Tony Cappellini wrote: I have a program which currently passes 6 lists as arguments to zip(), but this could easily change to a larger number of arguments. Would someone suggest a way to pass a variable number of lists to zip() ? well, I would have said "apply(zip, (l1, l2, l3, ...))" but apply

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

2005-03-22 Thread Sean Perry
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

Re: [Tutor] iterating through large dictionary

2005-03-22 Thread Sean Perry
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 '

Re: [Tutor] Apology

2005-03-22 Thread Sean Perry
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://m

Re: [Tutor] What does Python gain by having immutable types?

2005-03-22 Thread Sean Perry
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

Re: [Tutor] List comprehensions

2005-03-23 Thread Sean Perry
Liam Clarke wrote: Is there any guides to this (possibly obtuse) tool? Think of it this way. A list comprehension generates a new list. So, you should think about list comps whenever you have old_list -> new_list style behavior. There are two advantages to list comps over map: 1) a list comp can

Re: [Tutor] Unique elements mapping

2005-03-25 Thread Sean Perry
Srinivas Iyyer wrote: Hi all: I have a question and I request groups help please. My list has two columns: NameState DrewVirginia NoelMaryland NikiVirginia Adams Maryland JoseFlorida Monica Virginia Andrews Maryland I would like to have my ouput like this: Virginia : Drew,Ni

Re: [Tutor] a shorter way to write this

2005-03-25 Thread Sean Perry
jrlen balane wrote: basically, i'm going to create a list with 96 members but with only one value: list1[1,1,1,1...,1] is there a shorter way to write this one??? def generateN(n): while 1: yield n I'll leave the actual list creation up to you (-: ___

Re: [Tutor] a shorter way to write this

2005-03-25 Thread Sean Perry
Smith, Jeff wrote: 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 :-) Knowing you said this at least half in jest, I still feel the need to comment. In any programming language, you have flexibility

Re: [Tutor] Dates and databases, and blobs and Python.

2005-03-26 Thread Sean Perry
Liam Clarke wrote: And then there's the overall question - What would be the least fiddly & least error prone way of working with dates and times? Python or SQL? Liam, SQL is another language. You need to learn it like you are learning Python. It has pretty decent support for dates and times as p

Re: [Tutor] primes - sieve of odds

2005-03-26 Thread Sean Perry
John Miller wrote: How does one actually use this module? For example: >>> import eratosthenes >>> eratosthenes.primes() >>> eratosthenes.primes().next() 2 >>> eratosthenes.primes().next() 2 >>> eratosthenes.primes().next() 2 How does one get beyond the first prime? it = eratosthenes.primes()

Re: [Tutor] How and where to use pass and continue

2005-03-27 Thread Sean Perry
Kevin wrote: I am having lot of trouble learning where and when to use pass and continue. The two books that I use don't explian these very good. Is there a website the explains these is great detail? I have also looked at the python tutorial as well. language idioms are one of the hardest things t

Re: [Tutor] How and where to use pass and continue

2005-03-27 Thread Sean Perry
Kevin wrote: Ok I have another question now I noticed that at the tope of a while loop there will be somthing like this: test = None while test != "enter": test = raw_input("Type a word: ") if test == "enter": break what is the purpose of test = None ? 'test' must be

Re: [Tutor] If elif not working in comparison

2005-03-28 Thread Sean Perry
gerardo arnaez wrote: On Mon, 28 Mar 2005 09:27:11 -0500, orbitz <[EMAIL PROTECTED]> 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 that I cant expect 2 d

Re: [Tutor] If elif not working in comparison

2005-03-29 Thread Sean Perry
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. What?!?! OK, floats don't necessarily have the exact values you expect (they may have errors after many decimal places), and com

Re: [Tutor] If elif not working in comparison

2005-03-29 Thread Sean Perry
Smith, Jeff wrote: Which is just what you'd expect. It's absolutey absurd to tell someone to have *NO* faith in floating numbers. It's like anything else in programming: you have to understand what you are doing. Unless a float that has been through a round function I do not trus it. That is what

Re: [Tutor] Class and methods?

2005-03-30 Thread Sean Perry
Kevin wrote: In a class is every def called a method and the def __init__(self) is called the constructor method? This class stuff is a little confusing. I don't have a problem writting a def I am still not clear on how to use a constructor. Is there a site that explains the constructor in great de

Re: [Tutor] I am puzzled - help needed

2005-03-30 Thread Sean Perry
John Carmona wrote: I am not sure that it is possible to ask that question please feel free to turn me down if it is going against the forum rules. I have going through Josh Cogliati tutorial, I am stuck on one of the exercise. I need to rewrite the high_low.py program (see below) to use the la

Re: [Tutor] sorting a list of dictionaries

2005-04-12 Thread Sean Perry
Gooch, John wrote: I am working on a dictionary sorting problem just like the one in the email thread at the bottom of this message. My question about their solution is: In these lines: lst.sort(lambda m, n: cmp(m.get(field), n.get(field))) where field is either 'name' or 'size'. Wh

Re: [Tutor] Has anyone ever tried to convert the textual output of the dis module to another language

2005-04-17 Thread Sean Perry
R. Alan Monroe wrote: Just curious. Googling for 'python "dis module" convert "another language" ' only got two hits. So maybe no one is trying it? I was just daydreaming about a native python compiler, and wondered how feasible it would be. There is already a python -> exe converter. Comes up on t

Re: [Tutor] Has anyone ever tried to convert the textual output of the dis module to another language

2005-04-17 Thread Sean Perry
R. Alan Monroe wrote: The main things about it that would make it appealing to me: #1 - MUCH MUCH MUCH smaller exes. Speed is not an issue to me, but filesize is. Have you ever compiled "Hello world" in a new language, and found that the exe was 100K+, when it really only needs to be less than 1K?

Re: [Tutor] OT self-implementation?

2005-07-01 Thread Sean Perry
Brian van den Broek wrote: > Now's not the time in my life to start a comp. sci. degree. So, my > questions are: > > 1) What would be good terms to google for to find an explanation of > how the seeming magic doesn't violate all reason? > > 2) Much harder, so please pass unless you've a link yo

Re: [Tutor] dictionary

2005-10-24 Thread Sean Perry
Shi Mu wrote: > I typed: > landUse = {'res': 1, 'com': 2, 'ind': 3, "other" :[4,5,6,7]} > and when i checked landUse, I found it become: > {'ind': 3, 'res': 1, 'other': [4, 5, 6, 7], 'com': 2} > why the order is changed? the docs warn you about this. A dictionary stores its values based on the ke

Re: [Tutor] Percentage

2005-11-11 Thread Sean Perry
Johan Geldenhuys wrote: > Hi all, > > What is the syntax if I want to work out what percentage 42 is out of 250? > 42 is x percent of 250. (is / of) = (x / 100) one of those formulas from school I will always remember. (42 / 250) = (x / 100.0) 250x = 4200.0 x = 4200.0 / 250 x = 16.8%

Re: [Tutor] lunch.py

2006-02-07 Thread Sean Perry
Christopher Spears wrote: > I'm working on a program where a Customer orders Food > from an Employee. Here is what I have so far: > > class Food: > def __init__(self, name): > Food.foodName = name > what you want here is 'self.name = name' then in your code later you can do:

Re: [Tutor] Why None?

2006-02-07 Thread Sean Perry
Hey Chris, check out this version. class Food: def __init__(self, name): self.name = name class Customer: def __init__(self,name): self.name = name self.food = None # 0 is for numbers def placeOrder(self, foodName, employee): print "%s: Hi %s!" %

Re: [Tutor] Does casting exist in Python?

2006-02-22 Thread Sean Perry
Edgar Antonio Rodriguez Velazco wrote: > Does it? > Thanks, > not exactly. new_list = list(my_tuple) In general Python works without having to nudge the type system. For char -> int style conversions there is a builtin function called 'ord'. ___ Tuto

Re: [Tutor] Repeating a routine

2006-02-22 Thread Sean Perry
Jumping to the middle of a book or movie will lead to similar confusion. Give a look at Dive Into Python. Available as either a book or online. http://www.diveintopython.org/ ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinf

Re: [Tutor] list packing

2006-02-26 Thread Sean Perry
John Fouhy wrote: > On 27/02/06, kevin parks <[EMAIL PROTECTED]> wrote: > >>snd = [f for f in os.listdir('/Users/kevin/snd/') if f.endswith('.aif')] > > > If this is all you need, then you could do something like: > > snd = ['/Users/kevin/snd/%s' % f for f in > os.listdir('/Users/kevin/snd/') i

Re: [Tutor] Python challenge

2006-05-15 Thread Sean Perry
David Holland wrote: > I looked at this and got stuck on the first one :- Thanks for this. I missed it the first time it showed up on this list. Kinda fun and reminds me why I love python. Four lines in the interactive interpreter and most of the challenges are solved. __

[Tutor] understanding __import__()

2006-07-25 Thread Sean Perry
Ok, this may be slightly above tutor's level, but hey, never hurts to ask (-: I am playing with __import__(). Here is my code: [code] import os.path app_path = '/tmp/my/settings' app_path2 = 'my/settings' if os.path.exists(app_path + '.py'): print "Found", app_path try: f = __import

Re: [Tutor] understanding __import__()

2006-07-26 Thread Sean Perry
Kent Johnson wrote: > The first argument to __import__ should be a module or package name, not > a file path, e.g. "my.settings". Python will look for the module in the > current sys.path the same as if you used a normal import. Apparently the > / is being interpreted as a . and I guess you have

Re: [Tutor] Python decorator

2006-08-31 Thread Sean Perry
János Juhász wrote: > Hi, > > I have just started to play with TurboGears - it is really nice - and I > couldn't understand the decorators used by it. > I have tried to interpret the http://wiki.python.org/moin/PythonDecorators > about decorators, but it is too difficult for me. > > May someone