Похожие чаты

Is main a file ?

13 ответов

12 просмотров

Don't get you??

If you name your file that way, then yes it is a file. If you don't name a file like that, then no, it isn't a file.

You mean in the context of if __name__ == "__main__"? If so, __name__ is a variable that all python programs have, if you run your python file directly from the interpreter (e.g. if you do something like $ python my_script.py) then the value of __name__ for my_script will be "__main__", but ONLY if you execute that file directly like $ python my_script.py.

A- Автор вопроса
Bread pup ▲⬤ ×▫︎
You mean in the context of if __name__ == "__main_...

But when we import smth isn't it being runned by python?

A- Автор вопроса
A
I mean the code which we import

Then, __name__ is assigned the fully qualified name of the module it is defined in, most cases the file name of the module (the file with .py extension) that is imported

A- Автор вопроса
Bread pup ▲⬤ ×▫︎
Then, __name__ is assigned the fully qualified nam...

I knew it , but when we run something that is imported then it also runs directly from interpreter ,does it?

A
I knew it , but when we run something that is impo...

You can only run or import a python module, not both at the same time. If you were to have: import module1 module1.func() inside module2.py and then run module2.py, you'd have run module2 and imported module1. You can run module1 directly, but it wouldn't be imported (you can't import a module inside itself)

A- Автор вопроса
Bread pup ▲⬤ ×▫︎
You mean in the context of if __name__ == "__main_...

You sad if a module runs directly from interpreter then it is name is main So when i import module 1 to module 2 ,then module 1runs directly from interpreter but it is name is not main

A
You sad if a module runs directly from interpreter...

When you import module 1 into module 2 and you run module 2, module 1 is not run directly, but module 2 is. In this case module 2 __name__ is __main__, but module 1 __name__ is not.

A- Автор вопроса

U confused me a bit by saying "runs directly from interpreter"

A- Автор вопроса
Bread pup ▲⬤ ×▫︎
When you import module 1 into module 2 and you run...

I thought when we import it copies the code from module 1 to module2

Похожие вопросы

Обсуждают сегодня

Какой-то там пердун в 90-х решил, что есть какая-то разная типизация. Кого вообще это волнует?
КТ315
49
Hi. Do we have a raid bot? Why nobody doing raids on X? Even RH mentioned this and nobody paying attention...whats the channel for hex memes? If mods cant run raids just insta...
H
31
Подскажите, а есть vault lite или ченить такое?) А то нужен вольт для похода в вольт, но весит он ~500 мб) как-то многовато для парочки запросов ))
Alexandr Orloff
17
блеать, почему так?? где в роутере это исправляется?
Арсен Маньяков 🇦🇲
16
void terminal_scroll() { memmove(terminal_buffer, terminal_buffer + VGA_WIDTH, buffer_size - VGA_WIDTH); memset(terminal_buffer + buffer_size - VGA_WIDTH, 0, VGA_WIDTH); ...
Егор
47
🌊 Ocean Nodes Dashboard Update 🚀 Hey, Oceaners! First off, a massive round of applause 👏to all of you for the amazing engagement since we launched Ocean Nodes. In just a few ...
KreigDK | Never DM first🌊
3
Всем привет! Подскажите, пожалуйста, в чем ошибка? Настраиваю подключение к MySQL. Либы лежат рядом с exe. Все как по "учебнику"
Евгений
16
А можете как-то проверить меня по знаниям по ассемблеру?
A A
132
Здравствуйте! У меня появилась возможность купить книгу "Изучай Haskell во имя добра!". Но я где-то слышал, что эта книга устарела. Насколько это правда??
E
22
люди, которые используют flameshot, к вам вопрос. Можно-ли поставить хоткей на создание скриншота? В программе есть отдел "горячие клавиши", но там все для редактирования, скр...
ThunDer104
11
Карта сайта