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
6
votes
3 answers
python - sys.argv and flag identification
when I accept arguments how do I check if two show up at the same time without having a compound conditional
i.e.
#!/usr/bin/python
import random, string
import mymodule
import sys
z = ' '.join(sys.argv[2:])
q = ''.join(sys.argv[3:])
a =…

tekknolagi
- 10,663
- 24
- 75
- 119
6
votes
2 answers
Errors at Python program exit: "close failed in file object destructor"; "sys.excepthook is missing"
After the last line (print statement) in my python code, I get the following error:
close failed in file object destructor:
sys.excepthook is missing
lost sys.stderr
Anyone know where this might be coming from?
Update: My python code is extremely…

user20408
- 679
- 2
- 7
- 23
6
votes
3 answers
Why does not os.system("cd mydir") work and we have to use os.chdir("mydir") instead in python?
I tried doing a "pwd" or cwd, after the cd, it does not seem to work when we use os.system("cd"). Is there something going on with the way the child processes are created. This is all under Linux.

sadashiv30
- 601
- 2
- 7
- 15
6
votes
3 answers
ctypes in python size with the `sys.getsizeof(Var)` method vs `ctypes.sizeof(Var)`
I have a question about variable size in python, I'm using the the Ctypes because i want a 1 byte number, but when I tried to check it's size in python (via sys.getsize) it said it was 80 byte but when i checked with the ctypes (via ctypes.sizeof)…

Newbie
- 386
- 4
- 19
6
votes
1 answer
Difference between sys.exit(app.exec_()) and app.exec_()
I am working with PySide and PyQt for GUI development. I have been using these codes to run a GUI application:
app = QApplication(sys.argv)
ex = MyWin()
ex.show()
sys.exit(app.exec_())
Accidentally I found if I replace sys.exit(app.exec_()) with…

Northern
- 2,338
- 1
- 17
- 20
6
votes
3 answers
sys.path vs. $PATH
I would like to access the $PATH variable from inside a python program. My understanding so far is that sys.path gives the Python module search path, but what I want is $PATH the environment variable. Is there a way to access that from within…

J Jones
- 3,060
- 4
- 26
- 43
5
votes
4 answers
What does 'sys.argv' mean?
I am learning from code, and I am get confused by one of its lines which is:
things = [float(arg) for arg in sys.argv[1:]]
Omega_a, Omega_b, Delta_a, Delta_b, \
init_pop_a, init_pop_b, tstep, tfinal = things
I have searched online and tried to…

user1233157
- 345
- 3
- 5
- 11
5
votes
3 answers
Python `print` passing extra text to sys.stdout?
This is probably something stupid I am missing but it has really got me hung up on a larger project (c extension) that I am writing.
Why is print "Hello, World!" passing None and an extra \n to sys.stdout here?
>>> import sys
>>> class…

chown
- 51,908
- 16
- 134
- 170
5
votes
1 answer
Reading from sys.stdin, ending user input with RETURN
I am working on a script with user input in Py 3.6.
In the script, the user is asked to enter a text section - potentially containing new lines - into the shell. The entered text will then be saved to a Python variable for further processing.
Since…

patrick
- 4,455
- 6
- 44
- 61
5
votes
2 answers
Is sys 'temporarily' imported when print is called?
I was looking at the Python documentation for print which states:
print(*objects, sep=' ', end='\n', file=sys.stdout, flush=False)
As it can be seen, if the file on which to print is not specified, the default sys.stdout is used, which got me…

Ma0
- 15,057
- 4
- 35
- 65
5
votes
3 answers
How can I run a Python 3 script with imports from a subfolder?
Whatever I try, since I switched to Python 3 I can run scripts with imports only from the root folder of the project, but not from subfolders. I am aware that there are lots of questions here about the error messages I get, but the proposed…

Watchduck
- 1,076
- 1
- 9
- 29
5
votes
1 answer
Why does QtWidgets.QApplication require sys.argv?
Hello guys i am learning pyqt5 from a series of tutorials at youtube and i didn't get why QtWidgets.QApplication have the argument sys.argv i am not familiar with sys library i read the documentation but still have no clue so sorry i know this…

walrus
- 65
- 1
- 5
5
votes
1 answer
Python Process pool executor shutdown on signal
I use supervisor to run some script like this. so when supervisor is stopped or interrupt, i try to gracefully exit from the script. This is my current code
import concurrent.futures
import random
import os
import signal
import sys
executor =…

Anandan
- 353
- 3
- 17
5
votes
0 answers
Why does sys.stdin.read() return ' ' permanently without seeking input?
While playing with sys.stdin.read() (Terminal, Mac OS Sierra), found weird behavior where it becomes unusable. What's happening?
# Python 2.7.13
import sys
sys.stdin.read()
# waits for input
# user presses ctrl-d (without any input)
# returns…

JBallin
- 8,481
- 4
- 46
- 51
5
votes
1 answer
SyntaxWarning: name 'color' is assigned to before global declaration global color Python
In the code below it says:
"SyntaxWarning: name 'color' is assigned to before global declaration
global color"
However, I declared global color before I assign it? I am very confused. I ran it and it works but I just don't understand what the…

MissSprezzatura
- 183
- 2
- 3
- 13