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

Python will not read sys.argv

import sys print sys.argv[1] hi, this may seem very basic but I can't get Python to read in anything from the command line. thats the code above and what I type is: myfile.py helloworld and what i get back is: IndexError: list…
user1024028
  • 73
  • 1
  • 1
  • 3
7
votes
2 answers

Passing arguments to an entry point python script using argparser

I am looking to pass a user entered arguments from the command line to an entry point for a python script. Thus far I have tried to used argparse to pass the arguments from the command line to the test.py script. When I try to pass the arguments…
steve2020
  • 332
  • 2
  • 9
7
votes
1 answer

Sys.path.insert inserts path to module but imports are not working

I want to import a module in a project and it gives me lots of troubles because of an import error. So I decided to write a little test to see where the problem lies. I add a folder to my sys path and try to import it. And I get an Import Error: no…
Micromegas
  • 1,499
  • 2
  • 20
  • 49
7
votes
3 answers

python: sys.argv[0] meaning in official documentation

Quoting from docs.python.org: "sys.argv The list of command line arguments passed to a Python script. argv[0] is the script name (it is operating system dependent whether this is a full pathname or not). If the command was executed using the -c…
kynikos
  • 1,152
  • 4
  • 14
  • 25
7
votes
1 answer

Print all argparse arguments including defaults

I want to log the usage of a python program which uses the argparse module. Currently, the logger records the command line usage similar to the answer given in this post. However, that only gives the command line arguments, and not including the…
NWaters
  • 1,163
  • 1
  • 15
  • 27
7
votes
1 answer

Selenium: Quit Python script without closing browser

I use the following to handle the situation where Ctrl + C is used to terminate a running Python script. except KeyboardInterrupt: print "ABORTED" However, this also terminates my Selenium WebDriver browser. Is there a way to terminate the…
P A N
  • 5,642
  • 15
  • 52
  • 103
7
votes
1 answer

Python sys.stdin throws a UnicodeDecodeError

I'm trying to write a (very) basic web crawler using cURL and Python's BeautifulSoup library (since this is much easier to understand than GNU awk and a mess of regular expressions). Currently, I'm trying to pipe the contents of a webpage to the…
Charles German
  • 857
  • 10
  • 16
7
votes
5 answers

How to use sys.argv in python to check length of arguments so it can run as script?

Ok so here is part of my code (I have imported sys) if __name__ == '__main__': MyCaesarCipher = CaesarCipher() #MyCaesarCipher IS a CaesarCipher() if len(sys.argv) >1: #what will it check? Done = False while not Done: print('C Clear…
Elsa
  • 307
  • 1
  • 3
  • 12
7
votes
2 answers

Try and Except catch all errors, except for sys.exit()

I have created a function, but errors could pop up. That is why I want to use exceptions to generalize all errors into the same message. However, this function contains multiple sys.exit() calls. As a result, I would like to have my code jump into…
James the Great
  • 941
  • 2
  • 14
  • 46
7
votes
3 answers

IPython sys.path different from python sys.path

I generally use IPython and only recently noticed that the the search path for imports is wrong in the regular python shell. From what I understand, sys.path inherits from PYTHONPATH (although I don't know where PYTHONPATH lives), is this different…
paulsef11
  • 628
  • 1
  • 8
  • 11
7
votes
2 answers

Why are the methods sys.exit(), exit(), raise SystemExit not working?

I need an alternative to kill the python script while inside a thread function. My intention is killing the server when the client enters a 0... Is this not working because the threads haven't been terminated? Here is my code: socket =…
CS Gamer
  • 225
  • 1
  • 3
  • 12
7
votes
2 answers

Python 2.7: reload(sys) disables error messages and print in Windows

I'm making a script that requires me to change the encoding format to "UTF-8". I found a topic here on Stachoverflow that said i could use: import sys reload(sys) sys.setdefaultencoding('utf-8') It works great in OSX 10.8 (maybe earlier versions…
Mads Y
  • 342
  • 1
  • 4
  • 12
6
votes
2 answers

sys.path and sys.executable is incorrect in jupyter, but no applied fix is working

I've configured jupyter to be used from a remote computer and set a password to it while initial anaconda setup. Then after fixing this issue, I am trapped in another one. sys.path and sys.executable is incorrect in jupyter, but correct in python…
thepunitsingh
  • 713
  • 1
  • 12
  • 30
6
votes
1 answer

How does sys.executable determine the interpreter path?

I've installed python on mac with homebrew. Some tools (pipenv for example) have some troubles because they try to write to /lib/python3.7/site-packages/, not permitted under mac. After some investigation I found that they start a new python…
MrTJ
  • 13,064
  • 4
  • 41
  • 63
6
votes
7 answers

How to delete all tables from db? Cannot delete from sys.tables

How can I perform this query on whatever way: delete from sys.tables where is_ms_shipped = 0 What happened is, I executed a very large query and I forgot to put USE directive on top of it, now I got a zillion tables on my master db, and don't want…
Shimmy Weitzhandler
  • 101,809
  • 122
  • 424
  • 632