Python on the web: How to delete cookies in a CGI script

After you have a cookie that has been set, here is how you can delete it. The trick is to send an update to the cookie where you feed it an expiration date that is already in the past. For example: print “Set-Cookie: xml_edit_tool=Value of cookie; ‘expires=Wed, 28 Aug 2013 18:30:00 GMT’ \r\n” Note: When … Continue reading Python on the web: How to delete cookies in a CGI script

Python on the web: How to update cookies in a CGI script

Once you’ve retrieved a cookie via a function that returns the cookie as a dictionary of key value pairs, you can update the cookie in nearly the same way that you originally set the cookie. The only difference is that this time you can set different values. In this example, I am passing the retrieved … Continue reading Python on the web: How to update cookies in a CGI script

Python and Perl: A comparison of the language basics

In this table I will compare some basic programming syntax and conventions between the Python and Perl programming languages. Programming element Python Perl Creating a variable that contains an int: age = 25 %age = 25; Creating a variable that contains a float: probability = 0.62 %probability = 0.62; Creating a variable that contains a … Continue reading Python and Perl: A comparison of the language basics

Python on the web: How to get a CGI script to recognize two submit buttons with separate values in one form

In one of my Python cgi scripts I have a web form with some hidden values, text fields, and two submit buttons. I want my cgi script to do something different depending on which submit button was clicked. One of the submit buttons is for completing a review without making any changes and is called … Continue reading Python on the web: How to get a CGI script to recognize two submit buttons with separate values in one form

Python on the web: How to use Environment variables to detect script path

If you are writing Python scripts to run from the cgi-bin of your website, here is some code that will allow the script to detect it’s own path, so that it doesn’t have to be hard coded. The preferable way is to use the environment variable ‘SCRIPT_URI’. For example: this_script = os.environ[‘script_uri’] Note: Depending on … Continue reading Python on the web: How to use Environment variables to detect script path

WordPress: How to make a custom Enlighter theme for code highlighting

According to this page: https://wordpress.org/support/topic/custom-background-color-5/ The regular Enlighter plugin themes are stored in this minified css file: /wp-content/plugins/enlighter/resources/EnlighterJS.min.css and the css files for the Enlighter plugin themes can be found here: /wp-content/plugins/enlighter/views/themes/ for example: /wp-content/plugins/enlighter/views/themes/mootwo.css However, to create a new custom Enlighter css theme and have it show up in the Enlighter plugin options, I … Continue reading WordPress: How to make a custom Enlighter theme for code highlighting

Pandas: How to see the variety of values in a DataFrame column

To see the variety of values in an individual column of your DataFrame, you can use the name of the DataFrame column (in this case ‘Y’) and place it into a set, then print the values in the set. For example: # Check the variety of values in the Y column prop_variety = set(my_dataframe[“Y”]) prop_variety … Continue reading Pandas: How to see the variety of values in a DataFrame column

Pandas: How to export a DataFrame to .csv

Here is a function I wrote that will export an entire DataFrame to csv. It uses the Pandas function to_csv(). Just feed it the name of the DataFrame and the name you want for the .csv file. def dataframe_to_csv(filename, DataFrame): “””Export entire DataFrame to csv.””” output = DataFrame output.to_csv(filename, index=True) The filename can be a … Continue reading Pandas: How to export a DataFrame to .csv