About 1,550,000 results
Open links in new tab
  1. dictionary - I'm getting Key error in python - Stack Overflow

    In my python program I am getting this error: KeyError: 'variablename' From this code: path = meta_entry['path'].strip('/'), Can anyone please explain why this is happening?

  2. python - Best way to handle a keyerror in a dict - Stack Overflow

    Jan 15, 2019 · Exceptions in Python are not very expensive. Plus, if you consider that most of the time the key you are looking for (the count) is there, then it is totally fine. d = {} while True: try: d['count'] += 1 except KeyError: d['count'] = 1 # happens only once

  3. Catch KeyError in Python - Stack Overflow

    This still won't handle bare-string exceptions (or exceptions of unrelated types that you've somehow managed to raise behind the interpreter's back—pretty easy to do accidentally in a C extension module, not so easy to do even on purpose in …

  4. python dictionary keyError - Stack Overflow

    Sep 1, 2019 · You can get the same behavior in python by using collections.defaultdict. The modified code is given below. The modified code is given below. I took the liberty of converting the defaultdict to a regular dictionary at the end of the code:

  5. python - keyerror 1 in my code - Stack Overflow

    Nov 19, 2015 · I am writing a function that take dictionary input and return list of keys which have unique values in that dictionary. Consider, ip = {1: 1, 2: 1, 3: 3} so output should be [3] as key 3 has unique

  6. python - KeyError when indexing Pandas dataframe - Stack Overflow

    May 18, 2017 · I am trying to read data from a csv file into a pandas dataframe, and access the first column 'Date' import pandas as pd df_ticks=pd.read_csv('values.csv', delimiter=',') print(df_ticks.columns)

  7. python - KeyError when Key exists - Stack Overflow

    Jul 18, 2014 · Using python and twitter api to get tweet objects. I have a file (tweetfile = a .txt file on my computer) with tweets and I'm trying to loop through the objects to get the text. I checked the twitter object with tweetObj.keys() to see the keys and 'text' is there; however, when I try to get the individual text using tweetObj['text'] I get the ...

  8. string - Catching KeyError message in Python 3 - Stack Overflow

    Feb 18, 2018 · This behavior is perfectly explained in the source code:. static PyObject * KeyError_str(PyBaseExceptionObject *self) { /* If args is a tuple of exactly one item, apply repr to args[0].

  9. python - how to get the key information from a KeyError - Stack …

    Jun 17, 2013 · Is there a way to get the key that raised a KeyError? or in general, where can I find (if available) properties of an Exception?

  10. python - Ignore KeyError and continue program - Stack Overflow

    Mar 27, 2013 · In Python 3 I have a program coded as below. It basically takes an input from a user and checks it against a dictionary (EXCHANGE_DATA) and outputs a list of information. from shares import