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
2 answers

How do I fix argv[1] in Python?

I have a problem with argv[1] in Python 3.8.2. This is my code: from sys import * def open_file(filename): print(filename) def run(): open_file(argv[1]) run() And it shows error: Traceback (most recent call last): File "*File*", line…
-2
votes
1 answer

fins and move files with path name with python3

I am trying recreate python script from my perl script to find all files with common name model1_r.pdb and them move it to a new folder with newname of their previous existing folder. This is the python code I wrote; import os, shutil, glob # This…
Kay
  • 90
  • 8
-2
votes
2 answers

Convert JPG to PNG

I have used the below code to convert JPG into PNG file: But when i am running this code from the command line terminal using: python a.py "C:\Users\nishant.gupta2\PycharmProjects\jpgtopngconverter\photo" new The system is giving me the error: …
nishant gupta
  • 15
  • 1
  • 4
-2
votes
1 answer

How to ignore an error and not stop the script?

I have a working script (Powered by Python 2.7) : import sys a=0 b=7 p=0xB12D x2=0x38F if (len(sys.argv)>1): x1=int(sys.argv[1]) if (len(sys.argv)>2): x2=int(sys.argv[2]) if (len(sys.argv)>3): p=int(sys.argv[3]) if…
Rozwrcd
  • 11
  • 3
-2
votes
3 answers

How to store while loop produced string into variable

I want to store all the "o"'s printed by stdout.write function into a a variable which could be accesable any time I have tried using len function to break loop once it reaches certain amount of strings, but no luck import time import sys while…
-2
votes
1 answer

Is there any way to iterate over a list of input files in python?

I am trying to create a script that will do a certain iteration over a list of input files. In my case, I will have for example 3 files with a sequence of amino acids and I want to create 1 output file for each of the files. The problem I have now…
-2
votes
2 answers

python read lines in functional way

I need to write a program in a functional way. I have a text and I need to calculate a number of unique words, (for example: "word word, word word?" - has 3 different words, punctuation matters. I have a code: import sys import…
L.Bond
  • 37
  • 6
-2
votes
1 answer

Script loading data file from command prompt

Kinda new to this, and writing a script that loads in latitudes and longitudes from a CSV file and converts the formatting for another program to read...finally got it all to work. I was wondering how I might set this up so I could maybe run…
tarnis
  • 1
  • 3
-2
votes
1 answer

Sys arguments with while

The lines in the files will be top to bottom (one under the other) I have 2 ".txt" file like this : #john.txt hello my name is John #jack.txt second one is like that: hello your name is Jack I will compare this texts line by line but the…
Aybar Taş
  • 15
  • 1
  • 7
-2
votes
2 answers

fileku.write(sys.argv[i+3]+'\n') IndexError: list index out of range

i'm still new in python,i want to create a program that can read/write/append text file depending on the command line argument. here is my code : import sys def prosesfile(): fileku=open(sys.argv[1],sys.argv[2]) if(sys.argv[2] ==…
Cakra1337
  • 23
  • 4
-2
votes
1 answer

sys.argv : index out of range

I try to run this code import sys import numpy as np filename = sys.argv[1] X = [] y = [] with open(filename, 'r') as f: for line in f.readlines(): xt, yt = [float(i) for i in line.split(',')] X.append(xt) …
Hoda Fakharzadeh
  • 697
  • 3
  • 7
  • 18
-2
votes
2 answers

Why am I getting IndexError in this small python code?

Here is the code.Please help me correct it. #!/usr/bin/env python import sys def print5times(line_to_print): for count in range(0,5) : print line_to_print print5times(sys.argv[1]) when running this code i am getting this…
faust_
  • 17
  • 5
-2
votes
2 answers

What does this code concerning sys.args mean?

What does the following chunk of code mean? I don't understand the concept of sys.argv. I heard it has something to do with command-line prompts but my vocabulary isn't good enough to understand that. Also the output is strange. I don't understand…
HAMZAH AHMED
  • 159
  • 5
-2
votes
4 answers

Replacing sys.argv with docopt

I'm working on incorporating some string replacements and currently arguments are passed to my script using sys.argv[i]. I'd like to replace sys with docopt, but I've found the documentation relatively unclear so far. The way my code currently works…
PhysicistAbroad
  • 185
  • 1
  • 8
-2
votes
1 answer

Handling command-line arguments in Python

I am trying to get parameters from the command line to initialize the following class import sys class Test(object): def __init__(self): for item in sys.argv: if item.startswith("-Username"): self.Username…
Sepehr
  • 442
  • 1
  • 6
  • 17