472,328 Members | 1,854 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,328 software developers and data experts.

Need array help

I am switching from microsoft visual basic programming to python
programming. In microsoft
visual basic you can Dim a variable so that you can add variables by
changing the number
on the end of the variable as in the following example;

Dim acct(100)

numoffiles=4
data=10
ct=1
while ct <numoffiles
acctfile(ct) = data
ct= ct + 1
data= data + ct
Wend
The results are;
acctfile(1)=10
acctfile(2)=12
acctfile(3)=15

And you can compare the values of the new variables;
if acctfile(1) acctfile(2) then print "yes"
if acctfile(2) acctfile(1) then print "yes"

when I try to create acctfile(ct) = data I get the following error;
***can't assign to function call. Then it gives the program line of the
problem
Here is the progam in python;

numoffiles=4
data=10
ct=1

while ct != numoffiles:
acctfile(ct) =data
ct += 1
data= data + ct
print acctfile(ct)

Does anybody know how this is done in Python?
Oct 6 '06 #1
6 1148
Marion, I think you should start with the tutorials. To access an array
in Python, use brackets not parens. so, instead of "acctfile(ct) =
data" try "acctfile[ct] = data". The tutorials are excellent and if you
are learning from vb, you can go through them pretty quickly.

On Oct 6, 10:25 am, "Marion Long Jr" <mlon...@verizon.netwrote:
I am switching from microsoft visual basic programming to python
programming. In microsoft
visual basic you can Dim a variable so that you can add variables by
changing the number
on the end of the variable as in the following example;

Dim acct(100)

numoffiles=4
data=10
ct=1
while ct <numoffiles
acctfile(ct) = data
ct= ct + 1
data= data + ct
Wend
The results are;
acctfile(1)=10
acctfile(2)=12
acctfile(3)=15

And you can compare the values of the new variables;
if acctfile(1) acctfile(2) then print "yes"
if acctfile(2) acctfile(1) then print "yes"

when I try to create acctfile(ct) = data I get the following error;
***can't assign to function call. Then it gives the program line of the
problem
Here is the progam in python;

numoffiles=4
data=10
ct=1

while ct != numoffiles:
acctfile(ct) =data
ct += 1
data= data + ct
print acctfile(ct)

Does anybody know how this is done in Python?
Oct 6 '06 #2
Marion Long Jr wrote:
I am switching from microsoft visual basic programming to python
programming. In microsoft
visual basic you can Dim a variable so that you can add variables by
changing the number
on the end of the variable as in the following example;

Dim acct(100)

numoffiles=4
data=10
ct=1
while ct <numoffiles
acctfile(ct) = data
ct= ct + 1
data= data + ct
Wend
The results are;
acctfile(1)=10
acctfile(2)=12
acctfile(3)=15

And you can compare the values of the new variables;
if acctfile(1) acctfile(2) then print "yes"
if acctfile(2) acctfile(1) then print "yes"

when I try to create acctfile(ct) = data I get the following error;
***can't assign to function call. Then it gives the program line of the
problem
Here is the progam in python;

numoffiles=4
data=10
ct=1

while ct != numoffiles:
acctfile(ct) =data
ct += 1
data= data + ct
print acctfile(ct)

Does anybody know how this is done in Python?

You have two choices in Python: list or array
For simple lists of things use a list. If you want to
do vector math or matrix-type calculations look at the
array module.

For you simple example, here is the python code:

acctfile=[]
numoffiles=4
data=10
ct=1
for i in xrange(numoffiles-1):
acctfile.append(data)
ct=ct+1
data=data+ct
There are other ways, but this is closest to what you are
asking for (which I assume is a trivial example).

-Larry Bates
Oct 6 '06 #3
Others posted answer to your question.

If you are serious about programming in Python, I highly recommend that
you don't try to think in terms of "I did this in Visual Basic, how do
I do this in Python". You'll end up with Python code that are nothing
but a VB look alike. As recommended by others, go througth the
tutorial. It will be time well spent.
Marion Long Jr wrote:
I am switching from microsoft visual basic programming to python
programming. In microsoft
visual basic you can Dim a variable so that you can add variables by
changing the number
on the end of the variable as in the following example;

Dim acct(100)

numoffiles=4
data=10
ct=1
while ct <numoffiles
acctfile(ct) = data
ct= ct + 1
data= data + ct
Wend
The results are;
acctfile(1)=10
acctfile(2)=12
acctfile(3)=15

And you can compare the values of the new variables;
if acctfile(1) acctfile(2) then print "yes"
if acctfile(2) acctfile(1) then print "yes"

when I try to create acctfile(ct) = data I get the following error;
***can't assign to function call. Then it gives the program line of the
problem
Here is the progam in python;

numoffiles=4
data=10
ct=1

while ct != numoffiles:
acctfile(ct) =data
ct += 1
data= data + ct
print acctfile(ct)

Does anybody know how this is done in Python?
Oct 6 '06 #4
Larry Bates wrote:
If you want to
do vector math or matrix-type calculations look at the
array module.
The array module in the standard library does not provide such capabilities. If
you need them, look at numpy.

http://numpy.scipy.org

--
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
that is made terrible by our own mad attempt to interpret it as though it had
an underlying truth."
-- Umberto Eco

Oct 6 '06 #5
"Marion Long Jr" <ml*****@verizon.netwrote in message
news:EkwVg.362$P92.105@trndny02...
>I am switching from microsoft visual basic programming to python
programming.
Also, in anticipation of one of the most FA'ed Q's among VB->Python
migrators, you must always include the parens after a function name to
invoke the function. That is, to call the method MethodWithNoArguments, you
cannot write (as one would in VB):

val = MethodWithNoArguments

This simply assigns the method MethodWithNoArguments to name 'val'. To
invoke the method and assign the returned value to val, write:

val = MethodWithNoArguments()

And please don't ask for Python to be changed to be more VB-like in this
regard - let Python be Python! :)

And welcome to the Python world!

-- Paul
Oct 6 '06 #6
Robert Kern wrote:
Larry Bates wrote:
>If you want to
do vector math or matrix-type calculations look at the
array module.

The array module in the standard library does not provide such
capabilities. If you need them, look at numpy.

http://numpy.scipy.org
I stand corrected.

-Larry
Oct 6 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Nathan Rose | last post by:
Here's my problem. I am reading from a text file using this: if (!file_exists($file)) { echo "Don't exist\n"; return false; } $fd =...
4
by: KellyH | last post by:
Hi, I hope someone can point me in the right direction. I'll get it out of the way: Yes, I am a college student. No, I am not looking for anyone...
3
by: Tommy Lang | last post by:
I am working on this project and I need some help/pointers/comments to get me started, I am stuck. The program will be used to store information in...
3
by: ash | last post by:
Hey I am new, but I don't have time to intruduce myself yet. I am intro to C++ and this is a programme I have to write. all the direction are...
23
by: vinod.bhavnani | last post by:
Hello all, I need desperate help Here is the problem: My problem today is with multidimensional arrays. Lets say i have an array A this...
8
by: skumar434 | last post by:
i need to store the data from a data base in to structure .............the problem is like this ....suppose there is a data base which stores the...
12
by: gcary | last post by:
I am having trouble figuring out how to declare a pointer to an array of structures and initializing the pointer with a value. I've looked at...
5
by: SpreadTooThin | last post by:
If you are deriving a new class from another class, that you must (I assume) know the initializer of the other class. So in myClass import...
1
by: javabeginner123 | last post by:
i have a java prob, and i have to solve it fast, but i'm just getting to know it, so plz help me solve it with full code completed, thanks so much....
3
by: jac130 | last post by:
the program runs, and user is prompted via inputbox to enter an integer-this is the size of the array, then the user fills the array with that many...
0
by: tammygombez | last post by:
Hey fellow JavaFX developers, I'm currently working on a project that involves using a ComboBox in JavaFX, and I've run into a bit of an issue....
0
better678
by: better678 | last post by:
Question: Discuss your understanding of the Java platform. Is the statement "Java is interpreted" correct? Answer: Java is an object-oriented...
0
by: teenabhardwaj | last post by:
How would one discover a valid source for learning news, comfort, and help for engineering designs? Covering through piles of books takes a lot of...
0
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
0
by: CD Tom | last post by:
This happens in runtime 2013 and 2016. When a report is run and then closed a toolbar shows up and the only way to get it to go away is to right...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
0
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. ...
1
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.