Wilbert's website at SocSci

has a subtitle

psychopy/conventions.html 2017-03-31

Programming with PsychoPy, appendix 2, conventions and suggestions

Conventions

  • Code files are UTF-8. No BOM.
  • First line is: #!/usr/bin/env python, unix/OSX endline (\r) on all platforms.
  • Second line is # -*- coding: utf-8 -*-
  • Tabs are 4 spaces. There are no tab characters in the entire file.
  • Data files have the extension .csv, have one header line use semicolons as column separators. This conventions is also used for input. When using gnuplot use the following for reading these files:
    set datafile separator ";"
    plot "data.csv" every ::1 using 1:2
    
    When using python use the following for reading these files as list of lists:
    import csv
    datafile = open('data.csv', 'Ur')
    reader = csv.reader(datafile, delimiter=';')
    # now row[i][j] is the value in row i, column j
    
    When using python use the following for reading these files as dictionary:
    import csv
    datafile = open('data.csv', 'Ur')
    reader = csv.DictReader(datafile, delimiter=';')
    # now row[i]['column_name'] is the value in row i, column 'column_name'
    
    When using R use the following for reading these files:
    a = read.table("data.csv", header=1, sep=";")
    # now a['column_name'] consists of the values in the column