Skip to content

Instantly share code, notes, and snippets.

# On branch master
# Changes to be committed:
# (use "git reset HEAD <file>..." to unstage)
#
# modified: ex36_assignment.py
#
# Changes not staged for commit:
# (use "git add/rm <file>..." to update what will be committed)
# (use "git checkout -- <file>..." to discard changes in working directory)
#
import random
class Room:
explored = None
def __init__(self, description):
self.desc = description
def explore(self):
if not self.explored:
import string
with open('C:\Documents and Settings\[trimmed]\Desktop\list.txt',
'rb') as infile:
fread = infile.readlines()
fread = [x.strip() for x in fread]
fread = [x.lstrip('\x95') for x in fread]
fread = [x.strip() for x in fread]
fread = [x for x in fread if x != '']
@cluelesscoder
cluelesscoder / gist:5616667
Last active December 17, 2015 13:19
random issue: list indices must be integers not tuple python
import sqlite3
from collections import defaultdict
DATABASE = 'C:/Misc/myscripts/workprototype/workprototype.db'
conn = sqlite3.connect(database=DATABASE)
comp = conn.execute('select companies.name from companies')
comp = [dict(co_name=row[0]) for row in comp.fetchall()]
prod = conn.execute('select c.name, p.name, c.desc, p.desc from companies c inner join products p on c.co_id = p.co_id')
@cluelesscoder
cluelesscoder / gist:4208180
Created December 4, 2012 20:09
Enumerate and for loops
numbers = range(10)
for idx, y in enumerate(numbers):
if idx == 1:
continue
else:
print y
@cluelesscoder
cluelesscoder / gist:3418362
Created August 21, 2012 19:02
Python 2 testing DictReader
import csv
import re
# testreader = csv.DictReader(open('C:/Documents and Settings/'
# 'BJCREASY.SOA/Desktop/test2.csv', 'rb'))
with open('C:/Documents and Settings/'
'BJCREASY.SOA/Desktop/test2.csv', 'rb') as f:
reader = csv.reader(f)
for row in reader:
@cluelesscoder
cluelesscoder / gist:3406761
Created August 20, 2012 19:04
Python test file opening
import csv
testreader = csv.DictReader(open('C:/Documents and Settings/BJCREASY.SOA/Desktoptestcsv.csv', ''), dialect='excel')
for row in testreader:
print row
# if row['SERFF'] == csv.reader.next().row['SERFF']
# print 'Success'
@cluelesscoder
cluelesscoder / gist:3383623
Created August 18, 2012 00:27
Python test
import csv
testreader = csv.DictReader(open('test.csv', 'rb')
for row in testreader:
print row
@cluelesscoder
cluelesscoder / gist:3072712
Created July 8, 2012 20:41
loading many-to-many divs
function loadStockDivs() {
$.getJSON(
"test.php",
"process=loadstocks",
function(data) {
data.counter = 0;
$.each(data.stocks, function(i,stock) {
if (i != 0) {
counter = i;
counterminus = counter-1;
// loadSectorOptions works but loadCountryOptions does not
function loadSectorOptions() {
$.getJSON(
"list-process.php",
"process=loadSectorOptions",
function(data) {
$.each(data.sectors, function(i, sector) {
var sectorOption = '<option value=\"'
+sector.sector_id+'\">'