Ask your own question, for FREE!
MIT 6.00 Intro Computer Science (OCW) 21 Online
OpenStudy (anonymous):

working on problem set 1 is copying and pasting frowned upon in python? I pasted some code I had made for question 2 into my script for the whole problem set and suddely I'm getting a syntax error for x=1 I've tried deleting and rewriting lines but python continues to give me syntax error (no additional information) ideas? the code works in a separate script...

OpenStudy (rsmith6559):

Copy and paste is just a technique for editing. It only matters to the editor. That said, is the code you copied plain text? If it was a word processing document, it could have formatting and display information in it that will make Python barf. Is the code indented properly? This can be a real stinker since 8 spaces LOOK just like two tabs, but they're different and Python will barf.

OpenStudy (anonymous):

I noticed that python doesn't let me copy/paste unless the code is within a function. for example... x = 10 while x<100: x= x + 1 print x will not run if copy and pasted into the IDE... but the function... def blah( ): x = 10 while x < 100: x = x + 1 print is copy and paste-able, and will run in the IDE

OpenStudy (anonymous):

Thanks for the tips! your feedback means a lot! That said, I'm not sure if we're quite at a solution yet but I think if I describe the situation better, we should be able to figure it out. I'm currently using IDLE 2.7.11 on Mac OS 10.11.3. When working on the problem sets, I typically have 3 IDLE windows open. one for the shell, one for a script I call "test" and a 2nd script where I would paste and tweak functional solutions for the problem sets. Copy and Pasting functions from the test script to the PS script typically worked just fine, but this is not the first time that the PS script began to act erratically. I have noticed that in the problematic region of the script, anytime I hit return the curser begins two indentations over for no reason I can explain. for the moment, I've just re-written the code into a new script for the problem set, but I'd like to figure out why this is happening, how to avoid it, or how to fix it in the future.

OpenStudy (rsmith6559):

I gave up using IDLE because it was converting my tabs to 4 spaces. Gave me fits when I'd pick up the code the next day, inserted a new line with tabs and got errors. Now I use XCode for editing and Terminal for experimenting and execution. An easy way to check for the conversion is to open a Terminal window and: cd Desktop egrep '^ ' pythonFile cd is "Change Directory", in this case going onto your Desktop. egrep is "Enhanced General Regular Expression Program", you'll learn regular expressions (RE) later. They're used to write filters. In this case, the caret is the beginning of a line, then a couple of spaces. pythonFile is whatever file that's giving you problems. If your tabs have been converted to spaces, much of your program will print on the screen. If the tabs are still tabs, nothing will show.

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!