jython / book Goto Github PK
View Code? Open in Web Editor NEWThe Jython Book
The Jython Book
At least in Chapter 19 (did not check the other chapters) most code examples are not included correctly. Instead there is a message box like ".. literalinclude:: src/chapter19/threadsafety.py"
https://github.com/jython/book/blob/master/DefiningFunctionsandUsingBuilt-Ins.rst
I've tried Listing 4-46 where Decorators in Coroutines are declared, but i get
$ jython co_example.py
Traceback (most recent call last):
File "co_example.py", line 2, in <module>
@coroutine_next
NameError: name 'coroutine_next' is not defined
Added my code here: https://github.com/heywiki/jython-book-examples/blob/master/chapter4/co_example.py
Use naming like 01-language-and-syntax.rst
instead of chapter1.rst
. Lexicographical ordering is preserved (currently it is lost due to chapter1 vs chapter10), while allowing people to more readily find a specific chapter to edit.
When trying out code examples by copy & paste it from the browser into a sourcecode editor that uses UTF-8 by default, you at first don't recognize that some code examples contain non ASCII characters, which results in the error message
File "<string>", line None
SyntaxError: Non-ASCII character in file 'wrong_encoding.py', but no encoding declared; se
see http://www.python.org/peps/pep-0263.html for details
This is very confusing for beginners , time consuming to figure out and breaks the flow when learning. When you switch the encoding of the file to ASCII, you then can see the error. The code examples actually use the wrong character, the minus in that case is not the real minus character, its dash from UTF-8 charset:
The example shown is from chapter 1, break statement:
https://jython.readthedocs.io/en/latest/chapter1/#break-statement
I also had a similar error with "sports team" example in chapter 3.
https://jython.readthedocs.io/en/latest/chapter3/#example-code
Some chapters link to the wrong address, as seen in currently in this section.
Such fixups should be automated.
"The code for this program can be downloaded at XXX." -> so i created that on my own, see https://github.com/heywiki/jython-book-examples/tree/master/chapter7
what i discovered:
users have to start the program not by scanner.py like described, but by
jython searchdir.py . term
In searchdir.py you have to call a static method on ScanResults: scanner.ScanResults.scan(), not an object one, and exit() was not working, had to use sys.exit()
#from scanner import ScanResults
import search.scanner as scanner
import sys
help = """
Usage: search.py directory terms...
"""
args = sys.argv
if args == None or len(args) < 2:
print help
sys.exit()
dir = args[1]
terms = args[2:]
scan = scanner.ScanResults.scan(dir, terms)
scan.display()
Accordingly you have to add the @staticmethod annotation to ScanResults.scan
from search.walker import DirectoryWalker
from javax.swing import JFrame, JTable, WindowConstants
class ScanResults(object):
def __init__(self):
self.results = []
def add(self, file, line):
self.results.append((file, line))
def display(self):
colnames = ['file', 'line']
table = JTable(self.results, colnames)
frame = JFrame("%i Results" % len(self.results))
frame.getContentPane().add(table)
frame.size = 400, 300
frame.defaultCloseOperation = WindowConstants.EXIT_ON_CLOSE
frame.visible = True
@staticmethod
def scan(dir, terms):
results = ScanResults()
for filename in DirectoryWalker(dir):
for line in open(filename):
for term in terms:
if term in line:
results.add(filename,line)
return results
I have found a later version of the book in a repo belonging to Josh Juneau than the one we are building on. :( This version is much closer to the paper edition.
It will take some careful work to merge Josh's into this repository, because of fixes made here that that version lacks. (I think that's the right thing to do, but only trying will tell us if it's a lost cause.)
Believe it or not, I actually found this via the unfinished Korean translation on RTD, which I spotted contained stuff we didn't have.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.