Re: JavaScript's void operator in Python?

2020-02-02 Thread Jon Ribbens via Python-list
On 2020-02-02, Stefan Ram  wrote:
>   JavaScript has a void operator that maps everything to
>   undefined. E.g.,
>
>   JavaScript console
>
>|< void( console.log( 2 ) )
>|  2
>|> undefined
>
>   I can easily write a corresponding function in Python.
>
>   main.py
>
> def void( x ):
> pass
>
> void( ( print( 2 ), print( 3 )))
>
>   transcript
>
> 2
> 3
>
>   . But is an operator or a function like that already 
>   defined in Python or its standard library?

I'm not sure why you'd want to - but "None and foo" is an expression
that will return None regardless of the value of "foo".
-- 
https://mail.python.org/mailman/listinfo/python-list


App made with pyinstaller is not running on another computer.

2020-02-02 Thread Souvik Dutta
Hi,
I made an executable file with pyinstaller on my pc which had python 3.7.
It ran well in my pc but when I tried to run it on my friend computer
having a 32 bit windows 10 os it didn't run it is just saying that "this
app cannot be run on your pc". My pc has a 64 bit version of windows 10 and
also my friend does not has any version of python installed. Can you help
me solve this problem? Thank you for your precious time.
-- 
https://mail.python.org/mailman/listinfo/python-list


PyQt5 help on buttons and grid layout

2020-02-02 Thread Souvik Dutta
Hi,
I want to add about 40 buttons based upon a dictionary. I want them to be
added to a grid layout. How can I do it easily. Please write the code and
thank you for your trouble.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: App made with pyinstaller is not running on another computer.

2020-02-02 Thread Chris Angelico
On Mon, Feb 3, 2020 at 2:57 AM Souvik Dutta  wrote:
>
> Hi,
> I made an executable file with pyinstaller on my pc which had python 3.7.
> It ran well in my pc but when I tried to run it on my friend computer
> having a 32 bit windows 10 os it didn't run it is just saying that "this
> app cannot be run on your pc". My pc has a 64 bit version of windows 10 and
> also my friend does not has any version of python installed. Can you help
> me solve this problem? Thank you for your precious time.

Easy fix: Have your friend install Python, and then just give him/her
the .py file instead of using pyinstaller. Way WAY easier and more
reliable.

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


Re: App made with pyinstaller is not running on another computer.

2020-02-02 Thread Abdur-Rahmaan Janhangeer
recompile with the latest dev versio  of pyinstaller, fixed my issue.

On Sun, 2 Feb 2020, 19:55 Souvik Dutta,  wrote:

> Hi,
> I made an executable file with pyinstaller on my pc which had python 3.7.
> It ran well in my pc but when I tried to run it on my friend computer
> having a 32 bit windows 10 os it didn't run it is just saying that "this
> app cannot be run on your pc". My pc has a 64 bit version of windows 10 and
> also my friend does not has any version of python installed. Can you help
> me solve this problem? Thank you for your precious time.
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: PyQt5 help on buttons and grid layout

2020-02-02 Thread Abdur-Rahmaan Janhangeer
d = {}

layout = ...


for key in d:
layout.addWidget(QButton(...))


On Sun, 2 Feb 2020, 19:59 Souvik Dutta,  wrote:

> Hi,
> I want to add about 40 buttons based upon a dictionary. I want them to be
> added to a grid layout. How can I do it easily. Please write the code and
> thank you for your trouble.
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: JavaScript's void operator in Python?

2020-02-02 Thread Python

Stefan Ram wrote:

Jon Ribbens  writes:

On 2020-02-02, Stefan Ram  wrote:

void( ( print( 2 ), print( 3 )))
2
3

I'm not sure why you'd want to - but "None and foo" is an expression
that will return None regardless of the value of "foo".


   Yes, but it also does not evaluate the second operand. I.e.,

None and( print( 2 ), print( 3 ))

   prints nothing at all.

   I was looking for something that still evaluates and then
   maps the value obtained to None.


( (print(2), print(3)), None)[1]

I wonder why one would need such a thing, though...
--
https://mail.python.org/mailman/listinfo/python-list


My Python programming book for kids is free for 48 hours

2020-02-02 Thread Kent Tong
Hi,

If you're interested, please get it for free at:
https://www.amazon.com/Yes-Kids-can-learn-Python-ebook/dp/B084CY2L43/ref=sr_1_3

This is a set of training materials I used to successfully teach Python to kids 
as little as 10 years old. The online learning environment are freely available 
at https://p4kweb.appspot.com and the first four chapters are available at 
https://www.istudycenter.org/yes-kids-can-learn-python.
Lesson 1: Call a function & use variables
Lesson 2: Expressions and text strings
Lesson 3: Perform various calculations based values input by the user
Lesson 4: Use the tank to draw shapes with its bombs
Lesson 5: Show an input box and use "if" in Python
Lesson 6: Prompt for multiple values and display information in a message box
Lesson 7: increase the value of a variable and call a function that gives back 
information
Lesson 8: Use "if" without "else"
Lesson 9: Use "if" to guard against an operation that might fail
Lesson 10: 2D coordinate system for positioning objects
Lesson 11: Respond to mouse clicks and kick start a continuous process
Lesson 12: Use random numbers
Lesson 13: Use 'and' or embedded 'if's
Lesson 14: Respond to key presses
Lesson 15: Respond to key presses (2)
Lesson 16: Boolean values and stop a continuous process
Lesson 17: stop a continuous process (2)
Lesson 18: Steer a continuous process
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Pyqt5 help

2020-02-02 Thread Alan Gauld via Python-list
On 01/02/2020 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.

What is happening? Don't expect us to run your buggy code!

>  Now the no. Of labels depend upon something, so I decided to
> use a for loop which is not working.

Looking at the code I see:


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))

I'm no Qt expert but it seems that you are overwriting the same widget
(or widget location?) with all of the labels? And all of the labels are
identical since you use the same data to create them?


I would expect something more like (pseudo code!):

for a in self.n:
newLabel = QtWidgets.QLabel(self)
NewLabel.setText(self.friends[a].friend_name + "has birthday on " +
 self.friends[a]._date)
NewLabel.setGeometry(QtCore.QRect(self.calculateGeometry(a))
self.friendLabels.append(newLabel)   # if you need a reference


-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos


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


Re: Please answer fast.....

2020-02-02 Thread Abdur-Rahmaan Janhangeer
I'm 100% ready to answer your question, just add some more details like why
you need 40 labels.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Pyqt5 help

2020-02-02 Thread Alan Gauld via Python-list
On 01/02/2020 12:06, Souvik Dutta wrote:

> 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?

I just spotted something else odd in your code:


  def initUi(self):
   ...
   self.n = {}

self.n is a dictionary maybe self.friends would be a better name?

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

And here you add a new value from your UI fields

for a in self.n:

Now you iterate over the dictionary creating a label
for each entry in the dict but...

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

The labels all have the name of the most recent friend?
And they all have the same geometry, so presumably sit
on top of each other?

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos


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


Re: Please answer fast.....

2020-02-02 Thread Abdur-Rahmaan Janhangeer
Ah ok.

suggest you put names, birthday in csv

the load csv

for each row:
layout.addWidget(QLabel)

On Sun, 2 Feb 2020, 21:21 Souvik Dutta,  wrote:

> Because i want to show the name and date of 40 persons and their birthdays.
>
> On Sun, Feb 2, 2020, 10:42 PM Abdur-Rahmaan Janhangeer <
> [email protected]> wrote:
>
>> I'm 100% ready to answer your question, just add some more details like
>> why you need 40 labels.
>>
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Please answer fast.....

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

On 3/02/20 7:05 AM, Abdur-Rahmaan Janhangeer wrote:
...


suggest you put names, birthday in csv

the load csv

for each row:
 layout.addWidget(QLabel)

On Sun, 2 Feb 2020, 21:21 Souvik Dutta,  wrote:


Because i want to show the name and date of 40 persons and their birthdays.



Why csv?

Why prefer that over native-Python constructs, eg two 40-element lists, 
a list of (pairs) lists, or indeed a dict with name as 'key' and date as 
'value'?


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


Re: JavaScript's void operator in Python?

2020-02-02 Thread Greg Ewing

On 3/02/20 3:38 am, Stefan Ram wrote:


void( ( print( 2 ), print( 3 )))


If the functions you're calling all return None, you can
do this:

>>> print(2); print(3)
2
3

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


Re: JavaScript's void operator in Python?

2020-02-02 Thread Jon Ribbens via Python-list
On 2020-02-02, Stefan Ram  wrote:
> Greg Ewing  writes:
>>If the functions you're calling all return None, you can
>>do this:
>> >>> print(2); print(3)
>
>   »print(2); print(3)« is not an expression anymore but an stmt_list.
>   It cannot be used in all places where an expression is allowed.

Why does it matter if the return value is None?

"print(2), print(3)" is an expression that will evaluate all of its
sub-expressions. If the sub-expressions return None then I guess you
could do "(x, y, z)[0]" too.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: JavaScript's void operator in Python?

2020-02-02 Thread Jon Ribbens via Python-list
On 2020-02-02, Stefan Ram  wrote:
> Jon Ribbens  writes:
>>Why does it matter if the return value is None?
>
>   In a lambda, a return value of None sometimes would be
>   convenient as by convention it indicates that the return
>   value does not carry any information and the function is
>   intended to be used just for its effect. A value of None
>   will not be printed in the console, so it does not add
>   distracting noise there.

If it's a lambda then the arguments will be evaluated before the
lambda is called anyway, so:

>>> f = lambda *x: None
>>> f(print(2), print(3))
2
3

Or if you're writing it inline then:

>>> (None, print(2), print(3))[0]
2
3
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Please answer fast.....

2020-02-02 Thread Abdur-Rahmaan Janhangeer
CSV as data entry with " " is a pain.

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


The source of the PSL*

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

Is there a set location for PSL project repos?
(it used to be GitHub, and before that, Google)

I'd like to review some serious PyTest/Unittest examples, eg as are 
applied to familiar (Python source) library members...


* should be easier to find than was the source of the Nile (by Europeans)
--
Regards,
=dn
--
https://mail.python.org/mailman/listinfo/python-list


lxml - minor problem appending new element

2020-02-02 Thread Frank Millman

Hi all

I usually send lxml queries to the lxml mailing list, but it appears to 
be not working, so I thought I would try here.


This is a minor issue, and I have found an ugly workaround, but I 
thought I would mention it.


In Python I can iterate through a list, and on a certain condition 
append a new item to the list, which is then included in the iteration.


>>> x = ['a', 'b', 'c']
>>> for y in x:
...   print(y)
...   if y == 'b':
... x.append('d')
...
a
b
c
d
>>> x
['a', 'b', 'c', 'd']
>>>

The same thing works in lxml -

>>> lmx = ''
>>> xml = etree.fromstring(lmx)
>>> for y in xml:
...   print(etree.tostring(y))
...   if y.get('z') == 'b':
... xml.append(etree.Element('y', attrib={'z': 'd'}))
...
b''
b''
b''
b''
>>> etree.tostring(xml)
b''

However, if it happens that the condition is met on the last item in the 
list, Python still works, but lxml does not include the appended item in 
the iteration. In the following, the only change is checking for 'c' 
instead of 'b'.


>>> x = ['a', 'b', 'c']
>>> for y in x:
...   print(y)
...   if y == 'c':
... x.append('d')
...
a
b
c
d
>>> x
['a', 'b', 'c', 'd']
>>>

>>> lmx = ''
>>> xml = etree.fromstring(lmx)
>>> for y in xml:
...   print(etree.tostring(y))
...   if y.get('z') == 'c':
... xml.append(etree.Element('y', attrib={'z': 'd'}))
...
b''
b''
b''
>>> etree.tostring(xml)
b''

As you can see, the last element is correctly appended, but is not 
included in the iteration.


Is there any chance that this can be looked at, or is it just the way it 
works?


BTW, I see that ElementTree in the standard library does not have this 
problem.


Thanks

Frank Millman

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