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

Python use sys.argv in a function to read a filename

I have a function that takes in and reads a csv file such that when i can type python myscript.py filename.csv to run my script. Below is my function : def read(sys.argv[1]): ... ... However i get this error: File "myscript.py", line 6 def…
jxn
  • 7,685
  • 28
  • 90
  • 172
-3
votes
1 answer

Writing to file with sys.stdout in python

ascii85.encode(file('/work/file1'), sys.write('/work/file2') I am trying to write to a file with this code using sys.stdout, but it is not writing. How do I fix the code to write to a file?
sophanox
  • 39
  • 1
  • 1
  • 3
-3
votes
1 answer

How does if __name__ == '__main__': takes file path

I have written a driver code to take file path from user and use that file path in my functions. Driver code is as below; import sys if __name__ == '__main__': if len(sys.argv) != 2: print("Usage: %s input_file" % sys.argv[0]) …
svn_21
  • 17
  • 6
-3
votes
2 answers

how to run exe file and type arguments from python

I have an executable external program that ask the name of the arguments file. I am trying to program this action through python coding. How can it be done?
jmparejaz
  • 160
  • 1
  • 14
-3
votes
1 answer

Output strings into command line from Python script

I am currently working on an automation task. I have arrived at a part of the script where I need confirmation from the user to continue. For example the script is automatically entering some values in Selenium for the user however I need…
gold_cy
  • 13,648
  • 3
  • 23
  • 45
-3
votes
3 answers

Invalid literal for int() with base 10: ' ', reading off text file

Im trying to make a text game/rpg in python. Im getting an line 89, in surv = int(statload.readline(3)) ValueError: invalid literal for int() with base 10: '' error code, when trying to read off a file. the other ones around it read…
moogypoog
  • 1
  • 4
-3
votes
1 answer

python add http:// to url open sys args

Very new to python, I'm trying to take in a command line argument which is a website and set it to a variable. I use the line below to do this. sitefile = ur.urlopen(sys.argv[1]) The problem is it only works when formatted perfectly in the command…
KM617
  • 137
  • 1
  • 3
  • 16
-3
votes
2 answers

How do I choose over two python functions on terminal using sys and not argparse?

I've two functions, and I want to choose function message() or function number() on a UNIX terminal. This example I define the function will be used inside if __name__ == "__main__":: import sys def message(m=sys.argv[2]): print(" {}…
Shapi
  • 5,493
  • 4
  • 28
  • 39
-3
votes
1 answer

How to get input of arguments from the terminal along with the filename in python?

For example if I want to compare two numbers(compare which is greater, for example) and get this input from the terminal in linux along with the filename. Like: python myfilename.py 2 3 This program should output 3. I think that this can be done…
Sahil Babbar
  • 143
  • 1
  • 2
  • 8
-4
votes
1 answer

Using Python, why would sys.exit(0) hang, and not properly close a program?

The bug I am running into is that sys.exit(0) is not properly closing my program. I use pyinstaller to make this program an exe. When I use the exe, the program has to be shutdown using task manager. (I am running the program on a Windows 10…
Cemos121
  • 31
  • 4
-4
votes
1 answer

Running a program using subprocess in Python

I am trying to run the program 220_beta_1e-2_47_53ND.py using subprocess.run(). But the program doesn't run. Can somebody please help? import subprocess import sys subprocess.run(['python3.9.7 220_beta_1e-2_47_53ND.py'],shell=True)
user19862793
  • 169
  • 6
-4
votes
1 answer

How can I terminate Python Script with particular 'if' conditions that does not affect Tkinter GUI?

I have created GUI using Tkinter and one main script to run. I have some conditions in the main script. if conditions are not satisfied I want to terminate the further execution but keep the GUI active and open. Currently I am using sys.exit() to…
Vi_py123
  • 73
  • 1
  • 9
-4
votes
1 answer

First time Domain Hosting in the AWS directly

I have Domain which i purchased from the Domain.google Zeta and now i am trying to make it as live Domain by using the AWS instance and i have EC2 instance can you help me out with the procedure to some sample .
-4
votes
1 answer

Issue with parsing json files

I have a problem with the fonction. The fonction does not give me the right information I have this I look for this information…
hideyoshi
  • 37
  • 1
  • 7
-4
votes
1 answer

Command line arguments, sys.argv

I am reading Learn Python the Hard Way (3rd Ed.) and there is an exercise I was trying, but I am just unable to get it; the arguments and parameters stuff (Exercise 13). I've read other answers on the site for the same question, but my doubts…
sunp
  • 21
  • 6
1 2 3
73
74