__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
.
More Related Contents:
- 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?
- How to return dictionary keys as a list in Python?
- Is it ever useful to use Python’s input over raw_input?
- Python – ‘ascii’ codec can’t decode byte
- Python: avoid new line with print command [duplicate]
- Dangers of sys.setdefaultencoding(‘utf-8’)
- Django TemplateDoesNotExist?
- General Unicode/UTF-8 support for csv files in Python 2.6
- Read data from CSV file and transform from string to correct data-type, including a list-of-integer column
- How to reinstall python@2 from Homebrew?
- Python, default keyword arguments after variable length positional arguments
- NameError from Python input() function [duplicate]
- Malformed String ValueError ast.literal_eval() with String representation of Tuple
- Checking for interactive shell in a Python script
- Why does assigning to True/False not work as I expect?
- Multiple (asynchronous) connections with urllib2 or other http library?
- What does from __future__ import absolute_import actually do?
- What is the difference between isinstance(‘aaa’, basestring) and isinstance(‘aaa’, str)?
- How do convert unicode escape sequences to unicode characters in a python string
- How to accomplish relative import in python
- Relative imports in python 2.5
- What is a “callable” in Python?
- Empty string instead of unmatched group error
- Uninstall python built from source?
- How can I obtain the image size using a standard Python class (without using an external library)?
- Run interactive Bash with popen and a dedicated TTY Python
- Is it possible to run python SimpleHTTPServer on localhost only?
- Python: How to resize an image using PIL module
- How to add an element to the beginning of an OrderedDict?