![]() |
I'm fairly new to python. I am making a simple text 2 player chess game currently. It's working like a charm (I love python's array definitions), but the array is acting wierdly. Here's a snippet of what's mystifieing me.
:
#this just moves the pieces, board() is just a method that prints out The whole code is here: (sorry it's messy, I have some long prints) :
def newGame(): |
btw, there is a python forum, under scripting :)
|
Really? Sorry. Didn't see it.
I've made some progress, I now understand that b=a just makes b another name for a. Unfortunately, I havn't gotten any further than that on how to fix this problem. b = a[:] doesn't work on the type of dictionary arrays I'm using. Anybody know how to copy dictionary arrays (ex: a = {'a':1,'b':2,'c':3} )? |
Quote:
|
Ahh you're right, I didn't make myself clear. Let me clarify, I now understand that array b=array a just makes array b another name for array a. That's only true of arrays.
The question remains, how do you make an independent copy of a definition array? And admin thanks for moving to the right forum. |
I'm not quite sure what you're asking, but if you're trying to copy from dictionary to another variable all it is is this.
:
>>>a = {'a':1,'b':2,'c':3}As you can see, b is an exact copy of a. If that doesn't answere your question, keep asking. |
Yes I know! But take this piece of code for example
:
>>> a = {'a':1,'b':2,'c':3}Arrays in python act strangely, they act more like methods than variables. The question is, how do I copy one array into an independent array? With normal arrays (such as a = [1,2,3]), you would do this by "splicing" it with b = a[:] . But with definition arrays (a = {'a':1,'b':2,'c':3}) splice doesn't work. |
I figured it out. With normal arrays, you create an independent array with
:
arrayA = arrayB[:]:
arrayA = arrayB.copy() |
| All times are GMT -5. The time now is 5:54 PM. |
Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC