sys

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

孤人 提交于 2019-11-29 01:53:40
I have a script that does various things and access paramenters 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 = sys.argv[1] def hello(self): print self.value def suite(self): modules_to_test = ('external_sanity_onvif', 'starttest') alltests = unittest.TestSuite() for module in map(__import__, modules_to_test): alltests.addTest(unittest.findTestCases(module)) return alltests if __name__ == '__main__': Run = MyScript() Run.hello() log_file = 'log_file.txt'

How to import files in python using sys.path.append?

僤鯓⒐⒋嵵緔 提交于 2019-11-29 00:03:24
There are two directories on my desktop, DIR1 and DIR2 which contain the following files: DIR1: file1.py DIR2: file2.py myfile.txt The files contain the following: file1.py import sys sys.path.append('.') sys.path.append('../DIR2') import file2 file2.py import sys sys.path.append( '.' ) sys.path.append( '../DIR2' ) MY_FILE = "myfile.txt" myfile = open(MY_FILE) myfile.txt some text Now, there are two scenarios. The first works, the second gives an error. Scenario 1 I cd into DIR2 and run file2.py and it runs no problem. Scenario 2 I cd into DIR1 and run file1.py and it throws an error:

Cache-as-Ram (no fill mode) Executable Code

拈花ヽ惹草 提交于 2019-11-29 00:00:33
I have read about cache-as-ram mode (no-fill mode) numerous times and am wondering whether number one, can executable code be written and jumped to and if so is the executable code restricted to half of the level one cache (since the cache is really just sram). osgx Coreboot originally used CAR to save C stack in L1 data cache: http://rere.qmqm.pl/~mirq/cache_as_ram_lb_09142006.pdf http://www.coreboot.org/images/6/6c/LBCar.pdf To execute code, we should switch unified L2 to CAR mode, then L1i (you should know that most modern desktop/application CPUs has separated L1: one for data - L1d - with

What is the difference between a stack and a frame?

谁都会走 提交于 2019-11-28 15:47:40
Under what situations would I want to use one over the other? What is the difference between: >>> import inspect >>> print(inspect.getouterframes(inspect.currentframe())) [(<frame object at 0x8fc262c>, '<stdin>', 1, '<module>', None, None)] And: >>> import traceback >>> traceback.extract_stack() [('<stdin>', 1, '<module>', None)] Update: Another: >>> import sys >>> print(sys._getframe().f_trace,sys._getframe().f_code) (None, <code object <module> at 0x8682a88, file "<stdin>", line 1>) I do not understand the nuances here: Stack Frame Frame Object Stack Trace update 2, a bit of time since the

What does sys.stdin read?

爷,独闯天下 提交于 2019-11-28 10:26:38
I get how to open files, and then use Python's pre built in functions with them. But how does sys.stdin work? for something in sys.stdin: some stuff here lines = sys.stdin.readlines() What's the difference between the above two different uses on sys.stdin? Where is it reading the information from? Is it via keyboard, or do we still have to provide a file? So you have used Python's "pre built in functions", presumably like this: file_object = open('filename') for something in file_object: some stuff here This reads the file by invoking an iterator on the file object which happens to return the

Set LD_LIBRARY_PATH before importing in python

别等时光非礼了梦想. 提交于 2019-11-28 08:54:25
Python uses the PYTHONPATH environment-variable to determine in which folders it should look for modules. You can play around with it by modifying sys.path , which works nicely for pure Python-Modules. But when a module uses shared object files or static libraries, it looks for those in LD_LIBRARY_PATH (on linux), but this can't be changed as easily and is platform dependent as far as I know. The quick-fix for this problem is of course to set the environment-variable or invoke the script like LD_LIBRARY_PATH=. ./script.py , but then you'll have to set it again for every new shell you open.

Python: Which encoding is used for processing sys.argv?

白昼怎懂夜的黑 提交于 2019-11-28 08:09:19
In what encoding are the elements of sys.argv , in Python? are they encoded with the sys.getdefaultencoding() encoding? sys.getdefaultencoding(): Return the name of the current default string encoding used by the Unicode implementation. PS : As pointed out in some of the answers, sys.stdin.encoding would indeed be a better guess . I would love to see a definitive answer to this question, though, with pointers to solid sources! PPS : As Wim pointed out, Python 3 solves this issue by putting str objects in sys.argv (if I understand correctly). The question remains open for Python 2.x, though.

What does 'sys.argv' mean?

社会主义新天地 提交于 2019-11-28 07:51:24
I am learning from code, and I am get confused by one of its lines which is: things = [float(arg) for arg in sys.argv[1:]] Omega_a, Omega_b, Delta_a, Delta_b, \ init_pop_a, init_pop_b, tstep, tfinal = things I have searched online and tried to understand what sys.arg means, and here is my understanding: So sys.argv[0] is the file name, and sys.argv[1:] is the rest of the parameters which should given by users. I am not sure am I understood it right, and if it is, then I don't understand why cant it be like: Omega_a = input() Omega_b = input() etc... What's the difference between these two ways

How to connect in java as SYS to Oracle?

让人想犯罪 __ 提交于 2019-11-28 05:19:43
I receive this error: java.sql.SQLException: ORA-28009: connection as SYS should be as SYSDBA or SYSOPER How to fix? (I need to be SYS ). Thanks. try this : import java.sql as jsql import java.lang as lang driver, url, user, passwd = ( "oracle.jdbc.driver.OracleDriver", "jdbc:oracle:thin:@localhost:1234:xxx1", "sys as sysdba", "xxx1") lang.Class.forName(driver) c = jsql.DriverManager.getConnection(url,user,passwd) Answers already there, you are trying to connect as sys but the Server allows either sys as sysdba or sys as sysoper just change user parameter as either one from above user='sys as

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

蓝咒 提交于 2019-11-28 04:53:59
问题 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 command line option to the interpreter, argv[0] is set to the string '-c' . If no script name was passed to the Python interpreter, argv[0] is the empty string." Am I missing something, or sys.argv[0] always returns the script name, and to get '-c' I