Errors encountered while running scripts:
- Indentation error:
- Python follows a specific structure, like if loop is created inside for loop, there needs to be some space before you start if loop. Like the below, to justify the amount of space that needs to be given try to use compiler software's.
- Script:
- for key in list:
- <------>if key == "name":
- <----------->print "key is matching"
- ImportError: No module named 'urllib2'
- Source: http://stackoverflow.com/questions/2792650/python3-error-import-error-no-module-name-urllib2?noredirect=1&lq=1
- Solution: In python 3 urllib2 was merged into urllib. See also another Stack Overflow question and the urllib PEP 3108.
- Script: To make Python 2 code work in Python 3:
- try:
- import urllib.request as urllib2
- except ImportError:
- import urllib2
- TypeError:
- Script: urllib.request(jsonurl, jsonapi, headers)
- TypeError: 'module' object is not callable
- CSV error:
- Error script: csv.Error: iterator should return strings, not bytes.
- Soution Source: http://stackoverflow.com/questions/8515053/csv-error-iterator-should-return-strings-not-bytes
- I just fixed this problem with my code. The reason it is throwing that exception is because you have the argument
rb
. Change that to r
.
- Script with issue:
- import csv
- ifile = open('sample.csv', "rb")
- read = csv.reader(ifile)
- for row in read :
- print (row)
- Script with solution:
- import csv
- ifile = open('sample.csv', "r")
- read = csv.reader(ifile)
- for row in read :
- print (row)
- ImportError: No module named happybase
- NameError: name 'printfun' is not defined
- Script that has issue:
- printfun('123')
- def printfun(msg):
- print msg
- O/P of the script:
- Traceback (most recent call last):
- File "Connectingtohbase.py", line 17, in <module>
- printfun('123')
- NameError: name 'printfun' is not defined
- Resolution: <worked, as I have defined methods first(in the beginning) and accessed later> – .
- Solution script:
- def printfun(msg):
- print msg
- printfun('123')
No comments:
Post a Comment