Re: Retrieving an object from a set

2013-01-26 Thread Peter Otten
Vito De Tullio wrote:

> MRAB wrote:
> 
>> It turns out that both S & {x} and {x} & S return {x}, not {y}.
> 
> curious.
> 
> $ python
> Python 2.7.3 (default, Jul  3 2012, 19:58:39)
> [GCC 4.7.1] on linux2
> Type "help", "copyright", "credits" or "license" for more information.
 x = (1,2,3)
 y = (1,2,3)
 s = set([y])
 (s & set([x])).pop() is y
> False
 (set([x]) & s).pop() is y
> True
> 
> maybe it's implementation-defined?

I think the algorithm looks for the smaller set:
 
>>> set(range(5)) & set(map(float, range(10)))
set([0, 1, 2, 3, 4])
>>> set(range(10)) & set(map(float, range(5)))
set([0.0, 1.0, 2.0, 3.0, 4.0])

You have two sets of the same length, so there is no advantage in swapping 
them before calculating the intersection.

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


Re: mysql solution

2013-01-26 Thread Ferrous Cranus
Τη Παρασκευή, 25 Ιανουαρίου 2013 11:56:44 μ.μ. UTC+2, ο χρήστης Dennis Lee 
Bieber έγραψε:

=
#find the visitor record for the (saved) cID and 
current host 
cur.execute('''SELECT * FROM visitors WHERE counterID = 
%s and host = %s''', (cID, host) )   
data = cur.fetchone()#cID&host are unique

if not data:
#first time for this host on this page, create 
new record 
cur.execute('''INSERT INTO visitors (counterID, 
host, userOS, browser, lastvisit) VALUES (%s, %s, %s, %s, %s)''',


(cID, host, useros, browser, date) )
else:
#found the page, save its primary key for later 
use 
vID = data[0] 
#UPDATE record using retrieved vID 
cur.execute('''UPDATE visitors SET userOS = %s, 
browser = %s, hits = hits + 1, lastvisit = %s
WHERE 
counterID = %s and host = %s''', (useros, browser, date, vID, host) )
===

Instead of the above logic which you provided and it works as expected, 
wouldn't be easier to just:

Try to update the 'visitors' record, for that 'page' and that 'host'
if update fails(doesnt return any data), then we insert a new record entry.

We dont have to check 'SELECT * FROM visitors WHERE counterID = %s and host = 
%s' first, this one less cursor.execute.
-- 
http://mail.python.org/mailman/listinfo/python-list


sockobj.connect Errno 13 Permission denied

2013-01-26 Thread nobody
Hi,

I have a client program Client.py which has a statement of sockobj.connect(), 
the port number 6 is used, so no problem from port permission. 

I am puzzled because I can run Client.py from command line in my user account 
or apache user account without any problems. 

But if I run it from a web page http://localhost/client.php, the client.php 
called exec("Client.py"), then it got an exception of sockobj.connect Errno 13 
Permission denied.

Why it can run from command line, but cannot make connection from a web file? 
Appreciate any tips and clues.

Thank you.

Kind regards.



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


Cancel threads after timeout

2013-01-26 Thread hyperboreean
Here's the use case I want to implement - I have to generate a report
from multiple database servers. This report should be generated every 2
hours. Sometimes it happens that a query on one of the database servers
takes longer than expected and impedes the generation of this report
(that's right, the queries are ran sequential). What I am trying to
achieve is to parallelize the queries on each database server and to be
able to cancel one of them if it takes longer than X minutes.
threading.Thread doesn't support this and seems that in
general programming languages don't implement a way to cancel threads
from the outside.

Now, I've read all the stackoverflow threads about killing a thread,
canceling a thread after a timeout, but all of them imply that you are
able to check from within the thread if you should end the computation
or not - that's not really my case, where the computation is a SQL
query.

So, what I have in mind is something like: the main loop starts a
threading.Thread which in turn is responsible for starting another
thread in which the actual computation happens (could be a
threading.Thread or a multiprocessing.Process) *and* checks if the
specified timeout has passed. If the time is up, it exits, letting the
main loop know.

Lots of words, no code - let me know if you have any suggestions, ideas
to this rant.

Thanks!


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


Re: sockobj.connect Errno 13 Permission denied

2013-01-26 Thread Joel Goldstick
On Sat, Jan 26, 2013 at 6:19 AM, nobody  wrote:

> Hi,
>
> I have a client program Client.py which has a statement of
> sockobj.connect(), the port number 6 is used, so no problem from port
> permission.
>
> I am puzzled because I can run Client.py from command line in my user
> account or apache user account without any problems.
>
> But if I run it from a web page http://localhost/client.php, the
> client.php called exec("Client.py"),



Check the arguments to exec.  I think it has to be an open file object.



> then it got an exception of sockobj.connect Errno 13 Permission denied.
>
> Why it can run from command line, but cannot make connection from a web
> file? Appreciate any tips and clues.
>
> Thank you.
>
> Kind regards.
>
>
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>



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


Re: sockobj.connect Errno 13 Permission denied

2013-01-26 Thread Joel Goldstick
On Sat, Jan 26, 2013 at 8:47 AM, Joel Goldstick wrote:

>
>
>
> On Sat, Jan 26, 2013 at 6:19 AM, nobody  wrote:
>
>> Hi,
>>
>> I have a client program Client.py which has a statement of
>> sockobj.connect(), the port number 6 is used, so no problem from port
>> permission.
>>
>> I am puzzled because I can run Client.py from command line in my user
>> account or apache user account without any problems.
>>
>> But if I run it from a web page http://localhost/client.php, the
>> client.php called exec("Client.py"),
>
>
>
> Check the arguments to exec.  I think it has to be an open file object.
>
>
>
>> then it got an exception of sockobj.connect Errno 13 Permission denied.
>>
>> Why it can run from command line, but cannot make connection from a web
>> file? Appreciate any tips and clues.
>>
>> Thank you.
>>
>> Kind regards.
>>
>>
>>
Maybe I spoke too soon.  You should probably be asking in a php forum since
what you are doing is running a php exec.  If you are actually getting a
python error you should show the code and the traceback so that someone can
look at your code.

In either case (py and php) it looks like exec needs either a string of
executable text or (in py case) an open file handle.  So the code you
describe isn't really what you are running

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



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


Re: Cancel threads after timeout

2013-01-26 Thread Jason Friedman
> Sometimes it happens that a query on one of the database servers
> takes longer than expected and impedes the generation of this report
> (that's right, the queries are ran sequential). What I am trying to
> achieve is to parallelize the queries on each database server and to be
> able to cancel one of them if it takes longer than X minutes.

Only answering a small portion of your question 
Assuming you are able to figure out how to "cancel" a thread or
process on your side, it is possible the database itself will not
respect that.  In other words, if you execute "SELECT ..." singly,
outside of Python, and type CNTL-C, does your database quickly
recognize you are no longer interested in the result set and stop its
work?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Cancel threads after timeout

2013-01-26 Thread Matt Jones
It sounds like your real problem is with your SQL query...  Is that part of
this problem under your control?  Can you break the query into smaller,
quicker, pieces that you can run in a reasonable amount of time?

If not, nesting threads might be your best programmatic solution.  Heed
Jason's warning though that the SQL Server my still be working even if you
cancel an operation from the outside (which could compound your problem).

*Matt Jones*


On Sat, Jan 26, 2013 at 9:43 AM, Jason Friedman  wrote:

> > Sometimes it happens that a query on one of the database servers
> > takes longer than expected and impedes the generation of this report
> > (that's right, the queries are ran sequential). What I am trying to
> > achieve is to parallelize the queries on each database server and to be
> > able to cancel one of them if it takes longer than X minutes.
>
> Only answering a small portion of your question 
> Assuming you are able to figure out how to "cancel" a thread or
> process on your side, it is possible the database itself will not
> respect that.  In other words, if you execute "SELECT ..." singly,
> outside of Python, and type CNTL-C, does your database quickly
> recognize you are no longer interested in the result set and stop its
> work?
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Python Programming - 28 hours training in New York for $3999

2013-01-26 Thread joao . cowperthwaite
Python Programming - 28 hours training in New York for $3999


Course Outline: http://www.nobleprog.us/python-programming/training-course

Course Date: 2013-03-05 09:30 - 2013-03-08 16:30
Course Price: $3999 per person, usually $4730 per person
Remarks: A complimentary lunch will be provided

Venue: 
369 Lexington Ave
New York, New York 10017

Please use the link below to book:
http://be.nobleprog.us/node/add/course-booking?ce=751 

Link(s) to other Courses you might be interested in:
http://www.nobleprog.us/python-training-courses


Thanks
NobleProg LLC

If you need any further information please contact us at:
[email protected] or 646 461 6132 
-- 
http://mail.python.org/mailman/listinfo/python-list


??????????? DOES GOG EXIST

2013-01-26 Thread BV BV

DOES GOG EXIST


http://www.youtube.com/watch?v=tRMmTbCXXAk&feature=related



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


Re: sockobj.connect Errno 13 Permission denied

2013-01-26 Thread Albert Hopkins


On Sat, Jan 26, 2013, at 08:52 AM, Joel Goldstick wrote:
> On Sat, Jan 26, 2013 at 8:47 AM, Joel Goldstick
> wrote:
> 
> >
> >
> >
> > On Sat, Jan 26, 2013 at 6:19 AM, nobody  wrote:
> >
> >> Hi,
> >>
> >> I have a client program Client.py which has a statement of
> >> sockobj.connect(), the port number 6 is used, so no problem from port
> >> permission.
> >>
> >> I am puzzled because I can run Client.py from command line in my user
> >> account or apache user account without any problems.
> >>
> >> But if I run it from a web page http://localhost/client.php, the
> >> client.php called exec("Client.py"),
> >
> >
> >
> > Check the arguments to exec.  I think it has to be an open file object.
> >
> >
> >
> >> then it got an exception of sockobj.connect Errno 13 Permission denied.
> >>
> >> Why it can run from command line, but cannot make connection from a web
> >> file? Appreciate any tips and clues.
> >>
> >> Thank you.
> >>
> >> Kind regards.
> >>
> >>
> >>
> Maybe I spoke too soon.  You should probably be asking in a php forum
> since
> what you are doing is running a php exec.  If you are actually getting a
> python error you should show the code and the traceback so that someone
> can
> look at your code.
> 
> In either case (py and php) it looks like exec needs either a string of
> executable text or (in py case) an open file handle.  So the code you
> describe isn't really what you are running
> 

Also your php/apache config needs to be set up to enable execs (I think
it's off by the default).

Either way it's a PHP question, not a Python question.
-- 
http://mail.python.org/mailman/listinfo/python-list


Formatting a column's value output

2013-01-26 Thread Ferrous Cranus
try:
cur.execute( '''SELECT URL, hits FROM counters ORDER BY hits 
DESC''' )
except MySQLdb.Error, e:
print ( "Query Error: ", sys.exc_info()[1].excepinfo()[2] )
else:
data = cur.fetchall()

for row in data:
print ( "" )

for item in row:
print ( " %s " % 
item )

sys.exit(0)
=

In the aboce code wheb 'URL' is to be typed out be print i need it to be 
formatted as a link, so the viewer can click on it.

Is this possible please?

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


Re: Formatting a column's value output

2013-01-26 Thread Chris Angelico
On Sun, Jan 27, 2013 at 4:51 AM, Ferrous Cranus  wrote:
> print ( " %s " 
> % item )

>
> In the aboce code wheb 'URL' is to be typed out be print i need it to be 
> formatted as a link, so the viewer can click on it.
>
> Is this possible please?

Easy, just make a tuple of item,item and have two %s markers:

print( "%s" % (item, item) )

But you need to concern yourself with escaping. In fact, you already
needed to, just to produce it as text - but it's now even more
important. I strongly suggest you look into that.

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


python: HTTP connections through a proxy server requiring authentication

2013-01-26 Thread sajuptpm
Hi,

I followed http://dabase.com/blog/Minimal_squid3_proxy_configuration/ to setup 
proxy server.
I tested my proxy server with firefox with IP:127.0.0.1 and Port:3128 and it 
working (asking for proxy username and password).

But, i could not make http connection through proxy server requiring 
authentication using following python code..

## Python code ## 

import urllib2
proxy = 
urllib2.ProxyHandler({'http':'http://saju:123@saju-Inspiron-N5010:3128'})
opener = urllib2.build_opener(proxy, urllib2.HTTPHandler)
urllib2.install_opener(opener)

conn = urllib2.urlopen('http://python.org')
return_str = conn.read()
print "===return_st", return_str


 ERROR 

Traceback (most recent call last):
  File "my_proxy.py", line 6, in 
conn = urllib2.urlopen('http://python.org')
  File "/usr/lib/python2.7/urllib2.py", line 127, in urlopen
return _opener.open(url, data, timeout)
  File "/usr/lib/python2.7/urllib2.py", line 407, in open
response = meth(req, response)
  File "/usr/lib/python2.7/urllib2.py", line 520, in http_response
'http', request, response, code, msg, hdrs)
  File "/usr/lib/python2.7/urllib2.py", line 445, in error
return self._call_chain(*args)
  File "/usr/lib/python2.7/urllib2.py", line 379, in _call_chain
result = func(*args)
  File "/usr/lib/python2.7/urllib2.py", line 528, in http_error_default
raise HTTPError(req.get_full_url(), code, msg, hdrs, fp)
urllib2.HTTPError: HTTP Error 407: Proxy Authentication Required



## Proxy Server Settings ## 

sudo vim /etc/squid3/squid.conf
---
auth_param digest program /usr/lib/squid3/digest_pw_auth -c 
/etc/squid3/passwords
auth_param digest realm saju-Inspiron-N5010
acl authenticated proxy_auth REQUIRED
http_access allow authenticated
http_port 3128

Setting up user
--

htdigest -c /etc/squid3/passwords saju-Inspiron-N5010 saju

==



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


Re: python: HTTP connections through a proxy server requiring authentication

2013-01-26 Thread sajuptpm
Hi,

/etc/squid3/squid.conf
---

saju@saju-Inspiron-N5010:~$ cat squid.conf | grep ^[^#]
auth_param digest program /usr/lib/squid3/digest_pw_auth -c 
/etc/squid3/passwords
auth_param digest realm saju-Inspiron-N5010
acl manager proto cache_object
acl localhost src 127.0.0.1/32 ::1
acl to_localhost dst 127.0.0.0/8 0.0.0.0/32 ::1
acl authenticated proxy_auth REQUIRED
acl SSL_ports port 443
acl Safe_ports port 80# http
acl Safe_ports port 21# ftp
acl Safe_ports port 443# https
acl Safe_ports port 70# gopher
acl Safe_ports port 210# wais
acl Safe_ports port 1025-65535# unregistered ports
acl Safe_ports port 280# http-mgmt
acl Safe_ports port 488# gss-http
acl Safe_ports port 591# filemaker
acl Safe_ports port 777# multiling http
acl CONNECT method CONNECT
http_access allow manager localhost
http_access deny manager
http_access deny !Safe_ports
http_access deny CONNECT !SSL_ports
http_access allow authenticated
http_access deny all
http_port 3128
coredump_dir /var/spool/squid3
refresh_pattern ^ftp:144020%10080
refresh_pattern ^gopher:14400%1440
refresh_pattern -i (/cgi-bin/|\?) 00%0
refresh_pattern (Release|Packages(.gz)*)$  0   20% 2880
refresh_pattern .020%4320
saju@saju-Inspiron-N5010:~$


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


Re: Formatting a column's value output

2013-01-26 Thread Ferrous Cranus
Τη Σάββατο, 26 Ιανουαρίου 2013 8:04:12 μ.μ. UTC+2, ο χρήστης Chris Angelico 
έγραψε:
> On Sun, Jan 27, 2013 at 4:51 AM, Ferrous Cranus  wrote:
> 
> > print ( " %s 
> > " % item )
> 
> 
> 
> >
> 
> > In the aboce code wheb 'URL' is to be typed out be print i need it to be 
> > formatted as a link, so the viewer can click on it.
> 
> >
> 
> > Is this possible please?
> 
> 
> 
> Easy, just make a tuple of item,item and have two %s markers:
> 
> 
> 
> print( "%s" % (item, item) )
> 
> 
> 
> But you need to concern yourself with escaping. In fact, you already
> 
> needed to, just to produce it as text - but it's now even more
> 
> important. I strongly suggest you look into that.
 
I can use triple (''') quoting so i dont have to escape special characters.

But i didnt understand you suggestion about the tuple.

The dataset returns many lines and i need to transfor only the URL column
Sorry i did not understood.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Need Pattern For Logging Into A Website

2013-01-26 Thread Tim Daneliuk

On 01/26/2013 12:53 AM, Michael Torrie wrote:

On 01/25/2013 05:15 PM, Tim Daneliuk wrote:

Does it handle self-signed SSL certs?


No idea.  you'd have to try it.



OK, thanks for the pointer.

--

Tim Daneliuk [email protected]
PGP Key: http://www.tundraware.com/PGP/

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


Re: Formatting a column's value output

2013-01-26 Thread Ferrous Cranus
Τη Σάββατο, 26 Ιανουαρίου 2013 8:04:12 μ.μ. UTC+2, ο χρήστης Chris Angelico 
έγραψε:
> On Sun, Jan 27, 2013 at 4:51 AM, Ferrous Cranus  wrote:
> 
> > print ( " %s 
> > " % item )
> 
> 
> 
> >
> 
> > In the aboce code wheb 'URL' is to be typed out be print i need it to be 
> > formatted as a link, so the viewer can click on it.
> 
> >
> 
> > Is this possible please?
> 
> 
> 
> Easy, just make a tuple of item,item and have two %s markers:
> 
> 
> 
> print( "%s" % (item, item) )

That code works, but it creates links for both the URL and hits columns!
Only the URL must be linked not the hits column!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: word_set [snip enormous subject line]

2013-01-26 Thread Steven D'Aprano
Martin Musatov wrote:

> word_set = set()
[snip SIXTEEN THOUSAND words copied from a spelling dictionary]


If you have a question, please:


- ASK THE QUESTION, we cannot read your mind;

- don't send us thousands of lines taken straight out of a dictionary,
  just use the SMALLEST amount of sample data needed to demonstrate 
  the problem; three or four words is enough, no need to waste 
  everyone's time and bandwidth with sixteen thousand words;

- choose a MEANINGFUL subject line, there is no need to paste the entire
  body of your code in the subject line.



Thank you.


-- 
Steven

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


Re: Formatting a column's value output

2013-01-26 Thread Chris Angelico
On Sun, Jan 27, 2013 at 8:07 AM, Ferrous Cranus  wrote:
> That code works, but it creates links for both the URL and hits columns!
> Only the URL must be linked not the hits column!

1) Trim your quotes. I can't be bothered doing your trimming for you,
so I'm now under-quoting.

2) Quit using Google Groups, or manually fix its brain-dead double-spacing.

3) Look into Python's formatting options and see how to solve your own
problem. You'll probably want to use .format() rather than %.

4) Look into HTML entity escaping and do not publish anything to the
web until you understand why what you had before was dangerous.

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


Re: Formatting a column's value output

2013-01-26 Thread Michael Torrie
On 01/26/2013 12:41 PM, Ferrous Cranus wrote:
> I can use triple (''') quoting so i dont have to escape special characters.

Hmm.  I think you missed what he was getting at. He's not talking about
Python escape sequences. He's talking about HTML ones.  There is a
function in one of the standard library modules that does this.  I think
it's called html_sanitize or something.  Google will find this.

> But i didnt understand you suggestion about the tuple.

What don't you understand about it?  It's basic python string formatting
(well python 2.x string formatting).

http://docs.python.org/2/library/stdtypes.html#string-formatting-operations

A tuple is one method for passing variables into the string formatter.
So if you need to display something twice, just put in two "%s" in the
format string, and pass it the same variable twice.

> The dataset returns many lines and i need to transfor only the URL column
> Sorry i did not understood.

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


looking for advice python

2013-01-26 Thread twiztidtrees
Hey I'm new to programming and I have been working on calculating miles per 
gallon. iv posted below what I have and constructive criticism would be 
wonderful. Thanks

#This is a program used to calculate miles per gallon


#variable used to gather miles driven 
string_miles = input('How many miles did you drive?')

#variable used to gather the amount of gallons used 
string_gas = input('How many gallons of gas did you use?')

#used to convert the miles input
miles = int(string_miles)

#used to convert the gas input
gas = int(string_gas)

#used to calculate mpg through division
mpg = miles/gas

print(float(string_miles))
print(float(string_gas))
print('Your miles per gallon is', format(mpg,'.2f'))
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: looking for advice python

2013-01-26 Thread Chris Angelico
On Sun, Jan 27, 2013 at 9:26 AM,   wrote:
> miles = int(string_miles)
> gas = int(string_gas)
>
> #used to calculate mpg through division
> mpg = miles/gas
>
> print(float(string_miles))
> print(float(string_gas))
> print('Your miles per gallon is', format(mpg,'.2f'))

Welcome aboard!

You turn your inputs into integers, then display them as floats...
from the original strings. (Though I guess this is probably debugging
code?) I would advise against doing this; at very least, it's
confusing. I would recommend simply using floats everywhere, and thus
allowing non-integer inputs:

How many miles did you drive?60.9
How many gallons of gas did you use?11.9
Traceback (most recent call last):
  File "123.py", line 11, in 
miles = int(string_miles)
ValueError: invalid literal for int() with base 10: '60.9'

Small additional point: It's common to put a space at the end of your
prompt, to avoid the "crammed" look of "drive?60.9".

Are there any particular areas that you'd like comments on?

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


Re: looking for advice python

2013-01-26 Thread Dave Angel

On 01/26/2013 05:26 PM, [email protected] wrote:

Hey I'm new to programming and I have been working on calculating miles per 
gallon. iv posted below what I have and constructive criticism would be 
wonderful. Thanks



A good post for the python-tutor mailing list.

If you want help with a program, the first thing you should specify is 
what version of Python you're using.  And usually which OS you're 
running, but in this case it doesn't matter much.



I don't see either a shebang line nor a coding line.



#This is a program used to calculate miles per gallon


#variable used to gather miles driven
string_miles = input('How many miles did you drive?')

#variable used to gather the amount of gallons used
string_gas = input('How many gallons of gas did you use?')



Why do you bother to have separate variables for the string versions?
Why not just   miles = int( input("")) ?  For that matter, what if 
the user enters a decimal value for the gallons?  Perhaps you'd better 
use  gas = float( input("yyy") )



#used to convert the miles input
miles = int(string_miles)

#used to convert the gas input
gas = int(string_gas)

#used to calculate mpg through division
mpg = miles/gas


This isn't portable to Python 2.x.  In 2.x, it would truncate the result.



print(float(string_miles))
print(float(string_gas))
print('Your miles per gallon is', format(mpg,'.2f'))



What if the user enters something that isn't a valid number, either int 
or float?  Where's the try/catch to handle it?


Is this a class assignment?  If not, why would you have a comment and a 
blank line between every line of useful code?




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


Re: Formatting a column's value output

2013-01-26 Thread alex23
On Jan 27, 8:18 am, Chris Angelico  wrote:
> 1) Trim your quotes. I can't be bothered doing your trimming for you,
> so I'm now under-quoting.
>
> 2) Quit using Google Groups, or manually fix its brain-dead double-spacing.
>
> 3) Look into Python's formatting options and see how to solve your own
> problem. You'll probably want to use .format() rather than %.
>
> 4) Look into HTML entity escaping and do not publish anything to the
> web until you understand why what you had before was dangerous.

5) Please stop writing code for his _commercial web hosting service_
for free.

Notice that his next question is to ask you to modify your solution to
provide _exactly_ what he wants. He has no interest in learning Python.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: ??????????? DOES GOG EXIST

2013-01-26 Thread alex23
On Jan 27, 2:41 am, BV BV  wrote:
> DOES GOG EXIST

Yes, they've been happily selling non-DRMed games for years now:

http://www.gog.com/

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


Re: Python Programming - 28 hours training in New York for $3999

2013-01-26 Thread Juhani Karlsson
https://www.edx.org/courses/MITx/6.00x/2013_Spring/about

Or take this course for free and buy 500 lunches.
Your choice.

On 26 January 2013 18:12,  wrote:

> Python Programming - 28 hours training in New York for $3999
>
>
> Course Outline: http://www.nobleprog.us/python-programming/training-course
>
> Course Date: 2013-03-05 09:30 - 2013-03-08 16:30
> Course Price: $3999 per person, usually $4730 per person
> Remarks: A complimentary lunch will be provided
>
> Venue:
> 369 Lexington Ave
> New York, New York 10017
>
> Please use the link below to book:
> http://be.nobleprog.us/node/add/course-booking?ce=751
>
> Link(s) to other Courses you might be interested in:
> http://www.nobleprog.us/python-training-courses
>
>
> Thanks
> NobleProg LLC
>
> If you need any further information please contact us at:
> [email protected] or 646 461 6132
> --
> http://mail.python.org/mailman/listinfo/python-list
>



-- 
-- 
Juhani Karlsson
3D Artist/TD

Talvi Digital Oy
Pursimiehenkatu 29-31 b 2krs.
00150 Helsinki
+358 443443088
[email protected]
www.vimeo.com/talvi
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Formatting a column's value output

2013-01-26 Thread Chris Angelico
On Sun, Jan 27, 2013 at 10:29 AM, alex23  wrote:
> 5) Please stop writing code for his _commercial web hosting service_
> for free.

You mean, stop asking us to write &c.? With that edit, yes, I agree.

One of the difficulties on this list is that we don't have
two-dimensional people. Even our worst trolls have some redeeming
features. I can't just dismiss Ferrous out of hand...

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


Re: Python Programming - 28 hours training in New York for $3999

2013-01-26 Thread Chris Angelico
On Sun, Jan 27, 2013 at 3:38 AM, Juhani Karlsson
 wrote:
> Or take this course for free and buy 500 lunches.
> Your choice.

You spend $8 on lunch? Wow, that's taking TANSTAAFL a long way...

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


Ctypes can't find libc on Solaris

2013-01-26 Thread Skip Montanaro
I'm trying to build PyPy on a Solaris 10 system (not supported by the
PyPy gang).  After worming around distutils' inability to use
environment variables to add command line flags to gcc, I'm stuck with
an error trying to locate libc:

[translation:ERROR] Error:
[translation:ERROR]  Traceback (most recent call last):
[translation:ERROR]File "translate.py", line 269, in main
[translation:ERROR] default_goal='compile')
[translation:ERROR]File
"/var/tmp/pypy-pypy-07e08e9c885c/pypy/translator/driver.py", line 790,
in from_targetspec
[translation:ERROR] spec = target(driver, args)
[translation:ERROR]File "targetpypystandalone.py", line 152, in target
[translation:ERROR] enable_allworkingmodules(config)
[translation:ERROR]File
"/var/tmp/pypy-pypy-07e08e9c885c/pypy/config/pypyoption.py", line 419,
in enable_allworkingmodules
[translation:ERROR]
config.objspace.usemodules.suggest(**dict.fromkeys(modules, True))
[translation:ERROR]File
"/var/tmp/pypy-pypy-07e08e9c885c/pypy/config/config.py", line 118, in
suggest
[translation:ERROR] self.suggestoption(name, value)
[translation:ERROR]File
"/var/tmp/pypy-pypy-07e08e9c885c/pypy/config/config.py", line 122, in
suggestoption
[translation:ERROR] self.setoption(name, value, "suggested")
[translation:ERROR]File
"/var/tmp/pypy-pypy-07e08e9c885c/pypy/config/config.py", line 113, in
setoption
[translation:ERROR] child.setoption(self, value, who)
[translation:ERROR]File
"/var/tmp/pypy-pypy-07e08e9c885c/pypy/config/config.py", line 311, in
setoption
[translation:ERROR] self._validator(toplevel)
[translation:ERROR]File
"/var/tmp/pypy-pypy-07e08e9c885c/pypy/config/pypyoption.py", line 116,
in validator
[translation:ERROR] __import__(name)
[translation:ERROR]File
"/var/tmp/pypy-pypy-07e08e9c885c/pypy/rlib/clibffi.py", line 305, in

[translation:ERROR] assert libc_name is not None, "Cannot find C
library, ctypes.util.find_library('c') returned None"
[translation:ERROR]  AssertionError: Cannot find C library,
ctypes.util.find_library('c') returned None
[translation] start debugger...

Digging into ctypes/util.py, it became apparent that it can't find
libc on Solaris.  If you run ctypes/util.py as a main program, it
spits out some library info.  On Linux:

% python
Python 2.7.2 (default, Oct 16 2012, 16:54:10)
[GCC 4.4.6 [TWW]] on linux3
Type "help", "copyright", "credits" or "license" for more information.
>>>
% python /opt/TWWfsw/python27/lib/python2.7/ctypes/util.py
libm.so.6
libc.so.6
libbz2.so.1


libcrypt.so.1

On my Mac:

% python ~/src/python/release27-maint/Lib/ctypes/util.py
/usr/lib/libm.dylib
/usr/lib/libc.dylib
/usr/lib/libbz2.dylib





On Solaris:

% python /opt/TWWfsw/python27/lib/python2.7/ctypes/util.py
None
None
None


None

If I can't locate libc (and perhaps some other libraries), I'm not
going to get any further.  Has anyone encountered this problem and
figured out a workaround?

Thanks,

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


Re: Python Programming - 28 hours training in New York for $3999

2013-01-26 Thread Juhani Karlsson
Hah yeah! 8e is normal price here in Finland. : )

On 27 January 2013 01:57, Chris Angelico  wrote:

> On Sun, Jan 27, 2013 at 3:38 AM, Juhani Karlsson
>  wrote:
> > Or take this course for free and buy 500 lunches.
> > Your choice.
>
> You spend $8 on lunch? Wow, that's taking TANSTAAFL a long way...
>
> ChrisA
> --
> http://mail.python.org/mailman/listinfo/python-list
>



-- 
-- 
Juhani Karlsson
3D Artist/TD

Talvi Digital Oy
Pursimiehenkatu 29-31 b 2krs.
00150 Helsinki
+358 443443088
[email protected]
www.vimeo.com/talvi
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Ctypes can't find libc on Solaris

2013-01-26 Thread Skip Montanaro
>  After worming around distutils' inability to use
> environment variables to add command line flags to gcc, I'm stuck with
> an error trying to locate libc:
...

Should have poked around bugs.python.org first.  This was reported,
with a patch that works for me: http://bugs.python.org/issue5289

Sorry for the noise...

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


Re: Cancel threads after timeout

2013-01-26 Thread Cameron Simpson
On 26Jan2013 09:48, Matt Jones  wrote:
| It sounds like your real problem is with your SQL query...  Is that part of
| this problem under your control?  Can you break the query into smaller,
| quicker, pieces that you can run in a reasonable amount of time?

Another option to investigate is whether you can ask the database itself
to limit the run time of a query. Of course, that will abort the query
but so does your proposed solution.

Another approach might be to simply run each query regularly (with a
pause between so the database is not spending its whole life running
your query). Snapshot each latest result. Compute your report from the
latest pair of snapshots at any given time on an independent schedule.
It may not be valid for what you need, but if it is then this decouples
you from the query time completely.

Cheers,
-- 
Cameron Simpson 

Do not taunt Happy Fun Coder.
-- 
http://mail.python.org/mailman/listinfo/python-list


Comparing offset-aware and offset-naive datetimes?

2013-01-26 Thread Roy Smith
I have two datetimes.  One is offset-naive.  The other is offset-aware, 
but I happen to know its offset is 0 (i.e. GMT).  How can I compare 
these?

May the flies of a thousand Norwegian Blue parrots infest the armpits of 
whoever invented timezones.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: doctests/unittest problem with exception

2013-01-26 Thread Steven D'Aprano
Paul wrote:

> Hello. I converted doctests into DocTestSuite() to use with unittest. And
> try it under Python 3.
> 
> And, sure, I get errors with unmatched exceptions details (mismatched name
> of exception class: a.b.c.MyError instead of MyError). So, I have 2
> questions:
> 
> 1) how to turn on option IGNORE_EXCEPTION_DETAIL for all doctests in
> DocStestSuite (like 'optionflags' argument in doctest.testmod())

Have you tried reading the Fine Manual? If you don't have access to the
Python documentation 

http://docs.python.org/3/library/doctest.html

you can get interactive help at the interpreter. Launch the Python
interactive interpreter, and then give these two commands:

import doctest
help(doctest.DocTestSuite)


In particular, note that DocTestSuite takes a keyword argument:

optionflags
   A set of doctest option flags expressed as an integer.


So try passing optionFlags=doctest.IGNORE_EXCEPTION_DETAIL to the
DocTestSuite.



> 2) Is a way to ignore all 'package path' of exception but not message?
> Something like:
> ---cut--- 
> Traceback (most recent call last):
> ...
> ...MyError: 'details are not ignored!'
> ---cut---
> see, ellipsis-prefix in MyError


Have you tried it to see? Add this comment to your docstring, following the
line which causes an exception:

>>> example()  #doctest: +ELLIPSIS
Traceback (most recent call last):
  ...
...MyError: 'details are not ignored!'


Does that do what you expect?


-- 
Steven

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


Re: Comparing offset-aware and offset-naive datetimes?

2013-01-26 Thread Vito De Tullio
Roy Smith wrote:

> I have two datetimes.  One is offset-naive.  The other is offset-aware,
> but I happen to know its offset is 0 (i.e. GMT).  How can I compare
> these?

http://pytz.sourceforge.net/#localized-times-and-date-arithmetic

-- 
ZeD

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


Re: Comparing offset-aware and offset-naive datetimes?

2013-01-26 Thread Ben Finney
Roy Smith  writes:

> I have two datetimes.  One is offset-naive.  The other is offset-aware, 
> but I happen to know its offset is 0 (i.e. GMT).

Do you know the timezone of the offset-naive value?

Or is the above mixed up, and you mean “one is offset-aware; the other
is offset-naive, but I happen to know its offset is UTC+0”?

> How can I compare these?

Assuming you have a datetime value which is timezone-naive, and you have
no way of getting its timezone, and are unwilling to guess, you can't
sensibly compare that value to a datetime in a specific timezone::

>>> import datetime
>>> import pytz
>>> timestamp_a = datetime.datetime(2012, 7, 1, 3, 45, 0)
>>> timestamp_b = datetime.datetime(
... 2012, 8, 1, 20, 15, 0, tzinfo=pytz.UTC)
>>> timestamp_a.tzinfo is None
True
>>> timestamp_b.tzinfo

>>> timestamp_a == timestamp_b
Traceback (most recent call last):
  File "", line 1, in 
TypeError: can't compare offset-naive and offset-aware datetimes


So I'll assume that my interpretation about the mix-up is true, and that
you actually have a situation like the following::

>>> import datetime
>>> import pytz
>>> timestamp_a = datetime.datetime(2012, 7, 1, 3, 45, 0)
>>> timezone_for_a = pytz.UTC
>>> timestamp_b = datetime.datetime(
... 2012, 8, 1, 20, 15, 0, tzinfo=pytz.timezone("Asia/Gaza"))
>>> timestamp_a.tzinfo is None
True
>>> timestamp_b.tzinfo


In which case, you can create a new timezone-aware value using the
timezone-naive value and the timezone you've decided to apply::

>>> timestamp_c = timestamp_a.replace(tzinfo=timezone_for_a)
>>> timestamp_c.tzinfo

>>> timestamp_c == timestamp_b
False
>>> timestamp_c > timestamp_b
False
>>> timestamp_c < timestamp_b
True

> May the flies of a thousand Norwegian Blue parrots infest the armpits of 
> whoever invented timezones.

Heh. I'm fine with timezones; they are a good-enough solution to allow
our puny brains to speak about points in time in a reality that refuses
to accommodate our prejudice that the time of day is the same everywhere
on the globe.

What I'm not fine with is politicians who think it's a fun game to
fiddle with the specific timezone definitions with little advance notice
and leave we programmers to clean up the mess they keep making. Those
people are sorely in need of a nasal infestation of parrot fleas.

-- 
 \ “For every complex problem, there is a solution that is simple, |
  `\   neat, and wrong.” —Henry L. Mencken |
_o__)  |
Ben Finney

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


The utter mess of current timezone definitions (was: Comparing offset-aware and offset-naive datetimes?)

2013-01-26 Thread Ben Finney
Roy Smith  writes:

> but I happen to know its offset is 0 (i.e. GMT).

As further fuel for your hatred: GMT is not the same thing as UTC+0, and
never has been. (See the definitions of those two separate timezones for
more; Wikipedia's articles are probably a good start.)

> May the flies of a thousand Norwegian Blue parrots infest the armpits of 
> whoever invented timezones.

Further support my position that the inventor of timezones is not to
blame for the utter mess in their current implementation, if you are
interested, can be found in the commentary within the Olson timezone
database itself.

Here is a fun article giving a “literary appreciation” of the database
http://blog.jonudell.net/2009/10/23/a-literary-appreciation-of-the-olsonzoneinfotz-database/>.

-- 
 \  “What we usually pray to God is not that His will be done, but |
  `\   that He approve ours.” —Helga Bergold Gross |
_o__)  |
Ben Finney

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


Re: The utter mess of current timezone definitions (was: Comparing offset-aware and offset-naive datetimes?)

2013-01-26 Thread Chris Angelico
On Sun, Jan 27, 2013 at 4:25 PM, Ben Finney  wrote:
>> but I happen to know its offset is 0 (i.e. GMT).
>
> As further fuel for your hatred: GMT is not the same thing as UTC+0, and
> never has been. (See the definitions of those two separate timezones for
> more; Wikipedia's articles are probably a good start.)

For most people's purposes, GMT and UTC are equivalent. I tell people
that my D&D sessions are Sundays from 2:00 UTC to roughly 6:00-7:00
UTC, and if they treat that as GMT, they're not going to miss the
session. It's a lot better than a mess of "local time" with DST.

Timezones aren't a problem. Daylight/Summer time (or Ireland's
alternative, Winter time) is.

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


Re: ??????????? DOES GOG EXIST

2013-01-26 Thread Frank Millman

On 26/01/2013 18:41, BV BV wrote:


DOES GOG EXIST


http://www.youtube.com/watch?v=tRMmTbCXXAk&feature=related



THANK YOU



Did you hear about the dyslexic agnostic insomniac?

He lies awake at night wondering if there is a dog.


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


Re: Cancel threads after timeout

2013-01-26 Thread dieter
hyperboreean  writes:

> Here's the use case I want to implement - I have to generate a report
> from multiple database servers. This report should be generated every 2
> hours. Sometimes it happens that a query on one of the database servers
> takes longer than expected and impedes the generation of this report
> (that's right, the queries are ran sequential). What I am trying to
> achieve is to parallelize the queries on each database server and to be
> able to cancel one of them if it takes longer than X minutes.
> threading.Thread doesn't support this and seems that in
> general programming languages don't implement a way to cancel threads
> from the outside.

And it is difficult in general.

The problem lies in the interaction between Python and (unknown by Python)
C extensions. Many C extensions would not work properly when simply
aborted in between (loose memory, fail to release resources,
leave an inconsistent state). You need something like "try: ... finally: ..."
or "try: ... except: ..." to have the ability to handle asynchronous
aborts - but C lacks such support.

In the light of this difficulty, the Python developpers decided not
to expose the possibility of many threading packages to abort a thread.

I was told that their is an approximative function at the Python
C interface (in Python 2, not sure whether it is also available in
Python 3): a function that allows you register the wish for a thread
aborting. This wish is recognized only when the thread is on
Python (not C) level (thus, not applicable in your case) and it causes
an exception that normally leads to the thread abortion but
plays well with Python's "try: ... finally: ..." and
"try: ... except: ...": thus, the thread can properly clean up.


You best approach is probably to ask the databases in parallel,
wait for some time and simply ignore answers that do not arrive
within that time (without any aborting trial).

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