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
3 answers
How do I terminate the script once 'q' is pressed?
Below is a complete script I am trying to automate the process of pinging multiple routers and to do that every 2 hrs but I also want the ability to terminate it at any given time.
def start():
for file_name in file_list:
unrechable =…

Sahil Jain
- 21
- 6
2
votes
1 answer
How do I remove the white space in a python code?
I'm using the following code:
import time
import sys
def delay_print(s):
for c in s:
sys.stdout.write(c)
sys.stdout.flush()
time.sleep(0.25)
def Loading():
load = int(10)
while load != 0:
delay_print("...\r \r")
load =…

oscar
- 47
- 1
- 6
2
votes
2 answers
Include sys.stderr in a Pyinstaller project
One of the subdependencies of my project is transformers. This only happened when I upgraded transformers from 4.16.0 to the latest version 4.25.1. When I try to compile the project with pyinstaller I get the following error:
Traceback (most recent…

chiai-fuka
- 21
- 3
2
votes
3 answers
Running Another program from python
I want to call a program multiple times from a python code, and save the output of that program in a text file. My first problem right now is just calling the other code. I have to redirect to a different directory and call ./rank on output.txt.…

Sheerberenj
- 155
- 2
- 8
2
votes
2 answers
When I append a path, python gives an error
I tried to add a directory path to sys.path, but it gives me an error:
import sys
sys.path.append("C:\Users\tamer\Desktop\code\python\modules")
SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated…

mostafa ghobashy
- 23
- 2
2
votes
1 answer
How to uninstall a .exe from a python script
Hello I can't get an app to self uninstall. After converting a .py script to .exe when I press the button it is supposed to delete/uninstall itself from my computer.
Actually I would like it to uninstall completely from my computer after pressing…

Meme410
- 113
- 9
2
votes
3 answers
How to add a try & except construct so that the script ignores that there is no file
I don't really know the Python language, so I'm asking for help from experts. I have a simple script and I need to add a construct to it
try:
except:
this is necessary so that the script ignores that there is no 'file.txt' file and does not display…

Dew Debra
- 47
- 5
2
votes
1 answer
Python - How to find the average height of presidents from selected row numbers?
I am new to Python and trying to figure out how to pass two arguments that will correspond to the start and stop of a slice, respectively. It will slice the heights column in a csv file with president height.
Then print the average height, rounded…

MCly
- 105
- 7
2
votes
1 answer
How to return status code in Python without actually exiting the process?
I'm trying to return a status code without exiting the process of my script. Is there an equivalent to sys.exit() that does not stop execution ?
What I'd like to happen :
If no exception is raised, status code is by default 0. For minor exceptions,…

junsuzuki
- 100
- 7
2
votes
2 answers
How to pass a string variable from shell script to python with sys.argv?
I would like to pass a string variable from a Shell Script to my python script and have it stored in sys.argv[1].
Currently, this is my situation:
main.sh
TEST="This is a test"
python main.py $TEST
main.py
if __name__ == '__main__':
…

Hoxlegion
- 277
- 1
- 3
- 14
2
votes
2 answers
Create directory when it does not exist
I want to create a new directory if it doesn't exist already.
Tried several things, sadly I didn't find something in the Sys Library.
The nearest solution I got was:
if not (Sys.is_directory "vegetables") then Sys.mkdir "vegetabels"
Which obviously…

col.ulb
- 43
- 5
2
votes
0 answers
Running Streamlit based app as a package (
Apologies is this question is not clear enough - let me know and I can provide further details.
I've packaged up a Streamlit based app for a personal project. I've successfully deployed it on TestPyPi. I can install the package on a new environment/…

tristar8
- 75
- 7
2
votes
1 answer
How to send email alert through python if a string is found in a csv file?
im new to python and trying to understand how to send email alerts. I have a csv file, the below is the dataframe for…
user12309736
2
votes
2 answers
How do I stop Python's Sys module's "stdout" and "stderr" write method from returning the numbers of characters written
whenever I use the write method from the stdout or stderr object in Python's built-in "sys" module in Python with the Python interpreter, the method also prints an integer representing the number of characters there are in the string after the…

Marco El-Korashy
- 181
- 1
- 9
2
votes
2 answers
Python: Counting words from a directory of txt files and writing word counts to a separate txt file
New to Python and I'm trying to count the words in a directory of text files and write the output to a separate text file. However, I want to specify conditions. So if word count is > 0 is would like to write the count and file path to one file and…

JohnD
- 121
- 1
- 9