python-2.5

How to avoid line continuations in Python imports

橙三吉。 提交于 2019-12-13 03:35:30
问题 I have a number of classes / functions to import from a module and linters/ style checkers ( pylint , flake , pep8 ) are complaining that the line is too long and I am forced to use line continuation which is ugly: from my_lengthy_module import FirstClass, SecondClass, ThirdClass, \ foo_bar_with_long_name, bar_foo_with_longer_name, \ FourthClass, bar_foo_with_longer_name, foo_bar_with_longest_name How to do it better? 回答1: Python 2.5 introduced a concept of multi-line imports (PEP-328) which

Trying to get the value from a Tkinter scale and put it into a Label

倾然丶 夕夏残阳落幕 提交于 2019-12-13 02:23:08
问题 I have a small Python program that takes the value of a Tkinter scale and puts it into a label. #!/usr/bin/python from Tkinter import * class App: strval = StringVar() def __init__(self,master): frame = Frame(master) frame.pack() self.slide = Scale(frame, command = self.up, from_ = 1, to = 100) self.out = Label(frame, textvariable = self.strval) self.slide.pack() self.out.pack() def up(self,newscale): amount = str(newscale) self.strval.set(amount) root = Tk() app = App(root) root.mainloop()

Getting the end-memory address of a memory-range via python / ctypes

醉酒当歌 提交于 2019-12-13 01:28:48
问题 I'm creating a very basic (coverage) unittest for a (hardware) C-interface in python. A function of that C-interface needs memory-addresses since it talks directly to memory. The prototype of the function is: void function( ulong startAddress, ulong endAddress, ulong curAddress, nofPaddingElements ) The startAddress, endAddress and curAddress are basically memory-addresses of an array-of-structs. On the web (and stackoverflow ;-) ) I found references that if I want to do something with ctypes

Inheritance in web.py?

我只是一个虾纸丫 提交于 2019-12-12 05:01:53
问题 I am currently developing wep.py application. This is my web application which is binded with web.py and wsgi. root/main.py import web import sys import imp import os sys.path.append(os.path.dirname(__file__)) #from module import module from exam import exam urls = ( '/exam', 'exam' ) application = web.application(urls, globals(), autoreload = True).wsgifunc() My application has an abstract class called module in module.py in root directory and its purpose is to be inherited by modules. root

How to parse inbound GAE email manually?

谁都会走 提交于 2019-12-11 20:45:30
问题 Since I am having problems with standard GAE's e-mail functionality when e-mail subject is UTF-8 encoded, I am trying to handle it manually: msg_encoding = self.request.headers['Content-Type'].split('charset=')[1] # message/rfc822; charset=UTF-8 msg = email.message_from_string(self.request.body) if msg: logging.debug(msg.get_content_charset()) # None logging.debug(msg['to']) logging.debug(msg['from']) logging.debug(msg['Subject'].decode(msg_encoding)) Do I do it correctly? Should I decode

different behavior when using re.finditer and re.match

非 Y 不嫁゛ 提交于 2019-12-11 13:24:36
问题 I'm working on a regex to to collect some values from a page through some script. I'm using re.match in condition but it returns false but if i use finditer it returns true and body of condition is executed. i tested that regex in my own built tester and it's working there but not in script. here is sample script. result = [] RE_Add0 = re.compile("\d{5}(?:(?:-| |)\d{4})?", re.IGNORECASE) each = ''Expiration Date:\n05/31/1996\nBusiness Address: 23901 CALABASAS ROAD #2000 CALABASAS, CA 91302\n'

How to receive inbound messages with unicode subject?

孤人 提交于 2019-12-11 10:52:36
问题 When I receive message with Unicode subject, I am getting the following error: 'ascii' codec can't decode byte 0xd0 in position 0: ordinal not in range(128) Traceback (most recent call last): File "/base/python_runtime/python_lib/versions/1/google/appengine/ext/webapp/_webapp25.py", line 716, in __call__ handler.post(*groups) File "/base/python_runtime/python_lib/versions/1/google/appengine/ext/webapp/mail_handlers.py", line 69, in post self.receive(mail.InboundEmailMessage(self.request.body)

NameError: name 'buffer' is not defined with Ant Based framework batch file

99封情书 提交于 2019-12-11 07:29:09
问题 I'm using a python script to execute an Ant based framework batch file(Helium.bat) subprocess.Popen('hlm '+commands, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) However the script will always stop and display the following error when it executes the .bat file: import codecs File "C:\Python25\lib\codecs.py", line 1007, in <module> strict_errors = lookup_error("strict") File "C:\Python25\lib\codecs.py", line 1007, in <module> strict_errors = lookup_error("strict") File "C:

Does urllib or urllib2 in Python 2.5 support https?

久未见 提交于 2019-12-11 03:56:14
问题 Thanks for the help in advance. I am puzzled that the same code works for python 2.6 but not 2.5. Here is the code import cgi, urllib, urlparse, urllib2 url='https://graph.facebook.com' req=urllib2.Request(url=url) p=urllib2.urlopen(req) response = cgi.parse_qs(p.read()) And here is the exception I got Traceback (most recent call last): File "t2.py", line 6, in <module> p=urllib2.urlopen(req) File "/home/userx/lib/python2.5/urllib2.py", line 124, in urlopen return _opener.open(url, data) File

django.utils module import error in appengine 1.7.6

拈花ヽ惹草 提交于 2019-12-11 03:30:26
问题 I just updated to 1.7.6 appengine and started getting ImportError for django.utils, my app is using python 2.5 and had no issues running before this update. Any idea if this was removed in the update? line 1, in <module> from django.utils import simplejson ImportError: No module named django.utils 回答1: If you're not able to upgrade to 2.7, try using old_dev_appserver.py instead of dev_appserver.py . 来源: https://stackoverflow.com/questions/15665779/django-utils-module-import-error-in-appengine