Re: Getting "empty" attachment with smtplib

2012-11-14 Thread Dieter Maurer
Tobiah  writes:

> I just found out that the attachment works fine
> when I read the mail from the gmail website.  Thunderbird
> complains that the attachment is empty.

The MIME standard (a set of RFCs) specifies how valid messages
with attachments should look like.

Fetch the mail (unprocessed if possible) and look at its
structure. If it is conformant to the MIME standard, then
"Thunderbird" made a mistake; otherwise, something went wrong
with the message construction.

I can already say that "smtplib" is not to blame. It is (mostly) unconcerned
with the internal structure of the message -- and by itself
will not empty attachments.

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


Re: Python garbage collector/memory manager behaving strangely

2012-11-14 Thread Dieter Maurer
a...@pythoncraft.com (Aahz) writes:

> ...
 def readlines(f):
 lines = []
 while "f is not empty":
 line = f.readline()
 if not line: break
 if len(line) > 2 and line[-2:] == '|\n':
 lines.append(line)
 yield ''.join(lines)
 lines = []
 else:
 lines.append(line)
>>> 
>>> There's a few changes I'd make:
>>> I'd change the name to something else, so as not to shadow the built-in,
> ...
> Actually, as an experienced programmer, I *do* think it is confusing as
> evidenced by the mistake Dave made!  Segregated namespaces are wonderful
> (per Zen), but let's not pollute multiple namespaces with same name,
> either.
>
> It may not be literally shadowing the built-in, but it definitely
> mentally shadows the built-in.

I disagree with you. namespaces are there that in working
with a namespace I do not need to worry much about other
namespaces. Therefore, calling a function "readlines"
is very much justified (if it reads lines from a file), even
though there was a module around with name "readlines".
By the way, the module is named "readline" (not "readlines").

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


DNS from Python (was Re: Subprocess puzzle and two questions)

2012-11-14 Thread Aahz
In article ,
Chris Angelico   wrote:
>On Thu, Nov 15, 2012 at 3:20 AM, Roy Smith  wrote:
>> 
>> My first thought to solve both of these is that it shouldn't be too
>> hard to hand-craft a minimal DNS query and send it over UDP.  Then, I
>> hunted around a bit and found that somebody had already done that, in
>> spades.  Take a look at http://www.dnspython.org; it might be exactly
>> what's needed here.
>
>Yeah, that sounds like a good option. I'm slightly surprised that
>there's no way with the Python stdlib to point a DNS query at a
>specific server, but dnspython might be the solution. On the flip
>side, dnspython is dauntingly large; it looks like a full
>implementation of DNS, but I don't see a simple entrypoint that wraps
>it all up into a simple function that can be bracketed with
>time.time() calls (granted, I only skimmed the docs VERY quickly). So
>it may be simpler to hand-craft an outgoing UDP packet once, save it
>as a string literal, send that, and just wait for any response. That
>eliminates all DNS protocolling and just times the round trip.

>From one of my scripts lying around:

domain = MAILTO.split('@',1)[1]
server = str(dns.resolver.query(domain, 'MX')[0].exchange)

You'll need to play around a bit to find out what that does, but it
should point you in the right direction.
-- 
Aahz (a...@pythoncraft.com)   <*> http://www.pythoncraft.com/

"LL YR VWL R BLNG T S"  -- www.nancybuttons.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Subprocess puzzle and two questions

2012-11-14 Thread Kushal Kumaran
Chris Angelico  writes:

> On Thu, Nov 15, 2012 at 12:49 PM, Roy Smith  wrote:
>> In article ,
>>  Chris Angelico  wrote:
>>
>>> I'm slightly surprised that there's no way with the Python stdlib to
>>> point a DNS query at a specific server
>>
>> Me too, including the "only slightly" part.  The normal high-level C
>> resolver routines (getaddrinfo/getnameinfo, or even the old
>> gethostbyname series), don't expose any way to do that.  You have to dig
>> quite far down in the resolver library stack to get to the point where
>> you can do that.  The concept of not knowing or caring which specific
>> server has the data you need is quite deeply baked into the basic DNS
>> architecture.
>
> Indeed. But Python boasts that the batteries are included, and given
> the wealth of other networking facilities that are available, it is a
> bit of a hole that you can't run DNS queries in this way.
>
> Mind you, if Python's managed to get this far without it being a major
> stumbling-block, that probably means that it's not a serious lack. And
> I don't think many people write DNS *servers* in Python. (Most people
> don't write DNS servers at all, since BIND exists. But I did exactly
> that this week, since it would be easier than most other options.)
>

Indeed.  Most people would prefer if random applications didn't make
their own decisions about using specific DNS servers.  That way, the
users can make their own configuration choices (gai.conf, nsswitch.conf)
according to their site preferences.

If your application needs that level of control (if you're writing a
nslookup replacement for some reason, perhaps), dnspython
(www.dnspython.org) seems to have it.

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


Re: Subprocess puzzle and two questions

2012-11-14 Thread Dave Angel
On 11/14/2012 09:21 PM, Chris Angelico wrote:
> On Thu, Nov 15, 2012 at 1:10 PM, Roy Smith  wrote:
>> In article ,
>>  Chris Angelico  wrote:
>>
>>> Indeed. But Python boasts that the batteries are included, and given
>>> the wealth of other networking facilities that are available, it is a
>>> bit of a hole that you can't run DNS queries in this way.
>> Think of the socket and struct modules as a pile of carbon rods and gobs
>> of zinc paste, from which you can assemble your own batteries, and make
>> them in exactly the shape and size you need.
> Then assembly language is a pile of protons, neutrons, and electrons...

And real machine language (microcode) is a pile of quarks;  fermions
versus bosons.  But in recent years, you pretty much have to work at
Intel to see that part of the processor.



-- 

DaveA

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


Re: Subprocess puzzle and two questions

2012-11-14 Thread Chris Angelico
On Thu, Nov 15, 2012 at 1:10 PM, Roy Smith  wrote:
> In article ,
>  Chris Angelico  wrote:
>
>> Indeed. But Python boasts that the batteries are included, and given
>> the wealth of other networking facilities that are available, it is a
>> bit of a hole that you can't run DNS queries in this way.
>
> Think of the socket and struct modules as a pile of carbon rods and gobs
> of zinc paste, from which you can assemble your own batteries, and make
> them in exactly the shape and size you need.

Then assembly language is a pile of protons, neutrons, and electrons...

:)

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


Re: Subprocess puzzle and two questions

2012-11-14 Thread Roy Smith
In article ,
 Chris Angelico  wrote:

> Indeed. But Python boasts that the batteries are included, and given
> the wealth of other networking facilities that are available, it is a
> bit of a hole that you can't run DNS queries in this way.

Think of the socket and struct modules as a pile of carbon rods and gobs 
of zinc paste, from which you can assemble your own batteries, and make 
them in exactly the shape and size you need.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Subprocess puzzle and two questions

2012-11-14 Thread Chris Angelico
On Thu, Nov 15, 2012 at 12:49 PM, Roy Smith  wrote:
> In article ,
>  Chris Angelico  wrote:
>
>> I'm slightly surprised that there's no way with the Python stdlib to
>> point a DNS query at a specific server
>
> Me too, including the "only slightly" part.  The normal high-level C
> resolver routines (getaddrinfo/getnameinfo, or even the old
> gethostbyname series), don't expose any way to do that.  You have to dig
> quite far down in the resolver library stack to get to the point where
> you can do that.  The concept of not knowing or caring which specific
> server has the data you need is quite deeply baked into the basic DNS
> architecture.

Indeed. But Python boasts that the batteries are included, and given
the wealth of other networking facilities that are available, it is a
bit of a hole that you can't run DNS queries in this way.

Mind you, if Python's managed to get this far without it being a major
stumbling-block, that probably means that it's not a serious lack. And
I don't think many people write DNS *servers* in Python. (Most people
don't write DNS servers at all, since BIND exists. But I did exactly
that this week, since it would be easier than most other options.)

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


Re: Python questions help

2012-11-14 Thread Chris Angelico
On Thu, Nov 15, 2012 at 12:47 PM, su29090 <129k...@gmail.com> wrote:
> I brought a python book and i'm a beginner and I read and tried to do the 
> questions and I still get it wrong.

Pick one of the questions, write as much of the code as you can, and
then post the specific difficulties you're having. If we write the
code for you, it won't help you to learn, will it?

Once you have some code that isn't working, we can help you to figure
out what it is that isn't working. But do your best to write the code
yourself first.

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


Re: Subprocess puzzle and two questions

2012-11-14 Thread Roy Smith
In article ,
 Chris Angelico  wrote:

> I'm slightly surprised that there's no way with the Python stdlib to 
> point a DNS query at a specific server

Me too, including the "only slightly" part.  The normal high-level C 
resolver routines (getaddrinfo/getnameinfo, or even the old 
gethostbyname series), don't expose any way to do that.  You have to dig 
quite far down in the resolver library stack to get to the point where 
you can do that.  The concept of not knowing or caring which specific 
server has the data you need is quite deeply baked into the basic DNS 
architecture.
-- 
http://mail.python.org/mailman/listinfo/python-list


Python questions help

2012-11-14 Thread su29090
I brought a python book and i'm a beginner and I read and tried to do the 
questions and I still get it wrong.

How to create a program that reads an uspecified number of integers, that 
determines how many positive and negative values have been read, and computes 
the total and average of the input values(not counting zeroes). My program have 
to end with the input 0 and have to display the average as a floating-point 
number.


Use nested loops that display the following patterns in separate programs:

1
12
123
1234
12345
123456

123456
12345
1234
123
12
1

 1
21
   321
  4321
 54321
654321

Write a program that computes the following summation:

1/ 1+square root of 2 + 1/ 1+square root of 2 + square root of 3 + 1/ 1+square 
root of 3 + square root of 4...+ 1/ 1+square root of 624 + square root of 625

How to  a program to draw a chessboard using range?

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


Re: Simple Question regarding running .py program

2012-11-14 Thread Terry Reedy

On 11/14/2012 2:02 AM, ru...@yahoo.com wrote:


On the other hand finding and configuring a newsreader
for someone whose never done it before, as you recommend,
is a major time consumer.


Use a mail/news program such as Thunderbird and the newsreader comes for 
free. Setting up a gmane account with Thunderbird was, as I remember 
rather easy, easier than setting up a mail account.


--
Terry Jan Reedy

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


Re: Simple Question regarding running .py program

2012-11-14 Thread Terry Reedy

On 11/13/2012 11:10 PM, Chris Angelico wrote:

On Wed, Nov 14, 2012 at 2:31 PM, Caroline Hou  wrote:

Thank you Dave and everybody here for your helpful comments!This place is 
awesome! I found this group when I googled python-list. Seems like this is not 
the usual way you guys access the list?


There are several ways to communicate with this list.

* The comp.lang.python newsgroup - get a newsreader (there are plenty
around), and either connect to your ISP's news server (if they have
one that carries c.l.p) or to a public server, some of which cost
money.
* Use a news-to-web gateway such as Google Groups. That specific one
is deprecated on this list, as there's more noise than signal from
Google Groups.
* The mailing list python-list, delivered directly to your inbox many
times a day. This is what I personally use.


news.gmane.org group gmane.comp.python.general
many 'mail' programs such as Outlook Express or Thunderbird also handle news

--
Terry Jan Reedy

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


Re: Simple Question regarding running .py program

2012-11-14 Thread Steven D'Aprano
On Wed, 14 Nov 2012 23:07:53 +, Steven D'Aprano wrote:

> On Wed, 14 Nov 2012 10:20:13 -0800, rurpy wrote:
[...]
> [...]
>> As an aside, I've noticed that some those most vocal against GG have
>> also been very vocal about this group being inclusive.
> 
> I call bullshit. If you are going to accuse people of being "very vocal"
> against minorities, you damn well better have some evidence to back up
> your claim.
> 
> And if you don't, I would expect a public apology for that slur.

Ah, apparently I misread Rurpy's comment. I'm sorry, I was completely 
wrong to accuse Rurpy of accusing others of being opposed to including 
minorites in this group.

My apologies Rurpy, I don't know how I made that misreading.


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


Re: access spreadsheet data

2012-11-14 Thread Terry Reedy

On 11/14/2012 1:35 AM, Amit Agrawal wrote:

my problem is, i want to access data in spreadsheet to python code manualy
My data is

1/1982 8:00:000
1/2/1982 8:00:000
1/3/1982 8:00:000
1/4/1982 8:00:000
1/5/1982 8:00:000.7885
1/6/1982 8:00:000
1/7/1982 8:00:000
1/8/1982 8:00:001.6127


You used tabs, which get deleted by some mail/news readers. Anyway, here 
is a start:


data='''\
1/1982 8:00:00 0
1/5/1982 8:00:00 0.7885
1/19/1982 8:00:00 0
1/20/1982 8:00:00 0'''

lines = data.split('\n')
# up to here, only for example

for line in lines:
fields = line.split()
print('date {}: time {}: value {}'.format(fields[0], fields[1], 
fields[2]))


>>>
date 1/1982: time 8:00:00: value 0
date 1/5/1982: time 8:00:00: value 0.7885
date 1/19/1982: time 8:00:00: value 0
date 1/20/1982: time 8:00:00: value 0

For real usage assume data are in data.txt in current directory. Then 
start with


with open('data.txt') as lines:
  for line in lines

--
Terry Jan Reedy

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


Re: Simple Question regarding running .py program

2012-11-14 Thread Joshua Landau
Steven, whilst I hold you in high regard, this post seems spurned by bias.

I would urge you to reconsider your *argument*, although your *position*
has merit.

On 14 November 2012 23:07, Steven D'Aprano <
steve+comp.lang.pyt...@pearwood.info> wrote:

> On Wed, 14 Nov 2012 10:20:13 -0800, rurpy wrote:
>
> > On 11/14/2012 06:35 AM, Chris Angelico wrote:
> >> I stand by what I said. Members, plural, of this list. I didn't say
> >> "all members of", ergo the word "some" is superfluous, yet not needful,
> >> as Princess Ida put it.
> >
> > Then you would have no problem I suppose with "Australians are racists"
> > because some Australians are racist and I didn't say "all"?
>
> Speaking as an Australian, I wouldn't have a problem with that, because
> Australians *are* racist. To the degree that we can talk about a
> "national character", the national character of Australia is racist, even
> if many Aussies aren't, and many more try not to be.
>
> In any case, your example is provocative. Here's a less provocative
> version:
>
> [paraphrase]
> Then you would have no problem I suppose with "People have two legs"
> because some people have two legs and I didn't say "all"?
> [end paraphrase]


Ahem? Seriously?

With rounding, all people *do* have two legs. That's not fair. In fact, the
idea that most users of this list ban Google Groups is probably false.

Additionally, being provocative isn't actually  weakness of his argument,
although it is a distraction. He asked if you had a "problem" with it on
the basis that if it was a fair claim you would not, in order to show that
it was not a fair claim. That would *imply* his correctness.

How about this(?):
"People have brown hair."

 > As a user of GG, Usenet and email lists I claim you are wrong.  GG does
> > NOT require "quite a bit of extra work".  If it did, I wouldn't use it.
> > For occasional posters, GG is EASIER.  (It would be even easier if
> > Google would fix their execrable quoting behaviour but as I showed, it
> > is easy to work around that.) I think you are ignoring setup time and a
> > number of other secondary factors, things that are very significant to
> > occasional posters, in your evaluation of "easy".
>
> I don't understand why you suggest counting setup time for the
> alternatives to Google Groups, but *don't* consider setup time for Google
> Groups. You had to create a Google Account didn't you? You've either put
> in your mobile phone number -- and screw those who don't have one -- or
> you get badgered every time you sign in. You do sign in don't you?
>

That's not fair, either, on the basis that almost everyone has a Google
account. Additionally, who signs in manually any more [*wink*]?


> For *really* occasional posters, they might not even remember their
> Google account details from one post to the next. So they have to either
> create a new account, or go through the process of recreating it. Why do
> you ignore these factors in *your* evaluation of "easy"?
>

They might not remember their Email account either. This seems to be a
really contrived point.


> We all do it -- when we talk about "easy" or "difficult", we have an
> idealised generalised user in mind. Your idealised user is different from
> Chris' idealised user. You are both generalising. And that's *my*
> generalisation.
>

All of this is really beside the point, anyway. He claimed the he used it
because *he* found it easier. And there was claim that there were good
reasons to use Google Groups. If you claim that his point is invalid
because it only talks about *his* idealised user, you've only invalidated
your own point.


> Even if you are right that Google Groups is easier for some users, in my
> opinion it is easy in the same way as the Dark Side of the Force.
> Quicker, faster, more seductive, but ultimately destructive.


How so?


>  > As for "best", that is clearly a matter of opinion. The very fact that
> > someone would killfile an entire class of poster based on a some others'
> > posts reeks of intolerance and group-think.
>
> Intolerance? Yes. But group-think? You believe that people are merely
> copying the group's prejudice against Google Groups. I don't think they
> are. I think that the dislike against GG is group consensus based on the
> evidence of our own eyes, not a mere prejudice.


Consensus? Hrm...A synonym of "consensus" is "unanimity". This argument's
existence basically disproves that.


> The use of Google Groups
> is, as far as I can tell, the single most effective predictor of badly
> written, badly thought out, badly formatted posts, and a common source of
> spam.
>
> As for intolerance, you say that like it is that a bad thing. Why should
> people have to tolerate bad behaviour? Google Groups *encourages* bad
> behaviour.


I think this is a valid thing to say. I agree largely because it's the
user's choice to read and reply to this list. Calling someone helpful in a
community "intolerant" because you think they could be nicer would be a bi

Re: Simple Question regarding running .py program

2012-11-14 Thread rurpy
On Wednesday, November 14, 2012 4:07:53 PM UTC-7, Steven D'Aprano wrote:
> On Wed, 14 Nov 2012 10:20:13 -0800, rurpy wrote:
> [...]
> > As an aside, I've noticed that some those most vocal against GG have
> > also been very vocal about this group being inclusive.
> 
> I call bullshit. If you are going to accuse people of being "very vocal" 
> against minorities, you damn well better have some evidence to back up 
> your claim.
>
> And if you don't, I would expect a public apology for that slur.

I wasn't very clear.  I should have written "...those most vocal 
against GG have also been very vocal *in favor* of this group being
inclusive."

In the next paragraph which you clipped I pointed out
the irony of that attitude versus one possible effect of 
advocating the blacklisting of GG posters:

> > If one observes that women post here (as a group)
> > a lot less frequently then men, and if GG is easier
> > for occasional posters, then the anti-GG attitude
> > expressed here by a few would have the effect of
> > disproportionately discriminating against women.

Response to your other points will need to wait until
I have more time.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Simple Question regarding running .py program

2012-11-14 Thread Steven D'Aprano
On Wed, 14 Nov 2012 10:20:13 -0800, rurpy wrote:

> On 11/14/2012 06:35 AM, Chris Angelico wrote:
[...]
>> I stand by what I said. Members, plural, of this list. I didn't say
>> "all members of", ergo the word "some" is superfluous, yet not needful,
>> as Princess Ida put it.
> 
> Then you would have no problem I suppose with "Australians are racists"
> because some Australians are racist and I didn't say "all"?

Speaking as an Australian, I wouldn't have a problem with that, because 
Australians *are* racist. To the degree that we can talk about a 
"national character", the national character of Australia is racist, even 
if many Aussies aren't, and many more try not to be.

In any case, your example is provocative. Here's a less provocative 
version:

[paraphrase]
Then you would have no problem I suppose with "People have two legs"
because some people have two legs and I didn't say "all"?
[end paraphrase]



> As a user of GG, Usenet and email lists I claim you are wrong.  GG does
> NOT require "quite a bit of extra work".  If it did, I wouldn't use it. 
> For occasional posters, GG is EASIER.  (It would be even easier if
> Google would fix their execrable quoting behaviour but as I showed, it
> is easy to work around that.) I think you are ignoring setup time and a
> number of other secondary factors, things that are very significant to
> occasional posters, in your evaluation of "easy".

I don't understand why you suggest counting setup time for the 
alternatives to Google Groups, but *don't* consider setup time for Google 
Groups. You had to create a Google Account didn't you? You've either put 
in your mobile phone number -- and screw those who don't have one -- or 
you get badgered every time you sign in. You do sign in don't you?

For *really* occasional posters, they might not even remember their 
Google account details from one post to the next. So they have to either 
create a new account, or go through the process of recreating it. Why do 
you ignore these factors in *your* evaluation of "easy"?

We all do it -- when we talk about "easy" or "difficult", we have an 
idealised generalised user in mind. Your idealised user is different from 
Chris' idealised user. You are both generalising. And that's *my* 
generalisation.

Even if you are right that Google Groups is easier for some users, in my 
opinion it is easy in the same way as the Dark Side of the Force. 
Quicker, faster, more seductive, but ultimately destructive.


> As for "best", that is clearly a matter of opinion. The very fact that
> someone would killfile an entire class of poster based on a some others'
> posts reeks of intolerance and group-think.

Intolerance? Yes. But group-think? You believe that people are merely 
copying the group's prejudice against Google Groups. I don't think they 
are. I think that the dislike against GG is group consensus based on the 
evidence of our own eyes, not a mere prejudice. The use of Google Groups 
is, as far as I can tell, the single most effective predictor of badly 
written, badly thought out, badly formatted posts, and a common source of 
spam.

As for intolerance, you say that like it is that a bad thing. Why should 
people have to tolerate bad behaviour? Google Groups *encourages* bad 
behaviour. Should we tolerate spam because any spam filter might 
occasionally throw away a legitimate mail? Should we tolerate acid 
attacks on women because occasionally there might be some woman who 
actually deserves such a horrible fate? I don't think so. For many 
things, intolerance is a *good* thing, and many people here believe that 
intolerance for Google Groups is one of those cases.

You of course are free to make whatever arrangements to filter spam and 
use Google Groups as you like, but you equally must respect other 
people's right to control their own inbox by filtering away GG posters.

[...]
> As an aside, I've noticed that some those most vocal against GG have
> also been very vocal about this group being inclusive.

I call bullshit. If you are going to accuse people of being "very vocal" 
against minorities, you damn well better have some evidence to back up 
your claim.

And if you don't, I would expect a public apology for that slur.



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


Describing code with slides

2012-11-14 Thread John Graves
I'm trying to work out the best way to provide a description of some code
in a set of presentation slides which can be played backward and forward
through the bits that someone is trying to understand (rather than using a
screencast -- where you can never seem to rewind just the right amount ...).

This example
http://slidespeech.com/s/dLItUXnOen/
required taking multiple screenshots and then importing them into
PowerPoint with Insert > Photo Album.

I added a voice over script to the speaker notes.

The result was then run through SlideSpeech.

If the code is available on a website, the slides can link to that site:
http://slidespeech.com/s/dLItUXnOen?link=http://codepad.org/X1GPad5c

Any suggestions on
1/ how to speed up the authoring process for this or
2/ improve the display of the code (such as avoiding showing all the IDE)?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Subprocess puzzle and two questions

2012-11-14 Thread Chris Angelico
On Thu, Nov 15, 2012 at 3:20 AM, Roy Smith  wrote:
> I wrote:
>>> Oh, my.  You're using DNS as a replacement for ping?  Fair enough.  In
>>> that case, all you really care about is that you can connect to port 53
>>> on the server...
>>>
>>> s = socket.socket()
>>> s.connect(('8.8.8.8', 53))
>
> In article ,
> Chris Angelico   wrote:
>>That assumes that (a) the remote server supports TCP for DNS
>
> This is true.  I honestly don't know what percentage of DNS servers
> out there only support UDP.  The two I tried (Google's 8.8.8.8, and my
> Apple TimeCapsule) both supported TCP, but that's hardly a
> representitive sample.

I don't know either, all I know is that DNSReport recommends
supporting TCP, and none of my DNS servers ever fail that check.

>> and (b) that connection time for TCP is comparable to
>> ping or an actual DNS lookup.
>
> My first thought to solve both of these is that it shouldn't be too
> hard to hand-craft a minimal DNS query and send it over UDP.  Then, I
> hunted around a bit and found that somebody had already done that, in
> spades.  Take a look at http://www.dnspython.org; it might be exactly
> what's needed here.

Yeah, that sounds like a good option. I'm slightly surprised that
there's no way with the Python stdlib to point a DNS query at a
specific server, but dnspython might be the solution. On the flip
side, dnspython is dauntingly large; it looks like a full
implementation of DNS, but I don't see a simple entrypoint that wraps
it all up into a simple function that can be bracketed with
time.time() calls (granted, I only skimmed the docs VERY quickly). So
it may be simpler to hand-craft an outgoing UDP packet once, save it
as a string literal, send that, and just wait for any response. That
eliminates all DNS protocolling and just times the round trip.

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


Re: creating size-limited tar files

2012-11-14 Thread Dave Angel
On 11/14/2012 03:43 PM, Andrea Crotti wrote:
> 
> Anyway the only thing I wanted to understand is if using the pipes in
> subprocess is exactly the same as doing
> the Linux pipe, or not.

It's not the same thing, but you can usually assume it's close.  Other
effects will probably dominate any differences.
> 
> And any idea on how to run it in ram?
> Maybe if I create a pipe in tmpfs it might already work, what do you think?
> 
> 

In a good virtual OS, such as Linux, there's very little predictable
difference between running in RAM (which is to say reading and writing
to the swap file) or reading and writing to a file you specify.  In
fact, writing to a file can frequently be quicker, if it's sequential.

Why?  Linux is using any given piece of physical RAM to map a file, or
an allocated buffer, or shared memory, or nearly anything.  About the
only special cases are the kind of RAM that has to be locked into RAM
for hardware reasons.

Linux decides which pieces to keep in memory, whether it calls it
caching, swapping, memory mapping, or whatever.  And frequently,
attempts to "beat the system"  result in counterintuitive results.

If in doubt, measure.  But choose your measures carefully, because lots
more things will change the measurement than you might expect.


-- 

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


Re: creating size-limited tar files

2012-11-14 Thread Andrea Crotti

On 11/14/2012 04:33 PM, Dave Angel wrote:

Well, as I said, I don't see how the particular timing has anything to
do with the rest of the thread.  If you want to do an ls within a Python
program, go ahead.  But if all you need can be done with ls itself, then
it'll be slower to launch python just to run it.

Your first timing runs python, which runs two new shells, ls, and cat.
Your second timing runs ls and cat.

So the difference is starting up python, plus starting the shell two
extra times.

I'd also be curious if you flushed the system buffers before each
timing, as the second test could be running entirely in system memory.
And no, I don't know offhand how to flush them in Linux, just that
without it, your timings are not at all repeatable.  Note the two
identical runs here.

davea@think:~/temppython$ time ls -lR ~ | cat > /dev/null

real0m0.164s
user0m0.020s
sys 0m0.000s
davea@think:~/temppython$ time ls -lR ~ | cat > /dev/null

real0m0.018s
user0m0.000s
sys 0m0.010s

real time goes down by 90%, while user time drops to zero.
And on a 3rd and subsequent run, sys time goes to zero as well.



Right I didn't think about that..
Anyway the only thing I wanted to understand is if using the pipes in 
subprocess is exactly the same as doing

the Linux pipe, or not.

And any idea on how to run it in ram?
Maybe if I create a pipe in tmpfs it might already work, what do you think?
--
http://mail.python.org/mailman/listinfo/python-list


Re: Running a curl command within py script

2012-11-14 Thread Gisle Vanem

"Smaran Harihar"  wrote:


i found pycurl to execute python curl command but not sure how I can
execute the curl command using the pycurl.

curl -u admin:geoserver -v -XPUT -H 'Content-type: text/plain' -d
'file:/var/www/geo/shapefile/csvQshp/Quercus_iltisii.shp'
http://localhost:8080/geoserver/rest/workspaces/acme/datastores/Quercus_iltisii/external.shp
?


Off-topic, but here's an idea. Use the 'curl --libcurl foo' option to see
what setopt() calls to use in PyCurl. Like:

import sys, pycurl

c = pycurl.Curl()
c.setopt (c.URL, 
'http://localhost:8080/geoserver/rest/workspaces/acme/datastores/Quercus_iltisii/external.shp')
c.setopt (c.USERPWD, 'admin:geoserver')
c.setopt (c.POSTFIELDS, 
'file:/var/www/geo/shapefile/csvQshp/Quercus_iltisii.shp');

etc.

--gv

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


Re: Error

2012-11-14 Thread MRAB

On 2012-11-14 15:18, inshu chauhan wrote:


for this code m getting this error :

CODE :
def ComputeClasses(data):
 radius = .5
 points = []
 for cy in xrange(0, data.height):
 for cx in xrange(0, data.width):
 if data[cy,cx] != (0.0,0.0,0.0):
 centre = data[cy, cx]
 points.append(centre)



Look at this line:


 change = True


It's indented the same as the preceding 'if' statement, which means
that it's executed even if the body of the 'if' statement wasn't
executed and it hasn't assigned to 'centre'.

So 'change' has been set to True, the 'while' loop is entered, and
subsequently an attempt is made to get 'centre', which hasn't been set.


 while change:

 for ring_number in xrange(1, 1000):
 change = False
 new_indices = GenerateRing(cx, cy, ring_number)


 for idx in new_indices:
 point = data[idx[0], idx[1]]

 if point == (0.0, 0.0, 0.0 ):
   continue
 else:
 dist = distance(centre, point)
 if  dist < radius :
 print point
 points.append(point)
 change = True
 print change



The indentation of this line looks wrong to me:


 break


It'll affect the 'for cx' loop at the end of its first iteration, every
time.


ERROR :
Traceback (most recent call last):
   File "Z:\modules\classification2.py", line 74, in 
 ComputeClasses(data)
   File "Z:\modules\classification2.py", line 56, in ComputeClasses
 dist = distance(centre, point)
UnboundLocalError: local variable 'centre' referenced before assignment

And i am unable to understand .. WHY ?



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


Re: Simple Question regarding running .py program

2012-11-14 Thread rurpy
On 11/14/2012 06:35 AM, Chris Angelico wrote:
> On Wed, Nov 14, 2012 at 6:02 PM, rurpy wrote:
>> On 11/13/2012 11:02 PM, Chris Angelico wrote:
>>> To be more accurate: This is deprecated *by members of* this list. As
>>> there is no commanding/controlling entity here, it's up to each
>>> individual to make a decision - for instance, abusive users get
>>> killfiled rather than banned. The use of Google Groups to post is
>>> deprecated in the original sense of the word: strongly disapproved of.
>>
>> s/deprecated *by members of*/deprecated *by some members of*/
>>
>> (and accuracy could probably be increased further by replacing
>> "some" with "a few".)
> 
> I stand by what I said. Members, plural, of this list. I didn't say
> "all members of", ergo the word "some" is superfluous, yet not
> needful, as Princess Ida put it.

Then you would have no problem I suppose with "Australians
are racists" because some Australians are racist and I
didn't say "all"?

I stand by what I said.  Using the passive voice to
give a false sense of authority, leaving out quantifiers 
when there are likely thousands of readers of this group 
perhaps a half dozen who've been vocal against GG, is 
not an accurate description.  

> In any case, the fact remains that a number of this list's best
> responders have killfiled Google Groups posters as a whole.
> Consequently, GG forces you to go to quite a bit of extra work AND
> prevents your message from getting through to everyone. Why go to
> extra work to get a worse result?

As a user of GG, Usenet and email lists I claim you 
are wrong.  GG does NOT require "quite a bit of extra 
work".  If it did, I wouldn't use it.  For occasional 
posters, GG is EASIER.  (It would be even easier if 
Google would fix their execrable quoting behaviour 
but as I showed, it is easy to work around that.)
I think you are ignoring setup time and a number 
of other secondary factors, things that are very
significant to occasional posters, in your evaluation
of "easy".

As for "best", that is clearly a matter of opinion.
The very fact that someone would killfile an entire
class of poster based on a some others' posts reeks
of intolerance and group-think.  And since some of the 
anti-GG proponents are also among the most opinionated 
and argumentative participants here, their not reading
GG posts could be seen as an advantage.

As an aside, I've noticed that some those most vocal 
against GG have also been very vocal about this group
being inclusive.

If one observes that women post here (as a group) 
a lot less frequently then men, and if GG is easier 
for occasional posters, then the anti-GG attitude 
expressed here by a few would have the effect of 
disproportionately discriminating against women.

> I am therefore not going to
> recommend Google Groups to anyone as a means of posting to
> python-list/c.l.p, 

That's fine.  But when doing so please leave out the 
false metaphors...

> any more than I would recommend writing it on a
> Post-It note and feeding it into your floppy drive.

...such as posting here via GG is similar to feeding
post-its into a floppy drive.
-- 
http://mail.python.org/mailman/listinfo/python-list


How Run Py.test from PyScripter

2012-11-14 Thread san
I am a newbie to py.test , Please let me know how to run the py.test in 
PyScripter Editor. I have tried in the belwo way but it doesn't work.

import pytest

def func(x): return x + 1

def test_answer(): assert func(3) == 5

pytest.main()

below is the Exception that i get 

Traceback (most recent call last):
  File "", line 10, in 
  File "C:\Python27\lib\site-packages\pytest-2.3.2-py2.7.egg\_pytest\core.py", 
line 474, in main
exitstatus = config.hook.pytest_cmdline_main(config=config)
  File "C:\Python27\lib\site-packages\pytest-2.3.2-py2.7.egg\_pytest\core.py", 
line 422, in __call__
return self._docall(methods, kwargs)
  File "C:\Python27\lib\site-packages\pytest-2.3.2-py2.7.egg\_pytest\core.py", 
line 433, in _docall
res = mc.execute()
  File "C:\Python27\lib\site-packages\pytest-2.3.2-py2.7.egg\_pytest\core.py", 
line 351, in execute
res = method(**kwargs)
  File "C:\Python27\lib\site-packages\pytest-2.3.2-py2.7.egg\_pytest\main.py", 
line 107, in pytest_cmdline_main
return wrap_session(config, _main)
  File "C:\Python27\lib\site-packages\pytest-2.3.2-py2.7.egg\_pytest\main.py", 
line 92, in wrap_session
config.pluginmanager.notify_exception(excinfo, config.option)
  File "C:\Python27\lib\site-packages\pytest-2.3.2-py2.7.egg\_pytest\core.py", 
line 285, in notify_exception
res = self.hook.pytest_internalerror(excrepr=excrepr)
  File "C:\Python27\lib\site-packages\pytest-2.3.2-py2.7.egg\_pytest\core.py", 
line 422, in __call__
return self._docall(methods, kwargs)
  File "C:\Python27\lib\site-packages\pytest-2.3.2-py2.7.egg\_pytest\core.py", 
line 433, in _docall
res = mc.execute()
  File "C:\Python27\lib\site-packages\pytest-2.3.2-py2.7.egg\_pytest\core.py", 
line 351, in execute
res = method(**kwargs)
  File 
"C:\Python27\lib\site-packages\pytest-2.3.2-py2.7.egg\_pytest\terminal.py", 
line 152, in pytest_internalerror
self.write_line("INTERNALERROR> " + line)
  File 
"C:\Python27\lib\site-packages\pytest-2.3.2-py2.7.egg\_pytest\terminal.py", 
line 140, in write_line
self._tw.line(line, **markup)
  File 
"C:\Python27\lib\site-packages\py-1.4.11-py2.7.egg\py\_io\terminalwriter.py", 
line 181, in line
self.write(s, **kw)
  File 
"C:\Python27\lib\site-packages\py-1.4.11-py2.7.egg\py\_io\terminalwriter.py", 
line 225, in write
self._file.write(msg)
  File 
"C:\Python27\lib\site-packages\py-1.4.11-py2.7.egg\py\_io\terminalwriter.py", 
line 241, in write
self._writemethod(data)
TypeError: 'AsyncStream' object is not callable
-- 
http://mail.python.org/mailman/listinfo/python-list


Running a curl command within py script

2012-11-14 Thread Smaran Harihar
Hi Guys,

i found pycurl to execute python curl command but not sure how I can
execute the curl command using the pycurl.

curl -u admin:geoserver -v -XPUT -H 'Content-type: text/plain' -d
'file:/var/www/geo/shapefile/csvQshp/Quercus_iltisii.shp'
http://localhost:8080/geoserver/rest/workspaces/acme/datastores/Quercus_iltisii/external.shp
?

This is the curl command.

-- 
Thanks & Regards
Smaran Harihar
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Getting "empty" attachment with smtplib

2012-11-14 Thread Tobiah

I just found out that the attachment works fine
when I read the mail from the gmail website.  Thunderbird
complains that the attachment is empty.

Thanks,

Toby

On 11/14/2012 09:51 AM, Tobiah wrote:

I've been sending an email blast out with smtplib and
it's been working fine. I'm attaching an html doc with

msg.attach(MIMEText(email, 'html'))

and it displays fine. Now I need to attach a .pdf
doc, but Thunderbird complains that the attachment
is empty. When I view the source of the email, the
headers look ok to me, and a large base64 looking
mess follows:

--===0152408622==
Content-Type: application/pdf
MIME-Version: 1.0
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename="tics.pdf"

JVBERi0xLjYNJeLjz9MNCjE0IDAgb2JqDTw8L0xpbmVhcml6ZWQgMS9MIDExNzk1My9PIDE2L0Ug
MTEyNjE3L04gMS9UIDExNzY0My9IIFsgNjA2IDI1M10+Pg1lbmRvYmoNICAgICAgICAgICAgICAg
DQo2MSAwIG9iag08PC9EZWNvZGVQYXJtczw8L0NvbHVtbnMgNS9QcmVkaWN0b3IgMTI+Pi9GaWx0
ZXIvRmxhdGVEZWNvZGUvSURbPDg4RkMxMTM2QjQ3RDhEQzRFMjkxQkEzRDJGNEIyODBBPjxGRTNC
RkM3MjNFMDg3QzRCQUEyNTUzMkM5NEI5QjNCOT5dL0luZGV4WzE0IDc4XS9JbmZvIDEzIDAgUi9M

and so on. I've tried a few recipes, and this is the one I'm trying now:

pdf = MIMEApplication(pdf_data, 'pdf')
pdf.add_header('Content-Disposition','attachment', filename = 'tics.pdf')
msg.attach(pdf)

Any help is appreciated. Also, if anyone has a working recipe, I'd like to
see it.

Thanks!

Tobiah


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


Re: creating size-limited tar files

2012-11-14 Thread Dave Angel
On 11/14/2012 11:16 AM, andrea crotti wrote:
> 2012/11/14 Dave Angel :
>> On 11/14/2012 10:56 AM, andrea crotti wrote:
>>> Ok this is all very nice, but:
>>>
>>> [andrea@andreacrotti tar_baller]$ time python2 test_pipe.py > /dev/null
>>>
>>> real  0m21.215s
>>> user  0m0.750s
>>> sys   0m1.703s
>>>
>>> [andrea@andreacrotti tar_baller]$ time ls -lR /home/andrea | cat > /dev/null
>>>
>>> real  0m0.986s
>>> user  0m0.413s
>>> sys   0m0.600s
>>>
>>> 
>>>
>>>
>>> So apparently it's way slower than using this system, is this normal?
>>
>> I'm not sure how this timing relates to the thread, but what it mainly
>> shows is that starting up the Python interpreter takes quite a while,
>> compared to not starting it up.
>>
>>
>> --
>>
>> DaveA
>>
> 
> 
> Well it's related because my program has to be as fast as possible, so
> in theory I thought that using Python pipes would be better because I
> can get easily the PID of the first process.
> 
> But if it's so slow than it's not worth, and I don't think is the
> Python interpreter because it's more or less constantly many times
> slower even changing the size of the input..
> 
> 

Well, as I said, I don't see how the particular timing has anything to
do with the rest of the thread.  If you want to do an ls within a Python
program, go ahead.  But if all you need can be done with ls itself, then
it'll be slower to launch python just to run it.

Your first timing runs python, which runs two new shells, ls, and cat.
Your second timing runs ls and cat.

So the difference is starting up python, plus starting the shell two
extra times.

I'd also be curious if you flushed the system buffers before each
timing, as the second test could be running entirely in system memory.
And no, I don't know offhand how to flush them in Linux, just that
without it, your timings are not at all repeatable.  Note the two
identical runs here.

davea@think:~/temppython$ time ls -lR ~ | cat > /dev/null

real0m0.164s
user0m0.020s
sys 0m0.000s
davea@think:~/temppython$ time ls -lR ~ | cat > /dev/null

real0m0.018s
user0m0.000s
sys 0m0.010s

real time goes down by 90%, while user time drops to zero.
And on a 3rd and subsequent run, sys time goes to zero as well.

-- 

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


Re: Subprocess puzzle and two questions

2012-11-14 Thread Roy Smith
I wrote:
>> Oh, my.  You're using DNS as a replacement for ping?  Fair enough.  In
>> that case, all you really care about is that you can connect to port 53
>> on the server...
>>
>> s = socket.socket()
>> s.connect(('8.8.8.8', 53))

In article ,
Chris Angelico   wrote:
>That assumes that (a) the remote server supports TCP for DNS

This is true.  I honestly don't know what percentage of DNS servers
out there only support UDP.  The two I tried (Google's 8.8.8.8, and my
Apple TimeCapsule) both supported TCP, but that's hardly a
representitive sample.

> and (b) that connection time for TCP is comparable to
> ping or an actual DNS lookup.

My first thought to solve both of these is that it shouldn't be too
hard to hand-craft a minimal DNS query and send it over UDP.  Then, I
hunted around a bit and found that somebody had already done that, in
spades.  Take a look at http://www.dnspython.org; it might be exactly
what's needed here.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python-list Digest, Vol 110, Issue 106

2012-11-14 Thread Jun Tanaka
Hi,

I have a question about Django. I easy_installed Django1.4 and psycopg2,
and python manage.py syncdb. And gave me a error; No module named
psycopg2.extensions. posgre9.1 is installed.
It works fine on my MAC but not my Windows. Does anyone know about
this issue

Hope to resolve this issue soon.
Jun
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: creating size-limited tar files

2012-11-14 Thread andrea crotti
2012/11/14 Dave Angel :
> On 11/14/2012 10:56 AM, andrea crotti wrote:
>> Ok this is all very nice, but:
>>
>> [andrea@andreacrotti tar_baller]$ time python2 test_pipe.py > /dev/null
>>
>> real  0m21.215s
>> user  0m0.750s
>> sys   0m1.703s
>>
>> [andrea@andreacrotti tar_baller]$ time ls -lR /home/andrea | cat > /dev/null
>>
>> real  0m0.986s
>> user  0m0.413s
>> sys   0m0.600s
>>
>> 
>>
>>
>> So apparently it's way slower than using this system, is this normal?
>
> I'm not sure how this timing relates to the thread, but what it mainly
> shows is that starting up the Python interpreter takes quite a while,
> compared to not starting it up.
>
>
> --
>
> DaveA
>


Well it's related because my program has to be as fast as possible, so
in theory I thought that using Python pipes would be better because I
can get easily the PID of the first process.

But if it's so slow than it's not worth, and I don't think is the
Python interpreter because it's more or less constantly many times
slower even changing the size of the input..
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: creating size-limited tar files

2012-11-14 Thread Dave Angel
On 11/14/2012 10:56 AM, andrea crotti wrote:
> Ok this is all very nice, but:
>
> [andrea@andreacrotti tar_baller]$ time python2 test_pipe.py > /dev/null
>
> real  0m21.215s
> user  0m0.750s
> sys   0m1.703s
>
> [andrea@andreacrotti tar_baller]$ time ls -lR /home/andrea | cat > /dev/null
>
> real  0m0.986s
> user  0m0.413s
> sys   0m0.600s
>
> 
>
>
> So apparently it's way slower than using this system, is this normal?

I'm not sure how this timing relates to the thread, but what it mainly
shows is that starting up the Python interpreter takes quite a while,
compared to not starting it up.


-- 

DaveA

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


Re: Error

2012-11-14 Thread Joel Goldstick
On Wed, Nov 14, 2012 at 10:18 AM, inshu chauhan wrote:

>
> for this code m getting this error :
>
> CODE :
> def ComputeClasses(data):
> radius = .5
> points = []
> for cy in xrange(0, data.height):
> for cx in xrange(0, data.width):
> if data[cy,cx] != (0.0,0.0,0.0):
>
This code is only run if the test above is true

> centre = data[cy, cx]
> points.append(centre)
>
>
> change = True
>
> while change:
>
> for ring_number in xrange(1, 1000):
> change = False
> new_indices = GenerateRing(cx, cy, ring_number)
>
>
> for idx in new_indices:
> point = data[idx[0], idx[1]]
>
> if point == (0.0, 0.0, 0.0 ):
>   continue
> else:
> dist = distance(centre, point)
>
centre is only set if the test above is true.  In your run, it apparently
wasn't

> if  dist < radius :
> print point
> points.append(point)
> change = True
> print change
>
>
> break
>
>
> ERROR :
> Traceback (most recent call last):
>   File "Z:\modules\classification2.py", line 74, in 
> ComputeClasses(data)
>   File "Z:\modules\classification2.py", line 56, in ComputeClasses
> dist = distance(centre, point)
> UnboundLocalError: local variable 'centre' referenced before assignment
>
> And i am unable to understand .. WHY ?
>
>
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
>


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


Re: Subprocess puzzle and two questions

2012-11-14 Thread wrw
On Nov 14, 2012, at 9:22 AM, Roy Smith  wrote:

> In article ,
> William Ray Wing  wrote:
> 
>> On Nov 13, 2012, at 11:41 PM, Roy Smith  wrote:
>> 
>>> In article ,
>>> w...@mac.com wrote:
>>> 
 I need to time the operation of a command-line utility (specifically 
 nslookup) from within a python program I'm writing.
>>> 
>>> Ugh.  Why are you doing this?  Shelling out to nslookup is an incredibly 
>>> slow and clumsy way of doing name translation.  What you really want to 
>>> be doing is calling getaddrinfo() directly.
>>> 
>>> See http://docs.python.org/2/library/socket.html#socket.getaddrinfo for 
>>> details.
>>> -- 
>> Because, unless I'm badly mistaken (very possible), getaddrinfo doesn't let 
>> me specify the server from which the name is returned. I'm really not after 
>> the name, what I'm REALLY after is the fact that a path exists to the name 
>> server I specify (and how long it takes to respond). In the "good old days" 
>> I 
>> would just have ping'd it, but these days more and more DNS boxes (and 
>> servers of all sorts) are shutting off their ping response.
>> 
>> Thanks, Bill
> 
> Oh, my.  You're using DNS as a replacement for ping?  Fair enough.  In 
> that case, all you really care about is that you can connect to port 53 
> on the server...
> 
> import socket
> import time
> s = socket.socket()
> t0 = time.time()
> s.connect(('8.8.8.8', 53))
> t1 = time.time()
> print "it took %f seconds to connect" % (t1 - t0)
> -- 
> http://mail.python.org/mailman/listinfo/python-list

Now THAT looks better.  Simpler, cleaner, (longer, taller, stronger, faster, 
cheaper…  :-)

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


Re: Error

2012-11-14 Thread Chris Angelico
On Thu, Nov 15, 2012 at 2:18 AM, inshu chauhan  wrote:
>
> for this code m getting this error :
>
> CODE :
> def ComputeClasses(data):
> if data[cy,cx] != (0.0,0.0,0.0):
> centre = data[cy, cx]
> ...
> dist = distance(centre, point)
>
> ERROR :
> UnboundLocalError: local variable 'centre' referenced before assignment
>
> And i am unable to understand .. WHY ?

In brief, here's what causes that error:

1) Somewhere in the function, you assign to that name, which
implicitly sets it to be a local variable. That happens there where
you go "centre = data[cy, cx]".

2) Somewhere else in the function, you reference that name. That
happens where you try to calculate the distance from your
previously-defined centre to the current point.

3) At run-time, you haven't executed #1, but you do execute #2.

Your problem here I can't diagnose, but it looks like your first point
is (0.0,0.0,0.0), so centre never gets set. There are a couple of
possible fixes for this, and you'll need to figure out what to do
based on knowing your own code. Possibly you just need to initialize
centre above the loop, so that it always has a valid value; or
possibly the code below needs to not execute if the current centre
hasn't been set.

Go through your function's logic by hand and figure out what happens
when, and whether that's what it ought to do. Then decide what should
happen when a data value is (0.0,0.0,0.0) - currently it's retaining
the value of centre from the previous iteration of the loop, which
smells wrong to me.

Beyond that, I don't think I can really help, it's up to you.

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


Error

2012-11-14 Thread inshu chauhan
for this code m getting this error :

CODE :
def ComputeClasses(data):
radius = .5
points = []
for cy in xrange(0, data.height):
for cx in xrange(0, data.width):
if data[cy,cx] != (0.0,0.0,0.0):
centre = data[cy, cx]
points.append(centre)


change = True

while change:

for ring_number in xrange(1, 1000):
change = False
new_indices = GenerateRing(cx, cy, ring_number)


for idx in new_indices:
point = data[idx[0], idx[1]]

if point == (0.0, 0.0, 0.0 ):
  continue
else:
dist = distance(centre, point)
if  dist < radius :
print point
points.append(point)
change = True
print change


break


ERROR :
Traceback (most recent call last):
  File "Z:\modules\classification2.py", line 74, in 
ComputeClasses(data)
  File "Z:\modules\classification2.py", line 56, in ComputeClasses
dist = distance(centre, point)
UnboundLocalError: local variable 'centre' referenced before assignment

And i am unable to understand .. WHY ?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Subprocess puzzle and two questions

2012-11-14 Thread Chris Angelico
On Thu, Nov 15, 2012 at 1:22 AM, Roy Smith  wrote:
> Oh, my.  You're using DNS as a replacement for ping?  Fair enough.  In
> that case, all you really care about is that you can connect to port 53
> on the server...
>
> import socket
> import time
> s = socket.socket()
> t0 = time.time()
> s.connect(('8.8.8.8', 53))
> t1 = time.time()
> print "it took %f seconds to connect" % (t1 - t0)

That assumes that (a) the remote server supports TCP for DNS (since
UDP is by far the more often used, some name servers don't bother
supporting TCP), and (b) that connection time for TCP is comparable to
ping or an actual DNS lookup. But in terms of approximating your
connection times, that's gotta be way better than shelling out to
several other processes.

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


Re: Subprocess puzzle and two questions

2012-11-14 Thread Roy Smith
In article ,
 William Ray Wing  wrote:

> On Nov 13, 2012, at 11:41 PM, Roy Smith  wrote:
> 
> > In article ,
> > w...@mac.com wrote:
> > 
> >> I need to time the operation of a command-line utility (specifically 
> >> nslookup) from within a python program I'm writing.
> > 
> > Ugh.  Why are you doing this?  Shelling out to nslookup is an incredibly 
> > slow and clumsy way of doing name translation.  What you really want to 
> > be doing is calling getaddrinfo() directly.
> > 
> > See http://docs.python.org/2/library/socket.html#socket.getaddrinfo for 
> > details.
> > -- 
> Because, unless I'm badly mistaken (very possible), getaddrinfo doesn't let 
> me specify the server from which the name is returned. I'm really not after 
> the name, what I'm REALLY after is the fact that a path exists to the name 
> server I specify (and how long it takes to respond). In the "good old days" I 
> would just have ping'd it, but these days more and more DNS boxes (and 
> servers of all sorts) are shutting off their ping response.
> 
> Thanks, Bill

Oh, my.  You're using DNS as a replacement for ping?  Fair enough.  In 
that case, all you really care about is that you can connect to port 53 
on the server...

import socket
import time
s = socket.socket()
t0 = time.time()
s.connect(('8.8.8.8', 53))
t1 = time.time()
print "it took %f seconds to connect" % (t1 - t0)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python garbage collector/memory manager behaving strangely

2012-11-14 Thread Aahz
In article <50570de3$0$29981$c3e8da3$54964...@news.astraweb.com>,
Steven D'Aprano   wrote:
>On Mon, 17 Sep 2012 06:46:55 -0400, Dave Angel wrote:
>> On 09/16/2012 11:25 PM, alex23 wrote:
>>>
>>> def readlines(f):
>>> lines = []
>>> while "f is not empty":
>>> line = f.readline()
>>> if not line: break
>>> if len(line) > 2 and line[-2:] == '|\n':
>>> lines.append(line)
>>> yield ''.join(lines)
>>> lines = []
>>> else:
>>> lines.append(line)
>> 
>> There's a few changes I'd make:
>> I'd change the name to something else, so as not to shadow the built-in,
>
>Which built-in are you referring to? There is no readlines built-in.
>
>py> readlines
>Traceback (most recent call last):
>  File "", line 1, in 
>NameError: name 'readlines' is not defined
>
>There is a file.readlines method, but that lives in a different namespace 
>to the function readlines so there should be no confusion. At least not 
>for a moderately experienced programmer, beginners can be confused by the 
>littlest things sometimes.

Actually, as an experienced programmer, I *do* think it is confusing as
evidenced by the mistake Dave made!  Segregated namespaces are wonderful
(per Zen), but let's not pollute multiple namespaces with same name,
either.

It may not be literally shadowing the built-in, but it definitely
mentally shadows the built-in.
-- 
Aahz (a...@pythoncraft.com)   <*> http://www.pythoncraft.com/

"Normal is what cuts off your sixth finger and your tail..."  --Siobhan
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Simple Question regarding running .py program

2012-11-14 Thread Chris Angelico
On Wed, Nov 14, 2012 at 6:02 PM,   wrote:
> On 11/13/2012 11:02 PM, Chris Angelico wrote:
>> To be more accurate: This is deprecated *by members of* this list. As
>> there is no commanding/controlling entity here, it's up to each
>> individual to make a decision - for instance, abusive users get
>> killfiled rather than banned. The use of Google Groups to post is
>> deprecated in the original sense of the word: strongly disapproved of.
>
> s/deprecated *by members of*/deprecated *by some members of*/
>
> (and accuracy could probably be increased further by replacing
> "some" with "a few".)

I stand by what I said. Members, plural, of this list. I didn't say
"all members of", ergo the word "some" is superfluous, yet not
needful, as Princess Ida put it.

In any case, the fact remains that a number of this list's best
responders have killfiled Google Groups posters as a whole.
Consequently, GG forces you to go to quite a bit of extra work AND
prevents your message from getting through to everyone. Why go to
extra work to get a worse result? I am therefore not going to
recommend Google Groups to anyone as a means of posting to
python-list/c.l.p, any more than I would recommend writing it on a
Post-It note and feeding it into your floppy drive.

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


Re: Generate unique ID for URL

2012-11-14 Thread Johannes Bauer
On 14.11.2012 13:33, Dave Angel wrote:

> Te birthday paradox could have been important had the OP stated his goal
> differently.  What he said was:
> 
> """Ideally I would want to avoid collisions altogether. But if that means 
> significant extra CPU time then 1 collision in 10 million hashes would be 
> tolerable."""
> 
> That means that he's willing to do the necessary overhead of collision
> resolution, once in every 10 million lookups.  That's not the same as
> saying that he wants only one chance in 10 million of having ANY
> collisions among his data items.

Since he stated in a later post that he actually went with MD5, the
calculations are indeed relevant. They give the number of bits a perfect
hash needs to have in order to get the desired low probablility of
collision resolutions. And for that the birthday paradox probability
must be considered instead of the (much lower) pre-image probability.

In any case, it appeared to me as if the OP was rather looking for ideas
and wasn't sure himself what approach to take -- so I find it quite
appropriate to give suggestions one way or another (even if they might
not fit the exact phrasing of one of his postings).

Best regards,
Johannes

-- 
>> Wo hattest Du das Beben nochmal GENAU vorhergesagt?
> Zumindest nicht öffentlich!
Ah, der neueste und bis heute genialste Streich unsere großen
Kosmologen: Die Geheim-Vorhersage.
 - Karl Kaos über Rüdiger Thomas in dsa 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Generate unique ID for URL

2012-11-14 Thread Dave Angel
On 11/14/2012 06:29 AM, Johannes Bauer wrote:
> 
>
> When doing these calculations, it's important to keep the birthday
> paradox in mind (this is kind of counter-intuitive): The chance of a
> collission raises tremendously when we're looking for *any* arbitrary
> two hashes colliding within a certain namespace. The probability you've
> calculated is the pre-image probability (which you also again need to
> multiply with a factor of two, because when trying to collide one given
> hash, in the mean case you'll only have to search *half* the namespace
> before finding a collision).
> 

Te birthday paradox could have been important had the OP stated his goal
differently.  What he said was:

"""Ideally I would want to avoid collisions altogether. But if that means 
significant extra CPU time then 1 collision in 10 million hashes would be 
tolerable."""

That means that he's willing to do the necessary overhead of collision
resolution, once in every 10 million lookups.  That's not the same as
saying that he wants only one chance in 10 million of having ANY
collisions among his data items.



-- 

DaveA

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


Re: Detect file is locked - windows

2012-11-14 Thread Tim Golden
On 14/11/2012 11:51, Hans Mulder wrote:
> It would be nice if he could give specific error messages, e.g.
> 
> "Can't write %s because it is locked by %s."
> 
> vs.
> 
> "Can't write %s because you don't have write access."
> 
> I can't speak for Ali, but I'm always annoyed by error messages
> listing several possible cuases, such as "Can't delete file,
> because the source or destination is in use".

(I realise you're not demanding this particular behaviour from Python
but just to expand on what the obstacles are to this at present):

Speaking merely from the point of view of the current Python
implementation on Windows, there are two obstacles to this:

* Python calls into the CRT which simply returns 13 (EACCESS) for both
of these situations. Obviously, Python could do its own thing on
Windows, partly reimplementing what the CRT does anyway and giving more
precise feedback. Equally obviously, this wouldn't be a trivial exercise.

* The added information -- who's locked the file, what permissions are
in place which prevent you gaining the requested access -- is
surprisingly fiddly to get hold of and would be something of an overhead
for the majority of the time when it's not wanted. Of course, in this
hypothetical Python one could add some sort of flag to the open()
function which requested or not the additional information.

The first obstacle is more significant than the second but neither is
negligible.

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


Re: Detect file is locked - windows

2012-11-14 Thread Hans Mulder
On 14/11/12 11:02:45, Tim Golden wrote:
> On 14/11/2012 00:33, Ali Akhavan wrote:
>> I am trying to open a file in 'w' mode open('file', 'wb'). open()
>> will throw with IOError with errno 13 if the file is locked by
>> another application or if user does not have permission to open/write
>> to the file.
> 
> What version of Python are you using?
> 
>>
>> How can I distinguish these two cases ? Namely, if some application
>> has the file open or not.
> 
> Can I ask what you expect to do differently in each of those cases? In
> other words, if you can't access the file, you can't access it. (Not to
> dismiss your question; I just wonder how you're going to handle the
> different cases)

It would be nice if he could give specific error messages, e.g.

"Can't write %s because it is locked by %s."

vs.

"Can't write %s because you don't have write access."

I can't speak for Ali, but I'm always annoyed by error messages
listing several possible cuases, such as "Can't delete file,
because the source or destination is in use".

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


Re: creating size-limited tar files

2012-11-14 Thread andrea crotti
2012/11/14 Kushal Kumaran :
>
> Well, well, I was wrong, clearly.  I wonder if this is fixable.
>
> --
> regards,
> kushal
> --
> http://mail.python.org/mailman/listinfo/python-list

But would it not be possible to use the pipe in memory in theory?
That would be way faster and since I have in theory enough RAM it
might be a great improvement..
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Detect file is locked - windows

2012-11-14 Thread Tim Golden
On 14/11/2012 00:33, Ali Akhavan wrote:
> I am trying to open a file in 'w' mode open('file', 'wb'). open()
> will throw with IOError with errno 13 if the file is locked by
> another application or if user does not have permission to open/write
> to the file.
> 
> How can I distinguish these two cases ? Namely, if some application
> has the file open or not.

The Python io module calls into the MS CRT, which maps both errors
(ERROR_ACCESS_DENIED & ERROR_SHARING_VIOLATION) to posix errno EACCESS,
which is 13.


If you really need to distinguish the two situations, you'll need to
call CreateFile directly (via ctypes or the pywin32 modules or an
extension module) and then call GetLastError() to get the specific
condition.

You're far better off using this EAFP approach as, even if it were
simple to determine beforehand whether a file can be locked or read --
and it's not -- that situation could have changed by the time you
actually come to open it.

Once you've successfully got a handle to the file, that handle is valid
regardless of any later changes to the file's security.

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


Re: Generate unique ID for URL

2012-11-14 Thread Johannes Bauer
On 14.11.2012 02:39, Roy Smith wrote:

> The next step is to reduce the number of bits you are encoding.  You 
> said in another post that "1 collision in 10 million hashes would be 
> tolerable".  So you need:
> 
 math.log(10*1000*1000, 2)
> 23.25349666421154
> 
> 24 bits worth of key. 

Nope :-)

> Base64 encoded, that's only 4 characters.  
> Actually, I probably just proved that I don't really understand how 
> probabilities work, so maybe what you really need is 32 or 48 or 64 
> bits.

:-))

When doing these calculations, it's important to keep the birthday
paradox in mind (this is kind of counter-intuitive): The chance of a
collission raises tremendously when we're looking for *any* arbitrary
two hashes colliding within a certain namespace. The probability you've
calculated is the pre-image probability (which you also again need to
multiply with a factor of two, because when trying to collide one given
hash, in the mean case you'll only have to search *half* the namespace
before finding a collision).

There are three things you need to know before you can give an estimate:
1. The permissible probability of a collision (1e-7 in this case)
2. The hash size
3. The worst-case number of elements in the namespace

You neglected 3 completely -- but knowing this is really important. This
becomes obvious when looking at the extreme cases: Let's say you have a
hash of arbitrary size, but only hash one element. The chance of a
collision is *always* zero. Or look at a hash of size 2^n. Then put 2^n
+ 1 elements in the namespace. The chance of a collision is *always* one.

Doing the calculations (formulas can be found on wikipedia on the site
of the birthday phaenomenon), you can come up with these following
bitlenghts of the hash with a 1e-7 probability of collision in respect
to the worst-case number of elements

10k elements: 49 bit
100k elements: 56 bit
1e6 elements: 63 bit
100e6 elements: 76 bit
1e9 elements: 83 bit
1e12 elements: 102 bit

Best regards,
Johannes

-- 
>> Wo hattest Du das Beben nochmal GENAU vorhergesagt?
> Zumindest nicht öffentlich!
Ah, der neueste und bis heute genialste Streich unsere großen
Kosmologen: Die Geheim-Vorhersage.
 - Karl Kaos über Rüdiger Thomas in dsa 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Supported Platforms for Python

2012-11-14 Thread Ulrich Eckhardt

Am 14.11.2012 10:51, schrieb Kiran N Mallekoppa:

1. Is this information available somewhere?
2. I was pointed to PEP-11, which documents the platforms that are not
supported. So, can we take that all active versions of Python (2.7.3 and
3.3, i believe) are supported on all the OS flavors that Python claims to
run on -- unless mentioned otherwise in the PEP-11?


There is intent to support these platforms, but as with every software 
that relies on volunteers, the actual extent varies. If you want to be 
sure that a platform is actively supported, check that the platform has 
an available and active build bot, because only this detects bitrot to a 
certain extent. If you want to be sure, create build and test systems 
for the systems you target yourself, you will then see if it works.




3. Also, regarding the following entries listed in the PEP-11. So, any idea
which OSes implement these?
   Name: Linux 1(Am guessing its the Linux kernel version
   1.0?)
   Unsupported in: Python 2.3
   Code removed in: Python 2.4


Yes, Linux 1 is obsolete and has been for > 10 years.



   Name: Systems defining __d6_pthread_create (configure.in)
   Unsupported in: Python 2.3
   Code removed in: Python 2.4
   Name: Systems defining PY_PTHREAD_D4, PY_PTHREAD_D6, or PY_PTHREAD_D7
   in thread_pthread.h
   Unsupported in: Python 2.3
   Code removed in: Python 2.4
   Name: Systems using --with-dl-dld
   Unsupported in: Python 2.3
   Code removed in: Python 2.4
   Name: Systems using --without-universal-newlines,
   Unsupported in: Python 2.3
   Code removed in: Python 2.4
   Name: Systems using --with-wctype-functions
   Unsupported in: Python 2.6
   Code removed in: Python 2.6


I'm not sure where these are used.



   Name: Systems using Mach C Threads
   Unsupported in: Python 3.2
   Code removed in: Python 3.3


Mach is a microkernel. I'm not sure if the Mach C Threads interface is 
obsolete on Mach or if Mach overall isn't supported. Probably irrelevant 
for the desktop.




   Name: Systems using --with-pth (GNU pth threads)
   Unsupported in: Python 3.2
   Code removed in: Python 3.3


I think this is targetted at early Linux threads that used fork() while 
sharing most of the memory space. Obsolete.




   Name: Systems using Irix threads
   Unsupported in: Python 3.2
   Code removed in: Python 3.3


Irix was a Unix variant shipped with SGI workstations. I don't kknow to 
what extent this is relevant for you. I think that the main use cases 
for these machines is 3D rendering/modelling, unless they have been 
superseeded by common desktop machines.




Kiran M N | Software Development (Rational Team Concert for Visual Studio.NET)


Just out of curiosity by one of your RTC users: What nice gimmics are 
you planning?



Cheers!


Uli

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


Re: Generate unique ID for URL

2012-11-14 Thread Richard
thanks for perspective!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Supported Platforms for Python

2012-11-14 Thread Kiran N Mallekoppa

Hi there!

Our team at IBM are exploring the possibility of implementing one of our
products using Python. I had a query in this regard.

As per IBM's policy, we list details of platforms that our product works on
- including the flavors of OS, the versions supported (and sometimes, even
the service packs, if it matters) so that it is un-ambiguous to our
customers. As an example, you can have a look at this page.

Suppose we are riding on Python (i.e., implementing using Python), we need
to tell our customers in similar detail as to what platforms we support our
products on. I tried to find information about the platforms on which
Python is supported from your page. But, it does not detail the versions of
OS supported.

In this regard, I have the following questions. Thanks for taking your time
to respond.
1. Is this information available somewhere?
2. I was pointed to PEP-11, which documents the platforms that are not
supported. So, can we take that all active versions of Python (2.7.3 and
3.3, i believe) are supported on all the OS flavors that Python claims to
run on -- unless mentioned otherwise in the PEP-11?
3. Also, regarding the following entries listed in the PEP-11. So, any idea
which OSes implement these?
  Name: Linux 1 (Am guessing its the Linux kernel version
  1.0?)
  Unsupported in: Python 2.3
  Code removed in: Python 2.4
  Name: Systems defining __d6_pthread_create (configure.in)
  Unsupported in: Python 2.3
  Code removed in: Python 2.4
  Name: Systems defining PY_PTHREAD_D4, PY_PTHREAD_D6, or PY_PTHREAD_D7
  in thread_pthread.h
  Unsupported in: Python 2.3
  Code removed in: Python 2.4
  Name: Systems using --with-dl-dld
  Unsupported in: Python 2.3
  Code removed in: Python 2.4
  Name: Systems using --without-universal-newlines,
  Unsupported in: Python 2.3
  Code removed in: Python 2.4
  Name: Systems using --with-wctype-functions
  Unsupported in: Python 2.6
  Code removed in: Python 2.6
  Name: Systems using Mach C Threads
  Unsupported in: Python 3.2
  Code removed in: Python 3.3
  Name: Systems using --with-pth (GNU pth threads)
  Unsupported in: Python 3.2
  Code removed in: Python 3.3
  Name: Systems using Irix threads
  Unsupported in: Python 3.2
  Code removed in: Python 3.3


Warm Regards,
Kiran M N | Software Development (Rational Team Concert for Visual
Studio.NET) | IBM Rational | India Software Labs | Email:
kiran@in.ibm.com



From:   Michael Foord 
To: webmas...@python.org
Cc: Kiran N Mallekoppa/India/IBM@IBMIN
Date:   08-11-12 08:10 PM
Subject:Re: Supported Platforms for Python




On 8 Nov 2012, at 14:36, webmas...@python.org wrote:

> On Thu, Nov 08, 2012, Kiran N Mallekoppa wrote:
>>
>> Suppose we are riding on Python (i.e., implementing using Python), we
need
>> to tell our customers in similar detail as to what platforms we support
our
>> products on. I tried to find information about the platforms on which
>> Python is supported from your page. But, it does not detail the versions
of
>> OS supported.
>>
>> Is this information available somewhere? If not, can this be published
on
>> your site?
>
> Not really.  ;-)  You'll find some on
> http://www.python.org/download/other/
>
> However, Python is (mostly) plain C and Open Source, which essentially
> means that support is available for any platform where people are willing
> to invest resources.  AIX in particular has always been one of the
> problem platforms.
>
> What this means for you is that if IBM wants to allocate resources to get
> Python running on any particular platform, it almost certainly can be
> done, and we certainly would appreciate getting any such work contributed
> back to the community.
>
> If you want more information, you're probably best off using one of the
> discussion forums listed in your auto-reply.


As an addendum note that there is a list of explicitly unsupported
platforms (platforms that used to be supported and in which versions of
Python support was removed):

 http://www.python.org/dev/peps/pep-0011/

You can see which platforms we test Python, and the test systems are
considered stable, from our buildbots. The Python 2.7 ones are here:

 http://buildbot.python.org/all/waterfall?category=2.7.stable

Another tangible way to support a platform is to provide and maintain a
buildbot for running the Python tests on.

All the best,

Michael Foord

> --
> Aahz (a...@pythoncraft.com)   <*>
http://www.pythoncraft.com/
>
> "Normal is what cuts off your sixth finger and your tail..."
--Siobhan
>


--
http://www.voidspace.org.uk/


May you do good and not evil
May you find forgiveness for yourself and forgive others
May you share freely, never taking more than you give.
-- the sqlite blessing
http://www.sqlite.org/different.html







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


Re: Detect file is locked - windows

2012-11-14 Thread Tim Golden
On 14/11/2012 00:33, Ali Akhavan wrote:
> I am trying to open a file in 'w' mode open('file', 'wb'). open()
> will throw with IOError with errno 13 if the file is locked by
> another application or if user does not have permission to open/write
> to the file.

What version of Python are you using?

> 
> How can I distinguish these two cases ? Namely, if some application
> has the file open or not.

Can I ask what you expect to do differently in each of those cases? In
other words, if you can't access the file, you can't access it. (Not to
dismiss your question; I just wonder how you're going to handle the
different cases)

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


Re: Generate unique ID for URL

2012-11-14 Thread Johannes Bauer
On 14.11.2012 01:41, Richard Baron Penman wrote:
> I found the MD5 and SHA hashes slow to calculate.

Slow? For URLs? Are you kidding? How many URLs per second do you want to
calculate?

> The builtin hash is fast but I was concerned about collisions. What
> rate of collisions could I expect?

MD5 has 16 bytes (128 bit), SHA1 has 20 bytes (160 bit). Utilizing the
birthday paradox and some approximations, I can tell you that when using
the full MD5 you'd need around 2.609e16 hashes in the same namespace to
get a one in a million chance of a collision. That is, 26090
filenames.

For SHA1 This number rises even further and you'd need around 1.71e21 or
171000 hashes in one namespace for the one-in-a-million.

I really have no clue about how many URLs you want to hash, and it seems
to be LOTS since the speed of MD5 seems to be an issue for you. Let me
estimate that you'd want to calculate a million hashes per second then
when you use MD5, you'd have about 827 years to fill the namespace up
enough to get a one-in-a-million.

If you need even more hashes (say a million million per second), I'd
suggest you go with SHA-1, giving you 54 years to get the one-in-a-million.

Then again, if you went for a million million hashes per second, Python
would probably not be the language of your choice.

Best regards,
Johannes

-- 
>> Wo hattest Du das Beben nochmal GENAU vorhergesagt?
> Zumindest nicht öffentlich!
Ah, der neueste und bis heute genialste Streich unsere großen
Kosmologen: Die Geheim-Vorhersage.
 - Karl Kaos über Rüdiger Thomas in dsa 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: stackoverflow quote on Python

2012-11-14 Thread Chris Angelico
On Wed, Nov 14, 2012 at 7:56 PM,   wrote:
> I'am still fascinated by the mathematically absurd "negative
> logic" used in and by the flexible string representation
> (algorithm).

I am still fascinated that you persist in comparing a buggy old Python
against a bug-free new Python and haven't noticed the difference.

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


Re: Division matrix

2012-11-14 Thread wxjmfauth
Le mardi 13 novembre 2012 02:00:28 UTC+1, Cleuson Alves a écrit :
> Hello, I need to solve an exercise follows, first calculate the inverse 
> matrix and then multiply the first matrix.
> 
> I await help.
> 
> Thank you.
> 
> follows the code below incomplete.
> 
> 
> 
> m = [[1,2,3],[4,5,6],[7,8,9]]
> 
> x = []
> 
> for i in [0,1,2]:
> 
> y = []
> 
> for linha in m:
> 
> y.append(linha[i])
> 
> x.append(y)
> 
> 
> 
> print x
> 
> [[1, 4, 7], [2, 5, 8], [3, 6, 9]]
> 
> 
> 
> def ProdMatrix(x,b):
> 
> tamL = len(x)
> 
> tamC = len(x[0])
> 
> c = nullMatrix(tamL,tamC)
> 
> for i in range(tamL):
> 
> for j in range(tamC):
> 
> val = 0
> 
> for k in range(len(b)):
> 
> val = val + x[i][l]*b[k][j]
> 
> c[i][j]
> 
> return c

--

Pedagogical hint:
Before blindly calculating the inverse matrix, it may be
a good idea to know if the inverse matrix exists.

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


Re: Detect file is locked - windows

2012-11-14 Thread Tim Golden
On 14/11/2012 08:55, Hans Mulder wrote:
> On 14/11/12 02:14:59, Mark Lawrence wrote:
>> On 14/11/2012 00:33, Ali Akhavan wrote:
>>> I am trying to open a file in 'w' mode open('file', 'wb'). open() will
>>> throw with IOError with errno 13 if the file is locked by another
>>> application or if user does not have permission to open/write to the
>>> file.
>>>
>>> How can I distinguish these two cases ? Namely, if some application
>>> has the file open or not.
> 
> I don't have a Windows machine at hand to try, but this might work:
> 
> if exc.errno == 13:
> if os.access('file', os.W_OK):
> print "Locked by another process"
> else:
> print "No permission to write"

No luck, I'm afraid. os.access on Windows is basically non-functional
(and would have been deprecated if I'd actually got around to doing it).
It basically checks the old-style readonly flag and that's it. IOW,
you'd return True for a file whose attributes you could read regardless
of whether you could read/write the file contents.

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


Re: stackoverflow quote on Python

2012-11-14 Thread wxjmfauth
Le mardi 13 novembre 2012 16:53:30 UTC+1, Mark Lawrence a écrit :
> On 13/11/2012 13:21, wxjmfa...@gmail.com wrote:
> 
> > Le mardi 13 novembre 2012 06:42:19 UTC+1, Steven D'Aprano a écrit :
> 
> >> On Tue, 13 Nov 2012 03:08:54 +, Mark Lawrence wrote:
> 
> >>
> 
> >> * strings are now proper text strings (Unicode), not byte strings;
> 
> >>
> 
> >
> 
> > 
> 
> >
> 
> > Let me laugh.
> 
> >
> 
> > jmf
> 
> >
> 
> 
> 
> Presumably because you're looking at yourself in a mirror, and have 
> 
> finally realised that you've completely misunderstood the work done with 
> 
> unicode in Python 3, specifically Python 3.3?
> 
> 
> 
> -- 
> 
> Cheers.
> 
> 
> 
> Mark Lawrence.



I'am still fascinated by the mathematically absurd "negative
logic" used in and by the flexible string representation
(algorithm).

jmf



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


Re: Detect file is locked - windows

2012-11-14 Thread Hans Mulder
On 14/11/12 02:14:59, Mark Lawrence wrote:
> On 14/11/2012 00:33, Ali Akhavan wrote:
>> I am trying to open a file in 'w' mode open('file', 'wb'). open() will
>> throw with IOError with errno 13 if the file is locked by another
>> application or if user does not have permission to open/write to the
>> file.
>>
>> How can I distinguish these two cases ? Namely, if some application
>> has the file open or not.

I don't have a Windows machine at hand to try, but this might work:

if exc.errno == 13:
if os.access('file', os.W_OK):
print "Locked by another process"
else:
print "No permission to write"

> Anything here help http://www.python.org/dev/peps/pep-3151/ ?

That won't help: in Python 3.3, IOError with errno==13 has been
replaced by PermissionError.  It still doesn't tell you *why*
you got a PermissionError.


Hope this helps,

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


Re: creating size-limited tar files

2012-11-14 Thread Kushal Kumaran
Ian Kelly  writes:

> On Tue, Nov 13, 2012 at 11:05 PM, Kushal Kumaran
>  wrote:
>> Or, you could just change the p1's stderr to an io.BytesIO instance.
>> Then call p2.communicate *first*.
>
> This doesn't seem to work.
>
 b = io.BytesIO()
 p = subprocess.Popen(["ls", "-l"], stdout=b)
> Traceback (most recent call last):
>   File "", line 1, in 
>   File "/usr/lib64/python3.2/subprocess.py", line 711, in __init__
> errread, errwrite) = self._get_handles(stdin, stdout, stderr)
>   File "/usr/lib64/python3.2/subprocess.py", line 1112, in _get_handles
> c2pwrite = stdout.fileno()
> io.UnsupportedOperation: fileno
>
> I think stdout and stderr need to be actual file objects, not just
> file-like objects.

Well, well, I was wrong, clearly.  I wonder if this is fixable.

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


Re: how to simulate tar filename substitution across piped subprocess.Popen() calls?

2012-11-14 Thread Hans Mulder
On 13/11/12 22:36:47, Thomas Rachel wrote:
> Am 12.11.2012 19:30 schrieb Hans Mulder:
> 
>> This will break if there are spaces in the file name, or other
>> characters meaningful to the shell.  If you change if to
>>
>>  xargsproc.append("test -f '%s/{}'&&  md5sum '%s/{}'"
>>   % (mydir, mydir))
>>
>> , then it will only break if there are single quotes in the file name.
> 
> And if you do mydir_q = mydir.replace("'", "'\\''") and use mydir_q, you
> should be safe...

The problem isn't single quotes in mydir, but single quotes in the
files names that 'tar' generates and 'xargs' consumes.  In the shell
script, these names go directly from tar to xargs via a pipe.  If the
OP wants to do your replace, his script would have to read the output
of tar and do the replace before passing the filenames down a second
pipe to xargs.

However, once he does that, it's simpler to cut out xargs and invoke
"sh" directly.  Or even cut out "sh" and "test" and instead use
os.path.isfile and then call md5sum directly.  And once he does that,
he no longer needs to worry about single quotes.

The OP has said, he's going to d all that.  One step at a time.
That sounds like a sensible plan to me.


Hope this helps,

-- HansM


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