# Code in .py file - for beginners

**URL:** <https://discuss.python.org/t/code-in-py-file-for-beginners/82900>\
**Category:** Python Help\
**Created:** [March 3, 2025, 2:06pm UTC](https://discuss.python.org/t/code-in-py-file-for-beginners/82900 "2025-03-03T14:06:59Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![WimD](https://avatars.discourse-cdn.com/v4/letter/w/bcef8e/32.png) [@WimD](https://discuss.python.org/u/WimD)\
**Post date:** [March 3, 2025, 2:06pm UTC](https://discuss.python.org/t/code-in-py-file-for-beginners/82900/1 "2025-03-03T14:06:59Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![barry-scott](https://avatars.discourse-cdn.com/v4/letter/b/e9c0ed/32.png) [@barry-scott](https://discuss.python.org/u/barry-scott)\
**Post date:** [March 3, 2025, 4:00pm UTC](https://discuss.python.org/t/code-in-py-file-for-beginners/82900/2 "2025-03-03T16:00:51Z")

</div>

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.

```python
print('For example') # like this

```

---

<div class="post-metadata">

**Author:** ![WimD](https://avatars.discourse-cdn.com/v4/letter/w/bcef8e/32.png) [@WimD](https://discuss.python.org/u/WimD)\
**Post date:** [March 3, 2025, 4:43pm UTC](https://discuss.python.org/t/code-in-py-file-for-beginners/82900/3 "2025-03-03T16:43:47Z")

</div>

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](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.

 ![](https://us1.discourse-cdn.com/flex002/uploads/python1/original/3X/d/c/dc6ac27557a430b87bea9a91652881433ed03801.png)

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

---

<div class="post-metadata">

**Author:** ![barry-scott](https://avatars.discourse-cdn.com/v4/letter/b/e9c0ed/32.png) [@barry-scott](https://discuss.python.org/u/barry-scott)\
**Post date:** [March 3, 2025, 5:02pm UTC](https://discuss.python.org/t/code-in-py-file-for-beginners/82900/4 "2025-03-03T17:02:01Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![MegaIng](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/megaing/32/16162_2.png) [@MegaIng](https://discuss.python.org/u/MegaIng)\
**Post date:** [March 3, 2025, 5:06pm UTC](https://discuss.python.org/t/code-in-py-file-for-beginners/82900/5 "2025-03-03T17:06:22Z")

</div>

> [@WimD](#):
>
> This was originally a Word document, of which I changed the extension to \*.py

This is not a valid way to create a python file. Python is trying to open it as a [zipapp](https://docs.python.org/3/library/zipapp.html), which ofcourse doesn’t work since it’s not a valid zipapp either.

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

---

<div class="post-metadata">

**Author:** ![MRAB](https://avatars.discourse-cdn.com/v4/letter/m/e9c0ed/32.png) [@MRAB](https://discuss.python.org/u/MRAB)\
**Post date:** [March 3, 2025, 5:11pm UTC](https://discuss.python.org/t/code-in-py-file-for-beginners/82900/6 "2025-03-03T17:11:00Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![WimD](https://avatars.discourse-cdn.com/v4/letter/w/bcef8e/32.png) [@WimD](https://discuss.python.org/u/WimD)\
**Post date:** [March 3, 2025, 6:54pm UTC](https://discuss.python.org/t/code-in-py-file-for-beginners/82900/7 "2025-03-03T18:54:13Z")

</div>

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
