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
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
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
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
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
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
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
[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
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
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
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
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
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
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
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
[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
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
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
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
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
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
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
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
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
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
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 ==
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
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().
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
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
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
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
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 '
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
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
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
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
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 (-:
___
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
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
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()
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
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
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
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
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
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
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
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
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
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?
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
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
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%
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:
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!" %
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
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
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
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.
__
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
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
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
63 matches
Mail list logo