I am running ubuntu 12.04 and running programs through the terminal. I have a file that compiles and runs without any issues when I am in the current directory. Example below,
[email protected]:~/Documents/BudgetAutomation/BillList$ pwd /home/david/Documents/BudgetAutomation/BillList [email protected]:~/Documents/BudgetAutomation/BillList$ python3.4 bill.py ./otherlisted.txt ./monthlisted.txt [email protected]:~/Documents/BudgetAutomation/BillList$
Now when I go back one directory and try running the same piece of code, I get an error message,
ValueError: need more than 1 value to unpack. Below is what happens when I run the sample code one folder back and then the sample code below that.
[email protected]:~/Documents/BudgetAutomation$ python3.4 /home/david/Documents/BudgetAutomation/BillList/bill.py Traceback (most recent call last): File "/home/david/Documents/BudgetAutomation/BillList/bill.py", line 22, in <module> bill_no, bill_name, trash = line.split('|', 2) ValueError: need more than 1 value to unpack
bill.py, below. This program reads two text files from the folder that it is located in and parses the lines into variables.
#!/usr/bin/env python import glob # gather all txt files in directory arr = glob.glob('./*.txt') arrlen = int(len(arr)) # create array to store list of bill numbers and names list_num =  list_name =  # for loop that parses lines into appropriate variables for i in range(arrlen): with open(arr[i]) as input: w = 0 ## iterative variable for arrays for line in input: list_num.append(1) ## initialize arrays list_name.append(1) # split line into variables.. trash is rest of line that has no use bill_no, bill_name, trash = line.split('|', 2) # stores values in array list_num[w] = bill_no list_name[w] = bill_name w += 1
What is going on here? Am I not running the compile and run command in the terminal correctly? Another note to know is that I eventually call this code from another file and it will not run the for loop, I am assuming since it doesn't run unless its called from its own folder/directory?