sys

How to connect in java as SYS to Oracle?

南楼画角 提交于 2019-11-27 00:54:22
问题 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. 回答1: 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) 回答2: Answers already there, you are trying to connect as sys but the

Import from sibling directory

一笑奈何 提交于 2019-11-26 17:37:40
问题 I have a Python class called "ClassA" and another Python class which is supposed to import ClassA which is "ClassB". The directory structure is as follows: MainDir ../Dir ..../DirA/ClassA ..../DirB/ClassB How would I use sys.path so that ClassB can use ClassA? 回答1: You really should be using packages. Then MainDir is placed at a point in the file system on sys.path (e.g. .../site-packages), then you can say in ClassB: from MainDir.Dir.DirA import ClassA # which is actually a module You just

Capture stdout from a script in Python

Deadly 提交于 2019-11-26 12:57:00
suppose there is a script doing something like this: # module writer.py import sys def write(): sys.stdout.write("foobar") Now suppose I want to capture the output of the write function and store it in a variable for further processing. The naive solution was: # module mymodule.py from writer import write out = write() print out.upper() But this doesn't work. I come up with another solution and it works, but please, let me know if there is a better way to solve the problem. Thanks import sys from cStringIO import StringIO # setup the environment backup = sys.stdout # #### sys.stdout = StringIO

How to finish sys.stdin.readlines() input?

。_饼干妹妹 提交于 2019-11-26 10:58:28
问题 This might be a silly question, but as I can\'t find an answer, I have to ask it. In interactive python I want to process a message which i get with: >>> message = sys.stdin.readlines() Everything works fine, but... how to stop it from getting an input and make it save into message variable? Stopping with ctrl+c stops whole process so there is no input to be saved anywhere. I guess there\'s an easy answer I just can\'t find... 回答1: For unix based system : Hello, you can tape : Ctrl d Ctrl d

Python memory usage of numpy arrays

走远了吗. 提交于 2019-11-26 08:07:49
问题 I\'m using python to analyse some large files and I\'m running into memory issues, so I\'ve been using sys.getsizeof() to try and keep track of the usage, but it\'s behaviour with numpy arrays is bizarre. Here\'s an example involving a map of albedos that I\'m having to open: >>> import numpy as np >>> import struct >>> from sys import getsizeof >>> f = open(\'Albedo_map.assoc\', \'rb\') >>> getsizeof(f) 144 >>> albedo = struct.unpack(\'%df\' % (7200*3600), f.read(7200*3600*4)) >>> getsizeof

Usage of sys.stdout.flush() method

北城以北 提交于 2019-11-26 03:48:11
问题 What does sys.stdout.flush() do? 回答1: Python's standard out is buffered (meaning that it collects some of the data "written" to standard out before it writes it to the terminal). Calling sys.stdout.flush() forces it to "flush" the buffer, meaning that it will write everything in the buffer to the terminal, even if normally it would wait before doing so. Here's some good information about (un)buffered I/O and why it's useful: http://en.wikipedia.org/wiki/Data_buffer Buffered vs unbuffered IO

Capture stdout from a script?

…衆ロ難τιáo~ 提交于 2019-11-26 03:28:21
问题 suppose there is a script doing something like this: # module writer.py import sys def write(): sys.stdout.write(\"foobar\") Now suppose I want to capture the output of the write function and store it in a variable for further processing. The naive solution was: # module mymodule.py from writer import write out = write() print out.upper() But this doesn\'t work. I come up with another solution and it works, but please, let me know if there is a better way to solve the problem. Thanks import

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

只愿长相守 提交于 2019-11-25 23:01:59
问题 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\") 回答1: As per the documentation: This allows you to switch from the default ASCII to other encodings such as UTF-8, which the Python runtime will use whenever it has to decode a string buffer to unicode. This function is only available at Python start-up time, when Python scans the environment. It has to be called in a system-wide module,

Permanently add a directory to PYTHONPATH?

只谈情不闲聊 提交于 2019-11-25 22:26:40
问题 Whenever I use sys.path.append , the new directory will be added. However, once I close python, the list will revert to the previous (default?) values. How do I permanently add a directory to PYTHONPATH ? 回答1: You need to add your new directory to the environment variable PYTHONPATH , separated by a colon from previous contents thereof. In any form of Unix, you can do that in a startup script appropriate to whatever shell you're using ( .profile or whatever, depending on your favorite shell)