python-2.x

sublime text 3 use python 3.3 as compiler

余生颓废 提交于 2020-01-02 09:52:45
问题 Just purchased sublime 3. I'm wondering how I can compile in python 3 and not in python 2. When I execute import sys print(sys.version) I receive "2.7.3 |EPD_free 7.3-2 (32-bit)| (default, Apr 12 2012, 14:30:37) [MSC v.1500 32 bit (Intel)]" I've been stuck for the last 2 or 3 hours. I know it has something to do with builds but it just doesn't seem to be clicking. Any help would be greatly appreciated. Thanks! 回答1: The Sublime Text Python builder uses the Python executable found in your PATH.

How to install python-tk in my docker image

梦想的初衷 提交于 2020-01-02 06:58:11
问题 I get this error when I run my python script in my docker image ImportError: No module named _tkinter, please install the python-tk package So I tried 'pip install python-tk' root@43d2222b15c8:/tf_files# pip install python-tk Collecting python-tk Could not find a version that satisfies the requirement python-tk (from versions: ) No matching distribution found for python-tk But that does not fix my issue. Can you please tell me how can I fix my issue? Thank you. 回答1: Use import Tkinter . It

Appending a range to a list

与世无争的帅哥 提交于 2020-01-02 05:24:07
问题 I have some basic code that I'm not grasping the behaviour of: L = [ 'a', 'bb', 'ccc' ] L.append(range(2)) print len(L) print len(L + range(1)) print len(L) The output of which is 4 5 4 This is confusing to me, as my thought process is that the length of the initial list is 3, and appending range(2) to the end brings it to length of 5. Therefore I'd expect the output to be 5 6 5 . I'm sure it's a simple quirk, but I'm a bit lost and having a hell of a time trying to find an answer online.

Python on Raspberry Pi user input inside infinite loop misses inputs when hit with many

旧时模样 提交于 2020-01-02 04:27:23
问题 I have a very basic parrot script written in Python that simply prompts for a user input and prints it back inside an infinite loop. The Raspberry Pi has a USB barcode scanner attached for the input. while True: barcode = raw_input("Scan barcode: ") print "Barcode scanned: " + barcode When you scan at a "normal" speed it works reliably and the command output looks like this: Scan barcode: 9780465031467 Barcode scanned: 9780465031467 Scan barcode: 9780007505142 Barcode scanned: 9780007505142

Python futurize without replacing / with old_div

蹲街弑〆低调 提交于 2020-01-02 00:56:12
问题 I am using futurize --stage2 which aplies a number of source-source transformation to make the code python2 and python3 compatible. One of those fixes is that all divisions a/b are replaced by old_div(a/b) , which I would like to avoid (there is too many, and many of them are replaced unnecessarily, such as math.pi/2. . The documentation says that --nofix (or -x ) can be used to avoid running a certain fixes, but trying --nofix=fix_divison or --nofix=libfuturize.fixes.fix_divison has no

Installing Pip on 2.4

核能气质少年 提交于 2020-01-01 17:12:15
问题 How do I install pip on python 2.4? I've tried downloading the get-pip.py file, but it doesn't run on version 2.4 of python. Is there anyway to edit the file to run it? Or is there another download? 回答1: Python 2.4 was supported through v1.1. Try this: https://pypi.python.org/pypi/pip/1.1 回答2: From the Pip Installation guide: https://pip.pypa.io/en/latest/installing/ Python 2.5 was supported through v1.3.1, and Python 2.4 was supported through v1.1. 来源: https://stackoverflow.com/questions

TypeErrors using metaclasses in conjunction with multiple inheritance

可紊 提交于 2020-01-01 14:56:39
问题 I have two questions converning metaclasses and multiple inheritance. The first is: Why do I get a TypeError for the class Derived but not for Derived2 ? class Metaclass(type): pass class Klass(object): __metaclass__ = Metaclass #class Derived(object, Klass): pass # if I uncomment this, I get a TypeError class OtherClass(object): pass class Derived2(OtherClass, Klass): pass # I do not get a TypeError for this The exact error message is: TypeError: Error when calling the metaclass bases Cannot

Lambda Return Payload botocore.response.StreamingBody object prints but then empty in variable

|▌冷眼眸甩不掉的悲伤 提交于 2020-01-01 14:26:11
问题 I'm invoking a lambda function from another function and want to take a different action depending on the response, pretty standard stuff. However I get some unexpected behavior, it's probably something obvious, but it is eluding me. I've recreated my example in the simplest possible example any help would be much appreciated. The lambda function def lambda_handler(event, context): return 'Just a string' The code to call the lambda function def invoke_lambda(payload): r = lambda_client.invoke

Lambda Return Payload botocore.response.StreamingBody object prints but then empty in variable

只愿长相守 提交于 2020-01-01 14:25:08
问题 I'm invoking a lambda function from another function and want to take a different action depending on the response, pretty standard stuff. However I get some unexpected behavior, it's probably something obvious, but it is eluding me. I've recreated my example in the simplest possible example any help would be much appreciated. The lambda function def lambda_handler(event, context): return 'Just a string' The code to call the lambda function def invoke_lambda(payload): r = lambda_client.invoke

unicode_literals and doctest in Python 2.7 AND Python 3.5

半城伤御伤魂 提交于 2019-12-30 23:04:34
问题 Consider the following demo script: # -*- coding: utf-8 -*- from __future__ import division from __future__ import unicode_literals def myDivi(): """ This is a small demo that just returns the output of a divison. >>> myDivi() 0.5 """ return 1/2 def myUnic(): """ This is a small demo that just returns a string. >>> myUnic() 'abc' """ return 'abc' if __name__ == "__main__": import doctest extraglobs = {} doctest.testmod(extraglobs=extraglobs) The doctest passes on Python 3.5, but fails on