Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #102491 > unrolled thread

Re: .py file won't open in windows 7

Started byTim Golden <mail@timgolden.me.uk>
First post2016-02-04 13:09 +0000
Last post2016-02-04 13:09 +0000
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: .py file won't open in windows 7 Tim Golden <mail@timgolden.me.uk> - 2016-02-04 13:09 +0000

#102491 — Re: .py file won't open in windows 7

FromTim Golden <mail@timgolden.me.uk>
Date2016-02-04 13:09 +0000
SubjectRe: .py file won't open in windows 7
Message-ID<mailman.59.1454591350.30993.python-list@python.org>
On 04/02/2016 12:52, Yossifoff Yossif wrote:
> Hallow,
> I try to open a .py file (attached), but what I get is a windows DOS window opening and closing in a couple of seconds. Ran repair of the program, nothing happened.
> I cannot see error messages and don't know where to look for ones.
> Would appreciate your piece of advice.

Attachments won't make it through to the list, Yossif. But your code is
basically something like this:

"""
import sys

def main():
  # calculate stuff
  print(stuff)

if __name__ == '__main__':
  sys.exit(main())
"""

In that case, the program starts (in a console window), runs, prints the
result, and then closes. You've got a few simple ways of seeing the output:

* Run the program from the command line (start a console window in the
directory where the code is and type "ss7calc.py")


https://docs.python.org/3/faq/windows.html#how-do-i-run-a-python-program-under-windows

* Instead of use sys.exit immediately, add input("Press enter...") to
the end of your code:

  https://docs.python.org/3/library/functions.html?highlight=input#input

eg:

result = main()
input("Press enter...")
sys.exit(result)

* set the PYTHONINSPECT environment variable for your user

  https://docs.python.org/3/using/cmdline.html#envvar-PYTHONINSPECT

* Use a shebang line "#!python -i" (without the quotes) at the top of
your program.

  https://docs.python.org/3/using/windows.html#shebang-lines

These last two options will drop into the Python interpreter after your
code has run.

TJG

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web