0

I am trying to unpack a list with fewer variables and get the following error.

human_prots looks like this:

['9606.ENSP00000482075_HomoSapiens\t10029.XP_007627869.1_CricetulusGriseus,10036.XP_005079789.1_MesocricetusAuratus,10042.XP_006987441.1_PeromyscusManiculatus9986.ENSOCUP00000025621_OryctolagusCuniculus', '']

with open(path_to_homolog_file,'r') as ortho_tab:
    ortho_text = ortho_tab.read()

no_genes = []
ortho_list = []
ortho_text.strip()
human_prots = ortho_text.split('\n\n')

for horthos in human_prots:
    [hprot,orthos,_] = horthos.split('\t')
    [_,hprot] = hprot.split('.')
    hprot_info = find_match(db_dict.get('HomoSapiens'),hprot)    

    if len(hprot_info) > 1 and warning == 'on':
        print('WARNING! Multiple matches found for {}: {}'.format(hprot,hprot_info))
    [hgene,_] = hprot_info[0].split('\t')
    orthos = orthos.split(', ')
line 71, in <module>
    [hprot,orthos,*_] = horthos.split('\t')
ValueError: not enough values to unpack (expected at least 2, got 1)

what am I doing wrong?

SuperStormer
  • 4,997
  • 5
  • 25
  • 35
View7
  • 1
  • 2
  • `horthos.split('\t')` returns only one element but your trying to unpack it into 3 variables – devaerial Jul 25 '19 at 09:10
  • I have tried ```hprot,orthos = horthos.split('\t')``` but it gives the same error. ```ValueError: not enough values to unpack (expected 2, got 1)``` . while ```print(len(human_prots))``` gives 2. – View7 Jul 25 '19 at 09:26
  • `len(human_prots)` has noting to do with it. Try to call `pdb` and call `horthos.split('\t')` inside debugger to see what it returns – devaerial Jul 25 '19 at 09:30
  • extended unpacking in this [link](https://hackernoon.com/understanding-the-underscore-of-python-309d1a029edc) doesn't seem to work. using python 3.5 – View7 Jul 25 '19 at 09:36
  • update: I changed ```hprot,orthos = horthos.split('\t')``` to ```hprot,orthos = horthos.split("\t")``` and now its working. don't understand why that was the cause... using Spyder IDE BTW. thanks for prompt reply! – View7 Jul 25 '19 at 09:48

0 Answers0