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
1
vote
1 answer

How to get terminal print out when some print out are from exe file

I want to ask a question how to read all print out data in terminal in real time, which means that when the data is printed out in terminal, it's saved in text file synchronously. The python code is like: def exe_run(): os.system(r'"test.exe"') …
Doris
  • 63
  • 4
1
vote
0 answers

How to reload **builtin** module sys in python?

This is a theoretical or experimental question. I am searching for generality here. "Does a method apply to every possible appliable object?" I recently asked about how to reload builtin-modules. Here is the result so far : link As far as I know, we…
KH Kim
  • 1,155
  • 1
  • 7
  • 14
1
vote
1 answer

Adding python module from different folder

I have my application folder with my main.py and a lib folder with some modules: LeapMotionInterpreter --> DataExtractor.py lib --> Leap.py I've already looked at how to do this and they all say to use…
Win Barua
  • 131
  • 1
  • 1
  • 5
1
vote
2 answers

Doing print("Enter text: ", end="") sys.stdin.readline() does not work properly in Python-3

Something weird happened when i did this import sys print("Enter text: ", end="") sys.stdin.readline() Output: Enter text: (Here, (excluding quotation marks means that input happened on that line)) Why does the code run as though…
user15930270
1
vote
1 answer

Python unittest: How to raise IndexError for sys.argv?

I am trying to test the case where the number of parameters in the script being executed is less than three. When debugging, I see that an IndexError occurs, but for some reason assertRaises does not "see" it. Can anyone help fix…
ibarbylev
  • 67
  • 8
1
vote
1 answer

sudo and permission issues getting me crazy

I have defined a bash script to prepare gpio27 for setting it to 0 or 1 through additional scripts on a RaspberryPi Zero 2 with Buster installed. The script is the following one: #!/bin/bash echo "27" > /sys/class/gpio/export echo "out" >…
jivaro
  • 41
  • 4
1
vote
1 answer

How to check if not one but any Popen subprocess at all is still running?

I know there is the possibility to check if a subprocess is still running with .poll(). So for example: p = subprocess.Popen(... """ A None value indicates that the process hasn't terminated yet. """ poll = p.poll() if poll is None: # p.subprocess…
Gordian
  • 101
  • 8
1
vote
1 answer

Redirect console output to a file with errors python

Apologies if this has been answered before. I am trying to redirect my console output to a "log" file that includes any error messages. Currently I am able to send my print statements to a file using sys.stdout = open(r'mydir\Log.txt', 'w') My…
1
vote
3 answers

Passing variable name as command line arguments in python

I want the user to enter the arguments using command line with variable names in the command line itself. For example, python test.py a=10 b=20 The code should be able to use a=10 and b=10 wherever needed. I am able to achieve python test.py 10 20…
A. Gehani
  • 83
  • 7
1
vote
1 answer

python TypeError using sys.stdout.write for array element values

I have a print statement in Python that shows the value and length of elements in an array. I then need to do the same thing using sys.stdout.write instead of print, however am getting the below error. The original code using print: import sys words…
Merla
  • 23
  • 5
1
vote
1 answer

Imported sys module successfully but sys not defined (ATOM IDE)

I am a new Atom user. I am trying to set a higher recursion limit by using sys.setrecursionlimit(). Here is my code: import sys sys.setrecursionlimit(10**6) I ran the code line by line and sys was successfully imported. However, the second line…
Tim
  • 23
  • 4
1
vote
1 answer

open image files from window explorer using python code

i recently just took up python for my research studentship (so i don't have a very strong cs background). I'm dealing with a large set of image files in many different subfolders in a big folder so I want to build a python code to search and open…
Matcha38
  • 11
  • 1
1
vote
2 answers

python capture sys.stdout and sys.exit produced by other module

I have two scripts as below but I can not modify foo.py I have wrote code in bar.py to capture output produced by foo.py so I can modify the output before outputting it to terminal. But, capture does not work. What am I doing…
Dariusz Krynicki
  • 2,544
  • 1
  • 22
  • 47
1
vote
1 answer

Fatal Python error: Py_Initialize: can't initialize sys standard streams

I have a pyproject.toml file that was created using poetry, and I'm trying to run the command poetry install in this directory to create a poetry.lock file. However, when I run poetry install, I get the following error: EnvCommandError Command…
mmarion
  • 859
  • 8
  • 20
1
vote
0 answers

Why child process inherit parent process's sys.modules in python program on linux?

Background: I try to run a subprocess by Process,and use os.setuid to limit child process's authority. What I want to limit is : do not read file on disk by linux user authority control; through 1,limit child process load customize part,such as…
lanhao945
  • 427
  • 5
  • 21