diff --git a/Students/SSchwafel/Notes/11182014.notes b/Students/SSchwafel/Notes/11182014.notes new file mode 100644 index 00000000..39810549 --- /dev/null +++ b/Students/SSchwafel/Notes/11182014.notes @@ -0,0 +1,114 @@ +Notes - November 18, 2014 +==================== + + + Subclassing is not for specialization, it's for reusing code + + The subclass is in charge + + + Multiple inheritance - inheriting from more than one class + +class Combined(Super1, Super2, Super3): + +method resolution order - class order of operations + + is it an instance attribute? + Is it a class attribute? + Is it a superclass attribute? + + Is it an attributed of the left-most superclass? + Next? + +Mixins - classes that are designed to add functionality to a class, but can't do much on its own + + animal + + mammal + givebirth() + + Bird + layeggs() + + Where do you put platypus? + + Real world example: FloatCanvas + + + +All of the lcass definitions we've been showing inherit from object + +This is referred to as a "new style" class + +Always subclass from Object + + +super(): <--- use it to call a superclass method, rather than explicitly callin the unbound method on the superclass + +read manpages on super() + +Properties + +Attributes are simple and concise + +But what if you need to add extra behavior? + +class C(object): + _x = None + @property + def x(self): + return self._x + @x.setter + def x(self, value): + self._x = value + +@ <----decoration + +Syntax for wrapping up function with special syntax + +getters/setters/deleters + + +Static and Class Methods: + + Static method is a method that doesn't get 'self' + + @staticmethod + def(a,b): + return a+b + + +Why are static methods useful? They aren't, usually. + +99% of the time you just want a module-level function + +Class Methods + +A class method gets the class object, rather than an instance, as the first argument + +Why? Unlike static methods, class methods are quite common. They are friendly to subclassing + +Properties, Satic Methods, and Class Methods are powerful features of Python's OO model. + + Descriptor Protocol! + +Special Methods! MAgic Methods are the secret sauce to Python's Duck typing. Defining the appropriate special methods in your classes is how you make your classes behave like python Builtins. + +__init__ <---special method + +object.__str__ is what happens when you ask for a string version of an object, for example + + +Protocols + + THe set of special methods needed to emulate a particular type of Python object is called a protocol. + +Your classes can "become" like Python builtins by implementing methods in a given protocol + + +Use special methods when you want your class to act like a "standard" class in some way. + +Look up the special methods you need and define them + + Guide to Python's Magic Methods + diff --git a/Students/SSchwafel/Notes/11252014.notes b/Students/SSchwafel/Notes/11252014.notes new file mode 100644 index 00000000..65e1e9ec --- /dev/null +++ b/Students/SSchwafel/Notes/11252014.notes @@ -0,0 +1,68 @@ +Notes - Nov 25, 2014 + +__iadd__ + + augmented assignment, used for in-place addition; changes object in place + +Making your class behave like builtins! + +callable classes + +a_result = something(some_arguments) + + something <---Class + + __call__)*args, **kwargs) + + if you define a __call__ method, that method will be used when code "calls" an instance of your class + +Non-built-in sequence classes! + +You can create a class that looks like a regular sequence, just add __len__, __getitem_, __setitem__, __delitem__, etc. + + +Iterators and generators + +What goes on in for loops? + + iterators are what makes Python so readable + + an_iterator.__iter__() + + returns the iterator object itself + + an_iterator.next() + + returns next item until there are none, then returns StopIteration + + + What do for loops do? + + itertools -> build cool iterators out of sequences you have + + + +Generators + + generators give you the iterator immediately + + + conceptually - iterators are about various ways to loop over data, + generators generate the data on the fly + + practically - you can use either one either way (and generator is a type of + iterator + + def a_generator_function(params): + some_stuff + yield something + + + a function with 'yield' is a factory for a generator + + gen_a = a_generator() + gen_b a_generator() + + + + diff --git a/Students/SSchwafel/Notes/12022014.notes b/Students/SSchwafel/Notes/12022014.notes new file mode 100644 index 00000000..1179adea --- /dev/null +++ b/Students/SSchwafel/Notes/12022014.notes @@ -0,0 +1,16 @@ +Notes 11/02/2014 +==================== + +You can bind a function to a symbol and return/pass them to functions + +Decorator - function takes function as an argument, gives a function as a return value + +Rebinding the name of a function to the result of calling a decorator on that function is called decoration + +@ <---special operator + +Decorators can be used with anything that is callable + + A decorator is a callable that takes a callable as an argument and returns a callable as a return value. + + diff --git a/Students/SSchwafel/Notes/12092014.notes b/Students/SSchwafel/Notes/12092014.notes new file mode 100644 index 00000000..fb2e499d --- /dev/null +++ b/Students/SSchwafel/Notes/12092014.notes @@ -0,0 +1,75 @@ +Notes - 12/9/2014 +==================== + +Unicode and the Persistence of Serialization +--- + + Projects Due at the end of this week! - Friday + +Anything is bytes <-- if it's stored on a disk or sent over a network, it's bytes + +Unicode makes it easier to deal with bytes + +Used to be able to fit everything into a two byte integer, (65,536 chars.) + +Variety of encodings -> way of going between the canonical name of a character, and how it's stored in memory + +Py2 strings are a sequence of bytes - Unicode strings are sequences of platonic characters + +Platonic characters cannot be written to disk or network + + +Python has both str and unicode + +Two ways to work with binary data: + +str and bytes() and bytearray + +In Python 3 bytes and strings are completely different! + +Unicode object lets you work with characters - all the same methods as the string object + + Encoding is converting from unicode object to bytes + + Decoding is converting from bytes to a unicode object + + +import codects +#encoding and decoding stuff + +codecs.encode() +codecs.decode() +codecs.open() #better to use io.open + +Use Unicode in your source files - + + #-*- coding: utf-8 -*- + +The Trick in Using Unicode - Be Consistent: + + Always unicode, never Python strings + + Do the decoding when you input your data + + Decode on input + + Encode on output + + + get default encoding - sys.getdefaultencoding() + + +from __future__ import unicode_literals #<----after running this line u'' is assumed! + + -be aware that you can still get Python 2 strings from other places... + +JSON Requires UTF-8! + +In Python 3, all strings are unicode + +Py3 has two distinct concepts: + + text - uses str object + binary data - uses bytes + + diff --git a/Students/SSchwafel/Project/Draft_InformedVoter.py b/Students/SSchwafel/Project/Draft_InformedVoter.py new file mode 100644 index 00000000..b4531183 --- /dev/null +++ b/Students/SSchwafel/Project/Draft_InformedVoter.py @@ -0,0 +1,79 @@ +#!/usr/bin/python + +from __future__ import unicode_literals +from pprint import pprint +import urllib2 +import simplejson as json + +#user_local_data = json.load(urllib2.urlopen('http://freegeoip.net/json/')) +user_local_data = json.load(urllib2.urlopen('http://api.ipinfodb.com/v3/ip-city/?key=a648bf3844359d401197bcaa214dd01e0f8c0c6d623ec57f3716fbcafc8262bd&format=json')) + +user_lat = user_local_data['latitude'] +user_long = user_local_data['longitude'] + +#print gathered lat/long +#print user_lat,user_long + +#print """ +# +#You can get your latitude and longitude from http://www.latlong.net/ +# +#""" + +#user_lat = raw_input('Please enter your Latitude: \n') +#user_long = raw_input('Please enter your Longitude: \n') + +#user_lat = '47.653098' +#user_long = '-122.353731' + +lat_long_url = 'https://congress.api.sunlightfoundation.com/districts/locate?latitude={}&longitude={}&apikey=15f4679bdc124cd6a2c6be8666253000'.format(user_lat, user_long) + +congressional_district = json.load(urllib2.urlopen(lat_long_url)) + + +legislators = json.load(urllib2.urlopen('https://congress.api.sunlightfoundation.com/legislators/locate?latitude={}&longitude={}&apikey=15f4679bdc124cd6a2c6be8666253000'.format(user_lat, user_long))) + +for i in legislators['results']: + print i['last_name'] + ' ' + i['bioguide_id'] + +#All Legislators, irrespective of location + +#House only +#legislators = json.load(urllib2.urlopen('https://congress.api.sunlightfoundation.com/legislators?chamber=house&per_page=all&apikey=15f4679bdc124cd6a2c6be8666253000'.format(user_lat, user_long))) + +#All Legislators +#legislators = json.load(urllib2.urlopen('https://congress.api.sunlightfoundation.com/legislators?per_page=all&apikey=15f4679bdc124cd6a2c6be8666253000'.format(user_lat, user_long))) + +#print 'Based on the latitude and longitude provided, your United States Congresspeople are: \n' + + +#Prints Congressman/Congresswoman + First, Last + +def find_legislators(): + + for i in legislators['results']: + print i['last_name'] + ' ' + i['bioguide_id'] + #legislator_ids.append(i) + +#find_legislators() + +#votes_url = json.load(urllib2.urlopen('https://congress.api.sunlightfoundation.com/votes?voter_ids.{}__exists=true&apikey=15f4679bdc124cd6a2c6be8666253000')).format( __ THIS IS WHERE THE UNIQUE ID OF THE LEGISLATOR NEEDS TO BE __ ) + +#pprint(votes_url) + +#def recent_votes(): + + ##THIS IS WHERE YOU ARE GOING TO RETURN THE LAST 10 VOTES BY var = LEGISLATOR + +def print_legislators(): + + for i in legislators['results']: + + if i['chamber'] == 'house' and i['gender'] == 'M': + print 'Congressman {} {} - {} \nPhone: {}\nWebsite: {}\n'.format(i['first_name'],i['last_name'],i['party'],i['phone'],i['website'] ) + if i['chamber'] == 'house' and i['gender'] == 'F': + print 'Congresswoman {} {} - {} \nPhone: {}\nWebsite: {}\n'.format(i['first_name'],i['last_name'],i['party'],i['phone'],i['website'] ) + elif i['chamber'] == 'senate': + print 'Senator {} {} - {} \nPhone: {}\nWebsite: {}\n'.format(i['first_name'],i['last_name'],i['party'],i['phone'],i['website'] ) + +#print_legislators() diff --git a/Students/SSchwafel/Project/GovTrack_InformedVoter.py b/Students/SSchwafel/Project/GovTrack_InformedVoter.py new file mode 100644 index 00000000..119ca07a --- /dev/null +++ b/Students/SSchwafel/Project/GovTrack_InformedVoter.py @@ -0,0 +1,23 @@ + +#List Current Members of Congress with GovTrack +#congresspeople_url = 'https://www.govtrack.us/api/v2/role?current=true&limit=600' + +#One Particular Congressman +#url = 'https://www.govtrack.us/api/v2/person/400054' +# this takes a python object and dumps it to a string which is a JSON +# representation of that object +data = json.load(urllib2.urlopen(congresspeople_url)) + +objects = data['objects'] +#for representative in objects: +# print representative['person']['name'].encode('utf-8') +#pprint(objects[0][person]['sortname']) + +representatives = [] + +for i in objects: + representatives.append(i['person']['sortname'].encode('utf-8')) + +#representatives = sorted(representatives) +#pprint(representatives) + diff --git a/Students/SSchwafel/Project/InformedVoter.py b/Students/SSchwafel/Project/InformedVoter.py new file mode 100644 index 00000000..ac050868 --- /dev/null +++ b/Students/SSchwafel/Project/InformedVoter.py @@ -0,0 +1,94 @@ +#!/usr/bin/python + +from __future__ import unicode_literals +from pprint import pprint +import simplejson as json +import sys +import urllib2 + +#This allows printing to the console, including being able to pipe ( | ) the input +reload(sys) +sys.setdefaultencoding("utf-8") + +#Making sure that there is at least one command line argument, if not, is none +if len(sys.argv) == 1: + command_line_argument = None +else: + command_line_argument = sys.argv[1] + +#Finds out the user's IP address for lookup +user_local_data = json.load(urllib2.urlopen('http://api.ipinfodb.com/v3/ip-city/?key=a648bf3844359d401197bcaa214dd01e0f8c0c6d623ec57f3716fbcafc8262bd&format=json')) + +#Set variables for detected lat/long +user_lat = user_local_data['latitude'] +user_long = user_local_data['longitude'] + +#lat_long_url = 'https://congress.api.sunlightfoundation.com/districts/locate?latitude={}&longitude={}&apikey=15f4679bdc124cd6a2c6be8666253000'.format(user_lat, user_long) + +#Look up legislators from API with given lat/long, then store in a var. for later use +legislators = json.load(urllib2.urlopen('https://congress.api.sunlightfoundation.com/legislators/locate?latitude={}&longitude={}&apikey=15f4679bdc124cd6a2c6be8666253000'.format(user_lat, user_long))) + + +#Remnant of abandoned functionality +def find_legislators(): + """This function returns the legislator's last name and unique bioguide id, this would be useful for further, unimplemented features""" + for i in legislators['results']: + print '{} {}'.format(i['last_name'], i['bioguide_id']) + +def print_all_legislators(): + """This function prints all the legislators, then formats according to gender and title""" + + legislators = json.load(urllib2.urlopen('https://congress.api.sunlightfoundation.com/legislators?per_page=all&apikey=15f4679bdc124cd6a2c6be8666253000')) + for i in legislators['results']: + + if i['chamber'] == 'house' and i['gender'] == 'M': + print 'Congressman {} {} - {} \nPhone: {}\nWebsite: {}\n'.format(i['first_name'],i['last_name'],i['party'],i['phone'],i['website'] ) + if i['chamber'] == 'house' and i['gender'] == 'F': + print 'Congresswoman {} {} - {} \nPhone: {}\nWebsite: {}\n'.format(i['first_name'],i['last_name'],i['party'],i['phone'],i['website'] ) + elif i['chamber'] == 'senate': + print 'Senator {} {} - {} \nPhone: {}\nWebsite: {}\n'.format(i['first_name'],i['last_name'],i['party'],i['phone'],i['website'] ) + +def print_manual_legislators(): + """This function prints the legislators of the given lat/long, then formats according to gender and title""" + + print """ + + You can get your latitude and longitude from http://www.latlong.net/ + + """ + + user_lat = raw_input('Please enter your Latitude: \n') + user_long = raw_input('Please enter your Longitude: \n') + + legislators = json.load(urllib2.urlopen('https://congress.api.sunlightfoundation.com/legislators/locate?latitude={}&longitude={}&apikey=15f4679bdc124cd6a2c6be8666253000'.format(user_lat, user_long))) + + for i in legislators['results']: + + if i['chamber'] == 'house' and i['gender'] == 'M': + print 'Congressman {} {} - {} \nPhone: {}\nWebsite: {}\n'.format(i['first_name'],i['last_name'],i['party'],i['phone'],i['website'] ) + if i['chamber'] == 'house' and i['gender'] == 'F': + print 'Congresswoman {} {} - {} \nPhone: {}\nWebsite: {}\n'.format(i['first_name'],i['last_name'],i['party'],i['phone'],i['website'] ) + elif i['chamber'] == 'senate': + print 'Senator {} {} - {} \nPhone: {}\nWebsite: {}\n'.format(i['first_name'],i['last_name'],i['party'],i['phone'],i['website'] ) + +def print_detected_legislators(): + """This function prints the legislators local to the IP address of the user, then formats according to gender and title""" + for i in legislators['results']: + + if i['chamber'] == 'house' and i['gender'] == 'M': + print 'Congressman {} {} - {} \nPhone: {}\nWebsite: {}\n'.format(i['first_name'],i['last_name'],i['party'],i['phone'],i['website'] ) + if i['chamber'] == 'house' and i['gender'] == 'F': + print 'Congresswoman {} {} - {} \nPhone: {}\nWebsite: {}\n'.format(i['first_name'],i['last_name'],i['party'],i['phone'],i['website'] ) + elif i['chamber'] == 'senate': + print 'Senator {} {} - {} \nPhone: {}\nWebsite: {}\n'.format(i['first_name'],i['last_name'],i['party'],i['phone'],i['website'] ) + +if command_line_argument == '--all-legislators': + print_all_legislators() + +elif command_line_argument == None: + print 'Based on the latitude and longitude detected, your United States Congresspeople are: \n' + print_detected_legislators() + +elif command_line_argument == '--manual': + print_manual_legislators() + diff --git a/Students/SSchwafel/Project/README b/Students/SSchwafel/Project/README new file mode 100644 index 00000000..168b9463 --- /dev/null +++ b/Students/SSchwafel/Project/README @@ -0,0 +1,10 @@ +README +====== + +Welcome to the Informed Voter app! Right now, it provides the following functionality: + +Lists YOUR legislators based on an IP lookup, by running the program with no argument, these are returned + +Listing ALL legislators currently in Congress (run with the command line argument --all-legislators + +Finding out the representatives of a location via lat/long (access this functionality by running it with the --manual option) diff --git a/Students/SSchwafel/Project/test.py b/Students/SSchwafel/Project/test.py new file mode 100644 index 00000000..ea15c3a0 --- /dev/null +++ b/Students/SSchwafel/Project/test.py @@ -0,0 +1,9 @@ +#!/usr/bin/python + +from __future__ import unicode_literals +from pprint import pprint +import urllib2 +import simplejson as json + +url = json.load(urllib2.urlopen('https://congress.api.sunlightfoundation.com/votes?fields=voters&apikey=15f4679bdc124cd6a2c6be8666253000')) +pprint(url) diff --git a/Students/SSchwafel/session07/circle_class_lab.py b/Students/SSchwafel/session07/circle_class_lab.py new file mode 100644 index 00000000..904647e6 --- /dev/null +++ b/Students/SSchwafel/session07/circle_class_lab.py @@ -0,0 +1,64 @@ +#!/usr/bin/python +from math import pi + +class Circle(object): + def __init__(self, radius): + self.radius = float(radius) + + @classmethod + def from_diameter(cls, diameter): + + return cls(diameter/2.0) + + def __add__(self, other): + + return Circle(self.radius + other.radius) + + def __mul__(self, other): + try: + + return Circle(self.radius * other.radius) + except AttributeError: + + return Circle(self.radius * other) + + __rmul__ = __mul__ + + def __lt__(self, other): + + return self.radius < other.radius + + def __gt__(self, other): + + return self.radius > other.radius + + def __eq__(self, other): + + return self.radius == other.radius + + @property + def diameter(self): + return self.radius*2.0 + @diameter.setter + def diameter(self, value): + self.radius = value/2.0 + @property + def area(self): + return self.radius**2*pi + def __repr__(self): + return "Circle{}".format(self.radius) + +c = Circle(4) +c2 = Circle(5) + +print c.radius +print c.diameter +print c.area +#print c.__repr__ + +print c + c2 +print c2 * 2 +print 2 * c2 +print c2 < c2 + +print c2 * c2 diff --git a/Students/SSchwafel/session07/test_circles.py b/Students/SSchwafel/session07/test_circles.py new file mode 100644 index 00000000..e6739acd --- /dev/null +++ b/Students/SSchwafel/session07/test_circles.py @@ -0,0 +1,26 @@ +#!/usr/bin/python + +from circle_class_lab import Circle + +def test_area(): + + circle1 = Circle(4) + circle2 = Circle(5) + + assert circle1.area < circle2.area + +def test_adding(): + + circle1 = Circle(4) + circle2 = Circle(5) + + assert circle1+circle2 == Circle(9) + + +def test_mul(): + + circle1 = Circle(4) + circle2 = Circle(5) + + assert circle1*circle2 == Circle(20) + #assert circle1*2 == Circle8 diff --git a/Students/SSchwafel/session08/callable_lab.py b/Students/SSchwafel/session08/callable_lab.py new file mode 100644 index 00000000..d657a793 --- /dev/null +++ b/Students/SSchwafel/session08/callable_lab.py @@ -0,0 +1,18 @@ +#!/usr/bin/python + +class Quadratic(object): + + def __init__(self, a, b,c): + + self.a = a + self.b = b + self.c = c + + def __call__(self,x): + self.x = x + + return self.a * self.x**2 + self.b * self.x + self.c + +my_quad = Quadratic(a=2, b=3, c=1) + +my_quad(0) diff --git a/Students/SSchwafel/session08/generator_lab.py b/Students/SSchwafel/session08/generator_lab.py new file mode 100644 index 00000000..699aab46 --- /dev/null +++ b/Students/SSchwafel/session08/generator_lab.py @@ -0,0 +1,74 @@ +#!/usr/bin/python + + +def sum_generator(number_range): + + counter = list(range(number_range)) + + new_value = 0 + i = new_value + + while i < number_range: + + try: + + item = counter.pop(0)+counter.pop(0) + yield item + counter.insert(0,item) + + except IndexError: + + break + + +sum_gen = sum_generator(10) +print next(sum_gen) +print next(sum_gen) +print next(sum_gen) +print next(sum_gen) +print next(sum_gen) +print next(sum_gen) + +def doubler(number_range): + i = 0 + while i= self.length: + raise IndexError("Sparse array index out of range") + + else: + + self.values.get(index, 0) + + def __len__(self): + return self.length + + def __setitem__(self, index, value): + + if index >= self.length: + raise IndexError("Sparse array index out of range") + else: + if value == 0: + self.values.pop(index, None) + else: + self.values[index] = value + def __delitem__(self, index): + + if index >= self.length: + raise IndexError("Sparse array index out of range") + else: + self.values.pop(index,None) + self.length -= 1 + + diff --git a/Students/SSchwafel/session09/context_manager_lab.py b/Students/SSchwafel/session09/context_manager_lab.py new file mode 100644 index 00000000..8c027240 --- /dev/null +++ b/Students/SSchwafel/session09/context_manager_lab.py @@ -0,0 +1,15 @@ +#!/usr/bin/python + +class Timer(object): + + def __enter__(self): + print "In __enter__" + self.start = time.time() + return self + + def __exit__(self, err_type, err_val, err_trc): + + print "In __exit__" + self.elapsed = time.time() - self.start + print "Run took {} seconds".format(self.elapsed) + print err_type, err_val, err_trc diff --git a/Students/SSchwafel/session09/p_wrapper_lab.py b/Students/SSchwafel/session09/p_wrapper_lab.py new file mode 100644 index 00000000..26cb6b18 --- /dev/null +++ b/Students/SSchwafel/session09/p_wrapper_lab.py @@ -0,0 +1,24 @@ +#!/usr/bin/python + +def p_wrapper_func(func, tag): + + def tagger(tag): + + tag_type = raw_input("Tag? ") + tag_type = tag_type.title() + + return tag_type + + def p_wrapper(*args, **kwargs): + tag_type = tag + user_input = func(*args, **kwargs) + #return "

{}

".format(user_input) + return "<{}> {} ".format(tag, user_input, tag) + return p_wrapper + +@p_wrapper_func +def print_test_string(): + test_text = "this is a test string" + return test_text + +print print_test_string() diff --git a/Students/SSchwafel/session10/ICanEatGlass.utf81.txt b/Students/SSchwafel/session10/ICanEatGlass.utf81.txt new file mode 100644 index 00000000..49a44fd9 --- /dev/null +++ b/Students/SSchwafel/session10/ICanEatGlass.utf81.txt @@ -0,0 +1,23 @@ +I Can Eat Glass: + +And from the sublime to the ridiculous, here is a certain phrase in an assortment of languages: + +Sanskrit: काचं शक्नोम्यत्तुम् । नोपहिनस्ति माम् ॥ + +Sanskrit (standard transcription): kācaṃ śaknomyattum; nopahinasti mām. + +Classical Greek: ὕαλον ϕαγεῖν δύναμαι· τοῦτο οὔ με βλάπτει. + +Greek (monotonic): Μπορώ να φάω σπασμένα γυαλιά χωρίς να πάθω τίποτα. + +Greek (polytonic): Μπορῶ νὰ φάω σπασμένα γυαλιὰ χωρὶς νὰ πάθω τίποτα. + +Latin: Vitrum edere possum; mihi non nocet. + +Old French: Je puis mangier del voirre. Ne me nuit. + +French: Je peux manger du verre, ça ne me fait pas mal. + +Provençal / Occitan: Pòdi manjar de veire, me nafrariá pas. + +Québécois: J'peux manger d'la vitre, ça m'fa pas mal. diff --git a/Students/SSchwafel/session10/unicode_lab.py b/Students/SSchwafel/session10/unicode_lab.py new file mode 100644 index 00000000..5d0a42a2 --- /dev/null +++ b/Students/SSchwafel/session10/unicode_lab.py @@ -0,0 +1,21 @@ +#!/usr/bin/python + +file = open('/home/schuyler/PythonFolder/session10/ICanEatGlass.utf81.txt', 'rw') + +unicode_string = u'bananas'.encode('utf-8') + +unicode_chess_piece = u'\u2654' + +unicode_chess_piece = unicode_chess_piece.encode('utf-8') + +print unicode_chess_piece + +#print unicode_string + +print file.read() + +file.write(unicode_chess_piece) + +print file.read() + +file.close() diff --git a/Students/SSchwafel/session10/unicode_lab.py~ b/Students/SSchwafel/session10/unicode_lab.py~ new file mode 100644 index 00000000..5d0a42a2 --- /dev/null +++ b/Students/SSchwafel/session10/unicode_lab.py~ @@ -0,0 +1,21 @@ +#!/usr/bin/python + +file = open('/home/schuyler/PythonFolder/session10/ICanEatGlass.utf81.txt', 'rw') + +unicode_string = u'bananas'.encode('utf-8') + +unicode_chess_piece = u'\u2654' + +unicode_chess_piece = unicode_chess_piece.encode('utf-8') + +print unicode_chess_piece + +#print unicode_string + +print file.read() + +file.write(unicode_chess_piece) + +print file.read() + +file.close()