For questions about the Python module named sys. This tag is also used for questions relating to the Sys namespace - the root namespace for the Microsoft AJAX Library, which contains all fundamental classes and base classes.
Questions tagged [sys]
1100 questions
2
votes
1 answer
Python relative imports with sys.path
I have this weird Python import and I can't get it to work with any of the suggestions in other discussions.
I'm currently adding a small script to someone else's module, so I cannot change the file structure or any of the existing code, which makes…

goocreations
- 2,938
- 8
- 37
- 59
2
votes
1 answer
Does import look in the current working directory before the path? or the path then the cwd?
Which of the following describes the behavior of from [...] import [...]?
cwd first: look in working directory first, then the path
path first: look in the path, then the working directory
Consider the following scripts:
Change…

Toothpick Anemone
- 4,290
- 2
- 20
- 42
2
votes
0 answers
Python console: difference between sys.version() and os.system("python -V")
When I use Pycharm, whose default python interpreter is set to be python 2.7.14. When I run the integrated console in Pycharm several line of code bellow, the python versions are confusing. Could someone explain what's the difference between these…

Jason
- 3,166
- 3
- 20
- 37
2
votes
1 answer
Python import iteration, sys.path
So I was wondering, at this point in time I'm reading a book about Python. The book explains the following:
The import algorithm
To truly understand namespace packages, we have
to look under the hood to see how the import operation works in 3.3.
…

YetAnotherDuck
- 294
- 4
- 13
2
votes
2 answers
Sys.argv python error list index out of range
I'm new user of stackoverflow, besides I'm not an English guy, so I'm sorry for my english.
I was programming in python 'til I got a mistake tho I'm not able to figure out what's wrong...
#!/usr/bin/env python2.7
from random import choice
import…

Sharki
- 404
- 4
- 23
2
votes
1 answer
How to run a python script while storing live output from the console?
I'd like to create a function that executes python scripts while storing the console output live as it's executing.
For example, I use the subprocess module to run example.py, but I only receive the console output after the entire script has run…

Chris
- 5,444
- 16
- 63
- 119
2
votes
1 answer
Understanding sys.getrefcount differences in result
After reading about sys.getrefcount, I tried to play with it with the code below:
import sys
go = 102133333333333333333333333
sys.getrefcount(go)
>>> 2
sys.getrefcount(102133333333333333333333333)
>>> 3
Why am I getting this result, in particular…

Yuval Pruss
- 8,716
- 15
- 42
- 67
2
votes
1 answer
Python: pass sys.argv when loading python script with subprocess.Popen
I have a script that opens a file using subprocess.Popen so I can run it in the background. I would like to be able to run this script with ./[script] [params]
#!/usr/bin/python
import subprocess
import sys
sys.path.insert(0,"./pyqt")
import gui
if…

APorter1031
- 2,107
- 6
- 17
- 38
2
votes
1 answer
import a module up two and down one directory in Python package
I wanted to load a module named mymodule in a directory up two, and down one directory in my file system. Elsewhere I have used
import sys
sys.path.append('../mydirectory')
import mymodule # in mydirectory
in order to go up one, then down one…

Lucius Schoenbaum
- 67
- 9
2
votes
1 answer
running `print(sys.platform)` in the plain Python interpreter yielded a blank string
Running print(sys.platform) in the plain Python interpreter yielded a blank string
I try to configure the code of an open source python project on github..I installed the program with pip install and it worked perfectly. However, in order to make…

Spiros Chadoulos
- 21
- 2
2
votes
0 answers
what does sys._getframe(0).f_lineno do exactly?
The following is the code. I roughly understand that sys._getframe(i).f_lineno do, if the number i is bigger than 0. So, it's the line number when you actually make the function call. Python interpreter puts it in a stack. That's how you get the…

study
- 333
- 1
- 5
- 16
2
votes
3 answers
Why def main(argv=[__name__]) and if __name__ == "__main__": sys.exit(main(sys.argv))?
I'm working with/rewriting a code that first defines a function as follows:
def main(argv=[__name__]):
...
*rest of code*
...
and ends with:
if __name__ == "__main__":
sys.exit(main(sys.argv))
I'm under the impression that what…

D. W.
- 163
- 1
- 2
- 9
2
votes
0 answers
Are there WIN32 exit codes that roughly correspond to POSIX exit codes?
I'm writing a python application that runs in a cross platform environment. Every once in awhile I have to use a sys.exit to stop the program when something goes wrong (or if something goes right). I'd like to use standardized exit codes beyond just…

Erotemic
- 4,806
- 4
- 39
- 80
2
votes
2 answers
Execute another python script, then shut down current script
I have a python script script_a.py that uses subprocess.call() that executes another script script_b.py as it's last instruction before ending. I need script_b.py to wait until script_a.py closes before proceeding with its own instructions. For this…

KidMcC
- 486
- 2
- 7
- 17
2
votes
2 answers
Python external project script execution
After many researches on the web, on many different topics, I wasn't able to find the solution answering my problem.
I am developing a tool (with graphic interface) allowing to process python scripts from different projects.
To not have any…

v_lfr
- 63
- 8