On Thu, Apr 18, 2013 at 11:01 PM, aaB wrote:
> def get_index(thisgen, i):
> n = len(thisgen)-1
> cell = thisgen[i]
> if i is 0:
> print "i==0"
> prev, next = thisgen[n], thisgen[i+1]
> elif i is n:
> print "i==%d" % n
> prev, next = thisgen[i-1], thisgen[0]
> else:
>
> The second guess, more likely, is that you're using "is" to compare
> numbers, and that's never a safe idea. It might happen to work for
> small numbers, but you should be using ==.
The second guess was right, changing "is" for "==" solved it, thanks.
I still have a lot to learn about python sem
On 04/18/2013 09:01 AM, aaB wrote:
Hello,
I am still in the process of writing preliminary code for my CA project.
I am now running into a behavior that I can't explain.
Here is a script which, at least on my system, shows the issue (python2.7 on a
linux system).
The final project will be wrapp
Hello,
I am still in the process of writing preliminary code for my CA project.
I am now running into a behavior that I can't explain.
Here is a script which, at least on my system, shows the issue (python2.7 on a
linux system).
The final project will be wrapping these functions (and others) into
Ned Batchelder wrote:
> On 4/17/2013 12:10 PM, 8 Dihedral wrote:
>> Well, a new object is returned and can be used.
>> Then who is going to clean up the object when required?
>
> This is a key thing to understand about Python: memory is managed
> automatically, no one has to clean up the obj
On Thu, Apr 18, 2013 at 4:36 AM, Ned Batchelder wrote:
>
> On 4/17/2013 12:10 PM, 8 Dihedral wrote:
>> Well, a new object is returned and can be used.
>> Then who is going to clean up the object when required?
>
>
> This is a key thing to understand about Python: memory is managed
> automatica
On 4/17/2013 12:10 PM, 8 Dihedral wrote:
Serhiy Storchaka於 2013年4月17日星期三UTC+8下午5時35分07秒寫道:
17.04.13 07:57, Larry Hudson написав(ла):
So using a list comprehension you can do it in two lines:
def get_rule(num):
bs = bin(num)[2:]
return [0] * (8 - len(bs)) + [int(i) for i in bs]
Serhiy Storchaka於 2013年4月17日星期三UTC+8下午5時35分07秒寫道:
> 17.04.13 07:57, Larry Hudson написав(ла):
>
> > So using a list comprehension you can do it in two lines:
>
> >
>
> > def get_rule(num):
>
> > bs = bin(num)[2:]
>
> > return [0] * (8 - len(bs)) + [int(i) for i in bs]
>
>
>
> You
On Apr 17, 5:25 am, aaB wrote:
>
> - the "complement" thing:
> I haven't yet tried to reproduce this, but I will, and I will post back if I
> see
> this happening again, this time with a real log of python's interactive
> console,
> or a complete script which people can use.
>
That was happenin
aaB writes:
> - copy/paste vs retyping:
> Several people have remarked that I had retyped instead of copy/pasting.
> This is exactly what happened, the fact is I haven't figured out yet how to
> enable copy/pasting from urxvt to vim.
I used to use rxvt, but since a while I switched to roxterm fo
Hello,
Thanks for all your replies, things are getting clearer.
- copy/paste vs retyping:
Several people have remarked that I had retyped instead of copy/pasting.
This is exactly what happened, the fact is I haven't figured out yet how to
enable copy/pasting from urxvt to vim.
I'll try to get th
17.04.13 07:57, Larry Hudson написав(ла):
So using a list comprehension you can do it in two lines:
def get_rule(num):
bs = bin(num)[2:]
return [0] * (8 - len(bs)) + [int(i) for i in bs]
You can do it in one line!
def get_rule(num):
return list(map(int, '{:08b}'.format(num)))
On 04/16/2013 08:37 AM, aaB wrote:
hello,
I represent the CA's rule with a list of integers, of value 1 or 0.
Here is the function I use to generate the list:
def get_rule(rulenum):
rule = []
while rulenum > 0:
rule.append(rulenume % 2)
rulenum /= 2
while len(rule) < 8:
On 04/16/2013 08:37 AM, aaB wrote:
rule = getrule(int(8))
just rule = getrule(8) is sufficient -- you don't need to cast the integer 8
to an integer. ;)
Thanks, and sorry for the rather long post.
Not too long at all: it had lots of detail of what you were trying to do, what you were
On 04/16/2013 11:37 AM, aaB wrote:
hello,
I am a beginner programmer. I started learning programming about a year and a
half ago, using C. I picked up python a few months ago, but only wrote very few
scripts.
I am currently trying to learn more about the python way of doing things by
writing a
On 4/16/2013 11:37 AM, aaB wrote:
I represent the CA's rule with a list of integers, of value 1 or 0.
Here is the function I use to generate the list:
def get_rule(rulenum):
rule = []
while rulenum > 0:
rule.append(rulenume % 2)
rulenum /= 2
divmod(rulenum) will return both th
In aaB
writes:
> but when I do:
> for i in rule:
> print rule[i]
> I get the "complement":
> 1
> 1
> 1
> 1
> 0
> 1
> 1
> 1
When you iterate over a list with this statement:
for i in rule:
i contains each successive list item.
However, your code:
print rule[i]
acts as though i
On Wed, Apr 17, 2013 at 1:37 AM, aaB wrote:
> but when I do:
>
> for i in rule:
> print rule[i]
When you iterate over rule, you don't iterate over the indices, but
over the values themselves. Try this:
for i in rule:
print i
Incidentally, "for i in range(rule)" isn't actually going to wor
hello,
I am a beginner programmer. I started learning programming about a year and a
half ago, using C. I picked up python a few months ago, but only wrote very few
scripts.
I am currently trying to learn more about the python way of doing things by
writing a script that generates png images usin
19 matches
Mail list logo