Azure Function list operation show index out of range

Li, Gavin 1 Reputation point

I'm writing some script on Azure function with python, which want to handle the csv file which was upload to blob storage.

The coding I tested pass in local, but it got error on Azure function.

Result: Failure Exception: IndexError: list index out of range Stack: File "/azure-functions-host/workers/python/3.8/LINUX/X64/azure_functions_worker/", line 355, in _handle__invocation_request call_result = await self._loop.run_in_executor( File "/usr/local/lib/python3.8/concurrent/futures/", line 57, in run result = self.fn(*self.args, **self.kwargs) File "/azure-functions-host/workers/python/3.8/LINUX/X64/azure_functions_worker/", line 542, in __run_sync_func return func(**params) File "/home/site/wwwroot/csvhandler/", line 28, in main text1=list1[0]

Not quite sure why it said list index out of range Stack, the list index should begin from 0..

input string


import logging
import azure.functions as func
import pandas as pd
import numpy as np


def main(inputblob: func.InputStream, outputblob: func.Out[str]) -> None:'Python Queue trigger function processed %s',
           str1 ='utf-8-sig')
    str1 = str1.split('\\r\\n')   #split the string in list, str1="ab,cd,ef\r\n12,34,56\r\nff,gg,ee\r\n"
    str1 = str1[0:-1]
    for i in range(0,len(str1)):    #split the list which can be written into pandas DataFrame

    text1=list1[0]   #verify if the element correct

    df = pd.DataFrame(list1[1:], columns=list1[0])  #create the dataframe

    outstr=df.to_csv(index=False)   #transfer the output to string
    outputblob.set(outstr)          #output the string in the blob

In the other hand, would anyone suggest if we can explore the edited dataframe as csv to blob storage? I can't find much info here.

Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
4,182 questions
{count} votes

2 answers

Sort by: Most helpful
  1. JayaC-MSFT 5,521 Reputation points

    @Li, Gavin As mentioned in the thread :, did you try to declare the list variable as global? Does that help in this case?

  2. Evan Chatter 11 Reputation points

    The IndexError is raised when attempting to retrieve an index from a sequence (e.g. list, tuple), and the index isn’t found in the sequence. The Python documentation defines when this exception is raised:

    Raised when a sequence subscript is out of range. (Source)

    Here’s an Python Split() example that raises the IndexError:

    data = "one%two%three%four%five"
    numbers = data.split('%')

    The list numbers has 5 elements, and the indexing starts with 0, so, the last element will have index 4. If you try to subscript with an index higher than 4, the Python Interpreter will raise an IndexError since there is no element at such index.

    0 comments No comments