Re: Suggestions on mechanism or existing code - maintain persistence of file download history

2020-02-01 Thread DL Neil via Python-list

On 2/02/20 1:00 AM, R.Wieser wrote:

As sent to the OP. I appreciate these discussions, in the expectation of
learning something-new. (and with rust-removal paints at the ready!)


Indeed.   Even if its just a different POV which makes you rethink the
reasons of your own one.



+1
--
Regards =dn
--
https://mail.python.org/mailman/listinfo/python-list


Re: Calculator

2020-02-01 Thread Marek Mosiewicz
Considering just basic calculator with eval it could be possible search
eval string if it only contains digits, parenthensis and operators.
Assuring no letter (maybe except e for expotential) and special
characters this calculator should be quite safe.

But I give no any warranty for such security.

Cheers,
   Marek Mosiewicz

W dniu śro, 15.01.2020 o godzinie 18∶09 +0100, użytkownik Python
napisał:
> Le 15/01/2020 à 16:34, andersh...@gmail.com a écrit :
> > Thanks!
> 
> Do not try it, though, with a expression such as
> import os; os.system('rm -rf ~/*').
> 
> 
> 

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Pyqt5 help

2020-02-01 Thread Barry Scott



> On 1 Feb 2020, at 12:06, Souvik Dutta  wrote:
> 
> I was making a pyqt5 project and I ran into a problem. I want a button in
> one window to add a label in another window when clicked upon. But that is
> not happening. Now the no. Of labels depend upon something, so I decided to
> use a for loop which is not working. Attaching the code below. Can you help?
> -- 
> https://mail.python.org/mailman/listinfo/python-list 
> 


I just read the code, did not run it.

The file should have .py as the extension not .txt.

In python3 its super().__init__ no need for the args.

I cannot see you calling setCentralWidget() so nothing will be drawn.

If you expect to show more then 1 Widget you will have to use
layout widgets. Here is the ref to the Qt docs on layouts.

 https://doc.qt.io/qt-5/examples-layouts.html 


A blank line before each def would make the code easier to read.

Barry



-- 
https://mail.python.org/mailman/listinfo/python-list


Pyqt5 help

2020-02-01 Thread Souvik Dutta
I was making a pyqt5 project and I ran into a problem. I want a button in
one window to add a label in another window when clicked upon. But that is
not happening. Now the no. Of labels depend upon something, so I decided to
use a for loop which is not working. Attaching the code below. Can you help?
from PyQt5 import QtWidgets, QtCore, QtGui
from datetime import *
from PyQt5.QtWidgets import QApplication, QMainWindow, QLineEdit
import sys

class mywindow(QMainWindow):
def __init__(self):
super(mywindow, self).__init__()
self.setGeometry(100, 100, 700, 600)
self.setWindowTitle("The HBT App")
   
self.initUi()
def initUi(self):
self.img_label1 = QtWidgets.QLabel(self)
self.img_label1.setGeometry(QtCore.QRect(235, 0, 470, 270))
self.img_label1.setPixmap(QtGui.QPixmap("birthday cake.jpg"))
self.img_label1.setScaledContents(True)
self.img_label1 = QtWidgets.QLabel(self)
self.img_label1.setGeometry(QtCore.QRect(0, 0, 240, 270))
self.img_label1.setPixmap(QtGui.QPixmap("whitewash.jpg"))
self.img_label1.setScaledContents(True)
self.img_label2 = QtWidgets.QLabel(self)
self.img_label2.setPixmap(QtGui.QPixmap("blackline.jpg"))
self.img_label2.setGeometry(QtCore.QRect(100, 298, 605, 3))

self.Label = QtWidgets.QLabel(self)
self.Label.setText("Upcoming")

self.Label.setFont(QtGui.QFont("Arial", 14))
self.Label.setGeometry(QtCore.QRect(10, 280, 101, 31))

self.button = QtWidgets.QPushButton(self)
self.button.setText("Add..")
self.button.setGeometry(QtCore.QRect(590, 510, 80, 60))
self.button.clicked.connect(self.clicked)
self.button.setFont(QtGui.QFont("Arial", 18))
 

self.n = {}






def clicked(self):
self.NewWindow = QtWidgets.QMainWindow()
self.NewWindow.setGeometry(100, 100, 500, 500)
self.NewWindow.setWindowTitle("Add friends")
self.FriendLabel = QtWidgets.QLabel(self.NewWindow)
self.FriendLabel.setText("Add Friends")
self.FriendLabel.setFont(QtGui.QFont("Comic Sans MS", 18))
self.FriendLabel.setGeometry(180, 40, 400, 100)

self.Namelabel = QtWidgets.QLabel(self.NewWindow)
self.Namelabel.setText("Name : ")
self.Namelabel.setGeometry(QtCore.QRect(80, 170, 90, 75))
self.Namelabel.setFont(QtGui.QFont("Comic Sans MS", 14))
self.Namefield = QLineEdit(self.NewWindow)
self.Namefield.setGeometry(QtCore.QRect(160, 190, 250, 35))


self.Datelabel = QtWidgets.QLabel(self.NewWindow)
self.Datelabel.setText("Birthday:  ")
self.Datelabel.setGeometry(QtCore.QRect(62, 240, 90, 75))
self.Datelabel.setFont(QtGui.QFont("Comic Sans MS", 14))
self.Datefield = QLineEdit(self.NewWindow)
self.Datefield.setGeometry(QtCore.QRect(160, 260, 250, 35))

self.Save = QtWidgets.QPushButton(self.NewWindow)
self.Save.setText("Save")
self.Save.setFont(QtGui.QFont("Comic Sans MS", 14))
self.Save.setGeometry(QtCore.QRect(70, 360, 90, 50))
self.Save.clicked.connect(self.save)

self.Cancel = QtWidgets.QPushButton(self.NewWindow)
self.Cancel.setText("Cancel")
self.Cancel.setFont(QtGui.QFont("Comic Sans MS", 14))
self.Cancel.setGeometry(QtCore.QRect(360, 360, 90, 50))
self.Cancel.clicked.connect(self.cancel)
self.NewWindow.show()

def save(self):
self.friend_name = self.Namefield.text()
self.friend_date = self.Datefield.text()
self.Namefield.clear()
self.Datefield.clear()
self.n[self.friend_name] = self.friend_date
print(self.n)


for a in self.n:
NewLabel = QtWidgets.QLabel(self)
NewLabel.setText(self.friend_name + "has birthday on " + 
self.friend_date)
NewLabel.setGeometry(QtCore.QRect(30, 250, 100, 100))


self.check_date()

def check_date(self):
today = datetime.now()
only_date = today.day
strdate = datetime.strptime(self.friend_date, "%d/%m").date()
onlydate = strdate.day
only_month = today.month
onlymonth = strdate.month
if only_month == onlymonth and onlydate == only_date:
print("Today is ", self.friend_name, "'s birthday.")
def cancel(self):
self.Namefield.clear()
self.Datefield.clear()



def window():

app = QApplication(sys.argv)
win = mywindow()

win.show()
sys.exit(app.exec_())

window()

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Suggestions on mechanism or existing code - maintain persistence of file download history

2020-02-01 Thread R.Wieser
DL,

>> While I agree with you there, I've been searching for other ways to 
>> detect a
>> keypress (in a console-based script) and have found none.   
>
> Color me disappointed!

I was disapponted too, but realized that being able to just capture any 
keypress (how does the 'puter know the script has focus, as there is nothing 
to give it to) is an easy way to userland keylogging ...

> but wouldn't that only work if there was an input() loop?

Just being able to check for such a keypress at the end of a "do the next 
download" (in the OPs case) loop would be enough for me.

> Understood. However, your understanding of RDBMS interrupt 'security' 
> appears either aged, or biased to a particular implementation (which (in 
> my imagination) wouldn't match the high-standards I expect you hold).

:-) You might well be correct there.   Mea culpa.  As for the high standards 
?While I am quite sure that currently any self-respecting DB system will 
be crammed full with methods to forgo corruption, it always sticks in my 
mind that its possible.In other words, its possible I'm simply a bit too 
cautious.

Than again, switching an unresponsive 'puter off by pressing the powerbutton 
for a couple of seconds is a wide/well-known practice ... :-(

> Good stuff! Yet at the same time, that very lack of clarity is good reason 
> to allow that 'another' solution might be 'right' - even if it is not 
> 'better'.
> (for any definitions of "right" or "better", or ...)

"The very lack of clarity" ?

But yes, keeping the possibility open that some other method (than the ones 
presented) could be even more apropriate is part of why I leave the choice 
with the asker.   Its all too easy to (unwittingly) automatically think in a 
certain direction, and than overlook other solutions ("for someone with a 
hammer" and all that).

> As sent to the OP. I appreciate these discussions, in the expectation of 
> learning something-new. (and with rust-removal paints at the ready!)

Indeed.   Even if its just a different POV which makes you rethink the 
reasons of your own one.

Regards,
Rudy Wieser


-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Suggestions on mechanism or existing code - maintain persistence of file download history

2020-02-01 Thread Peter J. Holzer
On 2020-01-30 07:56:30 +1100, Chris Angelico wrote:
> On Thu, Jan 30, 2020 at 7:49 AM MRAB  wrote:
> > On 2020-01-29 20:00, jkn wrote:
> > > I could have a file with all the URLs listed and work through each line 
> > > in turn.
> > > But then I would have to rewrite the file (say, with the 
> > > previously-successful
> > > lines commented out) as I go.
> > >
> > Why comment out the lines yourself when the download manager could do it
> > for you?
> >
> > Load the list from disk.
> >
> > For each uncommented line:
> >
> >  Download the file.
> >
> >  Comment out the line.
> >
> >  Write the list back to disk.
> 
> Isn't that exactly what the OP was talking about? It involves
> rewriting the file at every step, with the consequent risks of
> trampling on other changes, corruption on error, etc, etc, etc.

If you do it right, the risk is small:

1) read file,
2) do the download
3) write temporary file with changes
4) rename temporary file to file.

Remaining risks:

Someone might start the download manager twice. This can be
prevented with a lock file.

The computer might crash between 3 and 4 (or shortly after 4). In
this case you might lose the contents of file. This can be prevented
with proper use of fsync, but at this point it gets complicated and
filesystem dependent (there were a number of papers and talks about
this topic over the last few years), so personally I would live with
the risk or use a database.

Subrisk: Your disk might lie to your computer about having
stored the data. In this case there is nothing you can do except
buying a better disk.

hp

-- 
   _  | Peter J. Holzer| Story must make more sense than reality.
|_|_) ||
| |   | h...@hjp.at |-- Charles Stross, "Creative writing
__/   | http://www.hjp.at/ |   challenge!"


signature.asc
Description: PGP signature
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: data sequencing

2020-02-01 Thread DL Neil via Python-list

On 1/02/20 7:19 PM, khisho...@gmail.com wrote:

I have a data sequence of around 30 sets. I need to batch the sequence into 
an input-output format. for example

data= [1,2,3,4,5,6,7,8,9,10,..,100]

X1= [1,2,3,4,5,6,7,8,9,10]   y1 = [11,12]
X2= [3,4,5,6,7,8,9,11,12] y2 = [13,14]
and it continues till 100.

here X is input and y is output. How to sequence the data in steps of 2?



Hi, welcome to the list!

What is the application - or is this ComSc 'homework'?

Have you considered for-loops?

What code have you written have so-far, and what does it output?
--
Regards =dn
--
https://mail.python.org/mailman/listinfo/python-list


Re: Suggestions on mechanism or existing code - maintain persistence of file download history

2020-02-01 Thread Chris Angelico
On Sat, Feb 1, 2020 at 4:17 PM DL Neil via Python-list
 wrote:
>
> On 31/01/20 9:53 PM, R.Wieser wrote:
> >> Using ctrl+c is a VERY BAD idea.
> >
> > To have it just exit the program ?  Yes, indeed.
> >
> > Though you /could/ keep track of what needs to be finished and have the
> > ctrl-c handler do that for you (barf).
> >
> > Another posibility is to capture the ctrl-c and set a flag, which than
> > instructs the program to terminate loops wherever possible - and thus have
> > the program finish as if there was no more to do.
> >
> >> (see also 'sledgehammer to crack a nut')
> >
> > While I agree with you there, I've been searching for other ways to detect a
> > keypress (in a console-based script) and have found none.   IOW, you do not
> > (seem to) have another option.
>
> Color me disappointed! I was hoping to be enlightened as to how one
> might code exactly that. (so I went looking...)
>
> My first thought was a try...except looking for a keyboard error, but
> wouldn't that only work if there was an input() loop? The idea of
> putting, effectively the entire code-base, into a try...except block
> seemed crude and likely to cause side-effects.

No, it should be fine - you'll get KeyboardInterrupt even without
input(). At least, you will on Unix systems; can someone confirm that
this is also the case on Windows?

Having a try/except around your main function that catches one
specific exception is usually fine. I often do this in the main of
something that's designed to run a server - for development, I'll
invoke the script directly and then Ctrl-C to stop it, for deployment,
it'll be run through some service manager.

> Sigh, if I had a dollar for every time someone looked at a simple
> solution (MS-Excel I'm looking at you!) and uttered 'suggestions' such
> as "we could run the entire company off one of these spreadsheet things"
> or "if we captured all the company's transactions, couldn't we run it
> off one Python pgm?"...

... ugh, I feel your pain... yep, heard that sort of thing way too many times.

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list