473,323 Members | 1,570 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,323 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 1187
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 = @fopen($file, 'r'); if (!is_resource($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 to do my homework, just looking for help. I have...
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 an array while it is running. I need to store...
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 here, It will be very nice of someone to figure this...
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 is a 4 dimensional static array.
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 sequence no and item type etc ...but i need only...
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 older posts in this group, and tried a solution that...
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 array class myClass(arrary.array): def...
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. the prob is to create a monter fight and there is...
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 values...but as the user enters the values, i need...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.