0

I am developing a program which works with a ; separated csv. When I try to execute the following code

def accomodate(fil, targets):
    l = fil
    io = []
    ret = []
    for e in range(len(l)):
        io.append(l[e].split(";"))
    for e in io:
        ter = []
        for theta in range(len(e)):
            if targets.count(theta) > 0:
                ter.append(e[theta])
        ret.append(ter)

    return ret

, being 'fil' the read rows of the csv file and 'targets' a list which contains the columns to be chosen. While applying the split to the csv file it raises the folowing error: "'l' name is not defined" while as far as I can see the 'l' variable has already been defined.

Does anyone know why this happens? Thanks beforehand


edit


As many of you have requested, I shall provide with an example. I shall post an example of csv, not a shard of the original one. It comes already listed

k = ["Cookies;Brioche;Pudding;Pie","Dog;Cat;Bird;Fish","Boat;Car;Plane;Skate"]

accomodate(k, [1,2]) = [[Brioche, Pudding], [Cat, Bird], [Car, Plane]]
Phazoning
  • 51
  • 5
  • 1
    use the csv module? And post a [mcve] - half of the stuff going on in your code-piece makes not much sense because we do not know what you do and how your csv looks like? – Patrick Artner Apr 25 '19 at 08:25
  • Beside that ... `l=fil` does nothing - it does not copy anything, it just provides another name to address the data of `fil` (if `fil` is a list) - see [How to clone or copy a list](https://stackoverflow.com/questions/2612802/how-to-clone-or-copy-a-list) – Patrick Artner Apr 25 '19 at 08:27
  • Please show a demo _csv_ (2-3 lines) and and example call of your method. Describe what the result for your method should be and explain _why_ it comes to that result. Thanks – Patrick Artner Apr 25 '19 at 08:31

1 Answers1

0

You should copy the content of fil list:

l = fil.copy()
Haritz Laboa
  • 718
  • 2
  • 8
  • 18