Re: python 3.7 - I try to close the thread without closing the GUI is it possible?
> I try to close the thread without closing the GUI is it possible? Qthread seems to be worth investigating: https://medium.com/@webmamoffice/getting-started-gui-s-with-python-pyqt-qthread-class-1b796203c18c -- https://mail.python.org/mailman/listinfo/python-list
Re: python 3.7 - I try to close the thread without closing the GUI is it possible?
Here's a small PyQt example of using Qt's asynchronous facilities: http://zetcode.com/pyqt/qnetworkaccessmanager/ That should get the original poster started. -- https://mail.python.org/mailman/listinfo/python-list
Re: python 3.7 - I try to close the thread without closing the GUI is it possible?
On 09/15/2018 01:23 AM, Albert-Jan Roskam wrote: > > I try to close the thread without closing the GUI is it possible? > > > Qthread seems to be worth investigating: > https://medium.com/@webmamoffice/getting-started-gui-s-with-python-pyqt-qthread-class-1b796203c18c Or better yet, investigate Qt's built-in, asynchronous http request calls. I believe the class is QNetworkRequest (and probably other related classes). This keeps the HTTP request all within the Qt event loop and eliminates the need for threads. Additionally it handles all the problems that might come up, such as connection problems, http errors, etc. It looks complicated, but it's simpler than using a thread. -- https://mail.python.org/mailman/listinfo/python-list
Re: Fumbling with emacs + elpy + flake8
Den 2018-09-13 skrev Brian Oney : > Hi Martin, > > I have messed around alot with the myriad emacs configurations out > there. I found spacemacs and threw out my crappy but beloved .emacs > config. I have looked back, but will stay put. http://spacemacs.org/ > Thanks Brian but not the answer I was looking for this time. I will investigate though. /Martin -- https://mail.python.org/mailman/listinfo/python-list
Re: Fumbling with emacs + elpy + flake8
Den 2018-09-14 skrev Toni Sissala : > I'm on Ubuntu 16.04. I found out that flake8 did not play well with > emacs if installed with --user option, nor when installed in a virtual > environment. Didn't research any further, since I got it working with > plain pip3 install flake8 > Toni, your advice did not work out-of-the-box but it put me on the right track. When I revert to installing flake8 from Debian's repo it works. Strange as I have not done it like that on my primary computer. Both Debian installations but a generation apart. Case closed, I think. /Martin -- https://mail.python.org/mailman/listinfo/python-list
python3.7 - how to open a new thread and close the old each click on a button?
hii all,
python3.7 - how to open a new thread and close the old each click on a button?
here is my code:
# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'AlonStockMarket.ui'
#
# Created by: PyQt5 UI code generator 5.11.2
#
# WARNING! All changes made in this file will be lost!
import time
import sys
import requests
from lxml import html
import requests
import urllib.request, urllib.error, urllib.parse
import _thread
from PyQt5 import QtCore, QtGui, QtWidgets
import threading
global flag
global loopexit
flag=0
loopexit=0
def get_quote(str):
url="https://api.iextrading.com/1.0/stock/"+str+"/price";
resource = urllib.request.urlopen(url)
content =
resource.read().decode(resource.headers.get_content_charset())
print (content)
content=float(content)
return content
def myfunction():
global flag
global loopexit
print ("Executing myfunction in thread: ")
print("hello, world")
while loopexit!=1:
if (loopexit==1):
break
time.sleep(15)
f=open("flag.txt", "r")
if f.mode == 'r':
flag =f.read()
timeHour = int(time.strftime('%H'))
print("keep alive")
print (time.strftime('%H:%M:%S'))
while ((timeHour>16) and (timeHour<23) and loopexit!=1):
if (loopexit==1):
break
print(time.strftime('%H:%M:%S'))
price=get_quote(UserSymbol)
time.sleep(5)
if flag!=time.strftime("%d/%m/%Y") and price>UserStockPrice
and (RadioButtonAbove==True):
print ("send SMS")
import requests
requests.post('https://textbelt.com/text', {
'phone': '+972541234567',
'message': "Hi Alon Najman,EVOK value: "+price,
'key': 'secret',
})
#write to file
with open("flag.txt", "w") as text_file:
text_file.write(format(time.strftime("%d/%m/%Y")))
#read from file
f=open("flag.txt", "r")
if f.mode == 'r':
flag =f.read()
if flag!=time.strftime("%d/%m/%Y") and
pricehttps://textbelt.com/text', {
'phone': '+972546233257',
'message': "Hi Alon Najman,EVOK value: "+price,
'key': 'secret',
})
#write to file
with open("flag.txt", "w") as text_file:
text_file.write(format(time.strftime("%d/%m/%Y")))
#read from file
f=open("flag.txt", "r")
if f.mode == 'r':
flag =f.read()
from PyQt5 import QtCore, QtGui, QtWidgets
class Ui_Dialog(object):
def setupUi(self, Dialog):
Dialog.setObjectName("Dialog")
Dialog.resize(666, 571)
self.radioButton = QtWidgets.QRadioButton(Dialog)
self.radioButton.setGeometry(QtCore.QRect(80, 190, 191, 24))
font = QtGui.QFont()
font.setPointSize(14)
self.radioButton.setFont(font)
self.radioButton.setObjectName("radioButton")
self.buttonGroup_2 = QtWidgets.QButtonGroup(Dialog)
self.buttonGroup_2.setObjectName("buttonGroup_2")
self.buttonGroup_2.addButton(self.radioButton)
self.checkBox = QtWidgets.QCheckBox(Dialog)
self.checkBox.setGeometry(QtCore.QRect(290, 450, 131, 17))
font = QtGui.QFont()
font.setPointSize(14)
self.checkBox.setFont(font)
self.checkBox.setObjectName("checkBox")
self.checkBox_2 = QtWidgets.QCheckBox(Dialog)
self.checkBox_2.setGeometry(QtCore.QRect(290, 480, 141, 17))
font = QtGui.QFont()
font.setPointSize(14)
self.checkBox_2.setFont(font)
self.checkBox_2.setObjectName("checkBox_2")
self.radioButton_2 = QtWidgets.QRadioButton(Dialog)
self.radioButton_2.setGeometry(QtCore.QRect(300, 190, 186, 24))
font = QtGui.QFont()
font.setPointSize(14)
self.radioButton_2.setFont(font)
self.radioButton_2.setObjectName("radioButton_2")
self.buttonGroup_2.addButton(self.radioButton_2)
self.
Re: Experiences with a programming exercise
On Sat, 15 Sep 2018 17:08:57 +, Stefan Ram wrote: > I gave two different functions: > > def triangle(): > for i in range( 3 ): > forward( 99 ); left( 360/3 ) > > def rectangle() > for i in range( 4 ): > forward( 99 ); left( 360/4 ) > > , and the exercise was to write a single definition for a function > »angle( n )« that can be called with »3« to paint a triangle and with > »4« to paint a rectangle. Nearly all participants wrote something like > this: > > def angle( n ): > if n == 3: > for i in range( 3 ): > forward( 99 ); left( 360/3 ) > if n == 4: > for i in range( 4 ): > forward( 99 ); left( 360/4 ) > > Now I have added the requirement that the solution should be as short > as possible! seems a good exercise & you are breaking the students in step by stem which is also good get something that works, then make it better i would suggest instead of the new requirement to be make it a short as possible make it work with ANY number of sides. -- Max told his friend that he'd just as soon not go hiking in the hills. Said he, "I'm an anti-climb Max." [So is that punchline.] -- https://mail.python.org/mailman/listinfo/python-list
Copy constructor and assignment operator
I have created below code and i want to restrict an object copy.
What are the methods called for copy constructor and assignment operator?
Basically i don't want to allow below operation.
p = Point(1,3)
p2 = Point(6,7)
=> How to disallow below operations?
p(p2)
p = p2
Please point out a documentation for the same if available.
class Point:
def _init_(self, x = 0, y = 0):
self.x = x
self.y = y
def _str_(self):
return "({0},{1})".format(self.x,self.y)
def _repr_(self):
return "({0},{1})".format(self.x,self.y)
def _call_(self,other):
print("_call_")
self.x = other.x
self.y = other.y
def _setattr_(self, name, value):
print("_setattr_",name,value)
--
https://mail.python.org/mailman/listinfo/python-list
Re: Add header at top with email.message
> > the EmailMessage class of email.message provides the methods > add_header() and __setitem__() to add a header to a message. > add_header() effectively calls __setitem__(), which does > `self._headers.append(self.policy.header_store_parse(name, val))`. This > inserts the header at the bottom. > > It is, however, sometimes desired to insert a new header at the top of > an (existing) message. This API doesn’t directly allow this. In my > opinion, add_header() should have a flag at_top=False or similar, so > that one can get this behaviour (it’ll be a bit difficult with > __setitem__). What do you think about this? Is there a feasible way to > do this and change the library? Should I post it somewhere where the > devs can hear it and suggest that?\ > I see this in the docs at https://docs.python.org/3/library/email.message.html#email.message.EmailMessage.get_unixfrom : The following methods implement the mapping-like interface for accessing the message’s headers. Note that there are some semantic differences between these methods and a normal mapping (i.e. dictionary) interface. For example, in a dictionary there are no duplicate keys, but here there may be duplicate message headers. Also, in dictionaries there is no guaranteed order to the keys returned by keys(), but in an EmailMessage object, headers are always returned in the order they appeared in the original message, or in which they were added to the message later. Any header deleted and then re-added is always appended to the end of the header list. I suppose you already figured out that you can call __delitem__() to clear the headers and add them back in whatever order you like. I'm interested in learning more about your use case. Do you have a third party with fixed logic that requires the headers in a particular order? -- https://mail.python.org/mailman/listinfo/python-list
Re: Copy constructor and assignment operator
On 2018-09-15 19:47, Ajay Patel wrote:
I have created below code and i want to restrict an object copy.
What are the methods called for copy constructor and assignment operator?
Basically i don't want to allow below operation.
p = Point(1,3)
p2 = Point(6,7)
=> How to disallow below operations?
p(p2)
p = p2
Please point out a documentation for the same if available.
class Point:
def _init_(self, x = 0, y = 0):
self.x = x
self.y = y
def _str_(self):
return "({0},{1})".format(self.x,self.y)
def _repr_(self):
return "({0},{1})".format(self.x,self.y)
def _call_(self,other):
print("_call_")
self.x = other.x
self.y = other.y
def _setattr_(self, name, value):
print("_setattr_",name,value)
"__init__", etc, are referred to as "dunder" methods because they have
double leading and trailing underscores. Those that you wrote have only
single leading and trailing underscores.
The term "copy constructor" is something from C++. It doesn't exist in
Python.
Assignment statements _never_ copy an object. If you want a copy of an
object, you have to be explicit.
Writing:
p = p2
will merely make 'p' refer to the same object that 'p2' currently refers to.
For making a copy of an object, have a look at the "copy" module.
--
https://mail.python.org/mailman/listinfo/python-list
