Re: RE: Problem resizing a window and button placement

2024-02-27 Thread Alan Gauld via Python-list
On 27/02/2024 07:13, Steve GS via Python-list wrote:

> Aside from using it to resized
> the window, is there no way to
> know the last value of the
> change for use in the program?

The last value would be the current width.
And you know how to get that as shown in
your configure function:

Ww = root.winfo_width()

> I could write the value to a
> label and read it back later

That's no different to writing it to
global Ww and accessing that as demonstrated
in my last code post (with button).

>>>  It's better just to ask tk
> for the values whenever you
> need them, as you do inside
> your handler.
> 
> How would that be done?

Ww = root.winfo_width()

Provided you can access the root widget
(which is (nearly?) always true) you
can get the width of the main window.

But can I ask if you have a particular use-case
in mind for this? We started out talking about
relocating some widgets when the window was
resized. We established that the best place
to do that was inside the configure event
handler, with no need to store the width.
(assuming you aren't using a dynamic layout
manager(grid/pack/form) which would be better
still!)

We've now moved on to the more general issue
of communicating values between event handlers
(although still using the width as our exemplar).
Is this just academic interest or do you have
a specific need for this? If we know the need
we might be able to suggest a specific (and
possibly better?)solution.

-- 
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: Problem resizing a window and button placement

2024-02-26 Thread Steve GS via Python-list
>> The configuration event
hasn't fired at the time you
include the print statement in
the handler's def block, and
therefore the print function
inside your handler hasn't
invoked.  It won't be invoked
until you resize the window.

Exactly

>> There is no point (really?)
to saving the width and height
outside your
on_configure() function,
because outside that function
you can't know if they have
been changed.  There could
even have been a race
condition where you use one
but the other changes before
you get around to using it. 

Aside from using it to resized
the window, is there no way to
know the last value of the
change for use in the program?
I could write the value to a
label and read it back later
in the process but that sounds
to be klugy.

>>  It's better just to ask tk
for the values whenever you
need them, as you do inside
your handler.

How would that be done?



SGA

-Original Message-
From: Python-list
 On
Behalf Of Thomas Passin via
Python-list
Sent: Monday, February 26,
2024 8:34 AM
To: python-list@python.org
Subject: Re: Problem resizing
a window and button placement

On 2/26/2024 6:02 AM, Steve GS
via Python-list wrote:
> Although your code produces
the value of Ww outside the
function, I do not see how I
can use the value of Ww unless
I close the program.

The configuration event hasn't
fired at the time you include
the print statement in the
handler's def block, and
therefore the print function
inside your handler hasn't
invoked.  It won't be invoked
until you resize the window.

There is no point to saving
the width and height outside
your
on_configure() function,
because outside that function
you can't know if they have
been changed.  There could
even have been a race
condition where you use one
but the other changes before
you get around to using it.
It's better just to ask tk for
the values whenever you need
them, as you do inside your
handler.

> import tkinter as tk
> 
> Ww = None  # What does this
do? Why not Integer?
> WwZ = None
# These could be integers,
like 0, but that would not be
the correct # window sizes at
that point. The window is
either not constructed or it #
has some definite size that is
not zero.

> def on_configure(*args):
>  global Ww
>  global WwZ
>  Ww =
root.winfo_width()
>  print("9  Ww Inside
=<"+str(Ww)+">")  # works
>  WwZ = Ww * 2
>  print("11  WwZ
Inside =<"+str(WwZ)+">")  #
works
>  return(Ww)  #Can I
use this?
>  
> root = tk.Tk()
>
root.bind('',on_con
figure)
> print("15  Ww Inside1 =
<"+str(Ww)+">")
> #Ww2 = int(Ww) * 2  # fails
> print("17  WwZ Inside2 =
<"+str(WwZ)+">")
> 
> root.mainloop()
> 
> Ww2 = int(Ww) * 2  #Works
but only after the program
stops
> print("21  Ww Outside2 =
<"+str(WwZ)+">") # Can I have
concentric 
> loops?
> 
> 
> SGA
> 
> -Original Message-
> From: Alan Gauld

> Sent: Monday, February 26,
2024 4:04 AM
> To: Steve GS
;
python-list@python.org
> Subject: Re: RE: Problem
resizing a window and button
placement
> 
> On 26/02/2024 07:56, Steve
GS via Python-list wrote:
> 
>> Then there is that
discovery
>> element: Why is my original
>> idea not working? I still
>> cannot pass the value back
>> from the function.  What is
>> different about this
function
>> that others would have
given
>> me the value?
> 
> There is nothing different,
see the code below.
> print() is a function like
any other.
> In this case it is called
after you close the window, ie
after mainloop() exits.
> But any other function
called inside
> mainloop - eg any other
event handler can also access
it.
> 
> For example, if you added a
button:
> 
> def printW(): print("Button
Ww = ", Ww)
> 
> bw = tk.Button(root,
text="Print Width",
command=printW)
> bw.pack()
> 
> You would be able to print
the value on demand.
> 
>>> import tkinter as tk
>>>
>>> Ww = None
>>>
>>> def on_configure(*args):
>>>  global Ww
>>>  Ww =
root.winfo_width()
>>>  print("Ww Inside
=<"+str(Ww)+">")
>>>
>>> root = tk.Tk()
>>>
root.bind('',on_con
figure)
>>> root.mainloop()
>>>
>>> print("Ww Outside =
<"+str(Ww)+">")
> 
> --
> Alan G
> Author of the Learn to
Program web site
http://www.alan-g.me.uk/ 
>
http://www.amazon.com/author/a
lan_gauld
> Follow my photo-blog on
Flickr at:
>
http://www.flickr.com/photos/a
langauldphotos
> 
> 

--
https://mail.python.org/mailma
n/listinfo/python-list

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


Re: Problem resizing a window and button placement

2024-02-26 Thread Thomas Passin via Python-list

On 2/26/2024 6:02 AM, Steve GS via Python-list wrote:

Although your code produces the value of Ww outside the function, I do not see 
how I can use the value of Ww unless I close the program.


The configuration event hasn't fired at the time you include the print 
statement in the handler's def block, and therefore the print function 
inside your handler hasn't invoked.  It won't be invoked until you 
resize the window.


There is no point to saving the width and height outside your 
on_configure() function, because outside that function you can't know if 
they have been changed.  There could even have been a race condition 
where you use one but the other changes before you get around to using 
it.  It's better just to ask tk for the values whenever you need them, 
as you do inside your handler.



import tkinter as tk

Ww = None  # What does this do? Why not Integer?
WwZ = None

# These could be integers, like 0, but that would not be the correct
# window sizes at that point. The window is either not constructed or it
# has some definite size that is not zero.


def on_configure(*args):
 global Ww
 global WwZ
 Ww = root.winfo_width()
 print("9  Ww Inside =<"+str(Ww)+">")  # works
 WwZ = Ww * 2
 print("11  WwZ Inside =<"+str(WwZ)+">")  # works
 return(Ww)  #Can I use this?
 
root = tk.Tk()

root.bind('',on_configure)
print("15  Ww Inside1 = <"+str(Ww)+">")
#Ww2 = int(Ww) * 2  # fails
print("17  WwZ Inside2 = <"+str(WwZ)+">")

root.mainloop()

Ww2 = int(Ww) * 2  #Works but only after the program stops
print("21  Ww Outside2 = <"+str(WwZ)+">")
# Can I have concentric loops?


SGA

-Original Message-
From: Alan Gauld 
Sent: Monday, February 26, 2024 4:04 AM
To: Steve GS ; python-list@python.org
Subject: Re: RE: Problem resizing a window and button placement

On 26/02/2024 07:56, Steve GS via Python-list wrote:


Then there is that discovery
element: Why is my original
idea not working? I still
cannot pass the value back
from the function.  What is
different about this function
that others would have given
me the value?


There is nothing different, see the code below.
print() is a function like any other.
In this case it is called after you close the window, ie after mainloop() exits.
But any other function called inside
mainloop - eg any other event handler can also access it.

For example, if you added a button:

def printW(): print("Button Ww = ", Ww)

bw = tk.Button(root, text="Print Width", command=printW)
bw.pack()

You would be able to print the value on demand.


import tkinter as tk

Ww = None

def on_configure(*args):
 global Ww
 Ww = root.winfo_width()
 print("Ww Inside =<"+str(Ww)+">")

root = tk.Tk()
root.bind('',on_configure)
root.mainloop()

print("Ww Outside = <"+str(Ww)+">")


--
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: RE: RE: Problem resizing a window and button placement

2024-02-26 Thread Alan Gauld via Python-list
On 26/02/2024 11:02, Steve GS via Python-list wrote:
> Although your code produces the value of Ww outside the function, 
> I do not see how I can use the value of Ww unless I close the program.

You have to use a function that operates inside the mainloop.
Thats the nature of event driven programs, all activity happens
inside the mainloop except initialisation and cleanup.

So you need to create an event handler as I described below.

Here is the complete program including the button:

###
import tkinter as tk

Ww=None

def on_configure(*args):
  global Ww
  Ww = root.winfo_width()
  print("Ww Inside = <" + str(Ww) + ">")

def printW(): print("Button Ww = ", Ww)


root = tk.Tk()
bw = tk.Button(root, text="Print Width", command=printW)
bw.pack()
root.bind('', on_configure)
root.mainloop()

print("Ww Outside = <" + str(Ww) + ">")


Notice that the button callback picks up the latest value of Ww.

-- 
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: RE: Problem resizing a window and button placement

2024-02-26 Thread Steve GS via Python-list
Although your code produces the value of Ww outside the function, I do not see 
how I can use the value of Ww unless I close the program.

import tkinter as tk

Ww = None  # What does this do? Why not Integer?
WwZ = None

def on_configure(*args):
global Ww
global WwZ
Ww = root.winfo_width()
print("9  Ww Inside =<"+str(Ww)+">")  # works
WwZ = Ww * 2
print("11  WwZ Inside =<"+str(WwZ)+">")  # works
return(Ww)  #Can I use this?

root = tk.Tk()
root.bind('',on_configure)
print("15  Ww Inside1 = <"+str(Ww)+">")
#Ww2 = int(Ww) * 2  # fails
print("17  WwZ Inside2 = <"+str(WwZ)+">")

root.mainloop()

Ww2 = int(Ww) * 2  #Works but only after the program stops
print("21  Ww Outside2 = <"+str(WwZ)+">")
# Can I have concentric loops?


SGA

-Original Message-
From: Alan Gauld  
Sent: Monday, February 26, 2024 4:04 AM
To: Steve GS ; python-list@python.org
Subject: Re: RE: Problem resizing a window and button placement

On 26/02/2024 07:56, Steve GS via Python-list wrote:

> Then there is that discovery
> element: Why is my original
> idea not working? I still
> cannot pass the value back
> from the function.  What is
> different about this function
> that others would have given
> me the value?

There is nothing different, see the code below.
print() is a function like any other.
In this case it is called after you close the window, ie after mainloop() exits.
But any other function called inside
mainloop - eg any other event handler can also access it.

For example, if you added a button:

def printW(): print("Button Ww = ", Ww)

bw = tk.Button(root, text="Print Width", command=printW)
bw.pack()

You would be able to print the value on demand.

>> import tkinter as tk
>>
>> Ww = None
>>
>> def on_configure(*args):
>> global Ww
>> Ww = root.winfo_width()
>> print("Ww Inside =<"+str(Ww)+">")
>>
>> root = tk.Tk()
>> root.bind('',on_configure)
>> root.mainloop()
>>
>> print("Ww Outside = <"+str(Ww)+">")

--
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: RE: Problem resizing a window and button placement

2024-02-26 Thread Alan Gauld via Python-list
On 26/02/2024 07:56, Steve GS via Python-list wrote:

> Then there is that discovery
> element: Why is my original
> idea not working? I still
> cannot pass the value back
> from the function.  What is
> different about this function
> that others would have given
> me the value?

There is nothing different, see the code below.
print() is a function like any other.
In this case it is called after you close the
window, ie after mainloop() exits.
But any other function called inside
mainloop - eg any other event handler can
also access it.

For example, if you added a button:

def printW(): print("Button Ww = ", Ww)

bw = tk.Button(root, text="Print Width", command=printW)
bw.pack()

You would be able to print the value on demand.

>> import tkinter as tk
>>
>> Ww = None
>>
>> def on_configure(*args):
>> global Ww
>> Ww = root.winfo_width()
>> print("Ww Inside =<"+str(Ww)+">")
>>
>> root = tk.Tk()
>> root.bind('',on_configure)
>> root.mainloop()
>>
>> print("Ww Outside = <"+str(Ww)+">")

-- 
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: Problem resizing a window and button placement

2024-02-26 Thread Steve GS via Python-list


Musta misstit
I had thought of that before I
started the discussion but
figured it would take more
code than it finally needed.
I guess I was also
variable-dependent thinking
that I would need the result
elsewhere in the code.  So
far, I see that I don't need
the value.

Then there is that discovery
element: Why is my original
idea not working? I still
cannot pass the value back
from the function.  What is
different about this function
that others would have given
me the value?


SGA

-Original Message-
From: Python-list
 On
Behalf Of Thomas Passin via
Python-list
Sent: Sunday, February 25,
2024 5:55 PM
To: python-list@python.org
Subject: Re: Problem resizing
a window and button placement

On 2/25/2024 4:19 PM, Steve GS
via Python-list wrote:
> SOLUTION FOUND!
> 
> The fix was to write the
code that uses the width value
and to place it into the
function itself.
> Kluge? Maybe but it works.

Right, just what I wrote
earlier:

"have the function that
responds to the resize event
perform the action that you
want"

> Mischief Managed.
> 
> 
> As for the most recent
suggestion, it fails for me:
> 
> Traceback (most recent call
last):
>File "F:/___zInsulin Code
A 08-02-23/WinPic/IOWw.pyw",
line 14, in 
>  print("Ww Outside = <"
+ str(Ww) > + ">")
> TypeError: bad operand type
for unary +: 'str'
> 
> With the need to close the
window, it adds an extra step
and intervention to the
program to use. I am not sure
how this help[s.
> 
> As a curio, it would be
interesting to see how to use
the value of a variable,
created in the function used
here, and make it available to
the code outside the function.
> 
> 
> 
> SGA
> 
> -Original Message-
> From: Alan Gauld

> Sent: Sunday, February 25,
2024 12:44 PM
> To: Steve GS
;
python-list@python.org
> Subject: Re: RE: Problem
resizing a window and button
placement
> 
> On 25/02/2024 03:58, Steve
GS via Python-list wrote:
> import tkinter as tk
> 
> Ww = None
> 
> def on_configure(*args):
> global Ww
> Ww =
root.winfo_width()
> print("Ww Inside =
<" + str(Ww) + ">")
> 
> root = tk.Tk()
> root.bind('',
on_configure)
> root.mainloop()
> 
> print("Ww Outside = <" +
str(Ww) > + ">")
> 
> Produces:
> Ww Inside = <200>
> Ww Inside = <200>
> Ww Inside = <205>
> Ww Inside = <205>
> Ww Inside = <206>
> Ww Inside = <206>
> Ww Outside = <206>
> 
> HTH
> 

--
https://mail.python.org/mailma
n/listinfo/python-list

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


RE: Problem resizing a window and button placement

2024-02-26 Thread Steve GS via Python-list
Ww Inside = <250>
Ww Inside = <249>
Ww Inside = <250>
Ww Outside =
<1770662408256on_configure>

Here is my result...

SGA

-Original Message-
From: Python-list
 On
Behalf Of MRAB via Python-list
Sent: Sunday, February 25,
2024 6:40 PM
To: python-list@python.org
Subject: Re: Problem resizing
a window and button placement

On 2024-02-25 21:19, Steve GS
via Python-list wrote:
> SOLUTION FOUND!
> 
> The fix was to write the
code that uses the width value
and to place it into the
function itself.
> Kluge? Maybe but it works.
> 
> Mischief Managed.
> 
> 
> As for the most recent
suggestion, it fails for me:
> 
> Traceback (most recent call
last):
>File "F:/___zInsulin Code
A 08-02-23/WinPic/IOWw.pyw",
line 14, in 
>  print("Ww Outside = <"
+ str(Ww) > + ">")
> TypeError: bad operand type
for unary +: 'str'
> 
It fails because there's a
mistake. It should be:

 print("Ww Outside = <" +
str(Ww) + ">")

> With the need to close the
window, it adds an extra step
and intervention to the
program to use. I am not sure
how this help[s.
> 
> As a curio, it would be
interesting to see how to use
the value of a variable,
created in the function used
here, and make it available to
the code outside the function.
> 
[snip]


-- 
https://mail.python.org/mailma
n/listinfo/python-list

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


Re: Problem resizing a window and button placement

2024-02-25 Thread MRAB via Python-list

On 2024-02-25 21:19, Steve GS via Python-list wrote:

SOLUTION FOUND!

The fix was to write the code that uses the width value and to place it into 
the function itself.
Kluge? Maybe but it works.

Mischief Managed.


As for the most recent suggestion, it fails for me:

Traceback (most recent call last):
   File "F:/___zInsulin Code A 08-02-23/WinPic/IOWw.pyw", line 14, in 
 print("Ww Outside = <" + str(Ww) > + ">")
TypeError: bad operand type for unary +: 'str'


It fails because there's a mistake. It should be:

print("Ww Outside = <" + str(Ww) + ">")


With the need to close the window, it adds an extra step and intervention to 
the program to use. I am not sure how this help[s.

As a curio, it would be interesting to see how to use the value of a variable, 
created in the function used here, and make it available to the code outside 
the function.


[snip]


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


Re: Problem resizing a window and button placement

2024-02-25 Thread Thomas Passin via Python-list

On 2/25/2024 4:19 PM, Steve GS via Python-list wrote:

SOLUTION FOUND!

The fix was to write the code that uses the width value and to place it into 
the function itself.
Kluge? Maybe but it works.


Right, just what I wrote earlier:

"have the function that responds to the resize event perform the action 
that you want"



Mischief Managed.


As for the most recent suggestion, it fails for me:

Traceback (most recent call last):
   File "F:/___zInsulin Code A 08-02-23/WinPic/IOWw.pyw", line 14, in 
 print("Ww Outside = <" + str(Ww) > + ">")
TypeError: bad operand type for unary +: 'str'

With the need to close the window, it adds an extra step and intervention to 
the program to use. I am not sure how this help[s.

As a curio, it would be interesting to see how to use the value of a variable, 
created in the function used here, and make it available to the code outside 
the function.



SGA

-Original Message-
From: Alan Gauld 
Sent: Sunday, February 25, 2024 12:44 PM
To: Steve GS ; python-list@python.org
Subject: Re: RE: Problem resizing a window and button placement

On 25/02/2024 03:58, Steve GS via Python-list wrote:
import tkinter as tk

Ww = None

def on_configure(*args):
global Ww
Ww = root.winfo_width()
print("Ww Inside = <" + str(Ww) + ">")

root = tk.Tk()
root.bind('', on_configure)
root.mainloop()

print("Ww Outside = <" + str(Ww) > + ">")

Produces:
Ww Inside = <200>
Ww Inside = <200>
Ww Inside = <205>
Ww Inside = <205>
Ww Inside = <206>
Ww Inside = <206>
Ww Outside = <206>

HTH



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


RE: RE: Problem resizing a window and button placement

2024-02-25 Thread Steve GS via Python-list
SOLUTION FOUND!

The fix was to write the code that uses the width value and to place it into 
the function itself.  
Kluge? Maybe but it works. 

Mischief Managed.


As for the most recent suggestion, it fails for me:

Traceback (most recent call last):
  File "F:/___zInsulin Code A 08-02-23/WinPic/IOWw.pyw", line 14, in 
print("Ww Outside = <" + str(Ww) > + ">")
TypeError: bad operand type for unary +: 'str'

With the need to close the window, it adds an extra step and intervention to 
the program to use. I am not sure how this help[s.

As a curio, it would be interesting to see how to use the value of a variable, 
created in the function used here, and make it available to the code outside 
the function.



SGA

-Original Message-
From: Alan Gauld  
Sent: Sunday, February 25, 2024 12:44 PM
To: Steve GS ; python-list@python.org
Subject: Re: RE: Problem resizing a window and button placement

On 25/02/2024 03:58, Steve GS via Python-list wrote:
import tkinter as tk

Ww = None

def on_configure(*args):
   global Ww
   Ww = root.winfo_width()
   print("Ww Inside = <" + str(Ww) + ">")

root = tk.Tk()
root.bind('', on_configure)
root.mainloop()

print("Ww Outside = <" + str(Ww) > + ">")

Produces:
Ww Inside = <200>
Ww Inside = <200>
Ww Inside = <205>
Ww Inside = <205>
Ww Inside = <206>
Ww Inside = <206>
Ww Outside = <206>

HTH

-- 
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: RE: Problem resizing a window and button placement

2024-02-25 Thread Alan Gauld via Python-list
On 25/02/2024 03:58, Steve GS via Python-list wrote:
import tkinter as tk

Ww = None

def on_configure(*args):
   global Ww
   Ww = root.winfo_width()
   print("Ww Inside = <" + str(Ww) + ">")

root = tk.Tk()
root.bind('', on_configure)
root.mainloop()

print("Ww Outside = <" + str(Ww) > + ">")

Produces:
Ww Inside = <200>
Ww Inside = <200>
Ww Inside = <205>
Ww Inside = <205>
Ww Inside = <206>
Ww Inside = <206>
Ww Outside = <206>

HTH

-- 
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: Problem resizing a window and button placement

2024-02-24 Thread Steve GS via Python-list
So, how do I use the width value in my code?

SGA

-Original Message-
From: Python-list  On Behalf 
Of MRAB via Python-list
Sent: Saturday, February 24, 2024 10:36 PM
To: python-list@python.org
Subject: Re: Problem resizing a window and button placement

On 2024-02-25 02:51, Steve GS wrote:
> import tkinter as tk
>
> #global Ww  Neither global helps
> def on_configure(*args):
> # print(args)
>   #global Ww  Neither global helps
>   Ww = root.winfo_width()
>   print("WwInside = <" + str(Ww) + ">")
>
> root = tk.Tk()
> root.bind('', on_configure) print("WwOutside = <" + str(Ww) 
> + ">")
> #NameError: name 'Ww' is not defined
> root.mainloop()
'Ww' won't exist until 'on_configure' assigns to it, and that won't happen 
until `mainloop` starts.

Also, 'global' works only within a function.

8<

import tkinter as tk

def on_configure(event):
 print(f'{event.width=}, {event.height=}')

root = tk.Tk()
root.bind('',on_configure)
root.mainloop()

8<

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

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


RE: Problem resizing a window and button placement

2024-02-24 Thread Steve GS via Python-list
The print statement in the
function prints. 
Does that not mean that the
function is being called?



SGA

-Original Message-
From: Python-list
 On
Behalf Of Thomas Passin via
Python-list
Sent: Saturday, February 24,
2024 10:39 PM
To: python-list@python.org
Subject: Re: Problem resizing
a window and button placement

On 2/24/2024 9:51 PM, Steve GS
via Python-list wrote:
First of all, please make sure
that the formatting is
readable and especially the
indentation.  This is Python,
after all.

Do not use tabs; use 3 or 4
spaces instead of each tab.
> import tkinter as tk
> 
> #global Ww  Neither global
> helps
> def on_configure(*args):
> # print(args)
>   #global Ww  Neither
> global helps
>   Ww =
root.winfo_width()
>   print("WwInside = <" +
> str(Ww) + ">")
> 
> root = tk.Tk()
> root.bind('',
> on_configure)
> print("WwOutside = <" +
> str(Ww) + ">")
> #NameError: name 'Ww' is not
> defined

The function that declares Ww
hasn't run yet. As I wrote
earlier, the function bound to
the callback should do all the
work for the callback, or it
should call other functions
that do.  That's if you don't
let a layout do it all for
you, as others have written.

> root.mainloop()
> 
> SGA
> 
> -Original Message-
> From: Python-list
>
 sga.ni...@python.org> On
> Behalf Of MRAB via
Python-list
> Sent: Saturday, February 24,
> 2024 7:49 PM
> To: python-list@python.org
> Subject: Re: Problem
resizing
> a window and button
placement
> 
> On 2024-02-25 00:33, Steve
GS
> via Python-list wrote:
>> "Well, yes, in Python a
>> variable created inside a
>> function or method is local
> to
>> that function unless you
>> declare it global."
>>
>> Yes, I knew that. I tried
to
>> global it both before the
>> function call and within
it.
>> Same for when I created the
>> variable. If I try to use
it
>> in the rest of the code, it
>> keeps coming up as not
>> declared.  In other
> functions,
>> I can 'return' the variable
>> but that apparently would
> not
>> work for this function.
>>
>> Is this type of function
any
>> different that that which I
>> have been using?
>>
> Please post a short example
> that shows the problem.
> 

--
https://mail.python.org/mailma
n/listinfo/python-list

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


Re: Problem resizing a window and button placement

2024-02-24 Thread MRAB via Python-list

On 2024-02-25 02:51, Steve GS wrote:

import tkinter as tk

#global Ww  Neither global helps
def on_configure(*args):
# print(args)
  #global Ww  Neither global helps
  Ww = root.winfo_width()
  print("WwInside = <" + str(Ww) + ">")

root = tk.Tk()
root.bind('', on_configure)
print("WwOutside = <" + str(Ww) + ">")
#NameError: name 'Ww' is not defined
root.mainloop()
'Ww' won't exist until 'on_configure' assigns to it, and that won't 
happen until `mainloop` starts.


Also, 'global' works only within a function.

8<

import tkinter as tk

def on_configure(event):
    print(f'{event.width=}, {event.height=}')

root = tk.Tk()
root.bind('',on_configure)
root.mainloop()

8<

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


Re: Problem resizing a window and button placement

2024-02-24 Thread Thomas Passin via Python-list

On 2/24/2024 9:51 PM, Steve GS via Python-list wrote:
First of all, please make sure that the formatting is readable and 
especially the indentation.  This is Python, after all.


Do not use tabs; use 3 or 4 spaces instead of each tab.

import tkinter as tk

#global Ww  Neither global
helps
def on_configure(*args):
# print(args)
  #global Ww  Neither
global helps
  Ww = root.winfo_width()
  print("WwInside = <" +
str(Ww) + ">")

root = tk.Tk()
root.bind('',
on_configure)
print("WwOutside = <" +
str(Ww) + ">")
#NameError: name 'Ww' is not
defined


The function that declares Ww hasn't run yet. As I wrote earlier, the 
function bound to the callback should do all the work for the callback, 
or it should call other functions that do.  That's if you don't let a 
layout do it all for you, as others have written.



root.mainloop()

SGA

-Original Message-
From: Python-list
 On
Behalf Of MRAB via Python-list
Sent: Saturday, February 24,
2024 7:49 PM
To: python-list@python.org
Subject: Re: Problem resizing
a window and button placement

On 2024-02-25 00:33, Steve GS
via Python-list wrote:

"Well, yes, in Python a
variable created inside a
function or method is local

to

that function unless you
declare it global."

Yes, I knew that. I tried to
global it both before the
function call and within it.
Same for when I created the
variable. If I try to use it
in the rest of the code, it
keeps coming up as not
declared.  In other

functions,

I can 'return' the variable
but that apparently would

not

work for this function.

Is this type of function any
different that that which I
have been using?


Please post a short example
that shows the problem.



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


RE: Problem resizing a window and button placement

2024-02-24 Thread Steve GS via Python-list
import tkinter as tk

#global Ww  Neither global
helps
def on_configure(*args):
# print(args)
 #global Ww  Neither
global helps
 Ww = root.winfo_width()
 print("WwInside = <" +
str(Ww) + ">")

root = tk.Tk()
root.bind('',
on_configure)
print("WwOutside = <" +
str(Ww) + ">")
#NameError: name 'Ww' is not
defined
root.mainloop()

SGA

-Original Message-
From: Python-list
 On
Behalf Of MRAB via Python-list
Sent: Saturday, February 24,
2024 7:49 PM
To: python-list@python.org
Subject: Re: Problem resizing
a window and button placement

On 2024-02-25 00:33, Steve GS
via Python-list wrote:
> "Well, yes, in Python a
> variable created inside a
> function or method is local
to
> that function unless you
> declare it global."
> 
> Yes, I knew that. I tried to
> global it both before the
> function call and within it.
> Same for when I created the
> variable. If I try to use it
> in the rest of the code, it
> keeps coming up as not
> declared.  In other
functions,
> I can 'return' the variable
> but that apparently would
not
> work for this function.
> 
> Is this type of function any
> different that that which I
> have been using?
> 
Please post a short example
that shows the problem.

-- 
https://mail.python.org/mailma
n/listinfo/python-list

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


Re: Problem resizing a window and button placement

2024-02-24 Thread MRAB via Python-list

On 2024-02-25 00:33, Steve GS via Python-list wrote:

"Well, yes, in Python a
variable created inside a
function or method is local to
that function unless you
declare it global."

Yes, I knew that. I tried to
global it both before the
function call and within it.
Same for when I created the
variable. If I try to use it
in the rest of the code, it
keeps coming up as not
declared.  In other functions,
I can 'return' the variable
but that apparently would not
work for this function.

Is this type of function any
different that that which I
have been using?


Please post a short example that shows the problem.

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


RE: Problem resizing a window and button placement

2024-02-24 Thread Steve GS via Python-list
"Well, yes, in Python a
variable created inside a
function or method is local to
that function unless you
declare it global."

Yes, I knew that. I tried to
global it both before the
function call and within it.
Same for when I created the
variable. If I try to use it
in the rest of the code, it
keeps coming up as not
declared.  In other functions,
I can 'return' the variable
but that apparently would not
work for this function.

Is this type of function any
different that that which I
have been using?

SGA

-Original Message-
From: Python-list
 On
Behalf Of Thomas Passin via
Python-list
Sent: Saturday, February 24,
2024 8:40 AM
To: python-list@python.org
Subject: Re: Problem resizing
a window and button placement

On 2/24/2024 3:20 AM, Steve GS
via Python-list wrote:
> Yes, I ran that elegantly
> simple code. The print
> statement reports the X, Y,
> Height and Width values.
> However, I do not see how to
> capture the width value.
> 
>   I experimented with the
code
> Vwidth = rootV.winfo_width()
> and it also reports the
width
> as I resize the window.
> 
> However, I cannot seem to
use
> the variable Vwidth outside
> the sub routine. It is
acting
> as if Vwidth is not global
but
> I added that.  It is
reported
> that Vwidth is not defined
> when I try to use it in my
> code.

Well, yes, in Python a
variable created inside a
function or method is local to
that function unless you
declare it global. That
characteristic is called its
"scope". But if you think you
need it to be a global
variable you should rethink
your design. For one thing,
before the next time you use
your global variable the
window size may have changed
again.

Instead, it would be better to
have the function that
responds to the resize event
perform the action that you
want, or call another function
that does, passing the new
width to it.

Note that in most programming
languages, variables have a
scope.  The rules about those
scopes vary between languages.

> 
> So close..
> SGA
> 
> -Original Message-
> From: Barry
> 
> Sent: Saturday, February 24,
> 2024 3:04 AM
> To: Steve GS
> 
> Cc: MRAB
>
;
> python-list@python.org
> Subject: Re: Problem
resizing
> a window and button
placement
> 
> 
> 
>> On 24 Feb 2024, at 04:36,
> Steve GS via Python-list
> 
> wrote:
>>
>> How do I extract the values
>> from args?
> 
> You can look up the args in
> documentation.
> You can run the example code
> MRAB provided and see what
is
> printed to learn what is in
> the args.
> 
> Barry
> 
> 

--
https://mail.python.org/mailma
n/listinfo/python-list

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


Re: Problem resizing a window and button placement

2024-02-24 Thread Grant Edwards via Python-list
On 2024-02-24, MRAB via Python-list  wrote:
> On 2024-02-24 01:14, Steve GS via Python-list wrote:
>
>> Python, Tkinter: How do I determine if a window has been resized? I
>> want to locate buttons vertically along the right border and need
>> to know the new width. The buttons are to move with the change of
>> location of the right-side border.
>
> Bind an event handler for '':
>
> 8<
> [...]
> 8<
>
> Are you placing the buttons yourself? I always use layouts and they 
> handle such things automatically.

Yes, definitely what he said: use a layout manager.

I hope this doesn't sound rude, but if you're calculating button
positions based on window size, you're doing it wrong and will end up
wasting a lot of time to produce something that won't work right.

Use a layout manager:

  
https://tkinterpython.top/layout/#:~:text=Tkinter%20has%20three%20built%2Din,%2C%20grid%20%2C%20and%20place%20managers.

  
https://www.pythonguis.com/tutorials/create-ui-with-tkinter-pack-layout-manager/

  https://www.pythonguis.com/tutorials/use-tkinter-to-design-gui-layout/

You'll have to spend a little time learning how they work, but in the
end you'll get done sooner and have better results.

--
Grant

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


Re: Problem resizing a window and button placement

2024-02-24 Thread Thomas Passin via Python-list

On 2/24/2024 3:20 AM, Steve GS via Python-list wrote:

Yes, I ran that elegantly
simple code. The print
statement reports the X, Y,
Height and Width values.
However, I do not see how to
capture the width value.

  I experimented with the code
Vwidth = rootV.winfo_width()
and it also reports the width
as I resize the window.

However, I cannot seem to use
the variable Vwidth outside
the sub routine. It is acting
as if Vwidth is not global but
I added that.  It is reported
that Vwidth is not defined
when I try to use it in my
code.


Well, yes, in Python a variable created inside a function or method is 
local to that function unless you declare it global. That characteristic 
is called its "scope". But if you think you need it to be a global 
variable you should rethink your design. For one thing, before the next 
time you use your global variable the window size may have changed again.


Instead, it would be better to have the function that responds to the 
resize event perform the action that you want, or call another function 
that does, passing the new width to it.


Note that in most programming languages, variables have a scope.  The 
rules about those scopes vary between languages.




So close..
SGA

-Original Message-
From: Barry

Sent: Saturday, February 24,
2024 3:04 AM
To: Steve GS

Cc: MRAB
;
python-list@python.org
Subject: Re: Problem resizing
a window and button placement




On 24 Feb 2024, at 04:36,

Steve GS via Python-list

wrote:


How do I extract the values
from args?


You can look up the args in
documentation.
You can run the example code
MRAB provided and see what is
printed to learn what is in
the args.

Barry




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


RE: Problem resizing a window and button placement

2024-02-24 Thread Steve GS via Python-list
Yes, I ran that elegantly
simple code. The print
statement reports the X, Y,
Height and Width values.
However, I do not see how to
capture the width value.  

 I experimented with the code
Vwidth = rootV.winfo_width()
and it also reports the width
as I resize the window.

However, I cannot seem to use
the variable Vwidth outside
the sub routine. It is acting
as if Vwidth is not global but
I added that.  It is reported
that Vwidth is not defined
when I try to use it in my
code.

So close..
SGA

-Original Message-
From: Barry
 
Sent: Saturday, February 24,
2024 3:04 AM
To: Steve GS

Cc: MRAB
;
python-list@python.org
Subject: Re: Problem resizing
a window and button placement



> On 24 Feb 2024, at 04:36,
Steve GS via Python-list

wrote:
> 
> How do I extract the values
> from args?

You can look up the args in
documentation.
You can run the example code
MRAB provided and see what is
printed to learn what is in
the args.

Barry


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


Re: Problem resizing a window and button placement

2024-02-24 Thread Barry via Python-list



> On 24 Feb 2024, at 04:36, Steve GS via Python-list  
> wrote:
> 
> How do I extract the values
> from args?

You can look up the args in documentation.
You can run the example code MRAB provided and see what is printed to learn 
what is in the args.

Barry


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


RE: Problem resizing a window and button placement

2024-02-23 Thread Steve GS via Python-list
How do I extract the values
from args?

SGA

-Original Message-
From: Python-list
 On
Behalf Of MRAB via Python-list
Sent: Friday, February 23,
2024 9:27 PM
To: python-list@python.org
Subject: Re: Problem resizing
a window and button placement

On 2024-02-24 01:14, Steve GS
via Python-list wrote:
> Python, Tkinter: How do I
> determine if a window has
been
> resized? I want to locate
> buttons vertically along the
> right border and need to
know
> the new width. The buttons
are
> to move with the change of
> location of the right-side
> border.
> 
Bind an event handler for
'':

8<

import tkinter as tk

def on_configure(*args):
 print(args)

root = tk.Tk()
root.bind('',
on_configure)
root.mainloop()

8<

Are you placing the buttons
yourself? I always use layouts
and they handle such things
automatically.

--
https://mail.python.org/mailma
n/listinfo/python-list

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


Re: Problem resizing a window and button placement

2024-02-23 Thread MRAB via Python-list

On 2024-02-24 01:14, Steve GS via Python-list wrote:

Python, Tkinter: How do I
determine if a window has been
resized? I want to locate
buttons vertically along the
right border and need to know
the new width. The buttons are
to move with the change of
location of the right-side
border.


Bind an event handler for '':

8<

import tkinter as tk

def on_configure(*args):
print(args)

root = tk.Tk()
root.bind('', on_configure)
root.mainloop()

8<

Are you placing the buttons yourself? I always use layouts and they 
handle such things automatically.


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


Re: Problem with accented characters in mailbox.Maildir()

2023-05-09 Thread Peter J. Holzer
On 2023-05-08 23:02:18 +0200, jak wrote:
> Peter J. Holzer ha scritto:
> > On 2023-05-06 16:27:04 +0200, jak wrote:
> > > Chris Green ha scritto:
> > > > Chris Green  wrote:
> > > > > A bit more information, msg.get("subject", "unknown") does return a
> > > > > string, as follows:-
> > > > > 
> > > > >   Subject: 
> > > > > =?utf-8?Q?aka_Marne_=C3=A0_la_Sa=C3=B4ne_(Waterways_Continental_Europe)?=
> > [...]
> > > > ... and of course I now see the issue!  The Subject: with utf-8
> > > > characters in it gets spaces changed to underscores.  So searching for
> > > > '(Waterways Continental Europe)' fails.
> > > > 
> > > > I'll either need to test for both versions of the string or I'll need
> > > > to change underscores to spaces in the Subject: returned by msg.get().
[...]
> > > 
> > > subj = email.header.decode_header(raw_subj)[0]
> > > 
> > > subj[0].decode(subj[1])
[...]
> > email.header.decode_header returns a *list* of chunks and you have to
> > process and concatenate all of them.
> > 
> > Here is a snippet from a mail to html converter I wrote a few years ago:
> > 
> > def decode_rfc2047(s):
> >  if s is None:
> >  return None
> >  r = ""
> >  for chunk in email.header.decode_header(s):
[...]
> >  r += chunk[0].decode(chunk[1])
[...]
> >  return r
[...]
> > 
> > I do have to say that Python is extraordinarily clumsy in this regard.
> 
> Thanks for the reply. In fact, I gave that answer because I did
> not understand what the OP wanted to achieve. In addition, the
> OP opened a second thread on the similar topic in which I gave a
> more correct answer (subject: "What do these '=?utf-8?' sequences
> mean in python?", date: "Sat, 6 May 2023 14:50:40 UTC").

Right. I saw that after writing my reply. I should have read all
messages, not just that thread before replying.

> the OP, I discovered that the MAME is not the only format used
> to compose the subject.

Not sure what "MAME" is. If it's a typo for MIME, then the base64
variant of RFC 2047 is just as much a part of it as the quoted-printable
variant.

> This made me think that a library could not delegate to the programmer
> the burden of managing all these exceptions,

email.header.decode_header handles both variants, but it produces bytes
sequences which still have to be decoded to get a Python string.


> then I have further investigated to discover that the library also
> provides the conversion function beyond that of coding and this makes
> our labors vain:
> 
> --
> from email.header import decode_header, make_header
> 
> subject = make_header(decode_header( raw_subject )))
> --

Yup. I somehow missed that. That's a lot more convenient than calling
decode in a loop (or generator expression). Depending on what you want
to do with the subject you may have wrap that in a call to str(), but
it's still a one-liner.

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: Problem with accented characters in mailbox.Maildir()

2023-05-08 Thread Peter J. Holzer
On 2023-05-06 16:27:04 +0200, jak wrote:
> Chris Green ha scritto:
> > Chris Green  wrote:
> > > A bit more information, msg.get("subject", "unknown") does return a
> > > string, as follows:-
> > > 
> > >  Subject: 
> > > =?utf-8?Q?aka_Marne_=C3=A0_la_Sa=C3=B4ne_(Waterways_Continental_Europe)?=
[...]
> > ... and of course I now see the issue!  The Subject: with utf-8
> > characters in it gets spaces changed to underscores.  So searching for
> > '(Waterways Continental Europe)' fails.
> > 
> > I'll either need to test for both versions of the string or I'll need
> > to change underscores to spaces in the Subject: returned by msg.get().

You need to decode the Subject properly. Unfortunately the Python email
module doesn't do that for you automatically. But it does provide the
necessary tools. Don't roll your own unless you've read and understood
the relevant RFCs.

> 
> This is probably what you need:
> 
> import email.header
> 
> raw_subj =
> '=?utf-8?Q?aka_Marne_=C3=A0_la_Sa=C3=B4ne_(Waterways_Continental_Europe)?='
> 
> subj = email.header.decode_header(raw_subj)[0]
> 
> subj[0].decode(subj[1])
> 
> 'aka Marne à la Saône (Waterways Continental Europe)'

You are an the right track, but that works only because the example
exists only of a single encoded word. This is not always the case (and
indeed not what the RFC recommends).

email.header.decode_header returns a *list* of chunks and you have to
process and concatenate all of them.

Here is a snippet from a mail to html converter I wrote a few years ago:

def decode_rfc2047(s):
if s is None:
return None
r = ""
for chunk in email.header.decode_header(s):
if chunk[1]:
try:
r += chunk[0].decode(chunk[1])
except LookupError:
r += chunk[0].decode("windows-1252")
except UnicodeDecodeError:
r += chunk[0].decode("windows-1252")
elif type(chunk[0]) == bytes:
r += chunk[0].decode('us-ascii')
else:
r += chunk[0]
return r

(this is maybe a bit more forgiving than the OP needs, but I had to deal
with malformed mails)

I do have to say that Python is extraordinarily clumsy in this regard.

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: Problem with accented characters in mailbox.Maildir()

2023-05-08 Thread jak

Chris Green ha scritto:

Chris Green  wrote:

A bit more information, msg.get("subject", "unknown") does return a
string, as follows:-

 Subject: 
=?utf-8?Q?aka_Marne_=C3=A0_la_Sa=C3=B4ne_(Waterways_Continental_Europe)?=

So it's the 'searchTxt in msg.get("subject", "unknown")' that's
failing. I.e. for some reason 'in' isn't working when the searched
string has utf-8 characters.

Surely there's a way to handle this.


... and of course I now see the issue!  The Subject: with utf-8
characters in it gets spaces changed to underscores.  So searching for
'(Waterways Continental Europe)' fails.

I'll either need to test for both versions of the string or I'll need
to change underscores to spaces in the Subject: returned by msg.get().
It's a long enough string that I'm searching for that I won't get any
false positives.


Sorry for the noise everyone, it's a typical case of explaining the
problem shows one how to fix it! :-)



This is probably what you need:

import email.header

raw_subj = 
'=?utf-8?Q?aka_Marne_=C3=A0_la_Sa=C3=B4ne_(Waterways_Continental_Europe)?='


subj = email.header.decode_header(raw_subj)[0]

subj[0].decode(subj[1])

'aka Marne à la Saône (Waterways Continental Europe)'




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


Re: Problem with accented characters in mailbox.Maildir()

2023-05-08 Thread Chris Green
Chris Green  wrote:
> A bit more information, msg.get("subject", "unknown") does return a
> string, as follows:-
> 
> Subject: 
> =?utf-8?Q?aka_Marne_=C3=A0_la_Sa=C3=B4ne_(Waterways_Continental_Europe)?=
> 
> So it's the 'searchTxt in msg.get("subject", "unknown")' that's
> failing. I.e. for some reason 'in' isn't working when the searched
> string has utf-8 characters.  
> 
> Surely there's a way to handle this.
> 
... and of course I now see the issue!  The Subject: with utf-8
characters in it gets spaces changed to underscores.  So searching for
'(Waterways Continental Europe)' fails.

I'll either need to test for both versions of the string or I'll need
to change underscores to spaces in the Subject: returned by msg.get().
It's a long enough string that I'm searching for that I won't get any
false positives.


Sorry for the noise everyone, it's a typical case of explaining the
problem shows one how to fix it! :-)

-- 
Chris Green
·
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Problem with accented characters in mailbox.Maildir()

2023-05-08 Thread Chris Green
A bit more information, msg.get("subject", "unknown") does return a
string, as follows:-

Subject: 
=?utf-8?Q?aka_Marne_=C3=A0_la_Sa=C3=B4ne_(Waterways_Continental_Europe)?=

So it's the 'searchTxt in msg.get("subject", "unknown")' that's
failing. I.e. for some reason 'in' isn't working when the searched
string has utf-8 characters.  

Surely there's a way to handle this.

-- 
Chris Green
·
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Problem with accented characters in mailbox.Maildir()

2023-05-08 Thread jak

Chris Green ha scritto:

I have a custom mail filter in python that uses the mailbox package to
open a mail message and give me access to the headers.

So I have the following code to open each mail message:-

 #
 #
 # Read the message from standard input and make a message object from it
 #
 msg = mailbox.MaildirMessage(sys.stdin.buffer.read())

and then later I have (among many other bits and pieces):-

 #
 #
 # test for string in Subject:
 #
 if searchTxt in str(msg.get("subject", "unknown")):
 do
 various
 things


This works exactly as intended most of the time but occasionally a
message whose subject should match the test is missed.  I have just
realised when this happens, it's when the Subject: has accented
characters in it (this is from a mailing list about canals in France).

So, for example, the latest case of this happening has:-

 Subject: aka Marne à la Saône (Waterways Continental Europe)

where the searchTxt in the code above is "Waterways Continental Europe".


Is there any way I can work round this issue?  E.g. is there a way to
strip out all extended characters from a string?  Or maybe it's
msg.get() that isn't managing to handle the accented string correctly?

Yes, I know that accented characters probably aren't allowed in
Subject: but I'm not going to get that changed! :-)




Hi,
you could try extracting the "Content-Type:charset" and then using it
for subject conversion:

subj = str(raw_subj, encoding='...')

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


Re: Problem with Matplotlib example

2023-04-14 Thread Martin Schöön
Den 2023-04-13 skrev MRAB :
> On 2023-04-13 19:41, Martin Schöön wrote:
>> Anyone had success running this example?
>> https://tinyurl.com/yhhyc9r
>> 

>> As far as I know I have an up-to-date matplotlib installed. Pip has
>> nothing more modern to offer me.
>> 
> All I can say is that it works for me!
>
> Python 3.10 and 3.11, matplotlib 3.6.1 and then 3.7.1 after updating it.
>
Thanks are due to both you and Thomas. Your replies put me on the right
scent. I soon learned what I should have know since ages: pip reporting
there is now newer version of a package does not mean there is *no
newer* version. It means there is no newer version for the version of
Python I use. In my case I am on Python 3.7. At work, where I am on
Python 3.8, this matplotlib example works just fine.

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


Re: Problem with Matplotlib example

2023-04-13 Thread MRAB

On 2023-04-13 19:41, Martin Schöön wrote:

Anyone had success running this example?
https://tinyurl.com/yhhyc9r

When I try I get this error:
"TypeError: __init__() got an unexpected keyword argument 'transform'"

This is for the line
"m = MarkerStyle(SUCESS_SYMBOLS[mood], transform=t)"

Yes, I know, I could dive into the documentation myself but I hope
some kind soul here will help out.

As far as I know I have an up-to-date matplotlib installed. Pip has
nothing more modern to offer me.


All I can say is that it works for me!

Python 3.10 and 3.11, matplotlib 3.6.1 and then 3.7.1 after updating it.

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


Re: Problem with Matplotlib example

2023-04-13 Thread Thomas Passin

On 4/13/2023 2:41 PM, Martin Schöön wrote:

Anyone had success running this example?
https://tinyurl.com/yhhyc9r

When I try I get this error:
"TypeError: __init__() got an unexpected keyword argument 'transform'"

This is for the line
"m = MarkerStyle(SUCESS_SYMBOLS[mood], transform=t)"

Yes, I know, I could dive into the documentation myself but I hope
some kind soul here will help out.

As far as I know I have an up-to-date matplotlib installed. Pip has
nothing more modern to offer me.


It works for me, copy-pasted as is.

Python 3.11.3

C:\Users\tom>py -m pip show matplotlib
Name: matplotlib
Version: 3.6.3

C:\Users\tom>py -m pip show numpy
Name: numpy
Version: 1.24.2

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


Re: Problem in using libraries

2023-04-04 Thread Mats Wichmann

On 4/3/23 10:43, Pranav Bhardwaj wrote:

Why can't I able to use python libraries such as numpy, nudenet, playsound,
pandas, etc in my python 3.11.2. It always through the error "import
'numpy' or any other libraries could not be resolved".


Will restate what others have said in the hopes it might be even more 
clear that way.


Python has an internal search path that it uses to find the module when 
you ask to "import".  If a module is not found, that means it's not in 
the search path ("it's always a path problem"). You installed it, sure - 
but it went somewhere else.


The search path is installation-specific (not just version-specific: for 
example if you have a system install of 3.10.x, and a virtualenv using 
the same 3.10.x, those will have different search paths). The search 
path can be amended or changed, but that's a different story.


If you're going to install with pip, use the same Python you're going to 
do your work with. Don't trust that a command named "pip" maps to the 
same installation as that Python command. For that, either use an 
activated virtualenv, or do "name-of-my-python -m pip install".  You can 
always check your work by doing "name-of-my-python -m pip list" - what 
does that particular installation see as installed?


Or - if you're using the classic set of "scientific" packages like numpy 
and pandas, you might look at installing it all using conda instead of 
pip: it to a large extent exists to help with getting those very common 
bundles of things set up without going through the wrestling match 
you're going though.

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


Re: Problem in using libraries

2023-04-04 Thread Dieter Maurer
Pranav Bhardwaj wrote at 2023-4-3 22:13 +0530:
>Why can't I able to use python libraries such as numpy, nudenet, playsound,
>pandas, etc in my python 3.11.2. It always through the error "import
>'numpy' or any other libraries could not be resolved".

The "libraries" you speak of are extensions (i.e. not part of
the Python download).

Extensions are Python minor version specific.
You must install them for each Python minor version.
E.g. you can use an extension installation for Python 3.10 for
any Python 3.10.x,
but you must install it again for Python 3.11.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Problem in using libraries

2023-04-03 Thread Thomas Passin

On 4/3/2023 12:43 PM, Pranav Bhardwaj wrote:

Why can't I able to use python libraries such as numpy, nudenet, playsound,
pandas, etc in my python 3.11.2. It always through the error "import
'numpy' or any other libraries could not be resolved".


You need to realize that no one can help you without some specific 
information.  You have not told us anything.  You might as well have 
said, if your car didn't start, "My car won't run.  Why can't I start it?.


Let's start with the most obvious thing - are those libraries installed? 
 If not, install them.  If you think they have been installed, then 
tell us how you installed them and how you know they have been 
successfully installed *for the version of python* you are trying to use.


Let's take numpy. The standard way to install it is using pip.  You have 
to make sure that you run the pip program that goes with the version of 
Python you plan to use.  I'm going to assume that if you type "py" 
(without quotes), you will get that version.  If not, use the command 
you have been using to run Python 3.11.


On my system:

C:\Users\tom>py -V
Python 3.10.9

C:\Users\tom>py -m pip show numpy
Name: numpy
Version: 1.23.4
Summary: NumPy is the fundamental package for array computing with Python.
Home-page: https://www.numpy.org
Author: Travis E. Oliphant et al.
Author-email:
License: BSD
Location: 
c:\users\tom\appdata\local\programs\python\python310\lib\site-packages

Requires:
Required-by: bokeh, causal-curve, cftime, contourpy, csaps, dcor, emd, 
frechetdist, imageio, localreg, matplotlib, mizani, netCDF4, numba, 
pandas, patsy, plotnine, pwlf, pyDOE, pygam, PyWavelets, scaleogram, 
scikit-image, scikit-learn, scipy, seaborn, sparse, statsforecast, 
statsmodels, tifffile


If a library is not installed (I'll use a non-existent library name) -

C:\Users\tom>py -m pip show numpyx
WARNING: Package(s) not found: numpyx

To install numpy with pip *for that version of Python* -

py -m pip install numpy   (or a form you may see sometimes: py -m 
install --user numpy)


Please reply with this information.
--
https://mail.python.org/mailman/listinfo/python-list


Re: Problem in using libraries

2023-04-03 Thread Barry


> On 3 Apr 2023, at 17:46, Pranav Bhardwaj  wrote:
> 
> Why can't I able to use python libraries such as numpy, nudenet, playsound,
> pandas, etc in my python 3.11.2. It always through the error "import
> 'numpy' or any other libraries could not be resolved".

You need to provide enough details for people to help you.

Include which OS you are using.
Where you got python from.
How you installed the libraries you are trying to use.
Commands and error messages you are seeing.

Barry


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

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


RE: Problem with __sub__

2023-03-23 Thread David Raymond
I believe your problem is __rsub__, not __sub__.
When you havethen that 
uses the "r" version of the operators.

In your __rsub__ (used when you have  - ) you instead return 
 -  which is backwards.

Notice how the final return should also be -4,95 and not the +4,95 it's 
returning.

> If on the left side is '0' the result of a subtraction is wrong.
> 
> *b1 = Betragswert(500)
>  b2 = 0 + b1
>  b3 = 0 - b1
>  b4 = 5 + b1
>  b5 = 5 - b1*
> 
> print(b1, b2, b3, b4, b5) shows 5,00 5,00 5,00 5,05 4,95; the third
> value (b3) should be -5,00 (not 5,00).
> 
> Why is the substraction wrong?
>  def __rsub__(self, zweiter):
>  if not isinstance(zweiter, type(self)):
>  zweiter = Betragswert(zweiter)
>  return Betragswert(self._Betrag - zweiter._Betrag)
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Problem with wxPython form

2023-03-12 Thread aapost

On 3/10/23 15:15, Chris wrote:
Hi everyone. I'm new to Python and wxPython. I've got a form I use to 
calculate the Sq In of a leather project.


I'm using python 3.9.13 and wxPython 4.20

I'm having the following issues:
1) When I come into the form, no grid cell has the focus set - I start 
typing and nothing happens. I have to click the cell.
If I hit Tab or Enter, the OnKeyDown fires, but does not move to the 
appropriate cell - it does nothing but run the update and move off of 
the current cell.

The action I'm trying to make is this
ENTER KEY: Always go down 1 row and to col 0
TAB, if Col 0 Move to Col 1 on same row, if Col 1 go to Row +1, Col 0
I also need to have what3ever cell it is supposed to land on to get the 
focus so I can just type.

Currently I have to click in each cell I want/need to add.
There could be up to 20 pieces of leather with differing sizes, so in 
order to accurately calculate the Sq In, I need to get all the 
measurements in.
The form, one of several tabs, comes up and does everything else I've 
coded for great. Just no navigation.

Can anyone assist? Here is the module with the form


Your source was badly mangled by whatever you submitted it in, so it was 
very difficult to parse. Additionally, it is usually best to strip your 
code down to a minimal example of the issue, and remove any references 
to modules that are likely not publicly available (i.e. alwlogic) 
(putting basic dummy data in place if need be).


That being said:
2 things will likely address your issue, remove 
self.grid.SetCellHighlightPenWidth(0) since this is making the highlight 
box of the selected cell invisible, this is preventing you from seeing 
that your tabs and enters are working as you are expecting.


Next, the wx.EVT_KEY_DOWN binding is grabbing all key presses, and your 
function is only addressing 2 keys, you need to add an else: to the end 
with an event.Skip() to allow the default behaviors of the grid cells to 
pass through for other keys (i.e. typing).


That should get you the behavior you need.


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


Re: Problem when scraping the 100 Movie titles.

2022-09-22 Thread Fabian Joseph
#Try using, it's save in json format of the website: 
import json
import requests
from bs4 import BeautifulSoup


url = "https://www.empireonline.com/movies/features/best-movies-2/;

soup = BeautifulSoup(requests.get(url).content, "html.parser")
data = json.loads(soup.select_one("#__NEXT_DATA__").contents[0])

# uncomment this to print all data:
#print(json.dumps(data, indent=4))


def find_articles(data):
if isinstance(data, dict):
for k, v in data.items():
if k.startswith("ImageMeta:"):
yield v['image']['name']
else:
yield from find_articles(v)
elif isinstance(data, list):
for i in data:
yield from find_articles(i)


for a in find_articles(data):
print(a)
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: problem downloading python

2022-09-14 Thread Dennis Lee Bieber
On Wed, 14 Sep 2022 11:42:39 +0200, "carlharrison"
 declaimed the following:

>I am working on a PC with windows 10 and use Eset internet security. I have
>tried downloading  python 3.10.7 for windows. Using a tutorial I see that a
>checkbox should appear called "Add python 3/7 to path" but this does not
>appear whichever version I try to download. I wondered if Eset was stopping
>this somehow and tried it with Eset switched off but the result is the same.
>Can you help?

Download from where? (There are a number of distributions available,
including ones in the M$ "app" store, Visual Studio, etc.)

"Add Python..." is a step when RUNNING the installer. It should not
appear when DOWNLOADING the installer.

The general sequence is:

Download the installer file for the distribution.

RUN the installer program to install Python (and any other stuff
the distribution includes)

Hide the installer program/icons -- since they do NOT run Python
itself. Pure Python is run from a command line/shell interface; it is NOT a
graphical IDE.


-- 
Wulfraed Dennis Lee Bieber AF6VN
wlfr...@ix.netcom.comhttp://wlfraed.microdiversity.freeddns.org/
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: problem downloading python

2022-09-14 Thread Lars Liedtke

Hello and welcome,

Sadly I don't know about Eset internet security, or why you do not get the 
choice of letting the installer do that, but you could try to add Python 
manually to your PATH like it is described in 
https://www.geeksforgeeks.org/how-to-add-python-to-windows-path/ .

But maybe some more windows savvy people than me might chime in to offer better 
advice ;-) .

Cheers

Lars


Lars Liedtke
Software Entwickler

[Tel.]
[Fax]   +49 721 98993-
[E-Mail]l...@solute.de


solute GmbH
Zeppelinstraße 15
76185 Karlsruhe
Germany


[Logo Solute]


Marken der solute GmbH | brands of solute GmbH
[Marken]
[Advertising Partner]

Geschäftsführer | Managing Director: Dr. Thilo Gans, Bernd Vermaaten
Webseite | www.solute.de 
Sitz | Registered Office: Karlsruhe
Registergericht | Register Court: Amtsgericht Mannheim
Registernummer | Register No.: HRB 110579
USt-ID | VAT ID: DE234663798



Informationen zum Datenschutz | Information about privacy policy
https://www.solute.de/ger/datenschutz/grundsaetze-der-datenverarbeitung.php




Am 14.09.22 um 11:42 schrieb carlharrison:

Dear Sir or Madam,

I am working on a PC with windows 10 and use Eset internet security. I have
tried downloading  python 3.10.7 for windows. Using a tutorial I see that a
checkbox should appear called "Add python 3/7 to path" but this does not
appear whichever version I try to download. I wondered if Eset was stopping
this somehow and tried it with Eset switched off but the result is the same.
Can you help?

Best regards,

Carl Harrison.




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


Re: Problem using cx_Freeze > auto-py-to-exe

2022-08-19 Thread Dennis Lee Bieber
On Thu, 18 Aug 2022 12:17:25 -0600, David at Booomer 
declaimed the following:

>
>I did count but hadn’t noticed this argument list before you mentioned it. 
>However, I still don’t see any of these argument names in the Executable list 
>or anywhere else.
>

It's your responsibility to provide them when you called Executable().
As I said, you are (were?) providing a whole bunch of .py files, which were
being mapped to these arguments.


>"""
>argument name  description
>
>#1
>script the name of the file containing 
>the script
>which is to be frozen
>
prjui.py

>#2
>init_scriptthe name of the initialization 
>script that will
>be executed before the actual script is executed; this script is used to
>set up the environment for the executable; if a name is given without an
>absolute path the names of files in the initscripts subdirectory of the
>cx_Freeze package is searched
>
Maiui.py

>#3
>base   the name of the base 
>executable; if a name is
>given without an absolute path the names of files in the bases subdirectory
>of the cx_Freeze package is searched
>
about.py

>#4
>target_namethe name of the target executable; the 
>default
>value is the name of the script; the extension is optional (automatically
>added on Windows); support for names with version; if specified a pathname,
>raise an error.
>
dict.py

>#5
>icon   name of icon which should be 
>included in the
>executable itself on Windows or placed in the target directory for other
>platforms (ignored in Microsoft Store Python app)
>
geometry.py

>#6
>manifest   name of manifest which should 
>be included in
>the executable itself (Windows only - ignored by Python app from Microsoft
>Store)
>
getEquation.py

>#7
>uac-admin  creates a manifest for an 
>application that will
>request elevation (Windows only - ignored by Python app from Microsoft
>Store)
>
gtrail.py

>#8
>shortcut_name  the name to give a shortcut for the 
>executable
>when included in an MSI package (Windows only).
>
main.py

>#9
>shortcut_dir   the directory in which to place 
>the
>shortcut when being installed by an MSI package; see the MSI Shortcut table
>documentation for more information on what values can be placed here
>(Windows only).

matchingstring.py

>#10
>copyright  the copyright value to include 
>in the version
>resource associated with executable (Windows only).
>
producelatex.py

>#11
>trademarks the trademarks value to include 
>in the version
>resource associated with the executable (Windows only).

readfile.py

and
separete.py
speak.py
are not mapped to anything, hence the too-many arguments error.
>"""

As you can see, a lot of those don't even fit with the data type of the
argument.
>
>I tried passing just main.py or one of the others that might be a starting 
>point but just got ’NoneType has no len()

What did the traceback say? Just reporting the last line message is
meaningless.

>Then I searched for ‘python executable’ and found auto-py-to-exe and 
>pyinstaller which I must/might explore later. First tries ran into PyQt4 to 
>PyQt5 conversions. Good start at 
>https://towardsdatascience.com/how-to-easily-convert-a-python-script-to-an-executable-file-exe-4966e253c7e9
>

Note that pretty much all such python->executable scheme is just making
an archive of the required Python source files, and packaging the core of
the Python interpreter is such a way that running this archive is simply
extracting the source files and running the packaged Python interpreter
with them.


-- 
Wulfraed Dennis Lee Bieber AF6VN
wlfr...@ix.netcom.comhttp://wlfraed.microdiversity.freeddns.org/
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Problem using cx_Freeze > auto-py-to-exe

2022-08-18 Thread Chris Angelico
On Fri, 19 Aug 2022 at 10:07, Grant Edwards  wrote:
>
> On 2022-08-18, Chris Angelico  wrote:
> > On Fri, 19 Aug 2022 at 05:05, Grant Edwards  
> > wrote:
> >> On 2022-08-18, Chris Angelico  wrote:
> >>
> >> > It's one of the frustrations with JSON, since that format doesn't
> >> > allow the trailing comma :)
> >>
> >> Yep, that's a constant, low-level pain for all the C code I deal with
> >> which generates JSON. You'd think after 10+ years of maintaining code
> >> that outputs JSON, I wouldn't trip over that any longer...
> >
> > With some JSON files, I just cheat and define a shim at the end of arrays...
> >
> > https://raw.githubusercontent.com/Rosuav/MustardMine/master/template.json
>
> That's OK if it's strictly internal. Almost all of the JSON data I
> work with is part of published APIs — many of which are defined by
> industry consortiums or corporate-wide "standards".
>

That's an export/import format that I defined, so I mandated (a) that
there's an empty-string key as a signature (on import, it can be
anywhere, but on export, it's that final shim), and (b) all arrays are
allowed to have an empty string at the end, which is ignored on
import. Saves so much trouble.

That particular export format is actually designed as a git-managed
config file as well, which is why the line breaks are done the way
they are (anything on a single line is intended to be added/removed as
a single unit), which is why I definitely don't want the "add a comma
to the previous line" deltas.

"Strictly internal" is a subset of "protocols/standards that you are
in control of". :)

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


Re: Problem using cx_Freeze > auto-py-to-exe

2022-08-18 Thread Grant Edwards
On 2022-08-18, Chris Angelico  wrote:
> On Fri, 19 Aug 2022 at 05:05, Grant Edwards  wrote:
>> On 2022-08-18, Chris Angelico  wrote:
>>
>> > It's one of the frustrations with JSON, since that format doesn't
>> > allow the trailing comma :)
>>
>> Yep, that's a constant, low-level pain for all the C code I deal with
>> which generates JSON. You'd think after 10+ years of maintaining code
>> that outputs JSON, I wouldn't trip over that any longer...
>
> With some JSON files, I just cheat and define a shim at the end of arrays...
>
> https://raw.githubusercontent.com/Rosuav/MustardMine/master/template.json

That's OK if it's strictly internal. Almost all of the JSON data I
work with is part of published APIs — many of which are defined by
industry consortiums or corporate-wide "standards".

--
Grant


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


Re: Problem using cx_Freeze

2022-08-18 Thread subin
Hope you had a good time.

On Wed, Aug 17, 2022 at 10:19 PM Peter J. Holzer  wrote:

> On 2022-08-17 12:09:14 -0600, David at Booomer wrote:
> > Executable(
> >
>  "prjui.py","Maiui.py","about.py","dict.py","geometry.py","getEquation.py",
> >
>  "gtrail.py","main.py","matchingstring.py","producelatex.py","readfile.py",
> > "separete.py","speak.py",
> > )
> [...]
> > I am/was worried about the trailing ‘,' after ',"speak.py”,’ <- but
> > deleting it or moving it after the ] didn’t help.
>
> This has nothing to do with your problem but:
>
> Python allows a trailing comma in any comma-separated list of values. It
> will just be ignored.
>
> This is really common in modern programming languages (read: programming
> languages younger than 30 years or so), because it makes it much more
> convenient to extend/shorten/reorder a list. Otherwise you alway have to
> remember add or remove a comma in the right place. (Some people
> (especially SQL programmers for some reason) resorted to put the comma
> at the start of each line to get around this, which is really ugly.)
>
> hp
>
> --
>_  | Peter J. Holzer| Story must make more sense than reality.
> |_|_) ||
> | |   | h...@hjp.at |-- Charles Stross, "Creative writing
> __/   | http://www.hjp.at/ |   challenge!"
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Problem using cx_Freeze > auto-py-to-exe

2022-08-18 Thread Chris Angelico
On Fri, 19 Aug 2022 at 05:05, Grant Edwards  wrote:
>
> On 2022-08-18, Chris Angelico  wrote:
> > On Fri, 19 Aug 2022 at 04:19, David at Booomer  wrote:
> >
> >> The trailing , does make commenting out arguments easier but
> >> unexpected coming from ‘older’ languages. ;-)
> >
> > It's one of the frustrations with JSON, since that format doesn't
> > allow the trailing comma :)
>
> Yep, that's a constant, low-level pain for all the C code I deal with
> which generates JSON. You'd think after 10+ years of maintaining code
> that outputs JSON, I wouldn't trip over that any longer...
>

With some JSON files, I just cheat and define a shim at the end of arrays...

https://raw.githubusercontent.com/Rosuav/MustardMine/master/template.json

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


Re: Problem using cx_Freeze > auto-py-to-exe

2022-08-18 Thread Grant Edwards
On 2022-08-18, Chris Angelico  wrote:
> On Fri, 19 Aug 2022 at 04:19, David at Booomer  wrote:
>
>> The trailing , does make commenting out arguments easier but
>> unexpected coming from ‘older’ languages. ;-)
>
> It's one of the frustrations with JSON, since that format doesn't
> allow the trailing comma :)

Yep, that's a constant, low-level pain for all the C code I deal with
which generates JSON. You'd think after 10+ years of maintaining code
that outputs JSON, I wouldn't trip over that any longer...

--
Grant

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


Re: Problem using cx_Freeze > auto-py-to-exe

2022-08-18 Thread Chris Angelico
On Fri, 19 Aug 2022 at 04:19, David at Booomer  wrote:
> > This is really common in modern programming languages (read: programming
> > languages younger than 30 years or so), because it makes it much more
> > convenient to extend/shorten/reorder a list. Otherwise you alway have to
> > remember add or remove a comma in the right place. (Some people
> > (especially SQL programmers for some reason) resorted to put the comma
> > at the start of each line to get around this, which is really ugly.)
> >
> >hp
>
> The trailing , does make commenting out arguments easier but unexpected 
> coming from ‘older’ languages. ;-)
>

It's one of the frustrations with JSON, since that format doesn't
allow the trailing comma :)

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


Re: Problem using cx_Freeze > auto-py-to-exe

2022-08-18 Thread David at Booomer
From: Dennis Lee Bieber 
> 
> On Wed, 17 Aug 2022 12:09:14 -0600, David at Booomer 
> declaimed the following:
> 
>>   executables=[
>>   Executable(
>>   
>> "prjui.py","Maiui.py","about.py","dict.py","geometry.py","getEquation.py",
>>   
>> "gtrail.py","main.py","matchingstring.py","producelatex.py","readfile.py",
>>   "separete.py","speak.py",
>>   )
>>   ]
>> )
>> 
>   You are defining a list "executables" with only ONE member... (and is
> that really how you spelled "separate").

Not my spelling, although I do have to be careful when typing that word.

From before:
"I’m trying to get LaTex-to-Speech 
(https://github.com/SGanesh19/LaTeX-to-Speech) to run as an accessibility aid, 
converting equations into speech. I haven’t used cx_Freeze before so stumbling 
somewhat."

> 
>> Searching for ‘__init__(' in the 13 *.py files returned five lines in two 
>> files (algorithm.py and prjui.py). As mentioned searching for this error 
>> only produced mention of adding self which is in these lines already. 
>> Previously I had search for __init__() which returned no lines due to the 
>> closing ).
>> 
>   You are still searching the wrong place... The __init__() that is
> complaining is the one in cx_Freeze.Executable().
> 
>> I had visited the page you provided 
>> (https://cx-freeze.readthedocs.io/en/latest/setup_script.html#cx-freeze-executable)
>>  but didn’t noticed the 11 plus self as 12 arguments.
> 
>   Really? Please count (reformatted from cut):

I did count but hadn’t noticed this argument list before you mentioned it. 
However, I still don’t see any of these argument names in the Executable list 
or anywhere else.

> """
> argument name description
> 
> #1
> scriptthe name of the file 
> containing the script
> which is to be frozen
> 
> ...
> 
> #11
> trademarksthe trademarks value to include 
> in the version
> resource associated with the executable (Windows only).
> """
> 
>   You are passing 13 .py file names. There are only two arguments that
> really want file names: script, and init_script. Most of the other
> arguments are either optional or Windows specific (#6-11).
> 
>   I suspect you need to pass JUST main.py or Maiui.py (based on casing)
> -- which ever is really the file you'd invoke to start the program running.
> I'd hope the freeze system then scans (recursively) that file to find
> anything imported, and include those in the final product.
> 

I tried passing just main.py or one of the others that might be a starting 
point but just got ’NoneType has no len()

I was hoping to use someone else’s code to turn Latex equations into Speech. 
Maybe easier to just narrated each equation to create an audio file.

Thanks for your suggestions Dennis. This was the first time I saw the 
possibility of creating a python executable.

Then I searched for ‘python executable’ and found auto-py-to-exe and 
pyinstaller which I must/might explore later. First tries ran into PyQt4 to 
PyQt5 conversions. Good start at 
https://towardsdatascience.com/how-to-easily-convert-a-python-script-to-an-executable-file-exe-4966e253c7e9

I might wait for the original author to respond to an issue I posted on GitHub.

Thanks again. David

> -- 
>   Wulfraed Dennis Lee Bieber AF6VN
>   wlfr...@ix.netcom.comhttp://wlfraed.microdiversity.freeddns.org/
> 
...

> From: "Peter J. Holzer" 
> Subject: Re: Problem using cx_Freeze
> Date: August 17, 2022 at 3:17:27 PM MDT
> To: python-list@python.org
> 
> On 2022-08-17 12:09:14 -0600, David at Booomer wrote:
>>Executable(
>>
>> "prjui.py","Maiui.py","about.py","dict.py","geometry.py","getEquation.py",
>>
>> "gtrail.py","main.py","matchingstring.py","producelatex.py","readfile.py",
>>"separete.py","speak.py",
>>)
> [...]
>> I am/was worried about the trailing ‘,' after ',"speak.py”,’ <- but
>> deleting it or moving it after the ] didn’t help.
> 
> This has nothing to do with your problem but:
> 
> Python allows a trailing comma in any comma-separated list of values. It
> will just be ignored.
> 
> This is really common in modern programming languages (read: programmi

Re: Problem using cx_Freeze

2022-08-17 Thread Peter J. Holzer
On 2022-08-17 12:09:14 -0600, David at Booomer wrote:
> Executable(
> 
> "prjui.py","Maiui.py","about.py","dict.py","geometry.py","getEquation.py",
> 
> "gtrail.py","main.py","matchingstring.py","producelatex.py","readfile.py",
> "separete.py","speak.py",
> )
[...]
> I am/was worried about the trailing ‘,' after ',"speak.py”,’ <- but
> deleting it or moving it after the ] didn’t help.

This has nothing to do with your problem but:

Python allows a trailing comma in any comma-separated list of values. It
will just be ignored.

This is really common in modern programming languages (read: programming
languages younger than 30 years or so), because it makes it much more
convenient to extend/shorten/reorder a list. Otherwise you alway have to
remember add or remove a comma in the right place. (Some people
(especially SQL programmers for some reason) resorted to put the comma
at the start of each line to get around this, which is really ugly.)

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: Problem using cx_Freeze

2022-08-17 Thread Dennis Lee Bieber
On Wed, 17 Aug 2022 12:09:14 -0600, David at Booomer 
declaimed the following:

>executables=[
>Executable(
>
> "prjui.py","Maiui.py","about.py","dict.py","geometry.py","getEquation.py",
>
> "gtrail.py","main.py","matchingstring.py","producelatex.py","readfile.py",
>"separete.py","speak.py",
>)
>]
>)
>
You are defining a list "executables" with only ONE member... (and is
that really how you spelled "separate").

>Searching for ‘__init__(' in the 13 *.py files returned five lines in two 
>files (algorithm.py and prjui.py). As mentioned searching for this error only 
>produced mention of adding self which is in these lines already. Previously I 
>had search for __init__() which returned no lines due to the closing ).
>
You are still searching the wrong place... The __init__() that is
complaining is the one in cx_Freeze.Executable().

>I had visited the page you provided 
>(https://cx-freeze.readthedocs.io/en/latest/setup_script.html#cx-freeze-executable)
> but didn’t noticed the 11 plus self as 12 arguments.

Really? Please count (reformatted from cut):
"""
argument name   description

#1
script  the name of the file containing 
the script
which is to be frozen

#2
init_script the name of the initialization 
script that will
be executed before the actual script is executed; this script is used to
set up the environment for the executable; if a name is given without an
absolute path the names of files in the initscripts subdirectory of the
cx_Freeze package is searched

#3
basethe name of the base 
executable; if a name is
given without an absolute path the names of files in the bases subdirectory
of the cx_Freeze package is searched

#4
target_name the name of the target executable; the 
default
value is the name of the script; the extension is optional (automatically
added on Windows); support for names with version; if specified a pathname,
raise an error.

#5
iconname of icon which should be 
included in the
executable itself on Windows or placed in the target directory for other
platforms (ignored in Microsoft Store Python app)

#6
manifestname of manifest which should 
be included in
the executable itself (Windows only - ignored by Python app from Microsoft
Store)

#7
uac-admin   creates a manifest for an 
application that will
request elevation (Windows only - ignored by Python app from Microsoft
Store)

#8
shortcut_name   the name to give a shortcut for the 
executable
when included in an MSI package (Windows only).

#9
shortcut_dirthe directory in which to place 
the
shortcut when being installed by an MSI package; see the MSI Shortcut table
documentation for more information on what values can be placed here
(Windows only).

#10
copyright   the copyright value to include 
in the version
resource associated with executable (Windows only).

#11
trademarks  the trademarks value to include 
in the version
resource associated with the executable (Windows only).
"""

You are passing 13 .py file names. There are only two arguments that
really want file names: script, and init_script. Most of the other
arguments are either optional or Windows specific (#6-11).

I suspect you need to pass JUST main.py or Maiui.py (based on casing)
-- which ever is really the file you'd invoke to start the program running.
I'd hope the freeze system then scans (recursively) that file to find
anything imported, and include those in the final product.


-- 
Wulfraed Dennis Lee Bieber AF6VN
wlfr...@ix.netcom.comhttp://wlfraed.microdiversity.freeddns.org/
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Problem using cx_Freeze

2022-08-17 Thread David at Booomer
Hi Dennis

Thank you for your reply. I’m am trying to get LaTex-to-Speech 
(https://github.com/SGanesh19/LaTeX-to-Speech) to run as an accessibility aid, 
converting equations into speech. I haven’t used cx_Freeze before so stumbling 
somewhat.

The error returned is

  File 
"/Users/duser/Documents/Win_ShareFolder/LaTeX-to-Speech-master/setup.py", line 
9, in 
Executable(
TypeError: __init__() takes from 2 to 12 positional arguments but 14 were given

The setup.py file is currently

import cx_Freeze
# from cx_Freeze import *
from cx_Freeze import setup, Executable

setup(
name="Latex2Speech",
options = {'build_exe':{'packages':['gtts','pyglet','PyQt4']}},
executables=[
Executable(

"prjui.py","Maiui.py","about.py","dict.py","geometry.py","getEquation.py",

"gtrail.py","main.py","matchingstring.py","producelatex.py","readfile.py",
"separete.py","speak.py",
)
]
)

I am/was worried about the trailing ‘,' after ',"speak.py”,’ <- but deleting it 
or moving it after the ] didn’t help. Adding base = None also didn’t help.

Searching for ‘__init__(' in the 13 *.py files returned five lines in two files 
(algorithm.py and prjui.py). As mentioned searching for this error only 
produced mention of adding self which is in these lines already. Previously I 
had search for __init__() which returned no lines due to the closing ).

I had visited the page you provided 
(https://cx-freeze.readthedocs.io/en/latest/setup_script.html#cx-freeze-executable)
 but didn’t noticed the 11 plus self as 12 arguments.

Thanks again for any suggestions.

David


> From: Dennis Lee Bieber 
> Subject: Re: Problem using cx_Freeze
> Date: August 15, 2022 at 8:18:54 PM MDT
> To: python-list@python.org
> 
> 
> On Mon, 15 Aug 2022 18:00:48 -0600, David at Booomer 
> declaimed the following:
> 
> 
>> However I now get an error
>> 
>> init() takes from 2 to 12 positional arguments but 14 were given
>> 
>> I found a couple instances of init in two .py files that were part of the 
>> whole.
>> 
>> One .py file
>> def __init__(self):
>> 
> 
>   Please cut the TEXT of the console where the errors are displayed
> -- don't paraphrase!
> 
>   init() is NOT the same as __init__()
> 
>   WHAT "One .py file"? This is a meaningless bit of information.
> 
>   The most likely __init__() involved is the one where
> cx_Freeze.Executable is instantiated.
> https://cx-freeze.readthedocs.io/en/latest/setup_script.html#cx-freeze-executable
> shows 11 parameters (and "self" would make the 12th).
> 
> -- 
>   Wulfraed Dennis Lee Bieber AF6VN
>   wlfr...@ix.netcom.comhttp://wlfraed.microdiversity.freeddns.org/
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Problem using cx_Freeze

2022-08-16 Thread Dennis Lee Bieber
On Mon, 15 Aug 2022 18:00:48 -0600, David at Booomer 
declaimed the following:


>However I now get an error
>
>init() takes from 2 to 12 positional arguments but 14 were given
>
>I found a couple instances of init in two .py files that were part of the 
>whole.
>
>One .py file
>def __init__(self):
>

Please cut the TEXT of the console where the errors are displayed
-- don't paraphrase!

init() is NOT the same as __init__()

WHAT "One .py file"? This is a meaningless bit of information.

The most likely __init__() involved is the one where
cx_Freeze.Executable is instantiated.
https://cx-freeze.readthedocs.io/en/latest/setup_script.html#cx-freeze-executable
shows 11 parameters (and "self" would make the 12th).





-- 
Wulfraed Dennis Lee Bieber AF6VN
wlfr...@ix.netcom.comhttp://wlfraed.microdiversity.freeddns.org/
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Problem using cx_Freeze

2022-08-15 Thread Dennis Lee Bieber
On Mon, 15 Aug 2022 10:30:41 -0600, David at Booomer 
declaimed the following:

>I’m trying to use cx_Freeze (https://pypi.org/project/cx-Freeze/) in a python 
>app but running into an error message:
>
>AttributeError: module 'cx_Freeze' has no attribute ‘BdistDMG’

What operating system? BdistDMG appears to be a Macintosh OS module --
something to do with disk images

https://cx-freeze.readthedocs.io/en/latest/setup_script.html
"""
On Windows, you can build a simple installer containing all the files
cx_Freeze includes for your application, by running the setup script as:

python setup.py bdist_msi

On Mac OS X, you can use bdist_dmg to build a Mac disk image.
"""

Note the command syntax and last line...


-- 
Wulfraed Dennis Lee Bieber AF6VN
wlfr...@ix.netcom.comhttp://wlfraed.microdiversity.freeddns.org/
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Problem using cx_Freeze

2022-08-15 Thread David at Booomer
Hi Jim

Thanks for your suggestions.

I changed

from cx_Freeze import *

to

from cx_Freeze import setup, Executable

And no longer get the BdistDMG error

—
I had found the page
https://cx-freeze.readthedocs.io/en/latest/setup_script.html
But hadn’t tried the setup, Executable option in the from statement
—

However I now get an error

init() takes from 2 to 12 positional arguments but 14 were given

I found a couple instances of init in two .py files that were part of the whole.

One .py file
def __init__(self):

Another .py file
class Aboutwindow(QtGui.QMainWindow, Ui_Aboutwindow):
def __init__(self,parent=None):
QtGui.QMainWindow.__init__(self,parent)
—
class Main(QtGui.QMainWindow):

def __init__(self):
QtGui.QMainWindow.__init__(self)

When searching for this error the answers found suggested including self in the 
init parameter list but the code already has self.

Thanks, David

> On Aug 15, 2022, at 5:51 PM, Jim Schwartz  wrote:
> 
> This link covers how to use BDist_dmg. 
> 
> https://cx-freeze.readthedocs.io/en/latest/setup_script.html
> 
> Sent from my iPhone
> 
>> On Aug 15, 2022, at 12:11 PM, David at Booomer  wrote:
>> 
>> I’m trying to use cx_Freeze (https://pypi.org/project/cx-Freeze/) in a 
>> python app but running into an error message:
>> 
>> AttributeError: module 'cx_Freeze' has no attribute ‘BdistDMG’
>> 
>> I’m using Anaconda and error appears with the import command: from cx_Freeze 
>> import *
>> 
>> From the terminal the command: python setup.py build gives much the same 
>> error.
>> 
>> I believe there is an issue specifying the output file name but don’t know 
>> how to resolve it.
>> 
>> Any suggestions, thanks. David
>> 
>> 
>> -- 
>> https://mail.python.org/mailman/listinfo/python-list

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


Re: Problem using cx_Freeze

2022-08-15 Thread Jim Schwartz
This link covers how to use BDist_dmg. 

https://cx-freeze.readthedocs.io/en/latest/setup_script.html

Sent from my iPhone

> On Aug 15, 2022, at 12:11 PM, David at Booomer  wrote:
> 
> I’m trying to use cx_Freeze (https://pypi.org/project/cx-Freeze/) in a 
> python app but running into an error message:
> 
> AttributeError: module 'cx_Freeze' has no attribute ‘BdistDMG’
> 
> I’m using Anaconda and error appears with the import command: from cx_Freeze 
> import *
> 
> From the terminal the command: python setup.py build gives much the same 
> error.
> 
> I believe there is an issue specifying the output file name but don’t know 
> how to resolve it.
> 
> Any suggestions, thanks. David
> 
> 
> -- 
> https://mail.python.org/mailman/listinfo/python-list
-- 
https://mail.python.org/mailman/listinfo/python-list


RE: Problem using cx_Freeze

2022-08-15 Thread jschwar
I see a class called BdistDMG in the module called bdist_mac.py.  Did you try 
importing that from cx_freeze?

-Original Message-
From: Python-list  On 
Behalf Of David at Booomer
Sent: Monday, August 15, 2022 11:31 AM
To: python-list@python.org
Subject: Problem using cx_Freeze

I’m trying to use cx_Freeze (https://pypi.org/project/cx-Freeze/) in a python 
app but running into an error message:

AttributeError: module 'cx_Freeze' has no attribute ‘BdistDMG’

I’m using Anaconda and error appears with the import command: from cx_Freeze 
import *

 From the terminal the command: python setup.py build gives much the same error.

I believe there is an issue specifying the output file name but don’t know how 
to resolve it.

Any suggestions, thanks. David


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

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


Re: Problem slicing a list with the C API

2022-03-12 Thread Chris Angelico
On Sun, 13 Mar 2022 at 10:41, Jen Kris  wrote:
>
>
> Thanks for PySequence_InPlaceConcat, so when I need to extend I'll know what 
> to use.  But my previous email was based on incorrect information from 
> several SO posts that claimed only the extend method will work to add tuples 
> to a list.  I found that's wrong -- even my own Python code uses the append 
> method.  But my PyList_Append is not doing the job so that's where I'm 
> looking now.
>

Ah. I guess that's one of the fundamental vulnerabilities of Stack
Overflow: people answer the question in front of them, which isn't
necessarily the question that YOU are trying to answer. Sometimes, the
solutions can be misleading, because your goal is actually different.

Fortunately, tuples in Python are objects, like every other value.
It's extremely convenient - to word that another way, it's extremely
INconvenient to work with a language where that isn't the case, and
you need to work differently depending on whether you're using
integers or strings. This is how you work with a trie (actually an
artifact name now, as it's implemented with a hashtable) in SourceMod
- this is the equivalent of dictionary subscript assignment:

https://sm.alliedmods.net/new-api/adt_trie/SetTrieValue
- works for integers, floats, and handles (which are integers)

https://sm.alliedmods.net/new-api/adt_trie/SetTrieString
- works for strings

Yup, it's annoying :)

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


Re: Problem slicing a list with the C API

2022-03-12 Thread Jen Kris via Python-list

Thanks for PySequence_InPlaceConcat, so when I need to extend I'll know what to 
use.  But my previous email was based on incorrect information from several SO 
posts that claimed only the extend method will work to add tuples to a list.  I 
found that's wrong -- even my own Python code uses the append method.  But my 
PyList_Append is not doing the job so that's where I'm looking now.  

Thanks very much for your reply.

Mar 12, 2022, 15:36 by ros...@gmail.com:

> On Sun, 13 Mar 2022 at 10:30, Jen Kris  wrote:
>
>>
>>
>> Chris, you were right to focus on the list pDictData itself.   As I said, 
>> that is a list of 2-tuples, but I added each of the 2-tuples with 
>> PyList_Append, but you can only append a tuple to a list with the extend 
>> method.  However, there is no append method in the C API as far as I can 
>> tell -- hence pDictData is empty.  I tried with PyList_SetItem but that 
>> doesn't work.  Do you know of way to "extend" a list in the C API.
>>
>
> Hmm. Not entirely sure I understand the question.
>
> In Python, a list has an append method, which takes any object (which
> may be a tuple) and adds that object to the end of the list:
>
 x = ["spam", "ham"]
 x.append((1,2))
 x

> ['spam', 'ham', (1, 2)]
>
> A list also has an extend method, which takes any sequence (that also
> includes tuples), and adds *the elements from it* to the end of the
> list:
>
 x = ["spam", "ham"]
 x.extend((1,2))
 x

> ['spam', 'ham', 1, 2]
>
> The append method corresponds to PyList_Append, as you mentioned. It
> should be quite happy to append a tuple, and will add the tuple
> itself, not the contents of it. So when you iterate over the list,
> you'll get tuples.
>
> Extending a list can be done with the sequence API. In Python, you can
> write extend() as +=, indicating that you're adding something onto the
> end:
>
 x = ["spam", "ham"]
 x += (1, 2)
 x

> ['spam', 'ham', 1, 2]
>
> This corresponds to PySequence_InPlaceConcat, so if that's the
> behaviour you want, that would be the easiest way to do it.
>
> Based on your other comments, I would suspect that appending the
> tuples is probably what you want here?
>
> ChrisA
> -- 
> https://mail.python.org/mailman/listinfo/python-list
>

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


Re: Problem slicing a list with the C API

2022-03-12 Thread Chris Angelico
On Sun, 13 Mar 2022 at 10:30, Jen Kris  wrote:
>
>
> Chris, you were right to focus on the list pDictData itself.   As I said, 
> that is a list of 2-tuples, but I added each of the 2-tuples with 
> PyList_Append, but you can only append a tuple to a list with the extend 
> method.  However, there is no append method in the C API as far as I can tell 
> -- hence pDictData is empty.  I tried with PyList_SetItem but that doesn't 
> work.  Do you know of way to "extend" a list in the C API.
>

Hmm. Not entirely sure I understand the question.

In Python, a list has an append method, which takes any object (which
may be a tuple) and adds that object to the end of the list:

>>> x = ["spam", "ham"]
>>> x.append((1,2))
>>> x
['spam', 'ham', (1, 2)]

A list also has an extend method, which takes any sequence (that also
includes tuples), and adds *the elements from it* to the end of the
list:

>>> x = ["spam", "ham"]
>>> x.extend((1,2))
>>> x
['spam', 'ham', 1, 2]

The append method corresponds to PyList_Append, as you mentioned. It
should be quite happy to append a tuple, and will add the tuple
itself, not the contents of it. So when you iterate over the list,
you'll get tuples.

Extending a list can be done with the sequence API. In Python, you can
write extend() as +=, indicating that you're adding something onto the
end:

>>> x = ["spam", "ham"]
>>> x += (1, 2)
>>> x
['spam', 'ham', 1, 2]

This corresponds to PySequence_InPlaceConcat, so if that's the
behaviour you want, that would be the easiest way to do it.

Based on your other comments, I would suspect that appending the
tuples is probably what you want here?

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


Re: Problem slicing a list with the C API

2022-03-12 Thread Jen Kris via Python-list

Chris, you were right to focus on the list pDictData itself.   As I said, that 
is a list of 2-tuples, but I added each of the 2-tuples with PyList_Append, but 
you can only append a tuple to a list with the extend method.  However, there 
is no append method in the C API as far as I can tell -- hence pDictData is 
empty.  I tried with PyList_SetItem but that doesn't work.  Do you know of way 
to "extend" a list in the C API.  
Thanks very much.  

Jen



Mar 12, 2022, 13:57 by ros...@gmail.com:

> On Sun, 13 Mar 2022 at 08:54, Jen Kris  wrote:
>
>>
>>
>> pDictData, despite the name, is a list of 2-tuples where each 2-tuple is a 
>> dictionary object and a string.
>>
>
> Ah, gotcha. In that case, yeah, slicing it will involve referencing
> the tuples all the way down the line (adding to their refcounts, so if
> there's a borked one, kaboom).
>
> ChrisA
> -- 
> https://mail.python.org/mailman/listinfo/python-list
>

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


Re: Problem slicing a list with the C API

2022-03-12 Thread Chris Angelico
On Sun, 13 Mar 2022 at 08:54, Jen Kris  wrote:
>
>
> pDictData, despite the name, is a list of 2-tuples where each 2-tuple is a 
> dictionary object and a string.
>

Ah, gotcha. In that case, yeah, slicing it will involve referencing
the tuples all the way down the line (adding to their refcounts, so if
there's a borked one, kaboom).

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


Re: Problem slicing a list with the C API

2022-03-12 Thread Jen Kris via Python-list

pDictData, despite the name, is a list of 2-tuples where each 2-tuple is a 
dictionary object and a string.  

Mar 12, 2022, 13:41 by ros...@gmail.com:

> On Sun, 13 Mar 2022 at 08:25, Jen Kris via Python-list
>  wrote:
>
>> PyObject* slice = PySlice_New(PyLong_FromLong(0), half_slice, 0);
>> PyObject* subdata_a = PyObject_GetItem(pDictddata, slice);
>>
>> On the final line (subdata_a) I get a segfault.  I know that the second 
>> parameter of  PyObject_GetItem is a “key” and I suspect that’s where the 
>> problem comes from, but I don’t understand what a key is in this context.
>>
>
> The key is simply whatever would be in the square brackets in Python
> code, so that part looks fine.
>
> But dictionaries aren't usually subscripted with slices, so I'm a bit
> confused as to what's going on here. What exactly is
> dictdata/pDictdata?
>
> Have you confirmed that pDictdata (a) isn't NULL, (b) is the object
> you intend it to be, and (c) contains the objects you expect it to?
> The segfault might not be from the slice object itself, it might be
> from actually iterating over the thing being sliced and touching all
> its elements. For instance, if dictdata is actually a list, that call
> will be constructing a new list with references to the same elements,
> so if one of them is broken (maybe NULL), it'll break badly.
>
> ChrisA
> -- 
> https://mail.python.org/mailman/listinfo/python-list
>

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


Re: Problem slicing a list with the C API

2022-03-12 Thread Jen Kris via Python-list

Thanks to you both.  I am going to implement PySequence_Get_Slice now.  If I 
have trouble then, per comments from Chris Angelico, I will iterate through 
pDictData to verify it because I haven't done that.  It is not null, however.  

 Jen


Mar 12, 2022, 13:40 by pyt...@mrabarnett.plus.com:

> On 2022-03-12 21:24, Jen Kris via Python-list wrote:
>
>> I have a C API project where I have to slice a list into two parts.   
>> Unfortunately the documentation on the slice objects is not clear enough for 
>> me to understand how to do this, and I haven’t found enough useful info 
>> through research.  The list contains tuple records where each tuple consists 
>> of a dictionary object and a string.
>>
>> The relevant part of the Python code is:
>>
>> half_slice = int(len(dictdata) * 0.5)
>> subdata_a = dictdata[half_slice:]
>> subdata_b = dictdata[:half_slice]
>>
>> This is what I’ve done so far with the C API:
>>
>> int64_t Calc_Slices(PyObject* pDictdata, int64_t records_count)
>> {
>> long round_half = records_count * 0.5;
>> PyObject* half_slice = PyLong_FromLong(round_half);
>>
>> PyObject* slice = PySlice_New(PyLong_FromLong(0), half_slice, 0);
>> PyObject* subdata_a = PyObject_GetItem(pDictddata, slice);
>>
>> return 0;
>> }
>>
>> On the final line (subdata_a) I get a segfault.  I know that the second 
>> parameter of  PyObject_GetItem is a “key” and I suspect that’s where the 
>> problem comes from, but I don’t understand what a key is in this context.
>>
>> The code shown above omits error handling but none of the objects leading up 
>> to the final line is null, they all succeed.
>>
>> Thanks for any ideas.
>>
> Use PySequence_GetSlice to slice the list.
>
> Also, why use floats when you can use integers?
>
>  long round_half = records_count / 2;
>
> (In Python that would be half_slice = len(dictdata) // 2.)
> -- 
> https://mail.python.org/mailman/listinfo/python-list
>

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


Re: Problem slicing a list with the C API

2022-03-12 Thread Chris Angelico
On Sun, 13 Mar 2022 at 08:25, Jen Kris via Python-list
 wrote:
> PyObject* slice = PySlice_New(PyLong_FromLong(0), half_slice, 0);
> PyObject* subdata_a = PyObject_GetItem(pDictddata, slice);
>
> On the final line (subdata_a) I get a segfault.  I know that the second 
> parameter of  PyObject_GetItem is a “key” and I suspect that’s where the 
> problem comes from, but I don’t understand what a key is in this context.
>

The key is simply whatever would be in the square brackets in Python
code, so that part looks fine.

But dictionaries aren't usually subscripted with slices, so I'm a bit
confused as to what's going on here. What exactly is
dictdata/pDictdata?

Have you confirmed that pDictdata (a) isn't NULL, (b) is the object
you intend it to be, and (c) contains the objects you expect it to?
The segfault might not be from the slice object itself, it might be
from actually iterating over the thing being sliced and touching all
its elements. For instance, if dictdata is actually a list, that call
will be constructing a new list with references to the same elements,
so if one of them is broken (maybe NULL), it'll break badly.

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


Re: Problem slicing a list with the C API

2022-03-12 Thread MRAB

On 2022-03-12 21:24, Jen Kris via Python-list wrote:

I have a C API project where I have to slice a list into two parts.   
Unfortunately the documentation on the slice objects is not clear enough for me 
to understand how to do this, and I haven’t found enough useful info through 
research.  The list contains tuple records where each tuple consists of a 
dictionary object and a string.

The relevant part of the Python code is:

half_slice = int(len(dictdata) * 0.5)
subdata_a = dictdata[half_slice:]
subdata_b = dictdata[:half_slice]

This is what I’ve done so far with the C API:

int64_t Calc_Slices(PyObject* pDictdata, int64_t records_count)
{
long round_half = records_count * 0.5;
PyObject* half_slice = PyLong_FromLong(round_half);

PyObject* slice = PySlice_New(PyLong_FromLong(0), half_slice, 0);
PyObject* subdata_a = PyObject_GetItem(pDictddata, slice);

return 0;
}

On the final line (subdata_a) I get a segfault.  I know that the second 
parameter of  PyObject_GetItem is a “key” and I suspect that’s where the 
problem comes from, but I don’t understand what a key is in this context.

The code shown above omits error handling but none of the objects leading up to 
the final line is null, they all succeed.

Thanks for any ideas.


Use PySequence_GetSlice to slice the list.

Also, why use floats when you can use integers?

long round_half = records_count / 2;

(In Python that would be half_slice = len(dictdata) // 2.)
--
https://mail.python.org/mailman/listinfo/python-list


Re: Problem upgrading pip and installing pygame

2022-01-31 Thread Mats Wichmann
On 1/31/22 07:18, ojomooluwatolami...@gmail.com wrote:
> 
> Good morning, Python. I am having trouble installing pygame. it keeps saying 
> to upgrade my pip version which I have done several times. then when I tried 
> importing python to see if it has worked, in the ide it says the module does 
> not exist or something along that line. what do I do please? Thanks.
> 
> Sent from my iPhone


When Python can't find modules it's *always* a path problem - the
install went somewhere on the system, but not to the places the Python
you are using is looking in.

One suggestion that usually helps is to use pip as a module, then it
will match exactly the Python used, because you're actually using that
Python.  So for example, if the way you invoke Python is through the
Windows Python launcher "py", then use this line:

py -m pip install --upgrade pip pygame


should put things in the right place.

adjust according to your situation, which we can't guess at.



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


Re: Problem upgrading pip and installing pygame

2022-01-31 Thread Dennis Lee Bieber
On Mon, 31 Jan 2022 14:18:47 +, ojomooluwatolami...@gmail.com declaimed
the following:

>
>Good morning, Python. I am having trouble installing pygame. it keeps saying 
>to upgrade my pip version which I have done several times. then when I tried 
>importing python to see if it has worked, in the ide it says the module does 
>not exist or something along that line. what do I do please? Thanks.

Where to begin... "importing python" is never done -- python is the
language and its interpreter/compiler.

Which "ide"?

Show us the EXACT operations you are performing and the results... [NOT
SCREEN CAPTURES -- this forum strips non-text attachments; select the TEXT
and cut that]


-- 
Wulfraed Dennis Lee Bieber AF6VN
wlfr...@ix.netcom.comhttp://wlfraed.microdiversity.freeddns.org/
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: problem reading a CSV file

2021-12-13 Thread Greg Ewing

On 14/12/21 7:07 am, MRAB wrote:
It's difficult to say what the problem is when you haven't given us the 
code!


Note: Attachments do not make it to this list.
You will need to insert the code into the message as text.

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


Re: problem reading a CSV file

2021-12-13 Thread MRAB

On 2021-12-12 23:37, Larry Warner wrote:

Win 10, Chrome, Python 3.10.1
New at python
error on open statement

Probably simple error but I do not see it.

The program is a python example with the file name being changed.  I want
to experiment with changing the literal file name in the open statement to
a variable name later.

It's difficult to say what the problem is when you haven't given us the 
code!

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


Re: problem reading a CSV file

2021-12-13 Thread Chris Angelico
On Tue, Dec 14, 2021 at 12:05 AM Larry Warner  wrote:
>
> Win 10, Chrome, Python 3.10.1
> New at python
> error on open statement
>
> Probably simple error but I do not see it.
>
> The program is a python example with the file name being changed.  I want
> to experiment with changing the literal file name in the open statement to
> a variable name later.
>

Use forward slashes "/" instead of backslashes "\".

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


RE: Problem with concatenating two dataframes

2021-11-08 Thread Schachner, Joseph
The problem I see here is use of Pandas.   I know I have he losing opinion, but 
people who use Python to load Panadas and then only use Pandas are missing out 
on the functionality of Python.

I'll bet you could code combining this data in pure Python, into one 
dictionary. In fact I'd be shocked if you couldn't do it.

 Joseph S.


Teledyne Confidential; Commercially Sensitive Business Data

-Original Message-
From: Mahmood Naderan  
Sent: Saturday, November 6, 2021 6:01 PM
To: python-list@python.org; MRAB 
Subject: Re: Problem with concatenating two dataframes

>The second argument of pd.concat is 'axis', which defaults to 0. Try 
>using 1 instead of 0.


Unfortunately, that doesn't help...


dict[name] = pd.concat( [dict[name],values], axis=1 )



{'dummy': Value
M1  0
M2  0
M3  0, 'K1':Value  Value
0   10.0NaN
15.0NaN
2   10.0NaN
6NaN2.0
7NaN2.0
8NaN2.0, 'K2':Value
3 20
4 10
5 15}



Regards,
Mahmood



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


Re: Problem with concatenating two dataframes

2021-11-06 Thread Mahmood Naderan via Python-list
>The second argument of pd.concat is 'axis', which defaults to 0. Try
>using 1 instead of 0.


Unfortunately, that doesn't help...


dict[name] = pd.concat( [dict[name],values], axis=1 )



{'dummy': Value
M1  0
M2  0
M3  0, 'K1':Value  Value
0   10.0NaN
15.0NaN
2   10.0NaN
6NaN2.0
7NaN2.0
8NaN2.0, 'K2':Value
3 20
4 10
5 15}



Regards,
Mahmood



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


Re: Problem with concatenating two dataframes

2021-11-06 Thread MRAB


On 2021-11-06 20:12, Mahmood Naderan wrote:

>Try this instead:
>
>
>    dict[name] = pd.concat([dict[name], values])


OK. That fixed the problem, however, I see that they are concatenated 
vertically. How can I change that to horizontal? The printed dictionary in the 
end looks like


{'dummy': Value
M1  0
M2  0
M3  0, 'K1':    Value
0 10
1  5
2 10
6  2
7  2
8  2, 'K2':    Value
3 20
4 10
5 15}



For K1, there should be three rows and two columns labeled as Value.

The second argument of pd.concat is 'axis', which defaults to 0. Try 
using 1 instead of 0.

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


Re: Problem with concatenating two dataframes

2021-11-06 Thread Mahmood Naderan via Python-list
>Try this instead:
>
>
>    dict[name] = pd.concat([dict[name], values])


OK. That fixed the problem, however, I see that they are concatenated 
vertically. How can I change that to horizontal? The printed dictionary in the 
end looks like


{'dummy': Value
M1  0
M2  0
M3  0, 'K1':    Value
0 10
1  5
2 10
6  2
7  2
8  2, 'K2':    Value
3 20
4 10
5 15}



For K1, there should be three rows and two columns labeled as Value.




Regards,
Mahmood





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


Re: Problem with concatenating two dataframes

2021-11-06 Thread MRAB

On 2021-11-06 16:16, Mahmood Naderan via Python-list wrote:

In the following code, I am trying to create some key-value pairs in a 
dictionary where the first element is a name and the second element is a 
dataframe.

# Creating a dictionary
data = {'Value':[0,0,0]}
kernel_df = pd.DataFrame(data, index=['M1','M2','M3'])
dict = {'dummy':kernel_df}
# dummy  ->  Value
#   M1  0
#   M2  0
#   M3  0


Then I read a file and create some batches and compare the name in the batch 
with the stored names in dictionary. If it doesn't exist, a new key-value (name 
and dataframe) is created. Otherwise, the Value column is appended to the 
existing dataframe.


df = pd.read_csv('test.batch.csv')
print(df)
for i in range(0, len(df), 3):
 print("\n--BATCH BEGIN")
 batch_df = df.iloc[i:i+3]
 name = batch_df.loc[i].at["Name"]
 values = batch_df.loc[:,["Value"]]
 print(name)
 print(values)
 print("--BATCH END")
 if name in dict:
 # Append values to the existing key
     dict[name] = pd.concat( dict[name],values )    ERROR
 else:
 # Create a new pair in dictionary
 dict[name] = values;



As you can see in the output, the join statement has error.



     ID Name Metric  Value
0   0   K1 M1 10
1   0   K1 M2  5
2   0   K1 M3 10
3   1   K2 M1 20
4   1   K2 M2 10
5   1   K2 M3 15
6   2   K1 M1  2
7   2   K1 M2  2
8   2   K1 M3  2

--BATCH BEGIN
K1
    Value
0 10
1  5
2 10
--BATCH END

--BATCH BEGIN
K2
    Value
3 20
4 10
5 15
--BATCH END

--BATCH BEGIN
K1
    Value
6  2
7  2
8  2
--BATCH END




As it reaches the contact() statement, I get this error:

TypeError: first argument must be an iterable of pandas objects, you passed an object of 
type "DataFrame"


Based on the definition I wrote in the beginning of the code, "dict[name]" 
should be a dataframe. Isn't that?

How can I fix that?

You're trying to concatenate by passing the 2 items as the first 2 
arguments to pd.concat, but I think that you're supposed to pass them as 
an _iterable_, e.g. a list, as the first argument to pd.concat.


Try this instead:

dict[name] = pd.concat([dict[name], values])
--
https://mail.python.org/mailman/listinfo/python-list


Re: Problem with python

2021-09-06 Thread Grant Edwards
On 2021-09-04, Hope Rouselle  wrote:
> Igor Korot  writes:
>
>> Hi,
>> Will this syntax work in python 2?
>
> If you say
>
>   print(something)
>
> it works in both.

But it doesn't always work the _same_ in both. If you're expecting
some particular output, then one or the other might not won't "work".

> So, stick to this syntax.

Only if you import print_function from __future__ in 2.x

--
Grant


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


Re: Problem with python

2021-09-04 Thread Grant Edwards
On 2021-09-04, Peter J. Holzer  wrote:
> On 2021-09-04 14:29:47 -0500, Igor Korot wrote:
>> Will this syntax work in python 2?
>
> Yes. It's just a redundant pair of parentheses.

Not really. With the parens, it doesn't produce the same results in
2.x unless you import the print function from the future:

 Python 3.9.6 (default, Aug  9 2021, 12:35:39)
 [GCC 10.3.0] on linux
 Type "help", "copyright", "credits" or "license" for more information.
 >>> print(1,2)
 1 2

 Python 2.7.18 (default, Jul 18 2021, 14:51:54)
 [GCC 10.3.0] on linux2
 Type "help", "copyright", "credits" or "license" for more information.
 >>> print(1,2)
 (1, 2)

 Python 2.7.18 (default, Jul 18 2021, 14:51:54)
 [GCC 10.3.0] on linux2
 Type "help", "copyright", "credits" or "license" for more information.
 >>> from __future__ import print_function
 >>> print(1,2)
 1 2




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


Re: Problem with python

2021-09-04 Thread Terry Reedy

On 9/4/2021 2:27 PM, Igor Korot wrote:

Hi, ALL,

[code]
igor@WaylandGnome ~/bakefile $ python
Python 3.9.6 (default, Aug  8 2021, 17:26:32)
[GCC 10.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.

from distutils import sysconfig


In 3.10, distutils and d.sysconfig are deprecated, with suggestions to 
use setuptools or sysconfig modules instead.



print sysconfig.get_python_inc()

   File "", line 1
 print sysconfig.get_python_inc()
   ^
SyntaxError: invalid syntax


In interactive mode, print is not usually needed.

>>> sysconfig.get_python_inc()
'C:\\Programs\\Python310\\include'


--
Terry Jan Reedy

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


Re: Problem with python

2021-09-04 Thread Dennis Lee Bieber
On Sat, 4 Sep 2021 22:41:12 +0200, "Peter J. Holzer" 
declaimed the following:

>Python 3 to be time well spent in 2021, especially not to someone who
>apparently just wants to report a bug to some unnamed project (whose
>maintainers may or may not care about Python2 compatibility).
>

Given the nature of the error reported by the OP... It may be closer to
state "whose maintainers may or may not care about" /Python3/
"compatibility"; the code appears to already be Python2 compatible 



-- 
Wulfraed Dennis Lee Bieber AF6VN
wlfr...@ix.netcom.comhttp://wlfraed.microdiversity.freeddns.org/

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


Re: Problem with python

2021-09-04 Thread Hope Rouselle
Igor Korot  writes:

> Hi,
> Will this syntax work in python 2?

If you say

  print(something)

it works in both.  So, stick to this syntax.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Problem with python

2021-09-04 Thread Peter J. Holzer
On 2021-09-04 21:07:11 +0100, Rob Cliffe via Python-list wrote:
> Well, up to a point.
> In Python 2 the output from
>     print 1, 2
> is '1 2'
> In Python 3 if you add brackets:
>     print(1, 2)
> the output is the same.
> But if you transplant that syntax back into Python 2, the output from
>     print(1, 2)
> is '(1, 2)'.  The brackets have turned two separate items into a single
> tuple.

Yes. I was just talking about that specific case with a single function
call. I do not consider explaining the differences between Python 2 and
Python 3 to be time well spent in 2021, especially not to someone who
apparently just wants to report a bug to some unnamed project (whose
maintainers may or may not care about Python2 compatibility).

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: Problem with python

2021-09-04 Thread Rob Cliffe via Python-list

Well, up to a point.
In Python 2 the output from
    print 1, 2
is '1 2'
In Python 3 if you add brackets:
    print(1, 2)
the output is the same.
But if you transplant that syntax back into Python 2, the output from
    print(1, 2)
is '(1, 2)'.  The brackets have turned two separate items into a single 
tuple.
If you want Python 2- and 3-compatibility you must find a work-around 
such as

    print('%d %d' % (1,2))
    print('%s %s' % (1,2))
    print(str(1) + ' ' + str(2))

Similarly
    'print' in Python 2 outputs a blank line.
    'print()' in Python 3 outputs a blank line.  In python 2 it prints 
a line containing a blank tuple: '()'.

A 2/3-compatible way of outputting a blank line is
    print('')

Best wishes
Rob Cliffe




On 04/09/2021 20:50, Peter J. Holzer wrote:

On 2021-09-04 14:29:47 -0500, Igor Korot wrote:

Will this syntax work in python 2?

Yes. It's just a redundant pair of parentheses.

 hp




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


Re: Problem with python

2021-09-04 Thread Peter J. Holzer
On 2021-09-04 14:29:47 -0500, Igor Korot wrote:
> Will this syntax work in python 2?

Yes. It's just a redundant pair of parentheses.

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: Problem with python

2021-09-04 Thread Igor Korot
Hi,
Will this syntax work in python 2?

Thank you.

On Sat, Sep 4, 2021 at 1:52 PM dn via Python-list
 wrote:
>
> On 05/09/2021 06.27, Igor Korot wrote:
> > Hi, ALL,
> >
> > [code]
> > igor@WaylandGnome ~/bakefile $ python
> > Python 3.9.6 (default, Aug  8 2021, 17:26:32)
> > [GCC 10.3.0] on linux
> > Type "help", "copyright", "credits" or "license" for more information.
>  from distutils import sysconfig
>  print sysconfig.get_python_inc()
> >   File "", line 1
> > print sysconfig.get_python_inc()
> >   ^
> > SyntaxError: invalid syntax
> 
> > [/code]
> >
> > What is the proper way to fix this?
>
> Remember that in Python3 print became a function:
>
>  print( sysconfig.get_python_inc() )
>
> --
> Regards,
> =dn
> --
> https://mail.python.org/mailman/listinfo/python-list
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Problem with python

2021-09-04 Thread Igor Korot
Thx guys.
I submitted a bug report for the project that uses it.

On Sat, Sep 4, 2021 at 1:42 PM Joel Goldstick  wrote:
>
> On Sat, Sep 4, 2021 at 2:29 PM Igor Korot  wrote:
> >
> > Hi, ALL,
> >
> > [code]
> > igor@WaylandGnome ~/bakefile $ python
> > Python 3.9.6 (default, Aug  8 2021, 17:26:32)
> > [GCC 10.3.0] on linux
> > Type "help", "copyright", "credits" or "license" for more information.
> > >>> from distutils import sysconfig
> > >>> print sysconfig.get_python_inc()
> >   File "", line 1
> > print sysconfig.get_python_inc()
>
>  print( sysconfig.get_python_inc())
>
> Since python3 print is a function.
> >   ^
> > SyntaxError: invalid syntax
> > >>>
> > [/code]
> >
> > What is the proper way to fix this?
> >
> > Thank you.
> > --
> > https://mail.python.org/mailman/listinfo/python-list
>
>
>
> --
> Joel Goldstick
> --
> https://mail.python.org/mailman/listinfo/python-list
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Problem with python

2021-09-04 Thread dn via Python-list
On 05/09/2021 06.27, Igor Korot wrote:
> Hi, ALL,
> 
> [code]
> igor@WaylandGnome ~/bakefile $ python
> Python 3.9.6 (default, Aug  8 2021, 17:26:32)
> [GCC 10.3.0] on linux
> Type "help", "copyright", "credits" or "license" for more information.
 from distutils import sysconfig
 print sysconfig.get_python_inc()
>   File "", line 1
> print sysconfig.get_python_inc()
>   ^
> SyntaxError: invalid syntax

> [/code]
> 
> What is the proper way to fix this?

Remember that in Python3 print became a function:

 print( sysconfig.get_python_inc() )

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


Re: Problem with python

2021-09-04 Thread Mats Wichmann

On 9/4/21 12:27 PM, Igor Korot wrote:

Hi, ALL,

[code]
igor@WaylandGnome ~/bakefile $ python
Python 3.9.6 (default, Aug  8 2021, 17:26:32)
[GCC 10.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.

from distutils import sysconfig
print sysconfig.get_python_inc()

   File "", line 1
 print sysconfig.get_python_inc()
   ^
SyntaxError: invalid syntax



[/code]

What is the proper way to fix this?


print is a function in Python 3.

print(sysconfig.get_python_inc())

Try:

>>> help(print)

for a quick check.

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


Re: Problem with python

2021-09-04 Thread Joel Goldstick
On Sat, Sep 4, 2021 at 2:29 PM Igor Korot  wrote:
>
> Hi, ALL,
>
> [code]
> igor@WaylandGnome ~/bakefile $ python
> Python 3.9.6 (default, Aug  8 2021, 17:26:32)
> [GCC 10.3.0] on linux
> Type "help", "copyright", "credits" or "license" for more information.
> >>> from distutils import sysconfig
> >>> print sysconfig.get_python_inc()
>   File "", line 1
> print sysconfig.get_python_inc()

 print( sysconfig.get_python_inc())

Since python3 print is a function.
>   ^
> SyntaxError: invalid syntax
> >>>
> [/code]
>
> What is the proper way to fix this?
>
> Thank you.
> --
> https://mail.python.org/mailman/listinfo/python-list



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


Re: Problem with pip installation

2021-05-27 Thread Mats Wichmann

On 5/27/21 1:08 PM, Dennis Lee Bieber wrote:

On Thu, 27 May 2021 09:22:09 +0300, ? ???
 declaimed the following:


Good morning. I have o Windows 10 system and i can install pip. I try to
follow the instruction that i find on internet but the did not work. Also
itry to write the command pip install pip but again did not work. Also the
command py. did not work.  Thank you!


"did not work" is meaningless... cut the exact text from your
console window (not an image grab) with the commands you are entering and
the messages that you get...

Is the location of pip on your Windows PATH environment variable?





python -m pip

Python knows how to find the pip that goes with it - these days it's not 
at all uncommon to have several Pythons on a system.  Windows pythons 
are always initialized with pip these days so this is reliable.


I'm sure you've read every bit of advice on the internet already, but 
make sure you've looked over this one:


https://docs.python.org/3/using/windows.html

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


Re: Problem in uninstalling python

2021-04-09 Thread Igor Korot
Hi,

On Fri, Apr 9, 2021 at 10:35 AM Paul Bryan  wrote:
>
> Please describe your problem in detail.
>
> Paul
>
>
> On Fri, 2021-04-09 at 11:03 +0530, arishmallick...@gmail.com wrote:
> >I am encountering problem in uninstalling python. Please help me
> > in this.

I presume you tried to send a screenshot to the list...

Please don't!!

The list will DROP ANY AND ALL attachments.

Rather cut-and-paste any error you receive to the body of your message.

Thank you.

> >
> >
> >
> >Sent from [1]Mail for Windows 10
> >
> >
> >
> > References
> >
> >Visible links
> >1. https://go.microsoft.com/fwlink/?LinkId=550986
>
> --
> https://mail.python.org/mailman/listinfo/python-list
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Problem in uninstalling python

2021-04-09 Thread Paul Bryan
Please describe your problem in detail.

Paul


On Fri, 2021-04-09 at 11:03 +0530, arishmallick...@gmail.com wrote:
>    I am encountering problem in uninstalling python. Please help me
> in this.
> 
> 
> 
>    Sent from [1]Mail for Windows 10
> 
> 
> 
> References
> 
>    Visible links
>    1. https://go.microsoft.com/fwlink/?LinkId=550986

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


Re: Problem with printing statement when condition is false

2021-03-05 Thread Terry Reedy

On 3/4/2021 4:28 PM, Terry Reedy wrote:

Quentin privately sent me 12 lines (which should have been posted here 
instead), which can be reduced to the following 4 that exhibit his bug.


if a == b:
     print('correct')
     if a != b:
     print('incorrect')

The bug is a != b will never be true when a == b and will not be tested 
when a != b.  The fix is to use else.


if a == b:
     print('correct')
else:
     print('incorrect')

This should not be reduced to a conditional expression since different 
code follows the print statements in the actual example.


Quentin wrote me privately that this, applied to his code, solved his 
problem.



--
Terry Jan Reedy


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


Re: Problem with printing statement when condition is false

2021-03-04 Thread Terry Reedy

On 3/4/2021 3:15 PM, Terry Reedy wrote:

On 3/4/2021 12:10 PM, Quentin Bock wrote:


I won't paste the code into
this because it's 164 lines so I will attach a file copy,


The alternative to posting too much is to reduce your code to the 
minimum needed to exhibit the behavior you want to change.  Doing so may 
reveal to you the solution.  It will certainly make it easier for anyone 
else to help you and will make any answer more useful to other readers.


Quentin privately sent me 12 lines (which should have been posted here 
instead), which can be reduced to the following 4 that exhibit his bug.


if a == b:
print('correct')
if a != b:
print('incorrect')

The bug is a != b will never be true when a == b and will not be tested 
when a != b.  The fix is to use else.


if a == b:
print('correct')
else:
print('incorrect')

This should not be reduced to a conditional expression since different 
code follows the print statements in the actual example.


--
Terry Jan Reedy


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


Re: Problem with printing statement when condition is false

2021-03-04 Thread Terry Reedy

On 3/4/2021 12:10 PM, Quentin Bock wrote:


I won't paste the code into
this because it's 164 lines so I will attach a file copy,


The alternative to posting too much is to reduce your code to the 
minimum needed to exhibit the behavior you want to change.  Doing so may 
reveal to you the solution.  It will certainly make it easier for anyone 
else to help you and will make any answer more useful to other readers.


--
Terry Jan Reedy

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


Re: Problem when scraping the 100 Movie titles.

2021-02-18 Thread Mats Wichmann

On 2/18/21 10:43 AM, Aakash Jana wrote:

I have done some webscraping before i think you need to get a slightly more
tactical way to get these titles scraped .
Try to see what classes identify the cards (in which movie title is given)
and then try to pull the heading out of those.
Try to get the divs in a list , something like this "" in my case and then try to
pull
the h3 tag out of it . Onething to note is react os single page heavy
webapps have seemed to be difficult to scrape maybe beautiful
isnt made for JSX .

On Thu, Feb 18, 2021 at 9:09 PM Bischoop  wrote:



I'm learning Scraping actually and would like to scrape the movie titles
from https://www.empireonline.com/movies/features/best-movies-2 .
In the course I was learning I was supposed to do it with bs4:


Just in general, most websites don't want you to scrape them, and some 
go to considerable efforts to make it difficult, and some explicitly 
disallow downloading any content except for caching purposes.  If the 
website provides an API, that's how they expect you go consume data that 
isn't render through a web browser.


Just sayin' ...  there's no reason not to learn the concepts of web 
scraping but should ALSO be aware of terms of use.


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


Re: Problem when scraping the 100 Movie titles.

2021-02-18 Thread Aakash Jana
I have done some webscraping before i think you need to get a slightly more
tactical way to get these titles scraped .
Try to see what classes identify the cards (in which movie title is given)
and then try to pull the heading out of those.
Try to get the divs in a list , something like this "" in my case and then try to
pull
the h3 tag out of it . Onething to note is react os single page heavy
webapps have seemed to be difficult to scrape maybe beautiful
isnt made for JSX .

On Thu, Feb 18, 2021 at 9:09 PM Bischoop  wrote:

>
> I'm learning Scraping actually and would like to scrape the movie titles
> from https://www.empireonline.com/movies/features/best-movies-2 .
> In the course I was learning I was supposed to do it with bs4:
> titles = soup.find_all(name = 'h3', class_ = 'title')
>
> but after after a while I guess the site has changed and now the class
> is: jsx-2692754980
>
> 100) Stand By Me
>
> but anyway if I do try get those titles by name and class, my list is
> empty:
> titles = soup.find_all(name = 'h3', class_ = 'jsx-2692754980')
>
> I tried also selenium and manage get those titles with:
> driver.get('https://www.empireonline.com/movies/features/best-movies-2')
>
> #driver.find_element_by_xpath('/html/body/div/div[3]/div[5]/button[2]').click()
>
> titles = driver.find_elements_by_css_selector("h3.jsx-2692754980")
>
> tit=[]
> for e in titles:
> tit.append(e.text)
>
> print(tit)
>
> But in Chrome I get a popup asking to accept cookies and I need to
> click to accept them.
>
> Is someone here who knows how can I get those titles with BeautifulSoup
> and how to deal with
> cookies if using Selenium?
>
> --
> Thanks
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: problem in installation of python 3.9.0

2020-12-02 Thread Barry


> On 2 Dec 2020, at 18:01, Dan Stromberg  wrote:
> 
> On Wed, Dec 2, 2020 at 9:45 AM Mats Wichmann  wrote:
> 
>>> On 12/2/20 10:57 AM, Priyankgasree K wrote:
>>> Hello,
>>> I am Priyankgasree, i am facing problem in installing
>> python3.9.0.
>>> after i finish download it always says you have to repair or uninstall. I
>>> have repaired and uninstalled and reinstalled several times but i can't
>> do
>>> anything . And also I cant able to download other versions of python. So
>>> tell me what`s the problem and the solution
>> 
>> Don't rerun the installer.  That's its purpose: to let you install, or
>> modify the existing installation.  You can remove the downloaded
>> installer after you're done with it.
>> 
>> Instead, either run Python from a shell - use the command name py if you
>> installed the Python launcher.  Or use the Windows search box to look
>> for the command named python, the match you want should looke something
>> like "Python 3.9 (64-bit)  App"
>> 
> This seems to be a common question and answer.
> 
> Perhaps the installer could be named better, or Python could provide a
> shortcut for itself?

You mean like including the word setup or installer in the file name?
That’s what everybody else does isn’t it?

Barry

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

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


  1   2   3   4   5   6   7   8   9   10   >