Ex25.py Am I doing it right?

Hi Ric

I still want to know if you have installed Powershell.

Ulfen69: As I said in the first sentence of this post…
Let me go over what I have done so far with ex25.py in the LP3THW book. I copied all the code on page 90 in Notebook ++. I opened it in Win Powershell.
So yes, I have only used WinPS and Notepad++.
I don’t mean to be nasty, but some of my questions don’t seem to be answered. All I want to know is what I’m supposed to put after the prompt, and why it is not loading my code? Thank you. Not2smart.

Ok.

Sorry. I did not anything before this answer that you are using Powershell.

So.
Do you know how to see where the powershell is located when you start it up?

Do you know how to navigate to the directory where your ex25.py is?

Do you know how to see if your file is in the directory where you have changed to?

I hope you just answer me:
Yes. I know this now.
Or:
No. But I will start learning this from now.

These are basic knowledge you should have to be comfortable with using powershell and much more effective working with Python.

You see. I still want to help you.
If you don’t want my help just tell me.

Best regards
Ulfen69

Hi @Not2smart I will try to give my 5 cents in this discussion. I think you have some confusion about how to use powershell. You don’t have to open anything in Powershell. You have to be in the Powershell and then run some commands.

  1. Go to the start button on the lower left side of windows and type “Powershell”. Click on “Powershell”

  1. Powershell will open up and look like this:

  1. Navigate to the directory/folder lpthw/ex25. In my case, the directory lpthw is on C:\lpthw, so I have to type:
cd \lpthw\ex25\

  1. Make sure your file ex25.py is in that directory/folder. Type ls and it should look something like this:

grafik

  1. Now you can run the script with Python. Type this:
python ex25.py

grafik

It should work.

Kind regards,
Didier

2 Likes

I’m back from my trip @Not2smart so I’ll handle your email and give you access to the videos, but this is the problem:

“at this point I return to my computer and launch Python 3.7 from the icon on my desktop. It loads up and has the lines of info as is on page 91 of the book, with the >>> prompt.”

I do NOT ever click on any icon to run python. Ever. Never. I never run anything in programming by clicking on anything with my mouse ever. I type the commands INTO POWERSHELL. Always.

If you are clicking on icons and clicking on files then that’s the problem. I suspect you’ve done this for all of the book up to exercise 25 and it mostly worked, but now you’re stuck. I actually wonder how you did that because I say and show how I do it over and over in the book.

So, I’d like to also give you a call and talk to you to find out what you’re doing. Mostly to see where you got derailed on this and how to course correct. I’ll shoot you an email, but look at what @DidierCH wrote and the screenshots he posted.

Ulfen69: Sorry that I was a little testy. I appreciate your help. I think Zed found my problem, because I’m opening PS with an icon on the Desktop. I don’t know what is wrong with that,but I guess I will learn pretty fast. Thanks. Not2smart.

Perhaps I was a bit harsh myself.

But I am happy to help if you want.
Please tell us how you get along.

Ulfen

Zed: Hmmm. I have been clicking on icons to launch programs since Win 3.1. When I load a new program, I just naturally put an icon on the desktop. I didn’t know it made a difference. (I still don’t know why.) My ISP is having problems with email right now so even if you send something I won’t be able to open it. I’ll spend the weekend going over what you and the others have written and see what happens. Thank you.
P.S. I’ll send you the money for the videos, right now I have Christmas and property taxes due in the next month, so it might be a few weeks. If I can’t afford something, I don’t buy it. No freebies for me. Not2 smart.

I have been using an icon on the desktop to launch P.S. According to Zed, that is a no no. First time I ever heard that. Not2smart.

To load PowerShell, yes that’s fine but I suspect you are loading a lot more than powershell by clicking on things.

But, I think a large part of the problem with helping you is the information you give on what your issue is ends up being very thin and vague. It looks like your writing style for the posts is without any formatting and there’s no screenshots or copying and pasting of output. I think that’s what I’m sort of baffled by, and why I wonder if you’re unaware of this or simply can’t do it for some less obvious reason.

So, let me take a minute to sort of lay out what you do vs. what would help people help you more. Here’s an example of an excerpt from your post, but broken down line by line:

  1. I opened it in Win Powershell. – Opened what on PowerShell? Did you start powershell, cd to the directory, and type exactly python ex25.py, or did you do something else. Where’s the screenshot for this, or the copy-paste of what is currently showing in your powershell?
  2. After correcting a few mistakes and running it again, all I get is the path. – What mistakes? Where’s the screenshot or copy-paste of the output? What’s the error codes? What’s the code? We never see your code?
  3. I assume that is all I’m supposed to get. – Yes, but then you didn’t show this code so we have no idea.
  4. Then I opened it in the Python 3.6 and – What do you mean “opened it in python 3.6”? If I have a microsoft powerpoint file with the ending .ppt then I will double click that file to open it in powerpoint. Or, I might start powerpoint, then use the File menu to open the .ppt file. HOWEVER, Python does not work like powerpoint at all. You don’t open code in it. You use the powershell command python to execute the ex25.py by typing only: python ex25.py. So, a detailed step by step explanation of what you’re doing to “open in python 3.6” would help us figure out what’s going on.
  5. get all sort of errors, even though I’m doing it like the book says to. – Again, where are the copy-paste or screenshots of these errors? Where’s the code?

Now, how you can improve your help requests (and also help yourself figure out what’s wrong) is to become systematic about explaining what’s wrong. Thinking systematically is what you have to do when you code. You tend to write huge giant stream of consciousness paragraphs with no line breaks and very little punctuation. To code you have to break this habit and start thinking in terms of step-by-step operations of a system. One way to help you think about this is to imagine this:

“How would I explain what’s wrong to a 5 year old?”

To explain to a 5 year old you’d have to do it slowly and in small incremental steps until they get it. So with that in mind, you can do this to improve how you communicate your problems:

  1. Use enumeration lists like this one to explain in excruciatingly detailed steps what you are doing. Just type 1 2 3 or 4 with a . (period) and then a sentence like you would if you were typing out the steps to fix a car or cook a recipe.
  2. Copy-and-paste every single thing. If you don’t know how to do that you use your mouse to select the text to copy, hold CTRL, then hit c. To paste it into the forum you hold CTRL then hit v. Before you do this, type out [code], then paste your errors, code, anything you want to show, then type [/code] to close your code block.
  3. Be honest about your setup and limitations. You say your ISP is limiting and you have to go to a library to do downloads. Well that would limit your ability to upload images, so explain that so we can adjust our recommendations to fit your needs. If you have troubles typing, hearing, seeing, anything just be honest and explain your limits so we can help work around them.
  4. Understand that sometimes people get frustrated not because they’re angry at you or think you’re stupid, but because your communication style is hiding information from people that they need to help you. I’m not sure why you refuse to post copy-paste code and errors, but if you’re worried people will make fun of you then remember that everyone here is a beginner or used to be a beginner so they wouldn’t make fun of you at all. Also, you’re using Not2Smart as your handle so nobody knows it’s you. Drop that trash code here in safety so you can get some help my friend!

Changing up how you post your code for help would vastly speed up and improve your response. If you have an explanation about why you aren’t posting your code and errors then let us hear it. Otherwise, let’s see that stuff. It’s easier to help you then.

Hi all, is there a reason why you all start off using a CMD line/terminal/shell versus editing code/a script file in Notepad++ a more robust text editor like Atom or Sublime? I find that their thematic syntax highlighting and built-in linting reduces errors due to whitespace or typos.

Indeed, we all use a robust text editor like VSCode, Atom or, like some of us, Vim. But to run the code I do it always from the terminal/shell (thought you can do it in some sophisticated text editors directly, aka VSCode, Atom).

For a beginner in coding it might be best to start with the simplest solution like gedit or notepad++ so you don’t get distracted by all the cool features of the other editors and still have syntax highlighting and the like.

p.s.: I think zed’s last suggestion was to try VSCode.

1 Like

For a beginner in coding it might be best to start with the simplest solution like gedit or notepad++ so you don’t get distracted by all the cool features of the other editors and still have syntax highlighting and the like.

I didn’t realize that there were so many similar capabilities between all the various tools. Thank you for clarifying, I was responding to the topic under numerous assumptions about the differences between editors.

p.s.: I think zed’s last suggestion was to try VSCode.

I missed it; I was reading too fast. Thank you!

To all that helped me: I’m going to not use this topic any more and will start the book over and do it the way the book says. Many times I would not send copies of my work because I would spend time trying to work things out, then disgusted and tired, just shut down the computer. I did not know that you can’t use icons to start a program for some programs. That might be my problem. I will also watch the videos and look over the .pdf files. Thanks for all your help. (To those that don’t like my handle, I’ll use my name. Ric Trexell, hopefully that was… Not2smart.

4 Likes

That’s amazing! Keep on it and you will finally get it. I had a hard start in programming too. It’s so different to my normal way of thinking. But as soon as you grasp it, a lot will be easier. Last year I enrolled in the free Stanford Computer Science 101 class. Something I can recommend to you, too. Nick Parlante does a good job in introducing some concepts of computer science. It’s a good complimentary to LPTHW.

I had the same problem with ex25. I went through the comments and came across this one, and all is fixed. It turns out I had saved the ex25.py file in a different folder via Atom. So I copied it in a correct folder and it worked out just fine.

OK, I had problems back in Nov. when I first started with ex25.py and went back and did the book from the beginning at lesson one. Now I’m back to lesson ex25.py and having some of the same problems. Basically, I do this. I go to the Start ball and click it to bring up Win Power Shell. In PS I notice something different from the video’s of Zed’s. This is what I get after the C stuff,Users\Ric and I type Python but Zed puts in lpthw> python. I get problems if I add ‘lpthw’. I wanted to paste that in here but that doesn’t work. I get the lines that say all that about help, copy write and then the >>>. I then type import ex25, and get error messages. I did go back today and check my ex25.py file for errors even after I had ran it in PS and found I really goofed up on line 28 and 29, but that is fixed and didn’t solve the problem. Is there a way to paste the error message in this message box? What I’m getting is a message that says there is no ex25. I’m using Win 7 if that matters. If I have to type out the error messages I will, but first I would like to know, why does putting lpthw in the command line mess me up, and just putting ‘python’ makes it work up to the >>> prompt. I’m beginning to wonder if there is something wrong with my computer! Thanks in advance. N2S.

Because the info before the prompt is generally the present working directory and the User.

If you haven’t created a folder calls ‘lpthw’ you won’t see it, like in Zed’s example.

Let’s say you are at Windows ‘My Documents’ when you open PS. If it helps syncing to the book, create a file call ‘lpthw’ and change into that directory:

Rics Prompt > mkdir lpthw 
Rics Prompt > cd lpthw

Now your Powershell is working in that location so you must have ex25.py in there before opening python prompt.

Assuming you’ve copied it there or creates it from scratch, when you type ‘python3’ you will open the python prompt (with all the copyright info etc).

Now you can call the info from the ex25.py file (as it’s in that location) from the prompt (as it’s a python file, you only need the name, not the ‘.py’ extension.

import ex25

As for posting errors, take a screen shot and add it by clicking and dragging it into this reply window. That should work.

Oh, I think I have the lpthw folder in the wrong place. I will look that over tomorrow. Up to this point, I have been just going to the folder and opening the files. Now I have to import them. I hope I got that right and make sense. Also, thanks for explaining how to take a screen shot to drag them into the message box. I’ll try that tomorrow. N2S.

Hey all: I got it working. I don’t know what I did today that I didn’t do last night, but was able to do the exercize three times due to spelling words like ‘word’, with a ‘k’ so that it was ‘work’. I had to fix it and start all over like the book said. I’ll try the Study Drills tomorrow. Thanks for the help. N2S.

3 Likes