Mike Bayer avatar Mike Bayer committed b4befd0

- get all the print() statements to work w python 3

Comments (0)

Files changed (5)

 tmp
 dist
 .venv
+.venv3
 .coverage
 .DS_Store
 .buildinfo

01_engine_usage.py

 
 result = engine.execute("select * from employee")
 for row in result:
-    print row
+    print(row)
 
 ### slide:: p
 # the fetchall() method is a shortcut to producing a list
 # of all rows.
 result = engine.execute("select * from employee")
-print result.fetchall()
+print(result.fetchall())
 
 ### slide:: p
 # The execute() method of Engine will *autocommit*
 ### slide:: i
 # It's a bit like a Python dictionary but not totally.
 
-print user_table.c
+print(user_table.c)
 
 ### slide::
 # Column itself has information about each Column, such as
 ### slide::
 # The Table object is at the core of the SQL expression
 # system - this is a quick preview of that.
-print user_table.select()
+print(user_table.select())
 
 ### slide:: p
 # Table and MetaData objects can be used to generate a schema
 user_reflected = Table('user', metadata2, autoload=True, autoload_with=engine)
 
 ### slide:: i
-print user_reflected.c
+print(user_reflected.c)
 
 ### slide::
 # Information about a database at a more specific level is available
         filter(a2.email_address=='jack@hotmail.com').\
         all()
 
-### slide:: -*-no_exec-*-
+### slide:: p
 # A major feature of Query is its great ability to build compound statements
 # using multiple SELECTs.  The subquery() method of Query combines the select()
 # and alias() Core constructs to return a new "derived table" from any Query.
 
 session.query(User.name, subq.c.count).join(subq, User.id==subq.c.user_id).all()
 
-### slide:: -*-no_exec-*-
+### slide:: p
 # The subquery() feature and aliased() constructs can be combined together,
 # so that we can load entities from a subquery.  This is an example of
 # mapping an arbitrary row to a domain object.
 ### slide::
 # Part VI. Eager loading
 
-### slide:: -*-no_exec-*-
+### slide:: p
 # A key issue when working with object relationships in ORMs is the
 # so-called "N+1" problem.  When we iterate through a series of User
 # objects and their Address collections, we see that many SQL statements are emitted
 for user in session.query(User):
     print(user, user.addresses)
 
-### slide:: -*-no_exec-*-
+### slide:: p
 # To deal with this issue, we need to selectively apply *eager load*
 # directives at *query time* so that the ORM knows what relationships should
 # be loaded up front.  subqueryload() is one such directive that emits
 session.expire_all()
 
 for user in session.query(User).options(subqueryload(User.addresses)):
-    print user, user.addresses
+    print(user, user.addresses)
 
-### slide:: -*-no_exec-*-
+### slide:: p
 # The subqueryload directive is complemented by the joinedload() directive,
 # which emits a JOIN in one statement.  It's particularly useful
 # for many-to-one loads.
 
 for address in session.query(Address).\
                 options(joinedload(Address.user)):
-    print address, address.user
+    print(address, address.user)
 
-### slide:: -*-no_exec-*-
+### slide:: p
 # an important thing about joinedload() is that
 # it does not change the results of the query.
 # You can't ORDER BY the joinedload(), you use join() for that.
                 join(Address.user).\
                 filter(User.name=='jack').\
                 options(joinedload(Address.user)):
-    print address, address.user
+    print(address, address.user)
 
-### slide:: -*-no_exec-*-
+### slide:: p
 # to join *and* eagerload at the same time without using two
 # JOIN clauses, use contains_eager.
 
                 join(Address.user).\
                 filter(User.name=='jack').\
                 options(contains_eager(Address.user)):
-    print address, address.user
+    print(address, address.user)
 
 ### slide::
 # Part VII. Cascades
     def __repr__(self):
         return "<Address(%r)>" % self.email_address
 
-### slide:: -*-no_exec-*-
+### slide:: p
 # now, removing an Address from a user means that it gets
 # *deleted*.
-session = Session()
+session = Session(bind=engine)
 
 u1 = session.query(User).filter_by(name="jack").one()
 
 del u1.addresses[1]
 session.commit()
 
-### slide:: -*-no_exec-*-
+### slide:: p
 # deleting the User also deletes all the Address objects
 # associated with it.
 
             log.setLevel(logging.INFO)
         else:
             log.setLevel(logging.WARN)
-        print "%% SQL echo is now %s" % (self._echo and 'ON' or 'OFF')
+        print("%% SQL echo is now %s" % (self._echo and 'ON' or 'OFF'))
 
 deck = SADeck
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.