Python: How to read and write JSON

JSON is a lightweight data-interchange format that stands for JavaScript Object Notation. It so happens that JavaScript objects look exactly like Python dictionaries, so JSON objects can be thought of as portable dictionaries of key-value pairs. This portability is what makes JSON so valuable. While JSON objects can be identical to Python dictionaries, there are some … Continue reading Python: How to read and write JSON

Python on the web: How to get a list of all available Python modules

If you want to get a complete list of Python modules available on your web host, you can do so with the following code: I saved the above code as a CGI script called “available_modules.py” and uploaded it to my website cgi-bin. Here is what the code produces, shown below in an iframe: For more … Continue reading Python on the web: How to get a list of all available Python modules

Python: How to print function details iteratively using inspect and getmembers

As described in a previous post, the help() function is great for seeing details about any given module function, one at at time. Python: How to use the built-in help( ) and dir( ) functions For example: print help(imageio.mimsave) However, sometimes we want to see details for all of the functions in an imported module. … Continue reading Python: How to print function details iteratively using inspect and getmembers

Python: Using requests to get web page source text

In addition to getting page lengths and status codes using the request method: Python: Using requests to get web page lengths and status codes You can also use requests to return the source code of web pages. For example: import requests sites = [ ‘http://www.python.org’, ‘http://www.jython.org’, ‘http://www.pypy.org’, ‘http://www.drudgereport.com’, ‘http://www.phys.org’, ‘http://www.bluegalaxy.info’, ‘http://www.bluegalaxy.info/codewalk’ ] for url in … Continue reading Python: Using requests to get web page source text

Python: Using requests to get web page lengths and status codes

With Python 3.6 and the requests module, it is easy to read data from the web. Here are a couple of basic things we can do with the requests module. Getting a Status code import requests r = requests.get(‘http://www.bluegalaxy.info’) print( r.status_code ) Which yields: 200 For more information about HTTP status codes, there are multiple … Continue reading Python: Using requests to get web page lengths and status codes