0

A snippet of my code:

def determinewelltype(currentuwi,welltype):
    if current uwi in vertuwis:
        welltype = "Vertical"

currentuwi = "1aa010109306w400"
welltype = "UNKNOWN"
determinewelltype(currentuwi,welltype)
print currentuwi,welltype

In another part of my code, I have built a list called vertuwis that consists of a number of strings.

This snippet is trying to determine if the currentuwi is in the list of vertuwis. If it is, the welltype should be vertical.

I know that the given currentuwi is in my list, but when I print the welltype in the last line of code, the well type is UNKNOWN, meaning that my code doesn't work.

Where have I gone wrong?

Flux Capacitor
  • 1,215
  • 5
  • 24
  • 40
  • 3
    parameters are passed by value in python but you're assuming they are passed by ref. Check out the following question which explains this in detail http://stackoverflow.com/questions/986006/python-how-do-i-pass-a-variable-by-reference – JaredPar Mar 28 '13 at 22:03

1 Answers1

2

This corrects the errors in your code:

vertuwis = ['a', 'b', 'c']

def determinewelltype(currentuwi,welltype):
    if currentuwi in vertuwis:
        welltype = "Vertical"
    return welltype

currentuwi = "a"
welltype = "UNKNOWN"
welltype = determinewelltype(currentuwi,welltype)
print currentuwi,welltype   # prints out: a Vertical
daedalus
  • 10,873
  • 5
  • 50
  • 71