Jump to content

I need a Python expert to help me with an error that I am getting on my strings file I worked wi...


G+_Thomas Chidwick
 Share

Recommended Posts

I need a Python expert to help me with an error that I am  getting on my strings file I worked with on the first Episode of Python.  Here is my link to the file.  So what is going on is that when I run the code after I had inputted everything correctly (or what I think looks correct) in to Notepad++.  I saved the file and then I ran it.  Once it started to run the window will open and then close on me.  I do not know what is going on, I don't see any difference from what Coding101 has out on Gethub.  Please help me.  Thank you!

https://drive.google.com/file/d/0B5MTNlVi-JbNS3lyVG9ibWdzRUU/edit?usp=sharing

Link to comment
Share on other sites

It appears you got some extra stuff at the beginning of your file.  The first line of the file should be:

 

#! usr/bin/env python

 

All the stuff you have before that is just the output of the python shell itself.  In fact, you don't even need that comment line with the "#!" unless you are a Linux or Mac user that likes to run scripts from the command line.  Under Windows, the .py extension is all you need so that you can double-click on a script to run it.

 

To catch errors like this in the future, I'd suggest keeping a command window open next to your Notepad++ window so that you can run your scripts by typing on the command line: python scriptname.py

 

It is a shame that the show didn't spend at least a few minutes on how to use IDLE, the editor that comes with Python.  You could have caught your errors there, too.  When you start IDLE, you first see an interactive Python shell window.  This is where you can try out stuff.  To write a script - what Python calls a "module" - choose File->New from the menu.  A new window opens up that is a code editor window.  Put your Python code here in this new window.  Notice that the code lines do not run instantly like over in the interactive window.  When you are ready to test your script, save it with File->Save, then run it from within IDLE by choosing Run->Run Module.  Your script will be "imported" into the interactive window and you will see any errors there.  I hope this helps.

Link to comment
Share on other sites

I agree that they should show how to use IDLE. The expert's time would be better spent with something like this rather than rewriting a few lines of code that Padre has just written. Also, when you're in the Windows IDLE code editor you can just press F5 to run the program you're editing in the shell.

Link to comment
Share on other sites

Tom, I can tell you that I "discovered" that it had been installed on my PC when I just happened to see it in my Start menu. Since I had downloaded what they recommended on the show I feel they should have mentioned it. Anyway, the editor has basic features to help you write code: block indent / un-indent, comment / un-comment, syntax checking (finds errors), highlighting, etc. Like Lee said, it's fairly weak compared to commercial IDE's and pro editors but it's way better than Notepad.

Link to comment
Share on other sites

 Share

×
×
  • Create New...