Re: Difficulty in generating .exe from .py file

2020-02-25 Thread Abdur-Rahmaan Janhangeer
Can you share your codes? Thank you!

On Wed, 26 Feb 2020, 00:45 Aakash Jana,  wrote:

> I have made a simple web scraper that scrapes Wikipedia and prints some
> info on to the command line using requests and BeautifulSoup. Whenever I
> execute pyinstaller it gives an error "expected integer got type bytes"
> although the code runs perfectly. I am using python 3.8
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Python 3.8.2 and 3.9.0a4 are now available

2020-02-25 Thread Łukasz Langa
On behalf of the entire Python development community, and the currently serving 
Python release team in particular, I’m pleased to announce the release of two 
of the latest Python editions.

Python 3.8.2

Python 3.8.2 is the second maintenance release of Python 3.8 and contains two 
months worth of bug fixes. Detailed information about all changes made in 3.8.2 
can be found in its change log 
.
 Note that compared to 3.8.1, version 3.8.2 also contains the changes 
introduced in 3.8.2rc1 and 3.8.2rc2.

The Python 3.8 series is the newest feature release of the Python language, and 
it contains many new features and optimizations. You can find Python 3.8.2 here:
https://www.python.org/downloads/release/python-382/ 

See the “What’s New in Python 3.8 
” document for more information 
about features included in the 3.8 series.

Maintenance releases for the 3.8 series will continue at regular bi-monthly 
intervals, with 3.8.3 planned for April 2020 (at the PyCon US sprints 
).

Python 3.9.0a4

An early developer preview of Python 3.9 is also ready:
https://www.python.org/downloads/release/python-390a4/ 

Python 3.9 is still in development. This releasee, 3.9.0a4 is the fourth of six 
planned alpha releases. Alpha releases are intended to make it easier to test 
the current state of new features and bug fixes and to test the release 
process. During the alpha phase, features may be added up until the start of 
the beta phase (2020-05-18) and, if necessary, may be modified or deleted up 
until the release candidate phase (2020-08-10). Please keep in mind that this 
is a preview release and its use is not recommended for production environments.

We hope you enjoy both!

Thanks to all of the many volunteers who help make Python Development and these 
releases possible! Please consider supporting our efforts by volunteering 
yourself or through organization contributions to the Python Software 
Foundation.
https://www.python.org/psf/ 
Your friendly release team,
Ned Deily
Steve Dower
Łukasz Langa
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: encapsulating a global variable

2020-02-25 Thread Greg Ewing

On 26/02/20 3:56 am, BlindAnagram wrote:

Does that not have the advantage of preventing the global
directory being directly fiddled with elsewhere?


That depends on what you mean by "prevent". There is nothing
to stop any code from directly accessing the .seen attribute
of the class.

It might make it less likely that someone will inadvertently
write code that does this.

If there will only ever be one instance of the dict, another
approach would be to put it into a dedicated module together
with the functions that access it. That will give you the
same amount of protection, while ensuring that there really
is only one instance, and making this fact clear to anyone
reading the code.

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


Re: encapsulating a global variable

2020-02-25 Thread Greg Ewing

On 26/02/20 4:06 am, BlindAnagram wrote:

My interest in this stems from wanting to keep the dictionary only
available to the function that uses it and also a worry about being
called from threaded code.


Doing this won't make any difference to the way threaded code behaves.
Threading problems need to be addressed by appropriate use of locks,
etc.

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


Difficulty in generating .exe from .py file

2020-02-25 Thread Aakash Jana
I have made a simple web scraper that scrapes Wikipedia and prints some
info on to the command line using requests and BeautifulSoup. Whenever I
execute pyinstaller it gives an error "expected integer got type bytes"
although the code runs perfectly. I am using python 3.8
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Tkinter layout designer

2020-02-25 Thread mm0fmf
I don't claim to be an expert on Windows Forms, I inherited the support 
role and have added the odd widget over the years. The apps work but 
scream that their UI has been incrementally arrived at by someone who 
was just tinkering. :-)


Thanks for the suggestions, I'll give Page a try.

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


Re: encapsulating a global variable (BlindAnagram)

2020-02-25 Thread BlindAnagram
On 25/02/2020 17:16, Christman, Roger Graydon wrote:
>> On Tue, 25 Feb 2020 3:06 PM BlindAnagram  wrote:
> 
>> My interest in this stems from wanting to keep the dictionary only
>> available to the function that uses it and also a worry about being
>> called from threaded code.
> 
> It seems like the simplest solution for this is to make
> a completely new file (module) containing nothing but
> the dictionary and this one function that uses it.
> Then you can import the function from the module
> wherever it is called without importing the dictionary.
> 
> The thing I find curious is that apparently no other
> function is allowed to create or populate the dictionary
> in the first place.   Is it practical to have the entire
> dictionary statically defined?

The dictionary is a static variable of the function. It is updated by
the function and must maintain values across function calls.

Reading some more, it seems that I can create static function variables
using attributes.

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


Re: Tkinter layout designer

2020-02-25 Thread jfong
mm0fmf於 2020年2月25日星期二 UTC+8上午5時29分33秒寫道:
> Can anyone recommend a graphic layout designer for Tkinter programs. I 
> have a number of older C# Windows Forms apps that need porting so they 
> can run on Linux and Windows and this is the chance to re-write them in 
> Python. However, after using the forms designer in Visual Studio, 
> manually coding up the widget positions etc. is a real pain in the 
> backside.
> 
> So please, recommendations for a designer that is usable and functional 
> please to save me working through everything a Google search throws up.
> 
> Thanks,
> Andy

Download PAGE here:
https://sourceforge.net/projects/page/

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


Re: encapsulating a global variable

2020-02-25 Thread Dieter Maurer
BlindAnagram wrote at 2020-2-25 12:38 +:
>I would appreciate advice on whether it is possible to avoid the use of
>a global variable used in a function by encapsulating it in a class
>without maaking any changes to the call interface (which I cannot change).
>
>I have:
>
>
>seen = dict()
>
>def get_it(piece):
>   ...
>   return seen[piece]
>
>
>and I am wondering if it is possible to use a class something like
>
>
>class get_it(object):
>
>  seen = dict()
>
>  def __call__(piece):
>return seen[piece]
>
>
>to avoid the global variable.

Apparently, you are ready to change the function.
In this case, you might be interested in `rebindFunction` from
the package `dm.reuse`.
Its primary purpose is to reuse a foreign function in one's own
code with minor modifications. One of the supported minor
modifications is to change globals seen by the function.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: encapsulating a global variable (BlindAnagram)

2020-02-25 Thread Christman, Roger Graydon
> On Tue, 25 Feb 2020 3:06 PM BlindAnagram  wrote:

> My interest in this stems from wanting to keep the dictionary only
> available to the function that uses it and also a worry about being
> called from threaded code.

It seems like the simplest solution for this is to make
a completely new file (module) containing nothing but
the dictionary and this one function that uses it.
Then you can import the function from the module
wherever it is called without importing the dictionary.

The thing I find curious is that apparently no other
function is allowed to create or populate the dictionary
in the first place.   Is it practical to have the entire
dictionary statically defined?

Roger Christman
Pennsylvania State University
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: encapsulating a global variable

2020-02-25 Thread BlindAnagram
On 25/02/2020 16:36, Rhodri James wrote:
> On 25/02/2020 15:20, BlindAnagram wrote:
>>> class GetIt:
>>>    seen = dict()
>>>
>>>    def __call__(self, piece):
>>>  return GetIt.seen[piece]
>>>
>>> get_it = GetIt()
>>>
>>> but then you have a global class instance hanging around, which is not
>>> actually any better than a global dictionary.
>> This doesn't work for me since get_it(piece) returns the error:
>>
>> builtins.TypeError: get_it() takes no arguments
> 
> It works for me (pace sticking something in GetIt.seen to avoid getting
> a KeyError).  You aren't muddling up the class name and instance name
> are you?

Apologies, I misunderstoof your proposal - it woks fine now I have
understood it

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


Re: encapsulating a global variable

2020-02-25 Thread Rhodri James

On 25/02/2020 15:20, BlindAnagram wrote:

class GetIt:
   seen = dict()

   def __call__(self, piece):
     return GetIt.seen[piece]

get_it = GetIt()

but then you have a global class instance hanging around, which is not
actually any better than a global dictionary.

This doesn't work for me since get_it(piece) returns the error:

builtins.TypeError: get_it() takes no arguments


It works for me (pace sticking something in GetIt.seen to avoid getting 
a KeyError).  You aren't muddling up the class name and instance name 
are you?


--
Rhodri James *-* Kynesim Ltd
--
https://mail.python.org/mailman/listinfo/python-list


Re: encapsulating a global variable

2020-02-25 Thread BlindAnagram
On 25/02/2020 14:14, Rhodri James wrote:
> On 25/02/2020 12:38, BlindAnagram wrote:
>> I would appreciate advice on whether it is possible to avoid the use of
>> a global variable used in a function by encapsulating it in a class
>> without maaking any changes to the call interface (which I cannot
>> change).
>>
>> I have:
>>
>> 
>> seen = dict()
>>
>> def get_it(piece):
>>     ...
>>     return seen[piece]
>> 
>>
>> and I am wondering if it is possible to use a class something like
>>
>> 
>> class get_it(object):
>>
>>    seen = dict()
>>
>>    def __call__(piece):
>>  return seen[piece]
>> 
>>
>> to avoid the global variable.
> 
> I wouldn't.  Calling the class name creates an instance of the class, so
> won't actually do what you want.  You could rewrite the class and create
> an instance to call instead:
> 
> class GetIt:
>   seen = dict()
> 
>   def __call__(self, piece):
>     return GetIt.seen[piece]
> 
> get_it = GetIt()
> 
> but then you have a global class instance hanging around, which is not
> actually any better than a global dictionary.

This doesn't work for me since get_it(piece) returns the error:

builtins.TypeError: get_it() takes no arguments

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


Re: encapsulating a global variable

2020-02-25 Thread BlindAnagram
On 25/02/2020 14:13, Chris Angelico wrote:
> On Wed, Feb 26, 2020 at 12:11 AM BlindAnagram  
> wrote:
>>
>> On 25/02/2020 12:56, Chris Angelico wrote:
>>> On Tue, Feb 25, 2020 at 11:41 PM BlindAnagram  
>>> wrote:

 I would appreciate advice on whether it is possible to avoid the use of
 a global variable used in a function by encapsulating it in a class
 without maaking any changes to the call interface (which I cannot change).
>>>
>>> Why bother? If you aren't changing where the function's called, then
>>> its state is effectively global anyway, so what's the point of the
>>> class?
>>
>> It's a good question!
>>
>> The main reason is that I would like to know if it is possible as I then
>> have a choice.  The choice might not be there.
>>
> 
> Well, yes, you can, but you would need a global instance of that class
> (or use the global class object itself). So you'd still have a global.
> 
> But if this is a transitional thing, then the answer is a resounding
> YES. You can start by packaging up all your state with a class, and
> have a single global instance of that class; but then you can rework
> your function to take an optional parameter which is a non-global
> instance of the class. Then all your state is kept in there, and you
> actually truly *do* avoid global state. As a good example of how this
> works, check out Python's random module - you can call
> random.randrange() to get a random number in a particular range, or
> you can instantiate your own random.Random() object and call its
> randrange() method. The first form uses global state; the second form
> doesn't.

Thanks, I think I understand most of this but the eample will help a lot.

My interest in this stems from wanting to keep the dictionary only
available to the function that uses it and also a worry about being
called from threaded code.

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


Re: encapsulating a global variable

2020-02-25 Thread BlindAnagram
On 25/02/2020 14:14, Rhodri James wrote:
> On 25/02/2020 12:38, BlindAnagram wrote:
>> I would appreciate advice on whether it is possible to avoid the use of
>> a global variable used in a function by encapsulating it in a class
>> without maaking any changes to the call interface (which I cannot
>> change).
>>
>> I have:
>>
>> 
>> seen = dict()
>>
>> def get_it(piece):
>>     ...
>>     return seen[piece]
>> 
>>
>> and I am wondering if it is possible to use a class something like
>>
>> 
>> class get_it(object):
>>
>>    seen = dict()
>>
>>    def __call__(piece):
>>  return seen[piece]
>> 
>>
>> to avoid the global variable.
> 
> I wouldn't.  Calling the class name creates an instance of the class, so
> won't actually do what you want.  You could rewrite the class and create
> an instance to call instead:
> 
> class GetIt:
>   seen = dict()
> 
>   def __call__(self, piece):
>     return GetIt.seen[piece]
> 
> get_it = GetIt()
> 
> but then you have a global class instance hanging around, which is not
> actually any better than a global dictionary.

Thanks. Does that not have the advantage of preventing the global
directory being directly fiddled with elsewhere?  Which is one of my
reasons for thinking about this.

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


Re: time.localtime add a parameter for timezone

2020-02-25 Thread Peter J. Holzer
On 2020-02-24 17:43:58 +, Rhodri James wrote:
> On 24/02/2020 17:21, Dieter Maurer wrote:
> > qbit wrote at 2020-2-24 05:18 -0800:
> > > How about adding a time zone parameter to time.localtime?
> > > 
> > > A  offset just like the form: ± hh[:mm[:ss]].
> > 
> > Why should this be necessary? `localtime` returns the time
> > in the "local timezone" -- and the "local timezone" usually
> > does not change between different calls to `localtime`.
> 
> It can if your calls to localtime() happen either side of a daylight saving
> time switch.
> 
> That said, I agree that the timezone doesn't really belong in the output of
> localtime().

I think it does (that POSIX omits it (and only includes the rather
useless tm_isdst) is a historical oversight which was unfortunately
never corrected).

However, it doesn't have to be added, since it is already there:

https://docs.python.org/3/library/time.html#time.struct_time

1084% python3
Python 3.6.9 (default, Nov  7 2019, 10:44:02)
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import time
>>> t = time.localtime()
>>> t.tm_gmtoff
3600
>>> t.tm_zone
'CET'

However, this not a parameter but a field of the return value.

I'm not sure what a parameter would do: Return the broken-down time for
the specified timezone? If so, an offset is not sufficient: It needs to
be a timezone name (something like "Europe/Vienna").

Proper general handling of timezones should probably be in datetime.

> There are a very few occasions when you want it, but more often you
> should be working in UTC not local time.

If you are working in UTC, you don't need localtime().

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: encapsulating a global variable

2020-02-25 Thread Rhodri James

On 25/02/2020 12:38, BlindAnagram wrote:

I would appreciate advice on whether it is possible to avoid the use of
a global variable used in a function by encapsulating it in a class
without maaking any changes to the call interface (which I cannot change).

I have:


seen = dict()

def get_it(piece):
...
return seen[piece]


and I am wondering if it is possible to use a class something like


class get_it(object):

   seen = dict()

   def __call__(piece):
 return seen[piece]


to avoid the global variable.


I wouldn't.  Calling the class name creates an instance of the class, so 
won't actually do what you want.  You could rewrite the class and create 
an instance to call instead:


class GetIt:
  seen = dict()

  def __call__(self, piece):
return GetIt.seen[piece]

get_it = GetIt()

but then you have a global class instance hanging around, which is not 
actually any better than a global dictionary.



--
Rhodri James *-* Kynesim Ltd
--
https://mail.python.org/mailman/listinfo/python-list


Re: encapsulating a global variable

2020-02-25 Thread Chris Angelico
On Wed, Feb 26, 2020 at 12:11 AM BlindAnagram  wrote:
>
> On 25/02/2020 12:56, Chris Angelico wrote:
> > On Tue, Feb 25, 2020 at 11:41 PM BlindAnagram  
> > wrote:
> >>
> >> I would appreciate advice on whether it is possible to avoid the use of
> >> a global variable used in a function by encapsulating it in a class
> >> without maaking any changes to the call interface (which I cannot change).
> >
> > Why bother? If you aren't changing where the function's called, then
> > its state is effectively global anyway, so what's the point of the
> > class?
>
> It's a good question!
>
> The main reason is that I would like to know if it is possible as I then
> have a choice.  The choice might not be there.
>

Well, yes, you can, but you would need a global instance of that class
(or use the global class object itself). So you'd still have a global.

But if this is a transitional thing, then the answer is a resounding
YES. You can start by packaging up all your state with a class, and
have a single global instance of that class; but then you can rework
your function to take an optional parameter which is a non-global
instance of the class. Then all your state is kept in there, and you
actually truly *do* avoid global state. As a good example of how this
works, check out Python's random module - you can call
random.randrange() to get a random number in a particular range, or
you can instantiate your own random.Random() object and call its
randrange() method. The first form uses global state; the second form
doesn't.

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


Re: encapsulating a global variable

2020-02-25 Thread BlindAnagram
On 25/02/2020 12:50, Musbur wrote:
> 
> Am 25.02.2020 13:38 schrieb BlindAnagram:
>> and I am wondering if it is possible to use a class something like
>>
>> class get_it(object):
>>
>>   seen = dict()
>>
>>   def __call__(piece):
>>     return seen[piece]
> 
> What happened when you tried it?

The nearest I got was:

-
class orientate(object):

  seen = defaultdict()
  @classmethod
  def do(self, piece, two_sided=False):


which works but requires a change to the function call interface from
orientate(piece) to  orientate.do(piece).

I was hoping that repalcing the above with:

-
class orientate(object):

  seen = defaultdict()
  @classmethod
  def __call__(self, piece, two_sided=False):


would eliminate the need for the 'do' but this gives the error:

builtins.TypeError: orientate() takes no arguments

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


Re: encapsulating a global variable

2020-02-25 Thread BlindAnagram
On 25/02/2020 12:56, Chris Angelico wrote:
> On Tue, Feb 25, 2020 at 11:41 PM BlindAnagram  
> wrote:
>>
>> I would appreciate advice on whether it is possible to avoid the use of
>> a global variable used in a function by encapsulating it in a class
>> without maaking any changes to the call interface (which I cannot change).
> 
> Why bother? If you aren't changing where the function's called, then
> its state is effectively global anyway, so what's the point of the
> class?

It's a good question!

The main reason is that I would like to know if it is possible as I then
have a choice.  The choice might not be there.

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


Re: encapsulating a global variable

2020-02-25 Thread Musbur



Am 25.02.2020 13:38 schrieb BlindAnagram:

and I am wondering if it is possible to use a class something like

class get_it(object):

  seen = dict()

  def __call__(piece):
return seen[piece]


What happened when you tried it?

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


Re: encapsulating a global variable

2020-02-25 Thread Chris Angelico
On Tue, Feb 25, 2020 at 11:41 PM BlindAnagram  wrote:
>
> I would appreciate advice on whether it is possible to avoid the use of
> a global variable used in a function by encapsulating it in a class
> without maaking any changes to the call interface (which I cannot change).

Why bother? If you aren't changing where the function's called, then
its state is effectively global anyway, so what's the point of the
class?

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


encapsulating a global variable

2020-02-25 Thread BlindAnagram
I would appreciate advice on whether it is possible to avoid the use of
a global variable used in a function by encapsulating it in a class
without maaking any changes to the call interface (which I cannot change).

I have:


seen = dict()

def get_it(piece):
   ...
   return seen[piece]


and I am wondering if it is possible to use a class something like


class get_it(object):

  seen = dict()

  def __call__(piece):
return seen[piece]


to avoid the global variable.

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


Re: Tkinter layout designer

2020-02-25 Thread Sibylle Koczian

Am 25.02.2020 um 07:32 schrieb Christian Gollwitzer:

Am 24.02.20 um 22:29 schrieb mm0fmf:

Can anyone recommend a graphic layout designer for Tkinter programs.


I have a number of older C# Windows Forms apps that need porting so 
they can run on Linux and Windows and this is the chance to re-write 
them in Python. However, after using the forms designer in Visual 
Studio, manually coding up the widget positions etc. is a real pain in 
the backside


If you want a designer, use QT, which brings the Qt Designer. Be careful 
though - if you misuse them, you can end up with inflexible GUIs, where 
changes in the font or display resolution can mess up your interface. 
Always test that your windows act sensibly upon resizing.


Coming from Windows Forms this is especially important. Windows Forms 
doesn't have a sensible geometry manager. Tkinter and PyQt / PySide both 
have them, and it's quite a change at first. But in the long run it's 
much more comfortable to put your controls into layouts (or pack / grid 
them - tkinter) instead of placing each and every thing yourself.


Greetings
Sibylle


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