Questions tagged [sys]

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.

1100 questions
2
votes
1 answer

Is there a way to check what you are running a python program in?

I want to create a script for just Terminal and IDLE, but I don't know how. Using if 'idlelib' in sys.modules: works for seeing if it is running in IDLE, but is there a way to use the same code to find if it is in Terminal by replacing 'idlelib'?
EnderCodesLol
  • 79
  • 1
  • 1
  • 10
2
votes
0 answers

Why is 0.5 taking less memory than 1 in python?

I think I understand the concept of how python is storing variables and why certain vars are larger than others. I also googled about float point but that couldn't answer my question: Why is a float e.g. 0.5 is only taking 24 bytes of memory but a…
29thDay
  • 83
  • 1
  • 9
2
votes
1 answer

How is types.SimpleNamespace implemented?

I noticed the types.SimpleNamespace class seems to be recursively implemented. In the types module, the class is defined as type(sys.implementation). However, type(sys.implementation) simply returns types.SimpleNamespace, which wouldn't be possible,…
fluffyyboii
  • 635
  • 6
  • 15
2
votes
0 answers

I got 'EOFError: EOF when reading a line' in the execution of my Python code. How do I fix this?

I'm using Python3.8 to make a program that takes an input from the user with the help of sys.stdin. This is the code: import sys try: file = open(sys.argv[1], "r") source = file.read() file.close() except: source =…
FourPaws
  • 21
  • 1
2
votes
0 answers

multiple arguments with sys.stdin in python

I would like to run the python script where the input is taken from unix cat function but I also want to give it few additional arguments in sys.argv, it should run in the following way: cat my_fasta_sequence.txt | get_region.py 193 445 get_region…
Ekat Sim
  • 115
  • 6
2
votes
7 answers

How to change part of files names using Sys and Subprocess modules and Linux Bash

I have Python script which reads files names from oldFiles.txt, iterate through files names which are files in a Linux directory, then update the files names using string.replace and finally run a subprocess to find those files (let's say in home…
user13824946
2
votes
3 answers

Delete a specific folder with a path as a parameter in python

I want to delete a Folder named "testfolder" and all the subfolders and files in it. I want to give the "testfolder" path as a parameter when calling the python file. For example ...... (testfolder location) and there it should delete the…
noggy
  • 85
  • 2
  • 9
2
votes
1 answer

Passing dictionary arguments through command line and accessing them in a python script

I am trying to pass a dictionary consisting of arguments to a python script and later use that dictionary in the script. I am saving the dictionary in the environment variable of airflow. For example, the script should run on the command line…
Sarvesh Pandey
  • 322
  • 7
  • 17
2
votes
1 answer

Private package was created and pip installed but cannot import with python

I created a private package in TestPyPI The package has successfully pip installed: (base) my_user:Desktop$ python3 -m pip install --index-url https://test.pypi.org/simple/ --no-deps charter-common-utils==0.0.1 Looking in indexes:…
sanjayr
  • 1,679
  • 2
  • 20
  • 41
2
votes
1 answer

accessing python interpreter from a pyinstaller bundle #2

I'm trying to execute a python script which is included in datas, and bundled into a pyinstaller executable (on a mac). I need to pass parameters to this script, so I can't just exec(open(read()). Outside of pyinstaller, sys.executable is the python…
Jay Jay
  • 117
  • 1
  • 4
2
votes
3 answers

pyttsx3 not working on python 3.7 no module found

I am receiving the following error with the following code import speech_recognition as sr import pyttsx3 engine = pyttsx3.init() engine.runAndWait engine.say("Hello") Traceback (most recent call last): File…
Luis Carnero
  • 21
  • 1
  • 2
2
votes
2 answers

How do I resolve TypeError: '<' not supported between instances of 'int' and 'str'?

I am trying to use the following code to train Keras-I3D model from the following link: https://github.com/srijandas07/i3d. I have slightly modified the code, but I can get it work. imported modules are import os os.environ['KERAS_BACKEND'] =…
SanOlans
  • 93
  • 3
  • 14
2
votes
1 answer

Why is this longer list smaller than this shorter list?

Why is img_list smaller than compressed even though is…
2
votes
0 answers

Why does \r in the print function not rewrite the stdout but prints on the next line?

I'm working on a machine learning project, and I want to display the accuracy and progress of my model as a constantly updating statistic in the stdout. However, instead of updating the same line, the statistics are being printed on a new line after…
Farzad
  • 21
  • 2
2
votes
0 answers

How to fix "'subprocess.CalledProcessError"

I'm trying to open explorer based on the location of the imported file. The code runs but opens "documents" folder instead of the file path. subprocess.check_call(["explorer", path]). But, if I hard code instead of using path variable it gives me…
Nandan
  • 21
  • 4