Re: Question about ast.literal_eval

2013-05-21 Thread Steven D'Aprano
On Tue, 21 May 2013 08:30:03 +0200, Frank Millman wrote:

> On 20/05/2013 18:12, Steven D'Aprano wrote:

>> Personally, I would strongly suggest writing your own mini- evaluator
>> that walks the list and evaluates it by hand. It isn't as convenient as
>> just calling eval, but *definitely* safer.
>>
>>
> I am not sure I can wrap my mind around mixed 'and's, 'or's, and
> brackets.


Parsers are a solved problem in computer science, he says as if he had a 
clue what he was talking about *wink*

Here's a sketch of a solution... suppose you have a sequence of records, 
looking like this:

(bool_op, column_name, comparison_op, literal)

with appropriate validation on each field. The very first record has 
bool_op set to "or". Then, you do something like this:


import operator
OPERATORS = {
'=': operator.eq,
'is': operator.is_,
'<': operator.lt,
# etc.
}


def eval_op(column_name, op, literal):
value = lookup(column_name)  # whatever...
return OPERATORS[op](value, literal)

result = False

for (bool_op, column_name, comparison_op, literal) in sequence:
flag = eval_op(column_name, comparison_op, literal)
if bool_op == 'and':
result = result and flag
else: 
assert bool_op == 'or'
result = result or flag
# Lazy processing?
if result:
break


and in theory it should all Just Work.




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


Re: Question about ast.literal_eval

2013-05-21 Thread Chris Angelico
On Tue, May 21, 2013 at 4:46 PM, Frank Millman  wrote:
> You may be right, Chris, but I don't think my approach is all that bad.

Frankly, I'm not altogether convinced that our approach is right
either :) But like the Oracle in the Matrix, I'm not here to push you
to one decision or another so much as to just put the options in front
of you and let you make up your own  mind. Except in a
few cases where I'm really certain of my ground (like "don't put any
untrusted data through eval()"...).

> The vast majority of tests will be simple - either a single line, or two
> lines for a range check, with no brackets at all.
>
> If the requirement is more complicated than that, well, I don't think the
> complication can be avoided, and at least this approach gives full control.

Yeah, and this is where the issue of complexity points comes in.
You're spending a lot of them on functionality that most users won't
even use, and those who do will use only occasionally. You're forcing
them to match their brackets (not just have the same number of each
type, but also to get the nesting correct), and according to your
current spec, there can be no more than one open/close bracket at each
condition, so they'll have to arbitrarily add dummy conditions to make
certain forms of nesting work. You're exposing a lot of the underlying
interpreter, while forcing the user to dance wearing a body cast.
Sure, it can work, but it's unnecessarily hard.

> FWIW, I use the same approach to allow users to construct their own WHERE
> clauses in custom views. Again, the vast majority are simple, but there are
> times when it can get complicated.

Our alpha system is actually online, and we have exactly that system -
a query builder that renders down to a WHERE clause. If you're
curious, message me offline and I'll give you the URL.

> The proof of the pudding will be when I try to get ordinary users to get
> their own hands dirty - I am not there yet. If I ever get this released, the
> business model will be free software, but support will be charged for. So if
> a user gets out of his/her depth, there will be assistance available.
>
> Time will tell who is right ... ;-)

Who is right, and who is dead. Hey, are you aware that both Steven and
I come from Australia, and that we are used to having people not trust
us? Truly, you have a dizzying intellect!

ChrisA
... couldn't resist...
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to run a python script twice randomly in a day?

2013-05-21 Thread Chris Angelico
On Tue, May 21, 2013 at 11:12 AM, Cameron Simpson  wrote:
> Ok, good. Some minor remarks:
>
> Personally, I always use:
>
>   #!/bin/sh
>
> instead of requiring bash. All UNIX systems have sh, bash is only
> common. And even when present, it may not be in /bin. /bin/sh is
> always there, and unless you're doing something quite unusual, it
> works just fine.

Also, on many systems, /bin/sh is a much lighter interpreter than bash
(eg Debian uses dash). It's more efficient to use that when you can,
even if you use bash for your login shell.

> On 20May2013 15:05, Avnesh Shakya  wrote:
> | but when I m using like
> |
> | import random
> | a = random.randrange(0, 59)
> | */a * * * * bash /home/avin/cronJob/test.sh
> | then it's showing error becose of varable 'a', so now how can i take
> | variable?

You put that into your crontab? I do not think this means what you
think it means; cron does not execute arbitrary Python code.

> - randrange() is like other python ranges: it does not include the end value.
>   So your call picks a number from 0..58, not 0..59.
>   Say randrange(0,60). Think "start, length".

Nitpick: It's not start, length; it's start, stop-before. If the start
is 10 and the second argument is 20, you'll get numbers from 10 to 19.
But your conclusion is still accurate :)

ChrisA
(two Princess Bride references in as many threads, doing well!)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Question about ast.literal_eval

2013-05-21 Thread Frank Millman

On 21/05/2013 09:21, Steven D'Aprano wrote:

On Tue, 21 May 2013 08:30:03 +0200, Frank Millman wrote:


I am not sure I can wrap my mind around mixed 'and's, 'or's, and
brackets.


Parsers are a solved problem in computer science, he says as if he had a
clue what he was talking about *wink*

Here's a sketch of a solution... suppose you have a sequence of records,
looking like this:

(bool_op, column_name, comparison_op, literal)

with appropriate validation on each field. The very first record has
bool_op set to "or". Then, you do something like this:

import operator
OPERATORS = {
 '=': operator.eq,
 'is': operator.is_,
 '<': operator.lt,
 # etc.
 }

def eval_op(column_name, op, literal):
 value = lookup(column_name)  # whatever...
 return OPERATORS[op](value, literal)

result = False

for (bool_op, column_name, comparison_op, literal) in sequence:
 flag = eval_op(column_name, comparison_op, literal)
 if bool_op == 'and':
 result = result and flag
 else:
 assert bool_op == 'or'
 result = result or flag
 # Lazy processing?
 if result:
 break

and in theory it should all Just Work.


That's very clever - thanks, Steven.

It doesn't address the issue of brackets. I imagine that the answer is 
something like -


  maintain a stack of results
  for each left bracket, push a level
  for each right bracket, pop the result

or something ...

I am sure that with enough trial and error I can get it working, but I 
might cheat for now and use the trick I mentioned earlier of calling 
eval() on a sequence of manually derived True/False values. I really 
can't see anything going wrong with that.


BTW, thanks to ChrisA for the following tip -

import operator
ops = {
  'in':lambda x,y: x in y,  # operator.contains has the args backwards

I would have battled with that one.

Frank


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


Re: How to run a python script twice randomly in a day?

2013-05-21 Thread Jussi Piitulainen
Chris Angelico writes:

> > On 20May2013 15:05, Avnesh Shakya wrote:
> >   So your call picks a number from 0..58, not 0..59.
> >   Say randrange(0,60). Think "start, length".
> 
> Nitpick: It's not start, length; it's start, stop-before. If the
> start is 10 and the second argument is 20, you'll get numbers from
> 10 to 19.  But your conclusion is still accurate :)

I've sometimes named the latter index "past", as in just past the
range. I'm also happy to call it just "end". The inclusive-style names
might be "first" and "last", so "past" is "last + 1".

The length of the range from "start" to "end" is "end - start" without
a "pest" term that is either -1 or +1 though I forget which; two
consecutive ranges are from b to m, then from m to e; an empty range
is from b to b.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Question about ast.literal_eval

2013-05-21 Thread Fábio Santos
On 21 May 2013 09:10, "Frank Millman"  wrote:
> It doesn't address the issue of brackets. I imagine that the answer is
something like -
>
>   maintain a stack of results
>   for each left bracket, push a level
>   for each right bracket, pop the result
>
> or something ...
>

Time for me to suggest pyparsing or PLY. You're better off creating your
own AST and walking it to produce python or SQL than reinventing the wheel,
I think.
-- 
http://mail.python.org/mailman/listinfo/python-list


sympy.nsimplify

2013-05-21 Thread Steven D'Aprano
For maths nerds like me, this is too cool for words:

http://www.johndcook.com/blog/2013/04/30/recognizing-numbers/



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


please help

2013-05-21 Thread iman . memarpour
WAP in python to accept a list of words on STDIN and searches for a line 
containing all five vowels(a,e,i,o,u)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Question about ast.literal_eval

2013-05-21 Thread Mark Lawrence

On 21/05/2013 09:23, Fábio Santos wrote:


On 21 May 2013 09:10, "Frank Millman" mailto:fr...@chagford.com>> wrote:
 > It doesn't address the issue of brackets. I imagine that the answer
is something like -
 >
 >   maintain a stack of results
 >   for each left bracket, push a level
 >   for each right bracket, pop the result
 >
 > or something ...
 >

Time for me to suggest pyparsing or PLY. You're better off creating your
own AST and walking it to produce python or SQL than reinventing the
wheel, I think.



Or pick one from this lot http://nedbatchelder.com/text/python-parsers.html

--
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: please help

2013-05-21 Thread Chris Angelico
On Tue, May 21, 2013 at 6:38 PM,   wrote:
> WAP in python to accept a list of words on STDIN and searches for a line 
> containing all five vowels(a,e,i,o,u)

Homework.

Have a shot at it yourself, post your code, show that you can put in
some effort. Otherwise we won't see much reason to put in effort for
you.

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


Re: please help

2013-05-21 Thread Mark Lawrence

On 21/05/2013 09:38, iman.memarp...@gmail.com wrote:

WAP in python to accept a list of words on STDIN and searches for a line 
containing all five vowels(a,e,i,o,u)



Sorry we don't do your homework for you.  But your starter for 10 is to 
use raw_input on Python 2 or input on Python 3 to fetch data from stdin. 
 I look forward to reviewing your code.


--
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: sympy.nsimplify

2013-05-21 Thread Chris Angelico
On Tue, May 21, 2013 at 6:26 PM, Steven D'Aprano
 wrote:
> For maths nerds like me, this is too cool for words:
>
> http://www.johndcook.com/blog/2013/04/30/recognizing-numbers/

It is indeed, very cool. I think I need to conjure an excuse to use
this someplace.

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


Re: How to run a python script twice randomly in a day?

2013-05-21 Thread Chris Angelico
On Tue, May 21, 2013 at 6:21 PM, Jussi Piitulainen
 wrote:
> Chris Angelico writes:
>
>> > On 20May2013 15:05, Avnesh Shakya wrote:
>> >   So your call picks a number from 0..58, not 0..59.
>> >   Say randrange(0,60). Think "start, length".
>>
>> Nitpick: It's not start, length; it's start, stop-before. If the
>> start is 10 and the second argument is 20, you'll get numbers from
>> 10 to 19.  But your conclusion is still accurate :)
>
> I've sometimes named the latter index "past", as in just past the
> range. I'm also happy to call it just "end". The inclusive-style names
> might be "first" and "last", so "past" is "last + 1".
>
> The length of the range from "start" to "end" is "end - start" without
> a "pest" term that is either -1 or +1 though I forget which; two
> consecutive ranges are from b to m, then from m to e; an empty range
> is from b to b.

Agreed. The inclusive-exclusive range is by far the most useful.
There's unfortunately a massive case of lock-in here, but Scripture
references would be ever so much more convenient as inc-exc. For
instance, today in family devotions we read Galatians 2:1 - 2:21. At a
glance, do you know whether that's the entire chapter? What if it were
written as Galatians 2 to Galatians 3? Simple!

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


64-bit Python for Solaris

2013-05-21 Thread Matchek
Hello python-list,

I'm looking into creating a 32/64-bit Python (2.x and/or 3.x) package
for Solaris. The specificity of that package is that I need to include
both 32-bit and 64-bit binaries in it. The exact way in which the
32/64 support is done is described at [1].

There currently is a Python package that I maintain, which is 32-bit only[2].

I have made an attempt to build a 64-bit package, and my findings are
that the ${prefix}/lib/pythonX.Y/_sysconfigdata.py file contains
system-specific information. Note that it's not ${libdir}/pythonX.Y -
that would have worked, because I'm specifying different ${libdir}
directories when running the 32-bit and 64-bit builds. The Python
installer specifically uses ${prefix}/lib/pythonX.Y. For the most part
is fine, because most of files in there are not architecture-specific,
and it would be quite good to share them among the 32-bit and 64-bit
binaries at runtime. The problem is that some files differ. I've
described it some more at [3].

Ideally, I'd make _sysconfigdata.py return/set different values
depending on the Python runtime that reads it. Something like:

if we're 64-bit:
  set values for the 64-bit platform
else:
  set values for the 32-bit platform

It's a similar approach to how we currently handle C header files. See
the 'Development packages' section in [1] for more information.

The problem is that it would involve somewhat intrusive patching of
the Python source code, and in long term that means maintainability
issues.

Has this issue been seen before? Is there a better solution? Is there
something that can be done upstream to accommodate this kind of
packaging?

Maciej

[1] http://www.opencsw.org/manual/for-maintainers/32-bit-and-64-bit.html
[2] http://www.opencsw.org/packages/python/
[3] http://lists.opencsw.org/pipermail/maintainers/2013-January/017583.html
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to run a python script twice randomly in a day?

2013-05-21 Thread Cameron Simpson
On 21May2013 17:56, Chris Angelico  wrote:
| On Tue, May 21, 2013 at 11:12 AM, Cameron Simpson  wrote:
| > - randrange() is like other python ranges: it does not include the end 
value.
| >   So your call picks a number from 0..58, not 0..59.
| >   Say randrange(0,60). Think "start, length".
| 
| Nitpick: It's not start, length; it's start, stop-before. If the start
| is 10 and the second argument is 20, you'll get numbers from 10 to 19.
| But your conclusion is still accurate :)

But it's still a useful thing to think when you're trying to reason
about ranges unless you're doing something unusual.

Cheers,
-- 
Cameron Simpson 

Life IS pain, highness...  anyone who tries to tell you different is
trying to sell you something.   - Wesley, The_Princess_Bride
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: sympy.nsimplify

2013-05-21 Thread Skip Montanaro
Very cool indeed.  In the comments was a link to an XKCD cartoon.  Its
tool tip mentioned "twin primes".  Looked that up.  Google pointed (of
course) at Wikipedia.  Read that.  Backed up to the Google Search, and
noticed there is a news item from 15 hours ago that an unknown
mathematician at the University of New Hampshire has proven the twin
primes conjecture:
http://www.wired.com/wiredscience/2013/05/twin-primes/

This is nothing to do with the original post.  It's just amazing to me
how short the distance between one very interesting topic on the net
and something almost unrelated can be.

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


Re: sympy.nsimplify

2013-05-21 Thread Paul Rudin
Skip Montanaro  writes:

> Very cool indeed.  In the comments was a link to an XKCD cartoon.  Its
> tool tip mentioned "twin primes".  Looked that up.  Google pointed (of
> course) at Wikipedia.  Read that.  Backed up to the Google Search, and
> noticed there is a news item from 15 hours ago that an unknown
> mathematician at the University of New Hampshire has proven the twin
> primes conjecture:
> http://www.wired.com/wiredscience/2013/05/twin-primes/
>
> This is nothing to do with the original post.  It's just amazing to me
> how short the distance between one very interesting topic on the net
> and something almost unrelated can be.

AIUI the twin primes conjecture hasn't been proved. But a significant
related fact - that there's an infinitude of primes no more that N apart
where N <~ 70,000,000. That might not sound like a lot of progress - but
the point is that the existence of some finite bound is very
significant.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: PEP 378: Format Specifier for Thousands Separator

2013-05-21 Thread Alysson Bruno
This work in 3.1+:

$ python3
Python 3.1.3 (r313:86834, Nov 28 2010, 11:28:10)
[GCC 4.4.5] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> one_number = 1234567
>>> print('number={:,}'.format(one_number))
number=1,234,567
>>>

paz e amor (love and peace),

Alysson Bruno
===
Palmas(TO)
Brasil

Blog: http://abruno.com
Twitter: http://twitter.com/alyssonbruno
Facebook: http://www.facebook.com/ProfessorAlyssonBruno

=
*Meu alterego Escritor:*

Leia alguns contos que escrevo, não esqueça de me dar sua opinião:
http://goo.gl/Wjn4p 

=


On Tue, May 21, 2013 at 2:44 AM, Ned Deily  wrote:

> In article ,
>  Carlos Nepomuceno  wrote:
> > Is there a way to format integers with thousands separator (digit
> grouping)
> > like the format specifier of str.format()?>
> > I'm currently using the following:>
> > >>> sys.stdout.write('Number = %s\n' % '{:,.0f}'.format(x))
> > Number = 12,345>
> > 'x' is unsigned integer so it's like using a sledgehammer to crack a
> nut!>
> > I'd like to have something like:
> > sys.stdout.write('Number = %,u\n' % x)
> > Is that possible? How can I do it if not already available?
>
> For Python 3.2+ or 2.7, why not just:
>
> >>> print('Number = {:,}'.format(x))
> Number = 12,345
>
> --
>  Ned Deily,
>  n...@acm.org
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Static Maps from Lat Long data in XLS file

2013-05-21 Thread kobewka
Hello,

I'm new to Python, but I think it can solve my problem and I am looking for a 
someone to point me to tutorial or give me some tips here.

I have an xls file that has about 1,000 latitude and longitude points. I want 
to do one of two things: 1) Save a static maps and street view image from the 
coordinates, or 2) create an html file with the map and street view image side 
by side.

I need the urls to look like this: 

Map with a pin in the centre:
http://maps.googleapis.com/maps/api/staticmap?center=43.65162,-79.40571&zoom=16&size=600x600&markers=color:blue%7Clabel:S%7C43.65162,-79.40571&sensor=false

Image:
http://maps.googleapis.com/maps/api/streetview?location=43.65162,%20-79.40571&size=600x600&sensor=false

I am not sure if option 1 will work because the url doesn't actually lead to an 
image, but rather Google returns an image when that url is used. 

Any tips or pointers are much appreciated!
-- 
http://mail.python.org/mailman/listinfo/python-list


suggestions for "best practices lite" for small site deployment with testing

2013-05-21 Thread Harry Percival
Hi everyone,

We've been having a bit of a discussion of this topic over on the Python-UK
list (http://mail.python.org/pipermail/python-uk/2013-May/thread.html#2949),
and I was a bit shy about mailing out to the big, bad, worldwide Python
list, but I'm forcing myself!

So I'm writing a book, for O'Reilly, on TDD with Python, and I'm looking
for some help and suggestions on my current chapter (well, I'm looking for
help and suggestions in general too!  i need all the help i can get.).

http://www.obeythetestinggoat.com/what-to-say-about-deployment.html

So far I've taken the user through building a basic site, and now I want to
get them to deploy it.  It's very early days, but minimum-viable-product
and all that, deploying early + often is a good habit to get into.

cf the blog post above for a bit of background.  I'm currently leaning away
from talking about the various PaaS offerings, they being too many +
varied, and I have a bit of a conflict of interest since I work at
PythonAnywere.  Instead, I'm currently thinking we'll spin up a small linux
box, put apache on it, and run both the staging and live site from  there.
All good stuff to learn...  Hopefully some of the lessons will be
applicable to PaaSes anyway.

So, some questions:
provisioning = spinning up a server, installing apache, setting up
virtualhost config.  confirm I should encourage people to automate this?
Am leaning towards just using fabric, is bringing in another tool
(chef/puppet/salt) overkill?

deployment = updating the source code, database migration, static files.
What are your favourite ways of doing this?  Shell scripts? Git push
hooks?  I'm thinking fabric, again...

Also: testing -- if the above two steps are automated using fabric, they'll
be *functionally* tested because we'll run the functional test suite
against the staging site.  Any thoughts on whether + how to *unit* test
deployment scripts?

Take a look at the blog post, and let me know what you think?  Bear in
mind, at this stage, I'm looking for "best practices lite" -- at this
stage, it's a tiny website, I can always bring in some more complexity
later on.  The idea is to get people introduced to the idea of deployment,
how you automated, and where testing comes in.  We don't have to talk about
CDNs or zero-downtime or multi-server configuration management yet...

Thanks in advance for any thoughts!
Harry

-- 
--
Harry J.W. Percival
--
Twitter: @hjwp
Mobile:  +44 (0) 78877 02511
Skype: harry.percival
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to run a python script twice randomly in a day?

2013-05-21 Thread Dave Angel

On 05/21/2013 06:32 AM, Cameron Simpson wrote:

On 21May2013 17:56, Chris Angelico  wrote:
| On Tue, May 21, 2013 at 11:12 AM, Cameron Simpson  wrote:
| > - randrange() is like other python ranges: it does not include the end 
value.
| >   So your call picks a number from 0..58, not 0..59.
| >   Say randrange(0,60). Think "start, length".
|
| Nitpick: It's not start, length; it's start, stop-before. If the start
| is 10 and the second argument is 20, you'll get numbers from 10 to 19.
| But your conclusion is still accurate :)

But it's still a useful thing to think when you're trying to reason
about ranges unless you're doing something unusual.




No, it's only happens to look like length when start is zero.  So as a 
mnemonic, it's highly misleading.



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


Re: Static Maps from Lat Long data in XLS file

2013-05-21 Thread Ken Bolton
On Tue, May 21, 2013 at 9:12 AM,  wrote:

> Hello,
>
> I'm new to Python, but I think it can solve my problem and I am looking
> for a someone to point me to tutorial or give me some tips here.
>

Hi! I am a first-time poster to python-list, but I think I can help you.


> I have an xls file that has about 1,000 latitude and longitude points. I
> want to do one of two things: 1) Save a static maps and street view image
> from the coordinates, or 2) create an html file with the map and street
> view image side by side.


If you save your xls file as a csv (comma-separated values), you can use
python's built-in csv module, documented here -
http://docs.python.org/2/library/csv.html, to read the file line by line.
Store the values and substitute the strings into a new list of URLs.


> I need the urls to look like this:
>
> Map with a pin in the centre:
>
> http://maps.googleapis.com/maps/api/staticmap?center=43.65162,-79.40571&zoom=16&size=600x600&markers=color:blue%7Clabel:S%7C43.65162,-79.40571&sensor=false
>
> Image:
>
> http://maps.googleapis.com/maps/api/streetview?location=43.65162,%20-79.40571&size=600x600&sensor=false


I was able to use curl to grab the images you linked. I believe you can use
urllib (or, better, requests - http://docs.python-requests.org/en/latest/)
to get and save the images.

hth.

best,
ken
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Harmonic distortion of a input signal

2013-05-21 Thread Oscar Benjamin
On 20 May 2013 18:23, jmfauth  wrote:
> Non sense.
>
> The discrete fft algorithm is valid only if the number of data
> points you transform does correspond to a power of 2 (2**n).

As with many of your comments about Python's unicode implementation
you are confusing performance with validity. The DFT is defined and is
a valid invertible map (barring roundoff) for complex vectors of any
integer length. It is also a valid method for understanding the
frequency content of periodic signals. The fastest FFT algorithms are
for vectors whose length is a power of 2 but the other algorithms
produce equally *valid* DFT results.

In the example I posted the computation of the DFT using numpy.fft.fft
was (as far as I could tell) instantaneous. I could use timeit to
discover exactly how many microseconds it took but why when I already
have the results I wanted?

> Keywords to the problem: apodization, zero filling, convolution
> product, ...
>
> eg. http://en.wikipedia.org/wiki/Convolution

These points are not relevant to the example given.


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


How to raise a socket "104 connection reset by peer error"

2013-05-21 Thread loial
For testing purposes I want my code to raise a socket "connection reset by 
peer" error, so that I can test how I handle it, but I am not sure how to raise 
the error.

Any advice appreciated

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


@staticmethods called more than once

2013-05-21 Thread Christian
Hi,

i'm somewhat confused working with @staticmethods. My logger and configuration  
methods are called n times, but I have only one call.  
n is number of classes which import the loger and configuration class
in the subfolder mymodule. What might be my mistake mistake?

Many thanks
Christian



### __init__.py ###

from  mymodule.MyLogger import MyLogger
from  mymodule.MyConfig import MyConfig


 
# my_test.py ##
from mymodule import MyConfig,MyLogger

#Both methods are static
key,logfile,loglevel = MyConfig().get_config('Logging')
log = MyLogger.set_logger(key,logfile,loglevel)
log.critical(time.time())

#Output
2013-05-21 17:20:37,192 - my_test - 17 - CRITICAL - 1369149637.19
2013-05-21 17:20:37,192 - my_test - 17 - CRITICAL - 1369149637.19
2013-05-21 17:20:37,192 - my_test - 17 - CRITICAL - 1369149637.19
2013-05-21 17:20:37,192 - my_test - 17 - CRITICAL - 1369149637.19

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


Re: Static Maps from Lat Long data in XLS file

2013-05-21 Thread Tim Daneliuk

On 05/21/2013 08:12 AM, kobe...@gmail.com wrote:

Hello,

I'm new to Python, but I think it can solve my problem and I am looking for a 
someone to point me to tutorial or give me some tips here.

I have an xls file that has about 1,000 latitude and longitude points. I want 
to do one of two things: 1) Save a static maps and street view image from the 
coordinates, or 2) create an html file with the map and street view image side 
by side.

I need the urls to look like this:

Map with a pin in the centre:
http://maps.googleapis.com/maps/api/staticmap?center=43.65162,-79.40571&zoom=16&size=600x600&markers=color:blue%7Clabel:S%7C43.65162,-79.40571&sensor=false

Image:
http://maps.googleapis.com/maps/api/streetview?location=43.65162,%20-79.40571&size=600x600&sensor=false

I am not sure if option 1 will work because the url doesn't actually lead to an 
image, but rather Google returns an image when that url is used.

Any tips or pointers are much appreciated!




https://pypi.python.org/pypi/xlrd



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


Re: @staticmethods called more than once

2013-05-21 Thread Skip Montanaro
Don't confuse the use of "static" in Python with its use in C/C++.  From a
post on StackOverflow:

A staticmethod is a method that knows nothing about the class or instance
> it was called on. It just gets the arguments that were passed, no implicit
> first argument. It is basically useless in Python -- you can just use a
> module function instead of a staticmethod.


That is, the "@staticmethod" decorator doesn't mean, "call this function
once."

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


Re: How to raise a socket "104 connection reset by peer error"

2013-05-21 Thread Andrew Berg
On 2013.05.21 10:26, loial wrote:
> For testing purposes I want my code to raise a socket "connection reset by 
> peer" error, so that I can test how I handle it, but I am not sure how to 
> raise the error.
Arbitrary exceptions can be raised with the raise keyword. In Python 3.3, that 
exact error got its own builtin exception:
http://docs.python.org/3.3/tutorial/errors.html#raising-exceptions
http://docs.python.org/3.3/library/exceptions.html#ConnectionResetError

In earlier versions of Python, you will have to raise OSError and set its errno 
attribute.

-- 
CPython 3.3.2 | Windows NT 6.2.9200 / FreeBSD 9.1
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: @staticmethods called more than once

2013-05-21 Thread John Gordon
In <02f0123d-2f9e-4287-b983-cfa1db9db...@googlegroups.com> Christian 
 writes:

> Hi,

> i'm somewhat confused working with @staticmethods. My logger and 
> configuration  methods are called n times, but I have only one call.  
> n is number of classes which import the loger and configuration class
> in the subfolder mymodule. What might be my mistake mistake?

> Many thanks
> Christian

> ### __init__.py ###

> from  mymodule.MyLogger import MyLogger
> from  mymodule.MyConfig import MyConfig

> # my_test.py ##
> from mymodule import MyConfig,MyLogger

> #Both methods are static
> key,logfile,loglevel = MyConfig().get_config('Logging')
> log = MyLogger.set_logger(key,logfile,loglevel)
> log.critical(time.time())

> #Output
> 2013-05-21 17:20:37,192 - my_test - 17 - CRITICAL - 1369149637.19
> 2013-05-21 17:20:37,192 - my_test - 17 - CRITICAL - 1369149637.19
> 2013-05-21 17:20:37,192 - my_test - 17 - CRITICAL - 1369149637.19
> 2013-05-21 17:20:37,192 - my_test - 17 - CRITICAL - 1369149637.19

You haven't given us the code for your MyLogger class, so it's difficult
to say exactly what the problem is.

However, I have a guess.  Does MyLogger.set_logger() contain a call to
addHandler()?  Each call to addHandler() adds another handler to your
logger, and when you call log.critical() [or any other log function] you
get one line of output for each handler.

You should only call addHandler() once.

-- 
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


Re: @staticmethods called more than once

2013-05-21 Thread John Gordon
In  John Gordon  writes:

> You should only call addHandler() once.

...for each intended logging output destination, of course.  If you want
logging output to appear in a file and on-screen, then you would call
addHandler() once with a file handler and once with a screen handler.

But I think you may be calling addHandler multiple times for the same
file handler, which is causing the duplicate logging output.

-- 
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


Re: @staticmethods called more than once

2013-05-21 Thread Ethan Furman

On 05/21/2013 08:39 AM, Skip Montanaro wrote:

Don't confuse the use of "static" in Python with its use in C/C++.  From a post 
on StackOverflow:

A staticmethod is a method that knows nothing about the class or instance 
it was called on. It just gets the
arguments that were passed, no implicit first argument. It is basically 
useless in Python -- you can just use a
module function instead of a staticmethod.


For there record, staticmethod is useful when you want to make it possible for 
subclasses to change behavior.

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


Re: @staticmethods called more than once

2013-05-21 Thread Christian
Am Dienstag, 21. Mai 2013 18:48:07 UTC+2 schrieb John Gordon:
> In  John Gordon  writes:
> 
> 
> 
> > You should only call addHandler() once.
> 
> 
> 
> ...for each intended logging output destination, of course.  If you want
> 
> logging output to appear in a file and on-screen, then you would call
> 
> addHandler() once with a file handler and once with a screen handler.
> 
> 
> 
> But I think you may be calling addHandler multiple times for the same
> 
> file handler, which is causing the duplicate logging output.
> 
> 
> 
> -- 
> 
> 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"

Yes you're right.
Many thanks!
-- 
http://mail.python.org/mailman/listinfo/python-list


More general way of generating PyODBC queries as a dict?

2013-05-21 Thread stackoverflowuser95
Here are my averagely general class methods for creating a dictionary from the 
result of database queries:

def make_schema_dict(self):
schema = [i[2] for i in self.cursor.tables()
  if i[2].startswith('tbl_') or i[2].startswith('vw_')]

self.schema = {table: {'scheme': [row.column_name for row
  in self.cursor.columns(table)]}
   for table in schema}

def last_table_query_as_dict(self, table):
return {'data': [{col: row.__getattribute__(col) for col in 
self.schema[table]['scheme']
  if col != 'RowNum'} for row in self.cursor.fetchall()]}
Unfortunately as you can see, there are many complications.

For example, when multiple tables are queried; some hackish lambdas are 
required to generate the resulting dictionary.

Can you think of some more general methods?

(and yes I know this is against the PEP; and that this is also on SO)
-- 
http://mail.python.org/mailman/listinfo/python-list


RE: PEP 378: Format Specifier for Thousands Separator

2013-05-21 Thread Carlos Nepomuceno

> From: alyssonbr...@gmail.com 
> Date: Tue, 21 May 2013 09:03:13 -0300 
> Subject: Re: PEP 378: Format Specifier for Thousands Separator 
> To: python-list@python.org 
>  
> This work in 3.1+: 
>  
> $ python3 
> Python 3.1.3 (r313:86834, Nov 28 2010, 11:28:10) 
> [GCC 4.4.5] on linux2 
> Type "help", "copyright", "credits" or "license" for more information. 
> >>> one_number = 1234567 
> >>> print('number={:,}'.format(one_number)) 
> number=1,234,567 
> >>> 
>  

Thank you, but let me rephrase it. I'm already using str.format() but I'd like 
to use '%' (BINARY_MODULO) operator instead.

I've looked into the source code of CPython 2.7.5 and I've found no evidence of 
the thousands separator been implemented on formatint() in 
"Objects/unicodeobject.c".

I also didn't find the _PyString_FormatLong() used in formatlong(). Where is 
_PyString_FormatLong() located?

So, the question is: Where would I change the CPython 2.7.5 source code to 
enable '%' (BINARY_MODULO) to format using the thousands separator like 
str.format() does, such as:

>>>sys.stderr.write('%,d\n' % 1234567)
1,234,567 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: PEP 378: Format Specifier for Thousands Separator

2013-05-21 Thread Chris “Kwpolska” Warrick
On Tue, May 21, 2013 at 8:49 PM, Carlos Nepomuceno
 wrote:
> Thank you, but let me rephrase it. I'm already using str.format() but I'd 
> like to use '%' (BINARY_MODULO) operator instead.

There is no real reason to do this.  `str.format()` is the new shiny
thing you should be using all the time.  Also, '%' is BINARY_MODULO
(where did you even get that name from?) if and only if you have two
numbers, and it performs the modulo division (eg. 27 % 5 = 2)

> So, the question is: Where would I change the CPython 2.7.5 source code to 
> enable '%' (BINARY_MODULO) to format using the thousands separator like 
> str.format() does, such as:
>
sys.stderr.write('%,d\n' % 1234567)
> 1,234,567

This will make your code unportable and useless, depending on one
patch you made.  Please don’t do that.  Instead,

> >>> sys.stdout.write('Number = %s\n' % '{:,.0f}'.format(x))
> Number = 12,345
>
> 'x' is unsigned integer so it's like using a sledgehammer to crack a nut!

In Python?  Tough luck, every int is signed.  And it isn’t just a
sledgehammer, it’s something worse.  Just do that:

>>> sys.stdout.write('Number = {:,.0f}\n'.format(x))

Much more peaceful.

You can also do a print, like everyone sane would.  Where did you
learn Python from?  “Python Worst Practice for Dummies”?

--
Kwpolska  | GPG KEY: 5EAAEA16
stop html mail| always bottom-post
http://asciiribbon.org| http://caliburn.nl/topposting.html
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: PEP 378: Format Specifier for Thousands Separator

2013-05-21 Thread Skip Montanaro
> Thank you, but let me rephrase it. I'm already using str.format() but I'd 
> like to use '%' (BINARY_MODULO) operator instead.

That's unlikely to change.  If not deprecated already string
interpolation using the modulo operator has lost favor to the string
object's format method.

You might be able to get by with a change of your LOCALE setting
and/or a peek at the documentation for the locale module.

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


Re: PEP 378: Format Specifier for Thousands Separator

2013-05-21 Thread Mark Lawrence

On 21/05/2013 20:13, Skip Montanaro wrote:

Thank you, but let me rephrase it. I'm already using str.format() but I'd like 
to use '%' (BINARY_MODULO) operator instead.


That's unlikely to change.  If not deprecated already string
interpolation using the modulo operator has lost favor to the string
object's format method.



Please stop perpetuating this myth, see 
http://mail.python.org/pipermail/python-dev/2012-February/116789.html 
and http://bugs.python.org/issue14123


--
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: PEP 378: Format Specifier for Thousands Separator

2013-05-21 Thread Carlos Nepomuceno

> From: kwpol...@gmail.com
> Date: Tue, 21 May 2013 21:06:11 +0200
> Subject: Re: PEP 378: Format Specifier for Thousands Separator
> To: carlosnepomuc...@outlook.com
> CC: python-list@python.org
>
> On Tue, May 21, 2013 at 8:49 PM, Carlos Nepomuceno
>  wrote:
>> Thank you, but let me rephrase it. I'm already using str.format() but I'd 
>> like to use '%' (BINARY_MODULO) operator instead.
>
> There is no real reason to do this. `str.format()` is the new shiny
> thing you should be using all the time. Also, '%' is BINARY_MODULO
> (where did you even get that name from?) if and only if you have two
> numbers, and it performs the modulo division (eg. 27 % 5 = 2)

I did:

>>> def fmt(s):
... return '%s' % s
...
>>> import dis
>>> dis.dis(fmt)
  2   0 LOAD_CONST   1 ('%s')
  3 LOAD_FAST    0 (s)
  6 BINARY_MODULO
  7 RETURN_VALUE
>>>

Then I've looked for 'BINARY_MODULO' in "Python/ceval.c" and found:

    case BINARY_MODULO:
    w = POP();
    v = TOP();
    if (PyString_CheckExact(v))
    x = PyString_Format(v, w);
    else
    x = PyNumber_Remainder(v, w);


Then I've looked for 'PyString_Format' and found it in "Objects/stringobject.c"

Analysing the code of "stringobject.c" I've found formatint() and formatlong().

I'm not using str.format() because it's slower than '%' and because I love '%'. 
str.format() looks like Java shit to me!

>> So, the question is: Where would I change the CPython 2.7.5 source code to 
>> enable '%' (BINARY_MODULO) to format using the thousands separator like 
>> str.format() does, such as:
>>
>sys.stderr.write('%,d\n' % 1234567)
>> 1,234,567
>
> This will make your code unportable and useless, depending on one
> patch you made. Please don’t do that. Instead,

I'm just learning how to improve things! ;)

> sys.stdout.write('Number = %s\n' % '{:,.0f}'.format(x))
>> Number = 12,345
>>
>> 'x' is unsigned integer so it's like using a sledgehammer to crack a nut!
>
> In Python? Tough luck, every int is signed. And it isn’t just a
> sledgehammer, it’s something worse. Just do that:
>
 sys.stdout.write('Number = {:,.0f}\n'.format(x))
>
> Much more peaceful.

Indeed! I just cut and pasted my code to create an example for the message. The 
actual format operation isn't done at the sys.stdout.write().

> You can also do a print, like everyone sane would. Where did you
> learn Python from? “Python Worst Practice for Dummies”?

lol I'm learning from my big mistakes up to now and a ton of online tutorials, 
besides "Dive into Python" (2004)[1], "Python Programming" (2012)[2] and 
"Programming Python, 3rd Ed" (2006) [print]

print isn't thread safe. That's why I've chosen sys.stdout.write() -- it's 
faster and thread safe by default.

I don't need any fancy formating, just need to send the string to screen.


[1] http://www.diveintopython.net/
[1] http://en.wikibooks.org/wiki/Python_Programming

> --
> Kwpolska  | GPG KEY: 5EAAEA16
> stop html mail | always bottom-post
> http://asciiribbon.org | http://caliburn.nl/topposting.html   
>   
-- 
http://mail.python.org/mailman/listinfo/python-list


RE: PEP 378: Format Specifier for Thousands Separator

2013-05-21 Thread Carlos Nepomuceno
> Analysing the code of "stringobject.c" I've found formatint() and 
> formatlong().

I mean _PyString_FormatLong() 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: PEP 378: Format Specifier for Thousands Separator

2013-05-21 Thread Andrew Berg
On 2013.05.21 14:26, Mark Lawrence wrote:
> On 21/05/2013 20:13, Skip Montanaro wrote:
>>> Thank you, but let me rephrase it. I'm already using str.format() but I'd 
>>> like to use '%' (BINARY_MODULO) operator instead.
>>
>> That's unlikely to change.  If not deprecated already string
>> interpolation using the modulo operator has lost favor to the string
>> object's format method.
>>
> 
> Please stop perpetuating this myth, see 
> http://mail.python.org/pipermail/python-dev/2012-February/116789.html 
> and http://bugs.python.org/issue14123
> 
What myth? People should indeed be using .format(), but no one said % 
formatting was going away soon. Also, the suggested change to the docs
wasn't made and the issue is closed. The current docs do not say that % 
formatting isn't going to be deprecated, but it does mention its
caveats and suggests .format(). If you are trying to say that % formatting will 
never ever go away, then you are wrong. It is highly
unlikely to go away in a 3.x release, but /may/ get phased out in Python 4.0.
-- 
CPython 3.3.2 | Windows NT 6.2.9200 / FreeBSD 9.1
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: PEP 378: Format Specifier for Thousands Separator

2013-05-21 Thread Ethan Furman

On 05/21/2013 12:06 PM, Chris “Kwpolska” Warrick wrote:

On Tue, May 21, 2013 at 8:49 PM, Carlos Nepomuceno wrote:


Thank you, but let me rephrase it. I'm already using str.format() but I'd like 
to use '%' (BINARY_MODULO) operator instead.


There is no real reason to do this.  `str.format()` is the new shiny
thing you should be using all the time.


.format() is useful, and has it's place, but % formatting is not going away.



So, the question is: Where would I change the CPython 2.7.5 source code to 
enable '%' (BINARY_MODULO) to format using the thousands separator like 
str.format() does, such as:

--> sys.stderr.write('%,d\n' % 1234567)
1,234,567


This will make your code unportable and useless, depending on one
patch you made.  Please don’t do that.


Agreed.  Unless you're willing to have your programs either run differently, or not at all, on other systems this is the 
wrong way to fix it.




Where did you learn Python from?  “Python Worst Practice for Dummies”?


Chris Warrick,

Was that necessary? Useful?  Helpful in any way?  If you can't be civil, keep 
your posts to yourself.

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


RE: PEP 378: Format Specifier for Thousands Separator

2013-05-21 Thread Carlos Nepomuceno

> To: python-list@python.org
> From: breamore...@yahoo.co.uk
> Subject: Re: PEP 378: Format Specifier for Thousands Separator
> Date: Tue, 21 May 2013 20:26:41 +0100
>
> On 21/05/2013 20:13, Skip Montanaro wrote:
>>> Thank you, but let me rephrase it. I'm already using str.format() but I'd 
>>> like to use '%' (BINARY_MODULO) operator instead.
>>
>> That's unlikely to change. If not deprecated already string
>> interpolation using the modulo operator has lost favor to the string
>> object's format method.
>>

I used to think str.__mod__() was going to be deprecated until Steven told me 
it was a myth! Think I got that idea from the own Python docs, but it's gone by 
now. Nevermind...

The fact is I have no need for str.format(). It's slow and awkward. 
str.format() looks like COBOL/Java idiom to me. I love Python! '%' is much more 
cool!!!

> Please stop perpetuating this myth, see
> http://mail.python.org/pipermail/python-dev/2012-February/116789.html
> and http://bugs.python.org/issue14123
>
> --
> If you're using GoogleCrap™ please read this
> http://wiki.python.org/moin/GoogleGroupsPython.
>
> Mark Lawrence
>
> --
> http://mail.python.org/mailman/listinfo/python-list   
>   
-- 
http://mail.python.org/mailman/listinfo/python-list


RE: PEP 378: Format Specifier for Thousands Separator

2013-05-21 Thread Carlos Nepomuceno

> Date: Tue, 21 May 2013 14:53:54 -0500
> From: bahamutzero8...@gmail.com
> To: python-list@python.org
[...]
>>
> What myth? People should indeed be using .format(), but no one said % 
> formatting was going away soon. Also, the suggested change to the docs
> wasn't made and the issue is closed. The current docs do not say that % 
> formatting isn't going to be deprecated, but it does mention its
> caveats and suggests .format(). If you are trying to say that % formatting 
> will never ever go away, then you are wrong. It is highly
> unlikely to go away in a 3.x release, but /may/ get phased out in Python 4.0.

I vote for keeping str.__mod__()!

Anyway, is it possible to overload str.__mod__() without deriving a class? I 
mean to have something like:

old_mod = str.__mod__
def new_mod(x):
    global old_mod
    try:
        old_mod(x)
    except ValueError, ex:
    #catch ValueError: unsupported format character ',' (0x2c) at index 1
        #process new '%,d' format here
    return '{:,}'.format(x)  #just to illustrate the behaviour. it would 
have it's own faster code

str.__mod__ = new_mod  #this raises TypeError: can't set attributes of 
built-in/extension type 'str'
sys.stdout.write('num=%,d\n' % 1234567)


> --
> CPython 3.3.2 | Windows NT 6.2.9200 / FreeBSD 9.1
> --
> http://mail.python.org/mailman/listinfo/python-list   
>   
-- 
http://mail.python.org/mailman/listinfo/python-list


Modules list-tool

2013-05-21 Thread Gisle Vanem

Are anyone aware of a tool that can show me at run-time
which modules (pyd/dll) are loaded into a Python program 
at a specific time (or over time)?


To clarify, e.g. when running a sample from PyQt4
(examples\tutorials\addressbook\part1.pyw) and using Process Explorer [1],
I can launch WinDbg from it and get this list of modules:


ModLoad: 1d00 1d00a000   G:\ProgramFiler\Python27\python.EXE
ModLoad: 7c90 7c9b1000   F:\WINDOWS\system32\ntdll.dll
ModLoad: 7c80 7c8f7000   F:\WINDOWS\system32\kernel32.dll
ModLoad: 1e00 1e261000   f:\windows\system32\python27.dll
ModLoad: 7e41 7e4a1000   F:\WINDOWS\system32\USER32.dll
ModLoad: 77f1 77f59000   F:\WINDOWS\system32\GDI32.dll
ModLoad: 77dc 77e6a000   F:\WINDOWS\system32\ADVAPI32.dll
ModLoad: 77e7 77f03000   F:\WINDOWS\system32\RPCRT4.dll
ModLoad: 77fe 77ff1000   F:\WINDOWS\system32\Secur32.dll
ModLoad: 7c9c 7d1d8000   F:\WINDOWS\system32\SHELL32.dll
ModLoad: 77c0 77c58000   F:\WINDOWS\system32\msvcrt.dll
ModLoad: 77f6 77fd6000   F:\WINDOWS\system32\SHLWAPI.dll
ModLoad: 7852 785c3000   
f:\windows\WinSxS\x86_Microsoft.VC90.CRT_1fc8b3b9a1e18e3b_9.0.30729.6161_x-ww_31a54e43\MSVCR90.dll
ModLoad: 7637 7638d000   f:\windows\system32\IMM32.DLL
ModLoad: 62f2 62f29000   f:\windows\system32\LPK.DLL
ModLoad: 7542 7548b000   f:\windows\system32\USP10.dll
ModLoad: 773c 774c3000 
f:\windows\WinSxS\x86_Microsoft.Windows.Common-Controls_6595b64144ccf1df_6.0.2600.6028_x-ww_61e65202\comctl32.dll

ModLoad: 5d5d 5d66a000   F:\WINDOWS\system32\comctl32.dll
ModLoad: 78aa 78b5f000   f:\windows\system32\MSVCR100.dll
ModLoad: 00d9 00f29000   
g:\ProgramFiler\Python27\lib\site-packages\PyQt4\QtCore.pyd
ModLoad: 6700 6726   
g:\ProgramFiler\Python27\lib\site-packages\PyQt4\QtCore4.dll
ModLoad: 774d 7760e000   F:\WINDOWS\system32\ole32.dll
ModLoad: 71aa 71ab7000   f:\windows\system32\WS2_32.dll
ModLoad: 71a9 71a98000   f:\windows\system32\WS2HELP.dll
ModLoad: 7848 7850e000   
f:\windows\WinSxS\x86_Microsoft.VC90.CRT_1fc8b3b9a1e18e3b_9.0.30729.6161_x-ww_31a54e43\MSVCP90.dll
ModLoad: 00a6 00a73000   g:\ProgramFiler\Python27\lib\site-packages\sip.pyd
ModLoad: 011f 0177f000   
g:\ProgramFiler\Python27\lib\site-packages\PyQt4\QtGui.pyd
ModLoad: 6500 657c4000   
g:\ProgramFiler\Python27\lib\site-packages\PyQt4\QtGui4.dll
...

-

My example may be mooth since part1.pyw above (when I enter
the debugger) is just waiting for events. The stack of pythonw.exe 
as shown in Process Explorer:

...
ntdll.dll!ZwWaitForMultipleObjects+0xc
kernel32.dll!WaitForMultipleObjectsEx+0x12c
USER32.dll!RealMsgWaitForMultipleObjectsEx+0x13e
QtCore4.dll!QEventDispatcherWin32::processEvents+0x3c3
ntdll.dll!RtlAcquirePebLock+0x28

Is there a tool that can do something similar? (written in Python maybe?). 
But a bit simpler to use than my current method. Just launch it from the 
command-line; something like "pyXX part1.pyw "


[1] http://technet.microsoft.com/en-gb/sysinternals/bb896653

--gv 


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


Re: Translation API in Python

2013-05-21 Thread Hala Gamal
ok MR,
I have searched before asking here,but i didn't find thing
-- 
http://mail.python.org/mailman/listinfo/python-list


A computer programmer, web developer and network admin resume

2013-05-21 Thread i...@databaseprograms.biz
A computer programmer, web developer and network administrator resume.

For a resume in HTML or .Doc format click on:
www.DatabasePrograms.Biz

If you would like this in text format instead, please let me know.


Daniel Rapaport

1-949-307-2485
i...@databaseprograms.biz







To unsubscribe click on: 
i...@databaseprograms.biz?Subject=unsubscribe

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


Re: @staticmethods called more than once

2013-05-21 Thread 88888 Dihedral
Ethan Furman於 2013年5月22日星期三UTC+8上午12時30分22秒寫道:
> On 05/21/2013 08:39 AM, Skip Montanaro wrote:
> 
> > Don't confuse the use of "static" in Python with its use in C/C++.  From a 
> > post on StackOverflow:
> 
> >
> 
> > A staticmethod is a method that knows nothing about the class or 
> > instance it was called on. It just gets the
> 
> > arguments that were passed, no implicit first argument. It is basically 
> > useless in Python -- you can just use a
> 
> > module function instead of a staticmethod.
> 
> 
> 
> For there record, staticmethod is useful when you want to make it possible 
> for subclasses to change behavior.
> 
> 
> 
> --
> 
> ~Ethan~

I prefer objects in classes with slimer figures not heavily weighted
with trivial methods in each instance construction and clone.

 But this is only my personal style of classes in python.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: A computer programmer, web developer and network admin resume

2013-05-21 Thread Denis McMahon
On Wed, 22 May 2013 01:15:27 +, i...@databaseprograms.biz wrote:

> If you would like this in text format instead, please let me know.

What if we don't want it at all?

-- 
Denis McMahon, denismfmcma...@gmail.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Myth Busters: % "this old style of formatting will eventually be removed from the language"

2013-05-21 Thread Carlos Nepomuceno
I was looking for something else and just found what I think is the place where 
I was first exposed to the myth[1]:

"Since str.format() is quite new, a lot of Python code still uses the % 
operator. However, because this old style of formatting will eventually be 
removed from the language, str.format() should generally be used."

Is this tutorial outdated or this still an issue?

[1] http://docs.python.org/2/tutorial/inputoutput.html#old-string-formatting
  
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: A computer programmer, web developer and network admin resume

2013-05-21 Thread Tim Chase
On 2013-05-22 01:15, i...@databaseprograms.biz wrote:
> A computer programmer, web developer and network administrator

...walk into a bar...

So what's the punchline?

-tkc


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


Re: PEP 378: Format Specifier for Thousands Separator

2013-05-21 Thread Steven D'Aprano
On Tue, 21 May 2013 23:22:24 +0300, Carlos Nepomuceno wrote:

> Anyway, is it possible to overload str.__mod__() without deriving a
> class? I mean to have something like:

No, not in Python. If you want to monkey-patch built-in classes on the 
fly, with all the troubles that causes, use Ruby.


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


RE: PEP 378: Format Specifier for Thousands Separator

2013-05-21 Thread Carlos Nepomuceno

> From: steve+comp.lang.pyt...@pearwood.info
> Subject: Re: PEP 378: Format Specifier for Thousands Separator
> Date: Wed, 22 May 2013 02:42:56 +
> To: python-list@python.org
>
> On Tue, 21 May 2013 23:22:24 +0300, Carlos Nepomuceno wrote:
>
>> Anyway, is it possible to overload str.__mod__() without deriving a
>> class? I mean to have something like:
>
> No, not in Python. If you want to monkey-patch built-in classes on the
> fly, with all the troubles that causes, use Ruby.
>

So, the only alternative to have "'%,d' % x" rendering the thousands separator 
output would a C source code modification?

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


Re: PEP 378: Format Specifier for Thousands Separator

2013-05-21 Thread Steven D'Aprano
On Tue, 21 May 2013 14:53:54 -0500, Andrew Berg wrote:

> On 2013.05.21 14:26, Mark Lawrence wrote:

>> Please stop perpetuating this myth, see
>> http://mail.python.org/pipermail/python-dev/2012-February/116789.html
>> and http://bugs.python.org/issue14123
>> 
> What myth? 

The myth that % string formatting is deprecated. It is not deprecated.

> People should indeed be using .format(), 

If it is useful to them, and not too slow, or indeed if they merely want 
to. And if not, then not.

This is a good case where the original poster *should* use str.format, 
since it does exactly what he wants, and % does not. Python gives you 
many tools, and the wise man uses the right tool for the job. Sometimes 
that is % and sometimes it is str.format and sometimes it is 
string.Template.

That str.format looks like Java is irrelevant. Method call syntax is 
common in Python, and is not original to Java. Besides, Python looks like 
many languages: some parts look like Java, some parts look like C, some 
parts remind me of functional languages like Lisp and Haskell, and some 
parts look like Algol or Pascal.


> but no one said % formatting was going away soon.

True, but only for the definition "no one = all the people who insist 
that % is deprecated, or soon to be deprecated".


> Also, the suggested change to the docs
> wasn't made and the issue is closed. The current docs do not say that %
> formatting isn't going to be deprecated, but it does mention its caveats
> and suggests .format(). If you are trying to say that % formatting will
> never ever go away, then you are wrong. It is highly unlikely to go away
> in a 3.x release, but /may/ get phased out in Python 4.0.

What happens in Python 4000 is irrelevant. If somebody is trying to 
"future proof" their code for a version that *may never exist*, and if it 
does exist is likely to be six or eight years away from even starting the 
design phase, they are wasting their time. It is hard enough to track a 
moving target, it is impossible to track a target that isn't even a gleam 
in GvR's eye yet.



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


Re: How to run a python script twice randomly in a day?

2013-05-21 Thread Cameron Simpson
On 21May2013 09:54, Dave Angel  wrote:
| On 05/21/2013 06:32 AM, Cameron Simpson wrote:
| >On 21May2013 17:56, Chris Angelico  wrote:
| >| On Tue, May 21, 2013 at 11:12 AM, Cameron Simpson  wrote:
| >| > - randrange() is like other python ranges: it does not include the end 
value.
| >| >   So your call picks a number from 0..58, not 0..59.
| >| >   Say randrange(0,60). Think "start, length".
| >|
| >| Nitpick: It's not start, length; it's start, stop-before. If the start
| >| is 10 and the second argument is 20, you'll get numbers from 10 to 19.
| >| But your conclusion is still accurate :)
| >
| >But it's still a useful thing to think when you're trying to reason
| >about ranges unless you're doing something unusual.
| 
| No, it's only happens to look like length when start is zero.  So as
| a mnemonic, it's highly misleading.

Feh! No self respecting computer scientist would ever count from
other than zero!

Actually, yes, you're right there.

Cheers,
-- 
Cameron Simpson 

Q: How does a hacker fix a function which doesn't work for all of the elements 
in its domain?
A: He changes the domain.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: PEP 378: Format Specifier for Thousands Separator

2013-05-21 Thread Steven D'Aprano
On Wed, 22 May 2013 05:56:53 +0300, Carlos Nepomuceno wrote:

> 
>> From: steve+comp.lang.pyt...@pearwood.info Subject: Re: PEP 378: Format
>> Specifier for Thousands Separator Date: Wed, 22 May 2013 02:42:56 +
>> To: python-list@python.org
>>
>> On Tue, 21 May 2013 23:22:24 +0300, Carlos Nepomuceno wrote:
>>
>>> Anyway, is it possible to overload str.__mod__() without deriving a
>>> class? I mean to have something like:
>>
>> No, not in Python. If you want to monkey-patch built-in classes on the
>> fly, with all the troubles that causes, use Ruby.
>>
>>
> So, the only alternative to have "'%,d' % x" rendering the thousands
> separator output would a C source code modification?

That's one alternative. But the language you would be then running will 
no longer be Python.

Another alternative would be to write a pre-processor that parses your 
Python source code, extracts any reference to the above, and replaces it 
with a call to the appropriate format call. But not only is that a lot of 
work for very little gain, but it's also more or less impossible to do in 
full generality. And again, what you are running will be something 
different than Python, it will be Python plus a pre-processor.


Don't fight the language. You will lose.



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


Re: Myth Busters: % "this old style of formatting will eventually be removed from the language"

2013-05-21 Thread Ethan Furman

On 05/21/2013 07:26 PM, Carlos Nepomuceno wrote:

I was looking for something else and just found what I think is the place where 
I was first exposed to the myth[1]:

"Since str.format() is quite new, a lot of Python code still uses the % operator. 
However, because this old style of formatting will eventually be removed from the 
language, str.format() should generally be used."

Is this tutorial outdated or this still an issue?


It was exuberant wishful thinking.  ;)

While .format() does have its uses, % is in wide-spread use even among the 
core-devs.  It's not going away any time soon.

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


Re: Myth Busters: % "this old style of formatting will eventually be removed from the language"

2013-05-21 Thread Ned Batchelder

On 5/21/2013 10:26 PM, Carlos Nepomuceno wrote:

I was looking for something else and just found what I think is the place where 
I was first exposed to the myth[1]:

"Since str.format() is quite new, a lot of Python code still uses the % operator. 
However, because this old style of formatting will eventually be removed from the 
language, str.format() should generally be used."

Is this tutorial outdated or this still an issue?

[1] http://docs.python.org/2/tutorial/inputoutput.html#old-string-formatting



That tutorial is out of date.  %-formatting isn't being removed.

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


Re: PEP 378: Format Specifier for Thousands Separator

2013-05-21 Thread Andrew Berg
On 2013.05.21 21:59, Steven D'Aprano wrote:
> On Tue, 21 May 2013 14:53:54 -0500, Andrew Berg wrote:
> 
>> On 2013.05.21 14:26, Mark Lawrence wrote:
> 
>>> Please stop perpetuating this myth, see
>>> http://mail.python.org/pipermail/python-dev/2012-February/116789.html
>>> and http://bugs.python.org/issue14123
>>> 
>> What myth? 
> 
> The myth that % string formatting is deprecated. It is not deprecated.
Skip didn't say that it was deprecated.

>> but no one said % formatting was going away soon.
> 
> True, but only for the definition "no one = all the people who insist 
> that % is deprecated, or soon to be deprecated".
Perhaps I missed something, but who is insisting this?

> What happens in Python 4000 is irrelevant. If somebody is trying to 
> "future proof" their code for a version that *may never exist*, and if it 
> does exist is likely to be six or eight years away from even starting the 
> design phase, they are wasting their time. It is hard enough to track a 
> moving target, it is impossible to track a target that isn't even a gleam 
> in GvR's eye yet.
I think you misunderstand. I'm not suggesting that format() be used simply 
because % formatting could be deprecated at some unknown time
years from now; I was clarifying the status of % formatting.
-- 
CPython 3.3.2 | Windows NT 6.2.9200 / FreeBSD 9.1
-- 
http://mail.python.org/mailman/listinfo/python-list


RE: PEP 378: Format Specifier for Thousands Separator

2013-05-21 Thread Carlos Nepomuceno

> From: steve+comp.lang.pyt...@pearwood.info
> Subject: Re: PEP 378: Format Specifier for Thousands Separator
> Date: Wed, 22 May 2013 03:08:54 +
> To: python-list@python.org
[...]
>> So, the only alternative to have "'%,d' % x" rendering the thousands
>> separator output would a C source code modification?
>
> That's one alternative. But the language you would be then running will
> no longer be Python.
>
> Another alternative would be to write a pre-processor that parses your
> Python source code, extracts any reference to the above, and replaces it
> with a call to the appropriate format call. But not only is that a lot of
> work for very little gain, but it's also more or less impossible to do in
> full generality. And again, what you are running will be something
> different than Python, it will be Python plus a pre-processor.
>
>
> Don't fight the language. You will lose.

Not fighting the language. In fact it's not even a language issue.
All I need is a standard library[1] improvement: "%,d"! That's all!

Just to put in perspective the performance difference of str.__mod__() and 
str.format():

C:\Python27>python -m timeit -cv -n1000 "'%d'%12345"
raw times: 0.386 0.38 0.373
1000 loops, best of 3: 0.0373 usec per loop

C:\Python27>python -m timeit -cv -n1000 "'{:d}'.format(12345)"
raw times: 7.91 7.89 7.98
1000 loops, best of 3: 0.789 usec per loop

C:\Python27>python -m timeit -cv -n1000 "'{:,d}'.format(12345)"
raw times: 8.7 8.67 8.78
1000 loops, best of 3: 0.867 usec per loop

That shows str.format() is 20 times slower than str.__mod__() for a simple 
decimal integer literal formatting.
And it's additionally 10% slower if the thousands separator format specifier 
(',') is used.

[1] I think that translates to Python source code in 'Objects/stringobject.c' 
and maybe 'Objects/unicodeobject.c'

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


Case insensitive dict

2013-05-21 Thread Joseph L. Casale
I was doing some work with the ldap module and required a ci dict that was case
insensitive but case preserving. It turned out the cidict class they 
implemented was
broken with respect to pop, it is inherited and not re implemented to work. 
Before
I set about re-inventing the wheel, anyone know of a working implementation?

I noticed twisted has one but it seems to omit pop.

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


Re: Case insensitive dict

2013-05-21 Thread Steven D'Aprano
On Wed, 22 May 2013 03:59:55 +, Joseph L. Casale wrote:

> I was doing some work with the ldap module and required a ci dict that
> was case insensitive but case preserving. It turned out the cidict class
> they implemented was broken with respect to pop, it is inherited and not
> re implemented to work. Before I set about re-inventing the wheel,
> anyone know of a working implementation?

class my_cidict(ldap.cidict):
"""Fix problems with pop."""
def pop(self):
# insert code here


You don't have to re-invent the entire wheel just to fix one broken 
spoke :-)

Other than that, no, I don't know of any case-insensitive but preserving 
dicts. If you do decide to write one from scratch, please consider 
releasing it as Open Source (I recommend GPL or MIT licences), either as 
a module on PyPI or as a recipe on ActiveState.

https://pypi.python.org/pypi
http://code.activestate.com/recipes/langs/python/



Thank you.






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


RE: Myth Busters: % "this old style of formatting will eventually be removed from the language"

2013-05-21 Thread Carlos Nepomuceno
Ok. Thanks!

bugs.python.org/issue18031


> Date: Tue, 21 May 2013 23:26:58 -0400
> From: n...@nedbatchelder.com
> To: carlosnepomuc...@outlook.com
> CC: python-list@python.org
> Subject: Re: Myth Busters: % "this old style of formatting will eventually be 
> removed from the language"
>
> On 5/21/2013 10:26 PM, Carlos Nepomuceno wrote:
>> I was looking for something else and just found what I think is the place 
>> where I was first exposed to the myth[1]:
>>
>> "Since str.format() is quite new, a lot of Python code still uses the % 
>> operator. However, because this old style of formatting will eventually be 
>> removed from the language, str.format() should generally be used."
>>
>> Is this tutorial outdated or this still an issue?
>>
>> [1] http://docs.python.org/2/tutorial/inputoutput.html#old-string-formatting
>
> That tutorial is out of date. %-formatting isn't being removed.
>
> --Ned.  
-- 
http://mail.python.org/mailman/listinfo/python-list


Newbie question about evaluating raw_input() responses

2013-05-21 Thread C. N. Desrosiers
Hi,

I'm just starting out with Python and to practice I am trying to write a script 
that can have a simple conversation with the user.

When I run the below code, it always ends up printing response to "if age > 
18:" -- even if I enter a value below 18.

Can anyone point me to what I am doing wrong?  Many thanks in advance.

age=raw_input('Enter your age: ')
if age > 18:
print ('Wow, %s. You can buy cigarettes.' % age)
else:
print ('You are a young grasshopper.')
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Newbie question about evaluating raw_input() responses

2013-05-21 Thread Fábio Santos
You have to convert `age` to an integer. Use int() to do it. Then you can
compare it to other numbers and obtain the expected results.
On 22 May 2013 07:29, "C. N. Desrosiers"  wrote:

> Hi,
>
> I'm just starting out with Python and to practice I am trying to write a
> script that can have a simple conversation with the user.
>
> When I run the below code, it always ends up printing response to "if age
> > 18:" -- even if I enter a value below 18.
>
> Can anyone point me to what I am doing wrong?  Many thanks in advance.
>
> age=raw_input('Enter your age: ')
> if age > 18:
> print ('Wow, %s. You can buy cigarettes.' % age)
> else:
> print ('You are a young grasshopper.')
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: A computer programmer, web developer and network admin resume

2013-05-21 Thread Chris Angelico
On Wed, May 22, 2013 at 12:32 PM, Tim Chase
 wrote:
> On 2013-05-22 01:15, i...@databaseprograms.biz wrote:
>> A computer programmer, web developer and network administrator
>
> ...walk into a bar...
>
> So what's the punchline?

;steps up to the mike

So yeah, as I was saying, a programmer, a web dev, and a BOFH walk
into a bar. The other two buy the BOFH a drink, because they're not
stupid, and anyway, so this luser walks up to them with a resume in
his hand.

"," says the luser.

"So what's the punchline?" says the computer programmer.

The stand-up comic steps up to the mike, and he says, "So yeah, as I
was saying, a programmer, a web dev, and a BOFH walk into a stable
time loop..."

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


Re: Newbie question about evaluating raw_input() responses

2013-05-21 Thread Kevin Xi
On Wednesday, May 22, 2013 2:23:15 PM UTC+8, C. N. Desrosiers wrote:
> Hi,
> 
Hi,
> 
> I'm just starting out with Python and to practice I am trying to write a 
> script that can have a simple conversation with the user.
> 
So you may want to search the doc before you ask: http://docs.python.org
> 
> When I run the below code, it always ends up printing response to "if age > 
> 18:" -- even if I enter a value below 18.
> 
> 
> 
> Can anyone point me to what I am doing wrong?  Many thanks in advance.
> 
> 
> 
> age=raw_input('Enter your age: ')
> 
> if age > 18:
> 
> print ('Wow, %s. You can buy cigarettes.' % age)
> 
> else:
> 
> print ('You are a young grasshopper.')

You can either use `raw_input` to read data and convert it to right type, or 
use `input` to get an integer directly. Read this: 
http://docs.python.org/2/library/functions.html#raw_input
http://docs.python.org/2/library/functions.html#input

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


Re: Newbie question about evaluating raw_input() responses

2013-05-21 Thread C. N. Desrosiers
Muchas gracias!

On Wednesday, May 22, 2013 2:35:18 AM UTC-4, Fábio Santos wrote:
> You have to convert `age` to an integer. Use int() to do it. Then you can 
> compare it to other numbers and obtain the expected results.
> 
> On 22 May 2013 07:29, "C. N. Desrosiers"  wrote:
> 
> Hi,
> 
> 
> 
> I'm just starting out with Python and to practice I am trying to write a 
> script that can have a simple conversation with the user.
> 
> 
> 
> When I run the below code, it always ends up printing response to "if age > 
> 18:" -- even if I enter a value below 18.
> 
> 
> 
> Can anyone point me to what I am doing wrong?  Many thanks in advance.
> 
> 
> 
> age=raw_input('Enter your age: ')
> 
> if age > 18:
> 
>     print ('Wow, %s. You can buy cigarettes.' % age)
> 
> else:
> 
>     print ('You are a young grasshopper.')
> 
> --
> 
> http://mail.python.org/mailman/listinfo/python-list


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