osdir.com


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Run python module from console


On 9/5/17 11:16 AM, Stefan Ram wrote:
> Andrej Viktorovich <viktorovichandrej at gmail.com> writes:
>> I suppose I can run python module by passing module as param for executable:
>> python.exe myscr.py
>> But how to run script when I'm inside of console and have python prompt:

The Python console isn't meant for ad-hoc execution of random scripts.?
It's designed for running one program, from the OS command line.? If you
need to run different scripts within one interpreter session, it might
be better to reorganize your code, or find a different execution
environment.

> exec( compile( open( 'myscr.py', 'rb' ).read(), 'myscr.py', 'exec' ))
>
>   . This looks quite complicated, but there are rumors
>   that Python 4 might have a ?execfile? function, and
>   one then will be able to write:
>
> execfile(  'myscr.py' )

It's better to not start rumors about fictitious Python versions.

--Ned.