sys

Why should we NOT use sys.setdefaultencoding("utf-8") in a py script?

Why should we NOT use sys.setdefaultencoding("utf-8") in a py script? Question: I have seen few py scripts which use this at the top of the script. In what cases one should use it? import sys reload(sys) sys.setdefaultencoding(“utf-8”) Asked By: mlzboy || Source Answers: As per the documentation: This allows you to switch from the default …

Total answers: 4

Problem with sys.argv[1] when unittest module is in a script

Problem with sys.argv[1] when unittest module is in a script Question: I have a script that does various things and access parameters using sys.argv but when the script gets to the unittest part of the code it says there is no module for this. The script that I have is: class MyScript(): def __init__(self): self.value …

Total answers: 4

What cool hacks can be done using sys.settrace?

What cool hacks can be done using sys.settrace? Question: I love being able to modify the arguments the get sent to a function, using settrace, like : import sys def trace_func(frame,event,arg): value = frame.f_locals[“a”] if value % 2 == 0: value += 1 frame.f_locals[“a”] = value def f(a): print a if __name__ == “__main__”: sys.settrace(trace_func) …

Total answers: 7

Where is Python's sys.path initialized from?

Where is Python's sys.path initialized from? Question: Where is Python’s sys.path initialized from? UPD: Python is adding some paths before refering to PYTHONPATH: >>> import sys >>> from pprint import pprint as p >>> p(sys.path) [”, ‘C:\Python25\lib\site-packages\setuptools-0.6c9-py2.5.egg’, ‘C:\Python25\lib\site-packages\orbited-0.7.8-py2.5.egg’, ‘C:\Python25\lib\site-packages\morbid-0.8.6.1-py2.5.egg’, ‘C:\Python25\lib\site-packages\demjson-1.4-py2.5.egg’, ‘C:\Python25\lib\site-packages\stomper-0.2.2-py2.5.egg’, ‘C:\Python25\lib\site-packages\uuid-1.30-py2.5.egg’, ‘C:\Python25\lib\site-packages\stompservice-0.1.0-py2.5.egg’, ‘C:\Python25\lib\site-packages\cherrypy-3.0.1-py2.5.egg’, ‘C:\Python25\lib\site-packages\pyorbited-0.2.2-py2.5.egg’, ‘C:\Python25\lib\site-packages\flup-1.0.1-py2.5.egg’, ‘C:\Python25\lib\site-packages\wsgilog-0.1-py2.5.egg’, ‘c:\testdir’, ‘C:\Windows\system32\python25.zip’, ‘C:\Python25\DLLs’, ‘C:\Python25\lib’, ‘C:\Python25\lib\plat-win’, ‘C:\Python25\lib\lib-tk’, ‘C:\Python25’, ‘C:\Python25\lib\site-packages’, …

Total answers: 2