• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

Problem with inserting code

Brett

Senior member
So I insert the following code:

reader = open("student.txt",'r') #open a file reader
studentList = []

while True:
line = reader.readline()

#note that '' is 2 single quotes, not one double quote
if line == '': #readers return an empty string when there are no lines left to read
break

line = line[:-1] #strip the trailing end of line character

myStudent = Student(line) #create a student from the name
studentList.append(myStudent) #add the student to the list

print studentList

into the AttachCode so that it retains the whitespace (since whitespace matters in python). The attached code looks like this:

any reason why its not preserving either the whitespace or the newlines? Also, if I edit the message (and dont repaste the code) all that gets left is what is seen here. See the reply for what it looks like initially
 
this is what it looks like just after attaching the code and not editing, above is what it looks like if I edit the message but dont reattach the code
 
Any chance the Add code feature is going to be fixed so it doesn't strip out line feeds, tabs, etc.? Thanks.
 
Back
Top