Quantcast
Channel: David Rostenne – theconsultant.net
Viewing all articles
Browse latest Browse all 21

Somedays I write more bugs than code…

$
0
0

I posted recently that I had started on Bites of Py Exercises, and i’m glad to say I have finished a few more. Small wins are good!

Along the way i’ve discovered, thanks again to the Python Bytes podcast, a new way to see crashes in my scripts. Currently I am working slowly towards scraping my favorite wallpapers from wallhaven.cc and downloading them. But, as I mention in the title, I seem to be better at writing bugs than functional code.

When a script crashes in Python you get a traceback, which seems to be a backwards listing of the things that caused the crash. With practice I will get better at making sense of things like this:

Traceback (most recent call last):
   File "wff-selenium-no-login.py", line 6, in 
     from urllib import Request
 ImportError: cannot import name 'Request' from 'urllib'  NameError: name 'Request' is not defined
   File "wff-selenium-no-login.py", line 24, in 
     req = request(wallpaper, headers = {"User-Agent": "Mozilla/5.0"})
 TypeError: 'module' object is not callable

But thanks to that episode I learned about friendly_traceback, which gives me this output instead:

Python exception:
         TypeError: 'module' object is not callable
A TypeError is usually caused by trying to combine two incompatible types of objects, by calling a function with the wrong type of object,
or by tring to do an operation not allowed on a given type of object.

Execution stopped on line 24 of file 'wff-selenium-no-login.py'.
-->24:     req = request(wallpaper, headers = {"User-Agent": "Mozilla/5.0"})

request: <module 'urllib.request' from '/Users/davidr/...>

How is this better? Well.. it explains the error, points to the line I need to fix.. and also tells me the module I have issue with. Though I still don’t know what to do to fix it it makes me feel like I have a better handle on it.


Viewing all articles
Browse latest Browse all 21

Trending Articles