python-2.6

How do I access an Oracle db without installing Oracle's client and cx_Oracle?

别等时光非礼了梦想. 提交于 2019-12-05 12:38:22
问题 I have two RHEL servers running Python 2.4 and 2.6 separately. There is an Oracle database on the other server I need to access. I was trying to install cx_oracle on my RHEL server but found out that the Oracle client must be installed first. The problem is, I don’t have permission to install Oracle's client on both RHEL servers. On the same servers, a Perl program can connect to the Oracle db using: DBI->connect("dbi:Oracle:host=myhost.prod.com;sid=prddb",'username','password') Can Python do

How do I install pip for Python 2.6 on OS X?

倖福魔咒の 提交于 2019-12-05 10:14:26
I have an OS X system where I need to install a module for python 2.6. Both pip and easy_install-2.6 are failing: # /usr/bin/easy_install-2.6 pip Searching for pip Reading http://pypi.python.org/simple/pip/ Download error: unknown url type: https -- Some packages may not be found! Couldn't find index page for 'pip' (maybe misspelled?) Scanning index of all packages (this may take a while) Reading http://pypi.python.org/simple/ Download error: unknown url type: https -- Some packages may not be found! No local packages or download links found for pip error: Could not find suitable distribution

fd.seek() IOError: [Errno 22] Invalid argument

点点圈 提交于 2019-12-05 06:06:31
My Python Interpreter (v2.6.5) raises the above error in the following codepart: fd = open("some_filename", "r") fd.seek(-2, os.SEEK_END) #same happens if you exchange the second arg. w/ 2 data=fd.read(2); last call is fd.seek() Traceback (most recent call last): File "bot.py", line 250, in <module> fd.seek(iterator, os.SEEK_END); IOError: [Errno 22] Invalid argument The strange thing with this is that the exception occurs just when executing my entire code, not if only the specific part with the file opening. At the runtime of this part of code, the opened file definitely exists, disk is not

Jupyter using the wrong version of python

我与影子孤独终老i 提交于 2019-12-05 03:35:11
问题 Hi I've installed python 2.7 but did not remove 2.6. i've added 2.7 to the path and also as an alias but it seems like when I do jupyter notebook it tries to access 2.6 > jupyter notebook Traceback (most recent call last): File "jupyter-notebook", line 7, in <module> from notebook.notebookapp import main File "/usr/lib/python2.6/site-packages/notebook/__init__.py", line 25, in <module> from .nbextensions import install_nbextension File "/usr/lib/python2.6/site-packages/notebook/nbextensions

writing back into the same file after reading from the file

ⅰ亾dé卋堺 提交于 2019-12-05 03:04:52
My aim is to read line from the file , strip the blank spaces at the end of it and write back into the same file. I have tried the following code: with open(filename, 'r+') as f: for i in f: f.write(i.rstrip()+"\n") This seems to write at the end of the file, keeping initial data in the file intact . I know that using f.seek(0) would take the pointer back to start of the file , which I am assuming would be somehow required for this solution. Can you please advise if there is different approach for this or am I on the right patch just need to add more logic into the code? Use a temporary file.

Can't install python module “pycrypto” on Debian lenny

两盒软妹~` 提交于 2019-12-04 23:05:50
I tried to install pycrypto module by downloading the source code and executing the following command python setup.py install , then an error came running install running build running build_py running build_ext warning: GMP library not found; Not building Crypto.PublicKey._fastmath. building 'Crypto.Hash.MD2' extension gcc -pthread -fno-strict-aliasing -fwrapv -Wall -Wstrict-prototypes -fPIC -std=c99 -O3 -fomit-frame-pointer -Isrc/ -I/usr/include/python2.5 -c src/MD2.c -o build/temp.linux-x86_64-2.5/src/MD2.o src/MD2.c:31:20: error: Python.h: No such file or directory src/MD2.c:118: error:

problems using __next__ method in python

夙愿已清 提交于 2019-12-04 16:30:45
问题 I have just started learning python and am reading about classes . this is the code i had written for a simple iterable class : class maths: def __init__(self,x): self.a=x def __iter__(self): self.b=0 return self def next(self): if self.b <= self.a: self.b = self.b+1 return self.b-1 else: raise StopIteration x=maths(5) for l in x: print l for the next() method when i used the __next__ (self): the following error was displayed Traceback (most recent call last): File "class.py", line 20, in

Python logging with rsyslog

心已入冬 提交于 2019-12-04 15:42:23
I've inherited the following python file: import logging from logging.handlers import SysLogHandler class Logger(object): # Return a logging instance used throughout the library def __init__(self): self.logger = logging.getLogger('my_daemon') # Log an info message def info(self, message, *args, **kwargs): self.__log(logging.INFO, message, *args, **kwargs) # Configure the logger to log to syslog def log_to_syslog(self): formatter = logging.Formatter('my_daemon: [%(levelname)s] %(message)s') handler = SysLogHandler(address='/dev/log', facility=SysLogHandler.LOG_DAEMON) handler.setFormatter

How can I set a subparser to be optional in argparse?

≯℡__Kan透↙ 提交于 2019-12-04 15:39:58
import argparse parser_sub = subparsers.add_parser('files') parser_sub.add_argument( '--file-name', action='store', dest='filename', nargs='*') options = parser.parse_args() Output: error: too few arguments. As per this link: https://bugs.python.org/issue9253 it states that subparsers cant be optional. Can this behaviour be changed? I would like my subcommands to be optional. How can I achieve this through argparse in python 2.6? There's not much that can be added to that bug/issue https://bugs.python.org/issue9253 . subparsers is a special kind of positional argument. Normally the only way to

PYTHON 2.6 XML.ETREE to output single quote for attributes instead of double quote

不想你离开。 提交于 2019-12-04 15:39:55
i got the following code : #!/usr/bin/python2.6 from lxml import etree n = etree.Element('test') n.set('id','1234') print etree.tostring(n) the output generate is <test id="1234"/> but i want <test id='1234'/> can someone help ? I checked the documentation and found no reference for single/double-quote option. I think your only recourse is print etree.tostring(n).replace('"', "'") Update Given: from lxml import etree n = etree.Element('test') n.set('id', "Zach's not-so-good answer") my original answer could output malformed XML because of unbalanced apostrophes: <test id='Zach's not-so-good