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
12
votes
3 answers
Relative path in Google Drive mounted in Google Colab
I have a Google Colab notebook that I want to distribute to other users, and I want to include relative paths for files and directories in my mounted Google Drive so that the code doesn't break when they put it in a different directory than the one…

rchurt
- 1,395
- 1
- 10
- 21
12
votes
1 answer
What does "del sys.modules[module]" actually do?
As everyone knows, you can do del sys.modules[module] to delete an imported module. So I was thinking: how is this different from rewriting sys.modules? An interesting fact is, rewriting sys.modules can't truely delete a module.
#…

laike9m
- 18,344
- 20
- 107
- 140
12
votes
4 answers
Problem with sys.argv[1] when unittest module is in a script
I have a script that does various things and access parameters using sys.argv but when the script gets to the unittest part of the code it says there is no module for this. The script that I have is:
class MyScript():
def __init__(self):
…

chrisg
- 40,337
- 38
- 86
- 107
10
votes
1 answer
What does sys.path.append("..") do?
I bumped into this statement in a Python script: sys.path.append("..")
I did some research, but I could not find what it does.
I know sys.path.append() function appends a path at the end of the PYTHONPATH list. But what does ".." stand for?
Needless…

CDuvert
- 367
- 1
- 3
- 14
10
votes
1 answer
Why does writing to stdout in console append the number of characters written, in Python 3?
I was just playing around with sys.stdout.write() in a Python console when I noticed that this gives some strange output.
For every write() call the number of characters written, passed to the function respectively gets append to the output in…

randhash
- 463
- 4
- 15
10
votes
2 answers
Python sys.argv to preserve ' ' or ""
terminal:
python test.py blah='blah'
in test.py
print sys.argv
['test.py', 'blah=blah'] <------------
How can blah arg preserve its '' OR
Is there a way to know if an arg is wrap with either "" or ''?

ealeon
- 12,074
- 24
- 92
- 173
9
votes
1 answer
Virtualenv, no-site-packages, sys.path
My essential problem is that I can't get --no-site-packages to "work."
I have read a bunch of posts on SO, including this post. I'm a huge Ubuntu noob, and not much better when it comes to how python interacts with the os.
Other posts suggested that…

NotAnAmbiTurner
- 2,553
- 2
- 21
- 44
9
votes
5 answers
Importing python libraries from Github
I have written some libraries in Python for use in my project. I have stored them locally on my system and also remotely on Github. Now every time I write some code I use sys.path.append() in the beginning to help import my libraries from the…

biryani
- 268
- 1
- 2
- 8
9
votes
2 answers
What is the difference between input() and sys.stdin?
I am new to python and trying some coding problems online. i come across sys.sdnin a lot for accepting input. I would like to know how input() and sys.stdin differs in action?

raj
- 5,989
- 7
- 30
- 62
9
votes
4 answers
Run python script with some of the argument that are optional
I have gone through the sys documentation, however there is something that is still unclear to me. I have looked for some similar question on stackoverflow, but I haven't find anything useful (clearly any reference is appreciated!).
I want to create…

rafforaffo
- 511
- 2
- 7
- 21
9
votes
1 answer
Why doesn't sys.excepthook work?
Why isn't the sys.excepthook function called if I try to execute this code?
import sys;
def MyExcepthook(ex_cls, ex, tb):
print("Oops! There's an Error.\n");
a=open("./ERR.txt","w"); #Fixed as suggested by unutbu BUT the problem is the…

NerdEngine
- 363
- 4
- 11
9
votes
2 answers
Python: Why does `sys.exit(msg)` called from a thread not print `msg` to stderr?
Today I ran against the fact, that sys.exit() called from a child-thread does not kill the main process. I did not know this before, and this is okay, but I needed long time to realize this. It would have saved much much time, if sys.exit(msg) would…

Dr. Jan-Philip Gehrcke
- 33,287
- 14
- 85
- 130
8
votes
2 answers
How to check if an argv refers to an existing file in python2.7?
I know how to check whether required arguments are given on the command line. But how do I check whether the given argument on the command line actually refers to an existing file in the folder I'm running the code in?
I'm trying to incorporate this…

Marlen
- 91
- 2
8
votes
2 answers
Call Python class methods from the command line
so I wrote some class in a Python script like:
#!/usr/bin/python
import sys
import csv
filepath = sys.argv[1]
class test(object):
def __init__(self, filepath):
self.filepath = filepath
def method(self):
list = []
…

JadenBlaine
- 275
- 1
- 3
- 13
8
votes
2 answers
Why is sys.getdefaultencoding() different from sys.stdout.encoding and how does this break Unicode strings?
I spent a few angry hours looking for the problem with Unicode strings that was broken down to something that Python (2.7) hides from me and I still don't understand. First, I tried to use u".." strings consistently in my code, but that resulted in…

Aleksandar Savkov
- 2,894
- 3
- 24
- 30