Python Forum
Using a list like an array
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Using a list like an array
#1


I'm new to python, but have been coding in VBA for a while. I need to move some of my VBA code to python. So far I have this to import data from a next file and put it into a list.
md=[]
"""Measured depth, ft"""
azi=[]
"""Azimuth angle angle, degrees"""
inc=[]
"""Inclination angle, degrees"""

fin = open("Wishbone 1N-24HZ.txt", "r") # open file for reading
for line in fin:
    mds, incs, azis = line.split()
    md += [float(mds)]
    inc += [float(incs)]
    azi += [float(azis)]
fin.close()
What I am needing to do is a loop till there is no more data. In VBA it would be using an array and using a do loop until a cell is empty in the worksheet. Within the loop would be lines like: changemd(i)=md(i)-md(i-1). I'm not sure how to translate into python. One of my main issue is not being sure how to take a value from the list as well as the value before it.
Reply
#2
you need to use append, example:
md5.append(float(mds))
Reply
#3
Ok, I've read up a little on append() and it seems like that adds to the list. I'm not trying to add, as I have all the data. I am trying to call in all the data to a loop, but with only two points at a time. Like taking a differential: change in something= current something-previous something.
Reply
#4
Maybe look into the numpy package. It contains functions to process data at C++ like speeds. If I understood your query correctly, this link should be of use.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  concat two list based on array MeeranRizvi 9 7,564 Jan-03-2017, 06:28 PM
Last Post: wavic

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020