{"id":4408,"date":"2014-03-30T10:42:10","date_gmt":"2014-03-30T10:42:10","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/problem-about-python-2-6-collection-of-common-programming-errors\/"},"modified":"2014-03-30T10:42:10","modified_gmt":"2014-03-30T10:42:10","slug":"problem-about-python-2-6-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/problem-about-python-2-6-collection-of-common-programming-errors\/","title":{"rendered":"problem about python-2.6-Collection of common programming errors"},"content":{"rendered":"<ul>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/132aeb33251a1eddee3efc87633c0af1?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\ntzot<br \/>\npython python-2.6<br \/>\nUsing 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()<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/f9d55521783a160949ef8e11da0b77e4?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nPaco<br \/>\npython python-2.6<br \/>\nIt seems like python (2.6) is not able to optimize this simple temp variable &#8216;a&#8217; ?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 &#8216; =&gt; function called&#8217;def unoptimized():print &#8216;in unoptimized&#8217;a = functioncallf(func=a)def optimized():print &#8216;in optimized&#8217;f(func=functioncall)unoptimized() optimized()print &#8216;dis(unoptimized)&#8217; di<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/eb06bbfd40ef1af832b1a773f8a2ef3a?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nLuffy<br \/>\npython python-3.x python-2.6<br \/>\nWhen I start program like thispython Script.pyabspath return sth like thatos.path.abspath(&#8220;..\/..\/house\/kitchen&#8221;) == &#8220;\/ex1\/ex2\/house\/kitchen&#8221;But when i start like this i gotpython ex3\/Script.py os.path.abspath(&#8220;..\/..\/house\/kitchen&#8221;) == &#8220;\/house\/kitchen&#8221;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<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/0263c4c9036955a2d9768bf6a35a8345?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nKara<br \/>\npython python-2.7 python-2.6<br \/>\nI&#8217;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:&gt;&gt;&gt; bytearray.fromhex(&#8216;B9 01EF&#8217;) Traceback (most recent call last):File &#8220;&lt;stdin&gt;&#8221;, line 1, in &lt;module&gt; 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&#8217;t want to always convert to unicode as it&#8217;s a performance hit<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/6cc1d82c11563b440c57280ad587ee47?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nsmci<br \/>\npython json json-decode python-2.6 known-issues<br \/>\nI&#8217;m using the json module in Python 2.6 to load and decode JSON files. However I&#8217;m currently getting slower than expected performance. I&#8217;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&#8217;d rather use the JSON module provided with<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/6f4cf77deb805a0fe43a89b2fac2b320?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nSkynet Believer<br \/>\npython-2.6<br \/>\nWhen I try to install PyGraphics-1.5.win32.exe it pops up with an error stating:&#8221;The program can&#8217;t start because MSVCR71.dll is missing from your computer. Try reinstalling the program to fix this problem.&#8221;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.<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/8744355c48ff471fda6fe94f603e8a0e?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\naskewchan<br \/>\npython sqlite3 wxpython python-2.6 crashing<br \/>\nSo, I have two pieces of code. The first is the GUI class:&#8221;&#8217; Created on Mar 6, 2013@author: Zach &#8221;&#8217; # -*- coding: utf-8 -*- ########################################################################### ## Python code generated with wxFormBuilder (version Sep 8 2010) ## http:\/\/www.wxformbuilder.org\/ ## ## PLEASE DO &#8220;NOT&#8221; EDIT THIS FILE! ###########################################################################import wx import wx.grid from Books import * #########################################<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/8b2d39a59a961ef26440e9c1453d1939?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nDon<br \/>\ndjango iis-7.5 isapi python-2.6 pyisapie<br \/>\nI 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 &#8220;Service not working&#8221; 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<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/2ec2dfd769b00dfa6188af569f246ba6?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nSheldon<br \/>\npython osx python-2.6 python-idle<br \/>\nI 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 \ud83d\ude41 Any ideas what it might be? Thanks<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/i.stack.imgur.com\/M1ZlR.jpg?s=32&amp;g=1\" \/><br \/>\njamylak<br \/>\npython scipy python-2.6 win64<br \/>\nI&#8217;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&#8217;m encountering a crash every time I try to use it in any other way than just importing the whole package &#8211; 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<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/6bd50c6e3a3772e1162a06e99abfac9d?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nSimon<br \/>\ncrash wxpython compatibility python-2.6 arcgis<br \/>\nmy 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 &#8216;import wx&#8217;and then press &#8216;enter&#8217;&#8230;funny thing happened, ArcMap crashed!!I did install a correct version of wxPython with Python 2.6.5&#8230;so I am wondering if anybody knows what&#8217;s going on? maybe there are some other libs I ne<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/i.stack.imgur.com\/3Yjcx.jpg?s=32&amp;g=1\" \/><br \/>\nfj123x<br \/>\npython unit-testing crash python-2.6<br \/>\nThis is the crash:Traceback (most recent call last): File &#8220;setup.py&#8221;, line 22, intest_suite = &#8220;tests.get_tests&#8221;, File &#8220;\/usr\/lib\/python2.6\/distutils\/core.py&#8221;, line 152, in setupdist.run_commands() File &#8220;\/usr\/lib\/python2.6\/distutils\/dist.py&#8221;, line 975, in run_commandsself.run_command(cmd) File &#8220;\/usr\/lib\/python2.6\/distutils\/dist.py&#8221;, line 995, in run_commandcmd_obj.run() File &#8220;\/home\/travis\/virtualenv\/python2.6\/lib\/python2.6\/site-packages\/setuptools\/command\/test.py&#8221;,line 138, in runself.wi<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/i.stack.imgur.com\/2Leg5.jpg?s=32&amp;g=1\" \/><br \/>\nUnknown<br \/>\npython multithreading python-2.6<br \/>\nI&#8217;m following a tutorial on simple threading. They give this example and when I try to use it I&#8217;m getting unintelligible errors from the interpreter. Can you please tell me why this isn&#8217;t working? I&#8217;m on WinXP SP3 w\/ Python 2.6 currentimport threaddef myfunction(mystring,*args):print mystringif __name__ == &#8216;__main__&#8217;:try:thread.start_new_thread(myfunction,(&#8216;MyStringHere&#8217;,1))except Exception as errtxt:print errtxtExecuting this results in::Unhandled exception in thread started by Error in sys.exc<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/fe1538b67030ef3dfef415b223e541ca?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nEbiDK<br \/>\npython oop python-2.7 python-2.6 super<br \/>\nAre there good (suitable for using in real projects) ways or reducing boilerplate in things like thisclass B(A):def qqq(self): # 1 unwanted token &#8220;self&#8221;super(B, self).qqq() # 7 unwanted tokens plus 2 duplications (&#8220;B&#8221;, &#8220;qqq&#8221;)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<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/9b96fb72e053d2b561e56be76286f549?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nThom Ives<br \/>\npython urllib python-2.6 python-3.2<br \/>\nPreviously, 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 &#8230;import urllib.requestfp = urllib.request.urlopen(URL_string_that_I_use)string = fp.read() fp.close() print(string.decode(&#8220;ut<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/2412de50d273085f5dcf3f2101c3996e?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nThe man on the Clapham omnibus<br \/>\nandroid python unicode python-2.6 sl4a<br \/>\nDoes 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, &#8216;r&#8217;, &#8216;utf-8&#8217; )) as f:for line in f:yield linepath = &#8216;\/path\/to\/norsk\/verbs.txt&#8217;for i in readfile(path):print ibut on the phone it gets to the first special character \u00f8 and throws: UnicodeEncodeError: &#8216;ascii&#8217;<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/edec79e9ab6705b81c0af0a8be8e6e70?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\njsawatzky<br \/>\nc++ python linux python-2.6<br \/>\nI 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&#8217;My plugin&#8217;s name is &#8216;_myplugin&#8217;. I do not have a function in my C++ file that is names &#8216;init_myplugin&#8217;. Help would be very much appreciated.<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/7b4f8689f02bf130a3f6e5e7c507cf73?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nIsrael<br \/>\nnumpy scipy python-2.6<br \/>\nI have this little code:from numpy import * from scipy import signal, misc import matplotlib.pyplot as pltpath=&#8221;~\/pics\/&#8221; band_1 = misc.imread(path + &#8220;foo.tif&#8221;);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 &#8220;foo.py&#8221;, line 2, in &lt;module&gt;from scipy import signalFile &#8220;\/usr\/lib\/python2.6\/site-packages\/scipy\/signal\/__init__.py&#8221;<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/2dc3314d5d44476a110fe2c3047983fa?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nm&#8211;s<br \/>\npython parsing datetime python-2.6<br \/>\nThe problem:I&#8217;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: &#8216;z&#8217; is a bad directive in format<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/24780fb6df85a943c7aea0402c843737?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nMartijn Pieters<br \/>\npython python-2.6 with-statement<br \/>\nI am trying to use &#8220;With open()&#8221; 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 = &#8220;&#8221;with open(&#8220;check_files\/&#8221;+exportfileCheckFilesFolder+&#8221;.txt&#8221;) as f1,open(&#8220;transfer-out\/&#8221;+exportfileTransferFolder) as f2:if f1.read().strip() in f2.read():pr<\/li>\n<\/ul>\n<p>Web site is in building<\/p>\n","protected":false},"excerpt":{"rendered":"<p>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 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-4408","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/4408","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=4408"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/4408\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=4408"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=4408"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=4408"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}