problem about python-2.6-Collection of common programming errors


  • tzot
    python python-2.6
    Using python 2.6 is there a way to check if all the items of a sequence equals a given value, in one statement?[pseudocode] my_sequence = (2,5,7,82,35)if all the values in (type(i) for i in my_sequence) == int:do()instead of, say:my_sequence = (2,5,7,82,35) all_int = True for i in my_sequence:if type(i) is not int:all_int = Falsebreakif all_int:do()

  • Paco
    python python-2.6
    It seems like python (2.6) is not able to optimize this simple temp variable ‘a’ ?I use to assign a local variable to some code in order to reduce the line length.To me this is a simple optimization any correct compiler can do automatically.from dis import disdef f(func):func()def functioncall():print ‘ => function called’def unoptimized():print ‘in unoptimized’a = functioncallf(func=a)def optimized():print ‘in optimized’f(func=functioncall)unoptimized() optimized()print ‘dis(unoptimized)’ di

  • Luffy
    python python-3.x python-2.6
    When I start program like thispython Script.pyabspath return sth like thatos.path.abspath(“../../house/kitchen”) == “/ex1/ex2/house/kitchen”But when i start like this i gotpython ex3/Script.py os.path.abspath(“../../house/kitchen”) == “/house/kitchen”I think i need to set working place to place where is script but how to do that.os.chdir(os.path.dirname(os.path.realpath(sys.argv[0])))This solved my problem

  • Kara
    python python-2.7 python-2.6
    I’ve come across a bug in Python (at least in 2.6.1) for the bytearray.fromhex function. This is what happens if you try the example from the docstring:>>> bytearray.fromhex(‘B9 01EF’) Traceback (most recent call last):File “<stdin>”, line 1, in <module> TypeError: fromhex() argument 1 must be unicode, not strThis example works fine in Python 2.7, and I want to know the best way of coding around the problem. I don’t want to always convert to unicode as it’s a performance hit

  • smci
    python json json-decode python-2.6 known-issues
    I’m using the json module in Python 2.6 to load and decode JSON files. However I’m currently getting slower than expected performance. I’m using a test case which is 6MB in size and json.loads() is taking 20 seconds.I thought the json module had some native code to speed up the decoding?How do I check if this is being used?As a comparison, I downloaded and installed the python-cjson module, and cjson.decode() is taking 1 second for the same test case.I’d rather use the JSON module provided with

  • Skynet Believer
    python-2.6
    When I try to install PyGraphics-1.5.win32.exe it pops up with an error stating:”The program can’t start because MSVCR71.dll is missing from your computer. Try reinstalling the program to fix this problem.”I have tried reinstalling Python and have had no luck. My installation currently includes PyWin, Pyserial, and PIL on Windows 7 x64.Any help much appreciated, thank you.

  • askewchan
    python sqlite3 wxpython python-2.6 crashing
    So, I have two pieces of code. The first is the GUI class:”’ Created on Mar 6, 2013@author: Zach ”’ # -*- coding: utf-8 -*- ########################################################################### ## Python code generated with wxFormBuilder (version Sep 8 2010) ## http://www.wxformbuilder.org/ ## ## PLEASE DO “NOT” EDIT THIS FILE! ###########################################################################import wx import wx.grid from Books import * #########################################

  • Don
    django iis-7.5 isapi python-2.6 pyisapie
    I managed to run Django using IIS as webserver (using PyISAPIe) and everything goes well in my test server, mounting Windows 2008 Server R2 64bit.Then I installed the application on another server with the same configuration and it works fine for the first request. Then when I reload the page, I get a “Service not working” page.On the event log I see an Application error saying that python26.dll had some problems:Faulting application name: w3wp.exe Faulting module name: python26.dll Exception co

  • Sheldon
    python osx python-2.6 python-idle
    I just installed python 2.6 on Mac OS X (Snow Leopard) and when I start IDLE it keeps quitting!I removed all the installations of python by: rm -rf /Library/Frameworks/Python.Frameworkand then re-installed it and I still get the same problem 🙁 Any ideas what it might be? Thanks

  • jamylak
    python scipy python-2.6 win64
    I’m trying to use the scipy package in my 32-bit Python 2.6 on 64-bit Windows 7.I have installed Scipy 0.12.0 from the 32-bit Python Superpack binary installer. The installation went through smoothly, but after completion, I’m encountering a crash every time I try to use it in any other way than just importing the whole package – either running the test (scipy.test()) or importing one of its submodules. When I just import the whole package, it generates a warning:C:\Program Files (x86)\ESRI\Pyth

  • Simon
    crash wxpython compatibility python-2.6 arcgis
    my PC have ArcGIS 10 installed, which has Python 2.6.5 built-in.. I am trying to write a wxPython script and want to link this script and make it executable in ArcGIS.. to test the compatibility of wxPython and ArcGIS 10, I opened python command window in ArcMap, and typed ‘import wx’and then press ‘enter’…funny thing happened, ArcMap crashed!!I did install a correct version of wxPython with Python 2.6.5…so I am wondering if anybody knows what’s going on? maybe there are some other libs I ne

  • fj123x
    python unit-testing crash python-2.6
    This is the crash:Traceback (most recent call last): File “setup.py”, line 22, intest_suite = “tests.get_tests”, File “/usr/lib/python2.6/distutils/core.py”, line 152, in setupdist.run_commands() File “/usr/lib/python2.6/distutils/dist.py”, line 975, in run_commandsself.run_command(cmd) File “/usr/lib/python2.6/distutils/dist.py”, line 995, in run_commandcmd_obj.run() File “/home/travis/virtualenv/python2.6/lib/python2.6/site-packages/setuptools/command/test.py”,line 138, in runself.wi

  • Unknown
    python multithreading python-2.6
    I’m following a tutorial on simple threading. They give this example and when I try to use it I’m getting unintelligible errors from the interpreter. Can you please tell me why this isn’t working? I’m on WinXP SP3 w/ Python 2.6 currentimport threaddef myfunction(mystring,*args):print mystringif __name__ == ‘__main__’:try:thread.start_new_thread(myfunction,(‘MyStringHere’,1))except Exception as errtxt:print errtxtExecuting this results in::Unhandled exception in thread started by Error in sys.exc

  • EbiDK
    python oop python-2.7 python-2.6 super
    Are there good (suitable for using in real projects) ways or reducing boilerplate in things like thisclass B(A):def qqq(self): # 1 unwanted token “self”super(B, self).qqq() # 7 unwanted tokens plus 2 duplications (“B”, “qqq”)do_something()I want it to look more like this:class B(A):def qqq:superdo_something()or (more realistically)class B(A):@autosuper_beforedef qqq(self):do_something()Is it possible in Python 2.6+ without overt hacks?@link super() in Python 2.x without args

  • Thom Ives
    python urllib python-2.6 python-3.2
    Previously, in python 2.6, I had made a lot of use of urllib.urlopen to capture web page content and then later post process the data that I received. Now, those routines, and the new routines I am trying to use for python 3.2 are running into what seems to be a windows only (maybe even windows 7 only problem).Using the following code with python 3.2.2 (64) on windows 7 …import urllib.requestfp = urllib.request.urlopen(URL_string_that_I_use)string = fp.read() fp.close() print(string.decode(“ut

  • The man on the Clapham omnibus
    android python unicode python-2.6 sl4a
    Does anyone have any experience with this? I have been using python 3.2 for the last half a year, and my memory of 2.6.2 is not that great. On my computer the following code works, tested using 2.6.1:import contextlib import codecsdef readfile(path):with contextlib.closing( codecs.open( path, ‘r’, ‘utf-8’ )) as f:for line in f:yield linepath = ‘/path/to/norsk/verbs.txt’for i in readfile(path):print ibut on the phone it gets to the first special character ø and throws: UnicodeEncodeError: ‘ascii’

  • jsawatzky
    c++ python linux python-2.6
    I have been trying to get Python 2.6 to build on Linux with a custom module for the past week and have been having a lot of problems. My latest one seems to be another linker issues when Python tries to link in my custom module. This is the error I get:libpython2.6.a(config.o):(.data+0xa8): undefined reference to `init_myplugin’My plugin’s name is ‘_myplugin’. I do not have a function in my C++ file that is names ‘init_myplugin’. Help would be very much appreciated.

  • Israel
    numpy scipy python-2.6
    I have this little code:from numpy import * from scipy import signal, misc import matplotlib.pyplot as pltpath=”~/pics/” band_1 = misc.imread(path + “foo.tif”);H = array((1/2.0, 1/4.0, 1/2.0)); signal.convolve2d(band_1.flatten(), H)plt.figure() plt.imshow(band_1) plt.show()then I execute this code python foo.py and it throws this error:Traceback (most recent call last):File “foo.py”, line 2, in <module>from scipy import signalFile “/usr/lib/python2.6/site-packages/scipy/signal/__init__.py”

  • m–s
    python parsing datetime python-2.6
    The problem:I’m about to parse a log file in Python 2.6. Problems arose parsing the common log date string into a time object:13/Sep/2012:06:27:18 +0200What I tried alreadyUse dateutils.parser.parseI already tried using dateutils.parser.parse but it failed parsing it with the following error:ValueError: unknown string formatUse time.strptimeI tried time.strptime with the format string %d/%b/%Y:%H:%M:%S %z but ran into trouble when parsing the timezone:ValueError: ‘z’ is a bad directive in format

  • Martijn Pieters
    python python-2.6 with-statement
    I am trying to use “With open()” with python 2.6 and it is giving error(Syntax error) while it works fine with python 2.7.3 Am I missing something or some import to make my program work!Any help would be appreciated.BrMy code is here:def compare_some_text_of_a_file(self, exportfileTransferFolder, exportfileCheckFilesFolder) :flag = 0error = “”with open(“check_files/”+exportfileCheckFilesFolder+”.txt”) as f1,open(“transfer-out/”+exportfileTransferFolder) as f2:if f1.read().strip() in f2.read():pr

Web site is in building