Code in .py file - for beginners

I am new to Python, so apologies for the basic Q.
When I try to execute this file, I get following result,
PS C:\pyfund> python words.py
C:\Program Files\Python313\python.exe: can’t find ‘main’ module in ‘C:\pyfund\words.py’
PS C:\pyfund>
Any suggestions please ?
Thank you.

You will need to share the contents of words.py for us to be able to help.
Also please use the preformatted text option when posting your code so that it is formatted nicely. It’s the </> button.

print('For example')   # like this

Hi Barry,

Thanks for your reply.

I just tried to send the document words.py ; but this has been rejected.

I thought it would be useful to print also the contents below in this email :

from urllib.request import urlopen

with urlopen(‘http://sixty-north.com/c/t.txt’) as story:

story_words =

for line in story:

line_words = line.decode(‘utf-8’).split()

for word in line_words:

story_words.append(word)

This was originally a Word document, of which I changed the extension to *.py

When I want to run the document with PowerShell, I get following error.

The above example comes from a book where I learn the Python language.

I program for +20 years with VBA, but Python is new to me.

Thanks in advance for your help.

Kind regards,

Wim

Please no screen shots. What you do is copy and paste the text from your program into preformatted text area.

You mention email. Best to access this site with your web browser so you can bet the formatting right.

You seem to have posted the contents of words.py but the error does not match the code you posted.

This is not a valid way to create a python file. Python is trying to open it as a zipapp, which ofcourse doesn’t work since it’s not a valid zipapp either.

You need to create a text file, using e.g. notepad.

1 Like

What exactly do you mean by “changed the extension to *.py”?

I believe you need to save the document as plain text and then change the extension, otherwise it’ll just be a Word document with the “.py” extension.

If you open the file in, say, Notepad, does it look like what you’ve posted?

Incidentally, what you’ve posted doesn’t have the required indentation.

In order to preserve formatting, please select any code or traceback that you post and then click the </> button.

Thanks all.
This is working now.
It had something to do with the way the *.py file was created.
I created now the file from NotePad and now this is all working.
Thanks again.
Wim