python lmfit.minimizer not working

2018-06-13 Thread Priya Singh
Dear All,

I am trying to fit a spectrum using a power law model. I am using 
lmfit.minimizer. But the problem is that the value of parameter I am getting is
same as the initial value. Means minimizer is not working. Here is the part of 
my code:


p = Parameters()
p.add('b', value=10)
p.add('x_0', value=0.007, vary=False)
p.add('a', value=0.2)
p.add('tv', value=3.0, min=0.0)

def residual(p):
v = p.valuesdict()
return  (f_c_unmask - (v['b'] * (w_c_unmask/ v['x_0'] 
)**(-v['a']))*(np.exp(-v['tv']*kpa_smc)))

mi = minimize(residual, p, method='leastsq')
print(fit_report(mi))

The output I am getting:

[[Fit Statistics]]
# fitting method   = leastsq
# function evals   = 48
# data points  = 1304
# variables= 3
chi-square = 232448.935
reduced chi-square = 178.669435
Akaike info crit   = 6764.93727
Bayesian info crit = 6780.45685
[[Variables]]
b:10.000 +/- 0. (0.00%) (init = 10)
x_0:  0.007 (fixed)
a:0.2000 +/- 0. (0.00%) (init = 0.2)
tv:   4.8215e-12 +/- 0. (0.00%) (init = 3)
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Why exception from os.path.exists()?

2018-06-13 Thread Marko Rauhamaa
"Peter J. Holzer" :

> On 2018-06-11 12:24:54 +, Steven D'Aprano wrote:
>> It also clearly states:
>> 
>> All functions in this module raise OSError in the case of
>> invalid or inaccessible file names and paths, or other
>> arguments that have the correct type, but are not accepted
>> by the operating system. 
>> 
>> You know... like strings with NUL in them.

Nice catch!

> Ok. I missed that. So either the documentation or the implementation
> should be fixed. 
>
> In any case, if the implementation is changed, I still think that
> OSError(ENOENT) is wrong. It would have to be OSError(None, "embedded
> null byte"), or, if that is not possible (I haven't checked)
> OSError(EINVAL, "embedded null byte"), although that is slightly
> misleading (it implies that the OS returned EINVAL, which it didn't).

You say "misleading", I say "abstracting".

> The same check for NUL is also in other functions (e.g. open()), so
> those would have to be changed as well.

Maybe.

> I wasn't entirely clear here. What I meant is that POSIX systems, as a
> group, provide no such way.

I still don't see how POSIX is directly relevant here.


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


Re: What is the "Unpacking Arguments List" rule?

2018-06-13 Thread [email protected]

[Of the first part]
line 19 is
action(progress=progress, *args)
where the args is a tuple
args = (i, 3)
and the function is defined as
def action(id, reps, progress):

In documents 4.7.2. Keyword Arguments, it says
'''
def parrot(voltage, state='a stiff', action='voom', type='Norwegian 
Blue'):

...
...
but all the following calls would be invalid:
...
parrot(voltage=5.0, 'dead')  # non-keyword argument after a keyword 
argument

...
'''

After unpack the args in line 19, it will be looks like
action(progress=progress, i, 3)
and it seems violate the above rule.

[Of the second part]
> The "*args" and "**kw" are very helpfull. I hope (and expect)
> they will remain.
There is no "**kw" involved in this topic:-) and the positional limit of
"*args" in a function definitions has its own good reason:-)

IMHO, there is no reason to check the *args has to appear at last in
positional argument list in a function call because of there is no
"unknown number of parameters" at the time of unpacking. It should be
alright to write line 19
action(*args, progress)
just like assignment below where both are valid.
a, *b = any
*a, b = any

Best Regards,
Jach Fong


dieter at 2018/6/13 PM 12:59 wrote:

Jach Fong  writes:

...
4.7.4. Unpacking Argument Lists
The reverse situation occurs when the arguments are already in a list or
tuple but need to be unpacked for a function call requiring separate
positional arguments.
 ...

args = [3, 6]
list(range(*args))

"""

I can't understand why line 19 works?


Not sure what "line 19" is - but if it refers to the example above:

   "range" accepts (among others) 2 integer arguments.
   The "*args" above means: unpack the sequence in "args" into
   individual arguments.
   This means (with the values of the example above),
   that "range(*args)" is equivalent to "range(3, 6)".


Didn't it violate the rule of
"# non-keyword argument after a keyword argument"?


No keyword arguments at all in the above example.


and why a more
reasonable look syntax gets an error?

 action(*args, progress)
  ^
SyntaxError: only named arguments may follow *expression  File
"test.py", line 19


This is (in my view) a somewhat arbitrary restriction -- maybe
introduced for symmetry with the function definition syntax.

The message is quite clear, however: after the "*arg",
you must pass keyword arguments only, i.e. they must have
the form "param=value".


The only reason I can guess is that it checks with the rule in 4.7.3
which is really unrelated. The "*any" notation used in different places
with different meaning, such as defining arbitrary argument, unpacking
argument or even in an assignment(a,*b=any). Maybe it will be better to
stop this syntax checking and lets both statements below valid:-)


The "*args" and "**kw" are very helpfull. I hope (and expect)
they will remain.



---
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus

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


Re: Splitting up large python module impact on performance?

2018-06-13 Thread Ed Kellett
On 2018-06-13 05:24, Chris Angelico wrote:
> Oh wait, your code isn't anything remotely sane. But for the rest of
> us, large files aren't a problem.

I don't like large files--I think mostly because files are an
organisational tool, they're quite good at that job, and one might as
well use them. But slightly more concretely, Python encourages us to use
module scope for things like imports, which can easily get messy and
confusing when files are large. A find feature isn't a replacement for a
global scope that's small enough to remember.



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


Regex to extract multiple fields in the same line

2018-06-13 Thread Ganesh Pal
 Hi Team,

I wanted to parse a file and extract few feilds that are present after "="
in a text file .


Example , form  the below line I need to extract the values present after
--struct =, --loc=, --size= and --log_file=

Sample input

line = '06/12/2018 11:13:23 AM python toolname.py  --struct=data_block
--log_file=/var/1000111/test18.log --addr=None --loc=0 --mirror=10
--path=/tmp/data_block.txt size=8'


Expected output

data_block
/var/1000111/test18.log
0
8


Here is my sample code , its still not complete ,  I wanted to use regex
and find and extract all the fields after " =", any suggestion or
alternative way to optimize this further


import re
line = '06/12/2018 11:13:23 AM python toolname.py  --struct=data_block
--log_file=/var/1000111/test18.log --addr=None --loc=0 --mirror=10
--path=/tmp/data_block.txt size=8'

r_loc = r"--loc=(\d+)"
r_struct = r'--struct=(\w+)'

if re.findall(r_loc, line):
   print re.findall(r_loc, line)

if re.findall(r_struct, line):
   print re.findall(r_struct, line)


root@X1:/# python regex_02.py
['0']
['data_block']


I am a  Linux  user with python 2.7


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


How to make a button flashing?

2018-06-13 Thread huey . y . jiang
Hi All,

I forgot the syntax of making a button flash, and failed to find an example in 
the web. I use Tkinter, to create a button. Then made it packed, and showed up. 
Now I am trying to make button b flashing, to make it get better noticed. I 
checked the docs, and found a method flash() is available, then I tried:

b.flash()

there was no error message popped out, but there was nothing happened also. I 
wonder who can give me this help? Thanks!

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


Re: Splitting up large python module impact on performance?

2018-06-13 Thread Chris Angelico
On Wed, Jun 13, 2018 at 5:56 PM, Ed Kellett  wrote:
> On 2018-06-13 05:24, Chris Angelico wrote:
>> Oh wait, your code isn't anything remotely sane. But for the rest of
>> us, large files aren't a problem.
>
> I don't like large files--I think mostly because files are an
> organisational tool, they're quite good at that job, and one might as
> well use them. But slightly more concretely, Python encourages us to use
> module scope for things like imports, which can easily get messy and
> confusing when files are large. A find feature isn't a replacement for a
> global scope that's small enough to remember.
>

It's more his definition of "large" and "small" that I was disagreeing
with. You're absolutely right that a dense global scope is a problem;
but a "one class per file" rule is a terrible idea. A hundred tiny
files is far harder to work with than ten medium-sized files, and IMO
a single file with all the code in it is only slightly worse. That is
to say, I would prefer to work with a single gigantic file than a
directory with lots and lots of tiny interdependent files, each one
importing six or seven others.

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


Re: UnicodeDecodeError: 'charmap' codec can't decode byte 0x9d in position 10442: character maps to

2018-06-13 Thread bellcanadardp
On Sunday, 10 June 2018 17:29:59 UTC-4, Cameron Simpson  wrote:
> On 10Jun2018 13:04, [email protected]  wrote:
> >here is the full error once again
> >to summarize, my script works fine in python2
> >i get this error trying to run it in python3
> >plz see below after the error, my settings for python 2 and python 3
> >for me it seems i need to change some settings to 'utf-8'..either just in 
> >python 3, since thats where i am having issues or change the settings to 
> >'utf-8' both in python 2 and 3i would appreciate feedback b4 i do some 
> >trial and error
> >thanks for the consideration
> >tommy
> >
> >***
> >Traceback (most recent call last):
> >File "createIndex.py", line 132, in 
> >c.createindex()
> >File "creatIndex.py", line 102, in createIndex
> >pagedict=self.parseCollection()
> >File "createIndex.py", line 47, in parseCollection
> >for line in self.collFile:
> >File 
> >"C:\Users\Robert\AppData\Local\Programs\Python\Python36\lib\encodings\cp1252.py",
> > 
> >line 23, in decode
> >return codecs.charmap_decode(input,self.errors,decoding_table[0]
> >UnicodeDecodeError: 'charmap'codec can't decode byte 0x9d in position 7414: 
> >character maps to 
> 
> Ok, this is more helpful. It says that the decoding error, which occurred in 
> ...\cp1252.py, was decoding lines from the file self.collFile.
> 
> What is that file? And how was it opened?
> 
> Also, your settings below may indeed be important.
> 
> >***
> >python 3 settings
> >import sys
> > import locale
> >locale.getpreferredencoding()
> >'cp1252'
> 
> The setting above is the default encoding used when you open a file in text 
> mode in Python 3, but you can override it.
> 
> In Python 3 this matters a lot, because Python 3 strings are Unicode. In 
> Python 
> 2, strings are just bytes, and are not "decoded" (there is a whole separate 
> "unicode" type for that when it matters).
> 
> So in Python 3 the text file reader is decoding the text in the file 
> according 
> to what it expects the encoding to be.
> 
> Find the place where self.collFile is opened. You can specify the decoding 
> method there by adding the "encoding=" parameter to the open() call. It is 
> defaulting to "cp1252" because that is what locale.getpreferredencoding() 
> returns, but presumably the actual file data are not encoded that way.
> 
> You can (a) find out what encoding _is_ used in the file and specify that or 
> (b) tell Python to be less picky. Choice (a) is better if it is feasible.
> 
> If you have to guess because you don't know the encoding, one possibility is 
> that collFile contains utf-8 or utf-16; of these 2, utf-8 seems more likely 
> given the 0x9d byte causing the trouble.  Try adding:
> 
>   encoding='utf-8'
> 
> to the open() call, eg:
> 
>   self.collFile = open('path-to-the-coll-file', encoding='utf-8')
> 
> at the appropriate place.
> 
> If that just produces a different decoding error, you have 2 choices: pick an 
> encoding where every byte is "valid", such as 'iso8859-1', or to tell the 
> decode to just cope with th errors by adding the errors="replace" or 
> "errors="ignore" or errors="namereplace" parameter to the open() call.
> 
> Both these choices have downsides.
> 
> There are several ISO8859 encodings, and they might all be wrong for your 
> file, 
> leading to _incorrect_ text lines.
> 
> The errors="..." parameter also has downsides: you will also end up with 
> missing (errors="ignore") or incorrect (errors="replace" or 
> errors="namereplace") text, because the decoder has to do something with the 
> data: drop it or replace it with something wrong. The former loses data while 
> the latter puts in bad data, but at least it is visible if you inspect the 
> data 
> later.
> 
> The full documentation for Python 3's open() call is here:
> 
>   https://docs.python.org/3/library/functions.html#open
> 
> where the various encoding= and errors= choices are described.
> 
> Cheers,
> Cameron Simpson 

hello community forums
still failed but i tried many things and i beleive we are getting close to 
getting

1st is this script is from a library module online open source so many things 
in source code i may not trully be sure since i cant reach the original authors 
or sub authors..so


the collFile has to be like a variable that would refer to the file 
Collection.dat..thats my best guess
also in the error line , it doesnt actually open the file ...so i didnt try 
your code but i did try somethin similar b4 and it didnt work..here is a 
snippet of the code line error
***
def parseCollection(self):
''' returns the id, title and text of the next page in the collection 
'''
doc=[]  
for line in self.collFile:
if line=='\n':
break
doc.append(line)

*
so as you can see there is not open file line to try to encode to utf-8

now here is what i tried anyways

Re: UnicodeDecodeError: 'charmap' codec can't decode byte 0x9d in position 10442: character maps to

2018-06-13 Thread bellcanadardp
On Sunday, 10 June 2018 17:29:59 UTC-4, Cameron Simpson  wrote:
> On 10Jun2018 13:04, [email protected]  wrote:
> >here is the full error once again
> >to summarize, my script works fine in python2
> >i get this error trying to run it in python3
> >plz see below after the error, my settings for python 2 and python 3
> >for me it seems i need to change some settings to 'utf-8'..either just in 
> >python 3, since thats where i am having issues or change the settings to 
> >'utf-8' both in python 2 and 3i would appreciate feedback b4 i do some 
> >trial and error
> >thanks for the consideration
> >tommy
> >
> >***
> >Traceback (most recent call last):
> >File "createIndex.py", line 132, in 
> >c.createindex()
> >File "creatIndex.py", line 102, in createIndex
> >pagedict=self.parseCollection()
> >File "createIndex.py", line 47, in parseCollection
> >for line in self.collFile:
> >File 
> >"C:\Users\Robert\AppData\Local\Programs\Python\Python36\lib\encodings\cp1252.py",
> > 
> >line 23, in decode
> >return codecs.charmap_decode(input,self.errors,decoding_table[0]
> >UnicodeDecodeError: 'charmap'codec can't decode byte 0x9d in position 7414: 
> >character maps to 
> 
> Ok, this is more helpful. It says that the decoding error, which occurred in 
> ...\cp1252.py, was decoding lines from the file self.collFile.
> 
> What is that file? And how was it opened?
> 
> Also, your settings below may indeed be important.
> 
> >***
> >python 3 settings
> >import sys
> > import locale
> >locale.getpreferredencoding()
> >'cp1252'
> 
> The setting above is the default encoding used when you open a file in text 
> mode in Python 3, but you can override it.
> 
> In Python 3 this matters a lot, because Python 3 strings are Unicode. In 
> Python 
> 2, strings are just bytes, and are not "decoded" (there is a whole separate 
> "unicode" type for that when it matters).
> 
> So in Python 3 the text file reader is decoding the text in the file 
> according 
> to what it expects the encoding to be.
> 
> Find the place where self.collFile is opened. You can specify the decoding 
> method there by adding the "encoding=" parameter to the open() call. It is 
> defaulting to "cp1252" because that is what locale.getpreferredencoding() 
> returns, but presumably the actual file data are not encoded that way.
> 
> You can (a) find out what encoding _is_ used in the file and specify that or 
> (b) tell Python to be less picky. Choice (a) is better if it is feasible.
> 
> If you have to guess because you don't know the encoding, one possibility is 
> that collFile contains utf-8 or utf-16; of these 2, utf-8 seems more likely 
> given the 0x9d byte causing the trouble.  Try adding:
> 
>   encoding='utf-8'
> 
> to the open() call, eg:
> 
>   self.collFile = open('path-to-the-coll-file', encoding='utf-8')
> 
> at the appropriate place.
> 
> If that just produces a different decoding error, you have 2 choices: pick an 
> encoding where every byte is "valid", such as 'iso8859-1', or to tell the 
> decode to just cope with th errors by adding the errors="replace" or 
> "errors="ignore" or errors="namereplace" parameter to the open() call.
> 
> Both these choices have downsides.
> 
> There are several ISO8859 encodings, and they might all be wrong for your 
> file, 
> leading to _incorrect_ text lines.
> 
> The errors="..." parameter also has downsides: you will also end up with 
> missing (errors="ignore") or incorrect (errors="replace" or 
> errors="namereplace") text, because the decoder has to do something with the 
> data: drop it or replace it with something wrong. The former loses data while 
> the latter puts in bad data, but at least it is visible if you inspect the 
> data 
> later.
> 
> The full documentation for Python 3's open() call is here:
> 
>   https://docs.python.org/3/library/functions.html#open
> 
> where the various encoding= and errors= choices are described.
> 
> Cheers,
> Cameron Simpson 

hello just to clarify a typo from my last post(i make many , not verify good 
with key buttons)...

#for line in self.collFile.decode("utf-8"): 

i actually write.encode...then i tried the decode 
but both dont have any effect

thank you for any comments
tommy
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: UnicodeDecodeError: 'charmap' codec can't decode byte 0x9d in position 10442: character maps to

2018-06-13 Thread INADA Naoki
​> 1st is this script is from a library module online open source

If it's open source, why didn't you show the link to the soruce?
I assume your code is this:

https://github.com/siddharth2010/String-Search/blob/6770c7a1e811a5d812e7f9f7c5c83a12e5b28877/createIndex.py

And self.collFile is opened here:

https://github.com/siddharth2010/String-Search/blob/6770c7a1e811a5d812e7f9f7c5c83a12e5b28877/createIndex.py#L91

You need to add `encoding='utf-8'` argument.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: UnicodeDecodeError: 'charmap' codec can't decode byte 0x9d in position 10442: character maps to

2018-06-13 Thread Steven D'Aprano
On Wed, 13 Jun 2018 04:01:24 -0700, bellcanadardp wrote:

> for line in self.collFile.decode("utf-8"):
> i actually write.encode...then i tried the decode but both dont have any
> effect

Raising AttributeError isn't an effect?

py> f = open("/tmp/x")
py> f.write.decode
Traceback (most recent call last):
  File "", line 1, in 
AttributeError: 'builtin_function_or_method' object has no attribute 
'decode'



-- 
Steven D'Aprano
"Ever since I learned about confirmation bias, I've been seeing
it everywhere." -- Jon Ronson

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


Re: How to make a button flashing?

2018-06-13 Thread Peter Otten
[email protected] wrote:

> Hi All,
> 
> I forgot the syntax of making a button flash, and failed to find an
> example in the web. I use Tkinter, to create a button. Then made it
> packed, and showed up. Now I am trying to make button b flashing, to make
> it get better noticed. I checked the docs, and found a method flash() is
> available, then I tried:
> 
> b.flash()
> 
> there was no error message popped out, but there was nothing happened
> also. I wonder who can give me this help? Thanks!
> 
> Huey

Quoting http://tcl.tk/man/tcl8.6/TkCmd/button.htm#M16

"""
pathName flash
Flash the button. This is accomplished by redisplaying the button 
several times, alternating between the configured activebackground and 
background colors. At the end of the flash the button is left in the same 
normal/active state as when the command was invoked. This command is ignored 
if the button's state is disabled.
"""

So to see something you have to ensure that the two background colors 
actually differ. Complete example:

import tkinter as tk
root = tk.Tk()

button = tk.Button(root, text="Hello")
button.pack()

button["activebackground"] = "red"
button["background"] = "silver"

root.after(1000, button.flash)
root.mainloop()


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


Re: Splitting up large python module impact on performance?

2018-06-13 Thread Steven D'Aprano
On Wed, 13 Jun 2018 14:08:35 +1000, Cameron Simpson wrote:

> I was going to say something along these lines, but to some extent this
> feels like an unfair finger pointing exercise. Huge files can be a PITA;
> having something that aids moving around them reduces the pain, but
> doesn't remove the fact that sometimes something is too big.

Indeed.

As a simple practical matter, it is often simpler to navigate a large 
code base when you can open separate files in separate windows or tabs, 
rather than one giant file.

An editor which supports multiple independent views of the same file can 
mitigate that somewhat, good tooling helps (but also only goes so far), 
but as the Zen says

Namespaces are one honking great idea

Even if we could put the entire Python std lib in a single giant file 
with half a million lines plus, we probably shouldn't.



-- 
Steven D'Aprano
"Ever since I learned about confirmation bias, I've been seeing
it everywhere." -- Jon Ronson

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


Re: Splitting up large python module impact on performance?

2018-06-13 Thread Rick Johnson
On Wednesday, June 13, 2018 at 4:27:35 AM UTC-5, Chris Angelico wrote:
> It's more his definition of "large" and "small" that I was
> disagreeing with. You're absolutely right that a dense
> global scope is a problem; but a "one class per file" rule
> is a terrible idea.

What if the "one class" spans thousands of lines? Surely you
don't believe that class definitions (outside of toy classes
and academic examples, that is) are limited to a couple
dozen lines, do you?

> A hundred tiny files is far harder to work with than ten
> medium-sized files,

I doubt anyone here is suggesting that modules should be
limited to 10 lines each, or something ridiculous like that.
Heck, the minimum class definition _alone_ (at least, if
you're going to properly utilize vertical whitespace)
requires around 2 dozen lines.

## BEGIN MODULE ##
01#
02# import something here
03#
04# define constants here
05#
06#
07# (WHITE SPACE BUFFER)
08#
09#
10class MyClass(object):
11def __init__(self):
12pass
13
14def method(self):
15pass
16#
17#
18# (WHITE SPACE BUFFER)
19#
20#
21# (INITIALIZATION/TESTING/LOGIC/ETC)
22#
23#
## END MODULE ##

That's 23 lines of code to define whitespace and boilerplate
_alone_.

> and IMO a single file with all the code in it is only
> slightly worse. That is to say, I would prefer to work with
> a single gigantic file than a directory with lots and lots
> of tiny interdependent files, each one importing six or
> seven others.

Blame the import mess on a missing feature, not on those of
us who prefer reasonably sized source files.

To alleviate a large portion of the circular import mess
(and depending on the coding style employed, possibly all of
it), python's packaging system could have leveraged the
power of "componentized modules" -- much the way that
classes share variables between them using class attributes
(no import required!) -- but unfortunately, this powerful
feature was overlooked. And packages are nothing more than
some kind of quasi directory tree which masquerades itself
as a namespace so that a programmer can replace a long
import path with a _dot_.

WELL, WHOOP-DEE-DO!

That's like a superhero without a superpower.

Hmm...

After considering the blinkered state of Python packages and
the resulting pitfalls of the python import mechanism, we
can only assume the Python gods found inspiration for this
"hot mess" in the title of GnR's fifth studio album.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Regex to extract multiple fields in the same line

2018-06-13 Thread Rhodri James

On 13/06/18 09:08, Ganesh Pal wrote:

  Hi Team,

I wanted to parse a file and extract few feilds that are present after "="
in a text file .


Example , form  the below line I need to extract the values present after
--struct =, --loc=, --size= and --log_file=

Sample input

line = '06/12/2018 11:13:23 AM python toolname.py  --struct=data_block
--log_file=/var/1000111/test18.log --addr=None --loc=0 --mirror=10
--path=/tmp/data_block.txt size=8'


Did you mean "--size=8" at the end?  That's what your explanation implied.



Expected output

data_block
/var/1000111/test18.log
0
8


Regexs are more complicated than you need for this.  Plain split will do.

line = '06/12/2018 11:13:23 AM python toolname.py  --struct=data_block
 --log_file=/var/1000111/test18.log --addr=None --loc=0 --mirror=10
 --path=/tmp/data_block.txt --size=8'

for item in line.split():
if item.startswith("--struct="):
# You may want to tidy this up
print(item[9:])
# ...and so on for the other fields

Alternatively you could observe this is a previously solved problem and 
abuse argparse:


import argparse

parser = argparse.ArgumentParser()
parser.add_argument("prefix", nargs=5)
parser.add_argument("--struct")
parser.add_argument("--log_file")
parser.add_argument("--addr")
parser.add_argument("--loc")
parser.add_argument("--mirror")
parser.add_argument("--path")
parser.add_argument("--size")

line = '06/12/2018 11:13:23 AM python toolname.py --struct=data_block 
--log_file=/var/1000111/test18.log --addr=None --loc=0 --mirror=10 
--path=/tmp/data_block.txt --size=8'


args = parser.parse_args(line.split())
print(args)


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


Re: What is the "Unpacking Arguments List" rule?

2018-06-13 Thread Alister via Python-list
On Wed, 13 Jun 2018 14:21:53 +0800, [email protected] wrote:

> [Of the first part]
> line 19 is
>  action(progress=progress, *args)
> where the args is a tuple
>  args = (i, 3)
> and the function is defined as
>  def action(id, reps, progress):
> 
> In documents 4.7.2. Keyword Arguments, it says '''
>  def parrot(voltage, state='a stiff', action='voom', type='Norwegian
> Blue'):
>  ...
>  ...
>  but all the following calls would be invalid:
>  ...
>  parrot(voltage=5.0, 'dead')  # non-keyword argument after a keyword
> argument
>  ...
> '''
> 
> After unpack the args in line 19, it will be looks like
>  action(progress=progress, i, 3)
> and it seems violate the above rule.
> 
> [Of the second part]
>  > The "*args" and "**kw" are very helpfull. I hope (and expect)
>  > they will remain.
> There is no "**kw" involved in this topic:-) and the positional limit of
> "*args" in a function definitions has its own good reason:-)
> 
> IMHO, there is no reason to check the *args has to appear at last in
> positional argument list in a function call because of there is no
> "unknown number of parameters" at the time of unpacking. It should be
> alright to write line 19
>  action(*args, progress)

Anyone wanting to write such code should be banned form ever accessing a 
computer.
if you know how many arguments are going to be passed to match the *args 
part of this function then they should be assigned known variables 
otherwise the code will soon become an unmanageable mess.

this is why the language specifications states it should only appear 
after all known positional arguments have been declared
 
> just like assignment below where both are valid.
>  a, *b = any *a, b = any

> 
> Best Regards,
> Jach Fong
> 
> 
> dieter at 2018/6/13 PM 12:59 wrote:
>> Jach Fong  writes:
>>> ...
>>> 4.7.4. Unpacking Argument Lists The reverse situation occurs when the
>>> arguments are already in a list or tuple but need to be unpacked for a
>>> function call requiring separate positional arguments.
>>>  ...
>> args = [3, 6] list(range(*args))
>>> """
>>>
>>> I can't understand why line 19 works?
>> 
>> Not sure what "line 19" is - but if it refers to the example above:
>> 
>>"range" accepts (among others) 2 integer arguments.
>>The "*args" above means: unpack the sequence in "args" into
>>individual arguments.
>>This means (with the values of the example above),
>>that "range(*args)" is equivalent to "range(3, 6)".
>> 
>>> Didn't it violate the rule of "# non-keyword argument after a keyword
>>> argument"?
>> 
>> No keyword arguments at all in the above example.
>> 
>>> and why a more reasonable look syntax gets an error?
>>>
>>>  action(*args, progress)
>>>   ^
>>> SyntaxError: only named arguments may follow *expression  File
>>> "test.py", line 19
>> 
>> This is (in my view) a somewhat arbitrary restriction -- maybe
>> introduced for symmetry with the function definition syntax.
>> 
>> The message is quite clear, however: after the "*arg",
>> you must pass keyword arguments only, i.e. they must have the form
>> "param=value".
>> 
>>> The only reason I can guess is that it checks with the rule in 4.7.3
>>> which is really unrelated. The "*any" notation used in different
>>> places with different meaning, such as defining arbitrary argument,
>>> unpacking argument or even in an assignment(a,*b=any). Maybe it will
>>> be better to stop this syntax checking and lets both statements below
>>> valid:-)
>> 
>> The "*args" and "**kw" are very helpfull. I hope (and expect)
>> they will remain.
>> 
>> 
> ---
> This email has been checked for viruses by Avast antivirus software.
> https://www.avast.com/antivirus





-- 
I have a theory that it's impossible to prove anything, but I can't prove 
it.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Why exception from os.path.exists()?

2018-06-13 Thread Steven D'Aprano
On Wed, 13 Jun 2018 10:10:03 +0300, Marko Rauhamaa wrote:

> "Peter J. Holzer" :
[...]
>> I wasn't entirely clear here. What I meant is that POSIX systems, as a
>> group, provide no such way.
> 
> I still don't see how POSIX is directly relevant here.

Linux users like to sneer at Windows users for believing that Windows is 
a synonym for "computer", that what Windows does is what all computers 
do, but Linux users (especially if they're also C programmers) sometimes 
have a hard time remembering that "what POSIX does" is no more a 
universal limitation on computing than "what Windows does".

(And ironically, Linux doesn't even have POSIX certification.)

That is, when they're not blindly writing shell scripts using bashisms 
and expecting them to work under any shell :-)


I still would like to see one real-world use-case where the distinction 
between "file name is invalid because it has NUL" and "file name is 
invalid for any of a dozen other reasons" is necessary and important.


-- 
Steven D'Aprano
"Ever since I learned about confirmation bias, I've been seeing
it everywhere." -- Jon Ronson

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


Re: UnicodeDecodeError: 'charmap' codec can't decode byte 0x9d in position 10442: character maps to

2018-06-13 Thread Steven D'Aprano
On Wed, 13 Jun 2018 03:55:58 -0700, bellcanadardp wrote:

> the collFile has to be like a variable that would refer to the file
> Collection.dat..thats my best guess also in the error line , it doesnt
> actually open the file ...

The file has to be opened if you are reading from it. If it isn't opened 
in the line of code you are looking at, look at the rest of the code. 
*Somewhere* is must be opened.




-- 
Steven D'Aprano
"Ever since I learned about confirmation bias, I've been seeing
it everywhere." -- Jon Ronson

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


Re: UnicodeDecodeError: 'charmap' codec can't decode byte 0x9d in position 10442: character maps to

2018-06-13 Thread bellcanadardp
On Wednesday, 13 June 2018 07:14:06 UTC-4, INADA Naoki  wrote:
> ​> 1st is this script is from a library module online open source
> 
> If it's open source, why didn't you show the link to the soruce?
> I assume your code is this:
> 
> https://github.com/siddharth2010/String-Search/blob/6770c7a1e811a5d812e7f9f7c5c83a12e5b28877/createIndex.py
> 
> And self.collFile is opened here:
> 
> https://github.com/siddharth2010/String-Search/blob/6770c7a1e811a5d812e7f9f7c5c83a12e5b28877/createIndex.py#L91
> 
> You need to add `encoding='utf-8'` argument.

thank you INADA
 here is the line of code solution
**
self.collFile=open(self.collectionFile,'r',encoding='utf-8')
**
it was tricky only because the modification had to be done not at the actual 
error line but further down in the file where INADA correctly pointed out where 
the collFile is opened

thank you to all who posted, i truly appreciate all posts

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


Design of my project

2018-06-13 Thread Fabien LUCE
 Hello everyone,

Here is a small picture of my project.
I'd like to fetch several datas from a website representing races results.
Each line of the result contains rank, runner's name and other attributes
of the runner (like club etc...).
For now I have created 2 classes (Race and Runner).
Methods of Race allow me to fetch datas on the www thanks to beautifulsoup
module.I instanciate a race at the beginning of the scan and for each line
I instanciate a Runner.
I want to store all those information in a database (for both Race and
Runner), but here is the point, I have the feeling, on a programming
elegance point of view, that I have to separate methods that fetch from
method that store and also have a kind of superior object that controls
those 2 features.
Moreover fetching will interact with storage: if race is already in
database, no need to fetch again.
How should I "design" this? Should I have only (despite my first
impression) one class and all the methods in it? Should I create a parent
class along with 2 childrens that manage the two kind of methods?
Is there a design pattern for this?

I precise I am relatively new in "intelligent" python programming ;)

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


Re: UnicodeDecodeError: 'charmap' codec can't decode byte 0x9d in position 10442: character maps to

2018-06-13 Thread bellcanadardp
On Wednesday, 13 June 2018 09:12:32 UTC-4, Steven D'Aprano  wrote:
> On Wed, 13 Jun 2018 03:55:58 -0700, bellcanadardp wrote:
> 
> > the collFile has to be like a variable that would refer to the file
> > Collection.dat..thats my best guess also in the error line , it doesnt
> > actually open the file ...
> 
> The file has to be opened if you are reading from it. If it isn't opened 
> in the line of code you are looking at, look at the rest of the code. 
> *Somewhere* is must be opened.
> 
> 
> 
> 
> -- 
> Steven D'Aprano
> "Ever since I learned about confirmation bias, I've been seeing
> it everywhere." -- Jon Ronson

yes thank you
further down in the script..the collectionFile is indeed opened
and all it took was this line, to get the full program to work in python 3
**
self.collFile=open(self.collectionFile,'r',encoding='utf-8')
**

where 
,encoding='utf-8'
is the only change that had to be made, pointed out from INADA
(plus i used the 2to3.py, which corrected many print statements)

thanks alot for your efforts...im sure i will need this forum for future errors

thanks again to all who posted for this python 2 to python3 utf-8 unicodedecode 
error 
its very kind and built on the online programmers community spirit

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


Design of my program

2018-06-13 Thread ftg
Hello everyone,

Here is a small picture of my project.
I'd like to fetch several datas from a website representing races results. Each 
line of the result contains rank, runner's name and other attributes of the 
runner (like club etc...).
For now I have created 2 classes (Race and Runner).
Methods of Race allow me to fetch datas on the www thanks to beautifulsoup 
module.I instanciate a race at the beginning of the scan and for each line I 
instanciate a Runner.
I want to store all those information in a database (for both Race and Runner), 
but here is the point, I have the feeling, on a programming elegance point of 
view, that I have to separate methods that fetch from method that store and 
also have a kind of superior object that controls those 2 features.
Moreover fetching will interact with storage: if race is already in database, 
no need to fetch again.
How should I "design" this? Should I have only (despite my first impression) 
one class and all the methods in it? Should I create a parent class along with 
2 childrens that manage the two kind of methods?
Is there a design pattern for this?

I precise I am relatively new in "intelligent" python programming ;)

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


Re: Posting warning message

2018-06-13 Thread Grant Edwards
On 2018-06-13, Tamara Berger  wrote:

> I  just meant edit within the moment or two after you've posted a
> message. I think a good feature in this forum would allow posters to
> edit their messages in just that way. I have such a feature enabled in
> gmail. I can "undo" my action for 30 seconds after I've clicked on
> "send."

You refer to "this forum" as if you think it's some centrally
controlled web application.  It's not.  It's a Usenet group gatewayed
to a mailing list gatewayed to an archive/nntp server at gmane.org.
Google then duct-taped the atrocity that is Google Groops onto the side
of the Usenet group.

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

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

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

IOW, there is no such think as "this forum".

If you want whatever user interface you're using to send postings to
hold onto them for 15 minutes to allow you a second chance to edit
them, then you need to talk to whoever maintains the user interface
that you use to send messages to the Usetnet group or mailing list.

-- 
Grant Edwards   grant.b.edwardsYow! LOOK!!  Sullen
  at   American teens wearing
  gmail.comMADRAS shorts and "Flock of
   Seagulls" HAIRCUTS!

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


PEP8 compliance

2018-06-13 Thread T Berger
Sorry for this basic question, but to change my code if it's failed the PEP8 
test, what code do I use to open my program and make changes? Obviously, I 
should still be in bash, but then what?

Thanks,

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


Re: PEP8 compliance

2018-06-13 Thread MRAB

On 2018-06-13 16:04, T Berger wrote:

Sorry for this basic question, but to change my code if it's failed the PEP8 
test, what code do I use to open my program and make changes? Obviously, I 
should still be in bash, but then what?


You edit it in a plain text editor (i.e. an editor for plain text).
--
https://mail.python.org/mailman/listinfo/python-list


Re: PEP8 compliance

2018-06-13 Thread Steven D'Aprano
On Wed, 13 Jun 2018 08:04:27 -0700, T Berger wrote:

> Sorry for this basic question, but to change my code if it's failed the
> PEP8 test, what code do I use to open my program and make changes?

Use your text editor to modify the source code of the program.


I'm of two minds here... on the one hand, I think that generally 
speaking, PEP 8 is a good style guide to follow, and I think that in the 
long run using a consistent style is a good habit to get into.

On the other hand, some people follow PEP 8 religiously, except for the 
most important rule of all: the one about knowing when to break all the 
other rules. They can get obsessed with following PEP 8 rules even when 
it makes the code *worse*. I don't want to encourage that way of thinking.

(Making purely stylistic changes to working code is also a good way to 
avoid doing actual productive work while still looking busy.)

On the third hand, you're a beginner and you may be finding this whole 
experience confusing enough without also being told off by the computer 
because you wrote "x+1" instead of "x + 1". I don't find that helpful for 
beginners.

So use your own judgement: if following PEP 8 becomes a chore, or if you 
would rather follow your own style, don't feel guilty about ignoring the 
style guide.



-- 
Steven D'Aprano
"Ever since I learned about confirmation bias, I've been seeing
it everywhere." -- Jon Ronson

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


Re: Posting warning message

2018-06-13 Thread Steven D'Aprano
On Wed, 13 Jun 2018 14:30:05 +, Grant Edwards wrote:

[...]
> You refer to "this forum" as if you think it's some centrally controlled
> web application.  It's not.  It's a Usenet group gatewayed to a mailing
> list gatewayed to an archive/nntp server at gmane.org. Google then
> duct-taped the atrocity that is Google Groops onto the side of the
> Usenet group.
> 
>   https://en.wikipedia.org/wiki/Usenet
> 
>   https://en.wikipedia.org/wiki/Electronic_mailing_list
> 
>   https://en.wikipedia.org/wiki/Google_Groups
> 
> IOW, there is no such think as "this forum".

Your description of the various technologies involved may be correct 
(although you've missed at least one: gmane) but there certainly is such 
a thing as "this forum".

"This forum" is an abstraction of the community and technologies (note 
plural) we are using (comp.lang.python/[email protected]/whatever 
Google Groups calls it) from *other* forums like python-dev mailing list, 
Stackoverflow, #python on Freenode, the various Python-related sub-
reddits, etc.

A forum is not necessarily a single piece of technology controlled at a 
single point. Like the internet itself, forums can be decentralised and 
running on multiple diverse technologies.


> If you want whatever user interface you're using to send postings to
> hold onto them for 15 minutes to allow you a second chance to edit them,
> then you need to talk to whoever maintains the user interface that you
> use to send messages to the Usetnet group or mailing list.

Indeed. The "I've changed my mind, don't send that message" function 
depends on the technology you use to communicate with the forum, not the 
forum.



-- 
Steven D'Aprano
"Ever since I learned about confirmation bias, I've been seeing
it everywhere." -- Jon Ronson

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


OFF-TOPIC Good sig [was Re: What is the "Unpacking Arguments List" rule?]

2018-06-13 Thread Steven D'Aprano
On Wed, 13 Jun 2018 12:43:12 +, Alister via Python-list wrote:

> I have a theory that it's impossible to prove anything, but I can't
> prove it.

Heh, that reminds me of Stephen Pinker's comment from "Enlightenment Now":

"one cannot reason that there's no such thing as reason"

but on the other hand, Kurt Gödel successfully proved using mathematics 
that (sufficiently powerful) maths is either inconsistent or incomplete, 
and we can never tell which. In a sense, Gödel proved that it is 
impossible to prove *certain* things which are true, or disprove some 
which are false, but we have no way of proving which are which.



-- 
Steven D'Aprano
"Ever since I learned about confirmation bias, I've been seeing
it everywhere." -- Jon Ronson

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


Re: PEP8 compliance

2018-06-13 Thread Marko Rauhamaa
[email protected] (Stefan Ram):

> T Berger  writes:
>>to change my code if it's failed the PEP8 test,
>>what code do I use to open my program and make changes?
>
>   A text editor (emacs, vim, pico, IDLE, notepad, ex, sed, ...).
>   What did you use to write your code in the first place?

This is a hugely important introductory hurdle for beginning
programmers. The Wikipedia page on the topic,

   https://en.wikipedia.org/wiki/Text_editor>

makes the gross mistake of equating a text editor with Microsoft's
Notepad.

In fact, I couldn't find a simple introduction to the topic on the Web.
One shouldn't think the term is obvious to beginning programmers because
they probably don't understand that "text editor" refers to a very
specific, hard-to-explain kind of a tool.

Maybe, before you try to explain what a text editor is, you should try
to explain what "text" is. For that you have to start explaining the
organization of information, "characters" and integers as sequences of
bits, and bits as disturbances in the force...


Marko

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


Re: PEP8 compliance

2018-06-13 Thread T Berger
On Wednesday, June 13, 2018 at 11:04:39 AM UTC-4, T Berger wrote:
> Sorry for this basic question, but to change my code if it's failed the PEP8 
> test, what code do I use to open my program and make changes? Obviously, I 
> should still be in bash, but then what?
> 
> Thanks,
> 
> Tamara

I did make the changes in IDLE, but I thought I must be in the wrong place. The 
line of code I got in terminal was:
/Users/TamaraB/Desktop/mymodules/vsearch.py:1:25: E231 missing whitespace after 
':'
def search4vowels(phrase:str)->set:

I thought the 1:25: E231 couldn't be referring to anything in my text editor. 
But now I see that 1:25 refers to the first line, 25th spot (I suppose the 25 
refers to the spot BEFORE which I'm supposed to add white space. I don't know 
what the E231 refers to, but it doesn't seem helpful.

And, no, I'm not going to make these picayune changes that actually make the 
code harder to read. Adding a white space between "phrase:" and "str" just 
splits apart a conceptual unit in a complicated line of code. I was just doing 
this exercise in my workbook.

Thanks,

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


What data types does matplotlib pyplot take?

2018-06-13 Thread C W
Hi everyone,

I'm curious what data types pyplot takes. It seems that it can take numpy
series, pandas series, and possibly pandas dataframe? How many people data
types are out there? Is that true for all functions in like hist(), bar(),
line(), etc?

Is there an official documentation that lists this?

I have seen this official documentation:
https://pandas.pydata.org/pandas-docs/stable/visualization.html

But it does not specify data types. I would appreciate it if someone can
point it out.

Thank you!
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to make a button flashing?

2018-06-13 Thread Terry Reedy

On 6/13/2018 7:21 AM, Peter Otten wrote:

[email protected] wrote:



I forgot the syntax of making a button flash, and failed to find an
example in the web. I use Tkinter, to create a button. Then made it
packed, and showed up. Now I am trying to make button b flashing, to make
it get better noticed. I checked the docs, and found a method flash() is
available, then I tried:

b.flash()

there was no error message popped out, but there was nothing happened
also. I wonder who can give me this help? Thanks!



Quoting http://tcl.tk/man/tcl8.6/TkCmd/button.htm#M16

"""
pathName flash
 Flash the button. This is accomplished by redisplaying the button
several times, alternating between the configured activebackground and
background colors. At the end of the flash the button is left in the same
normal/active state as when the command was invoked. This command is ignored
if the button's state is disabled.
"""

So to see something you have to ensure that the two background colors
actually differ. Complete example:

import tkinter as tk
root = tk.Tk()

button = tk.Button(root, text="Hello")
button.pack()

button["activebackground"] = "red"
button["background"] = "silver"

root.after(1000, button.flash)
root.mainloop()


On Windows, this flashes red about 3 time in about .2 seconds and stops. 
 The following repeat the flashing every second, and shows how to stop 
an animation.


import tkinter as tk
root = tk.Tk()

def stop_flash():
print('stop_flash')
root.after_cancel(flasher)

button = tk.Button(root, text="Hello", command=stop_flash,
   background='silver', activebackground='red')
button.pack()

def flash():
global flasher
button.flash()
flasher = root.after(1000, flash)

flasher = root.after(1000, flash)
root.mainloop()



--
Terry Jan Reedy

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


Re: PEP8 compliance

2018-06-13 Thread Rick Johnson
On Wednesday, June 13, 2018 at 10:47:40 AM UTC-5, Steven D'Aprano wrote:
 
> I'm of two minds here... 

Obviously.

> [...] So use your own judgement: if following PEP 8 becomes
> a chore, or if you would rather follow your own style,
> don't feel guilty about ignoring the style guide.

IOWs: 

  "Be consistent!" 

  "Except, when you don't want to be."

  "Although, it might be a good idea to be."

  "Hmm. Well. Maybe not.

  "Who knows!"

Great advice Steven. 

Great advice.

> "Ever since I learned about confirmation bias, I've been
> seeing it everywhere." -- Jon Ronson

I'm glad to see you've chosen a new foot quote, because as
opposed to the previous one, this is _actually_ funny.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: PEP8 compliance

2018-06-13 Thread Terry Reedy

On 6/13/2018 12:35 PM, T Berger wrote:


I did make the changes in IDLE, but I thought I must be in the wrong place.


This is a good place for beginners.


The line of code I got in terminal was:
/Users/TamaraB/Desktop/mymodules/vsearch.py:1:25: E231 missing whitespace after 
':'
def search4vowels(phrase:str)->set:


The recommended style is

def search4vowels(phrase: str) -> set:


I thought the 1:25: E231 couldn't be referring to anything in my text editor. 
But now I see that 1:25 refers to the first line, 25th spot (I suppose the 25 
refers to the spot BEFORE which I'm supposed to add white space.


25 is the slice position between ':' and 's', where a new space would go.


I don't know what the E231 refers to, but it doesn't seem helpful.


It is an arbitrary label.  You can probably use it to look up the 'error'.


And, no, I'm not going to make these picayune changes that actually make the code harder to read. 
Adding a white space between "phrase:" and "str" just splits apart a conceptual 
unit in a complicated line of code. I was just doing this exercise in my workbook.


*I* happen to prefer the spaced-out version, but I also prefer that 
people do what they want, especially in private code.  You should also 
able to use E231 to tell pep8 to not report E231s (because you disagree 
with the recommendation).


--
Terry Jan Reedy

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


Re: Regex to extract multiple fields in the same line

2018-06-13 Thread Ganesh Pal
On Wed, Jun 13, 2018 at 5:59 PM, Rhodri James  wrote:

> On 13/06/18 09:08, Ganesh Pal wrote:
>
>>   Hi Team,
>>
>> I wanted to parse a file and extract few feilds that are present after "="
>> in a text file .
>>
>>
>> Example , form  the below line I need to extract the values present after
>> --struct =, --loc=, --size= and --log_file=
>>
>> Sample input
>>
>> line = '06/12/2018 11:13:23 AM python toolname.py  --struct=data_block
>> --log_file=/var/1000111/test18.log --addr=None --loc=0 --mirror=10
>> --path=/tmp/data_block.txt size=8'
>>
>
> Did you mean "--size=8" at the end?  That's what your explanation implied.




Yes James you got it right ,  I  meant  "--size=8 " .,


Hi Team,


I played further with python's re.findall()  and  I am able to extract all
the required  fields , I have 2 further questions too , please suggest


Question 1:

 Please let me know  the mistakes in the below code and  suggest if it  can
be optimized further with better regex


# This code has to extract various the fields  from a single line (
assuming the line is matched here ) of a log file that contains various
values (and then store the extracted values in a dictionary )

import re

line = '06/12/2018 11:13:23 AM python toolname.py  --struct=data_block
--log_file=/var/1000111/test18.log --addr=None --loc=0 --mirror=10
--path=/tmp/data_block.txt --size=8'

#loc is an number
r_loc = r"--loc=([0-9]+)"
r_size = r'--size=([0-9]+)'
r_struct = r'--struct=([A-Za-z_]+)'
r_log_file = r'--log_file=([A-Za-z0-9_/.]+)'


if re.findall(r_loc, line):
   print re.findall(r_loc, line)

if re.findall(r_size, line):
   print re.findall(r_size, line)

if re.findall(r_struct, line):
   print re.findall(r_struct, line)

if re.findall(r_log_file, line):
   print re.findall(r_log_file, line)


o/p:
root@X1:/Play_ground/SPECIAL_TYPES/REGEX# python regex_002.py
['0']
['8']
['data_block']
['/var/1000111/test18.log']


Question 2:

I  tried to see if I can use  re.search with look behind assertion , it
seems to work , any comments or suggestions

Example:

import re

line = '06/12/2018 11:13:23 AM python toolname.py  --struct=data_block
--log_file=/var/1000111/test18.log --addr=None --loc=0 --mirror=10
--path=/tmp/data_block.txt --size=8'

match = re.search(r'(?P(?<=--loc=)([0-9]+))', line)
if match:
   print match.group('loc')


o/p: root@X1:/Play_ground/SPECIAL_TYPES/REGEX# python regex_002.py

0


I  want to build  the sub patterns and use match.group() to get the values
, some thing as show below but it doesn't seem to work


match = re.search(r'(?P(?<=--loc=)([0-9]+))'
  r'(?P(?<=--size=)([0-9]+))', line)
if match:
   print match.group('loc')
   print match.group('size')

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


Matplotlib and Python 3.7

2018-06-13 Thread BlindAnagram
Now that Python 3.7 has reached release candidate status, I thought that
I should try it.  But I use Matplotlib a lot and this fails to install
with Python 3.7 because "freetype and png cannot be installed" (I am
using Windows 10).

I am wondering if anyone knows how to work around this issue?

I looked for a way to report the issue to the Matplotlib team but the
only forum I could find for reporting issues required me to create an
account, which I don't want to do.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: PEP8 compliance

2018-06-13 Thread Paul Moore
On 13 June 2018 at 17:35, T Berger  wrote:

> I did make the changes in IDLE, but I thought I must be in the wrong place. 
> The line of code I got in terminal was:
> /Users/TamaraB/Desktop/mymodules/vsearch.py:1:25: E231 missing whitespace 
> after ':'
> def search4vowels(phrase:str)->set:
>
> I thought the 1:25: E231 couldn't be referring to anything in my text editor. 
> But now I see that 1:25 refers to the first line, 25th spot (I suppose the 25 
> refers to the spot BEFORE which I'm supposed to add white space. I don't know 
> what the E231 refers to, but it doesn't seem helpful.

That's the correct interpretation of that message. Well done (and I
don't mean that patronisingly) - messages from tools like whatever it
was that reported these errors to you are often rooted in assumptions
which are *far* from obvious to someone new to programming.

To expand a little:

The 1 is as you say the line on which the tool spotted the problem.
Program text is viewed (by tools just as by people) as a block of
lines of text, numbered starting from line 1. Tools will number blank
lines (lines with nothing on them) equally with lines with text on
them - sometimes people number only the non-blank lines, but
programming tools don't typically do that.

The 25 does refer to the position on the line that the tool is
referring to. Position is measured in characters. You say "spot", and
that's as good a term as any. Characters as counted by a computer
include letters, numbers, punctuation, and even spaces. You can think
of it as "column on the screen" in this case and not be far wrong.

The E231 is a code for the specific error that the tool found - so it
means "missing whitespace". The text of the message is all you need to
deal with, but having a unique, concise code can help, for example
when looking up information in the documentation or the source code of
the tool. It's very helpful to quote error numbers like this when
reporting problems or asking for help, as they are more precise (to
people who know how to interpret them) than the textual message. But
reporting the text as well is crucial, as it saves people having to
look up the code to know what you're talking about!

> And, no, I'm not going to make these picayune changes that actually make the 
> code harder to read. Adding a white space between "phrase:" and "str" just 
> splits apart a conceptual unit in a complicated line of code. I was just 
> doing this exercise in my workbook.

That's a very good attitude. There *are* good reasons for many of the
style recommendations, and as you learn more you may be persuaded to
change your view, but style guides are all ultimately about making
your code "readable", and it sounds like you are already developing a
good sense of how you want to group and present your code. That's
something many programmers can take a long time (years, in some cases)
to develop, and a good sense of style is often (IMO) what separates
good programmers from mediocre/bad ones. Reading other people's code
is often a very good way to develop a sense of style, if you get the
chance to do so.

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


ANN: A new version (0.4.3) of python-gnupg has been released. It contains a security-related change - please update to this version

2018-06-13 Thread Vinay Sajip via Python-list
A new version of the Python module which wraps GnuPG has been released.
What Changed?=This is a security-fix release, and all users are 
strongly encouraged to upgrade.This fix mitigates against CVE-2018-12020. See 
the discoverer's blog post [6] formore information.
Brief summary:

* Added --no-verbose to the gpg command line, in case verbose is specified in  
gpg.conf - we don't need verbose output.
This release [2] has been signed with my code signing key:
Vinay Sajip (CODE SIGNING KEY) Fingerprint: CA74 
9061 914E AC13 8E66 EADB 9147 B477 339A 9B86
Recent changes to PyPI don't show the GPG signature with the download links.An 
alternative download source where the signatures are available is the 
project'sown downloads page [5].
What Does It Do?The gnupg module allows Python programs to make 
use of thefunctionality provided by the Gnu Privacy Guard (abbreviated GPG 
orGnuPG). Using this module, Python programs can encrypt and decryptdata, 
digitally sign documents and verify digital signatures, manage(generate, list 
and delete) encryption keys, using proven Public KeyInfrastructure (PKI) 
encryption technology based on OpenPGP.
This module is expected to be used with Python versions >= 2.4, as itmakes use 
of the subprocess module which appeared in that version ofPython. This module 
is a newer version derived from earlier work byAndrew Kuchling, Richard Jones 
and Steve Traugott.
A test suite using unittest is included with the source distribution.
Simple usage:
>>> import gnupg>>> gpg = gnupg.GPG(gnupghome='/path/to/keyring/directory')>>> 
>>> gpg.list_keys()
[{...'fingerprint': 'F819EE7705497D73E3CCEE65197D5DAC68F1AAB2','keyid': 
'197D5DAC68F1AAB2','length': '1024','type': 'pub','uids': ['', 'Gary Gross (A 
test user) ']},{...'fingerprint': 
'37F24DD4B918CC264D4F31D60C5FEFA7A921FC4A','keyid': 
'0C5FEFA7A921FC4A','length': '1024',...'uids': ['', 'Danny Davis (A test user) 
']}]>>> encrypted = gpg.encrypt("Hello, world!", 
['0C5FEFA7A921FC4A'])>>> str(encrypted)
'-BEGIN PGP MESSAGE-\nVersion: GnuPG v1.4.9 
(GNU/Linux)\n\nhQIOA/6NHMDTXUwcEAf.-END PGP MESSAGE-\n'>>> decrypted = 
gpg.decrypt(str(encrypted), passphrase='secret')>>> str(decrypted)
'Hello, world!'>>> signed = gpg.sign("Goodbye, world!", passphrase='secret')>>> 
verified = gpg.verify(str(signed))>>> print "Verified" if verified else "Not 
verified"
'Verified'
As always, your feedback is most welcome (especially bug reports [3],patches 
and suggestions for improvement, or any other points via themailing 
list/discussion group [4]).
Enjoy!
Cheers
Vinay SajipRed Dove Consultants Ltd.
[1] https://bitbucket.org/vinay.sajip/python-gnupg[2] 
https://pypi.python.org/pypi/python-gnupg/0.4.3[3] 
https://bitbucket.org/vinay.sajip/python-gnupg/issues[4] 
https://groups.google.com/forum/#!forum/python-gnupg[5] 
https://bitbucket.org/vinay.sajip/python-gnupg/downloads/[6] 
https://neopg.io/blog/gpg-signature-spoof/
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: OFF-TOPIC Good sig [was Re: What is the "Unpacking Arguments List" rule?]

2018-06-13 Thread Ian Kelly
On Wed, Jun 13, 2018 at 10:10 AM Steven D'Aprano
 wrote:
>
> On Wed, 13 Jun 2018 12:43:12 +, Alister via Python-list wrote:
>
> > I have a theory that it's impossible to prove anything, but I can't
> > prove it.
>
> Heh, that reminds me of Stephen Pinker's comment from "Enlightenment Now":
>
> "one cannot reason that there's no such thing as reason"
>
> but on the other hand, Kurt Gödel successfully proved using mathematics
> that (sufficiently powerful) maths is either inconsistent or incomplete,
> and we can never tell which. In a sense, Gödel proved that it is
> impossible to prove *certain* things which are true, or disprove some
> which are false, but we have no way of proving which are which.

I'm not an expert, but my understanding of the Second Incompleteness
Theorem is that a consistent, sufficiently powerful formal system
cannot prove its own consistency. It doesn't mean that we can't prove
it in some other way.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Regex to extract multiple fields in the same line

2018-06-13 Thread MRAB

On 2018-06-13 18:32, Ganesh Pal wrote:

On Wed, Jun 13, 2018 at 5:59 PM, Rhodri James  wrote:


On 13/06/18 09:08, Ganesh Pal wrote:


  Hi Team,

I wanted to parse a file and extract few feilds that are present after "="
in a text file .


Example , form  the below line I need to extract the values present after
--struct =, --loc=, --size= and --log_file=

Sample input

line = '06/12/2018 11:13:23 AM python toolname.py  --struct=data_block
--log_file=/var/1000111/test18.log --addr=None --loc=0 --mirror=10
--path=/tmp/data_block.txt size=8'



Did you mean "--size=8" at the end?  That's what your explanation implied.


Yes James you got it right ,  I  meant  "--size=8 " .,

Hi Team,

I played further with python's re.findall()  and  I am able to extract all
the required  fields , I have 2 further questions too , please suggest

Question 1:

  Please let me know  the mistakes in the below code and  suggest if it  can
be optimized further with better regex


# This code has to extract various the fields  from a single line (
assuming the line is matched here ) of a log file that contains various
values (and then store the extracted values in a dictionary )

import re

line = '06/12/2018 11:13:23 AM python toolname.py  --struct=data_block
--log_file=/var/1000111/test18.log --addr=None --loc=0 --mirror=10
--path=/tmp/data_block.txt --size=8'

#loc is an number
r_loc = r"--loc=([0-9]+)"
r_size = r'--size=([0-9]+)'
r_struct = r'--struct=([A-Za-z_]+)'
r_log_file = r'--log_file=([A-Za-z0-9_/.]+)'



Here you're searching for each match _twice_:


if re.findall(r_loc, line):
print re.findall(r_loc, line)

if re.findall(r_size, line):
print re.findall(r_size, line)

if re.findall(r_struct, line):
print re.findall(r_struct, line)

if re.findall(r_log_file, line):
print re.findall(r_log_file, line)


o/p:
root@X1:/Play_ground/SPECIAL_TYPES/REGEX# python regex_002.py
['0']
['8']
['data_block']
['/var/1000111/test18.log']


Question 2:

I  tried to see if I can use  re.search with look behind assertion , it
seems to work , any comments or suggestions

Example:

import re

line = '06/12/2018 11:13:23 AM python toolname.py  --struct=data_block
--log_file=/var/1000111/test18.log --addr=None --loc=0 --mirror=10
--path=/tmp/data_block.txt --size=8'

match = re.search(r'(?P(?<=--loc=)([0-9]+))', line)
if match:
print match.group('loc')


o/p: root@X1:/Play_ground/SPECIAL_TYPES/REGEX# python regex_002.py

0


I  want to build  the sub patterns and use match.group() to get the values
, some thing as show below but it doesn't seem to work


match = re.search(r'(?P(?<=--loc=)([0-9]+))'
   r'(?P(?<=--size=)([0-9]+))', line)
if match:
print match.group('loc')
print match.group('size')


You can combine them into a single findall:


captures = 
re.findall(r'--(loc=[0-9]+)|--(size=[0-9]+)|--(struct=[A-Za-z_]+)|--(log_file=[A-Za-z0-9_/.]+)',
 line)
captures
[('', '', 'struct=data_block', ''), ('', '', '', 
'log_file=/var/1000111/test18.log'), ('loc=0', '', '', ''), ('', 
'size=8', '', '')]


In each tuple of the list, there's only one match, the others are empty, 
so get rid of the empty ones:



[c for cap in captures for c in cap if c]


Split each of the matches on the first '=':


[c.split('=', 1) for cap in captures for c in cap if c]


For ease of use, pass the key/value pairs into dict:


info = dict(c.split('=', 1) for cap in captures for c in cap if c)
info
{'struct': 'data_block', 'log_file': '/var/1000111/test18.log', 'loc': 
'0', 'size': '8'}

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


Re: Distributing a Python module as .rpm and .deb packages across major distributions

2018-06-13 Thread adam . preble
On Sunday, June 10, 2018 at 3:05:45 PM UTC-5, Barry wrote:

> The way I learn about the details of RPM packaging is to look at examples 
> like what I wish to achieve.
> 
> I would go get the source RPM for a python2 package from each distro you want 
> to supoort and read its .spec file.
> 
> I see on fedora that the way they install packages that are from pypi makes 
> it possible to use pip list to see them.

The impression I'm getting is that they're using tools to help in this process, 
rather than manually specifying crafting the package descriptors and shell 
scripts. I'd like to do similar, of course, since it sounds like it's a lot 
easier.

I have looked at a few already, which is where I got where I was already. In 
Debian packages I see a lot of references to dh_python, and the regularity of 
it implies the lines in question are being generated--but by what? The source 
packages will have these generated outputs, which means it's already too late 
in the process when it comes to reverse engineering what generated those 
outputs.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: PEP8 compliance

2018-06-13 Thread Chris Angelico
On Thu, Jun 14, 2018 at 1:45 AM, Steven D'Aprano
 wrote:
> On Wed, 13 Jun 2018 08:04:27 -0700, T Berger wrote:
>
>> Sorry for this basic question, but to change my code if it's failed the
>> PEP8 test, what code do I use to open my program and make changes?
>
> Use your text editor to modify the source code of the program.
>
>
> I'm of two minds here... on the one hand, I think that generally
> speaking, PEP 8 is a good style guide to follow, and I think that in the
> long run using a consistent style is a good habit to get into.
>
> On the other hand, some people follow PEP 8 religiously, except for the
> most important rule of all: the one about knowing when to break all the
> other rules. They can get obsessed with following PEP 8 rules even when
> it makes the code *worse*. I don't want to encourage that way of thinking.

... and THIS RIGHT HERE is why the tool should not be called "pep8".
Didn't this exact discussion come up and the tool got renamed? There's
big confusion here between "following PEP 8" (the document) and
"failing the PEP8 test" (the tool).

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


Re: Why exception from os.path.exists()?

2018-06-13 Thread Peter J. Holzer
On 2018-06-13 10:10:03 +0300, Marko Rauhamaa wrote:
> "Peter J. Holzer" :
> > On 2018-06-11 12:24:54 +, Steven D'Aprano wrote:
> >> It also clearly states:
> >> 
> >> All functions in this module raise OSError in the case of
> >> invalid or inaccessible file names and paths, or other
> >> arguments that have the correct type, but are not accepted
> >> by the operating system. 
> >> 
> >> You know... like strings with NUL in them.
> 
> Nice catch!
> 
> > Ok. I missed that. So either the documentation or the implementation
> > should be fixed. 
> >
> > In any case, if the implementation is changed, I still think that
> > OSError(ENOENT) is wrong. It would have to be OSError(None, "embedded
> > null byte"), or, if that is not possible (I haven't checked)
> > OSError(EINVAL, "embedded null byte"), although that is slightly
> > misleading (it implies that the OS returned EINVAL, which it didn't).
> 
> You say "misleading", I say "abstracting".

If I get an error message which leads me on a wild goose chase, I call
that misleading when I'm in a good mood. If I'm feeling cranky, I call
it "lying".


> > The same check for NUL is also in other functions (e.g. open()), so
> > those would have to be changed as well.
> 
> Maybe.

Consistency is a virtue.


> > I wasn't entirely clear here. What I meant is that POSIX systems, as a
> > group, provide no such way.
> 
> I still don't see how POSIX is directly relevant here.

POSIX systems (or more specifically, systems where the Python
implementation uses a POSIX-conforming API to access the file system)
are relevant here because on such systems the Python implementation
needs to treat filenames with an embedded NUL specially.

The reasons have been mentioned several times in this threadm, but to
recap:

1) The API uses nul-terminated byte strings for file names. 
2) Python may also use byte strings for for file names, but they are not
   nul-terminated (they may contain nuls)
3) Simply passing a pointer to the start of a python byte string to the
   OS seems to work, and is therefore tempting.
4) But this would mean the OS gets a different file name than the
   application passed to it if the name contains NUL, which can lead to
   security holes (this isn't theoretical, it has happened)
5) Therefore an implemntation must not succumb to the tempation in point 
   3 and must explicitely check for NULs.

A theoretical Python implementation on MacOS using the Carbon API
wouldn't have to do this (and in fact it shouldn't). This is
system-dependent code ensuring that the OS API is called correctly.

For os.stat() POSIX is further relevant because stat() is a POSIX
function. On POSIX systems, os.stat() is just a very thin wrapper around
the syscall. On other systems, POSIX stat is basically emulated by
invoking other system calls.

A user on a POSIX system should therefore expect the result of os.stat()
be the same as that of the stat() system call (i.e. if successful the
fields should have the same values and if not, the exception should
reflect the errno returned by the OS). On other systems a user can only
expect a rough correspondence between what the actual system call
returned and what os.stat() returns, because there may not be a simple
1:1 mapping.

POSIX specifies a number of error codes which can be returned by stat():

[EACCES]
Search permission is denied for a component of the path prefix.
[EIO]
An error occurred while reading from the file system.
[ELOOP]
A loop exists in symbolic links encountered during resolution of the
path argument.
[ENAMETOOLONG]
The length of a component of a pathname is longer than {NAME_MAX}.
[ENOENT]
A component of path does not name an existing file or path is an
empty string.
[ENOTDIR]
A component of the path prefix names an existing file that is
neither a directory nor a symbolic link to a directory, or the path
argument contains at least one non-  character and ends with
one or more trailing  characters and the last pathname
component names an existing file that is neither a directory nor a
symbolic link to a directory.
[EOVERFLOW]
The file size in bytes or the number of blocks allocated to the file
or the file serial number cannot be represented correctly in the
structure pointed to by buf. 

A Python application may want to treat these errors differently. Even if
the application doesn't, the user reading the stack trace will want to
see the correct errno and not some generic "something went wrong"
message.

Note that none of these covers "file name contains an illegal character"
for the simple reason that on POSIX systems there are no illegal
characters. 

So none of these is a good choice for the errno parameter of an OSError
to be thrown. One might try to find out what Linux returns on a
filesystem which doesn't allow some characters, but that would be Linux
specific and probably even file system specific, so not a good choice
for a situation whi

Re: Why exception from os.path.exists()?

2018-06-13 Thread Peter J. Holzer
On 2018-06-11 14:23:42 +0300, Marko Rauhamaa wrote:
> "Peter J. Holzer" :
> > On 2018-06-11 01:06:37 +, Steven D'Aprano wrote:
> >> Baking a limitation of some file systems into the high-level
> >> interface is simply a *bad idea*.
> >
> > We aren't talking about a high-level interface here.
> 
> Call it high-level or not, we *are* talking about an interface
> ("os.path") whose whole raison d'être is abstracting OS specifics from
> basic pathname processing.

I can understand that Stephen missed the fact that we were talking about
os.stat, not os.path. But how could you miss that? It was you who
brought up os.stat and I was just replying to your message. Please try
to keep track of what you are talking about, otherwise discussions will
not be very productive.


> > You are barking up the wrong tree here.
> 
> I believe the "wrong tree" would want a ValueError to be raised in this
> situation.

Nope. The wrong tree is os.path, when we are talking about os.stat.

hp

-- 
   _  | Peter J. Holzer| we build much bigger, better disasters now
|_|_) || because we have much more sophisticated
| |   | [email protected] | management tools.
__/   | http://www.hjp.at/ | -- Ross Anderson 


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


Re: Regex to extract multiple fields in the same line

2018-06-13 Thread Friedrich Rentsch




On 06/13/2018 07:32 PM, Ganesh Pal wrote:

On Wed, Jun 13, 2018 at 5:59 PM, Rhodri James  wrote:


On 13/06/18 09:08, Ganesh Pal wrote:


   Hi Team,

I wanted to parse a file and extract few feilds that are present after "="
in a text file .


Example , form  the below line I need to extract the values present after
--struct =, --loc=, --size= and --log_file=

Sample input

line = '06/12/2018 11:13:23 AM python toolname.py  --struct=data_block
--log_file=/var/1000111/test18.log --addr=None --loc=0 --mirror=10
--path=/tmp/data_block.txt size=8'


Did you mean "--size=8" at the end?  That's what your explanation implied.

How's this? (Supposing that the values contain no spaces):

>>> regex = re.compile 
(r"--(struct|loc|size|mirror|log_file)\s*=\s*([^\s]+)")

>>> regex.findall (line)
[('struct', 'data_block'), ('log_file', '/var/1000111/test18.log'), 
('loc', '0'), ('mirror', '10')]


Frederic








Yes James you got it right ,  I  meant  "--size=8 " .,


Hi Team,


I played further with python's re.findall()  and  I am able to extract all
the required  fields , I have 2 further questions too , please suggest


Question 1:

  Please let me know  the mistakes in the below code and  suggest if it  can
be optimized further with better regex


# This code has to extract various the fields  from a single line (
assuming the line is matched here ) of a log file that contains various
values (and then store the extracted values in a dictionary )

import re

line = '06/12/2018 11:13:23 AM python toolname.py  --struct=data_block
--log_file=/var/1000111/test18.log --addr=None --loc=0 --mirror=10
--path=/tmp/data_block.txt --size=8'

#loc is an number
r_loc = r"--loc=([0-9]+)"
r_size = r'--size=([0-9]+)'
r_struct = r'--struct=([A-Za-z_]+)'
r_log_file = r'--log_file=([A-Za-z0-9_/.]+)'


if re.findall(r_loc, line):
print re.findall(r_loc, line)

if re.findall(r_size, line):
print re.findall(r_size, line)

if re.findall(r_struct, line):
print re.findall(r_struct, line)

if re.findall(r_log_file, line):
print re.findall(r_log_file, line)


o/p:
root@X1:/Play_ground/SPECIAL_TYPES/REGEX# python regex_002.py
['0']
['8']
['data_block']
['/var/1000111/test18.log']


Question 2:

I  tried to see if I can use  re.search with look behind assertion , it
seems to work , any comments or suggestions

Example:

import re

line = '06/12/2018 11:13:23 AM python toolname.py  --struct=data_block
--log_file=/var/1000111/test18.log --addr=None --loc=0 --mirror=10
--path=/tmp/data_block.txt --size=8'

match = re.search(r'(?P(?<=--loc=)([0-9]+))', line)
if match:
print match.group('loc')


o/p: root@X1:/Play_ground/SPECIAL_TYPES/REGEX# python regex_002.py

0


I  want to build  the sub patterns and use match.group() to get the values
, some thing as show below but it doesn't seem to work


match = re.search(r'(?P(?<=--loc=)([0-9]+))'
   r'(?P(?<=--size=)([0-9]+))', line)
if match:
print match.group('loc')
print match.group('size')

Regards,
Ganesh


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


Re: Why exception from os.path.exists()?

2018-06-13 Thread Marko Rauhamaa
"Peter J. Holzer" :

> POSIX specifies a number of error codes which can be returned by stat():
>
> [EACCES]
> Search permission is denied for a component of the path prefix.
> [EIO]
> An error occurred while reading from the file system.
> [ELOOP]
> A loop exists in symbolic links encountered during resolution of the
> path argument.
> [ENAMETOOLONG]
> The length of a component of a pathname is longer than {NAME_MAX}.
> [ENOENT]
> A component of path does not name an existing file or path is an
> empty string.
> [ENOTDIR]
> A component of the path prefix names an existing file that is
> neither a directory nor a symbolic link to a directory, or the path
> argument contains at least one non-  character and ends with
> one or more trailing  characters and the last pathname
> component names an existing file that is neither a directory nor a
> symbolic link to a directory.
> [EOVERFLOW]
> The file size in bytes or the number of blocks allocated to the file
> or the file serial number cannot be represented correctly in the
> structure pointed to by buf. 
>
> [...]
>
> Note that none of these covers "file name contains an illegal character"
> for the simple reason that on POSIX systems there are no illegal
> characters.
>
> So none of these is a good choice for the errno parameter of an OSError
> to be thrown.

The natural errno value would be EINVAL, which is returned whenever a
system call is invoked with an illegal argument.


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


Django-hotsauce 1.0 LTS (Commercial Edition) now available for preorder!!

2018-06-13 Thread Etienne Robillard

Dear all,

It is my pleasure to announce the availability of Django-hotsauce 1.0 
LTS (Commercial Edition) for preorder:


https://www.livestore.ca/product/django-hotsauce/

Purchase this gem using Paypal before October 1st 2018 with the discount 
code "djangohotsauce" and get 50% off the regular price!


Everyone who will make this purchase will receive their registered copy 
of Django-hotsauce 1.0 on October 1st 2018.


One more thing, this discount code also works for all commercial 
softwares listed on livestore.ca! :)



Have fun!!

Etienne


--
Etienne Robillard
[email protected]
https://www.isotopesoftware.ca/

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


Re: Why exception from os.path.exists()?

2018-06-13 Thread Peter J. Holzer
On 2018-06-13 23:56:09 +0300, Marko Rauhamaa wrote:
> "Peter J. Holzer" :
> > POSIX specifies a number of error codes which can be returned by stat():
[...]
> > So none of these is a good choice for the errno parameter of an OSError
> > to be thrown.
> 
> The natural errno value would be EINVAL, which is returned whenever a
> system call is invoked with an illegal argument.

And you present it like it's a new idea, after I have already discussed
the pros and cons of that twice (the second time in the very message you
just replied to, except that decided to not quote that part but some
other part ...)

hp

-- 
   _  | Peter J. Holzer| we build much bigger, better disasters now
|_|_) || because we have much more sophisticated
| |   | [email protected] | management tools.
__/   | http://www.hjp.at/ | -- Ross Anderson 


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


Re: Design of my project

2018-06-13 Thread Cameron Simpson

On 13Jun2018 15:23, Fabien LUCE  wrote:

Here is a small picture of my project.
I'd like to fetch several datas from a website representing races results.
Each line of the result contains rank, runner's name and other attributes
of the runner (like club etc...).
For now I have created 2 classes (Race and Runner).
Methods of Race allow me to fetch datas on the www thanks to beautifulsoup
module.I instanciate a race at the beginning of the scan and for each line
I instanciate a Runner.
I want to store all those information in a database (for both Race and
Runner), but here is the point, I have the feeling, on a programming
elegance point of view, that I have to separate methods that fetch from
method that store and also have a kind of superior object that controls
those 2 features.
Moreover fetching will interact with storage: if race is already in
database, no need to fetch again.
How should I "design" this? Should I have only (despite my first
impression) one class and all the methods in it? Should I create a parent
class along with 2 childrens that manage the two kind of methods?
Is there a design pattern for this?


My inclination would be to start by providing a class which "wraps" your Race 
database table, and presents it as a mapping.


Something along the lines of:

 class RaceTable:
   def __init__(self, database_connection, table_name):
 self.conn = database_connection
 self.table_name = table_name
   def __contains__(self, race_id):
 ... do SQL to see if the race_id is already present, return True or False
   def __getitem__(self, race_id):
 ... do SQL to fetch a Race row from the table and return it ...
   def __setitem__(self, race_id, race_info):
 ... do SQL to store race_info in the table ...

The special __foo__ methods (called "dunder" methods in the Puython world 
because of the "double underscore") are what make the class look like a Python 
"dict" from outside: when you perform a mapping method like "value in x" or 
"x[key] = value", Python calls x.__contains__ or x.__setitem__ for you.


Look up "Emulating Container Types" here:

 https://docs.python.org/3/reference/datamodel.html#emulating-container-types

That will show you how to write a class like the above example to implement a 
"maping" interface. You don't need to implement everything, just what you need.  
The example above only implements 3 methods.


Then your outer code can look a bit like:

 race_store = RaceTable(database_connection, 'race_table_name_here')
 ...
 if race_id in race_store:
   ... mention that this race_id is already stored ...
 else:
   race_store[race_id] = race_info

So the objective here is a simple class that makes it easy to talk about where 
your information is stored in nice Pythonic terms, and which hides the details 
of database access - that lets you talk about the data in a sensbile and clear 
way outside the storage class, and also leaves scrope for changing the storage 
mechanism later without changing the main code (eg from a conventional SQL 
database to some other service).


Cheers,
Cameron Simpson 
--
https://mail.python.org/mailman/listinfo/python-list


Re: What is the "Unpacking Arguments List" rule?

2018-06-13 Thread Jach Fong

Alister via Python-list at 2018/6/13 PM 08:43 wrote:

IMHO, there is no reason to check the *args has to appear at last in
positional argument list in a function call because of there is no
"unknown number of parameters" at the time of unpacking. It should be
alright to write line 19
  action(*args, progress)


Anyone wanting to write such code should be banned form ever accessing a
computer.


Won't it be too hard to this guy:-)


if you know how many arguments are going to be passed to match the *args
part of this function then they should be assigned known variables
otherwise the code will soon become an unmanageable mess.


I think it's depend on the situation.


this is why the language specifications states it should only appear
after all known positional arguments have been declared


To a function call, where the spec is?

--Jach

---
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus

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


Re: How to make a button flashing?

2018-06-13 Thread huey . y . jiang
On Wednesday, June 13, 2018 at 5:23:17 PM UTC+8, [email protected] wrote:
> Hi All,
> 
> I forgot the syntax of making a button flash, and failed to find an example 
> in the web. I use Tkinter, to create a button. Then made it packed, and 
> showed up. Now I am trying to make button b flashing, to make it get better 
> noticed. I checked the docs, and found a method flash() is available, then I 
> tried:
> 
> b.flash()
> 
> there was no error message popped out, but there was nothing happened also. I 
> wonder who can give me this help? Thanks!
> 
> Huey

Thanks, Terry, it works!
-- 
https://mail.python.org/mailman/listinfo/python-list


mutable sequences

2018-06-13 Thread Sharan Basappa
The term mutable appears quite often in Python.
Can anyone explain what is meant by mutable and immutable sequences.

For example, Python lists are mutable.

BTW, is the below explanation correct (it is taken from a book I am reading)

Python lists are mutable sequences. They are very similar to tuples, but they
don't have the restrictions due to immutability.

It says lists are mutable and then says they are immutable???

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


How to find an object existing?

2018-06-13 Thread huey . y . jiang
Hi All,

root = Tkinter.Tk()
button = Tkinter.Button(root, text="Find me")
button.pack()

I created a button, Python object. I recall I can check this object existing by 
using   winfo, such as  winfo.exists(button). However, I forgot which super 
class contains this   winfo   method.  I printed out dir(os), dir(sys), 
dir(Tkinter), but did not find this winfo method. I wonder who will be kindly 
drop down a few lines? Thanks a lot!


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


Re: mutable sequences

2018-06-13 Thread Jim Lee



On 06/13/2018 07:56 PM, Sharan Basappa wrote:

The term mutable appears quite often in Python.
Can anyone explain what is meant by mutable and immutable sequences.

Mutable means changeable, and immutible means not mutable, or unchangeable.

For example, Python lists are mutable.

BTW, is the below explanation correct (it is taken from a book I am reading)

Python lists are mutable sequences. They are very similar to tuples, but they
don't have the restrictions due to immutability.

It says lists are mutable and then says they are immutable???

  You have come across a pet-peeve of mine.  The current crop of 
technical books are categorically inferior to those published in the 
past.   There seems to be little to no proofreading involved before 
publication, and the authors' grammar is no better than what we see in 
casual, off-the-cuff email.  You have shown us a prime example of 
email-speak being published as a finished work.  The author states (if 
one assumes that his grammar is correct) that immutability is what gives 
lists an advantage over tuples.  This is simply wrong due to poor 
grammar.   What the author *intended* to say is that lists don't suffer 
from the restrictions placed on tuples - i.e. immutability.  In other 
words, lists are mutable, tuples are immutable.  Try to find a better 
book - which is difficult to do these days.


-Jim


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


Re: mutable sequences

2018-06-13 Thread Chris Angelico
On Thu, Jun 14, 2018 at 12:56 PM, Sharan Basappa
 wrote:
> The term mutable appears quite often in Python.
> Can anyone explain what is meant by mutable and immutable sequences.
>
> For example, Python lists are mutable.
>
> BTW, is the below explanation correct (it is taken from a book I am reading)
>
> Python lists are mutable sequences. They are very similar to tuples, but they
> don't have the restrictions due to immutability.
>
> It says lists are mutable and then says they are immutable???

Lists are indeed mutable. Since they are mutable, they do not have the
restrictions of immutability, which is the state of NOT being mutable.

So what does "mutable" mean? It means the thing can be changed, while
still being itself. It has an identity, and a value, and you can
change the value. If you have a shopping list, it has certain items on
it - you need eggs, milk, bacon, and broccoli - and if you remove
broccoli from the list (seriously, you don't need it), the list is
still that same list.

In contrast, the number 5 is immutable. It is the number 5. It cannot
be any other number and still somehow be "itself". If you add 1 to it,
you now have a different number - you have 6 instead. Numbers are
immutable.

A tuple is like a group of values. For instance, the location (3,4)
can be represented as a tuple. It's immutable in the same way that
numbers are; the position (3,4) is different from the position (6,8)
and it's a completely different "thing".

I'm massively simplifying, but that should give you some idea of what
(im)mutability is.

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


Re: mutable sequences

2018-06-13 Thread Ben Finney
Sharan Basappa  writes:

> For example, Python lists are mutable.

Yes, that's correct.

> BTW, is the below explanation correct (it is taken from a book I am
> reading)
>
> Python lists are mutable sequences. They are very similar to tuples,
> but they don't have the restrictions due to immutability.
>
> It says lists are mutable and then says they are immutable???

The passage is correct, but is ambiguously phrased.

You appear to be parsing it as:

Python lists are mutable sequences. They are very similar to tuples,
but {{they don't have the restrictions} due to immutability}.

which would imply that Python lists are both mutable and are immutable.

Instead, I think the intended parsing is:

Python lists are mutable sequences. They are very similar to tuples,
but {they don't have {the restrictions due to immutability}}.

implying that Python lists are mutable; and then contrasting lists
against Python tuples which have “the restrictions due to immutability”.

Does that help?

You might send the publisher a request to clarify the text in a future
edition.

-- 
 \   “To have the choice between proprietary software packages, is |
  `\  being able to choose your master. Freedom means not having a |
_o__)master.” —Richard M. Stallman, 2007-05-16 |
Ben Finney

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


Re: python lmfit.minimizer not working

2018-06-13 Thread dieter
Priya Singh  writes:

> Dear All,
>
> I am trying to fit a spectrum using a power law model. I am using 
> lmfit.minimizer.

You are asking a question about a specific module ("lmfit") not part
of the Python standard library. You might get better help from
a different audience (one closer to "lmfit", maybe its authors).
I, for example, do not know "lmfit" at all.

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


Re: How to find an object existing?

2018-06-13 Thread dieter
[email protected] writes:
> root = Tkinter.Tk()
> button = Tkinter.Button(root, text="Find me")
> button.pack()
>
> I created a button, Python object. I recall I can check this object existing 
> by using   winfo, such as  winfo.exists(button). However, I forgot which 
> super class contains this   winfo   method.  I printed out dir(os), dir(sys), 
> dir(Tkinter), but did not find this winfo method. I wonder who will be kindly 
> drop down a few lines? Thanks a lot!

Python is suggesting some naming conventions. Those state, that
classes are using camel-case names. If they are applied, "winfo" is
not a class - but instead either an object (= class/type instance)
or a module.

"winfo" is obviously related to graphical objects (windows, in particular).
This means, you wont find it in "pure" Python. If it exists,
it belongs to "Tkinter".

I would look for "winfo" (or "WInfo" (potentially slightly
differently camel-cased)) in the "Tk[inter]" documentation.

Note, that "Tkinter" is a Python binding for the "tk" library.
If you find something in the "tk" documentation, it is likely
"translated" in a uniform way (to other "tk" objects) for "Tkinter".

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


Re: PEP8 compliance

2018-06-13 Thread T Berger
On Wednesday, June 13, 2018 at 1:44:49 PM UTC-4, Paul  Moore wrote:
> On 13 June 2018 at 17:35, T Berger  wrote:
> 
> > I did make the changes in IDLE, but I thought I must be in the wrong place. 
> > The line of code I got in terminal was:
> > /Users/TamaraB/Desktop/mymodules/vsearch.py:1:25: E231 missing whitespace 
> > after ':'
> > def search4vowels(phrase:str)->set:
> >
> > I thought the 1:25: E231 couldn't be referring to anything in my text 
> > editor. But now I see that 1:25 refers to the first line, 25th spot (I 
> > suppose the 25 refers to the spot BEFORE which I'm supposed to add white 
> > space. I don't know what the E231 refers to, but it doesn't seem helpful.
> 
> That's the correct interpretation of that message. Well done (and I
> don't mean that patronisingly) - messages from tools like whatever it
> was that reported these errors to you are often rooted in assumptions
> which are *far* from obvious to someone new to programming.
> 
> To expand a little:
> 
> The 1 is as you say the line on which the tool spotted the problem.
> Program text is viewed (by tools just as by people) as a block of
> lines of text, numbered starting from line 1. Tools will number blank
> lines (lines with nothing on them) equally with lines with text on
> them - sometimes people number only the non-blank lines, but
> programming tools don't typically do that.
> 
> The 25 does refer to the position on the line that the tool is
> referring to. Position is measured in characters. You say "spot", and
> that's as good a term as any. Characters as counted by a computer
> include letters, numbers, punctuation, and even spaces. You can think
> of it as "column on the screen" in this case and not be far wrong.
> 
> The E231 is a code for the specific error that the tool found - so it
> means "missing whitespace". The text of the message is all you need to
> deal with, but having a unique, concise code can help, for example
> when looking up information in the documentation or the source code of
> the tool. It's very helpful to quote error numbers like this when
> reporting problems or asking for help, as they are more precise (to
> people who know how to interpret them) than the textual message. But
> reporting the text as well is crucial, as it saves people having to
> look up the code to know what you're talking about!
> 
> > And, no, I'm not going to make these picayune changes that actually make 
> > the code harder to read. Adding a white space between "phrase:" and "str" 
> > just splits apart a conceptual unit in a complicated line of code. I was 
> > just doing this exercise in my workbook.
> 
> That's a very good attitude. There *are* good reasons for many of the
> style recommendations, and as you learn more you may be persuaded to
> change your view, but style guides are all ultimately about making
> your code "readable", and it sounds like you are already developing a
> good sense of how you want to group and present your code. That's
> something many programmers can take a long time (years, in some cases)
> to develop, and a good sense of style is often (IMO) what separates
> good programmers from mediocre/bad ones. Reading other people's code
> is often a very good way to develop a sense of style, if you get the
> chance to do so.
> 
> Paul

Thanks, Paul, for your encouraging, informative reply

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


Re: How to find an object existing?

2018-06-13 Thread Christian Gollwitzer

Am 14.06.18 um 05:14 schrieb [email protected]:

root = Tkinter.Tk()
button = Tkinter.Button(root, text="Find me")
button.pack()

I created a button, Python object. I recall I can check this object existing by using   winfo, such as  winfo.exists(button). However, I forgot which super class contains this   winfo   method.  I printed out dir(os), dir(sys), dir(Tkinter), but did not find this winfo method. I wonder who will be kindly drop down a few lines? 
This is due to a bad wrapping of the original Tcl interface of Tk. In 
the original Tcl, "winfo" is not a method of anything, it is a free 
function. In TkInter, all free functions that accept a widget as the 
first parameter were made methods of that widget. Therefore, 
"winfo_exists" is a method of "button", which is logically contorted: 
you are asking an object "do you exist?".


However, since it can be explicitly destroyed, this can still be useful:

>>> import Tkinter
>>> root = Tkinter.Tk()
>>> button = Tkinter.Button(root, text="Find me")
>>> button.pack()
>>> button.winfo_exists()
1
>>> button.destroy()
>>> button.winfo_exists()
0

I am not sure that this is very helpful, though. Usually you don't 
destroy a button yourself, it is done by the destructor when the button 
is deleted, and therefore, winfo_exists() under normal circumstances 
returns true. What are you really trying to achieve?


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


Re: pep8 Re: Posting warning message

2018-06-13 Thread Tamara Berger
Is it possible to do the "linting" after you've written your code but
before you install it for the first time?

Tamara
On Wed, Jun 13, 2018 at 12:30 AM Cameron Simpson  wrote:
>
> On 13Jun2018 00:05, Tamara Berger  wrote:
> >Thanks for the in-depth answer. I'm going to have to read it
> >carefully, with the help of a Python glossary. Some of the terms you
> >use are new to me.
>
> No worries. Just ask if you don't find definitions.
>
> BTW, a "lint" program, or "linter" is a program for reporting on style trivia,
> trivial logic errors like variable used before defined (or never defined, 
> which
> is often a typing error misspelling a variable or function name), and things
> that look like they might be bugs (a common mistake of mine is constructing
> exceptions like logging calls, and one of my linters has found dozens of these
> for me.)
>
> >>or am I supposed to root around for my module and make the edits one by one?
> >
> >I was trying to be amusing and didn't get my point across.
>
> Ah, ok then. Easy for stuff like that to fall flat in email.
>
> >>Finally, no you don't normally root around and change an installed module.
> >>Instead, modify your original copy and reinstall the newer version!
> >
> >What I meant was, do I have to open the file, search for, e.g., colons
> >and insert space after them? These were the sorts of picayune errors
> >picked up by PEP8 on my program. I deliberately omit such spaces when
> >I code because I like to do as little unnecessary work as possible.
> >There is enough repetitive coding as it is. I know some IDEs have word
> >completion suggestion for variables, etc, that the user creates. But
> >I'm practicing in barebones IDLE and that means a lot of extra work.
>
> Regrettably, yes, unless you're using an editor that has autoformatting
> support. Learn typing habits which minimise stuff like that, it saves going
> back later.
>
> I don't use IDEs on the whole, and I don't use an autoformatter for Python. My
> environment tends to be an editor window and a shell to run things from (thus:
> 2 terminals, one running vim and one running a shell).
>
> Training your fingers to do the trivia reflexively helps. And leaving the
> linting until _after_ you've got your code working correctly helps, because 
> you
> aren't changing tasks midstream and you are linting code you've deleted or
> changed :-)
>
> An editor with syntax support can help. I use vi or vim, and its syntax 
> support
> is fairly crude. Two things its does have which I use a lot is autoindent (as
> simple as starting the next line at the same indent as the one I just
> completed) and syntax highlighting, which colours keywords and identifiers and
> strings differently. When you make trivial mistakes like not closing a quote 
> or
> misspelling a keyword or leaving off a colon there is often a visual cue.
>
> Cheers,
> Cameron Simpson 
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: pep8 Re: Posting warning message

2018-06-13 Thread Cameron Simpson

On 14Jun2018 01:34, Tamara Berger  wrote:

Is it possible to do the "linting" after you've written your code but
before you install it for the first time?


Sure. I always do it that way.

Just as you can run your code before you install it, you can lint your code 
beforehand also. In fact, you should be doing both: run and test the code 
_before_ installing it, and also lint it (when you care) and test again 
(because if you made lint changes you want to check they haven't done something 
unwanted).


Cheers,
Cameron Simpson 
--
https://mail.python.org/mailman/listinfo/python-list


Re: How to apply filters to posts

2018-06-13 Thread T Berger
On Tuesday, April 10, 2018 at 1:21:53 AM UTC-4, Chris Angelico wrote:

> I recommend, instead, joining the mailing list:
> 
> https://mail.python.org/mailman/listinfo/python-list

There seem to be two options on the Python-list Information Page.  

* Subscribe to the list (see sections below)
* Send email to [email protected]

Which are you recommending?

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


Re: How to make a button flashing?

2018-06-13 Thread Terry Reedy

On 6/13/2018 8:57 PM, [email protected] wrote:

On Wednesday, June 13, 2018 at 5:23:17 PM UTC+8, [email protected] wrote:

Hi All,

I forgot the syntax of making a button flash, and failed to find an example in 
the web. I use Tkinter, to create a button. Then made it packed, and showed up. 
Now I am trying to make button b flashing, to make it get better noticed. I 
checked the docs, and found a method flash() is available, then I tried:

b.flash()

there was no error message popped out, but there was nothing happened also. I 
wonder who can give me this help? Thanks!

Huey


Thanks, Terry, it works!


I try to always test code before posting ;-).

With different code, you could switch state every 1/2 second or so, like 
a flashing red traffic light.  You might try to do that.


--
Terry Jan Reedy

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


pattern

2018-06-13 Thread Sharan Basappa
Can anyone explain to me the purpose of "pattern" in the line below:

documents.append((w, pattern['class']))

documents is declared as a list as follows:
documents.append((w, pattern['class']))
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Django-hotsauce 1.0 LTS (Commercial Edition) now available for preorder!!

2018-06-13 Thread Jim Lee
I haven't purchased commercial software in decades, so I'm not up on the 
prevailing business model, but I have to ask:


Why would anyone purchase software and then agree to wait 14 weeks for 
it to be delivered?  I can see that model for hardware, where material 
resources are limited and a finite number of product is produced, but 
software?  What's the point?



On 06/13/2018 02:37 PM, Etienne Robillard wrote:

Dear all,

It is my pleasure to announce the availability of Django-hotsauce 1.0 
LTS (Commercial Edition) for preorder:


https://www.livestore.ca/product/django-hotsauce/

Purchase this gem using Paypal before October 1st 2018 with the 
discount code "djangohotsauce" and get 50% off the regular price!


Everyone who will make this purchase will receive their registered 
copy of Django-hotsauce 1.0 on October 1st 2018.


One more thing, this discount code also works for all commercial 
softwares listed on livestore.ca! :)



Have fun!!

Etienne




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


Re: pep8 Re: Posting warning message

2018-06-13 Thread Tamara Berger
On Thu, Jun 14, 2018 at 1:49 AM Cameron Simpson  wrote:

> Just as you can run your code before you install it, you can lint your code
> beforehand also. In fact, you should be doing both: run and test the code
> _before_ installing it, and also lint it (when you care) and test again
> (because if you made lint changes you want to check they haven't done 
> something
> unwanted).

Great. So I'm using three interfaces: in my case, the text editor, the
Python shell, and the UNIX terminal. Is that right?

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


Re: Django-hotsauce 1.0 LTS (Commercial Edition) now available for preorder!!

2018-06-13 Thread Chris Angelico
On Thu, Jun 14, 2018 at 11:07 AM, Jim Lee  wrote:
> I haven't purchased commercial software in decades, so I'm not up on the
> prevailing business model, but I have to ask:
>
> Why would anyone purchase software and then agree to wait 14 weeks for it to
> be delivered?  I can see that model for hardware, where material resources
> are limited and a finite number of product is produced, but software?
> What's the point?
>

For the 50% discount, I presume. If you wait 14 weeks, then buy, then
own, you pay full price.

>From the company's point of view: if the release date is in the future
and ALL the revenue is also in the future, cash flow becomes tricky.
By getting at least _some_ money in advance, they give themselves a
way to pay the bills.

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


Re: How to find an object existing?

2018-06-13 Thread Terry Reedy

On 6/14/2018 1:20 AM, Christian Gollwitzer wrote:

Am 14.06.18 um 05:14 schrieb [email protected]:

root = Tkinter.Tk()
button = Tkinter.Button(root, text="Find me")
button.pack()

I created a button, Python object. I recall I can check this object 
existing by using   winfo, such as  winfo.exists(button). However, I 
forgot which super class contains this   winfo   method.  I printed 
out dir(os), dir(sys), dir(Tkinter), but did not find this winfo 
method. I wonder who will be kindly drop down a few lines? 
This is due to a bad wrapping of the original Tcl interface of Tk. In 
the original Tcl, "winfo" is not a method of anything, it is a free 
function. In TkInter, all free functions that accept a widget as the 
first parameter were made methods of that widget.


They were made methods of all widgets.  Thanks for pointing this out, as 
it same some anomalies more understandable.


Someone was overcome with Java-esque OO-itis, the notion that all 
function have to be methods.

http://infohost.nmt.edu/tcc/help/pubs/tkinter/web/universal.html
calls them universal methods.  The result is that help(Text), for 
instance, returns over 1000 lines because it includes all the universal 
methods in addition to the real Text methods. dir(Text(root)) is also 
overburdened with non-Text information.


Therefore, 
"winfo_exists" is a method of "button", which is logically contorted: 
you are asking an object "do you exist?".


You are actually asking the python instance whether the tk window it 
initially represented still exists.  In tk, the argument is a window 
name that represents a window structure.  Does the structure initially 
represented by a name still exist?


This is similar to a python file instance myfile existing after the 
corresponding OS file has been closed (destroyed) with myfile.close. 
This sets the attribute myfile.closed to True.  Calling other file 
methods fails because there is no OS structure to relay it to.



However, since it can be explicitly destroyed, this can still be useful:

 >>> import Tkinter
 >>> root = Tkinter.Tk()
 >>> button = Tkinter.Button(root, text="Find me")
 >>> button.pack()
 >>> button.winfo_exists()
1
 >>> button.destroy()
 >>> button.winfo_exists()
0

I am not sure that this is very helpful, though. Usually you don't 
destroy a button yourself, it is done by the destructor when the button 
is deleted, and therefore, winfo_exists() under normal circumstances 
returns true.


The reference above omits winfo-exists, perhaps because it is so useless.

--
Terry Jan Reedy


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


Re: Django-hotsauce 1.0 LTS (Commercial Edition) now available for preorder!!

2018-06-13 Thread Etienne Robillard



Le 2018-06-14 à 02:38, Chris Angelico a écrit :

On Thu, Jun 14, 2018 at 11:07 AM, Jim Lee  wrote:

I haven't purchased commercial software in decades, so I'm not up on the
prevailing business model, but I have to ask:

Why would anyone purchase software and then agree to wait 14 weeks for it to
be delivered?  I can see that model for hardware, where material resources
are limited and a finite number of product is produced, but software?
What's the point?


For the 50% discount, I presume. If you wait 14 weeks, then buy, then
own, you pay full price.

>From the company's point of view: if the release date is in the future
and ALL the revenue is also in the future, cash flow becomes tricky.
By getting at least _some_ money in advance, they give themselves a
way to pay the bills.



Chris got it right I think! :)

Thank you,

Etienne

--
Etienne Robillard
[email protected]
https://www.isotopesoftware.ca/

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