Re: Finding the name of a function while defining it

2012-12-29 Thread Jussi Piitulainen
Abhas Bhattacharya writes:

[...]

> If i call one() and two() respectively, i would like to see "one"
> and "two". I dont have much knowledge of lambda functions, neither
> am i going to use them, so that's something I cant answer.

It's not about lambda. The following does not contain lambda. What
should be name(one)? name(two)? name(foo)? name(fun(1))? name(fun(3))?

def foo():
return 3

def fun(x):
def foo(): return x
return foo

one = fun(1)
two = one

Note that fun(1)() is a valid call where fun(1) is not given any name
outside fun.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: email.message.Message - as_string fails

2012-12-29 Thread Helmut Jarausch
On Fri, 28 Dec 2012 20:57:46 -0500, Terry Reedy wrote:

> On 12/28/2012 7:22 AM, Helmut Jarausch wrote:
>> Hi,
>>
>> I'm trying to filter an mbox file by removing some messages.
>> For that I use Parser= FeedParser(policy=policy.SMTP)
>> and 'feed' any lines to it.
>> If the mbox file contains a white line followed by '^From ',
>> I do
>>
>> Msg= Parser.close()
>>
>> (lateron I delete the Parser and create a new one by Parser=
>> FeedParser(policy=policy.SMTP)
>> )
>>
>> I can access parts of the message by  Msg['Message-ID'], e.g.
>> but even for the very first message, trying to print it or convert it
>> to a string by  MsgStr=Msg.as_string(unixfrom=True)
>>
>> lets Python (3.3.1_pre20121209) die with
>>
>> Traceback (most recent call last):
>>File "Email_Parse.py", line 35, in 
>>  MsgStr=Msg.as_string(unixfrom=True)
>>File "/usr/lib64/python3.3/email/message.py", line 151, in as_string
>>  g.flatten(self, unixfrom=unixfrom)
>>File "/usr/lib64/python3.3/email/generator.py", line 112, in flatten
>>  self._write(msg)
>>File "/usr/lib64/python3.3/email/generator.py", line 171, in _write
>>  self._write_headers(msg)
>>File "/usr/lib64/python3.3/email/generator.py", line 198, in
>>_write_headers
>>  self.write(self.policy.fold(h, v))
>>File "/usr/lib64/python3.3/email/policy.py", line 153, in fold
>>  return self._fold(name, value, refold_binary=True)
>>File "/usr/lib64/python3.3/email/policy.py", line 176, in _fold
>>  (len(lines[0])+len(name)+2 > maxlen or
>> IndexError: list index out of range
> 
> The only list index visible is 0 in lines[0]. If this raises, lines is
> empty. You could trace back to see where lines is defined. I suspect it
> is all or part of the Msg you started with.
> 
> I believe that some of email was rewritten for 3.3, so it is possible
> that you found a bug based on an untrue assumption. It is also possible
> that you missed a limitation in the doc, or tripped over an intended but
> not written limitation. So I hope you do the tracing, so if doc or code
> need a fix, a tracker issue can be opened.

Thanks Terry,
I've debugged it and it smells like a bug.
I have created  http://bugs.python.org/issue16811

Helmut.

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


Re: Facing issue with Python loggin logger for printing object value

2012-12-29 Thread Morten Engvoldsen
Hi Dave,
Thanks for reply. I will really appreciate if you reply to my mail id and
keep python list in cc, since everytime you reply my query i need to search
the reply in the forwarding message of python list.

Using logger.setLevel(logging.DEBUG) will log only debug message in the log
file and discard other message from log file. So that's not solving the
issue of my problem. I am looking into code to find out the issue.

Thanks again for your effort
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Facing issue with Python loggin logger for printing object value

2012-12-29 Thread Chris Angelico
On Sat, Dec 29, 2012 at 11:39 PM, Morten Engvoldsen
 wrote:
> Hi Dave,
> Thanks for reply. I will really appreciate if you reply to my mail id and
> keep python list in cc, since everytime you reply my query i need to search
> the reply in the forwarding message of python list.

The normal thing to do with a mailing list is, as I'm doing here,
replying to the list. You'll get a copy of the email from the list (or
the newsgroup, if you subscribe that way), and it's much easier for
all concerned.

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


Re: PYTHON 3.3 + GUI + COMPILE

2012-12-29 Thread Kwpolska
On Fri, Dec 28, 2012 at 3:08 AM, Dimitrios Xenakis
 wrote:
> Morning,
> I have been looking for a library solution of both GUI and Compiler but for 
> Python 3.3 and ofcourse i was hoping for a combination that would be most 
> compatible between them. After searching i may have concluded to cx_Freeze 
> (because it was the only one that noticed that currently supports version 
> Python 3.3), but i do not know what GUI library should i combine it with. 
> Does cx_Freeze alone put any kind of restriction to my choice of GUI? I would 
> also be interested in using my programs for commercial purposes, so would 
> this put again some other kind of limitations to my GUI choice? I have read 
> many good stuff about PySide, but still i do not know wether this is the one 
> that i should choose. Is PySide same as PyQT and PyQT4 and QT or which is the 
> exact relationship between those? Disadvantages - advantages, capabilities, 
> benefits, costs, etc. (What is the lowest possible cost of buying such a 
> commercial license for my programming?. Are there different versions and 
> should i be carefull
>   to choose the best for me? Where could i get this from? PySide is total 
> free for my commercial needs?) I need to be legit so i guess i should learn 
> how to handle with the licencing thing. Please somebody clear things for me.
>
> Thanks 4 your time i really appreciate that.
> --
> http://mail.python.org/mailman/listinfo/python-list

cx_Freeze has nothing to do with GUIs, so it will work, no matter what.
---
PySide is a newer Python binding for the Qt framework (version 4),
developed by Openbossa, available under the LGPL license, meaning
there is no licensing problem for your commercial needs.
PyQt4 is an older binding by Riverbank Computing (Qt 4), available
under GPL or a commercial license, meaning you need to (a) go
open-source; or (b) pay a lot of money.
PyQt is the general name for PyQt4 and PyQt3, and you should not use PyQt3.
Qt is a GUI development framework for C++, with bindings for many
languages, including Python.

Also, the main difference for developers is the module name.  That’s it.

Now, I am a huge Qt advocate, but you may also want to look at other
toolkits, such as wxWidgets, GTK+ or Tck/Tk.  wxWidgets is a great
multi-platform toolkit with a nice Python binding, Tcl/Tk is an ugly
non-native toolkit, while GTK+ is a huge mess that I suggest to avoid
for your own sanity.
-- 
Kwpolska 
stop html mail  | always bottom-post
www.asciiribbon.org | www.netmeister.org/news/learn2quote.html
GPG KEY: 5EAAEA16
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Confused about logger config from within Python (3)

2012-12-29 Thread Roy Smith
In article <50de7a0a$0$29967$c3e8da3$54964...@news.astraweb.com>,
 Steven D'Aprano  wrote:

> In Python 3.2 and 3.3, the message about no handlers is not printed, 
> which is an interesting difference. (Somebody who knows more about the 
> logging package than I do might be able to state why that difference.) 

I hope that means that http://bugs.python.org/issue994421 has finally 
been fixed :-)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: noob can't install python modules/scripts

2012-12-29 Thread Joel Goldstick
On Fri, Dec 28, 2012 at 11:40 PM, lostguru  wrote:

> On Friday, December 28, 2012 11:12:19 PM UTC-5, Steven D'Aprano wrote:
> > "The website"? There's more than one website on the Internet. Which
> >
> > website are you referring to? What .py script did you download? How did
> >
> > you run it? Details are important!
> >
> sorry about that; I was using the setuptools package from pypi python [
> http://pypi.python.org/pypi/setuptools ]; I downloaded the ez_setup.py
> file from under the 64-bit windows installation section and ran that (by
> double clicking on it, I hope this wasn't another noob mistake lol)
> >
> > It looks like you tried to run the easy_install command from inside the
> >
> > Python interactive interpreter, rather than from your system shell.
> >
> >
> >
> > The system shell (command.com or cmd.exe I guess) will have a $ or %
> sign
> >
> > as the prompt. Python usually has >>> as the prompt, although if you are
> >
> > running ActivePython it may be something else. You need to run the
> >
> > "easy_install BeautifulSoup4" command from the system shell, not Python.
> >
> >
> >
> >
> >
> > Try that, and if there's another error, please copy and paste the exact
> >
> > command you used, and the full error message.
> >
> running easy_install from the command line worked and BeautifulSoup4 seems
> to have installed, thanks for pointing out my mistake
>
> the only problem I have now is that importing beautifulsoup into a .py
> file I wrote generates an error (I'm using ActiveState Komodo Edit 7, is
> there another program you would recommend to a beginner like me?)
>
> trying to run the script gives an import error:
> ImportError: No module named BeautifulSoup
>

You should read the BeautifulSoup tutorial/documentation.  If I remember
correctly you do

from bs4 import BeautifulSoup
Look at this tutorial to get started:
http://www.crummy.com/software/BeautifulSoup/bs4/doc/



> importing other modules like os and urllib that came with the python
> installation work without problems
>
> looking online, all I've found were other accounts talking about a
> beautifulsoup.py that should be in the C:\Python27\Lib\site-packages
> directory, but I've found no such thing from the installation anywhere in
> the Python folder (funnily enough, I did a drive search with Everything and
> found a BeautifulSoup.py in my autodesk maya installation)
>
> am I somewhere near the mark? or am I off completely?
> --
> http://mail.python.org/mailman/listinfo/python-list
>



-- 
Joel Goldstick
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: noob can't install python modules/scripts

2012-12-29 Thread lostguru
On Saturday, December 29, 2012 9:33:59 AM UTC-5, Joel Goldstick wrote:
> You should read the BeautifulSoup tutorial/documentation.  If I remember 
> correctly you do  
> from bs4 import BeautifulSoup
> 
> Look at this tutorial to get started:  
> http://www.crummy.com/software/BeautifulSoup/bs4/doc/

ah got it, I was told to use import -modulename- for pretty much everything by 
a classmate; I'll definitely look into the documentation


thanks again for the help guys
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Facing issue with Python loggin logger for printing object value

2012-12-29 Thread Dave Angel
On 12/29/2012 07:39 AM, Morten Engvoldsen wrote:
> Hi Dave,
> Thanks for reply. I will really appreciate if you reply to my mail id and
> keep python list in cc, since everytime you reply my query i need to search
> the reply in the forwarding message of python list.

I won't be able to remember to special-case your account, but maybe for
the next few days.  Far too many others have complained when they get an
email directly, either by sending me a request message, by using an
address at the "invalid" domain, by hijacking some bogus email address,
or by having an autoreply that says "Please don't try to contact me at
this address".  For a while I considered adding all such people to a
kill-file, but decided I'd miss too much.

I suggest you get used to reading all messages, or to simply following
the thread.  (For example, Thunderbird can keep all messages together
which are replies to each other) And while I've got you, it'd be nice if
you used reply-list yourself, instead of starting a new thread each time.

> 
> Using logger.setLevel(logging.DEBUG) will log only debug message in the log
> file and discard other message from log file. So that's not solving the
> issue of my problem. I am looking into code to find out the issue.
> 

That's not what setLevel() does.  It's a >= comparison, not an == one.
 http://docs.python.org/2/library/logging
"""Logger.setLevel(lvl)
Sets the threshold for this logger to lvl. Logging messages which are
less severe than lvl will be ignored."""

Perhaps you should also read the page:
http://docs.python.org/dev/howto/logging
search for the phrase " increasing order of severity" where it lists the
5 levels, in order.  The default level for the root logger is WARNING,
so it ignores DEBUG and INFO messages.  I suggested changing it to
DEBUG, so those won't get ignored.

You probably need to write a 10-line self-contained program to
experiment with this, and run it outside of openerp.  Chances are
openerp is doing something special that you need to conform to.  But I'm
not going to be able to guess that.



-- 

DaveA
-- 
http://mail.python.org/mailman/listinfo/python-list


Inserting Unicode chars in Entry widget

2012-12-29 Thread Alan Graham
Hello Python experts,

I want to insert Unicode chars in an Entry widget by pushing on buttons;
one for each Unicode character I need. I have made the Unicode buttons.
I just need a simple function that will send the Unicode character to
the Entry widget.
Is there a better approach?

Alan
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Facing issue with Python loggin logger for printing object value

2012-12-29 Thread Morten Engvoldsen
Hi Dave,
Thanks a lot for your reply. I have used logging.setLevel(logger.DEBUG)
because of threshold as you said.

I didn't copy paste the entire program since it was very huge. The "batch "
which value i am trying to retrieve is in a a for loop :

for payment in payment_line:

but here payment_line has null value since it was not able to retrieve
payment line value from the payment object. So i would like to know if
payment_line has null value, will it be enter into for loop since i was
able to log message which is  before the for loop but the message inside
the for loop i am not able to log.

Thanks again... :)

On Sat, Dec 29, 2012 at 5:41 PM, Dave Angel  wrote:

> On 12/29/2012 07:39 AM, Morten Engvoldsen wrote:
> > Hi Dave,
> > Thanks for reply. I will really appreciate if you reply to my mail id and
> > keep python list in cc, since everytime you reply my query i need to
> search
> > the reply in the forwarding message of python list.
>
> I won't be able to remember to special-case your account, but maybe for
> the next few days.  Far too many others have complained when they get an
> email directly, either by sending me a request message, by using an
> address at the "invalid" domain, by hijacking some bogus email address,
> or by having an autoreply that says "Please don't try to contact me at
> this address".  For a while I considered adding all such people to a
> kill-file, but decided I'd miss too much.
>
> I suggest you get used to reading all messages, or to simply following
> the thread.  (For example, Thunderbird can keep all messages together
> which are replies to each other) And while I've got you, it'd be nice if
> you used reply-list yourself, instead of starting a new thread each time.
>
> >
> > Using logger.setLevel(logging.DEBUG) will log only debug message in the
> log
> > file and discard other message from log file. So that's not solving the
> > issue of my problem. I am looking into code to find out the issue.
> >
>
> That's not what setLevel() does.  It's a >= comparison, not an == one.
>  http://docs.python.org/2/library/logging
> """Logger.setLevel(lvl)
> Sets the threshold for this logger to lvl. Logging messages which are
> less severe than lvl will be ignored."""
>
> Perhaps you should also read the page:
> http://docs.python.org/dev/howto/logging
> search for the phrase " increasing order of severity" where it lists the
> 5 levels, in order.  The default level for the root logger is WARNING,
> so it ignores DEBUG and INFO messages.  I suggested changing it to
> DEBUG, so those won't get ignored.
>
> You probably need to write a 10-line self-contained program to
> experiment with this, and run it outside of openerp.  Chances are
> openerp is doing something special that you need to conform to.  But I'm
> not going to be able to guess that.
>
>
>
> --
>
> DaveA
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Inserting Unicode chars in Entry widget

2012-12-29 Thread Chris Angelico
On Sun, Dec 30, 2012 at 3:43 AM, Alan Graham  wrote:
> Hello Python experts,
>
> I want to insert Unicode chars in an Entry widget by pushing on buttons;
> one for each Unicode character I need. I have made the Unicode buttons.
> I just need a simple function that will send the Unicode character to
> the Entry widget.
> Is there a better approach?

What GUI toolkit are you using?

Whatever it is, there ought to be a simple method on the Entry widget
that inserts a character. Poke around with it and you'll probably find
it, though you may find it under a name you don't expect. (Happens a
lot. GTK calls something "sensitive" when the rest of the world calls
it "enabled".)

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


Re: Facing issue with Python loggin logger for printing object value

2012-12-29 Thread Chris Angelico
On Sun, Dec 30, 2012 at 3:54 AM, Morten Engvoldsen  wrote:
> but here payment_line has null value since it was not able to retrieve
> payment line value from the payment object.

Specifically what value? Is it an empty string? An empty list? The
singleton None?

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


Re: Facing issue with Python loggin logger for printing object value

2012-12-29 Thread Dave Angel
On 12/29/2012 11:54 AM, Morten Engvoldsen wrote:
> Hi Dave,
> Thanks a lot for your reply. I have used logging.setLevel(logger.DEBUG)
> because of threshold as you said.
> 
> I didn't copy paste the entire program since it was very huge. The "batch "
> which value i am trying to retrieve is in a a for loop :
> 
> for payment in payment_line:
> 
> but here payment_line has null value since it was not able to retrieve
> payment line value from the payment object. 

The closest thing Python has to "null value" is called None.  If
payment_line is None, then you'll get an exception on that loop.

As I said a while ago, I have no idea how openerp handles exceptions.
Maybe it's just doing a bare except, and ignoring anything that goes
wrong in your functions.  (Very bad practice)

It could be that payment_line is an empty list.  In that case, the loop
will execute zero times.  That would also explain the lack of output.

So if openerp gives you no debugging aid, then you may have to fake it
with the logger.  How about logging a simple message just before the loop?

logger.debug("value of payment_line is " + repr(payment_line))

Did you ever fix the other things wrong with that create method?  Like
using log.debug when the object was called logger?  Or incrementing
line_counter when there was no such variable, and when it would vanish
when you exited the method anyway?



-- 

DaveA
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Inserting Unicode chars in Entry widget

2012-12-29 Thread Irmen de Jong
On 29-12-2012 17:43, Alan Graham wrote:
> Hello Python experts,
> 
> I want to insert Unicode chars in an Entry widget by pushing on buttons;
> one for each Unicode character I need. I have made the Unicode buttons.
> I just need a simple function that will send the Unicode character to
> the Entry widget.
> Is there a better approach?
> 
> Alan
> 

Not sure what the question is. A better approach to doing what?

I assuming you're doing tkinter (it is helpful if you mention the toolkit when 
posting a
question). I'd create a function that you bind to all 'unicode buttons', and 
let the
function insert the correct character depending on which button triggered it.

A possible way to do that is to use a lambda with a different parameter for 
every
button, like this:

b1=Button(f, text='char1', command=lambda b=1: insert_char(b))
b2=Button(f, text='char2', command=lambda b=2: insert_char(b))
...etc..

def insert_char(b):
if b==1:
entrywidget.insert(0, u"\u20ac")   # inserts € in the entry widget e
elif b==2:
entrywidget.insert(0, ...some other char...)
...


Or simply define a different command function for every button, then you don't 
have to
use the lambda.

-irmen

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


Re: Inserting Unicode chars in Entry widget

2012-12-29 Thread Chris Angelico
On Sun, Dec 30, 2012 at 4:11 AM, Irmen de Jong  wrote:
> b1=Button(f, text='char1', command=lambda b=1: insert_char(b))
> b2=Button(f, text='char2', command=lambda b=2: insert_char(b))
> ...etc..
>
> def insert_char(b):
> if b==1:
> entrywidget.insert(0, u"\u20ac")   # inserts € in the entry widget e
> elif b==2:
> entrywidget.insert(0, ...some other char...)
> ...

I'm not familiar with tkinter syntax, but why not:

b1=Button(f, text='char1', command=lambda: insert_char(1))
b2=Button(f, text='char2', command=lambda: insert_char(2))

or even:

b1=Button(f, text='char1', command=lambda: insert_char(u"\u20ac"))
b2=Button(f, text='char2', command=lambda: insert_char("... some other
char..."))

Seems weird to multiplex like that, but if there's a good reason for
it, sure. I'm more of a GTK person than tkinter, and more of a
command-line guy than either of the above.

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


Re: New to python, do I need an IDE or is vim still good enough?

2012-12-29 Thread Monte Milanuk

On 12/27/2012 12:01 PM, mogul wrote:


I'm new to python, got 10-20 years perl and C experience, all gained
on unix alike machines hacking happily in vi, and later on in vim.



Do I really need a real IDE, as the windows guys around me say I do,
or will vim, git, make and other standalone tools make it the next 20
years too for me?


If you've been using vi/vim happily, then I'd assume you're fully 
comfortable setting it up to do what ever you need.  In that case... I'd 
say stick with what you know.


Me, I have less 'invested' in any particular editor or environment, and 
I certainly don't 'need' a lot of the fancy extras that a lot of IDEs 
have... but setting up pydev/eclipse or spyder takes care of pretty much 
all that I need/want easily, and I can setup a fresh environment the way 
I want inside five minutes with a mouse, fairly intuitively, without 
having to go digging through config scripts and the web and books and 
such to figure out what does what.  I'd rather spend that time working 
on projects, not 'programming' my text editor.  It's neat and all if it 
works for you, but just doesn't turn my crank, personally.


I know a lot is made of the speed with which things can be done with vim 
and similar pure text editors... which is all well and good, but 
somewhere in the not-so-distant past I saw a comment which hit home for 
me.  Maybe its because I'm still just a hobbyist when it comes to 
coding, but I spend far more time 'thinking' about what I'm doing than 
typing things in... so shaving a few seconds here and there are less 
important to me.


YMMV,

Monte


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


Re: New to python, do I need an IDE or is vim still good enough?

2012-12-29 Thread Chris Angelico
On Sun, Dec 30, 2012 at 4:44 AM, Monte Milanuk  wrote:
> Maybe its because I'm still just a hobbyist when it comes to coding, but I
> spend far more time 'thinking' about what I'm doing than typing things in...
> so shaving a few seconds here and there are less important to me.

The value of a good editor isn't just in saving seconds. A couple of examples:

* Bracket matching helps to catch errors. Especially helpful when
combined with...
* Language-sensitive auto-indentation. If the editor detects that the
last line isn't complete (maybe you opened a parenthesis that you
didn't close...
... like that...)
and automatically indents, then you have instant feedback, before you
even run the program.
* Rapid location of relevant code. In SciTE, I can put the cursor on a
word and hit Ctrl-F3 to search for other occurrences of it - for
instance, put the cursor on a function name and find its definition.
(A strict declare-before-use policy helps here, as you can be fairly
sure that the first occurrence of that word will be the one you want.)
* Highlighting of comments and quoted strings, including all the
esoteric rules about line continuation and nesting.

Several of these points are more important to the polyglot than to
someone who uses only one language ever. For instance, in Python and
C, this would show an error, but in bash and PHP, it's not:

"asdf
qwer"

The difficulty of debugging varies directly with the time between
making and discovering the error. Finding a problem by compiling,
running, and using a program is good (better than it staying till
production); finding that same problem while you're in the
"compilation stage" is better; finding it right at that instant while
you're typing makes the correction trivial. That's why spell-checkers
have migrated from "press Ctrl-Q to check this document" to "red
squiggly lines underneath your text if the computer thinks it's
wrong". (That said, the number of spelling errors in published
documents hasn't gone down since red squigglies were invented, so
instant feedback isn't a panacea!)

Of course, editors are as much a matter of taste as they are science...

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


Re: Facing issue with Python loggin logger for printing object value

2012-12-29 Thread Morten Engvoldsen
Hi Dev,
Thanks a lot Dev for your reply. It is really a great help.  Yes i have
fixed what was wrong in the create method like log.debug. I have declared
line_counter=1 before the for loop.  i will try now to chcek the value of
payment_line.

Thanks again a lot. I am greateful be a member of this forum :)

On Sat, Dec 29, 2012 at 6:10 PM, Dave Angel  wrote:

> On 12/29/2012 11:54 AM, Morten Engvoldsen wrote:
> > Hi Dave,
> > Thanks a lot for your reply. I have used logging.setLevel(logger.DEBUG)
> > because of threshold as you said.
> >
> > I didn't copy paste the entire program since it was very huge. The
> "batch "
> > which value i am trying to retrieve is in a a for loop :
> >
> > for payment in payment_line:
> >
> > but here payment_line has null value since it was not able to retrieve
> > payment line value from the payment object.
>
> The closest thing Python has to "null value" is called None.  If
> payment_line is None, then you'll get an exception on that loop.
>
> As I said a while ago, I have no idea how openerp handles exceptions.
> Maybe it's just doing a bare except, and ignoring anything that goes
> wrong in your functions.  (Very bad practice)
>
> It could be that payment_line is an empty list.  In that case, the loop
> will execute zero times.  That would also explain the lack of output.
>
> So if openerp gives you no debugging aid, then you may have to fake it
> with the logger.  How about logging a simple message just before the loop?
>
> logger.debug("value of payment_line is " + repr(payment_line))
>
> Did you ever fix the other things wrong with that create method?  Like
> using log.debug when the object was called logger?  Or incrementing
> line_counter when there was no such variable, and when it would vanish
> when you exited the method anyway?
>
>
>
> --
>
> DaveA
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Keeping a Tkinter GUI alive during a long running process

2012-12-29 Thread Grant Edwards
On 2012-12-21, Kevin Walzer  wrote:

> I maintain a Tkinter application that's a front-end to to a package 
> manger, and I have never been able to find a way to keep the app from 
> locking up at some point during the piping in of the package manager's 
> build output into a text widget. At some point the buffer is overwhelmed 
> and the app simply can't respond anymore, or writes data to the text 
> widget after locking up for a period.
>
> I've long used the typical Tkinter design pattern of opening a pipe to 
> the external command, and letting it do its thing. However, after a 
> time, this locks up the app. If I try to throttle the buffer with some 
> combination of "update" or "after" or "update_idletasks," that keeps the 
> data flowing, but it comes in too slowly and keeps flowing in long after 
> the external process has terminated.

Isn't there a way in Tkinter to have a file descriptor produce an
event whenever it becomes readble?

http://stackoverflow.com/questions/3348757/how-to-make-tkinter-repond-events-while-waiting-socket-data

-- 
Grant Edwards   grant.b.edwardsYow! ... he dominates the
  at   DECADENT SUBWAY SCENE.
  gmail.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: New to python, do I need an IDE or is vim still good enough?

2012-12-29 Thread Grant Edwards
On 2012-12-27, mogul  wrote:

> I'm new to python, got 10-20 years perl and C experience, all gained
> on unix alike machines hacking happily in vi, and later on in vim.
>
> Now it's python, and currently mainly on my kubuntu desktop.
>
> Do I really need a real IDE, as the windows guys around me say I do,

No.

> or will vim, git, make and other standalone tools make it the next 20
> years too for me? 

I've been writing Python programs for 10-12 years, and I use the same
"IDE" I use for everything else:  Emacs, svn/git/whatever and a command line.

I do use the "meld" visual diff program quite a bit...

-- 
Grant Edwards   grant.b.edwardsYow! As President I have
  at   to go vacuum my coin
  gmail.comcollection!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: New to python, do I need an IDE or is vim still good enough?

2012-12-29 Thread Mitya Sirenef

On 12/29/2012 12:44 PM, Monte Milanuk wrote:
Maybe its because I'm still  just a hobbyist when it comes to coding, but I spend far more time 
'thinking' about what I'm doing than typing things in... so shaving a 
few seconds here and there are less important to me.



I think the general idea is that with editors like Vim you don't get
distracted by having to do some kind of an editor task, letting you keep
your full attention on the code logic. For instance, if I need to change
a block inside parens, I type ci) (stands for change inside parens),
while with a regular editor I'd have to do it manually and by the time
I'm done, I'd forget the bigger picture of what I'm doing with the code.
Another example: >ap stands for "indent a paragraph (separated by blank
lines)". And there are many dozens if not hundreds such commands that
let you stay focused on the logic of your code.

The trade-off, of course, is that you have to remember all (or most) of
the commands, but I figured if I spend the next 20-30+ years programming
in some version of Vim, it's well worth the initial investment.

By the way, to help me remember the commands, I wrote a small script
that lets me type in a few characters of a command or its description
and filters out the list of matching commands. It really helps,
especially when I change a lot of my mappings.

 - mitya


--
Lark's Tongue Guide to Python: http://lightbird.net/larks/

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


Re: Inserting Unicode chars in Entry widget

2012-12-29 Thread Irmen de Jong
On 29-12-2012 18:23, Chris Angelico wrote:
> On Sun, Dec 30, 2012 at 4:11 AM, Irmen de Jong  wrote:
>> b1=Button(f, text='char1', command=lambda b=1: insert_char(b))
>> b2=Button(f, text='char2', command=lambda b=2: insert_char(b))
>> ...etc..
>>
>> def insert_char(b):
>> if b==1:
>> entrywidget.insert(0, u"\u20ac")   # inserts € in the entry widget e
>> elif b==2:
>> entrywidget.insert(0, ...some other char...)
>> ...
> 
> I'm not familiar with tkinter syntax, but why not:
> 
> b1=Button(f, text='char1', command=lambda: insert_char(1))
> b2=Button(f, text='char2', command=lambda: insert_char(2))
> 
> or even:
> 
> b1=Button(f, text='char1', command=lambda: insert_char(u"\u20ac"))
> b2=Button(f, text='char2', command=lambda: insert_char("... some other
> char..."))
> 
> Seems weird to multiplex like that, but if there's a good reason for
> it, sure. I'm more of a GTK person than tkinter, and more of a
> command-line guy than either of the above.
> 
> ChrisA
> 

You're right there's nothing special about tkinter there, I was copying some 
existing
code a bit too literally. Simplify the lambdas as needed. :)

Irmen

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


Re: Py 3.3, unicode / upper()

2012-12-29 Thread wxjmfauth
Le mercredi 19 décembre 2012 16:33:50 UTC+1, Christian Heimes a écrit :
> 
> I think Python 3.3+ is using uppercase mapping (uc) instead of simple
> 
> upper case (suc).

I think you are thinking correctly. This a clever answer.

Note: I do not care about the uc / suc choice. As long
there is consistency, I'm fine with the choice. Anyway, the
only valid "programming technique" on that field is to create
a dedicated lib for a given script (esp. French!)

jmf



> 
> 
> 
> 
> 
> Some background:
> 
> 
> 
> The old German Fractur has three variants of the letter S:
> 
> 
> 
>  capital s: S
> 
>  long s: ſ
> 
>  round s: s.
> 
> 
> 
> ß is a ligature of ſs. ſ is usually used at the beginning or middle of a
> 
> syllable while s is used at the end of a syllable. Compare Wachſtube
> 
> (Wach-Stube == guard room) to Wachstube (Wachs-Tube == tube of wax). :)
> 
> 
> 
> Christian

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


dict comprehension question.

2012-12-29 Thread Quint Rankid
Newbie question.  I've googled a little and haven't found the answer.

Given a list like:
w = [1, 2, 3, 1, 2, 4, 4, 5, 6, 1]
I would like to be able to do the following as a dict comprehension.
a = {}
for x in w:
a[x] = a.get(x,0) + 1
results in a having the value:
{1: 3, 2: 2, 3: 1, 4: 2, 5: 1, 6: 1}

I've tried a few things
eg
a1 = {x:self.get(x,0)+1 for x in w}
results in error messages.

And
a2 = {x:a2.get(x,0)+1 for x in w}
also results in error messages.

Trying to set a variable to a dict before doing the comprehension
a3 = {}
a3 = {x:a3.get(x,0)+1 for x in w}
gets this result, which isn't what I wanted.
{1: 1, 2: 1, 3: 1, 4: 1, 5: 1, 6: 1}

I'm not sure that it's possible to do this, and if not, perhaps the
most obvious question is what instance does the get method bind to?

TIA
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: New to python, do I need an IDE or is vim still good enough?

2012-12-29 Thread Roy Smith
Monte Milanuk  wrote:
> > Maybe its because I'm still just a hobbyist when it comes to coding, but I
> > spend far more time 'thinking' about what I'm doing than typing things in...

If more "professional" programmers spent more time thinking and less 
type typing, the world would be a better place.  Keep doing what you're 
doing.  Really. 

Chris Angelico  wrote:
[regarding 
> Bracket matching
> Language-sensitive auto-indentation
> and automatically indents

Yeah, what he said, plus syntax coloring.  And keyword highlighting.  
And autocompletion of variable names.

And parsing of error messages.

I'll pause a moment to let that sink in.  Grok the fullness of just how 
awesome a feature it is.

In emacs, for example. I'll do C-C M (which I have bound to M-X 
Compile).  This runs a command and captures the output in a buffer.  If 
the output happens to contain something like:

Traceback (most recent call last):
  File 
"/home/roy/production/python/local/lib/python2.7/site-packages/nose/case.
py", line 197, in runTest
self.test(*self.arg)
  File "/home/roy/songza/api2/test_api2.py", line 16, in test_get_api
data = requests.get(url('api/v2/')).json
  File "/home/roy/songza/api2/test_common.py", line 13, in url
assert route.startswith('/')
AssertionError

emacs will parse that, highlight the filenames and line numbers and if I 
type M-`, it'll take me to the line of the next error (including opening 
the file if it's not already open).

I assume other smart editors have similar capabilities.  Different tools 
have different combinations of these, or slightly different 
implementations.  Find one you like and learn all of it's capabilities.  
It makes a huge difference in how productive you are.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: dict comprehension question.

2012-12-29 Thread Roy Smith
In article 
<724d4fea-606a-4503-b538-87442f6bc...@ci3g2000vbb.googlegroups.com>,
 Quint Rankid  wrote:

> Newbie question.  I've googled a little and haven't found the answer.
> 
> Given a list like:
> w = [1, 2, 3, 1, 2, 4, 4, 5, 6, 1]
> I would like to be able to do the following as a dict comprehension.
> a = {}
> for x in w:
> a[x] = a.get(x,0) + 1

Why are you trying to do this mind-blowing thing?  Other than as an 
entry in an obfuscated code contest, what is this for?

Anyway, I don't think this is possible with a dict comprehension.  
Entries in the dict depend on entries previously put into the dict.  I 
don't see any way a dict comprehension can deal with this.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: dict comprehension question.

2012-12-29 Thread Mitya Sirenef

On 12/29/2012 02:48 PM, Quint Rankid wrote:

Newbie question.  I've googled a little and haven't found the answer.

Given a list like:
w = [1, 2, 3, 1, 2, 4, 4, 5, 6, 1]
I would like to be able to do the following as a dict comprehension.
a = {}
for x in w:
 a[x] = a.get(x,0) + 1
results in a having the value:
{1: 3, 2: 2, 3: 1, 4: 2, 5: 1, 6: 1}

I've tried a few things
eg
a1 = {x:self.get(x,0)+1 for x in w}
results in error messages.

And
a2 = {x:a2.get(x,0)+1 for x in w}
also results in error messages.

Trying to set a variable to a dict before doing the comprehension
a3 = {}
a3 = {x:a3.get(x,0)+1 for x in w}
gets this result, which isn't what I wanted.
{1: 1, 2: 1, 3: 1, 4: 1, 5: 1, 6: 1}

I'm not sure that it's possible to do this, and if not, perhaps the
most obvious question is what instance does the get method bind to?

TIA


Will this do?:

>>> w = [1, 2, 3, 1, 2, 4, 4, 5, 6, 1]
>>> {x: w.count(x) for x in w}
{1: 3, 2: 2, 3: 1, 4: 2, 5: 1, 6: 1}


 - mitya

--
Lark's Tongue Guide to Python: http://lightbird.net/larks/

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


Re: dict comprehension question.

2012-12-29 Thread Mitya Sirenef

On 12/29/2012 03:01 PM, Mitya Sirenef wrote:

On 12/29/2012 02:48 PM, Quint  Rankid wrote:

>> Newbie question. I've googled a little and haven't found the answer.
>>
>> Given a list like:
>> w = [1, 2, 3, 1, 2, 4, 4, 5, 6, 1]
>> I would like to be able to do the following as a dict comprehension.
>> a = {}
>> for x in w:
>> a[x] = a.get(x,0) + 1
>> results in a having the value:
>> {1: 3, 2: 2, 3: 1, 4: 2, 5: 1, 6: 1}
>>
>> I've tried a few things
>> eg
>> a1 = {x:self.get(x,0)+1 for x in w}
>> results in error messages.
>>
>> And
>> a2 = {x:a2.get(x,0)+1 for x in w}
>> also results in error messages.
>>
>> Trying to set a variable to a dict before doing the comprehension
>> a3 = {}
>> a3 = {x:a3.get(x,0)+1 for x in w}
>> gets this result, which isn't what I wanted.
>> {1: 1, 2: 1, 3: 1, 4: 1, 5: 1, 6: 1}
>>
>> I'm not sure that it's possible to do this, and if not, perhaps the
>> most obvious question is what instance does the get method bind to?
>>
>> TIA
>
> Will this do?:
>
> >>> w = [1, 2, 3, 1, 2, 4, 4, 5, 6, 1]
> >>> {x: w.count(x) for x in w}
> {1: 3, 2: 2, 3: 1, 4: 2, 5: 1, 6: 1}
>
>
> - mitya
>

I should probably add that this might be inefficient for large lists as
it repeats count for each item. If you need it for large lists, profile
against the 'for loop' version and decide if performance is good enough
for you, for small lists it's a nice and compact solution.

In a more general case, you can't refer to the list/dict/etc
comprehension as it's being constructed, that's just not a design goal
of comprehensions.

 -m

--
Lark's Tongue Guide to Python: http://lightbird.net/larks/

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


Re: dict comprehension question.

2012-12-29 Thread Joel Goldstick
On Sat, Dec 29, 2012 at 3:09 PM, Mitya Sirenef wrote:

> On 12/29/2012 03:01 PM, Mitya Sirenef wrote:
>
>> On 12/29/2012 02:48 PM, Quint  Rankid wrote:
>>
> >> Newbie question. I've googled a little and haven't found the answer.
> >>
> >> Given a list like:
> >> w = [1, 2, 3, 1, 2, 4, 4, 5, 6, 1]
> >> I would like to be able to do the following as a dict comprehension.
> >> a = {}
> >> for x in w:
> >> a[x] = a.get(x,0) + 1
> >> results in a having the value:
> >> {1: 3, 2: 2, 3: 1, 4: 2, 5: 1, 6: 1}
> >>
> >> I've tried a few things
> >> eg
> >> a1 = {x:self.get(x,0)+1 for x in w}
> >> results in error messages.
> >>
> >> And
> >> a2 = {x:a2.get(x,0)+1 for x in w}
> >> also results in error messages.
> >>
> >> Trying to set a variable to a dict before doing the comprehension
> >> a3 = {}
> >> a3 = {x:a3.get(x,0)+1 for x in w}
> >> gets this result, which isn't what I wanted.
> >> {1: 1, 2: 1, 3: 1, 4: 1, 5: 1, 6: 1}
> >>
> >> I'm not sure that it's possible to do this, and if not, perhaps the
> >> most obvious question is what instance does the get method bind to?
> >>
> >> TIA
> >
> > Will this do?:
> >
> > >>> w = [1, 2, 3, 1, 2, 4, 4, 5, 6, 1]
> > >>> {x: w.count(x) for x in w}
> > {1: 3, 2: 2, 3: 1, 4: 2, 5: 1, 6: 1}
> >
> >
> > - mitya
> >
>
> I should probably add that this might be inefficient for large lists as
> it repeats count for each item. If you need it for large lists, profile
> against the 'for loop' version and decide if performance is good enough
> for you, for small lists it's a nice and compact solution.
>
> In a more general case, you can't refer to the list/dict/etc
> comprehension as it's being constructed, that's just not a design goal
> of comprehensions.
>

Would this help:

 >>> w = [1,2,3,1,2,4,4,5,6,1]
 >>> s = set(w)
 >>> s
 set([1, 2, 3, 4, 5, 6])
 >>> {x:w.count(x) for x in s}
 {1: 3, 2: 2, 3: 1, 4: 2, 5: 1, 6: 1}
>>>


>  -m
>
>
> --
> Lark's Tongue Guide to Python: http://lightbird.net/larks/
>
> --
> http://mail.python.org/**mailman/listinfo/python-list
>



-- 
Joel Goldstick
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: dict comprehension question.

2012-12-29 Thread Peter Otten
Quint Rankid wrote:

> Newbie question.  I've googled a little and haven't found the answer.
> 
> Given a list like:
> w = [1, 2, 3, 1, 2, 4, 4, 5, 6, 1]
> I would like to be able to do the following as a dict comprehension.
> a = {}
> for x in w:
> a[x] = a.get(x,0) + 1
> results in a having the value:
> {1: 3, 2: 2, 3: 1, 4: 2, 5: 1, 6: 1}
> 
> I've tried a few things
> eg
> a1 = {x:self.get(x,0)+1 for x in w}
> results in error messages.
> 
> And
> a2 = {x:a2.get(x,0)+1 for x in w}
> also results in error messages.
> 
> Trying to set a variable to a dict before doing the comprehension
> a3 = {}
> a3 = {x:a3.get(x,0)+1 for x in w}
> gets this result, which isn't what I wanted.
> {1: 1, 2: 1, 3: 1, 4: 1, 5: 1, 6: 1}
> 
> I'm not sure that it's possible to do this, and if not, perhaps the
> most obvious question is what instance does the get method bind to?

The name a3 will not be rebound until after the right side is evaluate. To 
spell it with a loop:

a3 = {}
_internal = {} # You have no access to this var. 
   # Even if you can beat a particular 
   # Python implementation -- you shouldn't

for x in w:
_internal[x] = a3.get(x, 0) + 1

a3 = _internal

That should make it clear that x will be looked up in the "old" empty a3 
dict.

The closest you can get to a self-updating dict is probably

>>> w = [1, 2, 3, 1, 2, 4, 4, 5, 6, 1]
>>> a1 = {}
>>> a1.update((x, a1.get(x, 0)+1) for x in w)
>>> a1
{1: 3, 2: 2, 3: 1, 4: 2, 5: 1, 6: 1}

but that it works doesn't mean it is a good idea. 
If your Python version supports it the obvious choice is

>>> from collections import Counter
>>> w = [1, 2, 3, 1, 2, 4, 4, 5, 6, 1]
>>> Counter(w)
Counter({1: 3, 2: 2, 4: 2, 3: 1, 5: 1, 6: 1})


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


Re: dict comprehension question.

2012-12-29 Thread MRAB

On 2012-12-29 19:48, Quint Rankid wrote:

Newbie question.  I've googled a little and haven't found the answer.

Given a list like:
w = [1, 2, 3, 1, 2, 4, 4, 5, 6, 1]
I would like to be able to do the following as a dict comprehension.
a = {}
for x in w:
 a[x] = a.get(x,0) + 1
results in a having the value:
{1: 3, 2: 2, 3: 1, 4: 2, 5: 1, 6: 1}

I've tried a few things
eg
a1 = {x:self.get(x,0)+1 for x in w}
results in error messages.

And
a2 = {x:a2.get(x,0)+1 for x in w}
also results in error messages.

Trying to set a variable to a dict before doing the comprehension
a3 = {}
a3 = {x:a3.get(x,0)+1 for x in w}
gets this result, which isn't what I wanted.
{1: 1, 2: 1, 3: 1, 4: 1, 5: 1, 6: 1}

I'm not sure that it's possible to do this, and if not, perhaps the
most obvious question is what instance does the get method bind to?


You can't do it with a comprehension.

The best way is probably with the 'Counter' class:

>>> w = [1, 2, 3, 1, 2, 4, 4, 5, 6, 1]
>>> from collections import Counter
>>> Counter(w)
Counter({1: 3, 2: 2, 4: 2, 3: 1, 5: 1, 6: 1})

If you want the result be a dict, then just the result to 'dict':

>>> dict(Counter(w))
{1: 3, 2: 2, 3: 1, 4: 2, 5: 1, 6: 1}

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


new pipeline manager, feedback welcome

2012-12-29 Thread franapoli
Hi all,

I hope this post can be of interest to someone of you. I'm the developer of a 
pipeline management system called Leaf (the Python library is called pyleaf). 
While initially developed for internal use only at my dpt., we tried to make it 
a decent standalone tool for everyone interested. You can find it at 
www.neuronelab.dmi.unisa.it/leaf.

Briefly, a pipeline manager is basically a system that helps you automating 
common tasks that arise in a pipes-and-filters processing context. That is: you 
have some data and want to process them through different series of cascading 
filters (python functions). Example:

  / filter1 -> filter2
data <
  \ filter3

The example above is actually in Leaf language and can be exploited directly in 
a Python environment thanks to the library pyleaf. Other nice pipeline managers 
exist, like Ruffus, but this ASCII-art approach is peculiar to Leaf.

We use the tool on a daily basis and are quite happy with it, but feedback from 
different users would be of great help to improve its stability and usability.

Pyleaf sources are available on git-hub, that also supports an issue tracker 
(empty at the moment):

https://github.com/franapoli/pyleaf


Thank you very much in advance for your interest. Any feedback appreciated.
Cheers,
Francesco.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Facing issue with Python loggin logger for printing object value

2012-12-29 Thread Morten Engvoldsen
Hi Dave,
It is able to log the message with:
logger.debug("value of payment_line is " +repr(payment_line))

The output is:
value of payment_line is []

So it means payment_line is an empty list, so may be it could be reason
it's not able to enter into the loop since the message in the for loop is
not logged in the log file.

Thanks and good night.. :)


On Sat, Dec 29, 2012 at 7:38 PM, Morten Engvoldsen wrote:

> Hi Dev,
> Thanks a lot Dev for your reply. It is really a great help.  Yes i have
> fixed what was wrong in the create method like log.debug. I have declared
> line_counter=1 before the for loop.  i will try now to chcek the value of
> payment_line.
>
> Thanks again a lot. I am greateful be a member of this forum :)
>
> On Sat, Dec 29, 2012 at 6:10 PM, Dave Angel  wrote:
>
>> On 12/29/2012 11:54 AM, Morten Engvoldsen wrote:
>> > Hi Dave,
>> > Thanks a lot for your reply. I have used logging.setLevel(logger.DEBUG)
>> > because of threshold as you said.
>> >
>> > I didn't copy paste the entire program since it was very huge. The
>> "batch "
>> > which value i am trying to retrieve is in a a for loop :
>> >
>> > for payment in payment_line:
>> >
>> > but here payment_line has null value since it was not able to retrieve
>> > payment line value from the payment object.
>>
>> The closest thing Python has to "null value" is called None.  If
>> payment_line is None, then you'll get an exception on that loop.
>>
>> As I said a while ago, I have no idea how openerp handles exceptions.
>> Maybe it's just doing a bare except, and ignoring anything that goes
>> wrong in your functions.  (Very bad practice)
>>
>> It could be that payment_line is an empty list.  In that case, the loop
>> will execute zero times.  That would also explain the lack of output.
>>
>> So if openerp gives you no debugging aid, then you may have to fake it
>> with the logger.  How about logging a simple message just before the loop?
>>
>> logger.debug("value of payment_line is " + repr(payment_line))
>>
>> Did you ever fix the other things wrong with that create method?  Like
>> using log.debug when the object was called logger?  Or incrementing
>> line_counter when there was no such variable, and when it would vanish
>> when you exited the method anyway?
>>
>>
>>
>> --
>>
>> DaveA
>>
>
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: New to python, do I need an IDE or is vim still good enough?

2012-12-29 Thread Monte Milanuk

On 12/29/2012 11:52 AM, Roy Smith wrote:


Chris Angelico  wrote:
[regarding

Bracket matching
Language-sensitive auto-indentation
and automatically indents


Yeah, what he said, plus syntax coloring.  And keyword highlighting.
And autocompletion of variable names.


I'll probably get dog-piled by the vim/emacs folks again here... but 
isn't that something most decent text editors do?



On 12/29/2012 11:52 AM, Roy Smith wrote:


And parsing of error messages.

I'll pause a moment to let that sink in.  Grok the fullness of just how
awesome a feature it is.

In emacs, for example. I'll do C-C M (which I have bound to M-X
Compile).  This runs a command and captures the output in a buffer.  If
the output happens to contain something like:

Traceback (most recent call last):
   File
"/home/roy/production/python/local/lib/python2.7/site-packages/nose/case.
py", line 197, in runTest
 self.test(*self.arg)
   File "/home/roy/songza/api2/test_api2.py", line 16, in test_get_api
 data = requests.get(url('api/v2/')).json
   File "/home/roy/songza/api2/test_common.py", line 13, in url
 assert route.startswith('/')
AssertionError

emacs will parse that, highlight the filenames and line numbers and if I
type M-`, it'll take me to the line of the next error (including opening
the file if it's not already open).

I assume other smart editors have similar capabilities.  Different tools
have different combinations of these, or slightly different
implementations.  Find one you like and learn all of it's capabilities.
It makes a huge difference in how productive you are.




While I probably don't use the vast majority of the 'fancy' features of 
most IDEs - most of what I do barely requires any real 'project 
manangement'... there are a couple things that I've gotten *very* used 
to with an IDE.


One is having it run pylint and pep8 checks against code, display the 
output in a friendly format with links straight to the offending items 
and even displaying colored carats in the gutter region and 
high-lighting them.


The other is having it parse my imports, and use them for the 
'auto-complete' aka 'code intelligence' features - and not just the 
standard library stuff, but also GUI toolkits like PyQt4.


I'm pretty sure those things can be done, or something fairly close at 
least, in editors like vim or emacs... but the few times I looked into 
it for vim, it was enough to send me running back to Eclipse/PyDev, even 
if it is kind of an 800lb gorilla otherwise.


It's still on my 'one of these days' list of things to do, though ;)



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


Re: Facing issue with Python loggin logger for printing object value

2012-12-29 Thread Mitya Sirenef

On 12/29/2012 03:50 PM, Morten Engvoldsen wrote:

Hi Dave,

> It is able to log the message with:
> logger.debug("value of payment_line is " +repr(payment_line))
>
> The output is:
> value of payment_line is []
>
> So it means payment_line is an empty list, so may be it could be 
reason it's not able to enter into the loop since the message in the for 
loop is not logged in the log file.

>
> Thanks and good night.. :)


You can easily test how iteration over empty list works:



l=[]

>>> for x in l: print(x)
...




i.e. nothing is printed because loop runs 0 times.


 -m



--
Lark's Tongue Guide to Python: http://lightbird.net/larks/

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


Re: Facing issue with Python loggin logger for printing object value

2012-12-29 Thread Roy Smith
In article ,
 Morten Engvoldsen  wrote:

> It is able to log the message with:
> logger.debug("value of payment_line is " +repr(payment_line))

As a side note, a better way to write that is

logger.debug("value of payment_line is %r", payment_line)

The difference is that the first way, repr(payment_line) is evaluated, 
and the string addition is done, before debug() is called.  Only then 
will it be decided if message should be logged, and if not, it will be 
discarded.

The second way, payment_line will just get passed to debug().  If the 
message is never logged, repr() will never get called.  Much more 
efficient that way, especially for debug calls which most of the time 
will not get logged.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: New to python, do I need an IDE or is vim still good enough?

2012-12-29 Thread Chris Angelico
On Sun, Dec 30, 2012 at 6:52 AM, Roy Smith  wrote:
> Chris Angelico  wrote:
> [regarding
>> Bracket matching
>> Language-sensitive auto-indentation
>> and automatically indents
>
> Yeah, what he said, plus syntax coloring.  And keyword highlighting.
> And autocompletion of variable names.

Syntax coloring I kinda touched on in different pieces; keyword
highlighting isn't, imho, all that important. Apart from reminding you
that the variable name you planned to use is an obscure keyword, it
doesn't save all that much time. Auto-complete is handy, but not
critical.

> And parsing of error messages.
>
> I'll pause a moment to let that sink in.  Grok the fullness of just how
> awesome a feature it is.

And how glaring an omission from my list. Yes. This one *definitely*
belongs there. Though unlike most of the other examples, it's not as
language-specific; you can cover a huge number of utilities by simply
recognizing:

filename:line: message

Coupled with a helpful C compiler, this lets you jump around pretty
easily. For instance, gcc will (if I recall correctly - haven't had to
use this feature in a while, something to do with writing more code in
Python and Pike than C, but anyway), if the arguments to a function
mismatch, show error lines highlighting both the invocation *and* the
declaration, so you can quickly compare (even if they're in different
files).

> emacs will parse that, highlight the filenames and line numbers and if I
> type M-`, it'll take me to the line of the next error (including opening
> the file if it's not already open).
>
> I assume other smart editors have similar capabilities.

Yeah, SciTE has F4 and Shift-F4 to cycle forwards/backwards through
messages, and I expect it's pretty much standard among editors that
can invoke external tools. It's extremely handy; not only errors from
compilation/execution, but things like a 'git grep -n' fit too.

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


Re: dict comprehension question.

2012-12-29 Thread Mitya Sirenef

On 12/29/2012 03:15 PM, Joel Goldstick wrote:




On Sat, Dec 29, 2012 at 3:09 PM, Mitya Sirenef > wrote:


On 12/29/2012 03:01 PM, Mitya Sirenef wrote:

On 12/29/2012 02:48 PM, Quint  Rankid wrote:

>> Newbie question. I've googled a little and haven't found the
answer.
>>
>> Given a list like:
>> w = [1, 2, 3, 1, 2, 4, 4, 5, 6, 1]
>> I would like to be able to do the following as a dict
comprehension.
>> a = {}
>> for x in w:
>> a[x] = a.get(x,0) + 1
>> results in a having the value:
>> {1: 3, 2: 2, 3: 1, 4: 2, 5: 1, 6: 1}
>>
>> I've tried a few things
>> eg
>> a1 = {x:self.get(x,0)+1 for x in w}
>> results in error messages.
>>
>> And
>> a2 = {x:a2.get(x,0)+1 for x in w}
>> also results in error messages.
>>
>> Trying to set a variable to a dict before doing the comprehension
>> a3 = {}
>> a3 = {x:a3.get(x,0)+1 for x in w}
>> gets this result, which isn't what I wanted.
>> {1: 1, 2: 1, 3: 1, 4: 1, 5: 1, 6: 1}
>>
>> I'm not sure that it's possible to do this, and if not, perhaps the
>> most obvious question is what instance does the get method bind to?
>>
>> TIA
>
> Will this do?:
>
> >>> w = [1, 2, 3, 1, 2, 4, 4, 5, 6, 1]
> >>> {x: w.count(x) for x in w}
> {1: 3, 2: 2, 3: 1, 4: 2, 5: 1, 6: 1}
>
>
> - mitya
>

I should probably add that this might be inefficient for large
lists as
it repeats count for each item. If you need it for large lists,
profile
against the 'for loop' version and decide if performance is good
enough
for you, for small lists it's a nice and compact solution.

In a more general case, you can't refer to the list/dict/etc
comprehension as it's being constructed, that's just not a design goal
of comprehensions.


Would this help:

 >>> w = [1,2,3,1,2,4,4,5,6,1]
 >>> s = set(w)
 >>> s
 set([1, 2, 3, 4, 5, 6])
 >>> {x:w.count(x) for x in s}
 {1: 3, 2: 2, 3: 1, 4: 2, 5: 1, 6: 1}
>>>



Indeed, this is much better -- I didn't think of it..


--
Lark's Tongue Guide to Python: http://lightbird.net/larks/

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


Re: New to python, do I need an IDE or is vim still good enough?

2012-12-29 Thread Roy Smith
In article ,
 Chris Angelico  wrote:

> Auto-complete is handy, but not critical.

You just wait until your finger joints get to be my age and tell me that 
auto-complete isn't critical :-)

> It's extremely handy; not only errors from
> compilation/execution, but things like a 'git grep -n' fit too.

Emacs has integrations with many version control systems.  Over the 
years, I've gone back and forth over whether I do my version control 
from within emacs or at the command line.

These days (with mercurial), I tend to do most vc-things at the command 
line.  But, I'm addicted to C-x v = (hg diff).  It diffs the current 
buffer against the last checked-in version of the file, and can take me 
directly to any particular changed line.

Again, I would imagine any decent editor these days would have something 
similar.  It just blows my mind when I see people editing program text 
with NotePad or some similar piece of crap.

Oh, yeah, one other thing I forgot.  You want to use an editor which can 
(preferably as something you can turn on and off easily) put line 
numbers down the left margin of the screen.  For solo editing, it's kind 
of silly.  But if you're doing any kind of pair programming, code 
review, or presentation to a group, it's invaluable.  Compare and 
contrast:

"In the big for loop, a couple of lines down, no, not there, the other 
for loop, yeah, now go down a couple of lines, no that's too far, back 
up one.  Yeah there.  On that line, why do you ..."

with:

"On line 647, why do you ..."
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: New to python, do I need an IDE or is vim still good enough?

2012-12-29 Thread Mitya Sirenef

On 12/29/2012 04:52 PM, Roy Smith wrote:

"In the big for loop, a couple  of lines down, no, not there, the other

> for loop, yeah, now go down a couple of lines, no that's too far, back
> up one. Yeah there. On that line, why do you ..."
>
> with:
>
> "On line 647, why do you ..."


It's even better when it prints line # from top of screen, I have a
handy mapping that jumps directly to a line # and it's much easier to
type 23 or 9 when you jump around a lot.

 - mitya

--
Lark's Tongue Guide to Python: http://lightbird.net/larks/

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


Re: New to python, do I need an IDE or is vim still good enough?

2012-12-29 Thread Chris Angelico
On Sun, Dec 30, 2012 at 8:52 AM, Roy Smith  wrote:
> In article ,
>  Chris Angelico  wrote:
>
>> It's extremely handy; not only errors from
>> compilation/execution, but things like a 'git grep -n' fit too.
>
> Emacs has integrations with many version control systems.  Over the
> years, I've gone back and forth over whether I do my version control
> from within emacs or at the command line.

My point was that it fits _many_ tools, without specific integration
with the tool. But yes, version control integration is a useful tool
(though not one I've personally made use of - I just run git commands
from the command line).

> Again, I would imagine any decent editor these days would have something
> similar.  It just blows my mind when I see people editing program text
> with NotePad or some similar piece of crap.

Yes. And then hopping over to Stack Overflow and trying to figure out
why their PHP script won't create HTTP headers. Combination of poor
language and poor editor...

> Oh, yeah, one other thing I forgot.  You want to use an editor which can
> (preferably as something you can turn on and off easily) put line
> numbers down the left margin of the screen.  For solo editing, it's kind
> of silly.  But if you're doing any kind of pair programming, code
> review, or presentation to a group, it's invaluable.  Compare and
> contrast:
>
> "In the big for loop, a couple of lines down, no, not there, the other
> for loop, yeah, now go down a couple of lines, no that's too far, back
> up one.  Yeah there.  On that line, why do you ..."
>
> with:
>
> "On line 647, why do you ..."

Absolutely! Though it's roughly as good to have the current cursor
position shown in a status line somewhere, and takes up less real
estate. But yes, vital to be able to see that. Even when I'm sitting
*right next to* my boss and communicating verbally, I'll talk about
the code by quoting line numbers. "Let me explain. (No, there is too
much. Let me sum up.) Pull up foobar dot jay ess and go to line
254-ish - see how the frobnosticator always gets called with a quuxed
argument?"

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


Re: New to python, do I need an IDE or is vim still good enough?

2012-12-29 Thread Mitya Sirenef

On 12/29/2012 05:30 PM, Chris Angelico wrote:

"In the big for loop, a couple of lines down, no, not there, the other
>for loop, yeah, now go down a couple of lines, no that's too far, back
>up one.  Yeah there.  On that line, why do you ..."
>
>with:
>
>"On line 647, why do you ..."

Absolutely! Though it's roughly as good to have the current cursor
position shown in a status line somewhere, and takes up less real
estate.


I have to disagree -- if someone is standing next to you
and they want to refer to a particular line, they can't
really tell you "move the cursor to that line there, so I
can read its line number from status line and then tell
you I'm referring to that line".

 - mitya

--
Lark's Tongue Guide to Python: http://lightbird.net/larks/

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


Re: New to python, do I need an IDE or is vim still good enough?

2012-12-29 Thread Chris Angelico
On Sun, Dec 30, 2012 at 9:40 AM, Mitya Sirenef  wrote:
> On 12/29/2012 05:30 PM, Chris Angelico wrote:
>>>
>>> "In the big for loop, a couple of lines down, no, not there, the other
>>> >for loop, yeah, now go down a couple of lines, no that's too far, back
>>> >up one.  Yeah there.  On that line, why do you ..."
>>> >
>>> >with:
>>> >
>>> >"On line 647, why do you ..."
>>
>> Absolutely! Though it's roughly as good to have the current cursor
>> position shown in a status line somewhere, and takes up less real
>> estate.
>
>
> I have to disagree -- if someone is standing next to you
> and they want to refer to a particular line, they can't
> really tell you "move the cursor to that line there, so I
> can read its line number from status line and then tell
> you I'm referring to that line".

Ah, to clarify: We have our separate computers in front of us. So when
I quote a line number, it's by looking at my screen, and allows him to
synchronize his display.

Of course, if you can afford the real estate, and as long as they're
not distracting, a column of numbers doesn't hurt.

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


Re: dict comprehension question.

2012-12-29 Thread Terry Reedy

On 12/29/2012 4:40 PM, Mitya Sirenef wrote:

On 12/29/2012 03:15 PM, Joel Goldstick wrote:



Would this help:

 >>> w = [1,2,3,1,2,4,4,5,6,1]
 >>> s = set(w)
 >>> s
 set([1, 2, 3, 4, 5, 6])
 >>> {x:w.count(x) for x in s}
 {1: 3, 2: 2, 3: 1, 4: 2, 5: 1, 6: 1}
>>>



Indeed, this is much better -- I didn't think of it..


It still turns an O(n) problem into an O(k*n) problem, where k is the 
number of distinct items.


--
Terry Jan Reedy

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


Re: dict comprehension question.

2012-12-29 Thread Terry Reedy

On 12/29/2012 2:48 PM, Quint Rankid wrote:


Given a list like:
w = [1, 2, 3, 1, 2, 4, 4, 5, 6, 1]
I would like to be able to do the following as a dict comprehension.
a = {}
for x in w:
 a[x] = a.get(x,0) + 1
results in a having the value:
{1: 3, 2: 2, 3: 1, 4: 2, 5: 1, 6: 1}


Let me paraphrase this: "I have nice, clear, straightforward, 
*comprehensible* code that I want to turn into an incomprehensible mess 
with a 'comprehension." That is the ironic allure of comprehensions.


Comprehensions do not allow for interactions between the source items. 
Mitya and Joel worked around this with solutions that do redundant 
calculation and multiply the time order.


Reductions do allow for interactions. Doing everything as a reduction 
was the fad before comprehensions came along ;-)


from functools import reduce
w = [1, 2, 3, 1, 2, 4, 4, 5, 6, 1]
def update(dic, n):
"Mutate and return dic (contrary to usual Python policy)"
dic[n] = dic.get(n, 0) + 1
return dic
counts = reduce(update, w, {})
print(counts == {1: 3, 2: 2, 3: 1, 4: 2, 5: 1, 6: 1})

# prints True

The above is how to rewrite your code in a functional language that does 
not have statements and explicit iteration. In Python, I would only 
bother to wrap the body of the loop in a function if I needed the same 
body in multiple places.


Comprehensions are filtered mappings and that both filter and map can be 
written as reduction, so reduction included comprehension. It is more 
powerful because it can also do sequential interaction. Indeed, I would 
say that it should only be used when there is sequential interaction.


--
Terry Jan Reedy

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


Re: Confused about logger config from within Python (3)

2012-12-29 Thread Terry Reedy

On 12/29/2012 8:48 AM, Roy Smith wrote:

In article <50de7a0a$0$29967$c3e8da3$54964...@news.astraweb.com>,
  Steven D'Aprano  wrote:


In Python 3.2 and 3.3, the message about no handlers is not printed,
which is an interesting difference. (Somebody who knows more about the
logging package than I do might be able to state why that difference.)


I hope that means that http://bugs.python.org/issue994421 has finally
been fixed :-)


I added an update ;-).

If Vijay wanted the message to be a warning rather than an exception, 
the warnings module and mechanism could have been used (once it was 
available -- I am not sure when that was). But I think a default handler 
is even better.


Given that you disagreed with his disposition of the issue, you might 
have posted to this list for other opinions.


I also hope you appreciate that Vijay has stuck with maintenance and 
upgrade of the module for nearly a decade now.


--
Terry Jan Reedy

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


Re: dict comprehension question.

2012-12-29 Thread Tim Chase

On 12/29/12 15:40, Mitya Sirenef wrote:

  >>> w = [1,2,3,1,2,4,4,5,6,1]
  >>> s = set(w)
  >>> s
  set([1, 2, 3, 4, 5, 6])
  >>> {x:w.count(x) for x in s}
  {1: 3, 2: 2, 3: 1, 4: 2, 5: 1, 6: 1}


Indeed, this is much better -- I didn't think of it..


Except that you're still overwhelmed by iterating over every element 
in "w" for every distinct element.  So you've gone from O(N**2) to 
O(k*N).


The cleanest way to write it (IMHO) is MRAB's

 >>> w = [1, 2, 3, 1, 2, 4, 4, 5, 6, 1]
 >>> from collections import Counter
 >>> results = dict(Counter(w))

which should gather all the statistics in one single pass across "w" 
making it O(N), and it's Pythonically readable.


-tkc



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


Re: New to python, do I need an IDE or is vim still good enough?

2012-12-29 Thread Tim Johnson
* Grant Edwards  [121229 10:02]:
> On 2012-12-27, mogul  wrote:
> 
> > I'm new to python, got 10-20 years perl and C experience, all gained
> > on unix alike machines hacking happily in vi, and later on in vim.
> >
> > Now it's python, and currently mainly on my kubuntu desktop.
> >
> > Do I really need a real IDE, as the windows guys around me say I do,
> 
> No.
> 
> > or will vim, git, make and other standalone tools make it the next 20
> > years too for me? 
 
  I've been using vim for 12 years now. And it works pretty good for
  me as an "IDE". I've written a lot of vimscripts to make vim
  better do my bidding and made generous use of contributed scripts.

  I see no reason to think that I would be more productive using
  anything else, but that is just me.

  Along the way, I did use emacs as well and ended doing quite a bit
  of elisping.

  Elisp does have the advantage of asynchronously running the
  interpereter inside of the editor Just one thing that I
  wouldn't mind seeing in vim.

  I do find vim a bit more nimble than emacs, but each to his/her
  own. It's wonderful to have all of the choices.

  """
  They'll take away my vim when they pry it from my cold, dead
  fingers.
  """
-- 
Tim 
tim at tee jay forty nine dot com or akwebsoft dot com
http://www.akwebsoft.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: New to python, do I need an IDE or is vim still good enough?

2012-12-29 Thread Chris Angelico
On Sun, Dec 30, 2012 at 11:38 AM, Tim Johnson  wrote:
> Along the way, I did use emacs as well and ended doing quite a bit
>   of elisping.

elispsis. n. the intentional omission of unnecessary work which can be
inferred by the editor; often indicated with three consecutive
parentheses ((( )))

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


Re: Confused about logger config from within Python (3)

2012-12-29 Thread Roy Smith
In article ,
 Terry Reedy  wrote:

> On 12/29/2012 8:48 AM, Roy Smith wrote:
> > In article <50de7a0a$0$29967$c3e8da3$54964...@news.astraweb.com>,
> >   Steven D'Aprano  wrote:
> >
> >> In Python 3.2 and 3.3, the message about no handlers is not printed,
> >> which is an interesting difference. (Somebody who knows more about the
> >> logging package than I do might be able to state why that difference.)
> >
> > I hope that means that http://bugs.python.org/issue994421 has finally
> > been fixed :-)
> 
> I added an update ;-).
> 
> If Vijay wanted the message to be a warning rather than an exception, 
> the warnings module and mechanism could have been used (once it was 
> available -- I am not sure when that was). But I think a default handler 
> is even better.

Having a default handler is clearly a good fix.

> I also hope you appreciate that Vijay has stuck with maintenance and 
> upgrade of the module for nearly a decade now.

Absolutely.

BTW, I recently discovered a truly awesome thing about logging and 
nosetests.  Apparently, nose attaches a hander to the root logger at 
debug level and buffers anything that gets sent there.  If a test fails, 
it prints anything that logger captured.  So, for example (intentionally 
breaking one of my tests):

 >> begin captured logging << 
requests.packages.urllib3.connectionpool: INFO: Starting new HTTP 
connection (1): localhost.lic.songza.com
requests.packages.urllib3.connectionpool: DEBUG: "GET 
/foo:80/api/v2/?format=json ('HTTP/1.1',)" 404 None
- >> end captured logging << -

This rocks!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: dict comprehension question.

2012-12-29 Thread Joel Goldstick
On Sat, Dec 29, 2012 at 7:26 PM, Tim Chase wrote:

> On 12/29/12 15:40, Mitya Sirenef wrote:
>
>>   >>> w = [1,2,3,1,2,4,4,5,6,1]
>>>   >>> s = set(w)
>>>   >>> s
>>>   set([1, 2, 3, 4, 5, 6])
>>>   >>> {x:w.count(x) for x in s}
>>>   {1: 3, 2: 2, 3: 1, 4: 2, 5: 1, 6: 1}
>>>
>>
>> Indeed, this is much better -- I didn't think of it..
>>
>
> Except that you're still overwhelmed by iterating over every element in
> "w" for every distinct element.  So you've gone from O(N**2) to O(k*N).
>
> The cleanest way to write it (IMHO) is MRAB's
>
>
>  >>> w = [1, 2, 3, 1, 2, 4, 4, 5, 6, 1]
>  >>> from collections import Counter
>  >>> results = dict(Counter(w))
>
> which should gather all the statistics in one single pass across "w"
> making it O(N), and it's Pythonically readable.
>
> -tkc
>
> I like this too.  I haven't learned about collections module yet.  Thanks
for the pointer

>
>
> --
> http://mail.python.org/**mailman/listinfo/python-list
>



-- 
Joel Goldstick
-- 
http://mail.python.org/mailman/listinfo/python-list