enter image description here enter image description here enter image description here Water code:

>>> import mymodule Traceback (most recent call last): File "<pyshell#0>", line 1, in <module> import mymodule File "C:\Users\art-a\AppData\Local\Programs\Python\Python37-32\mymodule.py", line 1 Python 3.7.1 (v3.7.1:260ec2c36a, Oct 20 2018, 14:05:16) [MSC v.1915 32 bit (Intel)] on win32 ^ SyntaxError: invalid syntax >>> 

I study according to the book and, at the moment, I go through the section "modules", it says there that in order to import enough of this command, even though I did everything that was said in the book, the error still comes out. The code for the imported program is:

 def hello(): print ("hello world") 
  • 2
    As obvious as this is, the Python 3.7.1 line Python 3.7.1 in fact not a valid python code. First put things in order in the file, and then import - andreymal
  • This is part of the mistake - Ayrat Khaibullin
  • Take a screenshot of the file mymodule.py - andreymal
  • Made a screenshot. When you open IDLE, this line is written automatically and cannot be erased, nor should it be read, but read as I understand - Ayrat Khaybullin
  • Take a screenshot of the file mymodule.py in a normal text editor, for example, in Notepad or in WordPad - andreymal

2 answers 2

I agree with the andreymal comment, judging by the traceback'y you have the first line is Python 3.7.1 (v3.7.1:260ec2c36a, Oct 20 2018, 14:05:16) [MSC v.1915 32 bit (Intel)] on win32 is one of the lines of your code, or it was in the book, and you accidentally rewrote, or throw the code in more detail (console screen), in general, if you go to the console and start python, you will have 4 icons and write import modulename , then it will work , moreover, judging by the traceback'y , the error is not in the import, which works, but in the mymodule.py file, mymodule.py its code here, please, if you can, or if it has a line:

 Python 3.7.1 (v3.7.1:260ec2c36a, Oct 20 2018, 14:05:16) [MSC v.1915 32 bit (Intel)] on win32 

remove it.

  • Added the first screen and the code of the second program - Ayrat Khaibullin
  • This is part of the mistake - Ayrat Khaibullin
  • I explain once again: judging by the traceback in the mymodule.py file for this: C:\Users\art-a\AppData\Local\Programs\Python\Python37-32\mymodule.py path, you have a file that is called an error (this is the file you are importing), namely on the first line of this file you will see this line: Python 3.7.1 (v3.7.1:260ec2c36a, Oct 20 2018, 14:05:16) [MSC v.1915 32 bit (Intel)] on win32 , you need to remove it it does not make sense, and I do not know where you took it from (maybe copied from the book) - NEStenerus nester
  • Yes you are right. I added a screenshot of this program. When opening IDLE, this line is written automatically and cannot be erased, as it should not be read, but read as I understood - Ayrat Khaybullin
  • These lines cannot be erased, but it DOES NOT NEED TO COPY to a file! You simply copied all the contents of the window, including service information, into mymodule.py . - Enikeyschik

The file mymodlue.py should look like this:

 def hello() print ("hello world") 

You are not looking copied there absolutely everything from IDLE, including service information.

  • I didn’t copy anything, when launching IDLE it appears itself ... Maybe I have something wrong with the python itself, but I wrote only what you quoted in the comment above - Airat Khaibullin
  • How did you create the mymodule file? - Enikeyschik
  • I went to IDLE through start-up, wrote the code, saved and gave the name of the program - Ayrat Khaybullin
  • Clear. When you just enter IDLE, it’s not a script editor, but a command line. Therefore, you have saved all the contents of the window, including service information. - Enikeyschik
  • Is the command line in the screenshots? - Ayrat Khaybullin