Re: So, what's the real story on Python 2 vs Python 3?

2013-12-26 Thread Dan Stromberg
On Thu, Dec 26, 2013 at 9:43 PM, Rustom Mody  wrote:
> On Fri, Dec 27, 2013 at 10:50 AM, Andrew Berg  wrote:

> As for 2 maybe we need a wiki page. (Or do we have one already?)
> Heres my largely ignoramus attempt at starting that:
>
> 1. print: Use print with (). Dont use funny 2 syntax.
In fact, use parens with a single argument that may be a relatively
complex string % or .format expression.  Otherwise 2.x will think it's
being passed a tuple and display accordingly.

> 2. Always write strings with a u" prefix
3.0, 3.1 and 3.2 don't understand this, but 3.3 does.

In a project I wanted to run on 2.5, 2.6, 2.7, 3.0, 3.1, 3.2 and 3.3,
I dedicated a python module to most of my string constants, and
converted as needed using a pair of helper functions.  If Jython had
been available with 2.7 compatibility at the time, I would've ignored
2.5 and 2.6; now Jython has a 2.7 beta which is good enough for at
least some of my purposes.
-- 
https://mail.python.org/mailman/listinfo/python-list


Brython (Python in the browser)

2013-12-26 Thread Pierre Quentel
Hi,

Ever wanted to use Python instead of Javascript for web client programming ? 
Take a look at Brython, an implementation of Python 3 in the browser, with an 
interface with DOM elements and events

Its use is very simple :
- load the Javascript library brython.js : 

Re: So, what's the real story on Python 2 vs Python 3?

2013-12-26 Thread Chris Angelico
On Fri, Dec 27, 2013 at 4:43 PM, Rustom Mody  wrote:
> 1. print: Use print with (). Dont use funny 2 syntax
> 2. Always write strings with a u" prefix
> 3. Always use new style classes
> 4. Always use relative imports with explicit relative (ie use .)

Even easier:

1. from __future__ import print_function
2. from __future__ import unicode_literals
(3 and 4 as per your above)

For anything 2.6 or newer, those two will give Py3 behaviour, at least
in those two ways. Saves you having to put the explicit u prefix on
everything.

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


Re: So, what's the real story on Python 2 vs Python 3?

2013-12-26 Thread Rustom Mody
On Fri, Dec 27, 2013 at 10:50 AM, Andrew Berg  wrote:
> On 2013.12.26 23:04, Travis McGee wrote:
>> The Python.org site says that the future is Python 3, yet whenever I try
>> something new in Python, such as Tkinter which I am learning now,
>> everything seems to default to Python 2. By this I mean that, whenever I
>> find that I need to install another package, it shows up as Python 2
>> unless I explicitly specify Python 3.
>>
>> What's the deal? If I want to make a distributable software package,
>> should it be 2 or 3? Enquiring minds want to know.
>>
> Oh boy, another 2 vs. 3 thread!

I believe that this is separable into at least two questions:

1. Whats the deal about 2 and 3, as in where on the
past-present-future do these sit

2. How to write software that is 2+3 compatible

As for 1 its the much heat little light kind of discussion. I'll leave
others to warm themselves and the planet

As for 2 maybe we need a wiki page. (Or do we have one already?)
Heres my largely ignoramus attempt at starting that:

1. print: Use print with (). Dont use funny 2 syntax
2. Always write strings with a u" prefix
3. Always use new style classes
4. Always use relative imports with explicit relative (ie use .)
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: cascading python executions only if return code is 0

2013-12-26 Thread Roy Smith
In article ,
 Chris Angelico  wrote:

> On Fri, Dec 27, 2013 at 4:05 PM, Roy Smith  wrote:
> > There's lists like that for names and genders too.  As in, what do you
> > mean there are people who don't have exactly two names and one gender?
> 
> And addresses, too. The only way to reliably query the user for an
> address is with a single field in which s/he may type anything at
> all... and that freedom includes the possibility of making a right
> hash of it and having delivery fail.
> 
> ChrisA

You're assuming people *have* addresses.

A bunch of years ago (I'm probably dating myself), there was a legal 
ruling in New York that having an address was not a requirement to 
register to vote.  The case in question had to do with a homeless person 
who was refused registration because he didn't have an address.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: So, what's the real story on Python 2 vs Python 3?

2013-12-26 Thread Dan Stromberg
On Thu, Dec 26, 2013 at 9:04 PM, Travis McGee  wrote:
> What's the deal? If I want to make a distributable software package, should
> it be 2 or 3? Enquiring minds want to know.

3.x alone isn't a bad option, but it doesn't really have to be an
either-or decision.  That is, even pretty substantial code bases can
run on both, without any 2to3 or 3to2.

Personally, I'd think very carefully before committing to a dependency
that's still 2.x-only today.

EG, when I was looking for a 3.x version of pygtk, it turned out that
pygtk was being replaced by something called "gobject", which runs on
both 2.x and 3.x.  I happily made my pygtk scripts use gobject, and
now they're portable between 2.x and 3.x - there was even a script
provided that made most of the changes for me.

Here's a link to a presentation I did at my local Python User Group
about writing code to run on both 2.x and 3.x:
http://stromberg.dnsalias.org/~dstromberg/Intro-to-Python/

HTH
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: So, what's the real story on Python 2 vs Python 3?

2013-12-26 Thread Andrew Berg
On 2013.12.26 23:04, Travis McGee wrote:
> The Python.org site says that the future is Python 3, yet whenever I try 
> something new in Python, such as Tkinter which I am learning now, 
> everything seems to default to Python 2. By this I mean that, whenever I 
> find that I need to install another package, it shows up as Python 2 
> unless I explicitly specify Python 3.
> 
> What's the deal? If I want to make a distributable software package, 
> should it be 2 or 3? Enquiring minds want to know.
> 
Oh boy, another 2 vs. 3 thread!

Always use 3 unless you absolutely have to use 2. Python 3 is not a shiny new 
thing. It is *five* years old at this point and is soon to
have its *fifth* significant release. Python 2.6 is EOL, and there will not be 
a 2.8.
However, people have stayed with Python 2 for various reasons, and 
unfortunately, many of those people haven't even made an effort to
migrate until the last year or so.
Most of the major third-party libraries these days are either 3.x compatible or 
have 3.x-compatible replacements, though.

-- 
CPython 3.3.3 | Windows NT 6.2.9200 / FreeBSD 10.0
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: cascading python executions only if return code is 0

2013-12-26 Thread Chris Angelico
On Fri, Dec 27, 2013 at 4:05 PM, Roy Smith  wrote:
> There's lists like that for names and genders too.  As in, what do you
> mean there are people who don't have exactly two names and one gender?

And addresses, too. The only way to reliably query the user for an
address is with a single field in which s/he may type anything at
all... and that freedom includes the possibility of making a right
hash of it and having delivery fail.

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


Re: How to learn Python effectively

2013-12-26 Thread Dan Stromberg
On Thu, Dec 26, 2013 at 6:54 PM, 汪伟斌  wrote:
> I am a beginner in Python, and I find that there are various books about
> Python.
> There are almost the same contents between some, So I want a recommendation
> of a
> good order of the books, which can make me learn Python more effectively.
> Thanks a lot.

There's a lot of good material on the web about Python:
https://wiki.python.org/moin/BeginnersGuide/Programmers
https://wiki.python.org/moin/BeginnersGuide/NonProgrammers

I don't have a book recommendation.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: So, what's the real story on Python 2 vs Python 3?

2013-12-26 Thread Chris Angelico
On Fri, Dec 27, 2013 at 4:07 PM, Roy Smith  wrote:
> In article ,
>  Travis McGee  wrote:
>
>> The Python.org site says that the future is Python 3, yet whenever I try
>> something new in Python, such as Tkinter which I am learning now,
>> everything seems to default to Python 2. By this I mean that, whenever I
>> find that I need to install another package, it shows up as Python 2
>> unless I explicitly specify Python 3.
>>
>> What's the deal? If I want to make a distributable software package,
>> should it be 2 or 3? Enquiring minds want to know.
>
> The future is indeed Python 3.  The problem with the future is that it's
> not here yet.

Or to be more precise, is not exclusively here yet. The past is Python
2; the future is Python 3. The present is both Pythons, running in
parallel; if you're lucky, that's 2.7 and the latest 3.x, though not
everyone has that luxury.

For new code, aim for Python 3 unless you have a good reason to go for
Python 2. Most Linux distributions come with Python 2 under the name
"python", and Python 3 under the name "python3"; stick with that and
you'll be fairly safe. Or, if you can depend on your users having a
recent Py3 installed, you can use the launcher packaged with 3.3 and
later, which can intelligently figure out versioning.

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


Re: So, what's the real story on Python 2 vs Python 3?

2013-12-26 Thread Roy Smith
In article ,
 Travis McGee  wrote:

> The Python.org site says that the future is Python 3, yet whenever I try 
> something new in Python, such as Tkinter which I am learning now, 
> everything seems to default to Python 2. By this I mean that, whenever I 
> find that I need to install another package, it shows up as Python 2 
> unless I explicitly specify Python 3.
> 
> What's the deal? If I want to make a distributable software package, 
> should it be 2 or 3? Enquiring minds want to know.

The future is indeed Python 3.  The problem with the future is that it's 
not here yet.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: cascading python executions only if return code is 0

2013-12-26 Thread Roy Smith
In article <52bd049d$0$29992$c3e8da3$54964...@news.astraweb.com>,
 Steven D'Aprano  wrote:

> Roy Smith wrote:
> 
> > In article ,
> >  Ethan Furman  wrote:
> > 
> >> Mostly I don't want newbies thinking "Hey!  I can use assertions for all
> >> my confidence testing!"
> > 
> > How about this one, that I wrote yesterday;
> > 
> > assert second >= self.current_second, "time went backwards"
> > 
> > I think that's pretty high up on the "can never happen" list.
> 
> Time goes backwards by one hour[1] at least once a year across most of the
> world. 

Only if you're stupid enough to run your systems in local time.

> http://infiniteundo.com/post/25509354022/more-falsehoods-programmers-believe-a
> bout-time-wisdom

Most of those deal with things like daylight saving time and time zones 
and calendars, which are all far more complicated (and chaotic) than 
just keeping track of UTC timestamps.

There's lists like that for names and genders too.  As in, what do you 
mean there are people who don't have exactly two names and one gender?
-- 
https://mail.python.org/mailman/listinfo/python-list


So, what's the real story on Python 2 vs Python 3?

2013-12-26 Thread Travis McGee
The Python.org site says that the future is Python 3, yet whenever I try 
something new in Python, such as Tkinter which I am learning now, 
everything seems to default to Python 2. By this I mean that, whenever I 
find that I need to install another package, it shows up as Python 2 
unless I explicitly specify Python 3.


What's the deal? If I want to make a distributable software package, 
should it be 2 or 3? Enquiring minds want to know.

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


Re: need to print seconds from the epoch including the millisecond

2013-12-26 Thread Dave Angel
On Thu, 26 Dec 2013 20:03:34 -0500, Terry Reedy  
wrote:

On 12/26/2013 5:48 PM, Dave Angel wrote:
> You're probably on Windows,  which does time differently.


With 3.3 and 3.4 on Windows 7, time.time() gives 6 fractional 

digits.

 >>> import time; time.time()
1388105935.971099



With 2.7, same machine, I only get 3.


The way I recall it,  Windows time is a mess. To get better than 10 
ms resolution you needed to use time.clock, but that isn't epoch 
time. Trickier solutions existed, depending on exactly what the 
problem was. But judging from your test, 3.3 built those gyrations 
into the stdlib. I dunno,  I pretty much stopped using Windows 4 
years ago.


--
DaveA

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


Re: cascading python executions only if return code is 0

2013-12-26 Thread Chris Angelico
On Fri, Dec 27, 2013 at 3:39 PM, Steven D'Aprano
 wrote:
> Time goes backwards by one hour[1] at least once a year across most of the
> world.
>
> http://infiniteundo.com/post/25509354022/more-falsehoods-programmers-believe-about-time-wisdom
>
> [1] Unless it's less than an hour. Or more than one hour.

Kinda. That should be accompanied by a change in UTC offset,
indicating that time hasn't gone backwards, just the clock. Anything
that queries the clock in UTC shouldn't see it go backward. But if
there's a time server that's misconfigured, and it actually jumps time
backward, then yes, you could see NTP change the time back by an hour
once a year. It's wrong, but it certainly can happen.

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


How to learn Python effectively

2013-12-26 Thread 汪伟斌
I am a beginner in Python, and I find that there are various books about 
Python. 
There are almost the same contents between some, So I want a recommendation of 
a 
good order of the books, which can make me learn Python more effectively. 
Thanks a lot.-- 
https://mail.python.org/mailman/listinfo/python-list


Re: cascading python executions only if return code is 0

2013-12-26 Thread Chris Angelico
On Fri, Dec 27, 2013 at 3:29 PM, Roy Smith  wrote:
> NTP is never supposed to move the clock backwards.  If your system clock
> is fast, it's supposed to reduce the rate your clock runs until it's
> back in sync.  Well, maybe it only does that for small corrections?

The exact rules are tweakable, but yes, it slews for small corrections
and steps for larger ones.

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


Re: cascading python executions only if return code is 0

2013-12-26 Thread Steven D'Aprano
Roy Smith wrote:

> In article ,
>  Ethan Furman  wrote:
> 
>> Mostly I don't want newbies thinking "Hey!  I can use assertions for all
>> my confidence testing!"
> 
> How about this one, that I wrote yesterday;
> 
> assert second >= self.current_second, "time went backwards"
> 
> I think that's pretty high up on the "can never happen" list.

Time goes backwards by one hour[1] at least once a year across most of the
world. 

http://infiniteundo.com/post/25509354022/more-falsehoods-programmers-believe-about-time-wisdom



[1] Unless it's less than an hour. Or more than one hour.


-- 
Steven

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


Re: cascading python executions only if return code is 0

2013-12-26 Thread Roy Smith
In article ,
 Chris Angelico  wrote:

> On Fri, Dec 27, 2013 at 1:20 PM, Dennis Lee Bieber
>  wrote:
> > On Fri, 27 Dec 2013 12:44:35 +1100, Chris Angelico 
> > declaimed the following:
> >
> >>On Fri, Dec 27, 2013 at 12:37 PM, Roy Smith  wrote:
> >>> How about this one, that I wrote yesterday;
> >>>
> >>> assert second >= self.current_second, "time went backwards"
> >>>
> >>> I think that's pretty high up on the "can never happen" list.
> >>
> >>assert second >= self.current_second, "user changed the clock"
> >>
> > Why blame the user if an NTP synch made the adjustment? 
> 
> True, it could have been NTP, or maybe the original assert was right
> and we're on the other side of an event horizon. But it's much more
> fun to blame the user.
> 
> ChrisA

NTP is never supposed to move the clock backwards.  If your system clock 
is fast, it's supposed to reduce the rate your clock runs until it's 
back in sync.  Well, maybe it only does that for small corrections?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: cascading python executions only if return code is 0

2013-12-26 Thread Tim Chase
On 2013-12-27 12:44, Chris Angelico wrote:
> On Fri, Dec 27, 2013 at 12:37 PM, Roy Smith  wrote:
> > In article ,
> >  Ethan Furman  wrote:
> >  
> >> Mostly I don't want newbies thinking "Hey!  I can use assertions
> >> for all my confidence testing!"  
> >
> > How about this one, that I wrote yesterday;
> >
> > assert second >= self.current_second, "time went
> > backwards"
> >
> > I think that's pretty high up on the "can never happen" list.  
> 
> assert second >= self.current_second, "user changed the clock"

There appears to be a Whovian at the wheel...

>>> from getpass import getuser
>>> getuser()
'doctor4'


Or perhaps a Star Trek fan:

>>> from startrek.movie import episode
>>> episode()
4


It's-clearly-past-my-bedtime-or-is-it-before'ly yers,

-tkc





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


Re: cascading python executions only if return code is 0

2013-12-26 Thread Chris Angelico
On Fri, Dec 27, 2013 at 1:20 PM, Dennis Lee Bieber
 wrote:
> On Fri, 27 Dec 2013 12:44:35 +1100, Chris Angelico 
> declaimed the following:
>
>>On Fri, Dec 27, 2013 at 12:37 PM, Roy Smith  wrote:
>>> How about this one, that I wrote yesterday;
>>>
>>> assert second >= self.current_second, "time went backwards"
>>>
>>> I think that's pretty high up on the "can never happen" list.
>>
>>assert second >= self.current_second, "user changed the clock"
>>
> Why blame the user if an NTP synch made the adjustment? 

True, it could have been NTP, or maybe the original assert was right
and we're on the other side of an event horizon. But it's much more
fun to blame the user.

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


Re: cascading python executions only if return code is 0

2013-12-26 Thread Chris Angelico
On Fri, Dec 27, 2013 at 12:37 PM, Roy Smith  wrote:
> In article ,
>  Ethan Furman  wrote:
>
>> Mostly I don't want newbies thinking "Hey!  I can use assertions for all my
>> confidence testing!"
>
> How about this one, that I wrote yesterday;
>
> assert second >= self.current_second, "time went backwards"
>
> I think that's pretty high up on the "can never happen" list.

assert second >= self.current_second, "user changed the clock"

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


Re: cascading python executions only if return code is 0

2013-12-26 Thread Roy Smith
In article ,
 Ethan Furman  wrote:

> Mostly I don't want newbies thinking "Hey!  I can use assertions for all my 
> confidence testing!"

How about this one, that I wrote yesterday;

assert second >= self.current_second, "time went backwards"

I think that's pretty high up on the "can never happen" list.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: need to print seconds from the epoch including the millisecond

2013-12-26 Thread Roy Smith
In article <59aa73ac-e06e-4c0e-83a4-147ac42ca...@googlegroups.com>,
 matt.doolittl...@gmail.com wrote:

> > In [1]: import time
> > In [2]: time.time()
> > Out[2]: 1388085670.1567955
> 
> OK i did what you said but I am only getting 2 decimal places.  
> Why is this and what can I do to get the millisecond?  

What operating system are you on?  The Python time routines can only 
return as much precision as the operating system makes available.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: need to print seconds from the epoch including the millisecond

2013-12-26 Thread Terry Reedy

On 12/26/2013 5:48 PM, Dave Angel wrote:

On Thu, 26 Dec 2013 14:06:17 -0800 (PST), matt.doolittl...@gmail.com wrote:

On Thursday, December 26, 2013 2:22:10 PM UTC-5, Dan Stromberg

wrote:

> In [1]: import time
> In [2]: time.time()
> Out[2]: 1388085670.1567955



OK i did what you said but I am only getting 2 decimal places.


You're probably on Windows,  which does time differently.


With 3.3 and 3.4 on Windows 7, time.time() gives 6 fractional digits.
>>> import time; time.time()
1388105935.971099

> Specify your os version and python version and somebody will probably 
know.


With 2.7, same machine, I only get 3.

--
Terry Jan Reedy

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


Re: Recovering deleted files

2013-12-26 Thread Rick Johnson
On Wednesday, December 25, 2013 10:44:39 PM UTC-6, George Tang wrote:
> I am new to python and was trying to program with txt
> files, and tried to move the txt file to a new directory.
> i did not read very carefully about what shutil.move(src,
> dst) does and it deleted some of my files. How do i
> recover my lost files. plz help!

Well George that's unfortunate. 

I hate to say "i told you so", but i've been preaching the
importance of testing code that manipulates files for many
years. If only you had run the code a few times and MERELY
printed the src and dst paths to stdout you MIGHT could have
saved yourself a tough lesson.

But all may not be lost. 

If you want to post the relevant bits of the source code we
may find a solution for you. Maybe your path munging was
clumsy and you moved them somewhere unexpected... who
knows???
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Getting updates and restarting a long running url request.

2013-12-26 Thread Jason Friedman
> Would this not keep requesting/submitting additional (duplicate) BLAST
> queries?
>>
>>  try:
>> this_result = get_BLAST(id)
>> result_dict[id] = True
>

I assumed that
NCBIWWW.qblast
waits for a response from the server.

Are you saying that instead it queues a request, and the
NCBIXML.read(blast_result)

command fetches the result?

>
> That said after some more research I found this tread.
> http://lists.open-bio.org/pipermail/biopython/2013-April/008507.html

I read that post to say that you will be submitting one request for a
lot of data points that you will then need to parse, is that true?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Google Groups + this list

2013-12-26 Thread rurpy
On 12/25/2013 09:11 PM, Ned Batchelder wrote:
> On 12/24/13 8:44 PM, ru...@yahoo.com wrote:
>> On 12/23/2013 04:48 AM, Ned Batchelder wrote:
>>> On 12/22/13 11:52 PM, ru...@yahoo.com wrote:
>[...]
>>> But it's a lot of work.
>> No, it not a "lot" of work (IMO and I use GG for every
>[...]
> Yes, that's a point I've also been trying to make: we're in agreement here.

Then you can understand why I was confused when you 
wrote that it *was* a lot of work? ;-)

>[...]
> I'm not telling people not to use Google Groups.  In fact, I've said 
> twice now in this thread that we have to accept Google Groups postings 
> as part of this list.  My point is simply that we have to take care not 
> to turn this list into a list about Google Groups, one way or the other.
> 
> Kevin started this thread by asking a question.  Chris responded without 
> helping the OP, and talked about Google Groups instead.  That's not 
> good.  Then you responded to Chris, not helping the OP, and talking 
> about Google Groups instead.  That's also not good.
> 
> I have found some of the anti-GG responses off-putting, and I wish they 
> would stop.  Words like "crap" aren't making anyone feel welcome.  In 
> this thread, I felt like your attempts to correct those responses were 
> also crossing a line.
> 
> That's why I'd personally prefer that everyone tone down the rhetoric on 
> both sides of the debate.  For the most part, it will be impossible to 
> get anyone to change how they access the list.  The best we can do is a 
> polite suggestion that Google Groups puts some people off, and that more 
> responses will likely result from using another tool.  Beyond that, it's 
> just more useless yelling at each other.

Yes, I agree.  And if it sounded like I was putting
you and Chris in the same bucket, I apologize.  It 
was partly because you did seem to be agreeing with 
him (see for example above and your other post) and 
partly because it is hard in dashing off a quick reply
to always distinguish between the personal "you" and
the general "you" (anti-GG people).

>[...]
>>> 3) Don't let's get into protracted internal debates about Google Groups.
>>>It is for the moment at least, an unavoidable part of this list.
>>
>> That all sounds fine but seems to apply to the anti-GG
>> crowd more than me.
> 
> Well, point 3 applies to you. "Protracted debates" include views from 
> both sides.
> 
>> I would add:
>>
>> 4) If someone continues to post from GG with no attempt
>> to fix the quoting problem (which seem to be the only
>> serious problem with GG) and the problem's been pointed
>> out one or twice, just stop reading their posts if it
>> bothers you too much.
> 
> I think that's a fine point #4, I'm not sure what other option there is 
> in that case.
> 
> I'm a big believer in ignoring behavior that bothers you.  But you 
> aren't ignoring Chris, and I'm not ignoring you, so clearly we both also 
> believe in directly addressing behavior we don't like.  When to ignore, 
> and when to act?  It's not easy to decide.

I do think one needs to distinguish between the initiator 
of a contentious topic, and a responder, with preponderance
of any "blame" to be assigned falling on the former.  
(I'm excluding responding to obvious trolling here.)

I've said all along (in agreement with what you wrote), 
I've no problem with pointing out, factually, that there 
are some here who have a problem with posts from GG and 
informing them that there are alternatives.  

But going beyond that to make false (or unsupportable) 
claims, or denigrating someone's tool, which they may 
prefer for perfectly good reasons, with excessively strong 
and offensive language, or other "pushing" (to use Chris' 
term), should not be ignored.  Not just for the obvious 
ethical reasons but for the practical one that ignoring 
them is likely to drive people new to Python away from 
what should be a useful place of support.  (Not ignoring
them, resulting in these GG threads, also drives people 
away but I don't know how to fix that.  Hopefully the 
number is fewer.)

Thanks for making a number of reasonable and sensible 
points in this sometimes overheated discussion. 
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: need to print seconds from the epoch including the millisecond

2013-12-26 Thread Dave Angel
On Thu, 26 Dec 2013 14:06:17 -0800 (PST), matt.doolittl...@gmail.com 
wrote:
On Thursday, December 26, 2013 2:22:10 PM UTC-5, Dan Stromberg 

wrote:

> In [1]: import time
> In [2]: time.time()
> Out[2]: 1388085670.1567955


OK i did what you said but I am only getting 2 decimal places.  


You're probably on Windows,  which does time differently.  Specify 
your os version and python version and somebody will probably know.


--
DaveA

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


Re: cascading python executions only if return code is 0

2013-12-26 Thread Travis Griggs

On Dec 22, 2013, at 10:37 AM, Frank Cui  wrote:

> hey guys,
> 
> I have a requirement where I need to sequentially execute a bunch of 
> executions, each execution has a return code. the followed executions should 
> only be executed if the return code is 0. is there a cleaner or more pythonic 
> way to do this other than the following ? 
> 
> if a() == 0:
> if b() == 0:
> c()

I know I’m a little late to the game on this one. Good answers and interesting 
discussions (and sometimes not). In some situations, I might do something like 
the following. It depends on just how many functions your cascading, and how 
arbitrary or pluggable those are.

If your model is that you have a sort of todo list of functions to execute 
(more than 3 or so), you might want to separate the definition of that run list 
from the logic that executes them. Given something like:

def a():
  print(‘Aye’)
  return 0

def b():
  print(‘Bee’)
  return 0

def c():
  print(’See’)
  return 0

def d():
  print(‘Dee’)
  return 1

def e():
  print(‘Eee’)
  return 1

You do the nested if as you original proposed or the chained or as also 
proposed. Or you could put the commands in a list:

script = [
  a,
  b,
  c,
  d,
  e]

This gives you a nice succinct list of stuff that needs to be done, not to 
different if you’d just coded it with no or logic, e.g.

a
b
c
d
e

Refactoring/evolving them then feels the same.

To run the script we could do it the good ol’ C'ish way:

for step in script:
  if step() != 0:
break

But we have more functional style stuff via builtins which can capture that 
pattern:

ranToEnd = all(step() == 0 for step in script)

So IF you’re use case lends itself to separation of the “list of stuff to do” 
and the “logic to execute said list”, then… this approach might be appealing.

Travis Griggs


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


Re: Recovering deleted files

2013-12-26 Thread Steven D'Aprano
Dennis Lee Bieber wrote:

> If I read the documents properly, shutil.move() does not just blindly
> delete files (it does a copy/delete if crossing file systems, otherwise it
> just does a rename).

What difference does that make? Regardless of whether you do a copy/delete
or rename, whatever file was overridden by the move is still overridden.


-- 
Steven

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


Re: need to print seconds from the epoch including the millisecond

2013-12-26 Thread Steven D'Aprano
matt.doolittl...@gmail.com wrote:

> On Thursday, December 26, 2013 2:22:10 PM UTC-5, Dan Stromberg wrote:
>> On Thu, Dec 26, 2013 at 10:32 AM,   wrote:
>> 
>> > i am using 2.7.   I need to print the time in seconds from the epoch
>> > with millisecond precision.  i have tried many things but have failed. 
[...]
>> In [1]: import time
>> In [2]: time.time()
>> Out[2]: 1388085670.1567955
>
> 
> OK i did what you said but I am only getting 2 decimal places.
> Why is this and what can I do to get the millisecond?

Please show *exactly* what you did. Also please tell us what operating
system you are using. It may be that your operating system's clock doesn't
provide millisecond precision.



-- 
Steven

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


Re: need to print seconds from the epoch including the millisecond

2013-12-26 Thread matt . doolittle33
On Thursday, December 26, 2013 2:22:10 PM UTC-5, Dan Stromberg wrote:
> On Thu, Dec 26, 2013 at 10:32 AM,   wrote:
> 
> > i am using 2.7.   I need to print the time in seconds from the epoch with 
> > millisecond precision.  i have tried many things but have failed.  heres my 
> > latest:
> 
> >
> 
> > from time import time, strftime
> 
> > from datetime import datetime, time
> 
> >
> 
> > #  write date, time, then seconds from epoch
> 
> > self.logfile.write('%s\t'%(strftime("%Y-%m-%d",)))
> 
> > self.logfile.write('%s\t'%(now.strftime("%H:%M:%S",)))
> 
> > self.logfile.write('%s\t'%(now.time()))
> 
> 
> 
> In [1]: import time
> 
> 
> 
> In [2]: time.time()
> 
> Out[2]: 1388085670.1567955
> 
> 
> 
> HTH

OK i did what you said but I am only getting 2 decimal places.  
Why is this and what can I do to get the millisecond?  
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: need to print seconds from the epoch including the millisecond

2013-12-26 Thread Dan Stromberg
On Thu, Dec 26, 2013 at 10:32 AM,   wrote:
> i am using 2.7.   I need to print the time in seconds from the epoch with 
> millisecond precision.  i have tried many things but have failed.  heres my 
> latest:
>
> from time import time, strftime
> from datetime import datetime, time
>
> #  write date, time, then seconds from epoch
> self.logfile.write('%s\t'%(strftime("%Y-%m-%d",)))
> self.logfile.write('%s\t'%(now.strftime("%H:%M:%S",)))
> self.logfile.write('%s\t'%(now.time()))

In [1]: import time

In [2]: time.time()
Out[2]: 1388085670.1567955

HTH
-- 
https://mail.python.org/mailman/listinfo/python-list


need to print seconds from the epoch including the millisecond

2013-12-26 Thread matt . doolittle33
i am using 2.7.   I need to print the time in seconds from the epoch with 
millisecond precision.  i have tried many things but have failed.  heres my 
latest:

from time import time, strftime
from datetime import datetime, time

#  write date, time, then seconds from epoch
self.logfile.write('%s\t'%(strftime("%Y-%m-%d",)))
self.logfile.write('%s\t'%(now.strftime("%H:%M:%S",)))
self.logfile.write('%s\t'%(now.time()))


what am i doing wrong?  what should i be doing here?  Thanks!
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Insert NULL into mySQL datetime

2013-12-26 Thread Jussi Piitulainen
Dennis Lee Bieber writes:

> On Wed, 25 Dec 2013 17:20:35 -0800 (PST), ru...@yahoo.com declaimed
> the following:
> 
> >  if a is None:
> >cur.execute("Insert Into mytable(datefield) VALUES(NULL))", (,))
> 
>   I'm pretty sure that MySQLdb, at least, does not require the 
>   , (,)
> when there are no placeholders in the SQL statement. Might even

Isn't (,) invalid syntax in itself? At least I get the exception from
writing just (,) to Python 3.

The empty tuple is denoted ().
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Airplane mode control using Python?

2013-12-26 Thread rurpy
On Wednesday, December 25, 2013 3:56:26 AM UTC-7, Chris Angelico wrote:
> On Wed, Dec 25, 2013 at 12:37 PM,   wrote:
> > I have addressed this several times already.  All
> > software is buggy.  I even posted long list on the
> > problems I've had with Thunderbird.  Choosing any
> > software is making a tradeoff of one set of features/-
> > bugs versus another.  For you, with your experience,
> > goals and use of the list, there is one tradeoff.
> > Others with different experience, goals and use of
> > the list may well choose different tradeoffs.

> Give me an example of how Thunderbird's problems force *every other
> reader* to suffer under them and maybe I'll believe that it's 
> equivalent.

1. I never said they are equivalent.
2. Please see my response to Ned B, I'm not going to 
 repeat it again here.
3. Your redirection away from the original subject, your
 unsubstantiated claim the GG is corrupting whitespace
 and my request for evidence, is noted.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Getting updates and restarting a long running url request.

2013-12-26 Thread Vincent Davis
On Wed, Dec 25, 2013 at 11:24 PM, Jason Friedman  wrote:

> Could you keep track of success?
>
> result_dict = dict()
> for id in taxid_list:
> result_dict[id] = False
> while not all(result_dict.values()): # continue if not every ID was
> successful
> for id in taxid_list:
> if result_dict[id]:
> continue # We were already successful with this ID
> try:
> this_result = get_BLAST(id)
> result_dict[id] = True
> except:
> print("A warning.")
>

Thanks for your response.​
Would this not keep requesting/submitting additional (duplicate) BLAST
queries?

>  try:
> this_result = get_BLAST(id)
> result_dict[id] = True


​It seems like I need to use threading, and there appears to be no way to
know if NCBIWWW.qblast is still waiting on results. It will either give a
result or possibly produce and error I suppose if the for example I lost
the connection to the internet but I am not really sure about that.

That said after some more research I found this tread.
http://lists.open-bio.org/pipermail/biopython/2013-April/008507.html



Vincent Davis
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Recovering deleted files

2013-12-26 Thread Chris Angelico
On Thu, Dec 26, 2013 at 3:44 PM, George Tang  wrote:
> I am new to python and was trying to program with txt files, and tried to 
> move the txt file to a new directory. i did not read very carefully about 
> what shutil.move(src, dst) does and it deleted some of my files. How do i 
> recover my lost files. plz help!
>

Ouch. I'm afraid Python can't really help you there; you have to go to
your OS and file system now. Do as little as you possibly can on that
disk and you might be able to recover the contents. If you're lucky,
your file system won't have reused those parts of the disk, so
everything'll be intact... if you're REALLY lucky, you might even be
able to find the bits you want without searching the whole disk. But
it depends now on your OS and FS, not on Python.

This is why we make backups of all important files. I like to use
source control (git for me, or you could use Mercurial or another one
with the same result), which makes backing up an inherent part of all
work. But everyone has those critical files that they didn't know
weren't backed up... :(

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


Recovering deleted files

2013-12-26 Thread George Tang
I am new to python and was trying to program with txt files, and tried to move 
the txt file to a new directory. i did not read very carefully about what 
shutil.move(src, dst) does and it deleted some of my files. How do i recover my 
lost files. plz help!
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Apache restart after source changes

2013-12-26 Thread Ned Batchelder

On 12/26/13 12:57 AM, Fredrik Bertilsson wrote:

I am evaluating Python for web development and just found out that I need to 
restart Apache after source changes on windows. Using linux the situation is 
better but I still have to touch the wsgi file. Is it only me that finds this 
being a major drawback compared to PHP?



In general, PHP is more tightly integrated into web servers than Python 
is.  Python's advantages are 1) a more disciplined and carefully planned 
language and standard library, and 2) a larger and broader ecosystem of 
libraries, especially for tasks not directly related to serving web pages.


As to restarting servers after source changes: most people do not change 
file directly on their production servers.  They develop on their own 
machines, test the code, then deploy it to a production server.  In this 
scenario, restarting the web server is not a burden.


I don't know what the options are for auto-restarting the kinds of web 
servers you'd use in production, I'm sure there are some.  Someone here 
mentioned the Django web server, but that isn't intended for production use.


--
Ned Batchelder, http://nedbatchelder.com

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


Re: Google Groups + this list

2013-12-26 Thread Ned Batchelder

On 12/25/13 11:17 PM, Chris Angelico wrote:

On Thu, Dec 26, 2013 at 3:11 PM, Ned Batchelder  wrote:

Kevin started this thread by asking a question.  Chris responded without
helping the OP, and talked about Google Groups instead.  That's not good.


The only reason I didn't directly help the OP was because the code was
misformatted and it was necessary to request that it be reposted.
Perhaps I should have been clearer in saying "Please repost your code
with correct formatting", but there wasn't much else I could have
done.


In this case, the OP provided an error message which showed that he 
wasn't getting a SyntaxError, so we could assume that the problem lay 
elsewhere.  It depends how much work you want to put into overlooking 
the mis-formatting of the code.




Or maybe I should have just filtered everything from Google Groups
into the bit bucket, because responding just creates threads like
this. Do you honestly think that would be better? No response at all
if the post comes from GG?


If *you* don't want to respond to any GG post, that will be fine: others 
will respond.  Even better is to respond to the posts to help the OP.




ChrisA




--
Ned Batchelder, http://nedbatchelder.com

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


Re: Apache restart after source changes

2013-12-26 Thread Chris “Kwpolska” Warrick
On Thu, Dec 26, 2013 at 7:36 AM, Fredrik Bertilsson  wrote:
>> Also, it's not a python issue, it's an issue with your particular
>> stack. Other stacks do automatic reloading (for example, the web
>> server that Django uses).
>
> Which web server do you suggest instead of Apache, which doesn't have this 
> problem? (I am not planning to use Django)
> --
> https://mail.python.org/mailman/listinfo/python-list

It depends.  Some other frameworks (like Flask) also offer auto-reload
in debug mode — auto-reload can be bad for you and is not supported by
production environments, in which uWSGI (in Emperor mode if
possible/makes sense on Windows) and nginx is the best solution
around, and auto-reload isn’t supported (for good reasons, as
mentioned before).
-- 
Chris “Kwpolska” Warrick 
PGP: 5EAAEA16
stop html mail | always bottom-post | only UTF-8 makes sense
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Google Groups + this list

2013-12-26 Thread Chris Angelico
On Thu, Dec 26, 2013 at 4:13 PM,   wrote:
> On 12/25/2013 09:17 PM, Chris Angelico wrote:
>>[...]
>> Or maybe I should have just filtered everything from Google Groups
>> into the bit bucket, because responding just creates threads like
>> this. Do you honestly think that would be better? No response at all
>> if the post comes from GG?
>
> Do you really think that if *you* ignore Google Groups, then
> Google Groups posters will get "no response at all"?  Could
> you please turn down your ego a little?

That's not what I said, and you're still ignoring the primary thrust
of my posts. I'm done debating this with you; I'll continue to push
people toward options that don't have bugs that inflict themselves on
everyone else, and if you continue apologizing for something that
needs to be fixed, that's your business.

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


Re: Google Groups + this list

2013-12-26 Thread rurpy
On 12/25/2013 09:17 PM, Chris Angelico wrote:
>[...]
> Or maybe I should have just filtered everything from Google Groups
> into the bit bucket, because responding just creates threads like
> this. Do you honestly think that would be better? No response at all
> if the post comes from GG?

Do you really think that if *you* ignore Google Groups, then
Google Groups posters will get "no response at all"?  Could 
you please turn down your ego a little?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Insert NULL into mySQL datetime

2013-12-26 Thread rurpy
On 12/24/2013 05:33 PM, Igor Korot wrote:
> Hi, ALL,
> I am working on  a script that parses CSV file and after successful
> parsing insert data ino mySQL table.
> One of the fields in CSV holds a date+time value.
> 
> What the script should do is check if the cell has any data, i.e. not
> empty and then make sure that the data is date+time.
> If the validation fails, it should insert NULL into the mySQL datetime
> field, otherwise the actual datetime will be inserted.
> 
> Right now the script uses a placeholder "-00-00 00:00:00.000" if
> the date validation fails (either cell is empty or it has wrong data)
> 
> What I tried so far is:
> 
[...]
 import MySQLdb as mdb
 conn = mdb.connect('127.0.0.1','root','pass')
 cur = conn.cursor()
 a = None
 cur.execute("Use mydb")
> 0L
 cur.execute("Insert Into mytable(datefield) VALUES(STR_TO_DATE(%s))", a)

[...sql syntax error...]

 a = ""
 cur.execute("Insert Into mytable(datefield) VALUES(STR_TO_DATE(%s))", a)

[..."Incorrect parameter count...to native function 'STR_TO_DATE'...]
 
> Is it possible to do what I want?
> I'd like to use one query to insert the data into the table.

I don't use MySql but a quick peak at the docs for 
str_to_date() at:

  
http://docs.oracle.com/cd/E17952_01/refman-5.6-en/date-and-time-functions.html#function_str-to-date

seems to say that it takes two arguments, the datetime 
string and a format string.  Perhaps that's part of 
your problem?  (And as Peter said, the values argument 
to cursor.execute need to be a tuple, not a single value).

And are you sure that NULL (aka None in Python) is an 
acceptable value for the 'str' argument of str_to_date()?

If not perhaps you need to do something like:

  if a is None:
cur.execute("Insert Into mytable(datefield) VALUES(NULL))", (,))
  else:
cur.execute("Insert Into mytable(datefield) VALUES(STR_TO_DATE(%s, '%M 
%d,%Y'))", (a,))
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Variables in a loop, Newby question

2013-12-26 Thread Chris Angelico
On Thu, Dec 26, 2013 at 7:14 PM, Dave Angel  wrote:
> On Thu, 26 Dec 2013 16:41:57 +1100, Steven D'Aprano
>  wrote:
>>
>> Chris Angelico wrote:
>> > Does anyone else have the vague feeling that the OP's problem
> might be
>> > better served by simply importing the script (thus making those
> values
>> > available to another Python script) than by any of these rather
> more
>> > complicated theories?
>> Damn yes!
>
> I take it then that my posts are invisible.

Ah, true. I'd only been skimming, and didn't see that you'd mentioned
importing as well as IPC.

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


Re: Variables in a loop, Newby question

2013-12-26 Thread Dave Angel
On Thu, 26 Dec 2013 16:41:57 +1100, Steven D'Aprano 
 wrote:

Chris Angelico wrote:



> Does anyone else have the vague feeling that the OP's problem 

might be
> better served by simply importing the script (thus making those 

values
> available to another Python script) than by any of these rather 

more

> complicated theories?




Damn yes!


I take it then that my posts are invisible.

--
DaveA

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


Re: Please stop the trolling

2013-12-26 Thread Joshua Landau
On 23 December 2013 20:53, Terry Reedy  wrote:
> On 12/23/2013 2:05 PM, wxjmfa...@gmail.com wrote:
>
>> Le lundi 23 décembre 2013 18:59:41 UTC+1, Wolfgang Keller a écrit :
>>>
>>> [me]

 I'll note that Python core developers do care about memory leaks.
>>>
>>> And that's a really good thing.
>
>> Memory? Let me laugh!
>
> [snip repeated (for about the 5th time) posting of single character memory
> sizes]
>
> Jim, since I know you are smart enough to know the different between a small
> fixed size and a continuous leak, I can only think that the purpose of your
> repeated post was to get similarly a inane response from a couple of other
> people. That is the definition of trolling. It is disrespectful of others
> and in my opinion is a violation of the Python Code of Conduct, which *does*
> apply to python-list. Please desist.

Agreed;
It's also a shame that it's so easy for such diversions to snowball so
often, and thus derail so many threads. Sometimes I feel that we have
so much trolling on this list because we're easy targets.

Nonetheless, I join in to ask jmf to stop posting these threads as
they do cause harm to the community. If you do not, I would rather
some form of moderating be applied.

A thanks to everyone who hasn't been so easily caught up in this malarky.
-- 
https://mail.python.org/mailman/listinfo/python-list