Re: Referencing section name by interpolation in ConfigParser

2017-01-25 Thread Peter Otten
Hans-Peter Jansen wrote:

> I would like to use a interpolated section name, e.g.:
> 
> [Section]
> secref: %{section}s/whatever
> 
> should result in:
> 
 config['Section']['secref']
> 'Section/whatever'
> 
> Any idea anybody, how to archive this with minimum fuzz?

If you can live with the existing "basic interpolation", i. e. %(...)s, not 
%{...}s:

$ cat config.ini
[Foo]
secref: %(section)s/whatever
[Bar]
secref: %(section)s/whatever
$ cat demo.py
import configparser


class Interpolation(configparser.BasicInterpolation):
def before_get(self, parser, section, option, value, defaults):
defaults = defaults.copy()
defaults["section"] = section
return super().before_get(parser, section, option, value, defaults)


p = configparser.ConfigParser(interpolation=Interpolation())
p.read("config.ini")
for section in "Foo", "Bar":
print(section, "-->", p[section]["secref"])
$ python3 demo.py 
Foo --> Foo/whatever
Bar --> Bar/whatever
$

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


Re: Hide text in entry box when i click on it.(GUI using Tkinter in python)

2017-01-25 Thread Peter Otten
hmmeeranrizv...@gmail.com wrote:

> Hello Guys,
> Here i am creating a entry box with some text,i need to hide the text when
> i click on it. Here is my code
> 
> from Tkinter import *
> obj = Tk()
> b = Entry(obj,width=100)
> b.insert(0,"Enter the value to search")
> b.pack()
> mainloop()

You need to bind a callback function to a mouse event:

import Tkinter as tk

def clear_search(event):
search.delete(0, tk.END)

root = tk.Tk()

search = tk.Entry(root, width=100)
search.insert(0, "Enter the value to search")
search.pack()
search.bind("", clear_search)

root.mainloop()

This will always clear the Entry; you probably want to check if it contains 
the initial message first to avoid that the user accidentally loses input.

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


Re: Hide text in entry box when i click on it.(GUI using Tkinter in python)

2017-01-25 Thread hmmeeranrizvi18
On Wednesday, January 25, 2017 at 1:15:11 PM UTC+5:30, hmmeera...@gmail.com 
wrote:
> Hello Guys,
> Here i am creating a entry box with some text,i need to hide the text when i 
> click on it.
> Here is my code
> 
> from Tkinter import *
> obj = Tk()
> b = Entry(obj,width=100)
> b.insert(0,"Enter the value to search")
> b.pack()
> mainloop()

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


configparser bug

2017-01-25 Thread Christos Malliopoulos
Hi,

I run Ubuntu 16.04 LTS in a VM using VMWare Workstation on a Windows 10
host.
apt show python-configparser shows 3.3.0r2-2
On python 2.7.12 I use the following code:

import configparser as cfg
root =
u'/'.join(os.path.split(os.path.abspath('cfg.py'))[0].split('/')[:-2])
cp = cfg.ConfigParser(interpolation = cfg.ExtendedInterpolation())
cp.read(os.path.abspath(os.path.join(root, u'config/sampling.cfg')))

cp.items('Sampling')

sampling.cfg contains the following lines:
[Sampling]
nobs = 10
nzin = 4
nzout = 3
ndrops = 1

inh = day,loc,z0,value
outh = day,loc,sku,value

invalran = 1,1e3
outvalran = 1,1000

cp.items(u'Sampling') prints the following:
[(u'nobs', u'10'),
 (u'nzin', u'4'),
 (u'nzout', u'3\nndrops = 1'),
 (u'inh', u'day,loc,z0,value'),
 (u'outh', u'day,loc,sku,value'),
 (u'invalran', u'1,1e3'),
 (u'outvalran', u'1,1000')]

ndrops = 1 is not parsed correctly
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: configparser bug

2017-01-25 Thread Peter Otten
Christos Malliopoulos wrote:

> Hi,
> 
> I run Ubuntu 16.04 LTS in a VM using VMWare Workstation on a Windows 10
> host.
> apt show python-configparser shows 3.3.0r2-2
> On python 2.7.12 I use the following code:
> 
> import configparser as cfg
> root =
> u'/'.join(os.path.split(os.path.abspath('cfg.py'))[0].split('/')[:-2])
> cp = cfg.ConfigParser(interpolation = cfg.ExtendedInterpolation())
> cp.read(os.path.abspath(os.path.join(root, u'config/sampling.cfg')))

This looks confusing. Are you sure you are reading the right sampling.cfg?

> cp.items('Sampling')
> 
> sampling.cfg contains the following lines:
> [Sampling]
> nobs = 10
> nzin = 4
> nzout = 3
> ndrops = 1
> 
> inh = day,loc,z0,value
> outh = day,loc,sku,value
> 
> invalran = 1,1e3
> outvalran = 1,1000
> 
> cp.items(u'Sampling') prints the following:
> [(u'nobs', u'10'),
>  (u'nzin', u'4'),
>  (u'nzout', u'3\nndrops = 1'),
>  (u'inh', u'day,loc,z0,value'),
>  (u'outh', u'day,loc,sku,value'),
>  (u'invalran', u'1,1e3'),
>  (u'outvalran', u'1,1000')]
> 
> ndrops = 1 is not parsed correctly

It looks like the parser does not expand tabs, and your problem may be 
mixing tabs and spaces:

$ cat demo.py
import configparser

data = """\
[Sampling]
\talpha = 1
\tbeta = 2
 \tgamma = 3
\tdelta = 4
"""
print "what you see:"
print data.expandtabs(4)

print "what the parser sees:"
print data.replace("\t", " ")

with open("sampling.cfg", "w") as f:
f.write(data)

cp = configparser.ConfigParser(
interpolation=configparser.ExtendedInterpolation()
)
cp.read("sampling.cfg")
for item in cp.items('Sampling'):
print item
$ python demo.py 
what you see:
[Sampling]
alpha = 1
beta = 2
gamma = 3
delta = 4

what the parser sees:
[Sampling]
 alpha = 1
 beta = 2
  gamma = 3
 delta = 4

(u'alpha', u'1')
(u'beta', u'2\ngamma = 3')
(u'delta', u'4')
$ 


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


Re: How coding in Python is bad for you

2017-01-25 Thread alister
On Tue, 24 Jan 2017 20:09:45 -0500, Dennis Lee Bieber wrote:

> On Tue, 24 Jan 2017 16:03:45 GMT, alister 
> declaimed the following:
> 
>>On Tue, 24 Jan 2017 14:28:55 +, Jon Ribbens wrote:
>>
>>> On 2017-01-24, alister  wrote:
 On Mon, 23 Jan 2017 20:39:26 +, Jon Ribbens wrote:
> That's a meaningless statement. *Everything* is a poison in
> sufficient quantities.

 indees when I here someone saying "I won't have any xyz because they
 have heard that too much is bad for them" I invariably inform them
 that too much oxygen is poisonous & challenge then to cut that out
 completely :-)
>>> 
>>> Just wait until they find out that raw fruit and vegetables contain
>>> hundreds of chemicals!
>>
>>then send them of to one of the sitre relating to Di-Hydrogen
>>Monoxide...
> 
>   Or: http://vintage.failed-dam.org/tomato.htm
>>
>>I know of one organic food producer that has even tried to deny the use
>>the stuff ;-)
> 
>   While I'm trying to figure out what significance Centrum vitamins 
have
> with being "non-GMO"... Unless they are implying that other companies
> are using modified bacteria as chemical factories... How many vitamin
> tablets can you think of that are compounded from plant extracts these
> days?

what has centrum vitamins & GMO got to do with di-hydrogen-monoxide?
(although 1000-1 says they use it in their processes somewhere)




-- 
A sequel is an admission that you've been reduced to imitating yourself.
-- Don Marquis
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: With class as contextmanager

2017-01-25 Thread This Wiederkehr
Thank you for your answers. Very appreciated.

I ended up doing it as follows:

class MetaLock(type):

def __init__(cls, *args):
super().__init__(*args)
cls.lock = Lock()
cls.instances = []

def register(cls, instance):
cls.instances.append(instance)

def __enter__(cls):
cls.lock.acquire()


def __exit__(cls, exc_type, exc_val, exc_tb):
for instance in cls.instances:
instance.cleanup()
cls.instances = []
cls.lock.release()
return False


class Klass(metaclass=MetaLock):

def __init__(self):
if not self.__class__.lock.locked():
raise Exception("You have to use the context manager on
the Class Object!")
self.__class__.register(self)

def cleaup(self):
pass

with Klass:
inst1 = Klass()
inst2 = Klass()

# on leaving the context the cleanup of each instance of Klass is called.

Regards

This


2017-01-25 3:21 GMT+01:00 Terry Reedy :

> On 1/24/2017 4:31 PM, This Wiederkehr wrote:
>
> having a class definition:
>>
>> class Test():
>>
>> @classmethod
>> def __enter__(cls):
>> pass
>>
>> @classmethod
>> def __exit__(cls, exception_type, execption_value, callback):
>> pass
>>
>> now using this as a contextmanager does not work, even though Test is an
>> object and has the two required methods __enter__ and __exit__.
>>
>> it fails with:
>> #Attribute Error: __enter__
>>
>>
>> This is not working because behind the scene it does something like:
>> type(Test).__enter__(Test)
>>
>> But isn't this supposed to be working?
>>
>
> No.  Unqualified 'method' means instance method, not class method.
>
> One can simulate instance methods like so:
>
> >>> import types
> >>> def f(self): print('f called')
>
> >>> class C: pass
>
> >>> c = C()
> >>> c.m = types.MethodType(f, c)
> >>> c.m()
> f called
>
> However, this will not work for dunder methods where the lookup for the
> method starts with the class and not the object itself.
>
> >>> def h(self): return 1
>
> >>> c.__hash__ = types.MethodType(h, c)
> >>> hash(c)  # calls type(c).__hash__, not c.__hash__
> -9223371924496369383
>
> --
> Terry Jan Reedy
>
> --
> https://mail.python.org/mailman/listinfo/python-list
>



-- 
This Wiederkehr
Vorgasse 21
5722 Gränichen
079 785 70 75
-- 
https://mail.python.org/mailman/listinfo/python-list


Python

2017-01-25 Thread murphyclara565
Need help

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


RE: Python

2017-01-25 Thread Joaquin Alzola


> Need help
I need a beer

Put your question in the mailing list I think you can get the help needed.
This email is confidential and may be subject to privilege. If you are not the 
intended recipient, please do not copy or disclose its content but contact the 
sender immediately upon receipt.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python

2017-01-25 Thread Stephane Wirtel via Python-list
Come to PythonFosdem https://www.python-fosdem.org we will offer some beers on 
4 & 5 feb in Brussels


> On 25 Jan 2017, at 15:46, Joaquin Alzola  wrote:
> 
> 
> 
>> Need help
> I need a beer
> 
> Put your question in the mailing list I think you can get the help needed.
> This email is confidential and may be subject to privilege. If you are not 
> the intended recipient, please do not copy or disclose its content but 
> contact the sender immediately upon receipt.
> -- 
> https://mail.python.org/mailman/listinfo/python-list

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


The argparse docs don't say who's responsible for closing FileType objects

2017-01-25 Thread Bob Kline
The subject line pretty much says it all. Should the programmer close the file? 
If the programmer does that, and the user has asked that the file object be 
hooked up to standard in (or standard out) what will happen? If the programmer 
doesn't close it, does it get closed cleanly in the face of an exception?

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


Re: How an editor can help with block nesting (was Re: How coding in Python is bad for you)

2017-01-25 Thread Ben Iannitelli
On Wed, Jan 25, 2017 at 6:31 AM, Ben Bacarisse 
 wrote:

In Python the editor could, for example, highlight the block you are
typing in, so as soon as you leave the body of the 'if' it would stop
being marked and the containing code would be highlighted.  Just moving
the cursor up and down would show you what block everything is in.  I
don't know if any editors help like this -- that's part of my reason to
ask.
@Ben B.: Have you had a look at Notepad++? When it detects that you're editing 
a Python file, a ruler on the left-hand margin of the editing window employs a 
system of boxes and lines to show which blocks of code belong to which 
conditional clause, with those pertaining to the current block in red.

Below are attempts to sketch it out without the benefit of screenshots or color.
First attempt:
[box with a dash inside of it ]if __name__ == "__main__":
[U+2514]main()

Second attempt (imagine that your cursor is somewhere in the same line as the 
"print" statement) :
[box with a dash inside of it, in gray ]def main():
[box with a dash inside of it, in gray ]with 
open("some_spreadsheet.csv",newline='') as sheet:
[U+2502, in gray]data = csv.DictReader(sheet)
[box with a dash inside of it, in RED ]for n,row in enumerate(data):
[U+2514, in RED]print(n,row)

I didn't do it justice, but that's honestly the best I can do. If you can find 
the time to install it and then play with it, you can actually see for yourself 
whether that feature is loyal to the idea you described.


HTH


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


Re: The argparse docs don't say who's responsible for closing FileType objects

2017-01-25 Thread alister
On Wed, 25 Jan 2017 07:16:24 -0800, Bob Kline wrote:

> The subject line pretty much says it all. Should the programmer close
> the file? If the programmer does that, and the user has asked that the
> file object be hooked up to standard in (or standard out) what will
> happen? If the programmer doesn't close it, does it get closed cleanly
> in the face of an exception?
> 
> Thanks!

i would think the principle is always the same

if you open a file close it behind you

using "with" should ensure this always happens
 




-- 
It is bad luck to be superstitious.
-- Andrew W. Mathis
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python

2017-01-25 Thread breamoreboy
On Wednesday, January 25, 2017 at 2:15:16 PM UTC, murphyc...@gmail.com wrote:
> Need help

Please read this http://www.catb.org/~esr/faqs/smart-questions.html and then 
this http://sscce.org/ before trying again.

Kindest regards.

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


Re: Hide text in entry box when i click on it.(GUI using Tkinter in python)

2017-01-25 Thread Christian Gollwitzer

Am 25.01.17 um 10:18 schrieb Peter Otten:

hmmeeranrizv...@gmail.com wrote:


Hello Guys,
Here i am creating a entry box with some text,i need to hide the text when
i click on it.



search.bind("", clear_search)



This is the correct answer for a mouse click. The typical use case 
(disappearing placeholder) should also trigger, when somebody uses the 
tab key to set the focus to the window. This can be achieved by binding 
to the  event instead:


search.bind("", clear_search)

In addition, repeated clicking does not clear the text then.

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


Re: PhotoImage.paste

2017-01-25 Thread rryan . asu
Hi Greg,

Yeah, I thought of that too...  So I was trying to store it as only a grayscale 
image and use the "L" format.  I wonder if maybe that didn't work?  I'll play 
around with that and ensure I did what I think I did.  But that's a good 
reminder.

Thanks!
Russell


On Tuesday, January 24, 2017 at 11:51:37 PM UTC-5, Gregory Ewing wrote:
> Dennis Lee Bieber wrote:
> > But practically everything these days uses true/high color, in which
> > each pixel encodes the exact color to be displayed. This means that
> > changing all matching pixels from one given color to another given color
> > requires rewriting those pixels color data.
> 
> Yes, and a 4k x 4k RGBA image is about 64MB of data.
> I'm not surprised it takes a noticeable amount of
> time to change all of that.
> 
> -- 
> Greg
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python

2017-01-25 Thread Paul Rudin
Joaquin Alzola  writes:

> This email is confidential and may be subject to privilege. If you are not the
> intended recipient, please do not copy or disclose its content but contact the
> sender immediately upon receipt.

Probably best not to send it to a publicly accessible mailing list
then :/
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python

2017-01-25 Thread mm0fmf

On 25/01/2017 14:15, murphyclara...@gmail.com wrote:

Need help


Can help, need money.
--
https://mail.python.org/mailman/listinfo/python-list


Need reviews for my book on introductory python

2017-01-25 Thread Sandeep Nagar
Hi,

A few month ago I wrote a book on introductory python based on my experinces 
while teaching python to Bachelor students of engineering. It is now available 
in e-book and paperback format at Amazon. 

https://www.amazon.com/dp/1520153686

The book is written for beginners of python programming language and written in 
learn-by-doing manner. If some group members can review the same, it will be 
useful for myself to come up with an improved version.

Other similar books of mine are based on Octave and Scilab with following links:

https://www.amazon.com/dp/152015111X (Scilab)

https://www.amazon.com/dp/1520158106 (Octave)

If you are interested in open source computing, please have a look. 

Also please do share the link for print books with your colleagues at other 
universities and recommend them for libraries and researchers, if you feel that 
they can be helpful to them.

Regards

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


Re: any one used moviepy please come in!!! I need help, thanks!

2017-01-25 Thread Tony Chen
On Wednesday, January 25, 2017 at 8:34:01 PM UTC+13, Chris Angelico wrote:
> On Wed, Jan 25, 2017 at 6:22 PM, Tony Chen  wrote:
> > This error can be due to the fact that ImageMagick is not installed on your 
> > computer, or (for Windows users) that you didn't specify the path to the 
> > ImageMagick binary in file conf.py, or.that the path you specified is 
> > incorrect
> 
> So... is ImageMagick installed?
> 
> ChrisA

Okay... Yes it's installed. This problem has been solved haha. Thank you for 
replying.
-- 
https://mail.python.org/mailman/listinfo/python-list