[Tutor] Need help

2016-09-28 Thread niraj pandey
Hi,

I am new in python. Could you guys please help me to short this code ?

Want to write this iteration (Yellow one) using loop.

r = 0
L1 = Label(bg = 'orange', text="Flat_No", relief=RIDGE,width=30)
L1.grid(row=0,column=0)
E1 = Entry(relief=SUNKEN,width=30)
E1.grid(row=0,column=1)
L2 = Label(bg = 'orange', text="Mains Unit", relief=RIDGE,width=30)
L2.grid(row=1,column=0)
E2 = Entry(relief=SUNKEN,width=30)
E2.grid(row=1,column=1)
L3 = Label(bg = 'orange', text="DG Unit", relief=RIDGE,width=30)
L3.grid(row=2,column=0)
E3 = Entry(relief=SUNKEN,width=30)
E3.grid(row=2,column=1)
L4 = Label(bg = 'orange', text="Month", relief=RIDGE,width=30)
L4.grid(row=3,column=0)
E4 = Entry(relief=SUNKEN,width=30)
E4.grid(row=3,column=1)


MyButton1 = Button(top, text="Submit", width=10, bg='red', command=lambda:
database.data(E1.get(), E2.get(), E3.get(), E4.get()))
MyButton1.grid(row=8, column=1)

The output should be like this :

[image: Inline image 1]

Thanks
Niraj
-- 
Success occurs when opportunity and preparation meet
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Need help

2016-09-28 Thread niraj pandey
Found the solution for this .

entry_option = ['Flat_No','Mains Unit','DG Unit','Month']

 r = 0
  entry = {}
  label = {}
  for item in entry_option:
  lb = Label(bg = 'orange', text=item, relief=RIDGE,width=30)
  lb.grid(row=r,column=0)
  label[item] = lb
  e = Entry(relief=SUNKEN,width=30)
  e.grid(row=r,column=1)
  entry[item] = e
  r=r+1

But now how to pass these values as an argument for this function  ?

command=lambda: database.data(E1.get(), E2.get(), E3.get(), E4.get())

Thanks
Niraj

On Wed, Sep 28, 2016 at 10:52 AM, niraj pandey 
wrote:

> Hi,
>
> I am new in python. Could you guys please help me to short this code ?
>
> Want to write this iteration (Yellow one) using loop.
>
> r = 0
> L1 = Label(bg = 'orange', text="Flat_No", relief=RIDGE,width=30)
> L1.grid(row=0,column=0)
> E1 = Entry(relief=SUNKEN,width=30)
> E1.grid(row=0,column=1)
> L2 = Label(bg = 'orange', text="Mains Unit", relief=RIDGE,width=30)
> L2.grid(row=1,column=0)
> E2 = Entry(relief=SUNKEN,width=30)
> E2.grid(row=1,column=1)
> L3 = Label(bg = 'orange', text="DG Unit", relief=RIDGE,width=30)
> L3.grid(row=2,column=0)
> E3 = Entry(relief=SUNKEN,width=30)
> E3.grid(row=2,column=1)
> L4 = Label(bg = 'orange', text="Month", relief=RIDGE,width=30)
> L4.grid(row=3,column=0)
> E4 = Entry(relief=SUNKEN,width=30)
> E4.grid(row=3,column=1)
>
>
> MyButton1 = Button(top, text="Submit", width=10, bg='red', command=lambda:
> database.data(E1.get(), E2.get(), E3.get(), E4.get()))
> MyButton1.grid(row=8, column=1)
>
> The output should be like this :
>
> [image: Inline image 1]
>
> Thanks
> Niraj
> --
> Success occurs when opportunity and preparation meet
>



-- 
Success occurs when opportunity and preparation meet
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] differences between map and partial?

2016-09-28 Thread source liu
Hi, Danny,


Thank you for your reply

I checked the mail, the attachment is attached, i don't know why you
can't see it ( I change the extension of .tar.gz to .tar.gz_src, as
gmail can't pass the security check of the .tar.gz)



I would like to inline the code  as well as attached again( the are
all simple files )


-- accouting
 -log1
 -log2
   logtool
 -__init__.py
 -tools.py
   run.py


log1,log2 ( write anything you like, it pretend to be log file )

__init__.py  :blank

--tools.py

#!/bin/env python
def identy(string):
print string;

def unity(string):
return 1

def line_op(string,op=identy):
return apply(op,(string,))

def file_op(filename,lineop):
f=open(filename)
res=None;
try:
res=map(lambda x:line_op(x,lineop),f)
finally:
f.close()
return res


run.py--
import os
#log_location="/home/source/python/pg/accounting"
log_location='accounting'
from multiprocessing import Pool

from functools import partial


if __name__=="__main__":
from logtool.tools import *
p=Pool(processes=4);
for root,dir,file in os.walk(log_location):
input=map(lambda x: os.path.join(root,x),file)

print p.map(partial(file_op,lineop=unity),input)
#print p.map(lambda x:file_op(x,unity), input)






==

THAT'S ALL OF THE CODE


Thank you






















On Wed, Sep 28, 2016 at 3:26 AM, Danny Yoo  wrote:
> On Tue, Sep 27, 2016 at 2:23 AM, source liu  wrote:
>> Hi, List
>>
>> the test code as attached
>
>
> Unfortunately, it didn't attach.  If you can inline the content of the
> test code, that would be helpful.
>
>
>> this one works print p.map(partial(file_op,lineop=unity),input)
>> this one doesn't work print p.map(lambda x:file_op(x,unity), input)
>
>
> I don't know what the function signature of file_op is.  This is an
> important detail!
>
>
>
> I would expect:
>
> p.map(partial(file_op,lineop=unity),input)
>
> and:
>
> p.map(lambda x:file_op(x,lineop=unity), input)
>
> to be functionality equivalent.
>
>
>
> However, I do not know, without seeing file_op, whether:
>
> p.map(lambda x:file_op(x, lineop=unity), input)
>
> versus:
>
> p.map(lambda x:file_op(x, unity), input)
>
> Depending on method signature, this might not be equivalent,
> especially if file_op takes in multiple keyword arguments.
>
>
>
> Also, I don't know what you mean by "works" vs. "doesn't work": those
> are human expressions that are ambiguous enough that I only know
> something is wrong, but I don't know what.  :)  Can you be more
> specific?  If you see error messages or stack traces, please post
> them, as they are additional "signal" that may be helpful in figuring
> out what's happening.



-- 
Liu An
Institution of modern physics, Shanghai, China
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] differences between map and partial?

2016-09-28 Thread Peter Otten
source liu wrote:

> Hi, Danny,
> 
> 
> Thank you for your reply
> 
> I checked the mail, the attachment is attached, i don't know why you
> can't see it ( I change the extension of .tar.gz to .tar.gz_src, as
> gmail can't pass the security check of the .tar.gz)

They are stripped off by the mailing list software, so don't bother trying.

> from multiprocessing import Pool

> p=Pool(processes=4);

> print p.map(partial(file_op,lineop=unity),input)
> #print p.map(lambda x:file_op(x,unity), input)

The missing part of information was that you are using multiprocessing (The 
traceback would also have shown the problem).
Multiprocessing uses pickle to pass data around between processes, and 
anonymous functions (aka lambdas) cannot be pickled. Instead you have to use 
an ordinary function defined on the module level

def whatever(x):
return file_op(x, unity)

p.map(whatever, input)

For these pickle need not pass the code, it just remembers the module and 
function name which are then used to look up the function during unpickling.

As you found out functools.partial() can be pickled, too, and thus works 
when all of its arguments can be pickled (in particular its first argument 
has to be a global function rather than a local one or a lambda).

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Need help

2016-09-28 Thread Peter Otten
niraj pandey wrote:

> Found the solution for this.

You can further simplifiy it with enumerate()
> entry_option = ['Flat_No','Mains Unit','DG Unit','Month']

> entry = {}
> label = {}
  for r, item in enumerate(entry_option):
> lb = Label(bg = 'orange', text=item, relief=RIDGE,width=30)
> lb.grid(row=r,column=0)
> label[item] = lb
> e = Entry(relief=SUNKEN,width=30)
> e.grid(row=r,column=1)
> entry[item] = e
> 
> But now how to pass these values as an argument for this function  ?
> 
> command=lambda: database.data(E1.get(), E2.get(), E3.get(), E4.get())

Well, you saved the Entry instances in a dict, so you can retrieve them:

command=lambda: database.data(*[entry[k].get() for k in entry_option]) 

If you use a list instead of or in addition to the dict

entries = []
for ...: # your loop from above
   ...
   entries.append(e)

the lambda becomes

command=lambda: database.data(*[e.get() for e in entries])

If you have not come across it before: the * operator unpacks the list, so

args = ["a", "b"]
f(*args)

is equivalent to calling f with all items in the list,

f(args[0], args[1])

in the above example.

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Google is not your friend

2016-09-28 Thread Alan Gauld via Tutor
On 28/09/16 01:25, Ben Finney wrote:
> Alan Gauld via Tutor  writes:
> 
>> I'm not sure if they are up to 3.5 yet or not but the easiest way is
>> just to grab a full distro such as Anaconda or Canopy. Google is your
>> friend.
> 
> I do wish that meme would die. Google is many things, but it is *not*
> your friend. Corporations are not friends of anyone.

Valid point, I actually use duck-duck-go personally, but I was intending
to imply google in the generic sense of a search engine.
So I should just have said search...

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Need help

2016-09-28 Thread niraj pandey
Thanks Peter for the help.

Best Regards
Niraj



On Wed, Sep 28, 2016 at 2:47 PM, Peter Otten <__pete...@web.de> wrote:

> niraj pandey wrote:
>
> > Found the solution for this.
>
> You can further simplifiy it with enumerate()
> > entry_option = ['Flat_No','Mains Unit','DG Unit','Month']
>
> > entry = {}
> > label = {}
>   for r, item in enumerate(entry_option):
> > lb = Label(bg = 'orange', text=item, relief=RIDGE,width=30)
> > lb.grid(row=r,column=0)
> > label[item] = lb
> > e = Entry(relief=SUNKEN,width=30)
> > e.grid(row=r,column=1)
> > entry[item] = e
> >
> > But now how to pass these values as an argument for this function  ?
> >
> > command=lambda: database.data(E1.get(), E2.get(), E3.get(), E4.get())
>
> Well, you saved the Entry instances in a dict, so you can retrieve them:
>
> command=lambda: database.data(*[entry[k].get() for k in entry_option])
>
> If you use a list instead of or in addition to the dict
>
> entries = []
> for ...: # your loop from above
>...
>entries.append(e)
>
> the lambda becomes
>
> command=lambda: database.data(*[e.get() for e in entries])
>
> If you have not come across it before: the * operator unpacks the list, so
>
> args = ["a", "b"]
> f(*args)
>
> is equivalent to calling f with all items in the list,
>
> f(args[0], args[1])
>
> in the above example.
>
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
>



-- 
Success occurs when opportunity and preparation meet
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Need help

2016-09-28 Thread niraj pandey
Ignore this I have done it.

Thanks
Niraj

On Wed, Sep 28, 2016 at 12:30 PM, niraj pandey 
wrote:

> Found the solution for this .
>
> entry_option = ['Flat_No','Mains Unit','DG Unit','Month']
>
>  r = 0
>   entry = {}
>   label = {}
>   for item in entry_option:
>   lb = Label(bg = 'orange', text=item, relief=RIDGE,width=30)
>   lb.grid(row=r,column=0)
>   label[item] = lb
>   e = Entry(relief=SUNKEN,width=30)
>   e.grid(row=r,column=1)
>   entry[item] = e
>   r=r+1
>
> But now how to pass these values as an argument for this function  ?
>
> command=lambda: database.data(E1.get(), E2.get(), E3.get(), E4.get())
>
> Thanks
> Niraj
>
> On Wed, Sep 28, 2016 at 10:52 AM, niraj pandey  > wrote:
>
>> Hi,
>>
>> I am new in python. Could you guys please help me to short this code ?
>>
>> Want to write this iteration (Yellow one) using loop.
>>
>> r = 0
>> L1 = Label(bg = 'orange', text="Flat_No", relief=RIDGE,width=30)
>> L1.grid(row=0,column=0)
>> E1 = Entry(relief=SUNKEN,width=30)
>> E1.grid(row=0,column=1)
>> L2 = Label(bg = 'orange', text="Mains Unit", relief=RIDGE,width=30)
>> L2.grid(row=1,column=0)
>> E2 = Entry(relief=SUNKEN,width=30)
>> E2.grid(row=1,column=1)
>> L3 = Label(bg = 'orange', text="DG Unit", relief=RIDGE,width=30)
>> L3.grid(row=2,column=0)
>> E3 = Entry(relief=SUNKEN,width=30)
>> E3.grid(row=2,column=1)
>> L4 = Label(bg = 'orange', text="Month", relief=RIDGE,width=30)
>> L4.grid(row=3,column=0)
>> E4 = Entry(relief=SUNKEN,width=30)
>> E4.grid(row=3,column=1)
>>
>>
>> MyButton1 = Button(top, text="Submit", width=10, bg='red',
>> command=lambda: database.data(E1.get(), E2.get(), E3.get(), E4.get()))
>> MyButton1.grid(row=8, column=1)
>>
>> The output should be like this :
>>
>> [image: Inline image 1]
>>
>> Thanks
>> Niraj
>> --
>> Success occurs when opportunity and preparation meet
>>
>
>
>
> --
> Success occurs when opportunity and preparation meet
>



-- 
Success occurs when opportunity and preparation meet
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] NumPy and SciPy

2016-09-28 Thread Steven D'Aprano
On Tue, Sep 27, 2016 at 03:23:23PM +, Floeck, Thomas wrote:
> Hi there,
> 
> you have an idea where I can find NumPy and SciPy windows *.exe-files 
> for Python 3.5?

Why does it have to be an .exe file?

http://www.scipy.org/install.html



-- 
Steve
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor