Re: How to tell people to ask questions the smart way

2012-09-05 Thread Andreas Perstinger

On 05.09.2012 01:05, Ben Finney wrote:

Andreas Perstinger  writes:


On 04.09.2012 11:34, Paolo wrote:
> how do I know if a JTextField has the focus?
> thank to all

Look there:
http://www.catb.org/esr/faqs/smart-questions.html#forum


That is an unhelpful response.


So we have to agree to disagree.

EOD.

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


Re: Error 32 - Broken Pipe . Please Help!!

2012-09-05 Thread Mark Lawrence

On 05/09/2012 06:33, Dennis Lee Bieber wrote:

On Tue, 4 Sep 2012 20:40:57 -0700 (PDT), Ramchandra Apte
 declaimed the following in
gmane.comp.python.general:



*Please* make your variable names more descriptive.


No kidding... I haven't seen such cryptic names since 1972 -- an era
when BASIC only allowed for

A..Z{"" | 1..0}{"" | $}

{that is, one letter, with optional single digit, with optional $ for
string}



Presumably BASIC aficianodas still insist that BASIC is the second best 
programming language in the world, with the best yet to be invented :)


--
Cheers.

Mark Lawrence.

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


Re: why did the WindowsError occur?

2012-09-05 Thread Mark Lawrence

On 05/09/2012 07:30, Levi Nie wrote:

my code:
import os
os.startfile(r'C:\Program Files\Internet Explorer.exe')

the error:
os.startfile(r'C:\Program Files\Internet Explorer.exe')
WindowsError: [Error 2] : 'C:\\Program Files\\Internet Explorer.exe'





Because you've done something wrong.  If you'd like to tell us what 
you've done to find out where the problem is, we are far more likely to 
help.  Please remember that the rates of pay here are amongst the lowest 
in the world :)


--
Cheers.

Mark Lawrence.

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


Re: Beginners question

2012-09-05 Thread Mark Lawrence

On 05/09/2012 07:28, charvigro...@gmail.com wrote:

Hi,

I have attached python interview questions and answers for beginners.

Please visit http://www.f2finterview.com/web/CorePython/ for core python and

http://www.f2finterview.com/web/PythonAdvanced/ for advanced python




The first question from the advanced list is really going to stretch an 
advanced Python developer, so only gurus need bother as it's so 
difficult.  Not.



--
Cheers.

Mark Lawrence.

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


Re: How to tell people to ask questions the smart way

2012-09-05 Thread Mark Lawrence

On 05/09/2012 08:00, Andreas Perstinger wrote:

On 05.09.2012 01:05, Ben Finney wrote:

Andreas Perstinger  writes:


On 04.09.2012 11:34, Paolo wrote:
> how do I know if a JTextField has the focus?
> thank to all

Look there:
http://www.catb.org/esr/faqs/smart-questions.html#forum


That is an unhelpful response.


So we have to agree to disagree.

EOD.

Bye, Andreas


Thinking about it your post was very unhelpful as I couldn't find 
anything about JTextField at the url you posted as seen above.  Fancy 
wasting my time like that :)


--
Cheers.

Mark Lawrence.

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


Re: Comparing strings from the back?

2012-09-05 Thread Peter Otten
Roy Smith wrote:

> There's been a bunch of threads lately about string implementations, and
> that got me thinking (which is often a dangerous thing).
> 
> Let's assume you're testing two strings for equality.  You've already
> done the obvious quick tests (i.e they're the same length), and you're
> down to the O(n) part of comparing every character.
> 
> I'm wondering if it might be faster to start at the ends of the strings
> instead of at the beginning?  If the strings are indeed equal, it's the
> same amount of work starting from either end.  But, if it turns out that
> for real-life situations, the ends of strings have more entropy than the
> beginnings, the odds are you'll discover that they're unequal quicker by
> starting at the end.
> 
> It doesn't seem un-plausible that this is the case.  For example, most
> of the filenames I work with begin with "/home/roy/".  Most of the
> strings I use as memcache keys have one of a small number of prefixes.
> Most of the strings I use as logger names have common leading
> substrings.  Things like credit card and telephone numbers tend to have
> much more entropy in the trailing digits.

But do you actually compare them with each other? Even if you do I'd guess 
that Python looks at the hash values most of the time.
 
> On the other hand, hostnames (and thus email addresses) exhibit the
> opposite pattern.

Nor do english words:

$ python3 reverse_compare2.py compare /usr/share/dict/words --word-len 8

comparing every pair in a sample of 1000 8-char words
taken from '/usr/share/dict/words'

head
1: 477222 
2:  18870 **
3:   2870 
4:435 
5: 74 
6: 17 
7: 12 

tail
1: 386633 
2:  74966 ***
3:  29698 
4:   6536 *
5:   1475 
6:154 
7: 28 
8: 10 

> Anyway, it's just a thought.  Has anybody studied this for real-life
> usage patterns?
> 
> I'm also not sure how this work with all the possible UCS/UTF encodings.
> With some of them, you may get the encoding semantics wrong if you don't
> start from the front.


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


Re: Comparing strings from the back?

2012-09-05 Thread Chris Angelico
On Wed, Sep 5, 2012 at 6:29 PM, Peter Otten <__pete...@web.de> wrote:
> comparing every pair in a sample of 1000 8-char words
> taken from '/usr/share/dict/words'
>
> head
> 1: 477222 
> 2:  18870 **
> ...

Not understanding this. What are the statistics, and what (if it's not
obvious from the previous answer) do they prove?

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


Re: Python Interview Questions

2012-09-05 Thread Kushal Kumaran
On Wed, Sep 5, 2012 at 12:20 PM,   wrote:
> On Tuesday, October 30, 2007 11:44:01 PM UTC+5:30, Krypto wrote:
>> Hi,
>>
>> I have used Python for a couple of projects last year and I found it
>> extremely useful. I could write two middle size projects in 2-3 months
>> (part time). Right now I am a bit rusty and trying to catch up again
>> with Python.
>>
>> I am now appearing for Job Interviews these days and I am wondering if
>> anybody of you appeared for a Python Interview. Can you please share
>> the questions you were asked. That will be great help to me.
>>
>
> Finally I have decided to put best interview question and answers.
>
> Please visit http://www.f2finterview.com/web/CorePython/ for core python and 
> http://www.f2finterview.com/web/PythonAdvanced/ for advanced python
>

As I see from a quick glance, several of your answers seem to be
copied from the python faq at http://docs.python.org/faq/.  The
copyright notice for the python.org website seems to be at
http://docs.python.org/copyright.html.  Do you have the Python
Software Foundation's permission to copy large chunks of the
python.org website and claim it as your own content?

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


Re: Why derivated exception can not be pickled ?

2012-09-05 Thread Mathieu Courtois
Thanks for your reply


On Wednesday, September 5, 2012 8:02:55 AM UTC+2, Dieter Maurer wrote:
> 
> The pickle interface is actually more complex and there are several
> 
> ways an object can ensure picklability. For example, there is
> 
> also a "__reduce__" method. I suppose, that "Exception" defines methods
> 
> which trigger the use of an alternative picklability approach (different
> 
> from "__getstate__/__setstate__").

You're right: Exception has __reduce__ & __reduce_ex__ methods. Always read 
carefully the manual ;-)

I must override these methods.


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


Re: How to tell people to ask questions the smart way

2012-09-05 Thread Andrew Artajos
Stack Overflow has a nice guideline on how to ask a question.
http://stackoverflow.com/questions/ask/advice?

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


Re: Comparing strings from the back?

2012-09-05 Thread Andrew Artajos
a random idea:

you could compare strings by their hashes..

print hash("randomstring") == hash("randomstring")
print hash("randomstring") == hash("randoMstring")

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


Re: is implemented with id ?

2012-09-05 Thread Steven D'Aprano
On Wed, 05 Sep 2012 08:30:31 +0200, Franck Ditter wrote:

> Hi !
> a is b <==> id(a) == id(b) in builtin classes. Is that true ?

Not just for builtin classes, for any objects, provided that they are 
alive at the same time.

There is no guarantee whether IDs will be re-used. Some versions of 
Python do re-use IDs, e.g. CPython:

steve@runes:~$ python
Python 2.6.6 (r266:84292, Dec 27 2010, 00:02:40) 
[GCC 4.4.5] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> a = ["some", "object"]
>>> id(a)
3074285228L
>>> del a
>>> b = [100, 200]
>>> id(b)
3074285228L

but others do not, e.g. Jython and IronPython:

steve@runes:~$ jython
Jython 2.5.1+ (Release_2_5_1, Aug 4 2010, 07:18:19) 
[OpenJDK Client VM (Sun Microsystems Inc.)] on java1.6.0_18
Type "help", "copyright", "credits" or "license" for more information.
>>> a = ["some", "object"]
>>> id(a)
1
>>> del a
>>> b = [100, 200]
>>> id(b)
2


steve@runes:~$ ipy
IronPython 2.6 Beta 2 DEBUG (2.6.0.20) on .NET 2.0.50727.1433
Type "help", "copyright", "credits" or "license" for more information.
>>> a = ["some", "object"]
>>> id(a)
43
>>> del a
>>> b = [100, 200]
>>> id(b)
44


CPython especially has the most complicated behaviour with IDs and object 
identity: 

>>> a = 99.99
>>> b = 99.99
>>> a is b
False
>>> a = 99.99; b = 99.99; a is b 
True


In general, you almost never need to care about IDs and object identity. 
The main exception is testing for None, which should always be written as:

if x is None


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


Re: Comparing strings from the back?

2012-09-05 Thread Johannes Bauer
On 04.09.2012 20:07, Steven D'Aprano wrote:
> A reasonable, conservative assumption is to calculate the largest 
> possible value of the average for random strings. That largest value 
> occurs when the alphabet is as small as possible, namely two characters. 
> In practice, strings come from a larger alphabet, up to 1114111 different 
> characters for full Unicode strings, so the average for them will be less 
> than the average we calculate now.
> 
> So for unequal strings, the number of comparisons is equally likely to be 
> 1, 2, 3, ..., N. The average then is:

That is exactly what I don't agree with. For unequal random strings, the
distribution is *not* equally likely to have the same amount of
comparisons. For demonstration, let's look at bitstrings and the string
"1010". There 15 bitstrings of same length which are unequal and I'll
put the number of comparisons needed next to them going left to right:

  1
0001  1
0010  1
0011  1
0100  1
0101  1
0110  1
0111  1
1100  2
1101  2
1110  2
  2
1000  3
1001  3
1011  4

i.e. about 1.73 (26/15) comparisons in average with random strings
compared to the 2.5 comparisons you end up with. My formula does respect
lazy termination (because the probabilty of higher comparisons gets
exponentially lower).

> sum([1, 2, 3, ..., N])/N
> 
> which by a bit of simple algebra works out to be (N+1)/2, or half the 
> characters as I said.

Yes, but it's a flawed assumption you're making since you're neglecting
lazy evaluation and early abort of comparison.

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: Comparing strings from the back?

2012-09-05 Thread Johannes Bauer
On 04.09.2012 23:59, Chris Angelico wrote:

>> n = (256 / 255) * (1 - 256 ^ (-c))
>>
>> where n is the average number of character comparisons and c. The
>> rationale as follows: The first character has to be compared in any
>> case. The second with a probability of 1/256, the third with 1/(256^2)
>> and so on.
> 
> That would be for comparing two random areas of memory. Python strings
> don't have 256 options per character; and in terms of actual strings,
> there's so many possibilities. 

The unit of comparison is completely arbitraty and can equally be used
to compare bitstrings if changed accordingly.

> The strings that a program is going to
> compare for equality are going to use a vastly restricted alphabet;
> for a lot of cases, there might be only a few dozen plausible
> characters.

This is very true. But if so, I would like to see the assumtion that
you're making (which might very well be plausible) in order to arrive at
a average of N/2 comparisons (which just seems *way* off).

> But even so, it's going to scale approximately linearly with the
> string length. If they're really random, then yes, there's little
> chance that either a 1MB string or a 2MB string will be the same, but
> with real data, they might very well have a long common prefix. So
> it's still going to be more or less O(n).

I understand what you're saying and surely this is true to some extent
(someone mentioned filenames, which is an excellent example). However in
order to derive a *formula* you need to formularize your assumtions.
With random data, it's definitely not O(n). And even in reality (with a
more limited alphabet) it usually will early abort:

Consider sorting a large dictionary. Sorting is in O(n log(n)), but this
assumes O(1) comparisons! If the comparison operation itself were in
O(n), the total sorting complexity would be O(n^2 log(n)), which is
definitely false. Most comparisons will abort *very* early (after the
first character).

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: python docs search for 'print'

2012-09-05 Thread Terry Reedy

On 9/5/2012 1:22 AM, Ramchandra Apte wrote:

On Wednesday, 5 September 2012 09:35:43 UTC+5:30, Terry Reedy  wrote:



If you do find the right place, you should contribute something to an
improvement. The current search performance is not a secret, so mere
complaints are useless.



I was thinking we could just use Google Site search (it's fast easy to

> setup and gives good results)

I have the impression that that is what we once did, but maybe not. Or 
maybe that is or was for python.org but not docs.python.org, etc. Ease 
version of the docs needs the search restricted to that version. If you 
can give the way to do the easy setup, with that constraint, that would 
be a positive suggestion, accepted or not.



--
Terry Jan Reedy

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


Re: Comparing strings from the back?

2012-09-05 Thread Johannes Bauer
On 05.09.2012 11:24, Johannes Bauer wrote:

> Consider sorting a large dictionary. Sorting is in O(n log(n)), but this
> assumes O(1) comparisons! If the comparison operation itself were in
> O(n), the total sorting complexity would be O(n^2 log(n)), which is
> definitely false. Most comparisons will abort *very* early (after the
> first character).

I've just written a program to demonstrate this (below it's attached). I
used my aspell dictionary, which contains about 100k words. To have
complexity down I went for only words wich occur most often (in this
case 9 characters or ~13k words). Here's the results (note it's
randomized, so they'll always differ a little, but are pretty stable)

Max Cmp: 100
Sum Cmp: 32111
Avg Cmp: 2.393842254361115
Num words  : 13414
Min wordlen: 9
Max wordlen: 9
Avg wordlen: 9.0

Going up in wordlength (only showing part now)

Avg Cmp: 2.2374929735806632
Num words  : 10674
Avg wordlen: 10.0

Avg Cmp: 2.261727078891258
Num words  : 7504
Avg wordlen: 11.0

Avg Cmp: 2.2335647202939977
Num words  : 4898
Avg wordlen: 12.0

Avg Cmp: 2.1743341404358354
Num words  : 2891
Avg wordlen: 13.0

Avg Cmp: 2.156782549420586
Num words  : 1467
Avg wordlen: 14.0

Avg Cmp: 2.112449799196787
Num words  : 747
Avg wordlen: 15.0

So, interestingly, in this real-world case(tm), the complexity does not
scale with O(n). It actually goes down (which is probably due to the
limit amount of words of higher length).

In summary, let's please not debate "feelings" or such. Either
measurements (with clear indiciation on what data they're based on and
how the test was conducted) or derivations (with an explanation of the
assumtions). Feelings can be very misleading in cases like this.

Best regards,
Johannes



#!/usr/bin/python3
import random

class Word():
def __init__(self, s):
self._s = s
self._c = 0

def __lt__(self, other):
if len(self) < len(other):
return True
elif len(self) > len(other):
return False

for i in range(len(self)):
self._c += 1
if self._s[i] < other._s[i]:
return True
return False

def __repr__(self):
return "%s<%d>" % (self._s, self._c)

def __len__(self):
return len(self._s)

def getcmp(self):
return self._c

wordlist = [ ]
for line in open("dict", "r"):
word = Word(line[:-1])
if len(word) == 9:
wordlist.append(word)

random.shuffle(wordlist)
wordlist.sort()

comparisons = [ word.getcmp() for word in wordlist ]
print("Max Cmp:", max(comparisons))
print("Sum Cmp:", sum(comparisons))
print("Avg Cmp:", sum(comparisons) / len(comparisons))

wordlengths = [ len(word) for word in wordlist ]
print("Min wordlen:", min(wordlengths))
print("Max wordlen:", max(wordlengths))
print("Avg wordlen:", sum(wordlengths) / len(wordlengths))


-- 
>> 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: Comparing strings from the back?

2012-09-05 Thread Peter Otten
Chris Angelico wrote:

> On Wed, Sep 5, 2012 at 6:29 PM, Peter Otten <__pete...@web.de> wrote:
>> comparing every pair in a sample of 1000 8-char words
>> taken from '/usr/share/dict/words'
>>
>> head
>> 1: 477222 
>> 2:  18870 **
>> ...

tail
1: 386633 
2:  74966 ***

 
> Not understanding this. What are the statistics, 

I measured how many chars they have in common for all combinations of 1000 
words taken from /usr/share/dict/words.

477222 pairs have one char in common, 18870 pairs have two chars in common 
when compared from the *beginning* of the string.

386633 pairs have one char in common, 74966 pairs have two chars in common 
when compared from the *end* of the string.

and what (if it's not obvious from the previous answer) do they prove?

They demonstrate that for two words from that particular corpus it is likely 
that a[::-1] == b[::-1] has to take more (1.34 versus 1.05 on average) 
characters into account than a == b, i. e. comparing from the back should be 
slower rather than faster.

If that doesn't help, here's the code ;)

import random
import itertools
from contextlib import contextmanager
from collections import defaultdict

@contextmanager
def open_corpus(args):
with open(args.name) as instream:
words = (line.strip() for line in instream)
#words = (word for word in words if not word.endswith("'s"))
yield words

def pick(items, count):
items = list(items)
return random.sample(items, count)

def count_common(a, b):
i = 0
for i, (x, y) in enumerate(zip(a, b), 1):
if x != y:
break
return i

def corpus(args):
with open_corpus(args) as words:
wordlens = (len(line.strip()) for line in words)
freq = defaultdict(int)
for wordlen in wordlens:
freq[wordlen] += 1
show_histogram(freq)

def show_histogram(freq):
peak = max(freq.values())
freq_width = len(str(peak))
max_freq = max(freq)
len_width = len(str(max_freq))
for i in range(min(freq), max_freq+1):
value = freq[i]
print("{:{}}: {:{}} {}".format(
i, len_width, value,
freq_width, "*" * (60 * value // peak)))

def compare(args):
with open_corpus(args) as words:
words = pick(
(word for word in words if len(word) == args.word_len),
args.sample_size)
n = 0
head_common = defaultdict(int)
tail_common = defaultdict(int)
n_tail = n_head = 0
for n, (a, b) in enumerate(itertools.combinations(words, 2), 1):
cc = count_common(a, b)
n_head += cc
head_common[cc] += 1
ccr = count_common(a[::-1], b[::-1])
n_tail += ccr
tail_common[ccr] += 1

print(n, "combinations")
print("average common chars (head) {:.3}".format(n_head/n))
print("average common chars (tail) {:.3}".format(n_tail/n))

print("comparing every pair in a "
  "sample of {sample} {len}-char words\n"
  "taken from {name!r}".format(
sample=args.sample_size,
len=args.word_len,
name=args.name))
print()
print("head")
show_histogram(head_common)
print()
print("tail")
show_histogram(tail_common)

def main():
import argparse
parser = argparse.ArgumentParser()
parsers = parser.add_subparsers()

pcorpus = parsers.add_parser("corpus")
pcorpus.add_argument("name")
pcorpus.set_defaults(func=corpus)

pcompare = parsers.add_parser("compare")
pcompare.add_argument("name")
pcompare.add_argument("--sample-size", type=int, default=1000)
pcompare.add_argument("--word-len", type=int, default=8)
pcompare.set_defaults(func=compare)
args = parser.parse_args()
args.func(args)

if __name__ == "__main__":
main()


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


Re: Why derivated exception can not be pickled ?

2012-09-05 Thread Mathieu Courtois
Hello,

The simple example works fine using __reduce__:

class MyError(Exception):
def __init__(self, arg):
self.arg = arg

def __reduce__(self):
return (MyError, (self.arg, ))

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


[web] Long-running process: FCGI? SCGI? WSGI?

2012-09-05 Thread Gilles
Hello

To write a long-running web application, I'd like to some feedback
about which option to choose.

Apparently, the choice boilds down to this:
- FastCGI
- SCGI
- WSGI

It seems like FCGI and SCGI are language-neutral, while WSGI is
Python-specific.

Besides that, how to make an informed choice about which option to
choose?

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


Re: python docs search for 'print'

2012-09-05 Thread Ramchandra Apte
On Wednesday, 5 September 2012 15:03:56 UTC+5:30, Terry Reedy  wrote:
> On 9/5/2012 1:22 AM, Ramchandra Apte wrote:
> 
> > On Wednesday, 5 September 2012 09:35:43 UTC+5:30, Terry Reedy  wrote:
> 
> 
> 
> >> If you do find the right place, you should contribute something to an
> 
> >> improvement. The current search performance is not a secret, so mere
> 
> >> complaints are useless.
> 
> 
> 
> > I was thinking we could just use Google Site search (it's fast easy to
> 
>  > setup and gives good results)
> 
> 
> 
> I have the impression that that is what we once did, but maybe not. Or 
> 
> maybe that is or was for python.org but not docs.python.org, etc. Ease 
> 
> version of the docs needs the search restricted to that version. If you 
> 
> can give the way to do the easy setup, with that constraint, that would 
> 
> be a positive suggestion, accepted or not.
> 
> 
> 
> 
> 
> -- 
> 
> Terry Jan Reedy

Google site search costs 2000$ for 500,000 searches per year and 750$ for 
150,000 searches so its quite expensive.
Also the print function only comes in the third result (python 3.2)
if you search for "site:docs.python.org/release/3.2 print" the print function 
is not found at all.
I think a specialized algorithm would work better.
I'm going to code an program for this.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: is implemented with id ?

2012-09-05 Thread Ramchandra Apte
On Wednesday, 5 September 2012 14:44:23 UTC+5:30, Steven D'Aprano  wrote:
> On Wed, 05 Sep 2012 08:30:31 +0200, Franck Ditter wrote:
> 
> 
> 
> > Hi !
> 
> > a is b <==> id(a) == id(b) in builtin classes. Is that true ?
> 
> 
> 
> Not just for builtin classes, for any objects, provided that they are 
> 

Seeing this thread, I think the is statment should be removed.
It has a replacement syntax of id(x) == id(y) and "a==True" should be 
automatically changed into memory comparison.
> alive at the same time.
> 
> 
> 
> There is no guarantee whether IDs will be re-used. Some versions of 
> 
> Python do re-use IDs, e.g. CPython:
> 
> 
> 
> steve@runes:~$ python
> 
> Python 2.6.6 (r266:84292, Dec 27 2010, 00:02:40) 
> 
> [GCC 4.4.5] on linux2
> 
> Type "help", "copyright", "credits" or "license" for more information.
> 
> >>> a = ["some", "object"]
> 
> >>> id(a)
> 
> 3074285228L
> 
> >>> del a
> 
> >>> b = [100, 200]
> 
> >>> id(b)
> 
> 3074285228L
> 
> 
> 
> but others do not, e.g. Jython and IronPython:
> 
> 
> 
> steve@runes:~$ jython
> 
> Jython 2.5.1+ (Release_2_5_1, Aug 4 2010, 07:18:19) 
> 
> [OpenJDK Client VM (Sun Microsystems Inc.)] on java1.6.0_18
> 
> Type "help", "copyright", "credits" or "license" for more information.
> 
> >>> a = ["some", "object"]
> 
> >>> id(a)
> 
> 1
> 
> >>> del a
> 
> >>> b = [100, 200]
> 
> >>> id(b)
> 
> 2
> 
> 
> 
> 
> 
> steve@runes:~$ ipy
> 
> IronPython 2.6 Beta 2 DEBUG (2.6.0.20) on .NET 2.0.50727.1433
> 
> Type "help", "copyright", "credits" or "license" for more information.
> 
> >>> a = ["some", "object"]
> 
> >>> id(a)
> 
> 43
> 
> >>> del a
> 
> >>> b = [100, 200]
> 
> >>> id(b)
> 
> 44
> 
> 
> 
> 
> 
> CPython especially has the most complicated behaviour with IDs and object 
> 
> identity: 
> 
> 
> 
> >>> a = 99.99
> 
> >>> b = 99.99
> 
> >>> a is b
> 
> False
> 
> >>> a = 99.99; b = 99.99; a is b 
> 
> True
> 
> 
> 
> 
> 
> In general, you almost never need to care about IDs and object identity. 
> 
> The main exception is testing for None, which should always be written as:
> 
> 
> 
> if x is None
> 
> 
> 
> 
> 
> -- 
> 
> Steven

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


Re: why did the WindowsError occur?

2012-09-05 Thread Ramchandra Apte
On Wednesday, 5 September 2012 13:21:58 UTC+5:30, Mark Lawrence  wrote:
> On 05/09/2012 07:30, Levi Nie wrote:
> 
> > my code:
> 
> > import os
> 
> > os.startfile(r'C:\Program Files\Internet Explorer.exe')
> 
> >
> 
> > the error:
> 
> > os.startfile(r'C:\Program Files\Internet Explorer.exe')
> 
> > WindowsError: [Error 2] : 'C:\\Program Files\\Internet Explorer.exe'
> 
> >
> 
> >
> 
> >
> 
> 
> 
> Because you've done something wrong.  If you'd like to tell us what 
> 
> you've done to find out where the problem is, we are far more likely to 
> 
> help.  Please remember that the rates of pay here are amongst the lowest 
> 
> in the world :)
I haven't heard anybody in a group paying money to be able to answer a question!
So it should be the lowest rates of pay in the world.
> 
> 
> 
> -- 
> 
> Cheers.
> 
> 
> 
> Mark Lawrence.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: sockets,threads and interupts

2012-09-05 Thread Ramchandra Apte
On Wednesday, 5 September 2012 11:26:16 UTC+5:30, Dieter Maurer  wrote:
> loial  writes:
> 
> 
> 
> > I have threaded python script that uses sockets to monitor network ports.
> 
> >
> 
> > I want to ensure that the socket is closed cleanly in all circumstances. 
> > This includes if the script is killed or interupted in some other way.
> 
> 
> 
> The operating system should close all sockets automatically when
> 
> the process dies. Thus, if closing alone is sufficient...

At least on Linux, if you kill a process using sockets, it takes about 10 
seconds for socket to be closed. A program should try to close all resources. 
OS'es may take a long time to close a unclosed socket automatically.
-- 
http://mail.python.org/mailman/listinfo/python-list


HTMLParser skipping HTML? [newbie]

2012-09-05 Thread BobAalsma
I'm trying to understand the HTMLParser so I've copied some code from 
http://docs.python.org/library/htmlparser.html?highlight=html#HTMLParser and 
tried that on my LinkedIn page.
No errors, but some of the tags seem to go missing for no apparent reason - any 
advice?
I have searched extensively for this, but seem to be the only one with missing 
data from HTMLParser :(

Code:
import urllib2
from HTMLParser import HTMLParser

from GetHttpFileContents import getHttpFileContents

# create a subclass and override the handler methods
class MyHTMLParser(HTMLParser):
def handle_starttag(self, tag, attrs):
print "Start tag:\n\t", tag
for attr in attrs:
print "\t\tattr:", attr
# end for attr in attrs:
#
def handle_endtag(self, tag):
print "End tag :\n\t", tag
#
def handle_data(self, data):
if data != '\n\n':
if data != '\n':
print "Data :\t\t", data
# end if 1
# end if 2
#
#
# -
#
def removeHtmlFromFileContents():
TextOut = ''

parser = MyHTMLParser()

parser.feed(urllib2.urlopen('http://nl.linkedin.com/in/bobaalsma').read())

return TextOut
#
# -
#
if __name__ == '__main__':
TextOut = removeHtmlFromFileContents()





Part of the output:
End tag :
script
Start tag:
title
Data :  Bob Aalsma - Nederland | LinkedIn
End tag :
title
Start tag:
script
attr: ('type', 'text/javascript')
attr: ('src', 
'http://www.linkedin.com/uas/authping?url=http%3A%2F%2Fnl%2Elinkedin%2Ecom%2Fin%2Fbobaalsma')
End tag :
script
Start tag:
link
attr: ('rel', 'stylesheet')
attr: ('type', 'text/css')
attr: ('href', 
'http://s3.licdn.com/scds/concat/common/css?h=5v4lkweptdvona6w56qelodrj-7pfvsr76gzb22ys278pbj80xm-b1io9ndljf1bvpack85gyxhv4-5xxmkfcm1ny97biv0pwj7ch69')
Start tag:
script
attr: ('type', 'text/javascript')
attr: ('src', 
'http://s4.licdn.com/scds/concat/common/js?h=7nhn6ycbvnz80dydsu88wbuk-1kjdwxpxv0c3z97afuz9dlr9g-dlsf699o6xkxgppoxivctlunb-8v6o0480wy5u6j7f3sh92hzxo')
End tag :
script
End tag :
head



But the source text for this is [and all of the " seem to go missing:

Bob Aalsma | LinkedIn
https://s3-s.licdn.com/scds/concat/common/css?h=7d22iuuoi1bmp3a2jb6jyv5z5";>
https://s4-s.licdn.com/scds/concat/common/css?h=b1io9ndljf1bvpack85gyxhv4-6qrj4gxbwq8loasfnyfmyuphe-dhog2e5h8scik4whkpqccnzou-dmo1gwj6nlhvdvzx7rmluambv-69sgyia02rmcjmco0t9d3xpvo";>






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


Re: [2.5.1] Read each line from txt file, replace, and save?

2012-09-05 Thread Gilles
On Sun, 02 Sep 2012 14:04:29 -0400, Terry Reedy 
wrote:
>If you process each line separately, there is no reason to read them all 
>at once. Use the file as an iterator directly. Since line is already a 
>string, there is no reason to copy it into a new string. Combining these 
>two changes with Mark's suggestion to use with and we have the following 
>simple code:

Thanks guys for the suggestion.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Is there a way to configure IDLE to use spaces instead of tabs for indenting?

2012-09-05 Thread Ramchandra Apte
On Saturday, 25 August 2012 04:03:52 UTC+5:30, Alex  wrote:
> I'm new to Python and have been using IDLE 3.2.3 to experiment with
> 
> code as I learn. Despite being configured to use a 4 space indentation
> 
> width, sometimes IDLE's "smart" indentation insists upon using width-8
> 
> tabs.
> 
> 
> 
> From what I've been able to find on Google, this is due to a
> 
> shortcoming in Tk. While it's not that big a deal in the grand scheme
> 
> of things, I think it looks like poop, and I'd like to change IDLE to
> 
> use 4-space indentation instead of tabs for all indentation levels.
> 
> 
> 
> Is there any way for me to achieve what I want in IDLE, or do I have to
> 
> start up my full-blown IDE if I want consistent 4-space indentation?
> 
> 
> 
> Alex

I think an IDE is better than IDLE. Try NINJA IDE. http://ninja-ide.org
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: simple client data base

2012-09-05 Thread Ramchandra Apte
On Monday, 3 September 2012 19:42:21 UTC+5:30, Manatee  wrote:
> Hello all, I am learning to program in python. I have a need to make a
> 
> program that can store, retrieve, add, and delete client data such as
> 
> name, address, social, telephone number and similar information. This
> 
> would be a small client database for my wife who has a home accounting
> 
> business.
> 
> 
> 
> I have been reading about lists, tuples, and dictionary data
> 
> structures in python and I am confused as to which would be more
> 
> appropriate for a simple database.
> 
> 
> 
> I know that python has real database capabilities but I'm not there
> 
> yet and would like to proceed with as simple a structure as possible.
> 
> 
> 
> Can anyone give me some idea's or tell me which structure would be
> 
> best to use?
> 
> 
> 
> Maybe its a combination of structures? I need some help.
> 
> 
> 
> Thanks for your help.

If there are not more than 1000 records you can just use `pickle`
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: sockets,threads and interupts

2012-09-05 Thread Chris Angelico
On Wed, Sep 5, 2012 at 10:54 PM, Ramchandra Apte  wrote:
> At least on Linux, if you kill a process using sockets, it takes about 10 
> seconds for socket to be closed. A program should try to close all resources. 
> OS'es may take a long time to close a unclosed socket automatically.

Err, that's not my experience. When a process terminates, its
resources are released promptly.

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


Re: Extract Text Table From File

2012-09-05 Thread Ramchandra Apte
On Monday, 27 August 2012 15:42:14 UTC+5:30, Laszlo Nagy  wrote:
> On 2012-08-27 11:53, Huso wrote:
> 
> > Hi,
> 
> >
> 
> > I am trying to extract some text table data from a log file. I am trying 
> > different methods, but I don't seem to get anything to work. I am kind of 
> > new to python as well. Hence, appreciate if someone could help me out.
> 
> 
> 
> #
> 
> # Write test data to test.txt
> 
> #
> 
> 
> 
> data = """
> 
> ROUTES TRAFFIC RESULTS, LSR
> 
> TRG  MP   DATE   TIME
> 
>   37  17 120824   
> 
> 
> 
> R TRAFF   NBIDS   CCONG   NDV  ANBLO   MHTIME  NBANSW
> 
> AABBCCO 6.4 204 0.0   1151.0113.4 144
> 
> AABBCCI 3.0 293   1151.0 37.0 171
> 
> DDEEFFO 0.2   5 0.0590.0107.6   3
> 
> EEFFEEI 0.0   0590.0  0.0   0
> 
> HHGGFFO 0.0   0 0.0300.0  0.0   0
> 
> HHGGFFI 0.3  15300.0 62.2   4
> 
> END
> 
> """
> 
> fout = open("test.txt","wb+")
> 
> fout.write(data)
> 
> fout.close()
> 
> 
> 
> #
> 
> # This is how you iterate over a file and process its lines
> 
> #
> 
> fin = open("test.txt","r")
> 
> for line in fin:
> 
>  # This is one possible way to extract values.
> 
>  values = line.strip().split()
> 
>  print values
> 
> 
> 
> 
> 
> This will print:
> 
> 
> 
> []
> 
> ['ROUTES', 'TRAFFIC', 'RESULTS,', 'LSR']
> 
> ['TRG', 'MP', 'DATE', 'TIME']
> 
> ['37', '17', '120824', '']
> 
> []
> 
> ['R', 'TRAFF', 'NBIDS', 'CCONG', 'NDV', 'ANBLO', 'MHTIME', 'NBANSW']
> 
> ['AABBCCO', '6.4', '204', '0.0', '115', '1.0', '113.4', '144']
> 
> ['AABBCCI', '3.0', '293', '115', '1.0', '37.0', '171']
> 
> ['DDEEFFO', '0.2', '5', '0.0', '59', '0.0', '107.6', '3']
> 
> ['EEFFEEI', '0.0', '0', '59', '0.0', '0.0', '0']
> 
> ['HHGGFFO', '0.0', '0', '0.0', '30', '0.0', '0.0', '0']
> 
> ['HHGGFFI', '0.3', '15', '30', '0.0', '62.2', '4']
> 
> ['END']
> 
> 
> 
> 
> 
> The "values" list in the last line contains these values. This will work 
> 
> only if you don't have spaces in your values. Otherwise you can use 
> 
> regular expressions to parse a line. See here:
> 
> 
> 
> http://docs.python.org/library/re.html
> 
> 
> 
the csv module should be used for this not regex
> Since you did not give any specification on your file format, it would 
> 
> be hard to give a concrete program that parses your file(s)
> 
> 
> 
> Best,
> 
> 
> 
>  Laszlo

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


Re: is implemented with id ?

2012-09-05 Thread Franck Ditter
Thanks to all, but :
- I should have said that I work with Python 3. Does that matter ?
- May I reformulate the queston : "a is b" and "id(a) == id(b)"
  both mean : "a et b share the same physical address". Is that True ?
Thanks,

franck

In article ,
 Benjamin Kaplan  wrote:

> On Tue, Sep 4, 2012 at 11:30 PM, Franck Ditter  wrote:
> > Hi !
> > a is b <==> id(a) == id(b) in builtin classes.
> > Is that true ?
> > Thanks,
> >
> > franck
> 
> No. It is true that if a is b then id(a) == id(b) but the reverse is
> not necessarily true. id is only guaranteed to be unique among objects
> alive at the same time. If objects are discarded, their ids may be
> reused even though the objects are not the same.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: why did the WindowsError occur?

2012-09-05 Thread Chris Angelico
On Wed, Sep 5, 2012 at 10:51 PM, Ramchandra Apte  wrote:
> On Wednesday, 5 September 2012 13:21:58 UTC+5:30, Mark Lawrence  wrote:
>> Because you've done something wrong.  If you'd like to tell us what
>> you've done to find out where the problem is, we are far more likely to
>> help.  Please remember that the rates of pay here are amongst the lowest
>> in the world :)
>
> I haven't heard anybody in a group paying money to be able to answer a 
> question!
> So it should be the lowest rates of pay in the world.

Technically no, but when you consider the number of man-hours that get
donated, it's pretty impressive. We may not pay money, but we sure do
pay a lot of time. And why? Because the problems are interesting and
fun to solve. There's a lot more "replay value" in this list than
there is in most video games!

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


Re: Comparing strings from the back?

2012-09-05 Thread Oscar Benjamin
On 5 September 2012 10:48, Peter Otten <__pete...@web.de> wrote:

> Chris Angelico wrote:
>
> > On Wed, Sep 5, 2012 at 6:29 PM, Peter Otten <__pete...@web.de> wrote:
> >> comparing every pair in a sample of 1000 8-char words
> >> taken from '/usr/share/dict/words'
> >>
> >> head
> >> 1: 477222 
> >> 2:  18870 **
> >> ...
>
> tail
> 1: 386633 
> 2:  74966 ***
>
>
> > Not understanding this. What are the statistics,
>
> I measured how many chars they have in common for all combinations of 1000
> words taken from /usr/share/dict/words.
>
> 477222 pairs have one char in common, 18870 pairs have two chars in common
> when compared from the *beginning* of the string.
>
> 386633 pairs have one char in common, 74966 pairs have two chars in common
> when compared from the *end* of the string.
>
> and what (if it's not obvious from the previous answer) do they prove?
>
> They demonstrate that for two words from that particular corpus it is
> likely
> that a[::-1] == b[::-1] has to take more (1.34 versus 1.05 on average)
> characters into account than a == b, i. e. comparing from the back should
> be
> slower rather than faster.
>
> If that doesn't help, here's the code ;)
>  

def count_common(a, b):
> i = 0
> for i, (x, y) in enumerate(zip(a, b), 1):
> if x != y:
> break
> return i
>

This function will return 1 if the first character differs. It does not
count the number of common characters but rather the more relevant quantity
which is the number of comparisons required to decide if the strings are
equal.

It shows that, for the English words in this dictionary, the first letters
of two randomly selected 8-character words are equal ~5% of the time while
the last letters are equal ~20% of the time.

But despite the non-uniformity in the distribution of these strings,
this provides a good example of the fact that for many situations involving
real data, average case comparison complexity is O(1). This is because the
probability of stopping after N comparisons decreases exponentially with N,
so that the sequence of counts forms something loosely like an arithmetic
progression:

>>> cmp_forward = [477222, 18870, 2870, 435, 74, 17, 12]
>>> cmp_backward = [386633, 74966, 29698, 6536, 1475, 154, 28, 10]
>>> def ratios(seq):
... for count1, count2 in zip(seq[:-1], seq[1:]):
... yield count2 / float(count1)
...
>>> list(ratios(cmp_forward))
[0.03954134553729711, 0.15209326974032855, 0.15156794425087108,
0.17011494252873563, 0.22972972972972974, 0.7058823529411765]
>>> list(ratios(cmp_backward))
[0.19389446839767946, 0.39615292265827173, 0.22008216041484274,
0.22567319461444307, 0.10440677966101695, 0.18181818181818182,
0.35714285714285715]

A notable outlier in these sequences is for comparing the first character
of the two words which is why for this string distribution it is better to
start at the beginning than the end.

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


Re: Beginners question

2012-09-05 Thread Dave Angel
On 09/05/2012 04:03 AM, Mark Lawrence wrote:
> On 05/09/2012 07:28, charvigro...@gmail.com wrote:
>> Hi,
>>
>> I have attached python interview questions and answers for beginners.
>>
>> Please visit http://www.f2finterview.com/web/CorePython/ for core
>> python and
>>
>> http://www.f2finterview.com/web/PythonAdvanced/ for advanced python
>>
>>
>
> The first question from the advanced list is really going to stretch
> an advanced Python developer, so only gurus need bother as it's so
> difficult.  Not.
>
>

If the interviewer wants the whole page, and not just the first line,
then there's some understanding needed there.  What bothers me more is
the provided code and description:

for c in xrange(len(records)):
   fvalues = records[c]
...

and

"Here we start a loop which starts from 1 (understood) to whatever the ..."

Isn't an "advanced" Python user going to be expected to replace those
two with

for fvalues in records:

?


-- 

DaveA

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


Re: is implemented with id ?

2012-09-05 Thread Dave Angel
On 09/05/2012 08:48 AM, Ramchandra Apte wrote:
> On Wednesday, 5 September 2012 14:44:23 UTC+5:30, Steven D'Aprano  wrote:
>>  
>>
> Seeing this thread, I think the is statment should be removed.
> It has a replacement syntax of id(x) == id(y) and "a==True" should be 
> automatically changed into memory comparison.

You didn't read the whole message carefully enough.  Id's can be reused,
so there are many ways to mess up comparing id's.  One is if the two
items x and y are expressions (eg. function calls).  You call a
function, and say it returns a new object, you call id() on that object,
and then the object gets discarded.  You now have a stale id, and you
haven't even evaluated the second expression yet.

It's id() which is superfluous.  But it's useful for debugging, and for
understanding.



-- 

DaveA

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


Re: is implemented with id ?

2012-09-05 Thread Hans Mulder
On 5/09/12 15:19:47, Franck Ditter wrote:
> Thanks to all, but :
> - I should have said that I work with Python 3. Does that matter ?
> - May I reformulate the queston : "a is b" and "id(a) == id(b)"
>   both mean : "a et b share the same physical address". Is that True ?

Yes.

Keep in mind, though, that in some implementation (e.g.
Jython), the physical address may change during the life
time of an object.

It's usually phrased as "a and b are the same object".
If the object is mutable, then changing a will also change b.
If a and b aren't mutable, then it doesn't really matter
whether they share a physical address.

Keep in mind that physical addresses can be reused when an
object is destroyed.  For example, in my Python3,


id(math.sqrt(17)) == id(math.cos(17))

returns True, even though the floats involved are different,
because the flaots have non-overlapping lifetimes and the
physical address happens to be reused.


Hope this helps,

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


Re: HTMLParser skipping HTML? [newbie]

2012-09-05 Thread Peter Otten
BobAalsma wrote:

> I'm trying to understand the HTMLParser so I've copied some code from 
http://docs.python.org/library/htmlparser.html?highlight=html#HTMLParser and 
tried that on my LinkedIn page.
> No errors, but some of the tags seem to go missing for no apparent reason 
- any advice?
> I have searched extensively for this, but seem to be the only one with 
missing data from HTMLParser :(
> 
> Code:
> import urllib2
> from HTMLParser import HTMLParser
> 
> from GetHttpFileContents import getHttpFileContents
> 
> # create a subclass and override the handler methods
> class MyHTMLParser(HTMLParser):
> def handle_starttag(self, tag, attrs):
> print "Start tag:\n\t", tag
> for attr in attrs:
> print "\t\tattr:", attr
> # end for attr in attrs:
> #
> def handle_endtag(self, tag):
> print "End tag :\n\t", tag
> #
> def handle_data(self, data):
> if data != '\n\n':
> if data != '\n':
> print "Data :\t\t", data
> # end if 1
> # end if 2

Please no! A kitten dies every time you write one of those comments ;)

> def removeHtmlFromFileContents():
> TextOut = ''
> 
> parser = MyHTMLParser()
> parser.feed(urllib2.urlopen(
> 'http://nl.linkedin.com/in/bobaalsma').read())
> 
> return TextOut
> #
> # -
> #
> if __name__ == '__main__':
> TextOut = removeHtmlFromFileContents()


After removing 

> from GetHttpFileContents import getHttpFileContents

from your script I get the following output (using python 2.7):

$ python parse_orig.py | grep meta -C2
script
Start tag:
meta
attr: ('http-equiv', 'content-type')
attr: ('content', 'text/html; charset=UTF-8')
Start tag:
meta
attr: ('http-equiv', 'X-UA-Compatible')
attr: ('content', 'IE=8')
Start tag:
meta
attr: ('name', 'description')
attr: ('content', 'Bekijk het (Nederland) professionele 
profiel van Bob Aalsma  op LinkedIn. LinkedIn is het grootste zakelijke 
netwerk ter wereld. Professionals als Bob Aalsma kunnen hiermee interne 
connecties met aanbevolen kandidaten, branchedeskundigen en businesspartners 
vinden.')
Start tag:
meta
attr: ('name', 'pageImpressionID')
attr: ('content', '711eedaa-8273-45ca-a0dd-77eb96749134')
Start tag:
meta
attr: ('name', 'pageKey')
attr: ('content', 'nprofile-public-success')
Start tag:
meta
attr: ('name', 'analyticsURL')
attr: ('content', '/analytics/noauthtracker')
$ 

So there definitely are some meta tags. 

Note that if you're logged in into a site the html the browser is "seeing" 
may differ from the html you are retrieving via urllib.urlopen(...).read(). 
Perhaps that is the reason why you don't get what you expect.

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


Re: is implemented with id ?

2012-09-05 Thread Dave Angel
Please don't top-post.  Now your message is out of order, and if I have
to delete the part Benjamin said.

On 09/05/2012 09:19 AM, Franck Ditter wrote:
> Thanks to all, but :
> - I should have said that I work with Python 3. Does that matter ?
> - May I reformulate the queston : "a is b" and "id(a) == id(b)"
>   both mean : "a et b share the same physical address". Is that True ?
> Thanks,

No, id() has nothing to do with physical address.  The Python language
does not specify anything about physical addresses.  Some
implementations may happen to use physical addresses, others arbitrary
integers.  And they may reuse such integers, or not.  Up to the
implementation.

And as others have pointed out, when you compare two id's, you're
risking that one of them may no longer be valid.  For example, the
following expression:

 flag = id(func1()) == id(func2())

could very well evaluate to True, even if func1() always returns a
string, and func2() always returns an int.  On the other hand, the 'is'
expression makes sure the two expressions are bound to the same object.

If a and b are simple names, and not placeholders for arbitrary
expressions, then I  THINK  the following would be true:

"a is b"  and   "id(a) == id(b)"  both mean that the names a and b are
bound to the same object at the time the statement is executed.

-- 

DaveA

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


Re: is implemented with id ?

2012-09-05 Thread Steven D'Aprano
On Wed, 05 Sep 2012 05:48:26 -0700, Ramchandra Apte wrote:

> Seeing this thread, I think the is statment should be removed. It has a
> replacement syntax of id(x) == id(y)

A terrible idea.

Because "is" is a keyword, it is implemented as a fast object comparison 
directly in C (for CPython) or Java (for Jython). In the C implementation 
"x is y" is *extremely* fast because it is just a pointer comparison 
performed directly by the interpreter.

Because id() is a function, it is much slower. And because it is not a 
keyword, Python needs to do a name look-up for it, then push the argument 
on the stack, call the function (which may not even be the built-in id() 
any more!) and then pop back to the caller.

And worst, *it doesn't even do what you think it does*. In some Python 
implementations, IDs can be reused. That leads to code like this, from 
CPython 2.7:

py> id("spam ham"[1:]) == id("foo bar"[1:])
True

You *cannot* replace is with id() except when the objects are guaranteed 
to both be alive at the same time, and even then you *shouldn't* replace 
is with id() because that is a pessimation (the opposite of an 
optimization -- something that makes code run slower, not faster).


> and "a==True" should be automatically changed into memory comparison.

Absolutely not. That would be a backward-incompatible change that would 
break existing programs:

py> 1.0 == True
True
py> from decimal import Decimal
py> Decimal("1.") == True
True



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


Re: Python Interview Questions

2012-09-05 Thread Peter Otten
charvigro...@gmail.com wrote:

> Finally I have decided to put best interview question and answers.
> 
> Please visit http://***/web/CorePython/ for core python
> and http://***/web/PythonAdvanced/ for advanced python

Hm, are you a reformed PHP programmer who has never heard of sql injection 
attacks? The first "advanced" answer (and probably all the database-related 
stuff) should definitely be withdrawn.

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


how can i register the non-default browser with the webbrowser module?

2012-09-05 Thread Levi Nie
how can i register the non-default browser with the webbrowser module?

the case:
i want open a site such as "google.com" in ie8 with the python.But my
default is chrome.
so i want to register a ie8 controller with the webbrowser.register(*name*,
*constructor*[, *instance*]).
so what does the parameter "constructor" "instance" mean?
how can i do it?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Comparing strings from the back?

2012-09-05 Thread Steven D'Aprano
On Wed, 05 Sep 2012 11:43:08 +0200, Johannes Bauer wrote:

> On 05.09.2012 11:24, Johannes Bauer wrote:
> 
>> Consider sorting a large dictionary. Sorting is in O(n log(n)), but
>> this assumes O(1) comparisons! If the comparison operation itself were
>> in O(n), the total sorting complexity would be O(n^2 log(n)), 

This shows some significant confusion about Big Oh complexity analysis 
here. When you say that sorting the list of words is O(N log N), the N 
refers to the number of words in the dictionary. But when you speak about 
comparisons being O(N), the N doesn't refer to the size of the dict, but 
the size of the individual strings being compared. There is no reasonable 
comparison algorithm where the effort required to compare two strings 
depends on the size of the dictionary they have come from.

Since these are *completely different Ns*, you can't combine them to get 
O(N**2 log N) as the overall algorithmic complexity. Doing so is sheer 
nonsense. If you state it like this:

sorting the list of words is O(N log N) where N = length of the list
comparing the words is O(M) where M = the average length of the words

then the overall complexity is O(N log N)*O(M), but since M is a constant 
for any particular dictionary (its just the average length of the words) 
that reduces down to O(N log N).

To say that sorting a dictionary is O(N log N) does *not* imply that 
string comparisons are O(1). It only implies that string comparisons 
don't depend on the size of the dictionary. Comparing:

s1 = 'a'*30002
s2 = 'a'*30001 + 'b'

takes the same amount of time whether they are in a dictionary of 100 
words or one of 10 words. For the purposes of calculating the 
algorithmic complexity of sorting a large list of words, we can treat 
comparisons as an elementary operation even though they actually aren't.


>> which is
>> definitely false. Most comparisons will abort *very* early (after the
>> first character).

You are making unjustified assumptions about the distribution of letters 
in the words. This might be a list of long chemical compounds where the 
words typically differ only in their suffix. It might be a list of people 
with titles:

Herr Professor Frederick Schmidt
Herr Professor Frederick Wagner
...

But either way, it doesn't matter for the Big Oh behaviour of sorting the 
words.


> I've just written a program to demonstrate this (below it's attached).

I have no idea why you think this program demonstrates anything about 
string equality comparisons. What you are counting is not the average 
number of comparisons for string equality, but the number of comparisons 
when sorting. These are *completely different*, because sorting a list 
does not require testing each string against every other string.

Whatever you have measured, it has nothing to do with the Big Oh 
complexity of string comparisons.

It seems to me that you have misunderstood the purpose of Big Oh 
notation. It gives an asymptotic upper bound on the amount of work done, 
ignoring all lower terms and multiplicative factors, not an exact formula.

If something is O(N), then this tells you:

1) the number of algorithmic steps is proportional to N, plus or
   minus some terms which are less than N (e.g. sqrt(N), or log(N), 
   or 1/N, or some constant, etc.);

2) if you ignore those other terms, and keep all other influences
   equal, then doubling N will *at worst* double the number of
   algorithmic steps;

3) if all those algorithmic steps take exactly the same amount of
   time, then doubling N will take twice as much time.

But of course *none* of those assumptions hold for measurements of actual 
elapsed time. In real life, operations rarely take constant time, you 
don't always see worst case behaviour, and the lower terms are not 
necessarily insignificant enough to ignore.


[...]
> So, interestingly, in this real-world case(tm), the complexity does not
> scale with O(n). It actually goes down (which is probably due to the
> limit amount of words of higher length).

I would guess that it probably has more to do with the ability of the 
timsort algorithm to exploit local order within a list and avoid 
performing comparisons.


> In summary, let's please not debate "feelings" or such.

I have no idea what feelings you are referring to.



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


Re: Python Interview Questions

2012-09-05 Thread Chris Angelico
On Thu, Sep 6, 2012 at 12:21 AM, Peter Otten <__pete...@web.de> wrote:
> charvigro...@gmail.com wrote:
>
>> Finally I have decided to put best interview question and answers.
>>
>> Please visit http://***/web/CorePython/ for core python
>> and http://***/web/PythonAdvanced/ for advanced python
>
> Hm, are you a reformed PHP programmer who has never heard of sql injection
> attacks? The first "advanced" answer (and probably all the database-related
> stuff) should definitely be withdrawn.

I wouldn't go that far. The 'name' parameter, I would expect, would be
a constant. However, this strikes me as encouraging some really
inefficient code, like iterating over all the rows in a table with N+1
queries (one to get the length, then a separate query for each row).
Plus, use of limit without order by is not guaranteed (although since
this is specific to MySQL, it's unlikely you'll run into trouble - but
PostgreSQL, with its MVCC storage system, frequently reorders rows in
a table).

As a general rule, I don't like SQL builders. I'd prefer to directly
embed SQL statements in my code. Although sometimes a class can
helpfully manage some things, it's seldom worth having something that
tries to pretend a table is iterable in that sort of way.

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


Re: Comparing strings from the back?

2012-09-05 Thread Johannes Bauer
On 05.09.2012 04:18, Neil Hodgson wrote:

>The memcpy patch was controversial as it broke Adobe Flash which
> assumed memcpy was safe like memmove.

Adobe Flash was broken before, making an assumption that is not
guaranteed by the standard. The patch only showed the problem.

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: Python Interview Questions

2012-09-05 Thread Chris Angelico
On Thu, Sep 6, 2012 at 12:34 AM, Chris Angelico  wrote:
> However, this strikes me as encouraging some really
> inefficient code, like iterating over all the rows in a table with N+1
> queries (one to get the length, then a separate query for each row).

Huh. And then I scroll down, and that's precisely what he's doing. Do
you understand why this is a bad thing to do?

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


Re: is implemented with id ?

2012-09-05 Thread Steven D'Aprano
On Wed, 05 Sep 2012 10:00:09 -0400, Dave Angel wrote:

> On 09/05/2012 09:19 AM, Franck Ditter wrote:
>> Thanks to all, but :
>> - I should have said that I work with Python 3. Does that matter ? -
>> May I reformulate the queston : "a is b" and "id(a) == id(b)"
>>   both mean : "a et b share the same physical address". Is that True ?
>> Thanks,
> 
> No, id() has nothing to do with physical address.  The Python language
> does not specify anything about physical addresses.  Some
> implementations may happen to use physical addresses, others arbitrary
> integers.  And they may reuse such integers, or not.  Up to the
> implementation.

True. In principle, some day there might be a version of Python that runs 
on some exotic quantum computer where the very concept of "physical 
address" is meaningless. Or some sort of peptide or DNA computer, where 
the calculations are performed via molecular interactions rather than by 
flipping bits in fixed memory locations.

But less exotically, Frank isn't entirely wrong. With current day 
computers, it is reasonable to say that any object has exactly one 
physical location at any time. In Jython, objects can move around; in 
CPython, they can't. But at any moment, any object has a specific 
location, and no other object can have that same location. Two objects 
cannot both be at the same memory address at the same time.

So, for current day computers at least, it is reasonable to say that 
"a is b" implies that a and b are the same object at a single location.

The second half of the question is more complex:

"id(a) == id(b)" *only* implies that a and b are the same object at the 
same location if they exist at the same time. If they don't exist at the 
same time, then you can't conclude anything.



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


Re: Comparing strings from the back?

2012-09-05 Thread Johannes Bauer
On 05.09.2012 16:30, Steven D'Aprano wrote:

> Since these are *completely different Ns*, you can't combine them to get 
> O(N**2 log N) as the overall algorithmic complexity. Doing so is sheer 
> nonsense. If you state it like this:

Yes, you are correct here.

> You are making unjustified assumptions about the distribution of letters 
> in the words. This might be a list of long chemical compounds where the 
> words typically differ only in their suffix. It might be a list of people 
> with titles:

Actually, I'm not. I'm stating exactly what assumptions I'm making to
get my calculation. I'm comparing *random* character strings or bitstrings.

You, on the other hand, are making vague assumptions which you do not
care for formalize and yet you claim that "the number of comparisons is
equally likely to be 1, 2, 3, ..., N. The average then is". Without any
explanation for this. At all.

> Herr Professor Frederick Schmidt
> Herr Professor Frederick Wagner
> ...

Is your assumtion that we're comparing words that have the common prefix
"Herr Professor Frederick "? Why don't you clearly state what you're
comparing. In the example you gave in the other thread you claimed "Note
that this average assumes the strings are completely random.", yet now
you're talking about specific word patterns.

> I have no idea why you think this program demonstrates anything about 
> string equality comparisons. What you are counting is not the average 
> number of comparisons for string equality, but the number of comparisons 
> when sorting. These are *completely different*, because sorting a list 
> does not require testing each string against every other string.

You're wrong. It's not counting the number of string comparisons, it's
counting the number of character comparisons. Which is exactly what
we're talking about in this thread, are we not? The sorting of the list
is just to show some example where lots of strings are compared.

>> So, interestingly, in this real-world case(tm), the complexity does not
>> scale with O(n). It actually goes down (which is probably due to the
>> limit amount of words of higher length).
> 
> I would guess that it probably has more to do with the ability of the 
> timsort algorithm to exploit local order within a list and avoid 
> performing comparisons.

Again, it's not counting the number of string comparisons. It's counting
the average number of character comparisons per string comparison. The
total amount of string comparisons has nothing to do with it.

>> In summary, let's please not debate "feelings" or such.
> 
> I have no idea what feelings you are referring to.

I'm referring to "the number of comparisons is equally likely to be 1,
2, 3, ..., N. The average then is" without any deduction or rationale.
Without any explanation or assumption.

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: is implemented with id ?

2012-09-05 Thread Dave Angel
On 09/05/2012 10:41 AM, Steven D'Aprano wrote:
> On Wed, 05 Sep 2012 10:00:09 -0400, Dave Angel wrote:
>
>> On 09/05/2012 09:19 AM, Franck Ditter wrote:
>>> Thanks to all, but :
>>> - I should have said that I work with Python 3. Does that matter ? -
>>> May I reformulate the queston : "a is b" and "id(a) == id(b)"
>>>   both mean : "a et b share the same physical address". Is that True ?
>>> Thanks,
>> No, id() has nothing to do with physical address.  The Python language
>> does not specify anything about physical addresses.  Some
>> implementations may happen to use physical addresses, others arbitrary
>> integers.  And they may reuse such integers, or not.  Up to the
>> implementation.
> True. In principle, some day there might be a version of Python that runs 
> on some exotic quantum computer where the very concept of "physical 
> address" is meaningless. Or some sort of peptide or DNA computer, where 
> the calculations are performed via molecular interactions rather than by 
> flipping bits in fixed memory locations.
>
> But less exotically, Frank isn't entirely wrong. With current day 
> computers, it is reasonable to say that any object has exactly one 
> physical location at any time. In Jython, objects can move around; in 
> CPython, they can't. But at any moment, any object has a specific 
> location, and no other object can have that same location. Two objects 
> cannot both be at the same memory address at the same time.
>
> So, for current day computers at least, it is reasonable to say that 
> "a is b" implies that a and b are the same object at a single location.

You're arguing against something i didn't say.  I only said that id()
doesn't promise to be a memory address.  i said nothing about what it
might mean if the "is" operator considers them the same.

> The second half of the question is more complex:
>
> "id(a) == id(b)" *only* implies that a and b are the same object at the 
> same location if they exist at the same time. If they don't exist at the 
> same time, then you can't conclude anything.
>
>
But by claiming that id() really means address, and that those addresses
might move during the lifetime of an object, then the fact that the id()
functions are not called simultaneously implies that one object might
move to where the other one used to be before the "move."

I don't claim to know the jython implementation.  But you're claiming
that id() means the address of the object, even in jython.  So if a
garbage collection can occur during the evaluation of the expression
   id(a) == id(b)

then the comparing of id()'s would be useless in jython.  Two distinct
objects could each be moved during evaluation, (very) coincidentally
causing the two to have the same addresses at the two times of
evaluation.  Or more likely, a single object could move to a new
location, rendering the comparison false.  Thus you have false positive
and false negative possible.

I think it much more likely that jython uses integer values for the id()
function, and not physical addresses.  I doubt they'd want a race condition.


-- 

DaveA

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


Re: Python Interview Questions

2012-09-05 Thread Ian Kelly
On Wed, Sep 5, 2012 at 8:34 AM, Chris Angelico  wrote:
> I wouldn't go that far. The 'name' parameter, I would expect, would be
> a constant.

The 'item' parameter, though, is probably not a constant, and it's
interpolated just the same.

> However, this strikes me as encouraging some really
> inefficient code, like iterating over all the rows in a table with N+1
> queries (one to get the length, then a separate query for each row).
> Plus, use of limit without order by is not guaranteed (although since
> this is specific to MySQL, it's unlikely you'll run into trouble - but
> PostgreSQL, with its MVCC storage system, frequently reorders rows in
> a table).

The lack of an ORDER BY is the least of the problems with that SQL.
He's also using LIMIT without OFFSET, so the only thing that the
'item' argument changes is how many rows are returned (all but one of
which are ignored), not which one is actually fetched.

It's a bit sad that these are touted as answers to interview
questions.  I wouldn't hire anybody who gave answers like these.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python Interview Questions

2012-09-05 Thread Chris Angelico
On Thu, Sep 6, 2012 at 1:22 AM, Ian Kelly  wrote:
> The lack of an ORDER BY is the least of the problems with that SQL.
> He's also using LIMIT without OFFSET, so the only thing that the
> 'item' argument changes is how many rows are returned (all but one of
> which are ignored), not which one is actually fetched.

No, he's using the two-arg form of LIMIT.

> It's a bit sad that these are touted as answers to interview
> questions.  I wouldn't hire anybody who gave answers like these.

The code does not work as posted; there are args missing from the
INSERT example, for, uhh, example. It makes it hard to evaluate the
quality of the code, in some places. I'm not sure what these posts are
supposed to be, but I hope they're not being held up as model answers
to interview questions. For a start, I can't find any sort of clear
questions.

Or is the code itself the question and "How would you improve this"?

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


Re: is implemented with id ?

2012-09-05 Thread Steven D'Aprano
On Wed, 05 Sep 2012 11:09:30 -0400, Dave Angel wrote:

> On 09/05/2012 10:41 AM, Steven D'Aprano wrote:
[...]
>> So, for current day computers at least, it is reasonable to say that "a
>> is b" implies that a and b are the same object at a single location.
> 
> You're arguing against something i didn't say. I only said that id()
> doesn't promise to be a memory address.  i said nothing about what it
> might mean if the "is" operator considers them the same.

I'm not arguing at all. I'm agreeing with you, but going into more detail.


>> The second half of the question is more complex:
>>
>> "id(a) == id(b)" *only* implies that a and b are the same object at the
>> same location if they exist at the same time. If they don't exist at
>> the same time, then you can't conclude anything.
>>
>>
> But by claiming that id() really means address,

I didn't actually say that. If you re-read Franck Ditter's previous post, 
he doesn't actually say that either.


> and that those addresses
> might move during the lifetime of an object, then the fact that the id()
> functions are not called simultaneously implies that one object might
> move to where the other one used to be before the "move."

Well, yes, but I expect that implementations where objects can move will 
not use memory addresses as IDs. They will do what Jython and IronPython 
do and use arbitrary numbers as IDs.

(Oh how I wish CPython hadn't used memory addresses as IDs.)


> I don't claim to know the jython implementation.  But you're claiming
> that id() means the address of the object, even in jython.

Good god no! I'm saying that, *if* a and b exist at the same time, *and* 
if id(a) == id(b), *then* a and b must be the same object and therefore 
at the same address. That doesn't mean that the ID is the address!


> I think it much more likely that jython uses integer values for the id()
> function, and not physical addresses.

That's exactly what it does. It appears to be a simple counter: each time 
you ask for an object's ID, it gets allocated the next value starting 
from 1, and values are never re-used.



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


Re: Comparing strings from the back?

2012-09-05 Thread Peter Otten
Oscar Benjamin wrote:

> On 5 September 2012 10:48, Peter Otten <__pete...@web.de> wrote:

>> def count_common(a, b):

[sorry for seriously broken implementation]

> This function will return 1 if the first character differs. It does not
> count the number of common characters but rather the more relevant
> quantity which is the number of comparisons required to decide if the
> strings are equal.

I remember stumbling over the non-zero frequency for len(word) but somehow 
plodded on with beautifying the broken results :(

def count_common(a, b):
"""
>>> count_common("alpha", "beta")
0
>>> count_common("", "")
0
>>> count_common("alpha", "argument")
1
>>> count_common("alpha", "alpha")
5
>>> count_common("alpha", "alphx")
4
"""
i = 0
for x, y in zip(a, b):
if x != y:
break
i += 1
return i


$ python3 reverse_compare2.py compare /usr/share/dict/words
499500 combinations
average common chars (head) 0.0535
average common chars (tail) 0.322
comparing every pair in a sample of 1000 8-char words
taken from '/usr/share/dict/words'

head
0: 477371 
1:  18310 **
2:   3191 
3:523 
4: 79 
5: 15 
6: 10 
7:  1 

tail
0: 385069 
1:  78742 
2:  26734 
3:   7462 *
4:   1297 
5:168 
6: 22 
7:  6 


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


Re: sockets,threads and interupts

2012-09-05 Thread Ramchandra Apte
On Wednesday, 5 September 2012 18:34:32 UTC+5:30, Chris Angelico  wrote:
> On Wed, Sep 5, 2012 at 10:54 PM, Ramchandra Apte  
> wrote:
> 
> > At least on Linux, if you kill a process using sockets, it takes about 10 
> > seconds for socket to be closed. A program should try to close all 
> > resources. OS'es may take a long time to close a unclosed socket 
> > automatically.
> 
> 
> 
> Err, that's not my experience. When a process terminates, its
> 
> resources are released promptly.

It is not guaranteed so a program shouldn't presume.
> 
> 
> 
> ChrisA

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


Re: sockets,threads and interupts

2012-09-05 Thread Ramchandra Apte
On Wednesday, 5 September 2012 21:29:12 UTC+5:30, Ramchandra Apte  wrote:
> On Wednesday, 5 September 2012 18:34:32 UTC+5:30, Chris Angelico  wrote:
> 
> > On Wed, Sep 5, 2012 at 10:54 PM, Ramchandra Apte  
> > wrote:
> 
> > 
> 
> > > At least on Linux, if you kill a process using sockets, it takes about 10 
> > > seconds for socket to be closed. A program should try to close all 
> > > resources. OS'es may take a long time to close a unclosed socket 
> > > automatically.
> 
> > 
> 
> > 
> 
> > 
> 
> > Err, that's not my experience. When a process terminates, its
> 
> > 
> 
> > resources are released promptly.
> 
> 
> 
> It is not guaranteed so a program shouldn't presume.
> 
> > 
> 
> > 
> 
> > 
> 
> > ChrisA

oops forgot my signature
---
Bragging rights (I belong an exclusive community of banned people): got banned 
on SO and #python-offtopic
Projects:http://code.google.com/p/py2c/ and http://code.google.com/p/uniqos 
(name may be changed to PyOS)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: sockets,threads and interupts

2012-09-05 Thread Bryan
loial wrote:
> I have threaded python script that uses sockets to monitor network ports.
>
> I want to ensure that the socket is closed cleanly in all circumstances. This 
> includes if the script is killed or interupted in some other way.
>
> As I understand it signal only works in the main thread, so how can I trap 
> interupts in my threaded class and always ensure I close the socket?

You may have various threads waiting in blocking calls, and I don't
think there's a good way to alert them. Closing sockets that other
threads may be waiting on is "probably unwise" according to Linux man
page on close(2).

Do you really need to worry about it? If your process is being
forcibly terminated you probably cannot do anything better than the OS
will do by default.

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


Re: Python Interview Questions

2012-09-05 Thread Dave Angel
On 09/05/2012 11:34 AM, Chris Angelico wrote:
> On Thu, Sep 6, 2012 at 1:22 AM, Ian Kelly  wrote:
>> The lack of an ORDER BY is the least of the problems with that SQL.
>> He's also using LIMIT without OFFSET, so the only thing that the
>> 'item' argument changes is how many rows are returned (all but one of
>> which are ignored), not which one is actually fetched.
> No, he's using the two-arg form of LIMIT.
>
>> It's a bit sad that these are touted as answers to interview
>> questions.  I wouldn't hire anybody who gave answers like these.
> The code does not work as posted; there are args missing from the
> INSERT example, for, uhh, example. It makes it hard to evaluate the
> quality of the code, in some places. I'm not sure what these posts are
> supposed to be, but I hope they're not being held up as model answers
> to interview questions. For a start, I can't find any sort of clear
> questions.
>
> Or is the code itself the question and "How would you improve this"?
>
> ChrisA

Skip ahead to about page 13 to get more traditional questions,  There,
many of the simplest questions have invalid answers, or confusing
explanations.

For example, on page 15, the question that says " ... if a list of words
is empty..."   uses a=""   as its source data to test with.

The first question on page 16 forgets to construct a loop, thus
processing only the first line in the file.

page 18 introduces new syntax to the language:
 print n+=1  ##will work

and reassures us in the comment that it will work !!

page 18 also claims that values are passed to function by value.





-- 

DaveA

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


Re: how can i register the non-default browser with the webbrowser module?

2012-09-05 Thread Peter Otten
Levi Nie wrote:

> how can i register the non-default browser with the webbrowser module?
> 
> the case:
> i want open a site such as "google.com" in ie8 with the python.But my
> default is chrome.
> so i want to register a ie8 controller with the
> webbrowser.register(*name*, *constructor*[, *instance*]).
> so what does the parameter "constructor" "instance" mean?
> how can i do it?

Isn't there already a controller for ie8? I can't check, but you can list 
the available browsers with

>>> import webbrowser
>>> list(webbrowser._browsers)
['x-www-browser', 'kfmclient', 'firefox', 'konqueror']

Then if you want to open a page with a specific browser just do

url = "http://www.python.org";
browser = "firefox"
webbrowser.get(browser).open(url)


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


Re: Comparing strings from the back?

2012-09-05 Thread Steven D'Aprano
On Wed, 05 Sep 2012 16:51:10 +0200, Johannes Bauer wrote:
[...]
>> You are making unjustified assumptions about the distribution of
>> letters in the words. This might be a list of long chemical compounds
>> where the words typically differ only in their suffix. It might be a
>> list of people with titles:
> 
> Actually, I'm not. I'm stating exactly what assumptions I'm making to
> get my calculation. I'm comparing *random* character strings or
> bitstrings.

Excuse me, you are not. You are comparing English words which are highly 
non-random.


> You, on the other hand, are making vague assumptions which you do not
> care for formalize and yet you claim that "the number of comparisons is
> equally likely to be 1, 2, 3, ..., N. The average then is". Without any
> explanation for this. At all.

I will accept that my explanation was not good enough, but I strongly 
disagree that I gave no explanation at all.


>> Herr Professor Frederick Schmidt
>> Herr Professor Frederick Wagner
>> ...
> 
> Is your assumtion that we're comparing words that have the common prefix
> "Herr Professor Frederick "? 

No, I am pointing out that *your* assumption that most string comparisons 
will halt close to the beginning of the string is an invalid assumption. 
Your assumption only holds for some non-random strings.


[...]
>> I have no idea why you think this program demonstrates anything about
>> string equality comparisons. What you are counting is not the average
>> number of comparisons for string equality, but the number of
>> comparisons when sorting. These are *completely different*, because
>> sorting a list does not require testing each string against every other
>> string.
> 
> You're wrong. It's not counting the number of string comparisons, 

I didn't say it was. 


> it's counting the number of character comparisons.

Correct. But only out of an extremely limited subset of all possible 
string comparisons, namely those very few that happen when sorting lists 
of English words using a very specific algorithm, namely timsort.


> Which is exactly what
> we're talking about in this thread, are we not? The sorting of the list
> is just to show some example where lots of strings are compared.

It is not good enough to extract a non-random subset of strings (only 
English words) and then decrease the data set even further by only 
comparing an extremely non-uniform subset of those strings: specifically 
those few string comparisons that happen to occur using timsort.

Whatever figure you have calculated by taking this non-random selection, 
it is irrelevant to the question of the average performance of string 
equality given random strings.



>>> So, interestingly, in this real-world case(tm), the complexity does
>>> not scale with O(n). It actually goes down (which is probably due to
>>> the limit amount of words of higher length).
>> 
>> I would guess that it probably has more to do with the ability of the
>> timsort algorithm to exploit local order within a list and avoid
>> performing comparisons.
> 
> Again, it's not counting the number of string comparisons. It's counting
> the average number of character comparisons per string comparison. The
> total amount of string comparisons has nothing to do with it.

I didn't say anything about counting string comparisons. But you are 
wrong -- the numbers you get are *strongly* influenced by the number of 
string comparisons performed. That is just one of the reasons why the 
results you get are biased.

Let me spell it out for you: given a list of five letter words:

['fruit', 'apple', 'claim', 'pears', ... , 'toast']

sorting the list may compare:

'fruit' with 'apple'
'apple' with 'claim'

but almost certainly will not compare:

'apple' with 'toast'

and it definitely won't compare:

'zzzax' with 'zzzaq'

because strings like those never get into the list in the first place.

For the sake of simple calculations, let's pretend that there are only 
1000 five-letter strings possible. We want to know how many character-
comparisons are done on average when testing two random five-letter 
strings for equality. To calculate this average, you must compare every 
string to every other string, *including* itself.

This gives 1000*1000 = one million equality tests to be performed. For 
each equality test, we count the number of character comparisons 
performed, sum all those counts, and divide by 1e6. That is the average 
number of char comparisons for random strings of five letters.

But that's not what you do. First you eliminate 900 out of the 1000 
possible strings by only sampling English words -- strings like "xxoij" 
cannot possibly be selected. So you are left with the highly non-random 
subset of 1 equality tests.

But you haven't finished. Instead of checking all 1 equality tests, 
you then decide to only check the 2000 tests that happen to randomly 
occur when using the timsort algorithm to sort a list.

So from the population of one million possible equality 

Re: Python Interview Questions

2012-09-05 Thread Roy Smith
In article ,
 charvigro...@gmail.com wrote:

> Hi Guys,
> 
> Finally I have decided to put best interview question and answers.
> 
> Please visit http://www.f2finterview.com/web/CorePython/ for core python and 
> http://www.f2finterview.com/web/PythonAdvanced/ for advanced python

I was going to comment on some of the specific items, but I got hung up 
being unable to copy-paste text from your site so I could quote it.  
That's usually done with some variation on "user-select: none" in the 
CSS, but I didn't see that.  I'm assuming it's some javascript trickery.

Why do you do that?  It degrades the usability of the site, and doesn't 
provide any real protection against people stealing content.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how can i register the non-default browser with the webbrowser module?

2012-09-05 Thread Mark Lawrence

On 05/09/2012 15:32, Levi Nie wrote:

how can i register the non-default browser with the webbrowser module?

the case:
i want open a site such as "google.com" in ie8 with the python.But my
default is chrome.
so i want to register a ie8 controller with the webbrowser.register(*name*,
*constructor*[, *instance*]).
so what does the parameter "constructor" "instance" mean?
how can i do it?





Have you read the documentation at all?  It clearly states "This entry 
point is only useful if you plan to either set the BROWSER variable or 
call get() with a nonempty argument matching the name of a handler you 
declare."  Is this what you plan to do in your code?


--
Cheers.

Mark Lawrence.

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


Re: Extract Text Table From File

2012-09-05 Thread Tim Chase
[trimming out a bunch of superfluous text so the thread is actually
readable]

On 09/05/12 08:08, Ramchandra Apte wrote:
> On Monday, 27 August 2012 15:42:14 UTC+5:30, Laszlo Nagy  wrote:
>> On 2012-08-27 11:53, Huso wrote:
>>> I am trying to extract some text table data from a log file
>>
>> fin = open("test.txt","r")
>>
>> for line in fin:
>>
>>  # This is one possible way to extract values.
>>
>>  values = line.strip().split()
>>
>>  print values
>
> the csv module should be used for this not regex

The problem is that the csv module expects a single delimiter
character, not columnar data.

-tkc


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


Re: is implemented with id ?

2012-09-05 Thread Tim Chase
On 09/05/12 08:46, Dave Angel wrote:
> It's id() which is superfluous.  But it's useful for debugging,
> and for understanding.

While I assiduously work to eschew shadowing most built-in names
such as "list" or "str", I do make an exception for "id" because
it's *so* useful in code, and the built-in nets me almost nothing
(well, nothing that I generally care about) that "is" doesn't
already provide me.

-tkc


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


Re: Python Interview Questions

2012-09-05 Thread Ian Kelly
On Wed, Sep 5, 2012 at 9:34 AM, Chris Angelico  wrote:
> On Thu, Sep 6, 2012 at 1:22 AM, Ian Kelly  wrote:
>> The lack of an ORDER BY is the least of the problems with that SQL.
>> He's also using LIMIT without OFFSET, so the only thing that the
>> 'item' argument changes is how many rows are returned (all but one of
>> which are ignored), not which one is actually fetched.
>
> No, he's using the two-arg form of LIMIT.

My mistake.  I didn't even know there was a two-arg form of LIMIT.
Must be a MySQL thing. :-)

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


Re: Python Interview Questions

2012-09-05 Thread Roy Smith
In article ,
 Ian Kelly  wrote:

> It's a bit sad that these are touted as answers to interview
> questions.  I wouldn't hire anybody who gave answers like these.

Over time, I've become convinced that most interview questions are crap.  
The best programming interview questions always start with, "write a 
program ...".
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python Interview Questions

2012-09-05 Thread Roy Smith
In article ,
 Ian Kelly  wrote:

> My mistake.  I didn't even know there was a two-arg form of LIMIT.
> Must be a MySQL thing. :-)

What are you talking about?  SQL is an ISO Standard.  Therefore, all 
implementations work the same way.  Didn't you get the memo?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: is implemented with id ?

2012-09-05 Thread Hans Mulder
On 5/09/12 17:09:30, Dave Angel wrote:
> But by claiming that id() really means address, and that those addresses
> might move during the lifetime of an object, then the fact that the id()
> functions are not called simultaneously implies that one object might
> move to where the other one used to be before the "move."

Whoa!  Not so fast!  The id() of an object is guaranteed to not
change during the object's lifetime.  So if an implementation
moves objects around (e.g. Jython), then it cannot use memory
addresses for the id() function.

> I think it much more likely that jython uses integer values for
> the id() function, and not physical addresses.

The id() function is guaranteed to return some flavour of integer.

In Jython, the return values are 1, 2, 3, 4, etc., except, of course,
if you invoke id() on an object you've id'd before, you get the same
number as before.

In current versions of CPython, you do get the (virtual) memory
address, converted to an int (or a long).  But then, CPython does
not move objects.

Maybe the next version of CPython should shift id values two or three
bits to the right, just to make sure people don't misinterpret ids as
memory addresses.


Hope this helps,

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


Re: is implemented with id ?

2012-09-05 Thread Ian Kelly
On Wed, Sep 5, 2012 at 8:13 AM, Steven D'Aprano
 wrote:
> You *cannot* replace is with id() except when the objects are guaranteed
> to both be alive at the same time, and even then you *shouldn't* replace
> is with id() because that is a pessimation (the opposite of an
> optimization -- something that makes code run slower, not faster).

Shouldn't that be "pessimization" for symmetry?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: is implemented with id ?

2012-09-05 Thread Dave Angel
On 09/05/2012 12:47 PM, Hans Mulder wrote:
> On 5/09/12 17:09:30, Dave Angel wrote:
>> But by claiming that id() really means address, and that those addresses
>> might move during the lifetime of an object, then the fact that the id()
>> functions are not called simultaneously implies that one object might
>> move to where the other one used to be before the "move."
> Whoa!  Not so fast!  The id() of an object is guaranteed to not
> change during the object's lifetime.  So if an implementation
> moves objects around (e.g. Jython), then it cannot use memory
> addresses for the id() function.
Which is equivalent to my point.  I had mistakenly thought that Steven
was claiming it was always an address, and disproving that claim by what
amounts to reductio ad absurdem.

>> I think it much more likely that jython uses integer values for
>> the id() function, and not physical addresses.
> The id() function is guaranteed to return some flavour of integer.
>
> In Jython, the return values are 1, 2, 3, 4, etc., except, of course,
> if you invoke id() on an object you've id'd before, you get the same
> number as before.
>
> In current versions of CPython, you do get the (virtual) memory
> address, converted to an int (or a long).  But then, CPython does
> not move objects.
>
> Maybe the next version of CPython should shift id values two or three
> bits to the right, just to make sure people don't misinterpret ids as
> memory addresses.
>
>

I think i'd prefer if it would put it through one step of a CRC32.

-- 

DaveA

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


Re: HTMLParser skipping HTML? [newbie]

2012-09-05 Thread BobAalsma
Op woensdag 5 september 2012 14:57:05 UTC+2 schreef BobAalsma het volgende:
> I'm trying to understand the HTMLParser so I've copied some code from 
> http://docs.python.org/library/htmlparser.html?highlight=html#HTMLParser and 
> tried that on my LinkedIn page.
> 
> No errors, but some of the tags seem to go missing for no apparent reason - 
> any advice?
> 
> I have searched extensively for this, but seem to be the only one with 
> missing data from HTMLParser :(
> 
> 
> 
> Code:
> 
> import urllib2
> 
> from HTMLParser import HTMLParser
> 
> 
> 
> from GetHttpFileContents import getHttpFileContents
> 
> 
> 
> # create a subclass and override the handler methods
> 
> class MyHTMLParser(HTMLParser):
> 
>   def handle_starttag(self, tag, attrs):
> 
>   print "Start tag:\n\t", tag
> 
>   for attr in attrs:
> 
>   print "\t\tattr:", attr
> 
>   # end for attr in attrs:
> 
>   #
> 
>   def handle_endtag(self, tag):
> 
>   print "End tag :\n\t", tag
> 
>   #
> 
>   def handle_data(self, data):
> 
>   if data != '\n\n':
> 
>   if data != '\n':
> 
>   print "Data :\t\t", data
> 
>   # end if 1
> 
>   # end if 2
> 
>   #
> 
> #
> 
> # -
> 
> #
> 
> def removeHtmlFromFileContents():
> 
>   TextOut = ''
> 
> 
> 
>   parser = MyHTMLParser()
> 
>   
> parser.feed(urllib2.urlopen('http://nl.linkedin.com/in/bobaalsma').read())
> 
> 
> 
>   return TextOut
> 
> #
> 
> # -
> 
> #
> 
> if __name__ == '__main__':
> 
>   TextOut = removeHtmlFromFileContents()
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> Part of the output:
> 
> End tag :
> 
>   script
> 
> Start tag:
> 
>   title
> 
> Data :Bob Aalsma - Nederland | LinkedIn
> 
> End tag :
> 
>   title
> 
> Start tag:
> 
>   script
> 
>   attr: ('type', 'text/javascript')
> 
>   attr: ('src', 
> 'http://www.linkedin.com/uas/authping?url=http%3A%2F%2Fnl%2Elinkedin%2Ecom%2Fin%2Fbobaalsma')
> 
> End tag :
> 
>   script
> 
> Start tag:
> 
>   link
> 
>   attr: ('rel', 'stylesheet')
> 
>   attr: ('type', 'text/css')
> 
>   attr: ('href', 
> 'http://s3.licdn.com/scds/concat/common/css?h=5v4lkweptdvona6w56qelodrj-7pfvsr76gzb22ys278pbj80xm-b1io9ndljf1bvpack85gyxhv4-5xxmkfcm1ny97biv0pwj7ch69')
> 
> Start tag:
> 
>   script
> 
>   attr: ('type', 'text/javascript')
> 
>   attr: ('src', 
> 'http://s4.licdn.com/scds/concat/common/js?h=7nhn6ycbvnz80dydsu88wbuk-1kjdwxpxv0c3z97afuz9dlr9g-dlsf699o6xkxgppoxivctlunb-8v6o0480wy5u6j7f3sh92hzxo')
> 
> End tag :
> 
>   script
> 
> End tag :
> 
>   head
> 
> 
> 
> 
> 
> 
> 
> But the source text for this is [and all of the " seem to go 
> missing:
> 
> 
> 
> Bob Aalsma | LinkedIn
> 
>  href="https://s3-s.licdn.com/scds/concat/common/css?h=7d22iuuoi1bmp3a2jb6jyv5z5";>
> 
>  href="https://s4-s.licdn.com/scds/concat/common/css?h=b1io9ndljf1bvpack85gyxhv4-6qrj4gxbwq8loasfnyfmyuphe-dhog2e5h8scik4whkpqccnzou-dmo1gwj6nlhvdvzx7rmluambv-69sgyia02rmcjmco0t9d3xpvo";>
> 
> 
> 
> 
> 
> 
> 
> 
> 
>  content="/profile/view?id=24198692&authType=name&authToken=KhOG">
> 
> 

Hmm, OK, Peter, thanks. I didn't consider the effect of logging in, that could 
certainly be a reason. So how could I have the script log in?

[Didn't understand the bit about the kittens, though. How about that?]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: HTMLParser skipping HTML? [newbie]

2012-09-05 Thread BobAalsma
Op woensdag 5 september 2012 19:23:45 UTC+2 schreef BobAalsma het volgende:
> Op woensdag 5 september 2012 14:57:05 UTC+2 schreef BobAalsma het volgende:
> 
> > I'm trying to understand the HTMLParser so I've copied some code from 
> > http://docs.python.org/library/htmlparser.html?highlight=html#HTMLParser 
> > and tried that on my LinkedIn page.
> 
> > 
> 
> > No errors, but some of the tags seem to go missing for no apparent reason - 
> > any advice?
> 
> > 
> 
> > I have searched extensively for this, but seem to be the only one with 
> > missing data from HTMLParser :(
> 
> > 
> 
> > 
> 
> > 
> 
> > Code:
> 
> > 
> 
> > import urllib2
> 
> > 
> 
> > from HTMLParser import HTMLParser
> 
> > 
> 
> > 
> 
> > 
> 
> > from GetHttpFileContents import getHttpFileContents
> 
> > 
> 
> > 
> 
> > 
> 
> > # create a subclass and override the handler methods
> 
> > 
> 
> > class MyHTMLParser(HTMLParser):
> 
> > 
> 
> > def handle_starttag(self, tag, attrs):
> 
> > 
> 
> > print "Start tag:\n\t", tag
> 
> > 
> 
> > for attr in attrs:
> 
> > 
> 
> > print "\t\tattr:", attr
> 
> > 
> 
> > # end for attr in attrs:
> 
> > 
> 
> > #
> 
> > 
> 
> > def handle_endtag(self, tag):
> 
> > 
> 
> > print "End tag :\n\t", tag
> 
> > 
> 
> > #
> 
> > 
> 
> > def handle_data(self, data):
> 
> > 
> 
> > if data != '\n\n':
> 
> > 
> 
> > if data != '\n':
> 
> > 
> 
> > print "Data :\t\t", data
> 
> > 
> 
> > # end if 1
> 
> > 
> 
> > # end if 2
> 
> > 
> 
> > #
> 
> > 
> 
> > #
> 
> > 
> 
> > # -
> 
> > 
> 
> > #
> 
> > 
> 
> > def removeHtmlFromFileContents():
> 
> > 
> 
> > TextOut = ''
> 
> > 
> 
> > 
> 
> > 
> 
> > parser = MyHTMLParser()
> 
> > 
> 
> > 
> > parser.feed(urllib2.urlopen('http://nl.linkedin.com/in/bobaalsma').read())
> 
> > 
> 
> > 
> 
> > 
> 
> > return TextOut
> 
> > 
> 
> > #
> 
> > 
> 
> > # -
> 
> > 
> 
> > #
> 
> > 
> 
> > if __name__ == '__main__':
> 
> > 
> 
> > TextOut = removeHtmlFromFileContents()
> 
> > 
> 
> > 
> 
> > 
> 
> > 
> 
> > 
> 
> > 
> 
> > 
> 
> > 
> 
> > 
> 
> > 
> 
> > 
> 
> > Part of the output:
> 
> > 
> 
> > End tag :
> 
> > 
> 
> > script
> 
> > 
> 
> > Start tag:
> 
> > 
> 
> > title
> 
> > 
> 
> > Data :  Bob Aalsma - Nederland | LinkedIn
> 
> > 
> 
> > End tag :
> 
> > 
> 
> > title
> 
> > 
> 
> > Start tag:
> 
> > 
> 
> > script
> 
> > 
> 
> > attr: ('type', 'text/javascript')
> 
> > 
> 
> > attr: ('src', 
> > 'http://www.linkedin.com/uas/authping?url=http%3A%2F%2Fnl%2Elinkedin%2Ecom%2Fin%2Fbobaalsma')
> 
> > 
> 
> > End tag :
> 
> > 
> 
> > script
> 
> > 
> 
> > Start tag:
> 
> > 
> 
> > link
> 
> > 
> 
> > attr: ('rel', 'stylesheet')
> 
> > 
> 
> > attr: ('type', 'text/css')
> 
> > 
> 
> > attr: ('href', 
> > 'http://s3.licdn.com/scds/concat/common/css?h=5v4lkweptdvona6w56qelodrj-7pfvsr76gzb22ys278pbj80xm-b1io9ndljf1bvpack85gyxhv4-5xxmkfcm1ny97biv0pwj7ch69')
> 
> > 
> 
> > Start tag:
> 
> > 
> 
> > script
> 
> > 
> 
> > attr: ('type', 'text/javascript')
> 
> > 
> 
> > attr: ('src', 
> > 'http://s4.licdn.com/scds/concat/common/js?h=7nhn6ycbvnz80dydsu88wbuk-1kjdwxpxv0c3z97afuz9dlr9g-dlsf699o6xkxgppoxivctlunb-8v6o0480wy5u6j7f3sh92hzxo')
> 
> > 
> 
> > End tag :
> 
> > 
> 
> > script
> 
> > 
> 
> > End tag :
> 
> > 
> 
> > head
> 
> > 
> 
> > 
> 
> > 
> 
> > 
> 
> > 
> 
> > 
> 
> > 
> 
> > But the source text for this is [and all of the " seem to go 
> > missing:
> 
> > 
> 
> > 
> 
> > 
> 
> > Bob Aalsma | LinkedIn
> 
> > 
> 
> >  > href="https://s3-s.licdn.com/scds/concat/common/css?h=7d22iuuoi1bmp3a2jb6jyv5z5";>
> 
> > 
> 
> >  > href="https://s4-s.licdn.com/scds/concat/common/css?h=b1io9ndljf1bvpack85gyxhv4-6qrj4gxbwq8loasfnyfmyuphe-dhog2e5h8scik4whkpqccnzou-dmo1gwj6nlhvdvzx7rmluambv-69sgyia02rmcjmco0t9d3xpvo";>
> 
> > 
> 
> > 
> 
> > 
> 
> > 
> 
> > 
> 
> > 
> 
> > 
> 
> > 
> 
> > 
> 
> >  > content="/profile/view?id=24198692&authType=name&authToken=KhOG">
> 
> > 
> 
> > 
> 
> 
> 
> Hmm, OK, Peter, thanks. I didn't consider the effect of logging in, that 
> could certainly be a reason. So how could I have the script log in?
> 
> 
> 
> [Didn't understand the bit about the kittens, though. How about that?]

Oops, sorry, found that bit about logging in - asked too soon; still wonder 
about the kittens ;)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python docs search for 'print'

2012-09-05 Thread Grant Edwards
On 2012-09-05, Terry Reedy  wrote:
> On 9/4/2012 11:22 PM, Ramchandra Apte wrote:
>
>> I was actually planning to write a bug on this.
>
> If you do, find the right place to submit it.
> bugs.python.org is for issues relating to the cpython repository.'
> I fairly sure that the website search code is not there.
>
> If you do find the right place, you should contribute something to an
> improvement. The current search performance is not a secret, so mere 
> complaints are useless.

Making the site's "search" box use Google or somesuch is probably the
simplest solution. I'm not enough of a web guy to know how to do
that, but I do know that some sites do handle site search that way.

-- 
Grant Edwards   grant.b.edwardsYow! I like the way ONLY
  at   their mouths move ...  They
  gmail.comlook like DYING OYSTERS
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: HTMLParser skipping HTML? [newbie]

2012-09-05 Thread Peter Otten
BobAalsma wrote:

> [Didn't understand the bit about the kittens, though. How about that?]
> 
> Oops, sorry, found that bit about logging in - asked too soon; still
> wonder about the kittens ;)

I just wanted to tell you not to mark the end of an if-suite with an "# end 
if" comment. As soon as you become familiar with the language that will look 
like noise that detracts from the actual code.

In an attempt to make this advice appear less patronizing I wrapped it into 
a lame joke by alluding to

http://en.wikipedia.org/wiki/Every_time_you_masturbate..._God_kills_a_kitten

Sorry for the confusion -- I hope you aren't offended.

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


Re: python docs search for 'print'

2012-09-05 Thread Dave Angel
On 09/05/2012 01:47 PM, Grant Edwards wrote:
> On 2012-09-05, Terry Reedy  wrote:
>> On 9/4/2012 11:22 PM, Ramchandra Apte wrote:
>>
>>> I was actually planning to write a bug on this.
>> If you do, find the right place to submit it.
>> bugs.python.org is for issues relating to the cpython repository.'
>> I fairly sure that the website search code is not there.
>>
>> If you do find the right place, you should contribute something to an
>> improvement. The current search performance is not a secret, so mere 
>> complaints are useless.
> Making the site's "search" box use Google or somesuch is probably the
> simplest solution. I'm not enough of a web guy to know how to do
> that, but I do know that some sites do handle site search that way.
>
And google has some API's to make it relatively painless.  And a license
form to fill in and send, along with your check.




-- 

DaveA

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


Re: python docs search for 'print'

2012-09-05 Thread Grant Edwards
On 2012-09-05, Dave Angel  wrote:
> On 09/05/2012 01:47 PM, Grant Edwards wrote:
>
>> Making the site's "search" box use Google or somesuch is probably the
>> simplest solution. I'm not enough of a web guy to know how to do
>> that, but I do know that some sites do handle site search that way.
>>
> And google has some API's to make it relatively painless.  And a
> license form to fill in and send, along with your check.

I just saw the posting mentioning the pricing.  So it is a simple
simple solution, but it's probably not cheap enough...

-- 
Grant Edwards   grant.b.edwardsYow! Yes, but will I
  at   see the EASTER BUNNY in
  gmail.comskintight leather at an
   IRON MAIDEN concert?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: is implemented with id ?

2012-09-05 Thread Terry Reedy

On 9/5/2012 8:48 AM, Ramchandra Apte wrote:


Seeing this thread, I think the is statment should be removed.
It has a replacement syntax of id(x) == id(y)


The thread is wrong then.

If the implementation reuses ids, which CPython does,
 is 
must be implemented as

internal-tem1 = 
internal-tem2 = 
id(internal-tem1) == id(internal-tem2)

in order to ensure that the two objects exist simultaneously,
so that the id comparison is valid.

> and "a==True" should be automatically changed into memory comparison.

I have no idea what that means.

--
Terry Jan Reedy

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


Re: is implemented with id ?

2012-09-05 Thread Terry Reedy

On 9/5/2012 10:41 AM, Steven D'Aprano wrote:


True. In principle, some day there might be a version of Python that runs
on some exotic quantum computer where the very concept of "physical
address" is meaningless.


You mean like the human brain? When people execute Python code, does 0 
have an address?


--
Terry Jan Reedy

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


Re: is implemented with id ?

2012-09-05 Thread Dave Angel
On 09/05/2012 02:27 PM, Terry Reedy wrote:
> On 9/5/2012 8:48 AM, Ramchandra Apte wrote:
>
>> Seeing this thread, I think the is statment should be removed.
>> It has a replacement syntax of id(x) == id(y)
>
> The thread is wrong then.
>
> If the implementation reuses ids, which CPython does,
>  is 
> must be implemented as
>
> internal-tem1 = 
> internal-tem2 = 
> id(internal-tem1) == id(internal-tem2)
>
> in order to ensure that the two objects exist simultaneously,
> so that the id comparison is valid.
>
> > and "a==True" should be automatically changed into memory comparison.
>
> I have no idea what that means.
>

It's probably a response to Steve's comment

"""

In general, you almost never need to care about IDs and object identity. 
The main exception is testing for None, which should always be written as:

if x is None
"""

 Somehow he substituted True for None.  Anyway, if one eliminates "is"
then Steve's comment wouldn't apply.

-- 

DaveA

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


Mailergate (was: python docs search for 'print')

2012-09-05 Thread Thomas 'PointedEars' Lahn
Stephen D'Aprano wrote:

> On Tue, 04 Sep 2012 20:27:38 +0200, Thomas 'PointedEars' Lahn wrote:
>> ¹  The other mess they created (or allowed to be created) is this mashup
>>of newsgroup and mailing list, neither of which works properly,
> 
> In what way do they not work properly?

Most prominently, threads are completely and utterly borken.

>>because the underlying protocols are not compatible.
> 
> What?
> 
> That is rather like saying that you can't read email via a web interface
> because the http protocol is not compatible with the smtp protocol.

Apples and oranges.  The problem is gating messages from a mail server to a 
news server and vice-versa without regard to the differences between the 
underlying protocols.

Netnews User Agents (NUAs, newsreaders), are currently based on [RFC3977] 
and [RFC5536].

In a Netnews article, a References header field is mandatory for a posting 
that is a follow-up.  (Threading by Subject and Date works poorly, if at 
all, so the Specification does not suggest that.)  The last element of the 
References header field value has to be a Message-ID specifiying the 
article's precursor.  That Message-ID has to match the Message-ID header 
field value of an existing posting, unless it has expired on the target 
newsserver or was canceled (with Supersedes being a special case).  The
In-Reply-To header field (see below) is not allowed there, but it is set by 
some hybrid MUA/NUAs like Mozilla Thunderbird anyway¹.

Mail User Agents (MUAs, mailreaders), on the other hand, are currently based 
on [RFC5321], [RFC1939], IMAP4 (various RFCs, starting with [RFC1730]), and 
last but not least [RFC5322].

There are two possible header fields to build a thread of e-mail messages: 
In-Reply-To, and References.  Whereas the first header field's value is 
supposed to be a Message-ID and the second one's as described in [RFC5536].  
Few MUAs set both, some set the first one, and many set none of them at all, 
because there is no absolute requirement to set any of them (see [RFC5322], 
section 3.6.4.)

And then there is utterly borken software – or shall we say utterly borken 
approaches?  Consider for example the recent thread with Subject "simple 
client data base" started by Mark R Rivet.  The original posting has:

| User-Agent: ForteAgent/7.00.32.1200

(posted using a newsreader)

| […]
| Message-ID: 

Chris Angelico's follow-up to that has

| In-Reply-To: 
| References: 
| […]
| Message-ID: 
| […]
| X-Mailman-Version: 2.1.15

(apparently posted using a mailreader, gated by python.org's mail software)

So far, so good.  But Peter Otten's follow-up to Chris Angelico's posting 
has

| References: 
|  
| […]
| User-Agent: KNode/4.7.3   

(posted using a newsreader)

| […]
| Message-ID: 

As you can see, the Message-ID of Chris' posting does not occur in the 
References header field value of Peter's posting, which is caused by 
python.org's SMTP-to-NNTP gating program to set its own Message-ID, ignoring 
the Message-ID of the server where the message was injected.  Therefore, 
although it is a followup to Chris' posting, Peter's posting has no 
*technical* (metadata) relation to Chris' posting.

Instead, it should have

| References: 
|  
| […]

or, better: Chris' posting should have had the original

| […]
| Message-ID: 
|   
| […]

(no word-wrap), then the header fields of Peter's posting can stay as they 
are.

My newsreader (KNode/4.4.11) tries its best to resolve this (short of 
threading by Subject and Date, which does not work; see above) which causes 
Peter's posting to end up as a follow-up to *Mark's* posting instead 
(specified by the only valid Message-ID in the References header).  Only 
when you read Peter's posting you realize that it is not a follow-up to 
Mark's at all.  Confusion ensues.

There are a lot of similar examples here.  As a result of the Message-ID 
rewriting, in several cases a follow-up even appears as if it was an 
original posting, without any technical (and therefore without any obvious 
visual) relation to the thread it actually belongs to at all, even though 
the precursor has not expired.  For example,

| […]
| X-Original-To: python-list@python.org
| Delivered-To: python-l...@mail.python.org
| […]
| In-Reply-To: <50464153.5090...@gmail.com>
   
| References: <50464153.5090...@gmail.com>
  
| Date: Tue, 4 Sep 2012 14:27:35 -0400
| Subject: Re: python docs search for 'print'
| From: Joel Goldstick 
| To: David Hoese 
| Content-Type: text/plain; charset=UTF-8
| Cc: python-list@python.org
| […]
| Newsgroups: comp.lang.python
| Message-ID: 
| […]
| 
| On Tue, Sep 4, 2012 at 1:58 PM, David Hoese  wrote:
| > […]

There is no message with Message-ID <50464153.5090...@gmail.com> (at least 
not on the newsserver that I use), because that header field value was 
overwritten by the borken gating software that python.org uses.  The actual 
message posted by that software

Re: python docs search for 'print'

2012-09-05 Thread Terry Reedy

On 9/5/2012 8:45 AM, Ramchandra Apte wrote:

On Wednesday, 5 September 2012 15:03:56 UTC+5:30, Terry Reedy  wrote:

On 9/5/2012 1:22 AM, Ramchandra Apte wrote:


On Wednesday, 5 September 2012 09:35:43 UTC+5:30, Terry Reedy  wrote:





If you do find the right place, you should contribute something to an



improvement. The current search performance is not a secret, so mere



complaints are useless.


These ever increasing extra blank lines with each quote are obnoxious. 
Consider using a news reader with news.gmane.org instead of google crap.

Or snip heavily.


Google site search costs 2000$ for 500,000 searches per year and 750$ for 
150,000 searches so its quite expensive.
Also the print function only comes in the third result (python 3.2)
if you search for "site:docs.python.org/release/3.2 print" the print function 
is not found at all.
I think a specialized algorithm would work better.
I'm going to code an program for this.


A simple algorithm would be to present index search results first, if 
there are any, and then page search results.


Then searching print would return
"Index entries for print:"
  Builtin-functions page
  a couple of others...

Pages containing print:
  

I would not worry about duplication.

Labeling index results as such would clue people in to the fact that 
they could have looked for the object name in the index. People names 
like 'Lundh' that are not indexed but which appear on several pages 
would give the same result as before.


Looking at the web page (which I do not normally use), I see that the 
problem is deeper. The left margin of every page have an inviting "Quick
search" box with text "Enter search terms or a module, class or function 
name." But it does not currently work very well for such object names. 
The index is only available from the main contents page.


This contrasts with the Windows docs which has an index tab, making the 
index directly available from *anywhere*. (There is also a separate text 
search tab.) I think an index search box should be added above the text 
search box. I will ask on pydev where the suggestion should go.


--
Terry Jan Reedy

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


Re: python docs search for 'print'

2012-09-05 Thread Walter Hurry
On Wed, 05 Sep 2012 15:03:16 -0400, Terry Reedy wrote:

> On 9/5/2012 8:45 AM, Ramchandra Apte wrote:


> These ever increasing extra blank lines with each quote are obnoxious.
> Consider using a news reader with news.gmane.org instead of google crap.
> Or snip heavily.

+1. And the duplicated posts. Enough of him. Bozo bin it is.

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


ctypes, strange structures of PKCS11

2012-09-05 Thread Cornelius Kölbel
Hi there,

I am trying to use a pkcs11 library (with python 2.7) and address this
library with ctypes.
Alas, I am neither the python black belt guru and C is not my preferred
language.

Till now, I do not want to use pykcs11, since I want to keep my
dependencies low.

I initialized the library, logged in to the token and got a session
(self.hSession).

Now I try to create an AES key using C_CreateKey.

--snip--
def createAES(self, ks=32):
rv=0
mechanism = CK_MECHANISM(CKM_AES_KEY_GEN, NULL, 0)
print "Mech:",mechanism.mechanism
print "Mech:",mechanism.pParameter
print "Mech:",mechanism.usParameterLen
   
keysize = c_ulong(ks)
klass = CKO_SECRET_KEY
keytype = CKK_AES
label = "testAES"
ck_true = c_ubyte(1)
ck_false = c_ubyte(0)
objHandle = CK_OBJECT_HANDLE()
   
size=7

CK_TEMPLATE = CK_ATTRIBUTE * 6
   
template =  CK_TEMPLATE( 
CK_ATTRIBUTE(CKA_KEY_TYPE, c_void_p(keytype),0),
CK_ATTRIBUTE(CKA_LABEL, cast( label, c_void_p),
len( label )),
CK_ATTRIBUTE(CKA_VALUE_LEN,
cast(byref(keysize),c_void_p), sizeof(keysize) ),
CK_ATTRIBUTE(CKA_PRIVATE, 
cast(byref(ck_false),c_void_p), sizeof(ck_false)),
CK_ATTRIBUTE(CKA_TOKEN, 
cast(byref(ck_true),c_void_p), sizeof(ck_true)),
CK_ATTRIBUTE(CKA_SENSITIVE,
cast(byref(ck_true),c_void_p), sizeof(ck_true))
)

template_len = c_ulong(size)
print "Template: ", template
print "Template: ", len(template)
print "Handle:", objHandle
print "Handle:", type(addressof(objHandle))
rv = self.etpkcs11.C_GenerateKey(self.hSession,
 addressof(mechanism),
 addressof(template),
 template_len,
 objHandle)
print "rv=",rv  
print "handle=",objHandle
   
if rv:
if self.debug: print "Failed to create key: " , rv
raise Exception("createAES - Failed to C_GenerateKey (%s):
%s" % (rv, pkcs11error(rv)) )
else:
if self.debug: print "created key successfully: %s" %
str(handle)
--snap--

Unfortunately I end up with a return value of 32, which means invalid
data -- I guess my template is not that, what is should be.

Any hint on this is highly appreciated.

Kind regards
Cornelius




signature.asc
Description: OpenPGP digital signature
-- 
http://mail.python.org/mailman/listinfo/python-list


Language workbench written in python3

2012-09-05 Thread Nestor Arocha
I'm developing a language workbench written in Python. The idea is to create an 
environment where grammars and translators can interact easily.

https://github.com/nesaro/pydsl

any comments, feedback or ideas? :)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python Interview Questions

2012-09-05 Thread Chris Angelico
On Thu, Sep 6, 2012 at 2:40 AM, Ian Kelly  wrote:
> On Wed, Sep 5, 2012 at 9:34 AM, Chris Angelico  wrote:
>> On Thu, Sep 6, 2012 at 1:22 AM, Ian Kelly  wrote:
>>> The lack of an ORDER BY is the least of the problems with that SQL.
>>> He's also using LIMIT without OFFSET, so the only thing that the
>>> 'item' argument changes is how many rows are returned (all but one of
>>> which are ignored), not which one is actually fetched.
>>
>> No, he's using the two-arg form of LIMIT.
>
> My mistake.  I didn't even know there was a two-arg form of LIMIT.
> Must be a MySQL thing. :-)

Yeah, it's not something I've used, but when my current job started,
we were using MySQL and I used to eyeball the logs to see what queries
were performing most suboptimally. (There were some pretty egregious
ones. Most memorable was rewriting a TEXT field several times a second
with several KB of PHP serialized array with status/statistical
information. Structured information, yes. Stored as a clob.) My first
databasing experience was DB2, with the uber-verbose "FETCH FIRST n
ROW[S] ONLY", but now I'm happily on Postgres.

Everyone who wants to use LIMIT without ORDER BY should try their code
on Postgres. You'll quickly discover the problem.

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


Re: Comparing strings from the back?

2012-09-05 Thread Oscar Benjamin
In news.gmane.comp.python.general, you wrote:
> On Wed, 05 Sep 2012 16:51:10 +0200, Johannes Bauer wrote:
> [...]
>>> You are making unjustified assumptions about the distribution of
>>> letters in the words. This might be a list of long chemical compounds
>>> where the words typically differ only in their suffix. It might be a
>>> list of people with titles:
>> 
>> Actually, I'm not. I'm stating exactly what assumptions I'm making to
>> get my calculation. I'm comparing *random* character strings or
>> bitstrings.
>
> Excuse me, you are not. You are comparing English words which are highly 
> non-random.

Evidently we have different understandings of what 'random' means. I don't
think it's unreasonable to say that strings drawn uniformly from the set of
all strings in the English language (having a given number of characters) is
random. The distribution is not uniform over the set of all possible character
strings but it is still random. I think Johannes deliberately chose these
strings to emulate a particular kind of 'real' distribution of strings that
might occur in practise.

>
>
>> You, on the other hand, are making vague assumptions which you do not
>> care for formalize and yet you claim that "the number of comparisons is
>> equally likely to be 1, 2, 3, ..., N. The average then is". Without any
>> explanation for this. At all.
>
> I will accept that my explanation was not good enough, but I strongly 
> disagree that I gave no explanation at all.
>
>
>>> Herr Professor Frederick Schmidt
>>> Herr Professor Frederick Wagner
>>> ...
>> 
>> Is your assumtion that we're comparing words that have the common prefix
>> "Herr Professor Frederick "? 
>
> No, I am pointing out that *your* assumption that most string comparisons 
> will halt close to the beginning of the string is an invalid assumption. 
> Your assumption only holds for some non-random strings.

I think you have this backwards. The case where this assumption is provably
true is precisely for random strings. To be clear, when I say 'random' in this
context I mean that each character is chosen independently from the same
probability distribution over the possible characters regardless of which
index it has in the string and regardless of what the other characters are
(IID). In this case the probability that comparison terminates at the jth
character decreases exponentially with j. This means that for large strings
the expected number of character comparisons is independent of the number of
characters in the string as the probability of reaching the later parts of the
string is too small for them to have any significant effect. This is provable
and applies regardless of how many possible characters there are and whether
or not each character is equally likely (except for the pathological case
where one character has a probability of 1).

For strings from 'real' distributions it is harder to make statements about
the 'average case' and it is possible to construct situations where the
comparison would regularly need to compare a common prefix. However, to get
asymptotic performance worse than O(1) it is not sufficient to say that there
may be a common prefix such as 'Herr' in the distribution of strings. It is
necessary that, somehow, the common prefix is likely to grow as the size of
the strings grows.

For example, the set of all strings of length N whose first N//2 characters
are always 'a' and whose remaining characters are chosen IID would lead to
O(N) performance. This is why the file paths example chosen at the start of
this thread is a good one. If a program is dealing with a number of large
strings representing file paths then it is not uncommon that many of those
paths would refer to files in the same deeply nested directory and hence
compare equal for a significant number of characters. This could lead to
average case O(N) performance.

I think it's appropriate to compare string comparison with dict insertion:
Best case O(1) (no hash collisions)
Worst case O(N) (collides with every key)
Average case O(1) (as long as you don't use pathological data)

The only difference with string comparison is that there are some conceivable,
non-malicious cases where the pathological data can occur (such as with file
paths). However, I suspect that out of all the different uses of python
strings these cases are a small minority.

In saying that, it's not inconceivable that someone could exploit string
comparison by providing pathological data to make normally O(1) operations
behave as O(N). If I understand correctly it was precisely this kind of
problem with dict insertion/lookup that lead to the recent hash-seed security
update.

Oscar

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


Re: webkit related problems

2012-09-05 Thread Mark Lawrence

On 05/09/2012 23:08, manish gupta wrote:

What should I do in order to install Webkit for Official Python (not
MacPorts Python) ?


INVOKER,
from INDIA





I'd start with your favourite search engine, type something like 
"install webkit official python" into the box, hit return, see what 
comes back and follow an appropriate link.  Probably faster than asking 
here.


--
Cheers.

Mark Lawrence.

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


Re: The opener parameter of Python 3 open() built-in

2012-09-05 Thread Antoine Pitrou
Chris Angelico  gmail.com> writes:
> 
> On Wed, Sep 5, 2012 at 5:16 AM, Terry Reedy  udel.edu> wrote:
> > io.open depends on a function the returns an open file descriptor. opener
> > exposes that dependency so it can be replaced.
> 
> I skimmed the bug report comments but didn't find an answer to this:
> Why not just monkey-patch? When a module function calls on a support
> function and you want to change that support function's behaviour,
> isn't monkey-patching the most usual?

Monkey-patching globals is not thread-safe: other threads will see your
modification, which is risky and fragile.

Regards

Antoine.


-- 
Software development and contracting: http://pro.pitrou.net

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


Re: Python Interview Questions

2012-09-05 Thread Kushal Kumaran
On Wed, Sep 5, 2012 at 3:11 PM, Stephen Anto  wrote:
> On Wed, Sep 5, 2012 at 2:10 PM, Kushal Kumaran
>  wrote:
>>
>> On Wed, Sep 5, 2012 at 12:20 PM,   wrote:
>> > On Tuesday, October 30, 2007 11:44:01 PM UTC+5:30, Krypto wrote:
>> >> Hi,
>> >>
>> >> I have used Python for a couple of projects last year and I found it
>> >> extremely useful. I could write two middle size projects in 2-3 months
>> >> (part time). Right now I am a bit rusty and trying to catch up again
>> >> with Python.
>> >>
>> >> I am now appearing for Job Interviews these days and I am wondering if
>> >> anybody of you appeared for a Python Interview. Can you please share
>> >> the questions you were asked. That will be great help to me.
>> >>
>> >
>> > Finally I have decided to put best interview question and answers.
>> >
>> > Please visit http://www.f2finterview.com/web/CorePython/ for core python
>> > and http://www.f2finterview.com/web/PythonAdvanced/ for advanced python
>> >
>>
>> As I see from a quick glance, several of your answers seem to be
>> copied from the python faq at http://docs.python.org/faq/.  The
>> copyright notice for the python.org website seems to be at
>> http://docs.python.org/copyright.html.  Do you have the Python
>> Software Foundation's permission to copy large chunks of the
>> python.org website and claim it as your own content?
>>
>
> Thank you for your information, I really sorry for this, if possible could
> you note which are the questions taken from faq, we will remove it as early
> as possible.
>

Since your website's Terms of Use state that you own the content, it
is your problem to make sure whatever's there is there legally.

Here's one example, though, to get you started: See the entry "Why
can’t I use an assignment in an expression?" at
http://docs.python.org/faq/design.html, and compare with the content
under the identical heading on page 3 of the CorePython section.

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


RPython, static type annotations, SafePython project (was: PhD Python & Smalltalk grant possibility (Lille/INRIA))

2012-09-05 Thread Stefan Behnel
Mariano Reingart, 05.09.2012 18:53, on python-announce-list:
> Context: Dynamically-typed languages cannot take advantage of static
> type information. In this context we would like to study
> the benefit of the introduction of static types *annotations* on
> library design and general robustness.

Works to a certain extent, but won't get you very far. You'll notice that
static types don't have all that rich semantics, so you'll eventually end
up wanting to extend the type declarations into contract specifications,
and then you'll end up duplicating half of your code to describe the
interface at some point. Has been done, IMHO not worth doing.


> The benefits can be at the level of the robustness (bug
> identification), but also tools (IDE) and support for assembly
> generation/c in case of JIT.

As the PyPy people keep reiterating, JITs (read: their JIT) don't need
static type declarations.

IDEs can benefit from them a bit (not much, just a bit - guessing usually
works quite well here), but I'd hate to change my code only to make my IDE
happy.

Static compilers obviously benefit from them, so you should take a look at
Cython if you are interested in a Python based type system with optional
static type declarations and how people use them in real code. (There's
definitely a lot more Cython code out there than RPython code...)


> The PhD grant is financed in the context of the Safe Python project
> therefore the Ph.D. will have to work in contact
> do we with the project partners and help in the context of some deliverables.
> 
> The following tasks have to be done:
> 
> - RPython is not formally defined. One of the first task will
> be to define the formal semantic of RPython.

Just to be sure: you are talking about RPython, the language that PyPy is
(mostly) written in, right? Why would you want to restrict yourself to that
instead of looking at general Python code? Is that due to those who pay the
project or because it's really of interest all by itself?


> One approach is to write a RPython interpreter based on an
> operational semantics and to compare the output
> with the RPython interpreter. We will certainly use PLT redex
> which is a domain-specific language to specify
> and debug operational semantics.

Sounds like a research-only project to me. From what I hear, RPython isn't
really an interesting programming language. It's very restrictive and easy
to get wrong. That might be related to the fact that the only definition of
the language is the only existing (incomplete) implementation, but maybe
not. (Sounds like some research could help to decide that at least).

There's also ShedSkin, which, I believe, has its own definition of an
"RPython", again based on what it understands and can statically analyse.


> - We may use the abstract syntax tree of PyLint and use the
> Frama-C infrastructure. We will also consider to
> build a Python parser based on petitParser.

My advice: skip the parser part, use the existing AST that Python provides.
That's the only sane way to integrate with other tools that process Python
code.


> - Define of some default metrics may also be necessary for the
> SafePython project. Their definition should
> be trivial on ASTs.

Not sure what you mean with "default metrics" here.


> - Analysis of the benefits of static typing for RPython. One
> idea is to study the existing python libraries
> and analyze the "distance" to the RPython subset.

That might be an interesting study in its own right: how static is
real-world Python code?


> - Exploring type checking in presence of inconsistent type 
> annotations.

Yep, that's only one of the problems you'll run into.


> - Since we are developing Pharo

Which, if I searched correcly, is a Smalltalk IDE?

> and that static type annotation are important to
> support C or assembly generation, we would like to apply the
> same technique to Pharo:
> - define a syntax to support type annotation (reuse
> the one developed by Pleaid team member)
> - perform some analysis of existing library.

I don't know Smalltalk well enough to comment on this.


> About Lille and INRIA:
> 
> Lille is located in the north of france at the border to Belgium
> one hour from Paris, 1h20 from London, 35 min from Brussels, by train.

And the most important thing (which you forgot to mention): a nice place to
live.


> French food, combined with belgian beer.

Well, yes, but it's still a nice place to live.

Stefan


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


===== Soft Skills Training In Chennai ======

2012-09-05 Thread mike pittenson
Ayus Technologies offers Dot net training in chennai,java/j2ee training in 
chennai,SEO training in chennai,web designing training in chennai,soft skills 
training in chennai,Software Testing training in chennai.



http://www.ayustechnologies.com/



More Information contact Mr, Jana 9080140107
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [web] Long-running process: FCGI? SCGI? WSGI?

2012-09-05 Thread Dieter Maurer
Gilles  writes:

> To write a long-running web application, I'd like to some feedback
> about which option to choose.
>
> Apparently, the choice boilds down to this:
> - FastCGI
> - SCGI
> - WSGI
>
> It seems like FCGI and SCGI are language-neutral, while WSGI is
> Python-specific.
>
> Besides that, how to make an informed choice about which option to
> choose?

Obviously, this depends on your environment. Some hosters, web servers,
applications may directly support one interface and not others.

If you control your whole environment, I would look for a newer
approach. I do not know "SCGI" but I know that "WSGI" is fairly recent.
This means that during its design, "FastCGI" was already known and
not deemed to be sufficient. Thus, you can expect more features
(more modularisation, in this case) in "WSGI".

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


Dynamically scheduling Cron Jobs for Python Scripts.

2012-09-05 Thread coldfire
I have a web scrapper script which run every day at 0100 hrs using cron Job 
over a shell account.
Now what I am looking for is to re run the same script.
1> The script goes online to scrape some data including a schedule time for my 
meeting.
I want to re run the script at that schedule time to send me a email.
How can I do that?

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


Re: The opener parameter of Python 3 open() built-in

2012-09-05 Thread Steven D'Aprano
On Thu, 06 Sep 2012 00:34:56 +, Antoine Pitrou wrote:

> Chris Angelico  gmail.com> writes:
>> 
>> On Wed, Sep 5, 2012 at 5:16 AM, Terry Reedy  udel.edu>
>> wrote:
>> > io.open depends on a function the returns an open file descriptor.
>> > opener exposes that dependency so it can be replaced.
>> 
>> I skimmed the bug report comments but didn't find an answer to this:
>> Why not just monkey-patch? When a module function calls on a support
>> function and you want to change that support function's behaviour,
>> isn't monkey-patching the most usual?
> 
> Monkey-patching globals is not thread-safe: other threads will see your
> modification, which is risky and fragile.

Isn't that assuming that you don't intend the other threads to see the 
modification?

If I have two functions in my module that call "open", and I monkey-patch 
the global (module-level) name "open" to intercept that call, I don't see 
that there is more risk of breakage just because one function is called 
from a thread.

Obviously monkey-patching the builtin module itself is much riskier, 
because it doesn't just effect code in my module, it affects *everything*.



-- 
Steven

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


Re: is implemented with id ?

2012-09-05 Thread Steven D'Aprano
On Wed, 05 Sep 2012 14:27:44 -0400, Terry Reedy wrote:

> On 9/5/2012 8:48 AM, Ramchandra Apte wrote:
> 
>  > and "a==True" should be automatically changed into memory comparison.
> 
> I have no idea what that means.

I interpret this as meaning that "a == True" should be special-cased by 
the interpreter as "a is True" instead of calling a.__eq__.



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


Re: The opener parameter of Python 3 open() built-in

2012-09-05 Thread Tim Delaney
On 6 September 2012 16:34, Steven D'Aprano <
steve+comp.lang.pyt...@pearwood.info> wrote:

> On Thu, 06 Sep 2012 00:34:56 +, Antoine Pitrou wrote:
> > Monkey-patching globals is not thread-safe: other threads will see your
>
> modification, which is risky and fragile.
>
> Isn't that assuming that you don't intend the other threads to see the
> modification?
>
> If I have two functions in my module that call "open", and I monkey-patch
> the global (module-level) name "open" to intercept that call, I don't see
> that there is more risk of breakage just because one function is called
> from a thread.
>
> Obviously monkey-patching the builtin module itself is much riskier,
> because it doesn't just effect code in my module, it affects *everything*.


It's not as though the option to monkey-patch has been taken away. But
hopefully there is now less of a need for it.

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