python-2.7

Python - sets .pop() behaviour

て烟熏妆下的殇ゞ 提交于 2021-01-28 04:20:49
问题 This is the strange thing I noticed in Python sets. I read there is no order in sets, but it does pop lower elements from 0 till 79 and later from 79 till 127. It does not pop the lower ones any more. Only after 128 comes in 79 is popped. Why is it like this? Is there any alternative where I can use the ordered data structure in Python? Why is it popping the lowest from 0 till 79 and not from 79 till 127? >>s = set() >>s.add(72) >> s.add(74) >> s.add(76) >> s.pop() 72 >> s.add(79) >> s.pop()

Shallow or deep copy in a list comprehension

爷,独闯天下 提交于 2021-01-28 03:04:30
问题 If you have a list (Original) in python like: class CustomID (object): def __init__(self, *args): self.ID = '' self.manymore = float() self.visited = False self.isnoise = False IDlist = ['1','2','3','4','5','6','7','8','9','10'] Original = list() for IDs in IDlist: NewObject = CustomID() NewObject.ID = IDs Original.append(NewObject) and if you do a comprehension for a new list and a function to use over the comprehension sublist: def Func(InputList=list()): for objects in InputList: objects

Pulling data from datastore and converting it in Json in python(Google Appengine)

末鹿安然 提交于 2021-01-28 03:02:14
问题 I am creating an apllication using google appengine, in which i am fetching a data from the website and storing it in my Database (Data store).Now whenever user hits my application url as "application_url\name =xyz&city= abc" ,i am fetching the data from the DB and want to show it as json.Right now i am using a filter to fetch data based on the name and city but getting output as [ ].I dont know how to get data from this.My code looks like this: class MainHandler(webapp2.RequestHandler): def

getting module import error while running PyInstaller generated binary

耗尽温柔 提交于 2021-01-28 02:20:33
问题 I'm getting an error while trying to a simple hello.py using PyInstaller on RHEL X64. Python 2.7.12 is alt installed in /opt/python Compilation Output: [root@myrig CommandManager]# pyinstaller Hello.py 21 INFO: PyInstaller: 3.2 21 INFO: Python: 2.7.12 22 INFO: Platform: Linux-3.10.0-327.22.2.el7.x86_64-x86_64-with-redhat-7.2-Maipo 62 INFO: wrote /home/myuser/CommandManager/Hello.spec 66 INFO: UPX is not available. 107 INFO: Extending PYTHONPATH with paths ['/home/myuser/CommandManager', '

Sharing queue between threads running in different modules

旧城冷巷雨未停 提交于 2021-01-28 02:19:29
问题 I have some modules in different packages for my project. This project requires several threads which might be started in different modules, and I intend to use queues for the inter-thread communication. Is there a way to pass a queue created in one module for use in another module? # ModuleA.py myQueue = Queue.Queue() thread = myThread(threadID1, tName1, myQueue) thread2 = myThread(threadID2, tName2, myQueue) # ModuleB.py myQueue = get_the_previous_queue_created() # possible? thread3 =

wxpython refresh window on button press

≯℡__Kan透↙ 提交于 2021-01-28 02:03:17
问题 I have been having some trouble with my Python program. Basically, it is a very very simple file manager. I have been trying to get it to move between folders (user clicks a folder, program refreshes display and shows contents of folder). The problem I am having is that I cant seem to get the button to refresh the display and then fill it with the new folders and files when clicked. Here is the code I am using and it is on Linux. import wx import fileBrowser class interface(wx.Frame): def _

AttributeError: 'xml.etree.ElementTree.Element' object has no attribute '_children'

佐手、 提交于 2021-01-28 01:35:40
问题 I have the following code : def result_saml_decoded(result_saml): """Illustrate to result saml decoded value as response in a string. :param result_saml:results saml decoded :return:return principle_arn, resultsamldecoded, role_arns """ result_saml_decoded = base64.b64decode(result_saml) root = ET.fromstring(result_saml_decoded) principle_arns, role_arns = [], [] inner_saml_tag = [saml2 for saml2 in root._children if 'Assertion' in saml2.tag] attribute_saml_tag = [saml_tag for saml_tag in

in pyqt how to print “Ctrl+key” in QLineEdit when pressed Ctrl + anyKey

放肆的年华 提交于 2021-01-28 00:44:41
问题 here my kode where I generated event for QLineEdit to put pressed key combination in textline it Ok for Shift key and Alt key but not for Ctrl key why ? #!/usr/bin/python import sys from PyQt4.QtCore import * from PyQt4.QtGui import * def main(): app = QApplication(sys.argv) w = MyWindow() w.show() sys.exit(app.exec_()) class MyWindow(QWidget): def __init__(self, *args): QWidget.__init__(self, *args) self.la = QLabel("Press tab in this box:") self.le = MyLineEdit() layout = QVBoxLayout()

How to update the progress bar using with pyqt4

牧云@^-^@ 提交于 2021-01-27 23:36:26
问题 Here it is sample program i want to update the my progress bar using with pyqt4.and i want to show th3 30% data saving and another 60% data processing.I am executing the my program it is aborting.Can any one please help me how to update the my progress bar.Thank you in advance. Given below is my code: import sys import time from pyface.qt import QtGui, QtCore global X,Y X= 5 Y= 4 import threading class SaveWorker(QtCore.QObject): progress_update = QtCore.Signal(int) def save_file(self): while

Why do strings in python 2.7 not have the “__iter__” attribute, but strings in python 3.7 have the “__iter__” attribute

风流意气都作罢 提交于 2021-01-27 22:51:04
问题 In both python 2.7 and python 3.7 I am able to do the following: string = "hello world" for letter in string: print(letter) But if I check for the iterable attribute: python 2.7 hasattr(string, "__iter__") >> False python 3.7 hasattr(string, "__iter__") >> True This is something that I have not found to be documented when making a 2to3 migration, and it has caused a little headache because I have hasattr(entity, "__iter__") checks in my code. In python 2.7 this works to differentiate a string