Re: MySQLdbd error. Perhpas it isn't installed?

2013-03-26 Thread Νίκος Γκρ33κ
Τη Τετάρτη, 27 Μαρτίου 2013 6:26:06 π.μ. UTC+2, ο χρήστης ru...@yahoo.com 
έγραψε:

> If not, maybe you can try adding a print statement to your code that 
> will print the value of 'page'.  This will be easier to do if you 
> can run you code interactively.  If you have to run it via a webserver
> than maybe you'll need wrap the print output in html commands to make
> it visible on the page, or to write it to a file.


I tried what you suggested by doign the following:

print( page )
sys.exit(0)
cur.execute( '''SELECT hits FROM counters WHERE url = %s''', (page,) )


and the result is printed in the webpage as 'index.html'

so page seem s to be a string but the error is still persistant.
Anything else i need to try?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: honking great ideas

2013-03-26 Thread Sean Felipe Wolfe
On Tue, Mar 26, 2013 at 7:25 PM, Ned Deily  wrote:
> One suggestion: take a look at Raymond Hettinger's keynote address from
> the recent PyCon.  Any of Raymond's talks are worth viewing but this one
> in particular is a higher-level sales pitch for Python:  "Show the
> specific features that make Python more than just another scripting
> language."
>
> http://pyvideo.org/video/1669/keynote-3

Great! I'm taking a look now.
-- 
http://mail.python.org/mailman/listinfo/python-list


Sudoku

2013-03-26 Thread Eric Parry
I downloaded the following program from somewhere using a link from Wikipedia 
and inserted the “most difficult Sudoku puzzle ever” string into it and ran it. 
It worked fine and solved the puzzle in about 4 seconds. However I cannot 
understand how it works. It seems to go backwards and forwards at random. Can 
anyone explain how it works in simple terms?
Eric.


def same_row(i,j): return (i/9 == j/9)
def same_col(i,j): return (i-j) % 9 == 0
def same_block(i,j): return (i/27 == j/27 and i%9/3 == j%9/3)

def r(a):
  i = a.find('0')
  if i == -1:
print a
exit(a)

  excluded_numbers = set()
  for j in range(81):
if same_row(i,j) or same_col(i,j) or same_block(i,j):
  excluded_numbers.add(a[j])

  for m in '123456789':
if m not in excluded_numbers:
  # At this point, m is not excluded by any row, column, or block, so let's 
place it and recurse
  r(a[:i]+m+a[i+1:])

r('80036007009020005000700045701000300016800850001009400')
Sudoku solver where the puzzle is an 81 character string representing the 
puzzle read left-to-right, top-to-bottom, and 0 is a blank.
 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Performance of int/long in Python 3

2013-03-26 Thread rurpy
On Tuesday, March 26, 2013 6:00:43 PM UTC-6, Ned Deily wrote:
> In article ,
>  Mark Lawrence  wrote:
> > But you are an idiot.
> 
> I repeat the friendly reminder I posted a few weeks ago and I'll be a 
> little less oblique: please avoid gratuitous personal attacks here.  It 
> reflects badly on the group and especially on those people making them.  
> We can disagree strongly about technical opinions without resorting to 
> such.
>[..]

+1, thank you for posting that.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: MySQLdbd error. Perhpas it isn't installed?

2013-03-26 Thread rurpy
On 03/26/2013 03:24 PM, Νίκος Γκρ33κ wrote:> Hello today i deiced to go form 
python 2.6 to python 3.2.3
> 
> although in 2.6 my script runs in the ht enewest python i ge this error:
> 
> 
> Traceback (most recent call last):
>   File 
> "/opt/python3/lib/python3.2/site-packages/MySQL_python-1.2.3-py3.2-linux-x86_64.egg/MySQLdb/cursors.py",
>  line 171, in execute
> r = self._query(query)
>   File 
> "/opt/python3/lib/python3.2/site-packages/MySQL_python-1.2.3-py3.2-linux-x86_64.egg/MySQLdb/cursors.py",
>  line 330, in _query
> rowcount = self._do_query(q)
>   File 
> "/opt/python3/lib/python3.2/site-packages/MySQL_python-1.2.3-py3.2-linux-x86_64.egg/MySQLdb/cursors.py",
>  line 294, in _do_query
> db.query(q)
> _mysql_exceptions.ProgrammingError: (1064, "You have an error in your SQL 
> syntax; check the manual that corresponds to your MySQL server version for 
> the right syntax to use near '%s' at line 1")
> 
> During handling of the above exception, another exception occurred:
> 
> Traceback (most recent call last):
>   File "metrites.py", line 193, in 
> cur.execute( '''SELECT hits FROM counters WHERE url = %s''', (page,) )
>   File 
> "/opt/python3/lib/python3.2/site-packages/MySQL_python-1.2.3-py3.2-linux-x86_64.egg/MySQLdb/cursors.py",
>  line 184, in execute
> self.errorhandler(self, exc, value)
>   File 
> "/opt/python3/lib/python3.2/site-packages/MySQL_python-1.2.3-py3.2-linux-x86_64.egg/MySQLdb/connections.py",
>  line 36, in defaulterrorhandler
> raise errorclass(errorvalue)
> _mysql_exceptions.ProgrammingError: (1064, "You have an error in your SQL 
> syntax; check the manual that corresponds to your MySQL server version for 
> the right syntax to use near '%s' at line 1")
> 
> 
> 
> you can also see it at http://superhost.gr
> 
> Any ideas what might be the problem?
> 
> My webhost (hostgator.com) says that The MySQLdb module is already installed 
> for python 3 on this server. 
> 
> Can you please tell me what's the nature of this error?
> 
> Thank you.

This seems to be the problem line of code:

>   File "metrites.py", line 193, in 
> cur.execute( '''SELECT hits FROM counters WHERE url = %s''', (page,) )

If 'page' is not a string as you expect, but is None or (for example)
a list or something else, you might well end up with invalid SQL when
MySQLdb tries to build the executable sql statement.  Sorry I can't 
be more specific -- I haven't used MySQLdb and I'm suggesting what I'd
try for any generic DBI module.

If MySQLdb has a way to turn on debugging so that it prints SQL 
statements before execution, you might want do that.  Then it may be 
obvious what is wrong, or if the SQL still looks ok, try copying it 
and pasting it in a interactive database session to see what error 
occurs.

If not, maybe you can try adding a print statement to your code that
will print the value of 'page'.  This will be easier to do if you 
can run you code interactively.  If you have to run it via a webserver
than maybe you'll need wrap the print output in html commands to make
it visible on the page, or to write it to a file.

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


Re: honking great ideas

2013-03-26 Thread Ned Deily
In article 
,
 Sean Felipe Wolfe  wrote:
> So I have been re-reading some of the python intro stuffs after a time
> away philandering with other languages. I have been thinking about the
> Zen of Python piece where it says 'namespaces are a honking great idea
> - let's do more of those'.
> 
> A question -- since then do we have any sort of list of major
> innovations like that? Do we keep any sort of 'honking great idea
> list' anywhere? Or maybe folks could suggest what some of those
> milestones have been over time?

One suggestion: take a look at Raymond Hettinger's keynote address from 
the recent PyCon.  Any of Raymond's talks are worth viewing but this one 
in particular is a higher-level sales pitch for Python:  "Show the 
specific features that make Python more than just another scripting 
language."

http://pyvideo.org/video/1669/keynote-3

-- 
 Ned Deily,
 n...@acm.org

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


Re: Performance of int/long in Python 3

2013-03-26 Thread Ned Deily
In article ,
 Mark Lawrence  wrote:
> On 27/03/2013 00:00, Ned Deily wrote:
[...]
> > I repeat the friendly reminder I posted a few weeks ago and I'll be a
> > little less oblique: please avoid gratuitous personal attacks here.  It
> > reflects badly on the group and especially on those people making them.
> > We can disagree strongly about technical opinions without resorting to
> > such.
> >
> > On Mon, 11 Mar 2013 11:13:16 -0700, I posted:
> >> A friendly reminder that this forum is for general discussion and
> >> questions about Python.
> >>
> >> "Pretty much anything Python-related is fair game for discussion, and
> >> the group is even fairly tolerant of off-topic digressions; there have
> >> been entertaining discussions of topics such as floating point, good
> >> software design, and other programming languages such as Lisp and Forth."
> >>
> >> But ...
> >>
> >> "Rudeness and personal attacks, even in reaction to blatant flamebait,
> >> are strongly frowned upon. People may strongly disagree on an issue, but
> >> usually discussion remains civil. In case of an actual flamebait
> >> posting, you can ignore it, quietly plonk the offending poster in your
> >> killfile or mail filters, or write a sharp but still-polite response,
> >> but at all costs resist the urge to flame back."
> >>
> >> http://www.python.org/community/lists/
> >>
> >> It's up to all of us to help keep this group/list a place where people
> >> enjoy participating, without fear of gratuitous personal sniping.
> >> Thanks!
> I suggest you spend more time telling the troll that he's a troll and 
> less time moaning at me.

I suggest you re-read the group charter.  He may be saying things that 
most of us disagree with but he does it without personal attacks.  He's 
made his position clear and it doesn't seem likely to change.  Ignoring, 
plonking, or polite responses are all fine responses.  Flaming is not.  
That's not the kind of group most of us want to see.

-- 
 Ned Deily,
 n...@acm.org

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


honking great ideas

2013-03-26 Thread Sean Felipe Wolfe
So I have been re-reading some of the python intro stuffs after a time
away philandering with other languages. I have been thinking about the
Zen of Python piece where it says 'namespaces are a honking great idea
- let's do more of those'.

A question -- since then do we have any sort of list of major
innovations like that? Do we keep any sort of 'honking great idea
list' anywhere? Or maybe folks could suggest what some of those
milestones have been over time?

I think a 'honking great list' of python innovations would be fun ...
maybe presumptuous, but fun anyways. :P


-- 
A musician must make music, an artist must paint, a poet must write,
if he is to be ultimately at peace with himself.
- Abraham Maslow
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to define "exec" method on a class object? Get syntax error due to built in command

2013-03-26 Thread Chris Angelico
On Wed, Mar 27, 2013 at 10:19 AM, Steven D'Aprano
 wrote:
> On Wed, 27 Mar 2013 06:39:24 +1100, Chris Angelico wrote:
>> I strongly recommend upgrading. 2.3.4 dates back to 2004, that's roughly
>> a decade of bug fixes and feature enhancements behind the times.
>
> Python 2.3 is still supported by Red Hat, at least if you have paid for
> extended support. In principle at least, Red Hat will be providing
> security fixes for 2.3.

Oh, I thought they only supported 2.4. My bad. Still, there's ten
years of feature improvements, even if not security patches.

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


Re: how do you make a loop run in reverse?

2013-03-26 Thread Oscar Benjamin
> On 27 March 2013 10:59,  wrote:
>>
>> So i have a set of for loops that create this :
>>
[snip]
>> but i want to nest all the loops under one BIG loop that'll run in reverse
>> to make this:
[snip]
>> Is this possible?

On 27 March 2013 00:19, Xavier Ho  wrote:
> There is a built-in function that reverses an iterable.  Have a look at the
> documentation.

I assume you mean the reversed function. It does not in general
reverse an iterable. From the docs:
"""
reversed(seq)

Return a reverse iterator. seq must be an object which has a
__reversed__() method or supports the sequence protocol (the __len__()
method and the __getitem__() method with integer arguments starting at
0).

New in version 2.4.

Changed in version 2.6: Added the possibility to write a custom
__reversed__() method.
"""

So it reverses a sequence (having the __len__ and __getitem__ methods)
or an object that advertises reversibility (having a __reversed__
method). It does not reverse anything else including generators,
iterators and most non-sequence iterables.

To the OP: To reverse a "set of for loops" as requested is not
possible using the reversed function. It is, however, possible to
reverse a list of strings. So if you have a function that returns the
list of strings you show as output then you can easily reverse that
list with reversed(mylist) or mylist[::-1].


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


Re: MySQLdbd error. Perhpas it isn't installed?

2013-03-26 Thread MRAB

On 26/03/2013 21:24, Νίκος Γκρ33κ wrote:

Hello today i deiced to go form python 2.6 to python 3.2.3

although in 2.6 my script runs in the ht enewest python i ge this error:


Traceback (most recent call last):
   File 
"/opt/python3/lib/python3.2/site-packages/MySQL_python-1.2.3-py3.2-linux-x86_64.egg/MySQLdb/cursors.py",
 line 171, in execute
 r = self._query(query)
   File 
"/opt/python3/lib/python3.2/site-packages/MySQL_python-1.2.3-py3.2-linux-x86_64.egg/MySQLdb/cursors.py",
 line 330, in _query
 rowcount = self._do_query(q)
   File 
"/opt/python3/lib/python3.2/site-packages/MySQL_python-1.2.3-py3.2-linux-x86_64.egg/MySQLdb/cursors.py",
 line 294, in _do_query
 db.query(q)
_mysql_exceptions.ProgrammingError: (1064, "You have an error in your SQL syntax; 
check the manual that corresponds to your MySQL server version for the right syntax to 
use near '%s' at line 1")

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
   File "metrites.py", line 193, in 
 cur.execute( '''SELECT hits FROM counters WHERE url = %s''', (page,) )
   File 
"/opt/python3/lib/python3.2/site-packages/MySQL_python-1.2.3-py3.2-linux-x86_64.egg/MySQLdb/cursors.py",
 line 184, in execute
 self.errorhandler(self, exc, value)
   File 
"/opt/python3/lib/python3.2/site-packages/MySQL_python-1.2.3-py3.2-linux-x86_64.egg/MySQLdb/connections.py",
 line 36, in defaulterrorhandler
 raise errorclass(errorvalue)
_mysql_exceptions.ProgrammingError: (1064, "You have an error in your SQL syntax; 
check the manual that corresponds to your MySQL server version for the right syntax to 
use near '%s' at line 1")



you can also see it at http://superhost.gr

Any ideas what might be the problem?

My webhost (hostgator.com) says that The MySQLdb module is already installed 
for python 3 on this server.

Can you please tell me what's the nature of this error?

Thank you.


The error's in the SQL.
--
http://mail.python.org/mailman/listinfo/python-list


Re: import in Python3.3

2013-03-26 Thread rocky
On Tuesday, March 26, 2013 7:06:02 PM UTC-4, Steven D'Aprano wrote:
> On Tue, 26 Mar 2013 08:37:00 -0700, rocky wrote:
> 
> 
> 
> > So again I come to import_relative,
> 
> > http://code.google.com/p/pyimport-relative/.  And again, I wish this
> 
> > package didn't have to exist.
> 
> 
> 
> 
> 
> I'm not convinced it does. 

Sure, the package doesn't have to exist. I'm pretty sure the majority of Python 
programmers don't use this. So on that sense it doesn't have to exist. 

I meant that I wished I didn't need it in order to support a development style 
that I use in other programming languages like Ruby, Perl, POSIX shell, or 
Emacs Lisp, among others. 

There, I can run each file/submodule in a large collection such as the dozens 
of files in http://code.google.com/p/python3-trepan/ without having to 
"install" the code. That includes not needing the copying that can go on inside 
say setup.py to put it in a "build" directory. 

With this I can treat each file/module/submodule in the collection as a main 
program or not. This helps me isolate and focus on just that part. I can debug 
it in isolation starting there even though it is a usually submodule of a 
bigger collection.

> 
> to solve. "Provide relative imports" is not that problem, because the use-
> 
> case you give on the project page does not describe relative imports, as 
> 
> they are understood in Python terminology.

If the information above and on that page isn't clear, then please let's just 
drop it. 

This is not a new problem. It's been discussed before, I think on this very 
same newsgroup.

As someone has said, relative imports have been around since 2.5 or so; they've 
been a disappointment to me ever since then too. 

> 
> 
> 
> The error message you get gives the game away:
> 
> 
> 
> ValueError: Attempted relative import in non-package
> 
> 
> 
> In a stand-alone module, you can't do a relative import because there is 
> 
> no package structure, hence there is nothing to import relative to.

So what pyimport-relative does is provide kind of import statement that makes 
it irrelevant whether or not this has been run as a main program or not. And 
yes, I know about Python's '-m' option. 

> 
> 
> 
> As I don't quite understand your use-case, I'm a shooting in the dark 
> 
> here, 


No need to shoot in the dark. If you don't understand the use case, I'm 
probably not explaining it that well. I'm not asking for help, so let's drop 
it, lest I get into another long discussion that ultimately leads nowhere.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how do you make a loop run in reverse?

2013-03-26 Thread Xavier Ho
There is a built-in function that reverses an iterable.  Have a look at the
documentation.

xav


On 27 March 2013 10:59,  wrote:

> So i have a set of for loops that create this :
>
> ***
> ***   ***   ***   ***   ***   ***   ***
> ***   ***   ***   ***   ***   ***   ***
>***   ***   ***   ***   ***   ***   ***
>***   ***   ***   ***   ***   ***   ***
> ***
>
>  *
> ***
>*
>   ***
>  *
>
> but i want to nest all the loops under one BIG loop that'll run in reverse
> to make this:
>
> ***
> ***   ***   ***   ***   ***   ***   ***
> ***   ***   ***   ***   ***   ***   ***
>***   ***   ***   ***   ***   ***   ***
>***   ***   ***   ***   ***   ***   ***
> ***
>
>  *
> ***
>*
>   ***
>  *
>   ***
>*
> ***
>  *
> ***
>***   ***   ***   ***   ***   ***   ***
>***   ***   ***   ***   ***   ***   ***
> ***   ***   ***   ***   ***   ***   ***
> ***   ***   ***   ***   ***   ***   ***
> ***
>
> Is this possible?
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Performance of int/long in Python 3

2013-03-26 Thread Mark Lawrence

On 27/03/2013 00:00, Ned Deily wrote:

In article ,
  Mark Lawrence  wrote:

But you are an idiot.


I repeat the friendly reminder I posted a few weeks ago and I'll be a
little less oblique: please avoid gratuitous personal attacks here.  It
reflects badly on the group and especially on those people making them.
We can disagree strongly about technical opinions without resorting to
such.

On Mon, 11 Mar 2013 11:13:16 -0700, I posted:

A friendly reminder that this forum is for general discussion and
questions about Python.

"Pretty much anything Python-related is fair game for discussion, and
the group is even fairly tolerant of off-topic digressions; there have
been entertaining discussions of topics such as floating point, good
software design, and other programming languages such as Lisp and Forth."

But ...

"Rudeness and personal attacks, even in reaction to blatant flamebait,
are strongly frowned upon. People may strongly disagree on an issue, but
usually discussion remains civil. In case of an actual flamebait
posting, you can ignore it, quietly plonk the offending poster in your
killfile or mail filters, or write a sharp but still-polite response,
but at all costs resist the urge to flame back."

http://www.python.org/community/lists/

It's up to all of us to help keep this group/list a place where people
enjoy participating, without fear of gratuitous personal sniping.
Thanks!




I suggest you spend more time telling the troll that he's a troll and 
less time moaning at me.


--
If you're using GoogleCrap™ please read this 
http://wiki.python.org/moin/GoogleGroupsPython.


Mark Lawrence

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


Re: how do you make a loop run in reverse?

2013-03-26 Thread Mark Lawrence

On 26/03/2013 23:59, rahulredd...@hotmail.com wrote:

So i have a set of for loops that create this :



snipped the art



but i want to nest all the loops under one BIG loop that'll run in reverse to 
make this:



snipped the art



Is this possible?



Yes read http://docs.python.org/3/library/stdtypes.html#range and 
http://docs.python.org/3/library/functions.html#reversed


--
If you're using GoogleCrap™ please read this 
http://wiki.python.org/moin/GoogleGroupsPython.


Mark Lawrence

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


Re: Performance of int/long in Python 3

2013-03-26 Thread Ned Deily
In article ,
 Mark Lawrence  wrote:
> But you are an idiot.

I repeat the friendly reminder I posted a few weeks ago and I'll be a 
little less oblique: please avoid gratuitous personal attacks here.  It 
reflects badly on the group and especially on those people making them.  
We can disagree strongly about technical opinions without resorting to 
such.

On Mon, 11 Mar 2013 11:13:16 -0700, I posted:
> A friendly reminder that this forum is for general discussion and 
> questions about Python.
> 
> "Pretty much anything Python-related is fair game for discussion, and 
> the group is even fairly tolerant of off-topic digressions; there have 
> been entertaining discussions of topics such as floating point, good 
> software design, and other programming languages such as Lisp and Forth."
> 
> But ...
> 
> "Rudeness and personal attacks, even in reaction to blatant flamebait, 
> are strongly frowned upon. People may strongly disagree on an issue, but 
> usually discussion remains civil. In case of an actual flamebait 
> posting, you can ignore it, quietly plonk the offending poster in your 
> killfile or mail filters, or write a sharp but still-polite response, 
> but at all costs resist the urge to flame back."
> 
> http://www.python.org/community/lists/
> 
> It's up to all of us to help keep this group/list a place where people 
> enjoy participating, without fear of gratuitous personal sniping.   
> Thanks!

-- 
 Ned Deily,
 n...@acm.org

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


how do you make a loop run in reverse?

2013-03-26 Thread rahulreddy24
So i have a set of for loops that create this :

***
***   ***   ***   ***   ***   ***   ***   
***   ***   ***   ***   ***   ***   ***   
   ***   ***   ***   ***   ***   ***   ***
   ***   ***   ***   ***   ***   ***   ***
***
  
 *
***
   *
  ***
 *

but i want to nest all the loops under one BIG loop that'll run in reverse to 
make this:

***
***   ***   ***   ***   ***   ***   ***   
***   ***   ***   ***   ***   ***   ***   
   ***   ***   ***   ***   ***   ***   ***
   ***   ***   ***   ***   ***   ***   ***
***
  
 *
***
   *
  ***
 *
  ***
   *
***
 *
***
   ***   ***   ***   ***   ***   ***   ***
   ***   ***   ***   ***   ***   ***   ***
***   ***   ***   ***   ***   ***   ***   
***   ***   ***   ***   ***   ***   ***   
***

Is this possible?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to define "exec" method on a class object? Get syntax error due to built in command

2013-03-26 Thread Steven D'Aprano
On Wed, 27 Mar 2013 06:39:24 +1100, Chris Angelico wrote:

> On Wed, Mar 27, 2013 at 6:24 AM, Kyle  wrote:
>> On Mar 26, 2:43 pm, Chris Angelico  wrote:
>>> On Wed, Mar 27, 2013 at 5:13 AM, Kyle  wrote:
>>> > Thanks for the suggestion. Looks like we currently use 2.3.4.
>>>
>>> > This still wouldn't solve the problem because now the user would
>>> > need to call something like  getattr(wbt, "exec")() instead of
>>> > wbt.exec() like all the other commands.
>>>
>>> > I think the easiest thing for me to do would be to just change the
>>> > command name from exec to something else.
>>>
>>> . that's pretty ancient. Any chance you can upgrade at least to
>>> 2.7.3?
>>>
>>> ChrisA
>>
>> Unfortunately, while I could update my machine, there's no guarantee
>> others would have the same version--the 2.3.4 seems to be the default
>> on our machines and in the automount dirs.
> 
> I strongly recommend upgrading. 2.3.4 dates back to 2004, that's roughly
> a decade of bug fixes and feature enhancements behind the times. 

Python 2.3 is still supported by Red Hat, at least if you have paid for 
extended support. In principle at least, Red Hat will be providing 
security fixes for 2.3.


> 2.7.3
> is the latest 2.x release, and most likely your code will run unchanged
> on it; if you can switch to 3.3.0 (the latest 3.x release), that would
> actually fix your exec problem, for what that's worth. (Moving to 3.3.0
> would be a much bigger change, though, and one that's likely to require
> code edits.)

If the OP's code uses string exceptions:

raise "an error occurred"

they will need to be replaced before migrating to 2.7.


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


Re: Performance of int/long in Python 3

2013-03-26 Thread Gregory Ewing

On Wed, Mar 27, 2013 at 8:08 AM, Grant Edwards  wrote:


Does that allow us to determine wheter integers are idiots or not?


No, it doesn't. I'm fairly confident that most of them are not...
however, I have my eye on 42.


He thought he was equal to 6 x 9 at one point, which
seems pretty idiotic to me.

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


Re: import in Python3.3

2013-03-26 Thread Steven D'Aprano
On Tue, 26 Mar 2013 12:33:54 -0400, Jerry Hill wrote:

> On Mon, Mar 25, 2013 at 11:49 PM, rocky  wrote:
>>> On Sun, 24 Mar 2013 18:12:49 -0500, Fabian von Romberg wrote:
>>> > I have a package name collections and inside of my package I want to
> 
>> I find this kind of thing sad: it feels to me that programmers are
>> working around somewhat arbitrary and changing restrictions. Rather
>> than avoid names like "collections", why not try to address the
>> underlying problem? There isn't an ambiguity here in my view: the
>> fullname is mypackage.collections
> 
> You've said a couple of times now that the original author has a package
> named "mypackage" with a module "collections" in it.  As far as I can
> tell, that's untrue.  The original post claims to have a package named
> "collections", which is colliding with the builtin module of the same
> name.

Ah, that would be my fault. I was the first one to mention "mypackage", 
and I misread the OP's description.

Given that he has a *top-level* package "collections" which clashes with 
the collections in the standard library, there's no simple way to bypass 
his package and find the standard library collections module. When you 
have two top-level modules/packages with the same name, whichever one 
comes first in sys.path will shadow the second one.


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


Re: import in Python3.3

2013-03-26 Thread Steven D'Aprano
On Tue, 26 Mar 2013 08:37:00 -0700, rocky wrote:

> And again, I get the impression that for the use case asked about, there
> isn't much ambiguity. If I am in mypackage.foo and I want to access
> mypackage.collections I should be able to say something like that
> without ambiguity or that much inference or directory searching.

And you can: either explicitly say

import mypackage.collections

or use a relative import:

from . import collections

both of which only look inside mypackage.

> If
> mypackage.colletions is not found inside the same directory as
> mypackage.foo, often I DON'T WANT Python to helpfully go searching
> around other places for it which sys.path will do.

With both solutions above, Python will not.


> Instead what I
> probably want is Python to give me an error.
> 
> So again I come to import_relative,
> http://code.google.com/p/pyimport-relative/.  And again, I wish this
> package didn't have to exist.


I'm not convinced it does. I don't understand the problem you are trying 
to solve. "Provide relative imports" is not that problem, because the use-
case you give on the project page does not describe relative imports, as 
they are understood in Python terminology.

The error message you get gives the game away:

ValueError: Attempted relative import in non-package

In a stand-alone module, you can't do a relative import because there is 
no package structure, hence there is nothing to import relative to.

As I don't quite understand your use-case, I'm a shooting in the dark 
here, but it seems to me that you could fix this entire problem by simply 
using a package instead of a directory of stand-alone modules. A mere 
directory of stand-alone modules should be merely loosely coupled, no 
different from any other modules in sys.path. If your modules are tightly 
coupled, they should go in a package.

One thing which would make import manipulations much easier would be if 
import (and __import__) took an explicit search path, as opposed to 
operating on a system-wide global. E.g.

import module using this_path

would be nice.


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


Re: Help me pick an API design (OO vs functional)

2013-03-26 Thread Steven D'Aprano
On Tue, 26 Mar 2013 07:33:18 -0700, Michael Herrmann wrote:

>> As long as you know the program is going to be simple, pile on the
>> globals.  But as soon as it advances, each of them is a trap to fall
>> into.
> 
> You're right with everything you say. globals are bad and it may happen
> that this will bite me.

Global *variables* are bad, not global functions. You have one global 
variable, "the current window". So long as your API makes it obvious when 
the current window changes, implicitly operating on the current window is 
no more dangerous than Python's implicit operations on the current 
namespace (e.g. "x = 2" binds 2 to x in the current namespace).

I recommend you look at the random.py API. You have a Random class, that 
allows the user to generate as many independent random number generators 
as needed. And the module also initialises a private instance, and 
exposes the methods of that instance as top-level functions, to cover the 
90% simple case where your application only cares about a single RNG.


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


Re: import in Python3.3

2013-03-26 Thread Rocky Bernstein
On Tue, Mar 26, 2013 at 5:16 PM, Phil Connell  wrote:

> On Tue, Mar 26, 2013 at 08:37:00AM -0700, rocky wrote:
> > And again, I get the impression that for the use case asked about, there
> isn't much ambiguity. If I am in mypackage.foo and I want to access
> mypackage.collections I should be able to say something like that without
> ambiguity or that much inference or directory searching. If
> mypackage.colletions is not found inside the same directory as
> mypackage.foo, often I DON'T WANT Python to helpfully go searching around
> other places for it which sys.path will do. Instead what I probably want is
> Python to give me an error.
> >
> > So again I come to import_relative,
> http://code.google.com/p/pyimport-relative/.  And again, I wish this
> package didn't have to exist.
>
> What's wrong with PEP 328 relative imports?
>

They've never worked for me. Some details are mentioned that in the link
above.

If it works for you, great, use it.


> In mypackage.foo, use
>
> from . import collections
>
> to import mypackage.collections.
>
>
> This has been part of the language since ~2.5
>
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Help me pick an API design (OO vs functional)

2013-03-26 Thread Mitya Sirenef

On 03/26/2013 10:59 AM, Michael Herrmann wrote:

On Tuesday, March 26, 2013  2:41:38 PM UTC+1, Mitya Sirenef wrote:

>> ...
>> At the __exit__, further commands are no longer routed to that window;
>> if it was a nested context, window is switched to the outer context,
>> WHEN there are commands in it (i.e. on the first command). This seems
>> pretty intuitive to me:
>>
>> with notepad1:
>>  ^S
>>  with notepad2:
>>  ^S
>>  write('something')
>>
>
>> ...
>>  > What I am most afraid of: that the window that's currently the
>>  > context "disappears":
>>
>>  > notepad = start("Notepad")
>>  > with notepad:
>>  > press(ALT + TAB)
>>  > write("Am I in Notepad now?")
>>
>>
>> Alt-tab needs to be handled by a wrapper function that gives you the
>> object of the window you've switched to:
>>
>> otherwin = alt_tab()
>> with otherwin:
>>  ...
>>
>> If window is changed within 'with' block, the rest of block should be
>> ignored. Perhaps there could also be a way to switch this behaviour off,
>> for the entire script or for current block only.
>>
>>
>>  > What do you think of designs #3 and #4?
>>  > ...
>>
>> These are ok, too, but I feel it's much easier to send commands to a
>> wrong window vs. context managers. The same command in a different
>> window can have vastly different and dangerous effect. In other python
>> code that's generally not common at all, and would be bad style:
>>
>> lst = lst1
>> lst.append('x')
>> del lst[3]
>> lst.insert(0, 'a')
>> lst = lst2
>> del lst[2]
>> lst.append('y')
>> lst = lst3
>> lst.insert(0, 'x')
>> lst += [1,2]
>>
>> I think current window should also be acquired explicitly:
>>
>> with get_current_window():
>>  type("some kind of snippet")
>>
>> For usage when a command should apply to all types of windows.
>
> I was skeptical of your suggestion at first but trying it out on an 
example script made me see its appeal:

>
> notepad_main = start("Notepad")
> with notepad_main:
> write("Hello World!")
> save_dialogue = press(CTRL + 's')
> with save_dialogue:
> write("test.txt", into="File name")
> click("Save")
> click("Close")
>
> Forcing the library user to always use the "with ..." seems like 
overkill though. I think the gained precision does not justify this 
burden on the library user. Hm



I don't see why that's a big deal, I've used AHK extensively and in my
experience you don't switch windows all that often. I think it's best to
optimize to have easy to type and read commands while you're working in
the same window.

I think you could argue that dialogs that belong to the main window
should be handled implicitly, though. I think for other windows it'd
definitely be good to use context managers, but for quick/simple dialogs
it's too much hassle, although for large, complex dialogs that have
inner tabs and require a lot of work, it again starts to make sense.

At the very least, for small dialogs it's sipmpler to do:

with press(CTRL + 's'):
write("test.txt", into="File name")
click("Save")


 -m


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

Calamities are of two kinds: misfortunes to ourselves, and good fortune 
to others.

Ambrose Bierce, The Devil's Dictionary

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


MySQLdbd error. Perhpas it isn't installed?

2013-03-26 Thread Νίκος Γκρ33κ
Hello today i deiced to go form python 2.6 to python 3.2.3

although in 2.6 my script runs in the ht enewest python i ge this error:


Traceback (most recent call last):
  File 
"/opt/python3/lib/python3.2/site-packages/MySQL_python-1.2.3-py3.2-linux-x86_64.egg/MySQLdb/cursors.py",
 line 171, in execute
r = self._query(query)
  File 
"/opt/python3/lib/python3.2/site-packages/MySQL_python-1.2.3-py3.2-linux-x86_64.egg/MySQLdb/cursors.py",
 line 330, in _query
rowcount = self._do_query(q)
  File 
"/opt/python3/lib/python3.2/site-packages/MySQL_python-1.2.3-py3.2-linux-x86_64.egg/MySQLdb/cursors.py",
 line 294, in _do_query
db.query(q)
_mysql_exceptions.ProgrammingError: (1064, "You have an error in your SQL 
syntax; check the manual that corresponds to your MySQL server version for the 
right syntax to use near '%s' at line 1")

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "metrites.py", line 193, in 
cur.execute( '''SELECT hits FROM counters WHERE url = %s''', (page,) )
  File 
"/opt/python3/lib/python3.2/site-packages/MySQL_python-1.2.3-py3.2-linux-x86_64.egg/MySQLdb/cursors.py",
 line 184, in execute
self.errorhandler(self, exc, value)
  File 
"/opt/python3/lib/python3.2/site-packages/MySQL_python-1.2.3-py3.2-linux-x86_64.egg/MySQLdb/connections.py",
 line 36, in defaulterrorhandler
raise errorclass(errorvalue)
_mysql_exceptions.ProgrammingError: (1064, "You have an error in your SQL 
syntax; check the manual that corresponds to your MySQL server version for the 
right syntax to use near '%s' at line 1")



you can also see it at http://superhost.gr

Any ideas what might be the problem?

My webhost (hostgator.com) says that The MySQLdb module is already installed 
for python 3 on this server. 

Can you please tell me what's the nature of this error?

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


Re: Performance of int/long in Python 3

2013-03-26 Thread Dave Angel

On 03/26/2013 05:14 PM, Chris Angelico wrote:

   

Does that allow us to determine wheter integers are idiots or not?


No, it doesn't. I'm fairly confident that most of them are not...
however, I have my eye on 42. He gets around, a bit, but never seems
to do anything very useful. I'd think twice before hiring him.


Ah, 42, the "Answer to Life, the Universe, and Everything"

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


Re: Performance of int/long in Python 3

2013-03-26 Thread Mark Lawrence

On 26/03/2013 21:14, Chris Angelico wrote:

On Wed, Mar 27, 2013 at 8:08 AM, Grant Edwards  wrote:

On 2013-03-26, Mark Lawrence  wrote:

On 26/03/2013 20:44, jmfauth wrote:



A character is not an integer (short form).


So?


A character is not an integer.

jmf


But you are an idiot.


I think we all agree that jmf is a character.

So we've established that no characters are integers, but some
characters are idiots.

Does that allow us to determine wheter integers are idiots or not?


No, it doesn't. I'm fairly confident that most of them are not...
however, I have my eye on 42. He gets around, a bit, but never seems
to do anything very useful. I'd think twice before hiring him.

But 1, now, he's a good fellow. Even when things get divisive, he's
the voice of unity.

ChrisA



Which reminds me, why do people on newsgroups often refer to 101, my 
favourite number?  I mean, do we really care about the number of a room 
that Eric Blair worked in when he was at the BBC?


--
If you're using GoogleCrap™ please read this 
http://wiki.python.org/moin/GoogleGroupsPython.


Mark Lawrence

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


Re: import in Python3.3

2013-03-26 Thread Phil Connell
On Tue, Mar 26, 2013 at 08:37:00AM -0700, rocky wrote:
> And again, I get the impression that for the use case asked about, there 
> isn't much ambiguity. If I am in mypackage.foo and I want to access 
> mypackage.collections I should be able to say something like that without 
> ambiguity or that much inference or directory searching. If 
> mypackage.colletions is not found inside the same directory as mypackage.foo, 
> often I DON'T WANT Python to helpfully go searching around other places for 
> it which sys.path will do. Instead what I probably want is Python to give me 
> an error. 
> 
> So again I come to import_relative, 
> http://code.google.com/p/pyimport-relative/.  And again, I wish this package 
> didn't have to exist.

What's wrong with PEP 328 relative imports?

In mypackage.foo, use

from . import collections

to import mypackage.collections.


This has been part of the language since ~2.5

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


Re: Performance of int/long in Python 3

2013-03-26 Thread Chris Angelico
On Wed, Mar 27, 2013 at 8:08 AM, Grant Edwards  wrote:
> On 2013-03-26, Mark Lawrence  wrote:
>> On 26/03/2013 20:44, jmfauth wrote:

> A character is not an integer (short form).

 So?
>>>
>>> A character is not an integer.
>>>
>>> jmf
>>
>> But you are an idiot.
>
> I think we all agree that jmf is a character.
>
> So we've established that no characters are integers, but some
> characters are idiots.
>
> Does that allow us to determine wheter integers are idiots or not?

No, it doesn't. I'm fairly confident that most of them are not...
however, I have my eye on 42. He gets around, a bit, but never seems
to do anything very useful. I'd think twice before hiring him.

But 1, now, he's a good fellow. Even when things get divisive, he's
the voice of unity.

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


Re: Performance of int/long in Python 3

2013-03-26 Thread Grant Edwards
On 2013-03-26, Mark Lawrence  wrote:
> On 26/03/2013 20:44, jmfauth wrote:
>>>
 A character is not an integer (short form).
>>>
>>> So?
>>
>> A character is not an integer.
>>
>> jmf
>
> But you are an idiot.

I think we all agree that jmf is a character.

So we've established that no characters are integers, but some
characters are idiots.

Does that allow us to determine wheter integers are idiots or not?

-- 
Grant Edwards   grant.b.edwardsYow! All of life is a blur
  at   of Republicans and meat!
  gmail.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Performance of int/long in Python 3

2013-03-26 Thread Mark Lawrence

On 26/03/2013 20:44, jmfauth wrote:

On 26 mar, 20:03, Chris Angelico  wrote:

On Wed, Mar 27, 2013 at 5:50 AM, jmfauth  wrote:

On 25 mar, 22:51, Chris Angelico  wrote:

The Python 3 merge of int and long has effectively penalized
small-number arithmetic by removing an optimization. As we've seen
from PEP 393 strings (jmf aside), there can be huge benefits from
having a single type with multiple representations internally ...



--



A character is not an integer (short form).


So?

ChrisA


A character is not an integer.

jmf



But you are an idiot.

--
If you're using GoogleCrap™ please read this 
http://wiki.python.org/moin/GoogleGroupsPython.


Mark Lawrence

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


Re: Performance of int/long in Python 3

2013-03-26 Thread Chris Angelico
On Wed, Mar 27, 2013 at 7:44 AM, jmfauth  wrote:
> On 26 mar, 20:03, Chris Angelico  wrote:
>> On Wed, Mar 27, 2013 at 5:50 AM, jmfauth  wrote:
>> > On 25 mar, 22:51, Chris Angelico  wrote:
>> >> The Python 3 merge of int and long has effectively penalized
>> >> small-number arithmetic by removing an optimization. As we've seen
>> >> from PEP 393 strings (jmf aside), there can be huge benefits from
>> >> having a single type with multiple representations internally ...
>>
>> > --
>>
>> > A character is not an integer (short form).
>>
>> So?
>>
>> ChrisA
>
> A character is not an integer.

Yes, I heard you the first time. And I repeat: A needle pulling thread?

You have not made any actual, uhh, _point_.

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


Re: problem with sys import argv

2013-03-26 Thread Dave Angel

On 03/26/2013 04:12 PM, Thomas 'PointedEars' Lahn wrote:

Dave Angel wrote:


Since the script takes a mandatory argument, run it with one.

python  myscript.py  Dave

Better would be to change the script to check len(argv) for exactly 2,
and tell the user how he should have run it.


I would use argparse.ArgumentParser instead.





As would I.  But that would be out of proportion of the rest of the 
code, and therefore presumably beyond the needs or interest of the OP.


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


Re: Performance of int/long in Python 3

2013-03-26 Thread jmfauth
On 26 mar, 20:03, Chris Angelico  wrote:
> On Wed, Mar 27, 2013 at 5:50 AM, jmfauth  wrote:
> > On 25 mar, 22:51, Chris Angelico  wrote:
> >> The Python 3 merge of int and long has effectively penalized
> >> small-number arithmetic by removing an optimization. As we've seen
> >> from PEP 393 strings (jmf aside), there can be huge benefits from
> >> having a single type with multiple representations internally ...
>
> > --
>
> > A character is not an integer (short form).
>
> So?
>
> ChrisA

A character is not an integer.

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


Re: problem with sys import argv

2013-03-26 Thread Thomas 'PointedEars' Lahn
Dave Angel wrote:

> Since the script takes a mandatory argument, run it with one.
> 
> python  myscript.py  Dave
> 
> Better would be to change the script to check len(argv) for exactly 2,
> and tell the user how he should have run it.

I would use argparse.ArgumentParser instead.



-- 
PointedEars

Twitter: @PointedEars2
Please do not Cc: me. / Bitte keine Kopien per E-Mail.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to define "exec" method on a class object? Get syntax error due to built in command

2013-03-26 Thread Chris Angelico
On Wed, Mar 27, 2013 at 6:24 AM, Kyle  wrote:
> On Mar 26, 2:43 pm, Chris Angelico  wrote:
>> On Wed, Mar 27, 2013 at 5:13 AM, Kyle  wrote:
>> > Thanks for the suggestion. Looks like we currently use 2.3.4.
>>
>> > This still wouldn't solve the problem because now the user would need to 
>> > call something like  getattr(wbt, "exec")() instead of 
>> > wbt.exec() like all the other commands.
>>
>> > I think the easiest thing for me to do would be to just change the command 
>> > name from exec to something else.
>>
>> . that's pretty ancient. Any chance you can upgrade at least to 2.7.3?
>>
>> ChrisA
>
> Unfortunately, while I could update my machine, there's no guarantee
> others would have the same version--the 2.3.4 seems to be the default
> on our machines and in the automount dirs.

I strongly recommend upgrading. 2.3.4 dates back to 2004, that's
roughly a decade of bug fixes and feature enhancements behind the
times. 2.7.3 is the latest 2.x release, and most likely your code will
run unchanged on it; if you can switch to 3.3.0 (the latest 3.x
release), that would actually fix your exec problem, for what that's
worth. (Moving to 3.3.0 would be a much bigger change, though, and one
that's likely to require code edits.)

It's a good thing Python has neither the number nor breadth of
security vulnerabilities as Windows; you're using something nearly as
old as an unpatched Windows XP, no service packs, no Windows Update,
nothing... no sane systems administrator would let you put that on the
internet. It may not be suicidal like that, but it's still ten years'
worth of updates you're missing out on!

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


Re: How to define "exec" method on a class object? Get syntax error due to built in command

2013-03-26 Thread Kyle
On Mar 26, 2:43 pm, Chris Angelico  wrote:
> On Wed, Mar 27, 2013 at 5:13 AM, Kyle  wrote:
> > Thanks for the suggestion. Looks like we currently use 2.3.4.
>
> > This still wouldn't solve the problem because now the user would need to 
> > call something like  getattr(wbt, "exec")() instead of 
> > wbt.exec() like all the other commands.
>
> > I think the easiest thing for me to do would be to just change the command 
> > name from exec to something else.
>
> . that's pretty ancient. Any chance you can upgrade at least to 2.7.3?
>
> ChrisA

Unfortunately, while I could update my machine, there's no guarantee
others would have the same version--the 2.3.4 seems to be the default
on our machines and in the automount dirs.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Performance of int/long in Python 3

2013-03-26 Thread Chris Angelico
On Wed, Mar 27, 2013 at 5:50 AM, jmfauth  wrote:
> On 25 mar, 22:51, Chris Angelico  wrote:
>> The Python 3 merge of int and long has effectively penalized
>> small-number arithmetic by removing an optimization. As we've seen
>> from PEP 393 strings (jmf aside), there can be huge benefits from
>> having a single type with multiple representations internally ...
>
> --
>
> A character is not an integer (short form).

So?

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


Re: Performance of int/long in Python 3

2013-03-26 Thread jmfauth
On 25 mar, 22:51, Chris Angelico  wrote:
> The Python 3 merge of int and long has effectively penalized
> small-number arithmetic by removing an optimization. As we've seen
> from PEP 393 strings (jmf aside), there can be huge benefits from
> having a single type with multiple representations internally ...

--

A character is not an integer (short form).

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


Re: I need a neat way to print nothing or a number

2013-03-26 Thread Chris Angelico
On Wed, Mar 27, 2013 at 4:21 AM, Ethan Furman  wrote:
> On 03/26/2013 10:06 AM, Wolfgang Maier wrote:
>>
>> Chris Angelico  gmail.com> writes:
>>
>>>
>>> Try printing out this expression:
>>>
>>> "%.2f"%value if value else ''
>>>
>>> Without the rest of your code I can't tell you how to plug that in,
>>> but a ternary expression is a good fit here.
>>>
>>> ChrisA
>>>
>>
>> Unfortunately, that's not working, but gives a TypeError: a float is
>> required
>> when the first value evaluates to False.
>> Apparently it's not that easy to combine number formatting with logical
>> operators - the same happens with my idea ('{:.2f}').format(value or '').
>
>
> Use parens then:
>
> ("%.2f" % value) if value else ''

According to the operator precedence table, the parens are unnecessary there.

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


[job] Python & AWS /Back-End Developer in New York, NY

2013-03-26 Thread Lana
We are looking for a strong Python Developer to work with our young and 
energetic team on the Next generation of clients website. This project is the 
first to implement the modern concepts of Cloud and MongoDB.

Job Responsibilities
- Creates new and modifies existing software, integrates software applications 
and modules based on specifications created in partnership with others
- Designs and runs unit and integration tests to ensure that software meets 
requirements
- Contributes and leads in the design process for less complex components
- Provides technical support to operations and/or to other development teams
- Creates, reviews, and maintains technical documentation related to assigned 
software
- Reviews work of both peers and more junior developers
- Helps identify and implement short- and long-term solution options including 
risk assessments
- Participates in devising and implementing solutions for problem remediation
- Participates in project planning sessions with team members
- Provides work breakdown and estimates for small software development tasks
- Provides timely status updates for areas of individual responsibilities in 
projects
- Develops software using disciplined software development processes, adhering 
to team/company standards and software best practice guidelines, and corporate 
policies
- Works independently with limited technical and management guidance, taking 
ownership of problems within own area of knowledge
- Makes decisions within ambiguous guidelines with limited review by 
appropriate people
- Is accountable for the quality of work
- Delivers results within agreed procedures and timeframes
- Attends to the needs of internal and/or external customer
- Reviews and may approve decisions of junior engineers

Qualifications:
- Development experience with object-oriented languages
- 1-2 years of Python development experience
- Knowledge of HTML5 concepts is a plus to coordinate with the front-end 
development
- Agile development experience a plus
- Demonstrated ability to work in a team environment
- Good unit testing practices
- Good communication and documentation skills
- Willingness to interact and work with different teams across organizations in 
different time zones
- Willingness to work overtime and weekends if required
- Bachelors degree in Computer Science is an added advantage

Required Skills:
- Strong in object-oriented concepts and Python language
- Proficient with concepts of virtual environments and familiarity with Fabric 
tool
- Knowledgeable about MVC pattern
- Experienced working with Tornado web server
- Familiar with REST API and JSON
- Familiar with asynchronous programming
- Familiar with AWS infrastructure
- Knowledgeable about NoSQL concepts

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


Re: How to define "exec" method on a class object? Get syntax error due to built in command

2013-03-26 Thread Chris Angelico
On Wed, Mar 27, 2013 at 5:13 AM, Kyle  wrote:
> Thanks for the suggestion. Looks like we currently use 2.3.4.
>
> This still wouldn't solve the problem because now the user would need to call 
> something like  getattr(wbt, "exec")() instead of wbt.exec() like 
> all the other commands.
>
> I think the easiest thing for me to do would be to just change the command 
> name from exec to something else.

. that's pretty ancient. Any chance you can upgrade at least to 2.7.3?

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


Re: How to define "exec" method on a class object? Get syntax error due to built in command

2013-03-26 Thread Ethan Furman

On 03/26/2013 11:13 AM, Kyle wrote:

On Monday, March 25, 2013 4:28:34 PM UTC-4, Kyle wrote:

I am using swig to generate our CLI for TCL and Python. In this CLI, we have a subcommand 
"exec" that is failing to compile in the python case. There seems to be some built-in 
python command "exec" which is giving a syntax error in the .py file generated by swig 
when I try to import it:



def exec(*args): return _wbt_daemon.dm_cli_exec(*args)

^

SyntaxError: invalid syntax



I don't really want to change the CLI commands or make them different between languages. Is there 
any way to define a method called "exec" on a class? It would be executed as obj.exec() 
so I don't see why it should conflict with the built in "exec" command.



class dm_cli(_object):

 __swig_setmethods__ = {}

 __setattr__ = lambda self, name, value: _swig_setattr(self, dm_cli, name, 
value)

 __swig_getmethods__ = {}

 __getattr__ = lambda self, name: _swig_getattr(self, dm_cli, name)

 def __init__(self): raise RuntimeError, "No constructor defined"

...

 def exec(*args): return _wbt_daemon.dm_cli_exec(*args)

...

}


Thanks for the suggestion. Looks like we currently use 2.3.4.

This still wouldn't solve the problem because now the user would need to call something like  
getattr(wbt, "exec")() instead of wbt.exec() like all the other 
commands.

I think the easiest thing for me to do would be to just change the command name 
from exec to something else.


Yeah, that's unfortunate.

I suggest 'execute'.  :)

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


Re: import in Python3.3

2013-03-26 Thread rocky
On Tuesday, March 26, 2013 12:33:54 PM UTC-4, Jerry Hill wrote:
> On Mon, Mar 25, 2013 at 11:49 PM, rocky wrote:
> 
> >> On Sun, 24 Mar 2013 18:12:49 -0500, Fabian von Romberg wrote:
> 
> >> > I have a package name collections and inside of my package I want to
> 
> 
> 
> > I find this kind of thing sad: it feels to me that programmers are working 
> > around somewhat arbitrary and changing restrictions. Rather than avoid 
> > names like "collections", why not try to address the underlying problem? 
> > There isn't an ambiguity here in my view: the fullname is 
> > mypackage.collections
> 
> 
> 
> You've said a couple of times now that the original author has a
> 
> package named "mypackage" with a module "collections" in it.  As far
> 
> as I can tell, that's untrue.  The original post claims to have a
> 
> package named "collections", which is colliding with the builtin
> 
> module of the same name.
> 
> 
> 
> As far as I can tell, all of your suggestions about using your
> 
> pyimport-relative tool aren't helpful unless the author re-names his
> 
> package from "collections" to "mypackage" and then moves all of their
> 
> code into a "collections" module inside "mypackage", right?

Right. Perhaps then I misunderstand. Having a package called "collections" when 
there is something out there already called "collections" clearly ill advised. 

But in that case, using sys.path to get around this is still a bad idea: the 
clash should be fixed. Sure, only in the case that this really can't be 
addressed would I use sys.path.

> 
> 
> 
> -- 
> 
> Jerry

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


Re: Performance of int/long in Python 3

2013-03-26 Thread Terry Reedy

On 3/26/2013 12:41 PM, Cousin Stanley wrote:


So where's the difference with your system ?


   CPU 


Compilers and compiler settings can also make a difference.

--
Terry Jan Reedy

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


Re: How to define "exec" method on a class object? Get syntax error due to built in command

2013-03-26 Thread Kyle
On Monday, March 25, 2013 4:28:34 PM UTC-4, Kyle wrote:
> I am using swig to generate our CLI for TCL and Python. In this CLI, we have 
> a subcommand "exec" that is failing to compile in the python case. There 
> seems to be some built-in python command "exec" which is giving a syntax 
> error in the .py file generated by swig when I try to import it:
> 
> 
> 
>def exec(*args): return _wbt_daemon.dm_cli_exec(*args)
> 
>^
> 
> SyntaxError: invalid syntax
> 
> 
> 
> I don't really want to change the CLI commands or make them different between 
> languages. Is there any way to define a method called "exec" on a class? It 
> would be executed as obj.exec() so I don't see why it should conflict with 
> the built in "exec" command.
> 
> 
> 
> class dm_cli(_object):
> 
> __swig_setmethods__ = {}
> 
> __setattr__ = lambda self, name, value: _swig_setattr(self, dm_cli, name, 
> value)
> 
> __swig_getmethods__ = {}
> 
> __getattr__ = lambda self, name: _swig_getattr(self, dm_cli, name)
> 
> def __init__(self): raise RuntimeError, "No constructor defined"
> 
> ...
> 
> def exec(*args): return _wbt_daemon.dm_cli_exec(*args)
> 
> ...
> 
> }

Thanks for the suggestion. Looks like we currently use 2.3.4.

This still wouldn't solve the problem because now the user would need to call 
something like  getattr(wbt, "exec")() instead of wbt.exec() like 
all the other commands.

I think the easiest thing for me to do would be to just change the command name 
from exec to something else.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: problem with sys import argv

2013-03-26 Thread Dave Angel

On 03/26/2013 01:26 PM, leonardo selmi wrote:

hi python community,

i wrote the following programm:

from sys import argv

script, userName = argv
prompt = '> '

print 'hi %s, i am the %s script' % (userName, script)
print "i'd like to ask you a few questions."
print 'do you like me %s' % userName
likes = raw_input(prompt)

print "where do you live %s?" % userName
lives = raw_input(prompt)

print 'what kind of computer do you have?'
computer = raw_input(prompt)

print """
alright so you said %r about liking me.
you live in %r. not sure where that is.
and you have a %r computer. nice
""" % (likes, lives, computer)

and i got the following error:  Traceback (most recent call last):
File "/var/folders/89/84z7tw3d3rv39gny3n2p963mgn/T/pythonInTerm.GUF6PWCM", line 
3, in 
   script, userName = argv
ValueError: need more than 1 value to unpack

what can i do?

thanks!



Since the script takes a mandatory argument, run it with one.

python  myscript.py  Dave

Better would be to change the script to check len(argv) for exactly 2, 
and tell the user how he should have run it.




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


Re: Help me pick an API design (OO vs functional)

2013-03-26 Thread Neil Cerutti
On 2013-03-26, Dave Angel  wrote:
> On 03/26/2013 10:40 AM, Michael Herrmann wrote:
>> On Tuesday, March 26, 2013 3:13:30 PM UTC+1, Neil Cerutti wrote:
>>>
>>>
>>> Have you considered adding a keyword argument to each of your
>>> global functions, which is normally None, but allows a user to
>>> provide a prefered focus window?
>>>
>>> enter_text("test.txt", focus=save_dialog)
>>>
>>> press_button(Savebutton, focus=save_dialog)
>>
>> It's an interesting new idea but I somehow feel it makes the existing 
>> functions too complicated. Also, having to add it to all existing, and 
>> future functions sounds a bit too cumbersome to me.
>>
>
> Perhaps Neil didn't make it clear enough.  I figure he meant a keyword 
> argument with an explicit default value of None.  (or if you followed my 
> earlier discussion, default value of focused)
>
> That way your user can keep using the functions for when there's no 
> ambiguity, but add a focus= parameter only when needed.
>
> To go back to my sample wrapper functions, they'd look something like 
> (untested):
>
>
> def write(*args, focus=focused):
>  focus.write(*args)
>
> Of course, the user should only use the wrappers when things
> are sure to remain "simple."

Yes, along those lines. Most code would never need to provide the
focus= keyword. Only when setting focus in a weird way would it
be needed.

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


Re: problem with sys import argv

2013-03-26 Thread Mark Lawrence

On 26/03/2013 17:26, leonardo selmi wrote:

hi python community,

i wrote the following programm:

from sys import argv

script, userName = argv
prompt = '> '

print 'hi %s, i am the %s script' % (userName, script)
print "i'd like to ask you a few questions."
print 'do you like me %s' % userName
likes = raw_input(prompt)

print "where do you live %s?" % userName
lives = raw_input(prompt)

print 'what kind of computer do you have?'
computer = raw_input(prompt)

print """
alright so you said %r about liking me.
you live in %r. not sure where that is.
and you have a %r computer. nice
""" % (likes, lives, computer)

and i got the following error:  Traceback (most recent call last):
File "/var/folders/89/84z7tw3d3rv39gny3n2p963mgn/T/pythonInTerm.GUF6PWCM", line 
3, in 
   script, userName = argv
ValueError: need more than 1 value to unpack

what can i do?

thanks!



Write some error handling to allow for the script being run without the 
user name.


--
If you're using GoogleCrap™ please read this 
http://wiki.python.org/moin/GoogleGroupsPython.


Mark Lawrence

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


Re: I need a neat way to print nothing or a number

2013-03-26 Thread Ethan Furman

On 03/26/2013 10:06 AM, Wolfgang Maier wrote:

Chris Angelico  gmail.com> writes:



Try printing out this expression:

"%.2f"%value if value else ''

Without the rest of your code I can't tell you how to plug that in,
but a ternary expression is a good fit here.

ChrisA



Unfortunately, that's not working, but gives a TypeError: a float is required
when the first value evaluates to False.
Apparently it's not that easy to combine number formatting with logical
operators - the same happens with my idea ('{:.2f}').format(value or '').


Use parens then:

("%.2f" % value) if value else ''

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


Re: Help with zip in a Python exercise

2013-03-26 Thread Joel Goldstick
On Tue, Mar 26, 2013 at 1:06 PM,  wrote:

> I've been working through a Python tutorial online and one of the
> exercises uses the zip command.  The only problem is that the command
> doesn't work.  I've read through the man page for zip and it looks like
> what I'm attempting should work, but it doesn't.
>
> The command is:
>
> zip -qr /media/backup/backups/test/20130326100218.zip -i
> /home/luggw1/Documents/ /home/luggw1/Code/
>
> The error it produces is:
>
> zip error: Invalid command arguments (nothing to select from)
>
> Can anybody point out the error of my ways?
>

Not sure what os you are using.  If linux, then the zip command looks odd.
-q is quiet mode, you might want to remove that til it works.  Also not
sure your -i is set up propery.  Try to google zip tutorial as this isn't a
python question at all

>
> Thanks.
> Bill Lugg
> --
> http://mail.python.org/mailman/listinfo/python-list
>



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


problem with sys import argv

2013-03-26 Thread leonardo selmi
hi python community,

i wrote the following programm:

from sys import argv

script, userName = argv
prompt = '> '

print 'hi %s, i am the %s script' % (userName, script)
print "i'd like to ask you a few questions."
print 'do you like me %s' % userName
likes = raw_input(prompt)

print "where do you live %s?" % userName
lives = raw_input(prompt)

print 'what kind of computer do you have?'
computer = raw_input(prompt)

print """
alright so you said %r about liking me.
you live in %r. not sure where that is.
and you have a %r computer. nice
""" % (likes, lives, computer)

and i got the following error:  Traceback (most recent call last):
File "/var/folders/89/84z7tw3d3rv39gny3n2p963mgn/T/pythonInTerm.GUF6PWCM", 
line 3, in 
  script, userName = argv
ValueError: need more than 1 value to unpack

what can i do?

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


Re: I need a neat way to print nothing or a number

2013-03-26 Thread Peter Otten
Wolfgang Maier wrote:

> Chris Angelico  gmail.com> writes:
> 
>>
>> Try printing out this expression:
>> 
>> "%.2f"%value if value else ''
>> 
>> Without the rest of your code I can't tell you how to plug that in,
>> but a ternary expression is a good fit here.
>> 
>> ChrisA
>> 
> 
> Unfortunately, that's not working, but gives a TypeError: a float is
> required when the first value evaluates to False.
> Apparently it's not that easy to combine number formatting with logical
> operators - the same happens with my idea ('{:.2f}').format(value or '').

Here's a round-about way:

class Prepare:
def __init__(self, value):
self.value = value
def __format__(self, spec):
if self.value is None or self.value == 0:
return format(0.0, spec).replace(".", " ").replace("0", " ")
elif isinstance(self.value, str):
return self.value.rjust(len(format(0.0, spec)))
return format(self.value, spec)

def prepare(row):
return map(Prepare, row)

data = [
("Credit", "Debit", "Description"),
(100, 0, "Initial balance"),
(123.45, None, "Payment for cabbages"),
(0.0, 202.0, "Telephone bill"),
]

for row in data:
print("{:10.2f} {:10.2f} {}".format(*prepare(row)))



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


Re: I need a neat way to print nothing or a number

2013-03-26 Thread Chris Angelico
On Wed, Mar 27, 2013 at 4:06 AM, Wolfgang Maier
 wrote:
> Chris Angelico  gmail.com> writes:
>
>>
>> Try printing out this expression:
>>
>> "%.2f"%value if value else ''
>>
>> Without the rest of your code I can't tell you how to plug that in,
>> but a ternary expression is a good fit here.
>>
>> ChrisA
>>
>
> Unfortunately, that's not working, but gives a TypeError: a float is required
> when the first value evaluates to False.
> Apparently it's not that easy to combine number formatting with logical
> operators - the same happens with my idea ('{:.2f}').format(value or '').

Really? Works for me in 3.3:

>>> value=1.2
>>> "%.2f"%value if value else ''
'1.20'
>>> value=0
>>> "%.2f"%value if value else ''
''
>>> value=None
>>> "%.2f"%value if value else ''
''

What's the full context? The way I've written the expression, it's
guaranteed to return a string (either "%.2f"5value or the literal '',
and yes, I'm aware that I was inconsistent with the quotes).

I tried it in 2.6 and it worked there, too. Now, if you parenthesize
the bit after the percent sign, the TypeError comes up. But that
wasn't the intention of the code (and "value if value else
something-else" is just "value or something-else", anyway).

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


Help with zip in a Python exercise

2013-03-26 Thread luggw1
I've been working through a Python tutorial online and one of the exercises 
uses the zip command.  The only problem is that the command doesn't work.  I've 
read through the man page for zip and it looks like what I'm attempting should 
work, but it doesn't.

The command is:

zip -qr /media/backup/backups/test/20130326100218.zip -i 
/home/luggw1/Documents/ /home/luggw1/Code/

The error it produces is:

zip error: Invalid command arguments (nothing to select from)

Can anybody point out the error of my ways?

Thanks.
Bill Lugg
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: I need a neat way to print nothing or a number

2013-03-26 Thread Wolfgang Maier
Chris Angelico  gmail.com> writes:

>
> Try printing out this expression:
> 
> "%.2f"%value if value else ''
> 
> Without the rest of your code I can't tell you how to plug that in,
> but a ternary expression is a good fit here.
> 
> ChrisA
> 

Unfortunately, that's not working, but gives a TypeError: a float is required
when the first value evaluates to False.
Apparently it's not that easy to combine number formatting with logical
operators - the same happens with my idea ('{:.2f}').format(value or '').

Wolfgang




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


Re: Performance of int/long in Python 3

2013-03-26 Thread Chris Angelico
On Wed, Mar 27, 2013 at 3:41 AM, Cousin Stanley  wrote:
>
> Chris Angelico wrote:
>
>> Once again, Py3 is slower on small integers than Py2.
>
>   Chris Angelico
>   Ubuntu Karmic.
>   Pentium(R) Dual-Core  CPU E6500  @ 2.93GHz.
>
>   python  inline  range_sum  forloop  forloop_offset
>
>   2.6.4   2.7050  2.6492  6.5877  16.5168
>
>   3.1.1   4.4453  4.3731 12.4834  13.5001
>
>   You do seem to have a slight py3 improvement
>   under ubuntu for the  forloop_offset  case 

Yes, that's correct. The forloop_offset one is using long integers in
all cases. (Well, on Py2 it's adding a series of ints to a long, but
the arithmetic always has to be done with longs.) Python 3 has had
some improvements done, but the main thing is that there's a massive
spike in the Py2 time, while Py3 has _already paid_ that cost - as
evidenced by the closeness of the forloop and forloop_offset times on
Py3.

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


Re: Performance of int/long in Python 3

2013-03-26 Thread Cousin Stanley

Chris Angelico wrote:

> Once again, Py3 is slower on small integers than Py2. 

  Chris Angelico  
  Ubuntu Karmic. 
  Pentium(R) Dual-Core  CPU E6500  @ 2.93GHz.

  python  inline  range_sum  forloop  forloop_offset

  2.6.4   2.7050  2.6492  6.5877  16.5168 

  3.1.1   4.4453  4.3731 12.4834  13.5001

  You do seem to have a slight py3 improvement
  under ubuntu for the  forloop_offset  case 


> So where's the difference with your system ? 

  CPU 


> This is really weird ! 

  Yep ...


> I assume you can repeat the tests 
> and get the same result every time ?

  Yes 

  First lines of numbers below are from yesterday
  while second lines are from today 

  Stanley C. Kitching
  Debian Wheezy
  Intel(R) Celeron(R) D CPU 3.33GH  Single Core

  python  inline  range_sum  forloop  forloop_offset

  2.7.3   3.1359  3.0725 9.0778   15.6475
  2.7.3   3.0382  3.1452 9.8799   16.8579

  3.2.3   2.8226  2.807413.47624  13.6430 
  3.2.3   2.8331  2.822813.54151  13.8716


-- 
Stanley C. Kitching
Human Being
Phoenix, Arizona

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


Re: Help me pick an API design (OO vs functional)

2013-03-26 Thread Dave Angel

On 03/26/2013 10:40 AM, Michael Herrmann wrote:

On Tuesday, March 26, 2013 3:13:30 PM UTC+1, Neil Cerutti wrote:


   
Have you considered adding a keyword argument to each of your
global functions, which is normally None, but allows a user to
provide a prefered focus window?

enter_text("test.txt", focus=save_dialog)

press_button(Savebutton, focus=save_dialog)


It's an interesting new idea but I somehow feel it makes the existing functions 
too complicated. Also, having to add it to all existing, and future functions 
sounds a bit too cumbersome to me.



Perhaps Neil didn't make it clear enough.  I figure he meant a keyword 
argument with an explicit default value of None.  (or if you followed my 
earlier discussion, default value of focused)


That way your user can keep using the functions for when there's no 
ambiguity, but add a focus= parameter only when needed.


To go back to my sample wrapper functions, they'd look something like 
(untested):



def write(*args, focus=focused):
focus.write(*args)

Of course, the user should only use the wrappers when things are sure to 
remain "simple."



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


Re: import in Python3.3

2013-03-26 Thread Jerry Hill
On Mon, Mar 25, 2013 at 11:49 PM, rocky  wrote:
>> On Sun, 24 Mar 2013 18:12:49 -0500, Fabian von Romberg wrote:
>> > I have a package name collections and inside of my package I want to

> I find this kind of thing sad: it feels to me that programmers are working 
> around somewhat arbitrary and changing restrictions. Rather than avoid names 
> like "collections", why not try to address the underlying problem? There 
> isn't an ambiguity here in my view: the fullname is mypackage.collections

You've said a couple of times now that the original author has a
package named "mypackage" with a module "collections" in it.  As far
as I can tell, that's untrue.  The original post claims to have a
package named "collections", which is colliding with the builtin
module of the same name.

As far as I can tell, all of your suggestions about using your
pyimport-relative tool aren't helpful unless the author re-names his
package from "collections" to "mypackage" and then moves all of their
code into a "collections" module inside "mypackage", right?

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


Samsung Galaxy Mini

2013-03-26 Thread 23alagmy
Samsung Galaxy Mini

http://natigtas7ab.blogspot.com/2012/10/samsung-galaxy-mini.html
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: I need a neat way to print nothing or a number

2013-03-26 Thread John Gordon
In  c...@isbd.net writes:

> What's a neat way to print columns of numbers with blanks where a number
> is zero or None?

print number or '  '

-- 
John Gordon   A is for Amy, who fell down the stairs
gor...@panix.com  B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"

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


Simple example of how to use importlib to create a loader

2013-03-26 Thread Paul Moore
I'm trying to write my own loader using importlib. And frankly, I'm getting 
nowhere. I'm struggling to understand precisely which methods of the various 
ABCs I need to implement, and in some cases what they should do.

Could anyone point me to a simple example (say, something that implements zip 
imports using the zipfile module - that was what I initially tried to get 
working as a proof of concept).

Where I've got to is the following stub implementation to try to log the 
sequence of calls:

from importlib.abc import PathEntryFinder, SourceLoader

class MyFinder(PathEntryFinder):
def __init__(self, pathentry):
"""Create a finder for the given `pathentry`"""
if pathentry == 'foo':
return
raise ImportError
def find_loader(self, fullname):
"""Return a loader for the module `fullname`"""
print("find_loader('{}')".format(fullname))
return MyLoader(), ['foo']

class MyLoader(SourceLoader):
def module_repr(self):
print("module_repr()")
return True
def is_package(self, fullname):
print("is_package('{}')".format(fullname))
return True
def get_data(self, path):
"""Return an open binary file object for `path`"""
print("get_data('{}')".format(path))
return b"print('hello from foo!')"
def get_filename(self, fullname):
"""Return the filename for module `fullname`"""
print("get_filename('{}')".format(fullname))
return '/this/is/foo'

if __name__ == '__main__':
import sys
sys.path_hooks.append(lambda p: MyFinder(p))
sys.path.insert(0, 'foo')
import a
import a.b
from a.b.c import x


It prints out

>py .\loader.py
find_loader('a')
is_package('a')
get_filename('a')
get_data('/this/is/foo')
get_filename('a')
is_package('a')
hello from foo!
Traceback (most recent call last):
  File ".\loader.py", line 46, in 
import a.b
ImportError: No module named 'a.b'

which is a good start, but I don't know why it isn't willing to check for 'a.b' 
(after all, I tell it that 'a' is a package).

I'm quite probably doing something trivially wrong here - after all, I'm not 
even *trying* to implement a sane view of a package structure here. But I'd 
have expected at least a find_loader('a.b') call...

Thanks for any help,
Paul.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: I need a neat way to print nothing or a number

2013-03-26 Thread Chris Angelico
On Wed, Mar 27, 2013 at 2:50 AM,   wrote:
> What's a neat way to print columns of numbers with blanks where a number
> is zero or None?
>
> E.g. I want to output something like:-
>
> Credit  Debit   Description
> 100.00  Initial balance
> 123.45  Payment for cabbages
> 202.00  Telephone bill
>
>
> For each line I have either the credit or the debit amount and the other
> is 0 or None.  However you can't get number formatting (old or new) to
> output a blank for 0 and it barfs on None.

Try printing out this expression:

"%.2f"%value if value else ''

Without the rest of your code I can't tell you how to plug that in,
but a ternary expression is a good fit here.

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


I need a neat way to print nothing or a number

2013-03-26 Thread cl
What's a neat way to print columns of numbers with blanks where a number
is zero or None?

E.g. I want to output something like:-

Credit  Debit   Description
100.00  Initial balance
123.45  Payment for cabbages
202.00  Telephone bill


For each line I have either the credit or the debit amount and the other
is 0 or None.  However you can't get number formatting (old or new) to
output a blank for 0 and it barfs on None.

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


Re: import in Python3.3

2013-03-26 Thread rocky
On Tuesday, March 26, 2013 3:04:44 AM UTC-4, Terry Reedy wrote:
> On 3/24/2013 7:12 PM, Fabian von Romberg wrote:
> 
> > Hi,
> 
> >
> 
> > I have a package name collections and inside of my package I want to
> 
> > import the collections package from the standard library, but there
> 
> > is name conflicts.
> 
> 
> 
> Yes. I strongly advise against trying to do this.
> 
> 
> 
> > How do I import explicitly from the standard library?
> 
> 
> 
> Manipulate sys.path. 

This is a common suggestion for working *around* the issue, but it has problems 
of its own.

In my opinion using sys.path is clunky - you may want to save an restore the 
value around use especially if the the place you are using it is not at the top 
level but in some inner less-exposed sub module. And make sure to restore 
sys.path in the presence of exceptions getting thrown somewhere inside the 
import. 

It is also a bit of a security nightmare. If something evil gets injected in 
there what does it effect and how would you know it? sys.path provides a series 
of directories where and evil masquerading Python program can linger.

And again, I get the impression that for the use case asked about, there isn't 
much ambiguity. If I am in mypackage.foo and I want to access 
mypackage.collections I should be able to say something like that without 
ambiguity or that much inference or directory searching. If 
mypackage.colletions is not found inside the same directory as mypackage.foo, 
often I DON'T WANT Python to helpfully go searching around other places for it 
which sys.path will do. Instead what I probably want is Python to give me an 
error. 

So again I come to import_relative, 
http://code.google.com/p/pyimport-relative/.  And again, I wish this package 
didn't have to exist.

> If you don't know how, either read about sys.path 
> 
> (see index) or don't do it.
> 
> 
> 
> -- 
> 
> Terry Jan Reedy

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


Re: Processing user input as it's entered

2013-03-26 Thread Sven
On 26 March 2013 14:41, Arnaud Delobelle  wrote:

> On 26 March 2013 10:07, Sven  wrote:
> > Hello,
> >
> > Is there a way (ideally cross platform but a *nix OS solution would be
> > great) to process user input as they type?
> > What I aim to achieve is to count the number of characters a user has
> > entered and display it while they are typing. The entered text will also
> > need to be captured once the user has finished typing.
> >
> > This is a gui-less CLI tool for python 2.7
> >
> > I've seen some information on tty.setraw but I'm not sure how you'd go
> about
> > wiring that up.
>
> Can you use curses (http://docs.python.org/2/library/curses.html




This could work. I've not used it before so I am having some issues echoing
out the text. I assume I can use this without having to create an ncurses
UI?

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


Re: Help me pick an API design (OO vs functional)

2013-03-26 Thread Chris Angelico
On Wed, Mar 27, 2013 at 1:59 AM, Michael Herrmann
 wrote:
> save_dialogue = press(CTRL + 's')

Does every single API need to then consider the possibility of focus
changing? How does the press() function know that this will (or might
- if the file's already been named, Ctrl-S won't open a dlg) change
focus? How does the caller know?

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


Re: python3 string format

2013-03-26 Thread Ian Kelly
On Tue, Mar 26, 2013 at 4:51 AM, Shiyao Ma  wrote:
> Thx for your reply.
> I am using pycharm and simply press "go to declaration" which directs me to
> a py file, containing the following code:
> def format(*args, **kwargs): # known special case of str.format
> """
> S.format(*args, **kwargs) -> string
>
> Return a formatted version of S, using substitutions from args and
> kwargs.
> The substitutions are identified by braces ('{' and '}').
> """
> pass

I would guess that Python declaration is maintained and used by
PyCharm for code intelligence.

> I am curious how you find the corresponding c source code.

The str object is mostly implemented in Objects/unicodeobject.c.  The
int object is mostly implemented in Objects/longobject.c.  Other
built-in types can also be found in that directory.  Each has a
PyMethodDef[] global array that declares the implementations of the
object's methods.  Finding the implementation is then just a matter of
grepping the source for its name.

The function I pointed you to before implements the str.__format__
method.  The str.format method itself is at:

http://hg.python.org/cpython/file/84e73ace3d7e/Objects/stringlib/unicode_format.h#l942

I'm not sure why that one is implemented in a .h file.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Help me pick an API design (OO vs functional)

2013-03-26 Thread Michael Herrmann
On Tuesday, March 26, 2013 2:41:38 PM UTC+1, Mitya Sirenef wrote:
> ... 
> At the __exit__, further commands are no longer routed to that window;
> if it was a nested context, window is switched to the outer context,
> WHEN there are commands in it (i.e. on the first command). This seems
> pretty intuitive to me:
> 
> with notepad1:
>  ^S
>  with notepad2:
>  ^S
>  write('something')
> 

> ...
>  > What I am most afraid of: that the window that's currently the 
>  > context "disappears":
> 
>  > notepad = start("Notepad")
>  > with notepad:
>  > press(ALT + TAB)
>  > write("Am I in Notepad now?")
> 
> 
> Alt-tab needs to be handled by a wrapper function that gives you the
> object of the window you've switched to:
> 
> otherwin = alt_tab()
> with otherwin:
>  ...
> 
> If window is changed within 'with' block, the rest of block should be
> ignored. Perhaps there could also be a way to switch this behaviour off,
> for the entire script or for current block only.
> 
> 
>  > What do you think of designs #3 and #4?
>  > ...
> 
> These are ok, too, but I feel it's much easier to send commands to a
> wrong window vs. context managers. The same command in a different
> window can have vastly different and dangerous effect. In other python
> code that's generally not common at all, and would be bad style:
> 
> lst = lst1
> lst.append('x')
> del lst[3]
> lst.insert(0, 'a')
> lst = lst2
> del lst[2]
> lst.append('y')
> lst = lst3
> lst.insert(0, 'x')
> lst += [1,2]
> 
> I think current window should also be acquired explicitly:
> 
> with get_current_window():
>  type("some kind of snippet")
> 
> For usage when a command should apply to all types of windows.

I was skeptical of your suggestion at first but trying it out on an example 
script made me see its appeal:

notepad_main = start("Notepad")
with notepad_main:
write("Hello World!")
save_dialogue = press(CTRL + 's')
with save_dialogue:
write("test.txt", into="File name")
click("Save")
click("Close")

Forcing the library user to always use the "with ..." seems like overkill 
though. I think the gained precision does not justify this burden on the 
library user. Hm
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Help me pick an API design (OO vs functional)

2013-03-26 Thread Michael Herrmann
On Tuesday, March 26, 2013 3:13:30 PM UTC+1, Neil Cerutti wrote:
> On 2013-03-25, Mitya Sirenef wrote:
> 
> > I think I would prefer context managers. I don't think it's a
> > big problem for win users because this behaviour would be one
> > of the first things documented in the start guide and would be
> > all over example scripts, so a new user missing or forgetting
> > it is not a realistic scenario.
> 
> 
> If window focus switching is really a rarity, and only done
> briefly then I agree that a context manager makes a nice and neat
> solution.
> 
> 
> But it's too powerful a generalisation for such a small corner
> case.
> 
> Have you considered adding a keyword argument to each of your
> global functions, which is normally None, but allows a user to
> provide a prefered focus window?
> 
> enter_text("test.txt", focus=save_dialog)
> 
> press_button(Savebutton, focus=save_dialog)

It's an interesting new idea but I somehow feel it makes the existing functions 
too complicated. Also, having to add it to all existing, and future functions 
sounds a bit too cumbersome to me. 

> (Those are just guesses at your API functions; sorry.)

No worries! Thank you for your suggestion!

Michael
www.getautoma.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Processing user input as it's entered

2013-03-26 Thread Arnaud Delobelle
On 26 March 2013 10:07, Sven  wrote:
> Hello,
>
> Is there a way (ideally cross platform but a *nix OS solution would be
> great) to process user input as they type?
> What I aim to achieve is to count the number of characters a user has
> entered and display it while they are typing. The entered text will also
> need to be captured once the user has finished typing.
>
> This is a gui-less CLI tool for python 2.7
>
> I've seen some information on tty.setraw but I'm not sure how you'd go about
> wiring that up.

Can you use curses (http://docs.python.org/2/library/curses.html)

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


Re: Help me pick an API design (OO vs functional)

2013-03-26 Thread Michael Herrmann
On Tuesday, March 26, 2013 1:42:26 PM UTC+1, Dave Angel wrote:
> ...
> 
> Also, it seems that in this thread, we are using "window" both to refer 
> to a particular application instance (like Notepad1 and Notepad2), and 
> to refer to windows within a single application.
> 
> 
> 
> Anyway, if you're only automating a few specific apps, you're not likely 
> to run into the problems that methods were intended to address.  After 
> all, Notepad's bugs haven't seemed to change for a couple of decades, so 
> why should they fix anything now?
> 
> Having a selected window be an implied object for those global functions 
> yields at least the same problems as any writable global. 
> Multithreading, unexpected side effects from certain functions, 
> callbacks, etc.
> 
> As long as you know the program is going to be simple, pile on the 
> globals.  But as soon as it advances, each of them is a trap to fall into.

You're right with everything you say. globals are bad and it may happen that 
this will bite me. I'm just not sure whether we should sacrifice the simpler 
syntax useful in say 80% of cases for something I'm not yet sure will ever 
become a real problem. 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Help me pick an API design (OO vs functional)

2013-03-26 Thread Michael Herrmann
On Tuesday, March 26, 2013 1:59:58 PM UTC+1, Steven D'Aprano wrote:
> On Tue, 26 Mar 2013 05:04:43 -0700, Michael Herrmann wrote:
> ...
> Am I the only one who appreciates the simplicity of
> 
> > start("Notepad")
> > write("Hello World!")
> > press(CTRL + 's')
> > write("test.txt", into="File name")
> > click("Save")
> > press(ALT + F4)
> 
> > over
> 
> > notepad = start("Notepad")
> > notepad.write("Hello World!")
> > notepad.press(CTRL + 's')
> > notepad.write("test.txt", into="File name")
> > notepad.click("Save")
> > notepad.press(ALT + F4)?
> 
> You are not the only one.
> 
> I suggest that you have a set of functions that work on "the current 
> window", whatever that is. Preferably there should always be a current 
> window, but if not, ensure that you give a clear error message.

This is exactly the way it is currently. I am glad you also see it that way.

> Then you have syntax for operating on any named(?) window. So a user can 
> implicitly operate on the current window:
> 
> select(notepad)
> write("goodbye cruel world")
> save()

One idea would be to use the Window(...) constructor to select windows:

notepad = Window('Untitled - Notepad')
select(notepad)
save()

One advantage of using a global method to switch to a window is that this would 
allow you to directly switch to a Window without having to call Window(...):

switch_to('Untitled - Notepad')

I'm still not fully convinced of a global method though, for the reasons 
several people here have already mentioned.

> or explicitly on any window they like:
> 
> excel.quit()

This example makes it look likely that there will have to be other operations 
that can be performed on windows (/running applications as Dave pointed out). 
So, a 'quit()' method that closes a window in addition to the already mentioned 
focus/select/activate method. This in turn makes the global function less 
attractive as once we start going down that route, global functions will 
proliferate.

> I suggest you dig up an old book on "Hypercard", for Apple Macs in the 
> 1980s and 90s. Back in the day, Macs could only run a single application 
> at a time, and Hypercard was limited to a single window at a time (called 
> a "stack"). But that stack (think: window) could have multiple 
> "cards" (think: window tabs), one of which was always current. 
> Hypercard's built-in programming language Hypertalk let you do things 
> like this:
> 
> go to stack "Notepad"
> type "goodbye cruel world" in field "main" of card 7
> click button "Save"
> click button "Quit" of card "Main" of stack "Excel"
> 
> (more or less... it's been a few years since I've had a classic Mac 
> capable of running Hypercard.)

Very interesting. I had never heard of HyperCard. I read up on it a little and 
it sounds very similar to the model we are internally building of open 
applications (stacks) and their windows (cards). Also funny that HyperCard was 
one of Ward Cunningham's inspirations for coming up with the Wiki idea: 
http://c2.com/cgi/wiki?WikiWikiHyperCard

Thanks for this!

Michael
www.getautoma.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Is it me or is the python-vobject documentation rather lacking?

2013-03-26 Thread cl
I'm trying to use the python vobject package instead of what I use at
the moment (the icalendar package) because it's more widely supported
and available from my Linux repository.

However I'm having a really hard time actually working out how to use
it. The 'Usage examples' at http://vobject.skyhouseconsulting.com/usage.html
have very little about parsing existing .ics files and say "More
examples can be found in source code doctests."  I can't find those
examples at all.  The only test code I can see comprises direct data
entry using the python interpreter directly and is just a mess.

I can open a .ics file and vobject parses it:-

>>> f = open("orage.ics")
>>> p = vobject.readOne(f)
>>> p.vevent.dtstart.value
datetime.date(2012, 3, 16)

... but then I need to know how to iterate through the .ics file and how
to get all the other fields out of an event entry.

Can anyone point me at some examples that do something rather more
extensive than the above example?

Alternatively where do I find how to extract other fields from a vevent
as values like vevent.dtstart.value?  These don't seem to be documented
anywhere obvious in http://vobject.skyhouseconsulting.com/epydoc/.


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


Re: Help me pick an API design (OO vs functional)

2013-03-26 Thread Neil Cerutti
On 2013-03-25, Mitya Sirenef  wrote:
> I think I would prefer context managers. I don't think it's a
> big problem for win users because this behaviour would be one
> of the first things documented in the start guide and would be
> all over example scripts, so a new user missing or forgetting
> it is not a realistic scenario.

If window focus switching is really a rarity, and only done
briefly then I agree that a context manager makes a nice and neat
solution.

But it's too powerful a generalisation for such a small corner
case.

Have you considered adding a keyword argument to each of your
global functions, which is normally None, but allows a user to
provide a prefered focus window?

enter_text("test.txt", focus=save_dialog)
press_button(Savebutton, focus=save_dialog)

(Those are just guesses at your API functions; sorry.)

When focus remains None, your usual assumptions about focus would
apply, otherwise the user preference overrides it.

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


Re: Performance of int/long in Python 3

2013-03-26 Thread Chris Angelico
On Wed, Mar 27, 2013 at 12:38 AM, Cousin Stanley
 wrote:
> Chris Angelico wrote:
>
>> Interesting, so your 3.x sum() is optimizing something somewhere.
>> Strange. Are we both running the same Python ?
>>
>> I got those from apt-get
>> 
>
>   I also installed python here under Debian Wheezy
>   via apt-get and our versions look to be the same 
>
>   -sk-
>
> 2.7.3 (default, Jan  2 2013, 16:53:07)   [GCC 4.7.2]
>
> 3.2.3 (default, Feb 20 2013, 17:02:41)   [GCC 4.7.2]
>
> CPU :  Intel(R) Celeron(R) D CPU 3.33GHz
>
>
>   -ca-
>
> 2.7.3 (default, Jan  2 2013, 13:56:14)   [GCC 4.7.2]
>
> 3.2.3 (default, Feb 20 2013, 14:44:27)   [GCC 4.7.2]
>
> CPU :  ???
>
>
>   Could differences in underlying CPU architecture
>   lead to our differing python integer results ?

Doubtful. I have Intel(R) Core(TM) i5-2500 CPU @ 3.30GHz quad-core
with hyperthreading, but I'm only using one core for this job. I've
run the tests several times and each time, Py2 is a shade under two
seconds for inline/range_sum, and Py3 is about 2.5 seconds for each.
Fascinating.

Just for curiosity's sake, I spun up the tests on my reiplophobic
server, still running Ubuntu Karmic. Pentium(R) Dual-Core  CPU
E6500  @ 2.93GHz.

gideon@gideon:~$ python inttime.py
2.6.4 (r264:75706, Dec  7 2009, 18:45:15)
[GCC 4.4.1]
inline: 2147450880
2.7050409317
range_sum: 2147450880
2.64918494225
forloop: 2147450880
6.58765792847
forloop_offset: 2147450880L
16.5167789459
gideon@gideon:~$ python3 inttime.py
3.1.1+ (r311:74480, Nov  2 2009, 14:49:22)
[GCC 4.4.1]
inline: 2147450880
4.44533085823
range_sum: 2147450880
4.37314105034
forloop: 2147450880
12.4834370613
forloop_offset: 2147450880
13.5000522137

Once again, Py3 is slower on small integers than Py2. So where's the
difference with your system? This is really weird! I assume you can
repeat the tests and get the same result every time?

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


Re: Performance of int/long in Python 3

2013-03-26 Thread Cousin Stanley
Chris Angelico wrote:

> Interesting, so your 3.x sum() is optimizing something somewhere.
> Strange. Are we both running the same Python ? 
> 
> I got those from apt-get
> 

  I also installed python here under Debian Wheezy
  via apt-get and our versions look to be the same 

  -sk-

2.7.3 (default, Jan  2 2013, 16:53:07)   [GCC 4.7.2]

3.2.3 (default, Feb 20 2013, 17:02:41)   [GCC 4.7.2]  

CPU :  Intel(R) Celeron(R) D CPU 3.33GHz


  -ca-

2.7.3 (default, Jan  2 2013, 13:56:14)   [GCC 4.7.2]

3.2.3 (default, Feb 20 2013, 14:44:27)   [GCC 4.7.2]

CPU :  ???


  Could differences in underlying CPU architecture  
  lead to our differing python integer results ?
  


-- 
Stanley C. Kitching
Human Being
Phoenix, Arizona

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


Re: Help me pick an API design (OO vs functional)

2013-03-26 Thread Mitya Sirenef

On 03/26/2013 05:38 AM, Michael Herrmann wrote:

On Tuesday, March 26, 2013  12:40:45 AM UTC+1, Mitya Sirenef wrote:

>> ...
>>
>> I think I would prefer context managers. I don't think it's a big
>> problem for
>> win users because this behaviour would be one of the first things 
documented

>> in the start guide and would be all over example scripts, so a new user
>> missing
>> or forgetting it is not a realistic scenario.
>>
>> The advantages are that it's explicit, blocks are indented and it's
>> impossible to
>> miss which window is the action applied to, and at the same time 
actions are

>> short and easy to type and read.
>
> Thank you for your reply. What do you think of Chris Angelico's points?


At the __exit__, further commands are no longer routed to that window;
if it was a nested context, window is switched to the outer context,
WHEN there are commands in it (i.e. on the first command). This seems
pretty intuitive to me:

with notepad1:
^S
with notepad2:
^S
write('something')




> He wrote:
>> What happens at the __exit__ of the context manager? What happens if
>> context managers are nested? I'd be inclined to the simpler option of
>> an explicit switch (since focus doesn't really "stack" and it'd feel
>> weird for focus to *sometimes* switch away when you're done working
>> with one window), though the context manager syntax does have its
>> advantages too.
>
> What I am most afraid of: that the window that's currently the 
context "disappears":

> notepad = start("Notepad")
> with notepad:
> press(ALT + TAB)
> write("Am I in Notepad now?")


Alt-tab needs to be handled by a wrapper function that gives you the
object of the window you've switched to:

otherwin = alt_tab()
with otherwin:
...

If window is changed within 'with' block, the rest of block should be
ignored. Perhaps there could also be a way to switch this behaviour off,
for the entire script or for current block only.




> What do you think of designs #3 and #4?
>
> notepad_1 = start("Notepad")
> notepad_2 = start("Notepad")
> switch_to(notepad_1)
> write("Hello World!")
> press(CTRL + 'a', CTRL + 'c')
> switch_to(notepad_2)
> press(CTRL + 'v')
>
> notepad_1 = start("Notepad")
> notepad_2 = start("Notepad")
> notepad_1.activate()
> write("Hello World!")
> press(CTRL + 'a', CTRL + 'c')
> notepad_2.activate()
> press(CTRL + 'v')
>
> I somehow prefer "activate" over "focus" as in my feeling, you'd 
normally say that you focus *on* something, so it should be called 
"focus_on" or "give_focus[_to]". Can you say, in everyday English, that 
you "focus a window"? I'm not a native speaker so maybe my feeling is 
misguided.



These are ok, too, but I feel it's much easier to send commands to a
wrong window vs. context managers. The same command in a different
window can have vastly different and dangerous effect. In other python
code that's generally not common at all, and would be bad style:

lst = lst1
lst.append('x')
del lst[3]
lst.insert(0, 'a')
lst = lst2
del lst[2]
lst.append('y')
lst = lst3
lst.insert(0, 'x')
lst += [1,2]


I think current window should also be acquired explicitly:

with get_current_window():
type("some kind of snippet")

For usage when a command should apply to all types of windows.

HTH, -m



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

Food is an important part of a balanced diet.
Fran Lebowitz

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


Re: Performance of int/long in Python 3

2013-03-26 Thread Roy Smith
In article <51512bb5$0$29973$c3e8da3$54964...@news.astraweb.com>,
 Steven D'Aprano  wrote:

> On Mon, 25 Mar 2013 20:55:03 -0400, Roy Smith wrote:
> 
> > In article <5150e900$0$29998$c3e8da3$54964...@news.astraweb.com>,
> >  Steven D'Aprano  wrote:
> > 
> >> Also, speaking as somebody who remembers a time when ints where not
> >> automatically promoted to longs (introduced in, Python 2.2, I think?)
> >> let me say that having a single unified int type is *fantastic*,
> > 
> > And incredibly useful when solving Project Euler problems :-)
> > 
> > [I remember when strings didn't have methods]
> 
> No string methods? You were lucky. When I were a lad, you couldn't even 
> use "" delimiters for strings.
> 
> >>> "b string"
> Parsing error: file , line 1:
> "b string"
>  ^
> Unhandled exception: run-time error: syntax error
> 
> 
> Python 0.9.1.

OK, you've got me beat.  For Python.  Am I going to have to go dig out 
my old IBM-1130 assembler decks?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Help me pick an API design (OO vs functional)

2013-03-26 Thread Steven D'Aprano
On Tue, 26 Mar 2013 05:04:43 -0700, Michael Herrmann wrote:

> On Tuesday, March 26, 2013 11:26:30 AM UTC+1, Dave Angel wrote:
>> ...
>> Seems to me that the official interface should all be methods. 
>> However, you could have a new object which always represents the
>> "focus" window.
>>   Then the USER could define trivial functions:
>> 
>> def write(*args):
>>  focused.write(*args)
> 
> It's an interesting idea. But why not give this write(...) to them in
> the first place? Am I the only one who appreciates the simplicity of
> 
> start("Notepad")
> write("Hello World!")
> press(CTRL + 's')
> write("test.txt", into="File name")
> click("Save")
> press(ALT + F4)
> 
> over
> 
> notepad = start("Notepad")
> notepad.write("Hello World!")
> notepad.press(CTRL + 's')
> notepad.write("test.txt", into="File name")
> notepad.click("Save")
> notepad.press(ALT + F4)?

You are not the only one.

I suggest that you have a set of functions that work on "the current 
window", whatever that is. Preferably there should always be a current 
window, but if not, ensure that you give a clear error message.

Then you have syntax for operating on any named(?) window. So a user can 
implicitly operate on the current window:

select(notepad)
write("goodbye cruel world")
save()

or explicitly on any window they like:

excel.quit()


I suggest you dig up an old book on "Hypercard", for Apple Macs in the 
1980s and 90s. Back in the day, Macs could only run a single application 
at a time, and Hypercard was limited to a single window at a time (called 
a "stack"). But that stack (think: window) could have multiple 
"cards" (think: window tabs), one of which was always current. 
Hypercard's built-in programming language Hypertalk let you do things 
like this:


go to stack "Notepad"
type "goodbye cruel world" in field "main" of card 7
click button "Save"

click button "Quit" of card "Main" of stack "Excel"


(more or less... it's been a few years since I've had a classic Mac 
capable of running Hypercard.)




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


Re: [WSGI] Tell Python to listen to LAN interface?

2013-03-26 Thread Gilles
On Tue, 26 Mar 2013 23:50:36 +1100, Chris Angelico 
wrote:
>According to the docstring, the first argument to make_server() is the
>host name to bind to. Using "localhost" means you're bound to
>127.0.0.1, as you see. Use your LAN IP address there, or "" to bind to
>all local addresses - or possibly "::" to bind to all IPv6 addresses
>(try it and see - some systems work with one or the other, others work
>happily with both together).

Thanks Chris. I was thinking it was due to how Python was configured,
and didn't first check that it could be some instruction in the script
itself. It works fine now.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [WSGI] Tell Python to listen to LAN interface?

2013-03-26 Thread Chris Angelico
On Tue, Mar 26, 2013 at 11:26 PM, Gilles  wrote:
> Hello
>
> I'm following this tutorial to learn about writing Python apps in
> WSGI:
>
> http://webpython.codepoint.net/wsgi_tutorial

I'm guessing you're using the initialization code from here?

http://webpython.codepoint.net/wsgi_environment_dictionary

According to the docstring, the first argument to make_server() is the
host name to bind to. Using "localhost" means you're bound to
127.0.0.1, as you see. Use your LAN IP address there, or "" to bind to
all local addresses - or possibly "::" to bind to all IPv6 addresses
(try it and see - some systems work with one or the other, others work
happily with both together).

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


Re: At a loss on python scoping.

2013-03-26 Thread Steven D'Aprano
On Tue, 26 Mar 2013 14:19:21 +0800, Shiyao Ma wrote:

> PS, I now python's scoping rule is lexical rule (aka static rule). How
> does LEGB apply to class?

It doesn't. Python does not use the same lookup rules for attributes and 
unqualified names.

Attribute lookups follow inheritance rules. `instance.name` searches in 
this order, from first to last:

if it exists, call instance.__class__.__getattribute__(name);
look in the instance __dict__;
look in the class __dict__; 
for each superclass in the inheritance chain:
look in the superclass __dict__;
if it exists, call instance.__class__.__getattr__(name)

(the above is a little simplified, but is close enough for ordinary work).


Unqualified `name` follow this lookup rule:

if name is recognised by the compiler as a local name:
look in the local function namespace;
otherwise:
look in any enclosing function scopes;
look in the global scope;
look in the builtins.



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


Re: Help me pick an API design (OO vs functional)

2013-03-26 Thread Dave Angel

On 03/26/2013 08:04 AM, Michael Herrmann wrote:

On Tuesday, March 26, 2013 11:26:30 AM UTC+1, Dave Angel wrote:

...
Seems to me that the official interface should all be methods.  However,
you could have a new object which always represents the "focus" window.
   Then the USER could define trivial functions:

def write(*args):
  focused.write(*args)


It's an interesting idea. But why not give this write(...) to them in the first 
place?


Just to be clear, I was avoiding the problem of having two ways of 
accessing each function, since most of us prefer the methods, and you 
have some users who prefer simple functions.



Am I the only one who appreciates the simplicity of

 start("Notepad")
 write("Hello World!")
 press(CTRL + 's')
 write("test.txt", into="File name")
 click("Save")
 press(ALT + F4)

over

 notepad = start("Notepad")
 notepad.write("Hello World!")
 notepad.press(CTRL + 's')
 notepad.write("test.txt", into="File name")
 notepad.click("Save")
 notepad.press(ALT + F4)?


Somewhere in this thread you mention that save() creates a new window,
so a method-oriented approach would require that the user get that
window object, and call its methods rather than the original window's.
I say that's a very good thing, since the things you send may very well
have very different meanings to the save dialog than they do in the
original one.


save() is not a function, but I assume you mean the action that opens the 
"Save" dialogue (I think that'd be `press(CTRL + 's')`). You are right that 
it's nice for it to be explicit. However, in 95% of cases, the window you want the next 
action to be performed in is the window that is currently active. I appreciate the 
explicitness, but to force it on the user for only 5% of cases seems a bit much.


Another concern I'd have is what happens if the user changes focus with
his mouse?  Does that change the meaning you had for focus() in the
above exchange?  Do you want your press() method to apply to a different
window when the user changes to that window?


No. Internally, we remember which window is the currently active window. If you 
just run a script without user-intervention, this will be the respective 
foreground window. If some other window is in the foreground - which most 
typically happens when the user is interactively entering commands one after 
the other, so the foreground window is the console window, we do switch to the 
window that's supposed to be the active one. It may sound like black magic, but 
it works very well in practice, and really is not too ambiguous. When you read 
a script like

start("Notepad")
write("Hello World")
press(CTRL + 's')
write("test.txt", into="File name")
click("Save")
click("Close")

I hold that you intuitively know what's going on, without even thinking about 
window switching.



Until the program you're scripting makes some minor change in its 
interface, or has something conditional on an attribute not intuitively 
obvious.


Also, it seems that in this thread, we are using "window" both to refer 
to a particular application instance (like Notepad1 and Notepad2), and 
to refer to windows within a single application.


Anyway, if you're only automating a few specific apps, you're not likely 
to run into the problems that methods were intended to address.  After 
all, Notepad's bugs haven't seemed to change for a couple of decades, so 
why should they fix anything now?


Having a selected window be an implied object for those global functions 
yields at least the same problems as any writable global. 
Multithreading, unexpected side effects from certain functions, 
callbacks, etc.


As long as you know the program is going to be simple, pile on the 
globals.  But as soon as it advances, each of them is a trap to fall into.


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


Re: Help me pick an API design (OO vs functional)

2013-03-26 Thread Michael Herrmann
On Tuesday, March 26, 2013 1:16:56 PM UTC+1, Jean-Michel Pichavant wrote:
> - Original Message -
> > > > notepad_1 = start("Notepad")
> > > > notepad_2 = start("Notepad")
> > > > notepad_1.write("Hello World!")
> > > > notepad_1.press(CTRL + 'a', CTRL + 'c')
> > > > notepad_2.press(CTRL + 'v')
> > > > 
> 
>  ^
>  |
>   here, this is an above example :D
> 
> > > > The problem with this design is that it effectively duplicates
> > > > our
> > > > API: We want to keep our "global" functions because they are so
> > > > easy
> > > > to read.
> > > 
> > > So is the example above. This is the best solution in my opinion.
> > 

Ah, so you meant "is also easy to read" ;) I agree but the example with global 
functions is even easier to read. I guess I am being pretty anal about these 
issues, but I see every unnecessary syntax we can save as a win.

> [snip]
> > Doesn't the IPython do auto-completion for "global" functions?
> 
> Yes it does, but as Chris pointed out, your global/module namespace will be 
> "polluted" by a lot of names.
> By using completion on an object, you get the method it has access to, which 
> is very useful to narrow down what you can do with it.

I see. I know you prefer design #1 but that would at least place design #4 over 
#3, right?

Thanks.
Michael
www.getautoma.com
-- 
http://mail.python.org/mailman/listinfo/python-list


[WSGI] Tell Python to listen to LAN interface?

2013-03-26 Thread Gilles
Hello

I'm following this tutorial to learn about writing Python apps in
WSGI:

http://webpython.codepoint.net/wsgi_tutorial

On a Linux host with Python 2.6.6 installed, I launched the
"Environment dictionary" sample, but can't connect to it from my
remote Windows host since the application only accepts local queries:

# netstat -tunlp
...
tcp0  0 127.0.0.1:8051  0.0.0.0:* LISTEN
13110/python

How can I tell the Python interpreter to listen on 0.0.0.0 or at least
192.168.0.0/24?

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


Re: Help me pick an API design (OO vs functional)

2013-03-26 Thread Michael Herrmann
On Tuesday, March 26, 2013 12:57:21 PM UTC+1, Chris Angelico wrote:
> On Tue, Mar 26, 2013 at 10:52 PM, Michael Herrmann
> > Doesn't the IPython do auto-completion for "global" functions?
> 
> Even if it does, it'll be polluted with every other global. Methods
> don't have that problem. On the flip side, since presumably this is
> (will be) a module, anyone who wants autocomplete of its top-level
> functions can simply "import module" instead of "from module import
> *", which will do the same namespacing.

True! I don't think "polluting" the global namespace is that much of an issue.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Help me pick an API design (OO vs functional)

2013-03-26 Thread Michael Herrmann
On Tuesday, March 26, 2013 12:43:18 PM UTC+1, Chris Angelico wrote:
> On Tue, Mar 26, 2013 at 8:38 PM, Michael Herrmann
> 
> > What do you think of designs #3 and #4?
> 
> > notepad_1 = start("Notepad")
> > notepad_2 = start("Notepad")
> > switch_to(notepad_1)
> > write("Hello World!")
> > press(CTRL + 'a', CTRL + 'c')
> > switch_to(notepad_2)
> > press(CTRL + 'v')
> >
> 
> > notepad_1 = start("Notepad")
> > notepad_2 = start("Notepad")
> > notepad_1.activate()
> > write("Hello World!")
> > press(CTRL + 'a', CTRL + 'c')
> > notepad_2.activate()
> > press(CTRL + 'v')
> 
> Ehh, I referred to these as options 2 and 4. Got lost in the indexing
> somewhere. These are the same two I meant, though - these are the
> options I think are the most plausible.
> 
> (Hindsight being 20/20, it'd have been awesome if the original
> snippets had had identifiers next to them. Oh well, no matter.)

True, and the indexing mistake was my fault... Here goes:

Design #1:
notepad_1 = start("Notepad") 
notepad_2 = start("Notepad") 
notepad_1.write("Hello World!") 
notepad_1.press(CTRL + 'a', CTRL + 'c') 
notepad_2.press(CTRL + 'v')

Design #2:
notepad_1 = start("Notepad") 
notepad_2 = start("Notepad") 
switch_to(notepad_1) 
write("Hello World!") 
press(CTRL + 'a', CTRL + 'c') 
switch_to(notepad_2) 
press(CTRL + 'v')

Design #3:
notepad_1 = start("Notepad") 
notepad_2 = start("Notepad") 
with notepad_1: 
write("Hello World!") 
press(CTRL + 'a', CTRL + 'c') 
with notepad_2: 
press(CTRL + 'v')

Design #4:
notepad_1 = start("Notepad") 
notepad_2 = start("Notepad") 
notepad_1.activate() 
write("Hello World!") 
press(CTRL + 'a', CTRL + 'c') 
notepad_2.activate() 
press(CTRL + 'v')

Michael
www.getautoma.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Help me pick an API design (OO vs functional)

2013-03-26 Thread Jean-Michel Pichavant


- Original Message -
> On Tuesday, March 26, 2013 11:07:45 AM UTC+1, Jean-Michel Pichavant
> wrote:
> > - Original Message -
> > >   notepad_1 = start("Notepad")
> > >   notepad_2 = start("Notepad")
> > >   notepad_1.write("Hello World!")
> > >   notepad_1.press(CTRL + 'a', CTRL + 'c')
> > >   notepad_2.press(CTRL + 'v')
> > > 

 ^
 |
  here, this is an above example :D

> > > The problem with this design is that it effectively duplicates
> > > our
> > > API: We want to keep our "global" functions because they are so
> > > easy
> > > to read.
> > 
> > So is the example above. This is the best solution in my opinion.
> 
> Thanks for your reply. What do you mean by "So is the example above"
> though?

Well the example above :).

 
[snip]
> Doesn't the IPython do auto-completion for "global" functions?

Yes it does, but as Chris pointed out, your global/module namespace will be 
"polluted" by a lot of names.
By using completion on an object, you get the method it has access to, which is 
very useful to narrow down what you can do with it.

JM


-- IMPORTANT NOTICE: 

The contents of this email and any attachments are confidential and may also be 
privileged. If you are not the intended recipient, please notify the sender 
immediately and do not disclose the contents to any other person, use it for 
any purpose, or store or copy the information in any medium. Thank you.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Help me pick an API design (OO vs functional)

2013-03-26 Thread Michael Herrmann
On Tuesday, March 26, 2013 12:38:35 PM UTC+1, Chris Angelico wrote:
> ...
> Fundamental point: As I understand the API, it doesn't *actually* tie
> to a window. You don't locate the Notepad window and send it keys -
> you switch focus to Notepad and then send keys to the whole system. Is
> this correct? I'm basing my understanding on this paragraph from your
> original post:
> 
> > We do not (yet) have a functionality that allows you to explicitly switch 
> > to a
> > specific window. Such a functionality would for instance make it possible to
> > open two Notepad windows using the start(...) command, and copy text
> > between them.
> 
> If so, then all of the method-based options are effectively lying,
> because they imply a binding that's not there. The actual sequence of
> actions includes imperatives of "switch to some other window", so I
> think that's what the API should reflect. Otherwise, there's risk that
> something will get horribly horribly confused between the programmer's
> brain and the end result (which could happen on either side of your
> code).

As I just wrote in my reply to Dave, internally we know very well which window 
an action is to be performed in. This window is the window that'd be in the 
foreground after the previous action, if nothing interferes with the system 
while the script is being executed. A common exception is when you enter 
commands in the interactive interpreter: say you write

>>> start("Notepad")

The Notepad window opens, but for you to enter the next command, you have to 
switch back to the interpreter window. If you do that, and enter

>>> write("Hello World")

then we remember that you were previously working with the Notepad window and 
activate this window before performing the key strokes to type "Hello World".

> But if you can unambiguously identify a running instance of something
> and switch to it, then a method on the object that start() returns
> would be absolutely correct. So I'd be looking at either your second
> or fourth options from the original post.

Those are also my favorites at the moment :)

Michael
www.getautoma.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Help me pick an API design (OO vs functional)

2013-03-26 Thread Michael Herrmann
On Tuesday, March 26, 2013 11:26:30 AM UTC+1, Dave Angel wrote:
> ...
> Seems to me that the official interface should all be methods.  However, 
> you could have a new object which always represents the "focus" window. 
>   Then the USER could define trivial functions:
> 
> def write(*args):
>  focused.write(*args)

It's an interesting idea. But why not give this write(...) to them in the first 
place? Am I the only one who appreciates the simplicity of

start("Notepad") 
write("Hello World!") 
press(CTRL + 's') 
write("test.txt", into="File name") 
click("Save") 
press(ALT + F4) 

over 

notepad = start("Notepad") 
notepad.write("Hello World!") 
notepad.press(CTRL + 's') 
notepad.write("test.txt", into="File name") 
notepad.click("Save") 
notepad.press(ALT + F4)?

> Somewhere in this thread you mention that save() creates a new window, 
> so a method-oriented approach would require that the user get that 
> window object, and call its methods rather than the original window's. 
> I say that's a very good thing, since the things you send may very well 
> have very different meanings to the save dialog than they do in the 
> original one.

save() is not a function, but I assume you mean the action that opens the 
"Save" dialogue (I think that'd be `press(CTRL + 's')`). You are right that 
it's nice for it to be explicit. However, in 95% of cases, the window you want 
the next action to be performed in is the window that is currently active. I 
appreciate the explicitness, but to force it on the user for only 5% of cases 
seems a bit much. 

> Another concern I'd have is what happens if the user changes focus with 
> his mouse?  Does that change the meaning you had for focus() in the 
> above exchange?  Do you want your press() method to apply to a different 
> window when the user changes to that window?

No. Internally, we remember which window is the currently active window. If you 
just run a script without user-intervention, this will be the respective 
foreground window. If some other window is in the foreground - which most 
typically happens when the user is interactively entering commands one after 
the other, so the foreground window is the console window, we do switch to the 
window that's supposed to be the active one. It may sound like black magic, but 
it works very well in practice, and really is not too ambiguous. When you read 
a script like

start("Notepad")
write("Hello World")
press(CTRL + 's')
write("test.txt", into="File name")
click("Save")
click("Close")

I hold that you intuitively know what's going on, without even thinking about 
window switching.

Best,
Michael
www.getautoma.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Help me pick an API design (OO vs functional)

2013-03-26 Thread Chris Angelico
On Tue, Mar 26, 2013 at 10:52 PM, Michael Herrmann
 wrote:
> Doesn't the IPython do auto-completion for "global" functions?

Even if it does, it'll be polluted with every other global. Methods
don't have that problem. On the flip side, since presumably this is
(will be) a module, anyone who wants autocomplete of its top-level
functions can simply "import module" instead of "from module import
*", which will do the same namespacing.

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


Re: Help me pick an API design (OO vs functional)

2013-03-26 Thread Michael Herrmann
On Tuesday, March 26, 2013 11:07:45 AM UTC+1, Jean-Michel Pichavant wrote:
> - Original Message -
> > notepad_1 = start("Notepad")
> > notepad_2 = start("Notepad")
> > notepad_1.write("Hello World!")
> > notepad_1.press(CTRL + 'a', CTRL + 'c')
> > notepad_2.press(CTRL + 'v')
> > 
> > The problem with this design is that it effectively duplicates our
> > API: We want to keep our "global" functions because they are so easy
> > to read. 
> 
> So is the example above. This is the best solution in my opinion. 

Thanks for your reply. What do you mean by "So is the example above" though? 

> I think you're having the same issue that some other APIs, let's say 
> matplotlib for example. They try to accommodate scientists (matlab) and 
> programmers(python) by having a double API style.
> 
> One looks like
> 
> legend()
> title()
> plot()
> save()
> 
> the other looks like
> 
> fig = figure()
> fig.add_legend()
> fig.title()
> fig.plot()
> fig.save()
> 
> The problem is, when searching for example on the net, you'll end up with a 
> mix of both, it can become a nightmare.

Interesting point. I'll google a little about matplotlib.

> I definitely prefer the later, for the reasons that have already been given 
> to you in this thread and by the fact that with the correct (I)python shell, 
> you can create your window object and get auto-completion on its methods just 
> by hitting , very helpful when introspecting objects. Can be achieved of 
> course in any python shell with function like dir() ; my point being that OOO 
> design keeps things in their place, see the zen of python "Namespaces are one 
> honking great idea -- let's do more of those!"

Doesn't the IPython do auto-completion for "global" functions? 

Thanks,
Michael (www.getautoma.com)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Help me pick an API design (OO vs functional)

2013-03-26 Thread Chris Angelico
On Tue, Mar 26, 2013 at 8:38 PM, Michael Herrmann
 wrote:
> What do you think of designs #3 and #4?
>
> notepad_1 = start("Notepad")
> notepad_2 = start("Notepad")
> switch_to(notepad_1)
> write("Hello World!")
> press(CTRL + 'a', CTRL + 'c')
> switch_to(notepad_2)
> press(CTRL + 'v')
>
> notepad_1 = start("Notepad")
> notepad_2 = start("Notepad")
> notepad_1.activate()
> write("Hello World!")
> press(CTRL + 'a', CTRL + 'c')
> notepad_2.activate()
> press(CTRL + 'v')

Ehh, I referred to these as options 2 and 4. Got lost in the indexing
somewhere. These are the same two I meant, though - these are the
options I think are the most plausible.

(Hindsight being 20/20, it'd have been awesome if the original
snippets had had identifiers next to them. Oh well, no matter.)

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


Re: Help me pick an API design (OO vs functional)

2013-03-26 Thread Chris Angelico
On Tue, Mar 26, 2013 at 7:53 PM, Michael Herrmann
 wrote:
> On Monday, March 25, 2013 10:08:53 PM UTC+1, Chris Angelico wrote:
>> ...
>> > I kind of like the context manager solution because the indentation makes 
>> > it very obvious what happens in which window. You are right about our 
>> > target group though. Also, the "with" is not as explicit as it probably 
>> > should be.
>>
>> What happens at the __exit__ of the context manager? What happens if
>> context managers are nested? I'd be inclined to the simpler option of
>> an explicit switch (since focus doesn't really "stack" and it'd feel
>> weird for focus to *sometimes* switch away when you're done working
>> with one window), though the context manager syntax does have its
>> advantages too.
>
> You are right, an __exit__ for a window doesn't really make sense and neither 
> does stacking. There's also the problem that the focus window may change - 
> for instance when closing it. What happens if you're still inside the "with 
> ..." then? At first glance, I think the context manager solution looks nice 
> syntactically, but maybe it isn't the way to go here.

Fundamental point: As I understand the API, it doesn't *actually* tie
to a window. You don't locate the Notepad window and send it keys -
you switch focus to Notepad and then send keys to the whole system. Is
this correct? I'm basing my understanding on this paragraph from your
original post:
> We do not (yet) have a functionality that allows you to explicitly switch to a
> specific window. Such a functionality would for instance make it possible to
> open two Notepad windows using the start(...) command, and copy text
> between them.

If so, then all of the method-based options are effectively lying,
because they imply a binding that's not there. The actual sequence of
actions includes imperatives of "switch to some other window", so I
think that's what the API should reflect. Otherwise, there's risk that
something will get horribly horribly confused between the programmer's
brain and the end result (which could happen on either side of your
code).

But if you can unambiguously identify a running instance of something
and switch to it, then a method on the object that start() returns
would be absolutely correct. So I'd be looking at either your second
or fourth options from the original post.

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


Re: At a loss on python scoping.

2013-03-26 Thread Shiyao Ma
After read Dave's answer, I think I confused LEGB with attribute lookup.
So, a.r has nothing to do with LEGB.

On Tue, Mar 26, 2013 at 7:03 PM, Shiyao Ma  wrote:

> Thx, really a nice and detailed explanation.
>
>
> On Tue, Mar 26, 2013 at 6:07 PM, Dave Angel  wrote:
>
>> On 03/26/2013 02:17 AM, Shiyao Ma wrote:
>>
>>> Hi,
>>> suppose I have a file like this:
>>> class A:
>>>  r = 5
>>>  def func(self, s):
>>>  self.s = s
>>> a = A()
>>> print(a.r)# this should print 5, but where does py store the name of
>>> r
>>>
>>> a.func(3)
>>> print(a.s)# this should print 3, also where does py store this name.
>>> what's the underlying difference between the above example?
>>>
>>>
>> I don't think this is a scoping question at all.  These references are
>> fully qualified, so scoping doesn't enter in.
>>
>> The class A has a dictionary containing the names of r and func.  These
>> are class attributes.  Each instance has a dictionary which will contain
>> the name s AFTER the A.func() is called.  Ideally such an attribute will be
>> assigned in the __init__() method, in which case every instance will have s
>> in its dictionary.
>>
>> When you use a.qqq  the attribute qqq is searched for in the instance
>> dictionary and, if not found, in the class dictionary.  If still not found,
>> in the parent classes' dictionary(s).
>>
>> You can use dir(A) and dir(a) to look at these dictionaries, but it shows
>> you the combination of them, so it's not as clear.  In other words, dir(a)
>> shows you both dictionaries, merged.  (Seems to me dir also sometimes
>> censors some of the names, but that's a vague memory. It's never left out
>> anything I cared about, so maybe it's things like single-underscore names,
>> or maybe just a poor memory.)
>>
>>
>> --
>> DaveA
>> --
>> http://mail.python.org/**mailman/listinfo/python-list
>>
>
>
>
> --
> My gpg pubring is available via: gpg --keyserver subkeys.pgp.net--recv-keys 
> 307CF736
>
> More on: http://about.me/introom
>
>


-- 
My gpg pubring is available via: gpg --keyserver
subkeys.pgp.net--recv-keys 307CF736

More on: http://about.me/introom
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: At a loss on python scoping.

2013-03-26 Thread Shiyao Ma
Thx, really a nice and detailed explanation.

On Tue, Mar 26, 2013 at 6:07 PM, Dave Angel  wrote:

> On 03/26/2013 02:17 AM, Shiyao Ma wrote:
>
>> Hi,
>> suppose I have a file like this:
>> class A:
>>  r = 5
>>  def func(self, s):
>>  self.s = s
>> a = A()
>> print(a.r)# this should print 5, but where does py store the name of r
>>
>> a.func(3)
>> print(a.s)# this should print 3, also where does py store this name.
>> what's the underlying difference between the above example?
>>
>>
> I don't think this is a scoping question at all.  These references are
> fully qualified, so scoping doesn't enter in.
>
> The class A has a dictionary containing the names of r and func.  These
> are class attributes.  Each instance has a dictionary which will contain
> the name s AFTER the A.func() is called.  Ideally such an attribute will be
> assigned in the __init__() method, in which case every instance will have s
> in its dictionary.
>
> When you use a.qqq  the attribute qqq is searched for in the instance
> dictionary and, if not found, in the class dictionary.  If still not found,
> in the parent classes' dictionary(s).
>
> You can use dir(A) and dir(a) to look at these dictionaries, but it shows
> you the combination of them, so it's not as clear.  In other words, dir(a)
> shows you both dictionaries, merged.  (Seems to me dir also sometimes
> censors some of the names, but that's a vague memory. It's never left out
> anything I cared about, so maybe it's things like single-underscore names,
> or maybe just a poor memory.)
>
>
> --
> DaveA
> --
> http://mail.python.org/**mailman/listinfo/python-list
>



-- 
My gpg pubring is available via: gpg --keyserver
subkeys.pgp.net--recv-keys 307CF736

More on: http://about.me/introom
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: JES account balance function help urgent!

2013-03-26 Thread Dave Angel

On 03/26/2013 06:30 AM, kidom...@gmail.com wrote:

I am supposed to complete the following five functions, i have no idea how to 
do this. I will greatly appreciate any help

The following five functions allow you to maintain the running balance of an 
account and print out lines relating to each transaction.

You'll also need a global variable (balance?) to maintain the running balance 
of the account.

1. def setBalance(amt): # Defines (but doesn't print) the value of the account 
balance

2. def printBalance(): # Displays current balance as a money value with a 
heading

3. def printLedgerLine(date, amount, details): # with items (and the balance) 
spaced and formatted

4. def deposit (date, details, amount): # Alter the balance and print ledger 
line

5. def withdraw(date, details, amount): # Alter the balance and print ledger 
line

Your task is to:
complete the five (very short) functions by creating the code for the body of 
each function, and
demonstrate that you code works by calling the functions, as is demonstrated 
below.

So when these functions are called
e.g.

setBalance(500)
printBalance()
withdraw("17-12-2012", "BP - petrol", 72.50)
withdraw("19-12-2012", "Countdown", 55.50)
withdraw("20-12-2012", "munchies", 1.99)
withdraw("22-12-2012", "Vodafone", 20)
deposit ("23-12-2012", "Income", 225)
withdraw("24-12-2012", "Presents", 99.02)
printBalance()
The output is something like this:

Current Balance is $ 500.00
17-12-2012 BP - petrol $ 72.50 $ 427.50
19-12-2012 Countdown $ 55.50 $ 372.00
20-12-2012 munchies $ 1.99 $ 370.01
22-12-2012 Vodafone $ 20.00 $ 350.01
23-12-2012 Income $ 225.00 $ 575.01
24-12-2012 Presents $ 99.02 $ 475.99
Current Balance is $ 475.99

So far i got:
def setBalance(amount):
global balance
assert isinstance(amount,numbers.number)
balance = euros
printNow(balance)

Im not sure whats wrong, i only started programming a week ago, im so lost, 
please help me with this assignment
thnx



I'm not sure how literally to take your proposal.  You have no 
indentation in the function body, so that's one serious problem.  And 
you're apparently calling printNow() from within that function, which is 
NOT what was called for.  And the function takes "amount" as its 
parameter, but then uses 'euros' in the body.  That's a big spelling error.


You're also going to need to import numbers, if you want that isinstance 
to work.


The layout of your code should be something like:

shebang line (optional)
imports
global variables
def's
testing code (supplied by instructor)

Write all the functions, making sure each takes the expected parameters, 
even if the function does nothing more than print its name and 
parameters.  Then when the code runs, refine the function bodies till 
they're all correct.



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


Re: python3 string format

2013-03-26 Thread Shiyao Ma
Thx for your reply.
I am using pycharm and simply press "go to declaration" which directs me to
a py file, containing the following code:
def format(*args, **kwargs): # known special case of str.format
"""
S.format(*args, **kwargs) -> string

Return a formatted version of S, using substitutions from args and
kwargs.
The substitutions are identified by braces ('{' and '}').
"""
pass
I am curious how you find the corresponding c source code.

On Tue, Mar 26, 2013 at 2:16 PM, Ian Kelly  wrote:

> On Mon, Mar 25, 2013 at 10:24 PM, Shiyao Ma  wrote:
> > HI.
> > one thing confuses me.
> > It is said in the pep3101 that "{}".format (x) will invoke the method
> > x.__format__
> > However, I looked at the src of python3 and found:
> > in class str(object), the format simply contains a pass statement
> > in class int(object), things is the same.
>
> I don't know what source you're looking at.  In CPython, both of those
> types are implemented in C, not Python, so there would be no pass
> statements involved.
>
> The int.__format__ method is implemented at:
>
> http://hg.python.org/cpython/file/3c437e591499/Objects/longobject.c#l4373
>
> It mainly just calls the _PyLong_FormatAdvancedWriter function, which is
> at:
>
>
> http://hg.python.org/cpython/file/3c437e591499/Python/formatter_unicode.c#l1399
>
> The str.__format__ method similarly is implemented at:
>
>
> http://hg.python.org/cpython/file/3c437e591499/Objects/unicodeobject.c#l12851
>
> and calls the _PyUnicode_FormatAdvancedWriter function at:
>
>
> http://hg.python.org/cpython/file/3c437e591499/Python/formatter_unicode.c#l1363
> --
> http://mail.python.org/mailman/listinfo/python-list
>



-- 
My gpg pubring is available via: gpg --keyserver
subkeys.pgp.net--recv-keys 307CF736

More on: http://about.me/introom
-- 
http://mail.python.org/mailman/listinfo/python-list


  1   2   >