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.
1,107
questions
0
votes
0
answers
8
views
Experiencing an error when trying to import from a diffrent directory
i am trying to import a function from another file
a/b/c.py
a/1/2.py
i wanted to import a funciton from c.py in 2.py
sys.path.insert(1, '/path/to/c/py/a/b/c')
from c import function1, function2
i ...
-3
votes
0
answers
40
views
How can I tell the OS or SYS packages where my directory is?
I'm trying to run someone else's code, and I don't know what this line does or how to get it to run on my machine (Windows):
sys.path.append(os.environ["CD_CODE_DIR"]
occurring after import ...
1
vote
0
answers
50
views
Why my code prints multiple same lines when it reaches the end of terminal?
import time
import sys
def animate_string(input_string, delay_second=0.01):
current_string = ""
for target_char in input_string:
if target_char == '\n':
# Print ...
0
votes
0
answers
26
views
How to resolve problem connection to oracle database using sys as sydba [closed]
I need your help to understund how is happends, Why I dont have connection to oracle database using sys as sysdba. I have client32 bit (because aplication is 32 bit), I have envirolment, TNS_ADMIN, ...
0
votes
0
answers
31
views
ValueError: dictionary update sequence element #0 has length 1; 2 is required While trying to get command line args in jinja2
I am trying to run this code :
import sys
from jinja2 import Template
vars = sys.argv
print(vars)
myTech = {
"mad 1": 'backend',
"mad 2": 'frontend'
}
temp = Template(&...
0
votes
1
answer
23
views
OSError: [WinError 10093] Either the application has not called WSAStartup, or WSAStartup failed
import sys
import select
print("Who is your best friend?")
print("You have ten seconds to answer!")
a, b, c = select.select([sys.stdin], [], [], 10)
if (a):
print("You stated ...
0
votes
1
answer
38
views
Import modules from a subfolder
I cannot import modules from a subfolder,where from a subfolder that I am in it;
the folders that I work with, is like this:
Project
__init__.py
/objects
__init__.py
button.py
...
0
votes
1
answer
43
views
Terminating a python program from within a try block [duplicate]
I have a python program that takes integer only inputs like this:
Valid = False
while not Valid:
try:
x = int(Input("enter integer value"))
Valid = True
except:
...
0
votes
3
answers
85
views
distance of a point from the lines that are contained in a list
I am making a python animation for a project in which, I am taking a star shaped boundary in which there are two balls which are moving inside that star. If the balls collide to other balls, a new ...
0
votes
0
answers
26
views
pandas not discoverable for different users on the same computer
I want to share my code with other users on a single computer to ensure a backup of automated procedures.
The python files are all there and everything appears to be in order, but when a secondary ...
1
vote
1
answer
56
views
Do comprehensions in python call a function in the background?
I defined the following factorial function using recursion :
def factorial(n):
if n == 0:
return n
else:
return n*factorial(n-1)
Then, I defined the following function to ...
2
votes
0
answers
71
views
What exactly is recursion depth in Python? [duplicate]
From my understanding, when a recursive function is executed in Python, a stack is created internally, containing the function's calls. I assumed that the recursion depth is the number of functions in ...
0
votes
2
answers
25
views
Importing classes from different module levels causes typehint and argument warning disabling
I have this file structure:
- package
- sub_package_1
- __init__.py
- sub_module_1.py
- sub_package_2
- __init__.py
- sub_module_2.py
In sub_module_1.py we have this code:
...
0
votes
3
answers
99
views
How to output and log messages at the same time in python
I want something like what the tee command does in Linux based systems, but in pure python code.
I have tried using this snippet:
import sys
# Define the file name for logging
log_file_name = 'output....
0
votes
0
answers
33
views
Directory issue: Module not Found
I'm trying to import two modules in a main.py file. The file structure is like this
|Common-Folder
|
|
|__Folder
| |___main.py
|
|
|__Tools(folder)
| |___models
| |___maze
inside main, I do
import ...
0
votes
0
answers
46
views
Why does running this python program from Terminal fail? [duplicate]
So, I wrote a basic script:
import sys
if len(sys.argv) != 3:
print(0)
else:
arg1 = int(sys.argv[1])
arg2 = int(sys.argv[2])
print(arg1 + arg2)
But when I try to do python3 test.py 1 ...
0
votes
0
answers
52
views
Get current console output(sys.stdin) in python
I want to get the current console output(sys.stdin) of my program in python. I found the answer for sys.stdout, however, I found out for the output caused by input() function it goes to sys.stdin ...
0
votes
0
answers
24
views
byte size information using sys and pympler
I am using the pandas library to import a dataset. I split the dataset into X and y variables. I preprocessed X through a pipeline and have the X_data variable. Later, I am using XGBoost and RF models ...
0
votes
1
answer
331
views
add multiple directory-paths to $PYTHONPATH (Git-Bash in Windows)
I want to add multiple paths (A,B) to the PYTHONPATH environment variable in Windows every time I launch a Git Bash. Python should draw it's dependencies from path A and B in addition to the ...
-1
votes
1
answer
62
views
Python program works with test cases but PyTest fails. How can I understand the issue?
I am new to Python and PyTest. I wrote a program that calculates the lines of code from another Python file. The source code is the following:
import os.path
import sys
def main():
print(...
0
votes
1
answer
93
views
Getting unexpected sys.argv when running script as a module
test.py:
import sys
print(sys.executable, [sys.executable] + sys.argv)
Running normally:
C:\Program Files\Python\Python311\python.exe ['C:\\Program Files\\Python\\Python311\\python.exe', 'test.py']
...
2
votes
1
answer
96
views
Where is the sys module located, or how to find it in Win 11 & Python
Does anyone know how to find where the sys module is installed in a Windows 11 install of anaconda3 & Python? I've tried looking in the Lib folder already and although there is a file called sys....
1
vote
0
answers
81
views
How can I modify `sys.path` before python interpreter initializes using Python/C API?
From the official example, I understand that I can modify sys.path before the interpreter initializes using the following code(exception handlings are omitted):
PyConfig config;
...
0
votes
0
answers
40
views
I get the error IndexError: list index out of range [duplicate]
I am trying to use the following code in a python script and line 7 produces the error
import numpy as np
import pandas as pd
from astropy.io import fits
import os
import sys
datafile_dir = r'C:\Users\...
0
votes
2
answers
120
views
(How) is it true that the write() syscall stores data in the kernel?
In this stackoverflow question answer it is said that after sys call returns the data is in kernel. But isn't data output to the display and no more in kernel? Can someone explain in more detail? I ...
0
votes
0
answers
92
views
The group of gpio is reset after reboot the Orangepi 5 plus
I am using OrangePi 5 plus and followed the answer in this link text, the group is changed to gpio, which contains my local user, but after reboot the group is reset to root. how can I permanently ...
1
vote
1
answer
108
views
import a class from a file from another folder
I have recently started working with Selenium and the page object model, the program works fine if I don't divide the files into folders class-tests_scripts. the flow of the program looks like this:
\...
1
vote
2
answers
93
views
Typewriter Effect on a list
I am making the base of a game, and for the intro, I need it to print out like a typewriter. When I call it as multiple, it prints out the whole object, rather than slowly printing it out, like a ...
0
votes
1
answer
198
views
Problem deleting files/folders using Python
Now I'm sitting and making a Python program to clean up junk on my PC. And everything would be fine, but one problem appeared.
The fact is that I cannot delete files from the “Temp” folder of my ...
0
votes
1
answer
254
views
How to import dependencies from other folder?
I have to folders A and B. In folder A is my main.py. In folder B there are a few classes in different scripts: B1.py, B2.py, B3.py…
I want to import a class from B1.py. I got that to work with sys....
0
votes
2
answers
54
views
Python import from another folder
I made this structure as an example:
application
| main.py
├── folder
├── __init__.py
└── file.py
when I want to import something in main.py from file.py, I can simply do
from folder.file ...
2
votes
0
answers
107
views
sys.setrecursionlimit() and recursion in python
I don't understand why the code is running 170 times instead of using the sys function by setting its limit to 200.
import sys
i=0
def fun1():
global i
print("hello i = ",i)
i+=1
...
0
votes
1
answer
119
views
`sys.dont_write_bytecode` not working if I just import the function instead of the whole sys library
I'm trying to delete the __pycache__ folder for importing modules and if I:
from sys import dont_write_bytecode
dont_write_bytecode = True
import folder.modulename as modulename
the folder still ...
0
votes
0
answers
38
views
Communicating between 2 python processes by changing sys.stdout variable
I already soved this but am not feeling good about the solution I came up with.
Here is the Issue:
I created a command line utility that works fine.
eg: my main.py file is
def Parser():
...
0
votes
1
answer
95
views
In python how to pass a variable to the command line?
I have a function that I use something like that:
def func(file_path):
!python some_script.py --par file_path
func('/some/file/path/file.csv')
This obviously results in an error message, because ...
0
votes
0
answers
39
views
Why is it impossible to pass the string "curve?" to a python script using sys.argv
First time poster, long time googler.
Ok, I have a workaround for this but, for the life of me, I can't figure out why this is happening.
import sys
print(sys.argv)
This will not print "curve?&...
0
votes
1
answer
144
views
Why can't python suddenly not run functions from imported modules?
I have some weird problems with python, and I don't know how to fix it.
For the following code:
df = pd.DataFrame.from_dict(mydict)
I get the error:
AttributeError: module 'pandas' has no attribute '...
0
votes
1
answer
39
views
how do i access both my file using sys.argv?
I sent two files on sys path.
Below is my code:
arr = [filename1.csv,filename2.csv]
for i in arr:
sys.stdout.write(i + '\n')
but when I try to access it with sys.argv[1:], it only returns me last ...
-2
votes
1
answer
390
views
Import sys and sys.argv Not Responsive in VS Code Terminal [duplicate]
Edit(07/08/2023)
I'm new to coding and was using the terminal/code wrong and did not understand what I was doing wrong. Resolved now and learnt the lesson.
If you find yourself in a similar position, ...
0
votes
1
answer
26
views
Importing functions from different packet
I'm studying PCAP certificate and I have one question about how import functions from other packets whose location is different to the current directory.
Theory says that I have to do the next code:
...
0
votes
2
answers
53
views
handleExit() function not working correctly
I'm basically trying to code a C2 server to learn about python networking and actually python basics.
I come from C and Java and I dont really know python best practices lol, I know that i'm running ...
0
votes
4
answers
105
views
Missing 3 required positional argument with sys.argv[]
I have a problem with a python script I call from a Jenkins pipeline.
In the main script I have this:
import sys
authentication = sys.argv[1]
style = sys.argv[2]
ip = sys.argv[3]
accounting = sys....
0
votes
0
answers
64
views
Why is my thread still alive and how do I terminate it?
So I previously had the same problem but I somehow fixed it. Now that I have started using Tkinter to display my output(Previously I just used the terminal) I have run into it again. I tried ...
0
votes
0
answers
34
views
Is there a way to rename/move a file at the conclusion (no matter the reason for exit) of a Python script running?
Working within Ubuntu 22.04 and Python 3.9.13 within VSCode 1.80.1.
I have a Python script set up to stream data from an API 'in perpetuity'.
As part of this, I create a CSV file to which I save all ...
2
votes
3
answers
57
views
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():
...
-1
votes
1
answer
149
views
Error regarding subprocess install in python
import sys
import subprocess
subprocess.check_call([sys.executable, '-m', 'pip', 'install', openpyxl])
import openpyxl
I am trying to install openpyxl using subprocess and sys module, but get error ...
0
votes
0
answers
31
views
How to get the current line from python's subprocess module
I am trying to accomplish a pseudo console with python's subprocess module for my web app.
The point of the webapp is to be able to run and interact with python code via the web.
I have a simple test....
0
votes
1
answer
112
views
value of len(sys.argv)'s posing problems
So I'm trying to use the value of sys.argv to get a font for the input to be printed in. But sys.argv's value remains 1 no matter how many values I type in the terminal.
the first if works great, but ...
1
vote
0
answers
29
views
my sys.argv[1] is not receiving value from my php
ive been trying to pass value from my php to python to save to my database but my sys.argv[1] is not receiving any value.
import firebase_admin
from firebase_admin import credentials, db
import mysql....
0
votes
1
answer
284
views
python cannot import class, path variable shown defaults to anaconda?
my file directory is simple:
/Users/dd/python/folder/
main.py
store.py
__init__.py
# store.py
class Store:
def __init__(self,location):
self.location = location
# main.py
from ...