Re: Python3 - How do I import a class from another file

2019-12-10 Thread R.Wieser
DL,

> I went through this cycle of thinking, first using if __name__... to 
> 'hide' testing, then adding test functions within the module, and now keep 
> test code quite separate from 'the real thing'.

:-) The normal newbie progression, off of which I'm in phase #1.   Having a 
working program (riddeled with debugging output) is still (way) more 
important than having the best code I'm afraid.   But reading about how 
others handle it definitily makes it easier for me to progress.

> Expanding on 'names' and del(): the first point is that there is seldom 
> much to be gained by using del(), ie becoming your own 'garbage 
> collector'.

In my case deleting the instance was needed to release its hold on something 
that was taken when the instance was initialised (in my case a GPIO pin on a 
Raspberry Pi).   I did not even think of garbage collection.

> Python enables you to play fast-and-loose, eg

I know (similar to VBScript which uses Variants for everything).   Its all 
about wnat I /intend/ to have inside it, and the type prefix character 
keeping myself aware of where (not) to use the variable.  Also, silent type 
conversions can work against you.I normally prefix an instanciated class 
(having methods) with an "o".

Than again, I normally camel-case my variable and function names (to make 
them stand out from the build-in commands), as I normally do not use editors 
with syntax highlighting.

> A Python-list will handle the former (wow, that's a bit of 'rocket 
> science'!?) whereas a Python-set will only contain unique values. So, 
> rather than using a somewhat-bland varNM such as "letters", I would choose 
> to be more explicit:

:-) Always start with a descriptive* name for the variable, regardless of if 
it is a compounded one or not.   As said, the type prefix is just a 
reminder.

*though not /too/ descriptive.   Languages which can easily have 
40-character names for variables, functions and such are simply the pits, 
especially when they start to differ only for a single/few character(s) 
somewhere in the middle. :-(

> rudy = Man( etc ) #rudy probably does have class, in this instance

You almost owed me a new keyboard there. :-p

Regards,
Rudy Wieser


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


[RELEASE] Python 3.8.1rc1 is now available for testing

2019-12-10 Thread Łukasz Langa
Python 3.8.1rc1 is the release candidate of the first maintenance release of 
Python 3.8.

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.1rc1 
here:

https://www.python.org/downloads/release/python-381rc1/ 

Assuming no critical problems are found prior to 2019-12-16, the scheduled 
release date for 3.8.1 as well as Ned Deily's birthday, no code changes are 
planned between this release candidate and the final release.

That being said, please keep in mind that this is a pre-release of 3.8.1 and as 
such its main purpose is testing.

See the “What’s New in Python 3.8 
” document for more information 
about features included in the 3.8 series. Detailed information about all 
changes made in 3.8.0 can be found in its change log.

Maintenance releases for the 3.8 series will continue at regular bi-monthly 
intervals, with 3.8.2 planned for February 2020.

We hope you enjoy Python 3.8!

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/ 


signature.asc
Description: Message signed with OpenPGP
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python3 - How do I import a class from another file

2019-12-10 Thread Greg Ewing

On 10/12/19 9:45 pm, R.Wieser wrote:


In my case deleting the instance was needed to release its hold on something
that was taken when the instance was initialised (in my case a GPIO pin on a
Raspberry Pi).   I did not even think of garbage collection.


In that case, it was only working by accident. You were unwittingly
relying on the garbage collector to immediately clean up the object
as soon as the last reference to it disappeared. That happens to be
true currently in CPython (which uses reference counting), but it's
not guaranteed by the language.

If your object has a method for explicitly making it release its
resources, it would be better to use that rather than rely on
the garbage collector.


Than again, I normally camel-case my variable and function names (to make
them stand out from the build-in commands), as I normally do not use editors
with syntax highlighting.


Python differs from VBScript and other VB-family languages in that
names are case-sensitive. So it's common to use case to distinguish
between things such as a class and an instance.

--
Greg

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


The file method read does not "see" CR

2019-12-10 Thread Stephen Tucker
I am running Python 2.7.10 on a Windows 10 machine. I have written a Python
program that counts occurrences of bytes in a text file and have run it on
a small test file. This file has CR-LF sequences at the ends of its lines.
The Python program counted the LF bytes, but didn't count any CR bytes.
Given that the documentation for the read method claims that exactly size
bytes are read by each call to the method (in this case, size is 1) does
this behaviour constitute a bug?

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


Re: More efficient/elegant branching

2019-12-10 Thread Python

Musbur wrote:

Hello,

I have a function with a long if/elif chain that sets a couple of 
variables according to a bunch of test expressions, similar to function 
branch1() below. I never liked that approach much because it is clumsy 
and repetetive, and pylint thinks so as well. I've come up with two 
alternatives which I believe are less efficient due to the reasons given 
in the respective docstrings. Does anybody have a better idea?


I tried a lot of times to write down a useful Switch module
without convincing myself. Recently here is what I ended up
with, what do you think ?

https://gitlab.com/snippets/1921123


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


Re: The file method read does not "see" CR

2019-12-10 Thread Chris Angelico
On Tue, Dec 10, 2019 at 9:17 PM Stephen Tucker  wrote:
>
> I am running Python 2.7.10 on a Windows 10 machine. I have written a Python
> program that counts occurrences of bytes in a text file and have run it on
> a small test file. This file has CR-LF sequences at the ends of its lines.
> The Python program counted the LF bytes, but didn't count any CR bytes.
> Given that the documentation for the read method claims that exactly size
> bytes are read by each call to the method (in this case, size is 1) does
> this behaviour constitute a bug?
>

Are you trying to treat the file as text, or bytes? Are you looking
for occurrences of bytes, or characters? Make a decision on that, then
code accordingly. If you want to look for bytes, then open the file in
binary mode and read it as bytes. If you want to look for characters,
then you probably shouldn't care about which sort of line ending it
is, but if you really do, then disable newline processing and examine
the end of each logical line.

The read call will return one character, if the file is in text mode.

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


Re: Python3 - How do I import a class from another file

2019-12-10 Thread R.Wieser
Greg,

> In that case, it was only working by accident.

I don't think so.

Or you must be thinking that the __del__ method of an instance is only 
called by the garbage collector - which would be rather daft (just think of 
a file thats created when initialising an instance, but not closes until the 
garbage collector comes around to it.   Much luck with reopening the file). 
Removing an unused object from memory is a bit different than 
closing/"destroying" an instance.

> Python differs from VBScript and other VB-family languages in that
> names are case-sensitive.

I was aware of that.

> So it's common to use case to distinguish
> between things such as a class and an instance.

For some reason (the lacluster use of interpunction on tha intarwebz, or 
perhaps The Irritating Habit To Capitalise Every Word) I tend to largely 
ignore capitalisation.   Time will tell if I can cope with names that only 
differ by their capitalisation.   Most likely not.  Combine that with 
Pythons create-on-use behaviour and you have a recipe for disaster. :-|

Regards,
Rudy Wieser


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


Re: Python3 - How do I import a class from another file

2019-12-10 Thread Chris Angelico
On Tue, Dec 10, 2019 at 9:51 PM R.Wieser  wrote:
>
> Greg,
>
> > In that case, it was only working by accident.
>
> I don't think so.
>
> Or you must be thinking that the __del__ method of an instance is only
> called by the garbage collector - which would be rather daft (just think of
> a file thats created when initialising an instance, but not closes until the
> garbage collector comes around to it.   Much luck with reopening the file).
> Removing an unused object from memory is a bit different than
> closing/"destroying" an instance.

Well, that's exactly what happens. Daft as it might seem, the __del__
method IS only called when an object is disposed of by the garbage
collector. CPython happens to use a refcounting garbage collector that
will usually dispose of things fairly promptly, but in the case of
cyclic references, that won't happen till the cycle detection GC goes
through.

Check out the 'with' statement. Also, when you scorn something without
knowing your facts, you tend to make yourself look like a fool :)

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


Re: More efficient/elegant branching

2019-12-10 Thread Musbur
I like it! I think it's a cute exercise but it doesn't really solve any 
problem. The if/elif chain can accomplish the same thing (and much more) 
in the same line count for the price of being clunkier. **D


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


Re: Python3 - How do I import a class from another file

2019-12-10 Thread R.Wieser
Chris,

> Well, that's exactly what happens.

So, only the reference count gets lowered.  Yep, thats daft.

... unless you explain why it can only be done that way.

> Also, when you scorn something without knowing your facts,
> you tend to make yourself look like a fool :)

I tend to go with logic.   No logic => it most likely doesn't work that way.

Choosing to go with a delayed action like you say will, as I already 
explained, create problems later on (race conditions everywhere).  And as I 
do not think the designers of the language where that stupid I must 
therefore reject your claim to what you think happens.

But, as you mentioned, I do not know (all) the facts.  Please do present 
them.   Maybe there is a logic in there I do not yet see.

> Check out the 'with' statement.

I'm sorry, but nope.

Rule one: When debugging do *not* throw more stuff at a problem than what is 
neccessary to make it show its ugly head.
Rule two: When in doubt, see rule One. :-)

Regards,
Rudy Wieser


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


Re: Python3 - How do I import a class from another file

2019-12-10 Thread Chris Angelico
On Tue, Dec 10, 2019 at 11:46 PM R.Wieser  wrote:
>
> Chris,
>
> > Well, that's exactly what happens.
>
> So, only the reference count gets lowered.  Yep, thats daft.
>
> ... unless you explain why it can only be done that way.

Okay. What should happen when you do this?

x = 5
del x

Should the integer 5 be deleted?

> > Also, when you scorn something without knowing your facts,
> > you tend to make yourself look like a fool :)
>
> I tend to go with logic.   No logic => it most likely doesn't work that way.
>
> Choosing to go with a delayed action like you say will, as I already
> explained, create problems later on (race conditions everywhere).  And as I
> do not think the designers of the language where that stupid I must
> therefore reject your claim to what you think happens.
>
> But, as you mentioned, I do not know (all) the facts.  Please do present
> them.   Maybe there is a logic in there I do not yet see.
>
> > Check out the 'with' statement.
>
> I'm sorry, but nope.
>
> Rule one: When debugging do *not* throw more stuff at a problem than what is
> neccessary to make it show its ugly head.
> Rule two: When in doubt, see rule One. :-)

So the language designers couldn't possibly have been so stupid as to
do things this way, but you're going to ignore what they did? Cool.
Bye!

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


I downloaded the python application but my system is having issues with it. please, can you provide help?

2019-12-10 Thread Princess Oluchi



Sent from Mail for Windows 10

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


Re: More efficient/elegant branching

2019-12-10 Thread Python

Musbur wrote:
I like it! I think it's a cute exercise but it doesn't really solve any 
problem. The if/elif chain can accomplish the same thing (and much more) 
in the same line count for the price of being clunkier. **D


Yep! This is why I wrote half a dozen of switch implementation but never
actually used any of them in a real project :-)

If we had macros it may be another story, but we don't, and we won't (or
will we ?)



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


Installation Error (0xc000007b)

2019-12-10 Thread Abhi Patel
i'm getting the error message while installing python in my dell laptop.
ERROR: the application was unable to start (0xc07b). Close the
application
Please help
-- 
https://mail.python.org/mailman/listinfo/python-list


Site Packages Folder Red on Clean Install

2019-12-10 Thread Timothy Coca
Hello,

I have a new dell XPS, I freshly installed the latest version of
Pythong (3.8.0) and pycharm. Pycharm shows the site packages folder as red,
and I can not import and modules from inside of it. Pip install works to
install some programs like numpy, scipy, but would not install matplotlib
successfully.

Even though Pip installed numpy successfully to the Sitpackages folder, I
can not import or use it. Any advice?

Note: Upon purchase I did replace the hard drive and ram, and reinstall
windows. It all runs fine, but if you suspect that can be related please
let me know.

Any advice on how to resolve this would be appreciated. I've seen forum
posts where others had the same issue but no ressolutions.

I am trying installing a previous version of Python to see if it works.

Thanks,

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


Re: More efficient/elegant branching

2019-12-10 Thread Daniel Haude

Hello Neil,

thanks for the detailed answer.


Question: are there other people/factors who/which should be regarded
as more important than the linter's opinion?


Yes. Mine.

I was just puzzled at the linter's output (took me a while to figure out 
what it actually meant), and that got me started on the track if there 
was maybe a more Pythonic way of dealing with that decision chain.



The usual dictionary-controlled construct I've seen (and used)
involves using functions as the dict's values:
[...]


Yeah, I do that a lot, too, but for that you need a meaningful "key" 
object. In the case at hand, I'm really using individually formulated 
conditions.



Is it ironic that the language does not have a form of case/switch
statement (despite many pleas and attempts to add it),


Wouldn't do me any good here because case/switch also compares a fiked 
key against a bunch of candidates, like a dict. Also, in terms of line 
count the if/elif chain isn't worse than a switch statement.



yet the linter objects to an if-elif-else nesting???


Like I said, that's what got me started on this. And it's not even 
nested, it's purely linear.



One reason why this code looks a bit strange (and possibly why PyLint
reacts?) is because it is trivial. When we look at the overall
picture, the question becomes: what will the 'mainline' do with
"result" (the returned value)? Immediately one suspects it will be fed
into another decision, eg:


No, the "result" is a text message that actually means something and is 
eventually output for human consumption.


The whole thing is rather academic. Also my efficiency argument doesn't 
hold water because this routine is executed just a few times per hour. I 
like the "condition table" approach for its lower line count but I'll 
stick with if/elif because it's more conventional and therefore easier 
to understand for the casual reader.


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


Re: Python3 - How do I import a class from another file

2019-12-10 Thread Python

R.Wieser wrote:

Chris,

...


But, as you mentioned, I do not know (all) the facts.  Please do present
them.   Maybe there is a logic in there I do not yet see.


We may, but then you wrote:


Check out the 'with' statement.


I'm sorry, but nope.

Rule one: When debugging do *not* throw more stuff at a problem than what is
neccessary to make it show its ugly head.
Rule two: When in doubt, see rule One. :-)


which contradicts your previous statement.

"with" is "more stuff" it is the right way to deal with disposable
ressource in the first place. In the documentation it is used from
the very first example of, say, open().


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


Re: More efficient/elegant branching

2019-12-10 Thread Chris Angelico
On Wed, Dec 11, 2019 at 12:26 AM Daniel Haude  wrote:
> The whole thing is rather academic. Also my efficiency argument doesn't
> hold water because this routine is executed just a few times per hour. I
> like the "condition table" approach for its lower line count but I'll
> stick with if/elif because it's more conventional and therefore easier
> to understand for the casual reader.

Agreed. It is a fault with the linter, and nothing more.

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


Re: Randomizing Strings In A Microservices World

2019-12-10 Thread Rhodri James

On 10/12/2019 03:35, Tim Daneliuk wrote:

On 12/9/19 8:50 PM, Paul Rubin wrote:

Tim Daneliuk  writes:

- Imagine an environment in which there may be multiple instances of a given
   microservice written in Python.


Decide the maximum number of microservice instances, say 1000.  Chop up
the 10 digit range into 1000 pieces, so 0..99, 100-199, etc.
Give one range to each microservice instance.  Then have the
microservices give out the numbers sequentially, but treating them as 10
digit numbers and encrypting each one under a 10 digit pseudorandom
permutation shared by all the instances.  Look up "format preserving
encryption" for how to do this.

Obvious variants of the above are obvious, and maybe you need some way
to hand around chunks of range if some instance gives out more than a
million numbers.




The problem here is that the services are ephemeral and the number of said
services is not fixed.


Hm.  Normally I'd mash together the MAC address of the interface and the 
process ID of the service (or whatever individual identifier 
microservices have -- indeed, whatever microservices *are* :-), but ten 
digits is a bit few for that.  So you want some variant of Paul's approach.


* I assume there are a number of machines providing these services. 
Give them unique numbers -- I'm guessing three digits should be enough 
for that, but you know your own setup better.  How you assign those 
numbers is up to you; a config file in /etc, a Windows registry key, or 
some broadcast protocol that the machines use to dynamically configure 
themselves are all options that spring to mind.


* On each machine, something must spin up services when they are needed. 
 That something will be in a position to assign a unique number (within 
an individual machine) to each service.  So do that, using whatever 
digits you have left after the unique machine number.


* Mash these two numbers into a single ten digit identifier.

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


Re: Randomizing Strings In A Microservices World

2019-12-10 Thread Peter Otten
Tim Daneliuk wrote:

> I ran across a kind of fun problem today that I wanted to run past you
> Gentle Geniuses (tm):
> 
> - Imagine an environment in which there may be multiple instances of a
> given
>   microservice written in Python.
> 
> - Each of these services needs to produce a string of ten digits
> guaranteed to be unique
>   on a per service instance basis AND to not collide for - oh, let's say -
>   forever :)s
> 
> Can anyone suggest a randomization method that might achieve this
> efficiently?
> 
> My first thought was to something like nanonseconds since the epoch plus
> something
> unique about the service instance - like it's IP?  (This is in a K8s
> cluster) - to see the randomization and essentially eliminate the string
> being repeated.
> 
> Ideas welcome ..
> 
> P.S. I do not want to resort to a number generation service that each
> instance asks
>  for a new number.  The network and service call overhead militates
>  against this in my application.

Hand out a range of numbers when the service is started. Once that range is 
used up the service can terminate itself.

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


Re: Python3 - How do I import a class from another file

2019-12-10 Thread Antoon Pardon
On 10/12/19 13:44, R.Wieser wrote:
> Chris,
>
>> Well, that's exactly what happens.
> So, only the reference count gets lowered.  Yep, thats daft.
>
> ... unless you explain why it can only be done that way.
>
>> Also, when you scorn something without knowing your facts,
>> you tend to make yourself look like a fool :)
> I tend to go with logic.   No logic => it most likely doesn't work that way.
>
> Choosing to go with a delayed action like you say will, as I already 
> explained, create problems later on (race conditions everywhere).  And as I 
> do not think the designers of the language where that stupid I must 
> therefore reject your claim to what you think happens.

Well yes that is why it is stupid to rely on the garbage collector to do
those things for you. That is why Greg Ewing already stated:

> If your object has a method for explicitly making it release its
> resources, it would be better to use that rather than rely on
> the garbage collector. 

> But, as you mentioned, I do not know (all) the facts.  Please do present 
> them.   Maybe there is a logic in there I do not yet see.

What would you want to happen in the following case:

   foo1 = Bar()
   foo2 = foo1
   del foo1

Should the object be cleaned up now or not?


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


Re: More efficient/elegant branching

2019-12-10 Thread Musbur

Hello Neil,

thanks for the detailed answer.


Question: are there other people/factors who/which should be regarded
as more important than the linter's opinion?


Yes. Mine.

I was just puzzled at the linter's output (took me a while to figure out 
what it actually meant), and that got me started on the track if there 
was maybe a more Pythonic way of dealing with that decision chain.



The usual dictionary-controlled construct I've seen (and used)
involves using functions as the dict's values:
[...]


Yeah, I do that a lot, too, but for that you need a meaningful "key" 
object. In the case at hand, I'm really using individually formulated 
conditions.



Is it ironic that the language does not have a form of case/switch
statement (despite many pleas and attempts to add it),


Wouldn't do me any good here because case/switch also compares a fiked 
key against a bunch of candidates, like a dict. Also, in terms of line 
count the if/elif chain isn't worse than a switch statement.



yet the linter objects to an if-elif-else nesting???


Like I said, that's what got me started on this. And it's not even 
nested, it's purely linear.



One reason why this code looks a bit strange (and possibly why PyLint
reacts?) is because it is trivial. When we look at the overall
picture, the question becomes: what will the 'mainline' do with
"result" (the returned value)? Immediately one suspects it will be fed
into another decision, eg:


No, the "result" is a text message that actually means something and is 
eventually output for human consumption.


The whole thing is rather academic. Also my efficiency argument doesn't 
hold water because this routine is executed just a few times per hour. I 
like the "condition table" approach for its lower line count but I'll 
stick with if/elif because it's more conventional and therefore easier 
to understand for the casual reader.

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


Re: python 2 to 3 converter

2019-12-10 Thread songbird
Chris Angelico wrote:
> On Tue, Dec 10, 2019 at 12:15 PM songbird  wrote:
>>
>> Chris Angelico wrote:
>> ...
>> >
>> > Here's an example piece of code.
>> >
>> > sock = socket.socket(...)
>> > name = input("Enter your username: ")
>> > code = input("Enter the base64 code: ")
>> > code = base64.b64decode(code)
>> > sock.write("""GET /foo HTTP/1.0
>> > Authentication: Demo %s/%s
>> >
>> > """ % (name, code))
>> > match = re.search(r"#[A-Za-z0-9]+#", sock.read())
>> > if match: print("Response: " + match.group(0))
>> >
>> > Your challenge: Figure out which of those strings should be a byte
>> > string and which should be text. Or alternatively, prove that this is
>> > a hard problem. There are only a finite number of types - two, to be
>> > precise - so by your argument, this should be straightforward, right?
>>
>>   this isn't a process of looking at isolated code.  this
>> is a process of looking at the code, but also the test cases
>> or working examples.  so the inputs are known and the code
>> itself gives clues about what it is expecting.
>
> Okay. The test cases are also written in Python, and they use
> unadorned string literals to provide mock values for input() and the
> socket response. Now what?

  wouldn't there be clues in how that string is used in
the program itself (either calls to converters or when
the literal is assigned to some variable or used in a
print statement)?


> What if the test cases are entirely ASCII characters?

  it all goes utf in that case and the string is not 
binary.


> What if the test cases are NOT entirely ASCII characters?

  if the program has more than one language then you may
have to see what the character set falls into.  is it hex
it it octal or binary or some language.  i'd guess there
will be clues in the code as to how that string is used
later.


>>   regular expressions can be matched in finite time as well
>> as a fixed length text of any type can be scanned as a match
>> or rejected.
>>
>>   if you examined a thousand uses of match and found the
>> pattern used above and then examined what those programs did
>> with that match what would you select as the first type, the
>> one used the most first, if that doesn't work go with the 2nd,
>> etc.
>>
>
> That's not really the point. Are your regular expressions working with
> text or bytes? Does your socket return text or bytes?

  clues in the program again.  you're not limited to looking
only at the string itself, but the context of the entire
program.  i'm sure patterns are there to be found if you
can scan enough programs they'll start showing up.  once
you've found a viable pattern then you have a way to
generate a test case to see if it works or not.


> I've deliberately chosen these examples because they are hard. And I
> didn't even get into an extremely hard problem, with the inclusion of
> text inside binary data inside of text inside of bytes. (It does
> happen.)
>
> These problems are fundamentally hard because there is insufficient
> information in the source code alone to determine the programmer's
> intent.

  that is why we would be running the program itself and
examining test case results.

  none of these programs run in isolation, information is
known what they expect as input or produce as output.


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


Re: python 2 to 3 converter

2019-12-10 Thread songbird
Chris Angelico wrote:
> On Tue, Dec 10, 2019 at 4:41 PM songbird  wrote:
>>
>> Chris Angelico wrote:
>> ...
>> > What if neither works, because there are assumptions that don't work?
>>
>>   then you get stuck doing it by hand, but you would have
>> been stuck doing it before for sure by hand so if you can
>> write something which might get some of the easy cases
>> done then at least you're saving your efforts for the
>> harder stuff.
>
> The easy cases are easy for anything, and don't need AI.

  i consider calling a statistical approach to conversion
"AI" is like calling snobol AI.  it is pattern matching
and applying tests to see what happens.  that's all, it
might even be brute forced.


>> > I get the very strong impression that you've never tried this.
>>
>>   of course not!  i don't have that kind of pipeline
>> or machine power and i'm several years away from being
>> where i'd like to be in terms of understanding the
>> language itself.  i hope to have the time over the
>> next few years to learn enough but i don't know how
>> that will go.
>>
>>   i'm glad in looking around more the past few evenings
>> that the conversion effort is making progress and
>> things are not as dire as some have made it out to be.
>> i just hope the lessons have been learned going
>> forwards.
>
> Never even done it manually, I mean. It's very difficult to try to
> design an AI to do something that you can't do yourself and don't even
> understand the problem.

  for me it would be a way of learning python 2 and python
3 better.  i have enough understanding of how compilers 
work so those parts of the project wouldn't be scary to me
at all.  the statistical aspects i'd need help with and
the generating of tests and how to run them would be new
to me.  but that tests already exist and that they are 
intended to be simple bits of code should be a goldmine 
for conversion scripts to look at IMHO.  so perhaps 
someone who's facing a huge conversion problem might find
this as a worthwhile thing to ponder.

  personally, if i were working again full time and 
facing several million lines of code and a lot of 
recalcitrant workers, well, i'd be stuck trying to do
something to get it done.

  i have gone through conversions before (a major one
at a university where we went from an inhouse system to
a vendor supplied system).  we didn't do the conversion
automatically and it didn't happen overnight, but it did
get done on schedule and i think we also came in under
budget.  i was only part of the team involved as a
general systems person as i still supported the mainframe
we were coming off of to go to the mini but for the new
system i worked with all the conversion efforts going on
in the departments along with any interface issues to 
the printers, how to run jobs in sequence, scanning 
grades, ...).  i pretty much did whatever was needed.
when the conversion was winding down was a good point
for me to retire/quit as i'd been doing nothing but
going to school and programming or working with computers
for 15yrs.  right before the internet took off...

  my own local conversion effort recently was my small
website setup where the theme author had introduced a
lot of breaking changes over several years and no 
conversion utility so i wrote one in a few days.  it 
saved me a few weeks of converting it all by hand (and 
i've posted it to github so anyone else stuck in the 
same spot at least has a workable framework to go from).
no, it's not AI or complex enough to be considered all
that interesting but it worked and saved me enough time 
that i can start looking at python 3 again.


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


Re: Python3 - How do I import a class from another file

2019-12-10 Thread Chris Angelico
On Wed, Dec 11, 2019 at 1:53 AM Antoon Pardon  wrote:
> What would you want to happen in the following case:
>
>foo1 = Bar()
>foo2 = foo1
>del foo1
>
> Should the object be cleaned up now or not?
>

TBH both are plausible, and to a Python programmer it's immediately
obvious that "foo1.close()" should close foo2 as well. Logic doesn't
preclude either of them. Imagine if the base object type had a
__destroy__() method that would dereference everything the object
referenced, clear its __dict__ (if it has one), and causes all
attribute access (including methods) to raise DestroyedObjectError. It
would be absolutely plausible to call foo1.__destroy__() and have the
object actually be destroyed.

I know this is plausible because I know of languages that work both
ways - that destroying an object actually destroys it immediately, or
that explicitly deleting a name binding leaves the object till it's
not referenced anywhere. And if there are languages working both ways,
it seems a little presumptive to heap scorn on a language designer for
either of those options.

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


Re: python 2 to 3 converter

2019-12-10 Thread Chris Angelico
On Wed, Dec 11, 2019 at 1:57 AM songbird  wrote:
>
> Chris Angelico wrote:
> > On Tue, Dec 10, 2019 at 12:15 PM songbird  wrote:
> >>
> >> Chris Angelico wrote:
> >> ...
> >> >
> >> > Here's an example piece of code.
> >> >
> >> > sock = socket.socket(...)
> >> > name = input("Enter your username: ")
> >> > code = input("Enter the base64 code: ")
> >> > code = base64.b64decode(code)
> >> > sock.write("""GET /foo HTTP/1.0
> >> > Authentication: Demo %s/%s
> >> >
> >> > """ % (name, code))
> >> > match = re.search(r"#[A-Za-z0-9]+#", sock.read())
> >> > if match: print("Response: " + match.group(0))
> >> >
> >> > Your challenge: Figure out which of those strings should be a byte
> >> > string and which should be text. Or alternatively, prove that this is
> >> > a hard problem. There are only a finite number of types - two, to be
> >> > precise - so by your argument, this should be straightforward, right?
> >>
> >>   this isn't a process of looking at isolated code.  this
> >> is a process of looking at the code, but also the test cases
> >> or working examples.  so the inputs are known and the code
> >> itself gives clues about what it is expecting.
> >
> > Okay. The test cases are also written in Python, and they use
> > unadorned string literals to provide mock values for input() and the
> > socket response. Now what?
>
>   wouldn't there be clues in how that string is used in
> the program itself (either calls to converters or when
> the literal is assigned to some variable or used in a
> print statement)?
>
>
> > What if the test cases are entirely ASCII characters?
>
>   it all goes utf in that case and the string is not
> binary.
>
>
> > What if the test cases are NOT entirely ASCII characters?
>
>   if the program has more than one language then you may
> have to see what the character set falls into.  is it hex
> it it octal or binary or some language.  i'd guess there
> will be clues in the code as to how that string is used
> later.
>
>
> >>   regular expressions can be matched in finite time as well
> >> as a fixed length text of any type can be scanned as a match
> >> or rejected.
> >>
> >>   if you examined a thousand uses of match and found the
> >> pattern used above and then examined what those programs did
> >> with that match what would you select as the first type, the
> >> one used the most first, if that doesn't work go with the 2nd,
> >> etc.
> >>
> >
> > That's not really the point. Are your regular expressions working with
> > text or bytes? Does your socket return text or bytes?
>
>   clues in the program again.  you're not limited to looking
> only at the string itself, but the context of the entire
> program.  i'm sure patterns are there to be found if you
> can scan enough programs they'll start showing up.  once
> you've found a viable pattern then you have a way to
> generate a test case to see if it works or not.
>
>
> > I've deliberately chosen these examples because they are hard. And I
> > didn't even get into an extremely hard problem, with the inclusion of
> > text inside binary data inside of text inside of bytes. (It does
> > happen.)
> >
> > These problems are fundamentally hard because there is insufficient
> > information in the source code alone to determine the programmer's
> > intent.
>
>   that is why we would be running the program itself and
> examining test case results.
>
>   none of these programs run in isolation, information is
> known what they expect as input or produce as output.
>

Go do it. Then come back and revisit your assumptions here.

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


Re: The file method read does not "see" CR

2019-12-10 Thread Stephen Tucker
Chris,

Many thanks. The first part of your answer was spot on. I have modified the
program, opening its input file in "rb" mode, and now the program is
working as I intend it to.

I am puzzled by the second part, where you say that the read call will
return one character, if the file is in text mode.

I was expecting this statement to read

   The read call will return one byte if the file is in binary mode.

Given that I *was *opening the file in "r" mode (which, I am assuming, is
"text" mode), then, if your statement is true, I have two more questions:

   1. If CR is a character and I open the file in text mode, then why does
the program not "see" the CR characters?

   2. Does the program not see CR characters under these circumstances
because they do not "count" as characters or for some other reason?

(You have probably spotted that this question 1 is virtually the same as my
original question.)

Stephen.














On Tue, Dec 10, 2019 at 10:39 AM Chris Angelico  wrote:

> On Tue, Dec 10, 2019 at 9:17 PM Stephen Tucker 
> wrote:
> >
> > I am running Python 2.7.10 on a Windows 10 machine. I have written a
> Python
> > program that counts occurrences of bytes in a text file and have run it
> on
> > a small test file. This file has CR-LF sequences at the ends of its
> lines.
> > The Python program counted the LF bytes, but didn't count any CR bytes.
> > Given that the documentation for the read method claims that exactly size
> > bytes are read by each call to the method (in this case, size is 1) does
> > this behaviour constitute a bug?
> >
>
> Are you trying to treat the file as text, or bytes? Are you looking
> for occurrences of bytes, or characters? Make a decision on that, then
> code accordingly. If you want to look for bytes, then open the file in
> binary mode and read it as bytes. If you want to look for characters,
> then you probably shouldn't care about which sort of line ending it
> is, but if you really do, then disable newline processing and examine
> the end of each logical line.
>
> The read call will return one character, if the file is in text mode.
>
> ChrisA
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python3 - How do I import a class from another file

2019-12-10 Thread Antoon Pardon
On 10/12/19 16:10, Chris Angelico wrote:
> On Wed, Dec 11, 2019 at 1:53 AM Antoon Pardon  wrote:
>> What would you want to happen in the following case:
>>
>>foo1 = Bar()
>>foo2 = foo1
>>del foo1
>>
>> Should the object be cleaned up now or not?
>>
> TBH both are plausible,

I find that strange because if you cleanup the object in that scenario
it should also
be cleaned up in the following.

def newbar():
foo = Bar
return foo

bar = newbar()

foo goes out of scope, so that is equivallent to a del foo. But I wouldn't
want the object cleaned up because of that.

-- 
Antoon Pardon.

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


Re: The file method read does not "see" CR

2019-12-10 Thread Chris Angelico
On Wed, Dec 11, 2019 at 2:18 AM Stephen Tucker  wrote:
>
> Chris,
>
> Many thanks. The first part of your answer was spot on. I have modified the 
> program, opening its input file in "rb" mode, and now the program is working 
> as I intend it to.
>

Cool!

> I am puzzled by the second part, where you say that the read call will return 
> one character, if the file is in text mode.
>
> I was expecting this statement to read
>
>The read call will return one byte if the file is in binary mode.

Both statements are true.

> Given that I was opening the file in "r" mode (which, I am assuming, is 
> "text" mode), then, if your statement is true, I have two more questions:
>
>1. If CR is a character and I open the file in text mode, then why does 
> the program not "see" the CR characters?
>

It's kinda a little messy, but because CR + LF means "line ending" on
Windows, the two-byte unit is generally considered to be a single
logical character "end of line". You can disable this by passing
another keyword argument to the open() call, but in general, text
files care about lines, rather than being bothered by exactly what
sort of line ending they're using.

>2. Does the program not see CR characters under these circumstances 
> because they do not "count" as characters or for some other reason?
>
> (You have probably spotted that this question 1 is virtually the same as my 
> original question.)
>

The Python file handler is interpreting a two-byte sequence as a
single logical unit, and then representing that unit with the single
character "\n". Basically, you're at the tail end of decades of mess
involving line endings, and we're all doing our best to cope with the
morass of craziness that's out in the world. For the most part, what
Python does is what you want; in the situations where it isn't, you
can override it with the parameter.

Be aware that bytes and characters are FAR more different than this.
But if you're confident that your file is encoded ASCII or UTF-8
(which are probably the most common encodings you'll encounter), then
you can at least be certain that the byte value b"\r" corresponds
exactly to the character "\r".

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


Re: Python3 - How do I import a class from another file

2019-12-10 Thread Chris Angelico
On Wed, Dec 11, 2019 at 2:36 AM Antoon Pardon  wrote:
>
> On 10/12/19 16:10, Chris Angelico wrote:
> > On Wed, Dec 11, 2019 at 1:53 AM Antoon Pardon  wrote:
> >> What would you want to happen in the following case:
> >>
> >>foo1 = Bar()
> >>foo2 = foo1
> >>del foo1
> >>
> >> Should the object be cleaned up now or not?
> >>
> > TBH both are plausible,
>
> I find that strange because if you cleanup the object in that scenario
> it should also
> be cleaned up in the following.
>
> def newbar():
> foo = Bar
> return foo
>
> bar = newbar()
>
> foo goes out of scope, so that is equivallent to a del foo. But I wouldn't
> want the object cleaned up because of that.
>

Going out of scope isn't the same as explicit destruction. If you want
to simulate "going out of scope" without an actual scope change, the
nearest equivalent is something like "foo = None". In Python, there
isn't any such thing as "explicit destruction" (although
obj.__exit__() is often used for that kind of purpose), so the del
statement is just a removal from the current namespace; but when
explicit destruction does actually exist, it's an operation that
affects an object, not a name binding. (Any names previously bound to
that object will end up bound to the destroyed object.)

(Did you intend for that to be "foo = Bar()" ?)

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


Re: Python3 - How do I import a class from another file

2019-12-10 Thread Antoon Pardon
On 10/12/19 16:56, Chris Angelico wrote:
> On Wed, Dec 11, 2019 at 2:36 AM Antoon Pardon  wrote:
>> On 10/12/19 16:10, Chris Angelico wrote:
>>> On Wed, Dec 11, 2019 at 1:53 AM Antoon Pardon  wrote:
 What would you want to happen in the following case:

foo1 = Bar()
foo2 = foo1
del foo1

 Should the object be cleaned up now or not?

>>> TBH both are plausible,
>> I find that strange because if you cleanup the object in that scenario
>> it should also
>> be cleaned up in the following.
>>
>> def newbar():
>> foo = Bar
>> return foo
>>
>> bar = newbar()
>>
>> foo goes out of scope, so that is equivallent to a del foo. But I wouldn't
>> want the object cleaned up because of that.
>>
> Going out of scope isn't the same as explicit destruction.

In the context of this discussion it is. We are talking about about
automatic cleanup
and whether it should happen immediatly after a name is no longer
available. or wait
until the object is garbage collected. The fact that I used a del for
illustrating the
possible problems is just a detail.

That other languages may have different semantics with the del statement
is irrelevant.

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


Re: Randomizing Strings In A Microservices World

2019-12-10 Thread Peter Pearson
On Mon, 9 Dec 2019 21:38:43 -0600, Tim Daneliuk  wrote:
> On 12/9/19 8:54 PM, Dennis Lee Bieber wrote:
>> On Mon, 9 Dec 2019 18:52:11 -0600, Tim Daneliuk 
>> declaimed the following:
>> 
>>> - Each of these services needs to produce a string of ten digits
>>> guaranteed to be unique on a per service instance basis AND to not
>>> collide for - oh, let's say - forever :)s
>>>
>>> Can anyone suggest a randomization method that might achieve this
>>> efficiently?
>>>
>>> My first thought was to something like nanonseconds since the epoch
>>> plus something unique about the service instance - like it's IP?
>>> (This is in a K8s cluster) - to see the randomization and
>>> essentially eliminate the string being repeated.
>>>
>>> Ideas welcome ..
>> 
>>  Well, 10 digits is rather short, but studying
>> https://en.wikipedia.org/wiki/Universally_unique_identifier might provide
>> some ideas.
>
> For a variety of reasons the length of this string cannot exceed 10
> digits.  It is believed that - in this application - the consumption
> of values will be sparse over time.  All I really need is a high
> entropy way to select from among the billion possible values to
> minimize the possibility of collisions (which require retry and time
> we don't want to burn).

Just to be sure: you *are* aware that the "Birthday Paradox" says
that if you pick your 10-digit strings truly randomly, you'll probably
get a collision by the time of your 10**5th string . . . right?

-- 
To email me, substitute nowhere->runbox, invalid->com.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python3 - How do I import a class from another file

2019-12-10 Thread Michael Torrie
On 12/10/19 5:44 AM, R.Wieser wrote:
>> Well, that's exactly what happens.
> 
> So, only the reference count gets lowered.  Yep, thats daft.

Why?  Consider:

a = someobject
b = a

How many references for someobject?  After "del a" what should be be?
It's still someobject (the same object).

Or the example Antoon provided:

def foo()
   b = Bar()
   return b
   # b reference is deleted automatically


> ... unless you explain why it can only be done that way.

That is how a ref-counting resource management system works.

> I tend to go with logic.   No logic => it most likely doesn't work that way.

Interestingly I just saw a podcast recently titled, "Why too much logic
leads to irrationality."  In this case your logic is faulty because, as
you say, you lack information, which others have tried to provide.

> Choosing to go with a delayed action like you say will, as I already 
> explained, create problems later on (race conditions everywhere).  And as I 
> do not think the designers of the language where that stupid I must 
> therefore reject your claim to what you think happens.

No, that is exactly what happens.  And for good reasons.  Google for
reference-counting garbage collection.  This is not just some brand new
Python thing.  Be careful who you call stupid.  Seriously.  Doesn't
reflect well on you, who by your own admission is still learning the
language.  Python is not C++; don't code like it is.  If you need
semantics that are like RAII, then as Chris has said, you need to look
at the "with" statement and context handlers.


> But, as you mentioned, I do not know (all) the facts.  Please do present 
>them.   Maybe there is a logic in there I do not yet see.

And that's exactly what Chris and others did.  They explained the facts
and how relying on "del" to release the GPIO pin only works because you
got lucky.

>> Check out the 'with' statement.
> 
> I'm sorry, but nope.

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


Re: Installation Error (0xc000007b)

2019-12-10 Thread poltone

i'm getting the error message while installing python in my dell laptop.
ERROR: the application was unable to start (0xc07b).


The error code 0xc07b means STATUS_INVALID_IMAGE_FORMAT, i.e. probably that 
the program you want to start is not made for the processor architecture of 
your computer. Is it possible that you are trying to run a 64-bit program on a 
32-bit computer?


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


Re: Python3 - How do I import a class from another file

2019-12-10 Thread R.Wieser
Python,

> which contradicts your previous statement.

I don't think so.

> "with" is "more stuff" it is the right way to deal with disposable 
> ressource in the first place.

Than you have missed the point altogether.  It isn't about what you think is 
the perfect way to deal with something, but how an instanciated class 
responds to an explicit "del" command.

Regards,
Rudy Wieser


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


Re: Python3 - How do I import a class from another file

2019-12-10 Thread R.Wieser
Chris,

> Okay. What should happen when you do this?
>
> x = 5
> del x
>
> Should the integer 5 be deleted?

Yep.

What do you think happens instead ?   I've not seen you explain or support 
anything in that regard, not even now.

There is a bit of a problem with the above though: It has got zero to do 
with the __del__ I was talking about.  I've not seen you point out any 
mistake with my example (pointing out race contition problems) either.

Not a smooth move bro.  Not a smooth move /at all/ :-(

> So the language designers couldn't possibly have been so stupid
> as to do things this way, but you're going to ignore what they did?

Actually, they didn't.

Did you know you can disable the garbage collector ?  Well, you can.   Guess 
what I saw when I disabled it, created a class instance and than deleted it 
again.  Yup, the "print" command I placed in the "__del__" method did 
actually show output - something that, according to you, could/should never 
happen ...

Than again, I've used Python 3 for the test.  Maybe you're remembering 
something from an older version ?

Regards,
Rudy Wieser


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


Re: Python3 - How do I import a class from another file

2019-12-10 Thread R.Wieser
Antoon,

> Well yes that is why it is stupid to rely on the garbage collector to do
> those things for you. That is why Greg Ewing already stated:
>
>> If your object has a method for explicitly making it release its
>> resources, it would be better to use that rather than rely on
>> the garbage collector.

I think that you are mistaken to the meaning of word "resources" in the 
above ...

>   foo1 = Bar()
>   foo2 = foo1
>   del foo1
>
> Should the object be cleaned up now or not?

Seriously ?No, as the object is still being referenced by "foo2".And 
I do not see you explain anything either. :-(

Also, what has that got to do anything with my example talking about the 
"__del__" method  I posted ?As far as I can tell ?  Nothing.

Regards,
Rudy Wieser

P.s.
Be sure to read my reply to Chris.


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


Re: Randomizing Strings In A Microservices World

2019-12-10 Thread Tim Daneliuk
On 12/10/19 10:36 AM, Peter Pearson wrote:
> Just to be sure: you *are* aware that the "Birthday Paradox" says
> that if you pick your 10-digit strings truly randomly, you'll probably
> get a collision by the time of your 10**5th string . . . right?

I did not consider this, but the point is taken.

Could you kindly point me to a source for calculating this given
n-digit numeric-only strings?

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


Re: Python3 - How do I import a class from another file

2019-12-10 Thread MRAB

On 2019-12-10 17:18, R.Wieser wrote:

Chris,


Okay. What should happen when you do this?

x = 5
del x

Should the integer 5 be deleted?


Yep.

What do you think happens instead ?   I've not seen you explain or support
anything in that regard, not even now.

There is a bit of a problem with the above though: It has got zero to do
with the __del__ I was talking about.  I've not seen you point out any
mistake with my example (pointing out race contition problems) either.

Not a smooth move bro.  Not a smooth move /at all/ :-(


So the language designers couldn't possibly have been so stupid
as to do things this way, but you're going to ignore what they did?


Actually, they didn't.

Did you know you can disable the garbage collector ?  Well, you can.   Guess
what I saw when I disabled it, created a class instance and than deleted it
again.  Yup, the "print" command I placed in the "__del__" method did
actually show output - something that, according to you, could/should never
happen ...

Than again, I've used Python 3 for the test.  Maybe you're remembering
something from an older version ?


You merely disabled the mark-and-sweep collector.

When the reference out reaches zero, the object is deleted, but if an 
object is part of a reference cycle, the reference count will never 
reach zero.


To deal with that, there's a mark-and-sweep collector that's called 
periodically.

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


Re: Randomizing Strings In A Microservices World

2019-12-10 Thread Chris Angelico
On Wed, Dec 11, 2019 at 5:01 AM Tim Daneliuk  wrote:
>
> On 12/10/19 10:36 AM, Peter Pearson wrote:
> > Just to be sure: you *are* aware that the "Birthday Paradox" says
> > that if you pick your 10-digit strings truly randomly, you'll probably
> > get a collision by the time of your 10**5th string . . . right?
>
> I did not consider this, but the point is taken.
>
> Could you kindly point me to a source for calculating this given
> n-digit numeric-only strings?
>

The exact formula is pretty gnarly, but you can get remarkably close
by assuming that you're likely to get a collision at the square root -
which is half the exponent (so a 16-bit checksum will collide after
about 2**8 examples, and a 128-bit UUID4 will collide after about
2**64 UUIDs are generated).

https://en.wikipedia.org/wiki/Birthday_problem

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


Re: Python3 - How do I import a class from another file

2019-12-10 Thread Rhodri James

On 10/12/2019 17:18, R.Wieser wrote:

Chris,


Okay. What should happen when you do this?

x = 5
del x

Should the integer 5 be deleted?


Yep.

What do you think happens instead ?   I've not seen you explain or support
anything in that regard, not even now.


As it happens, the object that is the integer 5 *isn't* deleted.  Once 
again, you are making assertions based on what you believe to be true, 
despite having been told otherwise.  That's fair enough, but you then 
give those assertions the weighting of fact.



There is a bit of a problem with the above though: It has got zero to do
with the __del__ I was talking about.


On the contrary, it's exactly the point.  You are asserting behaviour 
that you are not guaranteed.  It happens that current versions of 
CPython conform to your expectations.  I have a vague and unreliable 
recollection that earlier versions didn't.  Other Python interpreters 
may or may not.  The language description does not give you that 
guarantee, so relying on it is at best foolish.



 I've not seen you point out any
mistake with my example (pointing out race contition problems) either.


Greg Ewing did:

"In that case, it was only working by accident. You were unwittingly
relying on the garbage collector to immediately clean up the object
as soon as the last reference to it disappeared. That happens to be
true currently in CPython (which uses reference counting), but it's
not guaranteed by the language."

Unless you're referring to some other example.  It's a bit hard to tell 
without the context.



Not a smooth move bro.  Not a smooth move /at all/ :-(


Words fail me.


So the language designers couldn't possibly have been so stupid
as to do things this way, but you're going to ignore what they did?


Actually, they didn't.

Did you know you can disable the garbage collector ?  Well, you can.   Guess
what I saw when I disabled it, created a class instance and than deleted it
again.  Yup, the "print" command I placed in the "__del__" method did
actually show output - something that, according to you, could/should never
happen ...


What you disabled wasn't the garbage collector, it was the garbage 
collector's periodic background run to detect reference cycles and 
delete them when they have no external references.  The garbage 
collector itself ran just fine when your instance's reference count 
reached zero, exactly as everyone has been saying to you.


And to repeat, you have *no* guarantee *at all* in the language spec 
that this will happen.  The garbage collector could have waited until it 
was short of space before deleting the object, for example, which might 
not happen until your script terminates.


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


Re: Python3 - How do I import a class from another file

2019-12-10 Thread R.Wieser
Michael,

>> So, only the reference count gets lowered.  Yep, thats daft.
>
> Why?  Consider:

You missed the point.

It was-and-is not about decrementing a reference but still having it above 
zero, but what happens when the reference becomes zero: is the __del__ 
method called directly (as I find logical), or is it only called when the 
garbage collector actually removes the instance from memory (which Chris 
thinks what happens) ?

> No, that is exactly what happens.

No, it doesn't.  As a simple bit of testcode has shown me (read my reply to 
Chris).

> Be careful who you call stupid.  Seriously.

Who did I call stupid ?I mentioned that the language doing it as Chris 
thinks it happens would be stupid, and I gave a reason for that (race 
conditions everywhere).  But odd: Neither him nor you nor anyone else who 
complains about me thinking for myself has even /tried/ to shoot holes in my 
example (or explain, let alone underbuild their own stance).  Do you have 
/any/ idea to what that makes me think ?  Yeah, exactly that. :-((

> Doesn't reflect well on you, who by your own admission is still learning
> the language.

True, I'm a newbie learning /Python/.   But it is far from the first 
language I've used.  Experience /does/ count for something you know. :-)

> And that's exactly what Chris and others did.  They explained the facts

No, they didn't.  They just TOLD me /their/ "facts".  Not an explanation 
anywhere. :-(

Regards,
Rudy Wieser 


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


Re: Python3 - How do I import a class from another file

2019-12-10 Thread Chris Angelico
On Wed, Dec 11, 2019 at 5:51 AM R.Wieser  wrote:
>
> Michael,
>
> >> So, only the reference count gets lowered.  Yep, thats daft.
> >
> > Why?  Consider:
>
> You missed the point.
>
> It was-and-is not about decrementing a reference but still having it above
> zero, but what happens when the reference becomes zero: is the __del__
> method called directly (as I find logical), or is it only called when the
> garbage collector actually removes the instance from memory (which Chris
> thinks what happens) ?
>
> > No, that is exactly what happens.
>
> No, it doesn't.  As a simple bit of testcode has shown me (read my reply to
> Chris).

You continue to be grossly mistaken and oblivious to this fact.

> > Be careful who you call stupid.  Seriously.
>
> Who did I call stupid ?I mentioned that the language doing it as Chris
> thinks it happens would be stupid, and I gave a reason for that (race
> conditions everywhere).  But odd: Neither him nor you nor anyone else who
> complains about me thinking for myself has even /tried/ to shoot holes in my
> example (or explain, let alone underbuild their own stance).  Do you have
> /any/ idea to what that makes me think ?  Yeah, exactly that. :-((

x = []
x.append(x)
x = None

At what point does the reference count for that list drop to zero?
When should its __del__ method be called? Have you actually looked
into what you're heaping scorn onto?

> > Doesn't reflect well on you, who by your own admission is still learning
> > the language.
>
> True, I'm a newbie learning /Python/.   But it is far from the first
> language I've used.  Experience /does/ count for something you know. :-)
>
> > And that's exactly what Chris and others did.  They explained the facts
>
> No, they didn't.  They just TOLD me /their/ "facts".  Not an explanation
> anywhere. :-(
>

No, we told you facts. Facts are not owned by anyone. They simply are.

I'm pretty much done with talking to you. You aren't listening, and
you're being abrasive and scornful at every turn.

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


Re: Python3 - How do I import a class from another file

2019-12-10 Thread R.Wieser
MRAB,

> You merely disabled the mark-and-sweep collector.

Nope.   Go check the docs on "gc"

Regards,
Rudy Wieser


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


Re: Python3 - How do I import a class from another file

2019-12-10 Thread Chris Angelico
On Wed, Dec 11, 2019 at 6:06 AM R.Wieser  wrote:
>
> MRAB,
>
> > You merely disabled the mark-and-sweep collector.
>
> Nope.   Go check the docs on "gc"
>

https://docs.python.org/3/library/gc.html

"""
This module provides an interface to the optional garbage collector.
... Since the collector supplements the reference counting already
used in Python, you can disable the collector if you are sure your
program does not create reference cycles.
"""

Once again, you make positive assertions about things you don't understand.

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


Re: Python3 - How do I import a class from another file

2019-12-10 Thread Rhodri James

On 10/12/2019 19:00, R.Wieser wrote:

MRAB,


You merely disabled the mark-and-sweep collector.


Nope.   Go check the docs on "gc"


Yep.  Go and check the docs on "gc" *carefully*

*plonk*


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


Re: Python3 - How do I import a class from another file

2019-12-10 Thread Roel Schroeven

R.Wieser schreef op 10/12/2019 om 13:44:


Also, when you scorn something without knowing your facts,
you tend to make yourself look like a fool :)


I tend to go with logic.   No logic => it most likely doesn't work that way.

Choosing to go with a delayed action like you say will, as I already
explained, create problems later on (race conditions everywhere).  And as I
do not think the designers of the language where that stupid I must
therefore reject your claim to what you think happens.


Chris: long-time contributor to this mailing list, lots of Python 
experience, knows his stuff.

Rudy: new to Python, still learning the basics.

Chris: explains how things work, states the facts correctly.
Rudy: disregards all that and thinks he knows better.

Me: does not compute


But, as you mentioned, I do not know (all) the facts.  Please do present
them.   Maybe there is a logic in there I do not yet see.


Check out the 'with' statement.


I'm sorry, but nope.


That's a very foolish rejection.

Rudy, unless/until you know the language inside out, you'd better listen 
to Chris and other people here who spend a lot of time and effort in 
helping people like you. Don't correct them on things like this unless 
you can cite chapter and verse.

You're doing yourselves a massive disservice by acting this way.

Best regards,
Roel

--
"Honest criticism is hard to take, particularly from a relative, a
friend, an acquaintance, or a stranger."
-- Franklin P. Jones

Roel Schroeven

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


Re: Python3 - How do I import a class from another file

2019-12-10 Thread R.Wieser
Rhodri,

> the object that is the integer 5 *isn't* deleted

That was not the question.  And you're now referring to the object as well 
as the integer, which makes it confusing. You also have not explained what 
happens instead.   In short, your above statement has ZERO value to me.

> On the contrary, it's exactly the point.  You are asserting behaviour that 
> you are not guaranteed.

Prove it.  I'm getting a bit fed up with you guys yapping along without 
anything to back anything up.

> What you disabled wasn't the garbage collector,

Prove it.  The docs.python.org page I found says something else, starting 
with the pages title being "Garbage Collector".

> And to repeat, you have *no* guarantee *at all* in the language spec that 
> this will happen.

There is also absolutily no guarantee in those specs that my 'puter will not 
suddenly transform into a bonzai tree.   Should I now expect it to happen ?

Regards,
Rudy Wieser


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


Re: Python3 - How do I import a class from another file

2019-12-10 Thread MRAB

On 2019-12-10 19:25, R.Wieser wrote:

Rhodri,


the object that is the integer 5 *isn't* deleted


That was not the question.  And you're now referring to the object as well
as the integer, which makes it confusing. You also have not explained what
happens instead.   In short, your above statement has ZERO value to me.

On the contrary, it's exactly the point.  You are asserting behaviour that 
you are not guaranteed.


Prove it.  I'm getting a bit fed up with you guys yapping along without
anything to back anything up.


What you disabled wasn't the garbage collector,


Prove it.  The docs.python.org page I found says something else, starting
with the pages title being "Garbage Collector".


From the help:

"""CPython implementation detail: CPython currently uses a 
reference-counting scheme with (optional) delayed detection of 
cyclically linked garbage, which collects most objects as soon as they 
become unreachable, but is not guaranteed to collect garbage containing 
circular references. See the documentation of the gc module for 
information on controlling the collection of cyclic garbage. Other 
implementations act differently and CPython may change. Do not depend on 
immediate finalization of objects when they become unreachable (so you 
should always close files explicitly)."""


Ultimately, the proof of how CPython works is in its source code, which 
is open.


And to repeat, you have *no* guarantee *at all* in the language spec that 
this will happen.


There is also absolutily no guarantee in those specs that my 'puter will not
suddenly transform into a bonzai tree.   Should I now expect it to happen ?


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


Re: Python3 - How do I import a class from another file

2019-12-10 Thread Rhodri James

On 10/12/2019 19:25, R.Wieser wrote:

And to repeat, you have*no*  guarantee*at all*  in the language spec that
this will happen.

There is also absolutily no guarantee in those specs that my 'puter will not
suddenly transform into a bonzai tree.   Should I now expect it to happen ?


That's an implementation detail of your computer.

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


Re: Python3 - How do I import a class from another file

2019-12-10 Thread R.Wieser
Dennis,

> In common Python, small integers are cached internally for reuse

That is what I imagined could possibly be happening, reading the specific 
"the integer 5" formulation in the question ("reading between the lines" and 
all that).

And thanks for that explanation, underbuild an all.  :-)

> If you had an object on which you invoked "del", then it had a
> reference count, and if that reference count dropped to 0, then any
> __del__ method would be called.

That is exactly what I thought (the most logical thing), but Greg seemed to 
know better:

[quote: greg]
In that case, it was only working by accident. You were unwittingly
relying on the garbage collector to immediately clean up the object
as soon as the last reference to it disappeared.
[/quote]

My doubt to that (explicitily mentioning the __del__ method) was than picked 
up by Chris, who continued in the same vein.  After which the others started 
to pile up on me.

I hope you do realise that you are opening yourself up to those same guys ? 
After a few of those ontop of you quickly ceases to be funny. :-(

> Remember that reference counting, the main garbage collection
> mechanism in Python, can't be disabled.

Even /wanting/ to do so would be rather stupid, as it would mean the program 
would than be hemmoraging memory.

> The only garbage collection behavior you can
> alter is the generational garbage collector in the gc module.

Which I assume just takes care of compacting the available memory (and 
dealing with those (already found?) circular references).

Regards,
Rudy Wieser


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


Python3 - How do I import a class from another file

2019-12-10 Thread R.Wieser
Chris,

> Once again, you make positive assertions about things you
> don't understand.

And you have refused to bring any kind of help (explanation!) forward that
could have shown me the erring of my ways, as well as refusing to adress my
(attempting to explain) examples.

You might know a thing or two about Python, but you (and a number of others
here) positivily stink as teachers, incapable or even unwilling to place
themselves in the shoes of a newbie.

Only now I know, after Dennis explanation, that there are (at least) /two/
garbage collectors.  One of which is triggered by a reference count becoming
zero, and one periodically called.

And although you have been fighting me over when the __del__ method is
called, it /is/ called directly as a result of an "del instance" and the
refcount goes zero.  There is /no/ delay.(with the only exception is
when a circular reference exists).

Hence, no "race condition" problem.

But for some reason even my claiming that that would happen didn't trigger
any kind of understanding.

And you  blame /me/ for making certain (logical!) assumptions ?   Really ?

Regards,
Rudy Wieser



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


Re: Python3 - How do I import a class from another file

2019-12-10 Thread R.Wieser
Roel,

> Rudy, unless/until you know the language inside out, you'd better listen 
> to Chris and other people here who spend a lot of time and effort in 
> helping people like you.

I tried.   But what he said made no sense to me, and no matter how hard I 
tried I could not get Chris (or others for that matter) to understand.   And 
as you might have seen, I tried. In several different ways.

The only thing I got was regurgitation, without /any/ attempt to figure out 
where my mistake would be.  Do you have /any/ idea how frustrating that that 
is ?   Do you ?

Also, if I would not care about it, why would I than not simply have stopped 
responding ?   Much easier than to try to get someone to understand.

And as it turned out, I /didn't/ make a mistake.The __del__ method /is/ 
directly called as a result of the "del instance" command (and the reference 
count going zero).  No delay, and thus no "race condition" exist.

Regards,
Rudy Wieser


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


Re: Python3 - How do I import a class from another file

2019-12-10 Thread Chris Angelico
On Wed, Dec 11, 2019 at 8:26 AM R.Wieser  wrote:
>
> Roel,
>
> > Rudy, unless/until you know the language inside out, you'd better listen
> > to Chris and other people here who spend a lot of time and effort in
> > helping people like you.
>
> I tried.   But what he said made no sense to me, and no matter how hard I
> tried I could not get Chris (or others for that matter) to understand.   And
> as you might have seen, I tried. In several different ways.
>
> The only thing I got was regurgitation, without /any/ attempt to figure out
> where my mistake would be.  Do you have /any/ idea how frustrating that that
> is ?   Do you ?

Given that you aren't listening when we point out where the mistake
is, yes, I know how frustrating it is.

> Also, if I would not care about it, why would I than not simply have stopped
> responding ?   Much easier than to try to get someone to understand.
>
> And as it turned out, I /didn't/ make a mistake.The __del__ method /is/
> directly called as a result of the "del instance" command (and the reference
> count going zero).  No delay, and thus no "race condition" exist.
>

And once again, you are maintaining your assumptions despite being
very clearly shown that they are wrong. "del instance" does not
directly call __del__ any more than "instance = 1" does. You HAVE been
shown.

I'm done responding to you. I'm very close to blocking you in my mail client.

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


Re: Python3 - How do I import a class from another file

2019-12-10 Thread Paul Moore
On Tue, 10 Dec 2019 at 21:12, R.Wieser  wrote:
> And although you have been fighting me over when the __del__ method is
> called, it /is/ called directly as a result of an "del instance" and the
> refcount goes zero.  There is /no/ delay.(with the only exception is
> when a circular reference exists).

You do understand that the reference counting garbage collector is an
implementation detail of the CPython implementation *only*, don't you?
The (implementation independent) language semantics makes no assertion
about what form of garbage collection is used, and under other garbage
collectors, there can be an indefinite delay between the last
reference to a value being lost and the object being collected (which
is when __del__ gets called). There is not even a guarantee that
CPython will retain the reference counting GC in future versions.
Removing it would be a big change, but not impossible.

If all you are interested is the semantics of the current CPython
release, then your statements are true. But why would anyone here know
that you were looking at the situation from such a limited
perspective?

Your "logic" seems to be full of hidden assumptions and unstated
qualifications. And your attitude seems to be confrontational and
aggressive. Frankly, it's unlikely that you're going to learn much
without a change in your approach.

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


Re: Python3 - How do I import a class from another file

2019-12-10 Thread MRAB

On 2019-12-10 21:08, R.Wieser wrote:

Chris,


Once again, you make positive assertions about things you
don't understand.


And you have refused to bring any kind of help (explanation!) forward that
could have shown me the erring of my ways, as well as refusing to adress my
(attempting to explain) examples.

You might know a thing or two about Python, but you (and a number of others
here) positivily stink as teachers, incapable or even unwilling to place
themselves in the shoes of a newbie.

Only now I know, after Dennis explanation, that there are (at least) /two/
garbage collectors.  One of which is triggered by a reference count becoming
zero, and one periodically called.

And although you have been fighting me over when the __del__ method is
called, it /is/ called directly as a result of an "del instance" and the
refcount goes zero.  There is /no/ delay.(with the only exception is
when a circular reference exists).

You don't "del" an instance, you "del" a reference, which might be in 
the form of a name in a namespace.


If that was the only reference to the instance, then the instance can be 
collected.


When the instance is collected, whenever that happens to be, its 
"__del__" method is called.


CPython uses reference counting, so if del removes the only reference, 
the instance will collected the instance immediately.


The language definition doesn't specify that reference counting must be 
used; that's just what CPython happens to use, and it's nice in that 
collection tends to happen sooner.


Other implementations can use other techniques, and for some of them 
there might be a delay before collection kicks in, so if an instance is 
holding a resource, that resource would not be released as quickly.



Hence, no "race condition" problem.

But for some reason even my claiming that that would happen didn't trigger
any kind of understanding.

And you  blame /me/ for making certain (logical!) assumptions ?   Really ?


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


Re: Python3 - How do I import a class from another file

2019-12-10 Thread Michael Torrie
On 12/10/19 11:47 AM, R.Wieser wrote:
> Who did I call stupid ?I mentioned that the language doing it as Chris 
> thinks it happens would be stupid, and I gave a reason for that (race 
> conditions everywhere).  But odd: Neither him nor you nor anyone else who 
> complains about me thinking for myself has even /tried/ to shoot holes in my 
> example (or explain, let alone underbuild their own stance).  Do you have 
> /any/ idea to what that makes me think ?  Yeah, exactly that. :-((

You said it by implication.

quote:  "And as I do not think the designers of the language where that
stupid I must therefore reject your claim to what you think happens."

Since the language does behave as Chris described (calling __del__ does
not always happen when you want or think it does, hence the "with"), you
have implied that Guido and friends are stupid and that you are not.

You can imply that I'm stupid all you want because I can't "shoot holes
in your example" to your satisfaction.  Doesn't change the fact that
what we've told you are facts about Python's operation.  I'm stupid
about many things but not this one.

>> Doesn't reflect well on you, who by your own admission is still learning
>> the language.
> 
> True, I'm a newbie learning /Python/.   But it is far from the first 
> language I've used.  Experience /does/ count for something you know. :-)

In this case your experience is perhaps leading you astray when it comes
to Python.

>> And that's exactly what Chris and others did.  They explained the facts
> 
> No, they didn't.  They just TOLD me /their/ "facts".  Not an explanation 
> anywhere. :-(

There's no such thing as "their facts."  There are facts, lies, and just
opinions.  What Chris said was fact.  Even if it isn't supported by your
brief and incomplete testing.

I was quite happy to see your posts up until this point. It appeared
that you were making great headway and maybe even enjoying Python. But
now I fear you're going to end up in a lot of awesome contributors'
killfiles.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python3 - How do I import a class from another file

2019-12-10 Thread Michael Torrie
On 12/10/19 2:08 PM, R.Wieser wrote:
> You might know a thing or two about Python, but you (and a number of others
> here) positivily stink as teachers, incapable or even unwilling to place
> themselves in the shoes of a newbie.

As it happens, I've heard Chris speak about teaching Python to students.
 I suspect they learn rather well from him.  Chris is a very articulate
and great explainer.

It's a two-way street.  It's hard to teach someone that won't be taught.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python3 - How do I import a class from another file

2019-12-10 Thread Python

Michael Torrie wrote:

On 12/10/19 2:08 PM, R.Wieser wrote:

You might know a thing or two about Python, but you (and a number of others
here) positivily stink as teachers, incapable or even unwilling to place
themselves in the shoes of a newbie.


As it happens, I've heard Chris speak about teaching Python to students.
  I suspect they learn rather well from him.  Chris is a very articulate
and great explainer.

It's a two-way street.  It's hard to teach someone that won't be taught.


+1



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


datetime gotcha

2019-12-10 Thread Frank Millman

Hi all

It took me a while to track down a bug that stemmed from this -

>>> from datetime import date as dt, time as tm, datetime as dtm
>>> x = dt.today()
>>> isinstance(x, dt)
True
>>> isinstance(x, dtm)
False
>>> y = dtm.now()
>>> isinstance(y, dt)
True   <--- ??
>>> isinstance(y, dtm)
True
>>> isinstance(y, tm)
False
>>>

Why is a dtm instance also an instance of dt?

From the docs, "A datetime object is a single object containing all the 
information from a date object and a time object."


If it was using multiple inheritance, a dtm should also be an instance 
of tm, but it is not.


This is using Python 3.7.2.

Frank Millman

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