New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Ported some examples of File IO into Python mode #236
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you! Please apply my comments throughout all of the examples, and then we'll take another look.
def draw(): | ||
global index | ||
pieces = [] | ||
if (index < len(lines)): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need for java-isms like parens around conditionals.
if (index < len(lines)): | ||
pieces = split(lines[index], '\t') | ||
if (len(pieces) == 2): | ||
x = int(pieces[0]) * 2 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why * 2?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I took this as is from the example in the Java mode. I think this was done because the inputs are in the range of 0-99 whereas the canvas was of size 200 X 200. Should I remove it?
|
||
lines = loadStrings("cars2.tsv") | ||
records = [] | ||
for i in xrange(len(lines)): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for line in lines:
global recordCount | ||
global records | ||
global num | ||
global startingEntry |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
None of these global statements are needed
|
||
def mousePressed(): | ||
global records | ||
global num |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no need for global statements for records and num
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The other examples also need to be fixed in the same way as the few I commented on.
for i in xrange(len(lines)): | ||
pieces = split(lines[i], TAB) # Load data array | ||
if (len(pieces) == 9): | ||
for line in xrange(len(lines)): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for line in lines:
no need to use indexes
for line in lines: | ||
pieces = split(line, TAB) # Load data array | ||
if len(pieces) == 9: | ||
records.insert(recordCount, Record(pieces)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why not just records.append(Record(pieces))
?
|
||
|
||
def setup(): | ||
global recordCount |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This variable is unnecessary; just use len(records)
def setup(): | ||
global recordCount | ||
global records | ||
global num |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
num
is not a good name
20, | ||
20 + | ||
index * | ||
20) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
text("%d > %s" % (thisEntry, records[thisEntry].name), 20, 20 * index * 20)
beginShape() | ||
for i in xrange(len(x)): | ||
vertex(x[i], y[i]) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
delete this blank line
def keyPressed(): # Press a key to save the data | ||
lines = [] | ||
for i in xrange(len(x)): | ||
lines.insert(i, str(x[i]) + "\t" + str(y[i])) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lines.append("%d\t%d" % (x[i], y[i]))
|
||
# An arbitrary oscillating rotating animation | ||
# so that we have something to render | ||
for a in xrange(0, TWO_PI, 1): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This shouldn't even run; I don't think you can use a foating point number in a range statement. Have you run these programs?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did run this program and it gave the correct output, but I understand, i'll change this to something more appropriate
20) | ||
|
||
if thisEntry < len(records): | ||
text("%d > %s" % (thisEntry, records[thisEntry].name), 20, 20 + index * 20) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please format
20, | ||
20 + | ||
index * | ||
20) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did the auto-format do this strange formatting?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I used autopep8 for the formatting. Is it wrong?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here is how these lines should be formatted:
if thisEntry < len(records):
text("%d > %s" %
(thisEntry, records[thisEntry].name), 20, 20 + index * 20)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you, I have made the changes.
global startingEntry | ||
startingEntry += numEntries | ||
if startingEntry > len(records): | ||
startingEntry=0 # go back to the beginning |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All files need to be correctly formatted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Made the change. Thank you.
|
||
# An arbitrary oscillating rotating animation | ||
# so that we have something to render | ||
for a in xrange(0, 6, 1): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not how Daniel Shiffman's example works; goes between 0 and 2pi by 0.2 at a time.
I don't have time to evaluate every line of code in this pull request, and I don't think there's anything to be gained from further work. I'm sorry you've spent so much time on it, but I'm closing this request.
referencing issue: jdf/Processing.py-Bugs#4