__main__.__file__
doesn’t exist in the interactive interpreter:
import __main__ as main
print hasattr(main, '__file__')
This also goes for code run via python -c
, but not python -m
.
Related Contents:
- How can I force division to be floating point? Division keeps rounding down to 0?
- How does Python 2 compare string and int? Why do lists compare as greater than numbers, and tuples greater than lists?
- How can I concatenate str and int objects?
- What is the difference between range and xrange functions in Python 2.X?
- What are the differences between the urllib, urllib2, urllib3 and requests module?
- Nested arguments not compiling
- How to get string objects instead of Unicode from JSON?
- Writing Unicode text to a text file?
- f-strings giving SyntaxError?
- No module named MySQLdb
- Setting the correct encoding when piping stdout in Python
- Alternative to dict comprehension prior to Python 2.7
- Python unexpected EOF while parsing
- Why does Python print unicode characters when the default encoding is ASCII?
- What is __future__ in Python used for and how/when to use it, and how it works
- Python – ‘ascii’ codec can’t decode byte
- How do I prevent a C shared library to print on stdout in python?
- How to decorate a class?
- Converting “yield from” statement to Python 2.7 code
- Python exception chaining [duplicate]
- How to reinstall python@2 from Homebrew?
- Is it ever useful to use Python’s input over raw_input?
- Running an interactive command from within Python
- How can I read large text files partially (out-of-core)? [duplicate]
- How to print a percentage value in python?
- Defining “boolness” of a class in python
- How dangerous is setting self.__class__ to something else?
- What is more ‘pythonic’ for ‘not’ [duplicate]
- write() versus writelines() and concatenated strings
- NameError from Python input() function [duplicate]
- How to read a CSV file from a URL with Python?
- How to: Macports select python
- Implement an interactive shell over ssh in Python using Paramiko?
- Convert float to string in positional format (without scientific notation and false precision)
- Get output from a Paramiko SSH exec_command continuously
- Why does input() give a SyntaxError when I just press enter?
- Malformed String ValueError ast.literal_eval() with String representation of Tuple
- Why does assigning to True/False not work as I expect?
- Strange behaviour with floats and string conversion
- How do you use subprocess.check_output() in Python?
- Multiple (asynchronous) connections with urllib2 or other http library?
- compare lines in a file with a string
- UnicodeDecodeError: ‘utf8’ codec can’t decode bytes in position 3-6: invalid data
- How do convert unicode escape sequences to unicode characters in a python string
- How do comparison operators < and > work with a function as an operand?
- How to accomplish relative import in python
- Replace list of list with “condensed” list of list while maintaining order
- ImportError: DLL load failed: %1 is not a valid Win32 application for Python Matplotlib
- Pretty print JSON dumps
- IndentationError: unindent does not match any outer indentation level, although the indentation looks correct