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
1 answer
sys.getsizeof() value doesn't increase with increase of float value
While playing around with sys.getsizeof(), I noticed that it returns higher values for ints as their magnitude grows, signifying that they use more memory:
>>> sys.getsizeof(3)
28
>>>
>>> sys.getsizeof(300000000000000000000000)
36
However with…

Moondra
- 4,399
- 9
- 46
- 104
2
votes
1 answer
How to capture sys.exit() from subprocesses in Python?
I've created a master.py to kick off other scripts.
from subprocess import PIPE, STDOUT, run
def main():
command = ["python3", "file1.py"]
print("Executing: {}".format(command))
exit_code, output_string = run_command(command)
…

wrx96
- 29
- 3
2
votes
2 answers
How to nest script that inputs variable for automation purposes?
I'm creating a python script (cmd_exec.py) to open another python script (entername.py). How do I nest it so the script inputs string and execute the enter button all automatically? Trying to remember the question about ASCII input code for enter,…

Antonow297296
- 317
- 1
- 4
- 12
2
votes
2 answers
How do I execute functions via sys.argv
I'm very new to coding (started 2 days ago) and for practice a friend gave me the task of writing a program that provides either the nth Fibonacci number or the sequence up to the nth point. I successfully completed that task using input() and…

Jens Wagner
- 21
- 2
2
votes
3 answers
Avoid export PYTHONPATH every time for __init__.py to work
`-- MyDir
|-- FolderA
| |-- __init__.py
| |-- ScriptA.py
`-- FolderB
|-- __init__.py
|-- ScriptB.py
The above is an example of my current structure. In both FolderA and FolderB, there are .from FolderX import * in __init__.py, X is A or…

Francis
- 6,416
- 5
- 24
- 32
2
votes
2 answers
Check if method is imported, from X import Y
In Python 3.7 I would like to import few methos and use them later in the same script. Before that I would like to check if they are correctly imported.
Based on this answer I can check if a module is fully imported into the script but how if I…

Nicolaesse
- 2,554
- 12
- 46
- 71
2
votes
1 answer
Calling Sys.argv in Print Command in Python
I am a beginner programmer and i can't get this. Trying to print Sys.argv. I have the PRINT command set in script which should call sys.argv.
how do i run : python test.py device1
what i have tried :
print ('please Check' + sys.argv[1]_config.txt…

Nirmal Gauda
- 43
- 8
2
votes
1 answer
How do I trace all functions calls and args automatically?
For the purpose of building a specialized debugger for my code I would like to trace some of the functions in my code, and to log the arguments they received in each call.
I would like to be able to do this without adding line of code to each…

Oren Matar
- 651
- 4
- 11
2
votes
1 answer
Ignore comma in quotes when using json.loads() / Python?
currently working with the below command:
python foo.py "['A,B,C,D','A,B,C','A,B','A']"
And I want to transform it into an actual string array:
A[0] = 'A,B,C,D'
A[1] = 'A,B,C'
A[2] = 'A,B'
A[3] = 'A'
At the moment, I've been trying to use…

Chloe Bennett
- 901
- 2
- 10
- 23
2
votes
2 answers
Python - script hangs on open() function
I have a Python script that first kills all hostapd processes then starts a fresh one. I want to capture the output of the hostapd start command to determine if it returns AP-ENABLED or AP-DISABLED so I decided to write it to a temporary file then…

ChumiestBucket
- 868
- 4
- 22
- 51
2
votes
1 answer
Why does `sys.stderr` and `sys.stdout` put a number at the end on the shell, but not in a module - python
Basically my question is the title,
so for example in shell:
>>> import sys
>>> sys.stdout.write('Hello')
Hello5
(same with stderr)
But from a file:
import sys
sys.stdout.write('Hello')
Output:
Hello
(same with stderr)
So why is this happening???

U13-Forward
- 69,221
- 14
- 89
- 114
2
votes
1 answer
How to build a 'cascading' CLI tool using system arguments?
Here is my sample code:
def function1():
parser = argparse.ArgumentParser(description='Test Cascading Utility')
parser.add_argument('--number', type=str, help='Enter number')
args = parser.parse_args()
x = str(args.number)
…

TheTank
- 495
- 2
- 9
- 21
2
votes
0 answers
Code which checks file size of video using download link before downloading? [edited]
I was reading the book 'Automating the boring stuff with python' where I read about webbrowser module. I tried to make a program that downloads a given number of videos from the web. But since Chrome starts multiple downloads simultaneously, I…

Shohan Dutta Roy
- 125
- 7
2
votes
1 answer
How to resolve "ValueError: attempted relative import beyond top-level package"
I have the following problem with my project, help me please! Here is the structure of my package:
/pkg
/pkg/__init__.py
/pkg/sub1/__init__.py
/pkg/sub2/__init__.py
/pkg/sub1/foo1.py
/pkg/sub2/foo2.py
Here is implementation of foo1.py:
from…

Alex Rozhnov
- 199
- 3
- 12
2
votes
2 answers
Using Script = argv in Python3
I'm playing around with Python3 and every time I run the code Python3 ex14.py below and I print the (f"Hi {user_name}, I'm the {script} script.") I get the {user_name} right but the {script} shows the file I'm running plus the variable…

A Sanz
- 47
- 9