Re: Performance of int/long in Python 3

2013-03-31 Thread Chris Angelico
On Mon, Apr 1, 2013 at 4:33 PM, rusi  wrote:
> So I really wonder: Is python losing more by supporting SMP with
> performance hit on BMP?

If your strings fit entirely within the BMP, then you should see no
penalty compared to previous versions of Python. If they happen to fit
inside ASCII, then there may well be significant improvements. But
regardless, what you gain is the ability to work with *any* string,
regardless of its content, without worrying about it. You can count
characters regardless of their content. Imagine if a tuple of integers
behaved differently if some of those integers flipped to being long
ints:

x = (1, 2, 4, 8, 1<<30, 1<<300, 1<<10)

Wouldn't you be surprised if len(x) returned 8? I certainly would be.
And that's what a narrow build of Python does with Unicode.

Unicode strings are approximately comparable to tuples of integers. In
fact, they can be interchanged fairly readily:

string = "Treble clef: \U0001D11E"
array = tuple(map(ord,string))
assert(len(array) == 14)
out_string = ''.join(map(chr,array))
assert(out_string == string)

This doesn't work in Python 2.6 on Windows, partly because of
surrogates, but also because chr() isn't designed for Unicode strings.
There's probably a solution to the second, but not really to the
first. The tuple of ords should match the way the characters are laid
out to a human.

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


Re: Performance of int/long in Python 3

2013-03-31 Thread Ian Kelly
On Sun, Mar 31, 2013 at 11:33 PM, rusi  wrote:
>
> So I really wonder: Is python losing more by supporting SMP with
> performance hit on BMP?

I don't believe so.  Although performance is undeniably worse for some
benchmarks, it is also better for some others.  Nobody has yet
demonstrated an actual, real-world program that is affected negatively
by the Unicode change.  All of jmf's complaints amount to
cherry-picking data and leaping to conclusions.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Help please

2013-03-31 Thread khaosyt
On Monday, April 1, 2013 1:24:52 AM UTC-4, Chris Angelico wrote:
> On Mon, Apr 1, 2013 at 4:15 PM,   wrote:
> 
> > integer = input("Enter a positive integer: ")
> 
> > again = raw_input("Again? (Y/N): ")
> 
> 
> 
> Okay, the first thing I'm going to say is: Don't use input() in Python
> 
> 2. It's dangerous in ways you won't realize. Use int(raw_input(...))
> 
> for something like this, which will guarantee you an integer.
> 
> 
> 
> I'm guessing this is homework. Please be honest about that; we'll help
> 
> you learn but won't just give you the answers.
> 
> 
> 
> All you need to do is initialize something to zero, and then keep
> 
> adding 'number' onto it in the loop. You should be able to sort that
> 
> out.
> 
> 
> 
> ChrisA

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


Re: Performance of int/long in Python 3

2013-03-31 Thread rusi
On Mar 31, 5:55 pm, Mark Lawrence  wrote:



> I'm feeling very sorry for this horse, it's been flogged so often it's
> down to bare bones.

While I am now joining the camp of those fed up with jmf's whining, I
do wonder if we are shooting the messenger…

>From a recent Roy mysqldb-unicode thread:
> My unicode-fu is a bit weak.  Are we looking at a Python problem, a
> MySQLdb problem, or a problem with the underlying MySQL server?  We've
> certainly inserted utf-8 data before without any problems.  It's
> possible this is the first time we've tried to handle a character
> outside the BMP.
:
:
> OK, that leads to the next question.  Is there anyway I can (in Python
> 2.7) detect when a string is not entirely in the BMP?  If I could find
> all the non-BMP characters, I could replace them with U+FFFD
> (REPLACEMENT CHARACTER) and life would be good (enough).

Steven's:
> But it means that if you're one of the 99.9% of users who mostly use
> characters in the BMP, …

And from http://www.tlg.uci.edu/~opoudjis/unicode/unicode_astral.html
> The informal name for the supplementary planes of Unicode is "astral planes", 
> since
> (especially in the late '90s) their use seemed to be as remote as
> the theosophical "great beyond". …
> As of this writing for instance, Dreamweaver MX for MacOSX (which I am 
> currently using
> to prepare this) will let you paste BMP text into its WYSIWYG window; but 
> pasting
> Supplementary Plane text there will make it crash.

So I really wonder: Is python losing more by supporting SMP with
performance hit on BMP?
The problem as I see it is that a choice that is sufficiently skew is
no more a straightforward choice. An example will illustrate:

I can choose to drive or not -- a choice.
Statistics tell me that on average there are 3 fatalities every day; I
am very concerned that I could get killed so I choose not to drive.
Which neglects that there are a couple of million safe-drives at the
same time as the '3 fatalities'

[What if anything this has to do with jmf's rants I dont know because
I dont know if anyone (including jmf) knows what he is ranting about. ]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Help please

2013-03-31 Thread Chris Angelico
On Mon, Apr 1, 2013 at 4:15 PM,   wrote:
> integer = input("Enter a positive integer: ")
> again = raw_input("Again? (Y/N): ")

Okay, the first thing I'm going to say is: Don't use input() in Python
2. It's dangerous in ways you won't realize. Use int(raw_input(...))
for something like this, which will guarantee you an integer.

I'm guessing this is homework. Please be honest about that; we'll help
you learn but won't just give you the answers.

All you need to do is initialize something to zero, and then keep
adding 'number' onto it in the loop. You should be able to sort that
out.

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


Help please

2013-03-31 Thread khaosyt
I want to add up the integers of this code in one line. For example, if I had 
the code

integer = 0
denom = 10
again = "y" #sentinel:
while again == "y" or again == "Y":
integer = input("Enter a positive integer: ")
while denom <= integer:
denom = denom*10
while denom > 1:
denom = denom/10
number = integer/denom
integer = integer%denom
print str(number)
again = raw_input("Again? (Y/N): ")

and inputted "54321," it would look like:
Enter a positive integer: 54321
5
4
3
2
1
Again? (Y/N): n

What I want to do is add up the "54321" so it comes out with
"Sum of digits is 15." on one line.

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


executor.map() TypeError: zip argument #2 must support iteration

2013-03-31 Thread iMath
executor.map()TypeError: zip argument #2 must support iteration

when I run it ,just generated TypeError: zip argument #2 must support iteration.
can anyone help me fix this problem ?

import time, concurrent.futures
lst100=[i for i in range(100)]

t1=time.clock()
print(list(map(str,lst100)))
t2=time.clock()
print(t2-t1)

t3=time.clock()
with concurrent.futures.ThreadPoolExecutor(max_workers=100) as executor:
future_to_url = executor.map(str,lst100, 60)
print(list(future_to_url))
t4=time.clock()
print(t4-t3)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Why does 1**2**3**4**5 raise a MemoryError?

2013-03-31 Thread Steven D'Aprano
On Mon, 01 Apr 2013 00:39:56 +, Alex wrote:

> Chris Angelico wrote:
> 
> 
>> Opening paragraph, "... exponentiation, which groups from right to
>> left". It follows the obvious expectation from mathematics. (The OP is
>> using Python 2, but the same applies.)
> 
> Thanks. I did miss that parenthetical comment in para 6.15, and that
> would have been the correct place to look, since it appears that
> operators are not parts of expressions, but rather separate them. Is
> that the "obvious expectation from mathematics," though? Given that
> 
>   3
>  5
> 4
> 
> (i.e.: 4**5**3) is transitive, I would have expected Python to exhibit
> more consistency with the other operators. I guess that is one of the
> foolish consistencies that comprise the hobgoblins of my little mind,
> though.

I don't think you mean "transitive" here. Transitivity refers to 
relations, not arbitrary operators. If ≎ is some relation, then it is 
transitive if and only if:

x ≎ y and y ≎ z implies that x ≎ y.

http://en.wikipedia.org/wiki/Transitive_relation

Concrete examples of transitive relations: greater than, equal to, less 
than and equal to.

On the other hand, "unequal to" is not a transitive relation. Nor is 
"approximately equal to". Suppose we say that two values are 
approximately equal if their difference is less than 0.5:

2.1 ≈ 2.4 and 2.4 ≈ 2.7
but 2.1 ≉ 2.7


Exponentiation is not commutative:

2**3 != 3**2

nor is it associative:

2**(3**2) != (2**3)**2


so I'm not really sure what you are trying to say here.



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


Re: Sudoku

2013-03-31 Thread Eric Parry
Sorry.
Won't happen again.
signing off this topic.
Eric.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Why does 1**2**3**4**5 raise a MemoryError?

2013-03-31 Thread Chris Angelico
On Mon, Apr 1, 2013 at 11:39 AM, Alex  wrote:
> Given that
>
>   3
>  5
> 4
>
> (i.e.: 4**5**3) is transitive, I would have expected Python to exhibit
> more consistency with the other operators. I guess that is one of the
> foolish consistencies that comprise the hobgoblins of my little mind,
> though.

Not sure what you mean by transitive here. Certainly (4**5)**3 and
4**(5**3) are not the same value.

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


Re: Why does 1**2**3**4**5 raise a MemoryError?

2013-03-31 Thread Alex
Chris Angelico wrote:

> 
> Opening paragraph, "... exponentiation, which groups from right to
> left". It follows the obvious expectation from mathematics. (The OP is
> using Python 2, but the same applies.)

Thanks. I did miss that parenthetical comment in para 6.15, and that
would have been the correct place to look, since it appears that
operators are not parts of expressions, but rather separate them. Is
that the "obvious expectation from mathematics," though? Given that

  3
 5
4

(i.e.: 4**5**3) is transitive, I would have expected Python to exhibit
more consistency with the other operators. I guess that is one of the
foolish consistencies that comprise the hobgoblins of my little mind,
though.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: collections.Iterator __subclasshook__ does not check if next() is callable

2013-03-31 Thread Ethan Furman

On 03/31/2013 10:57 AM, Byron Ruth wrote:

I submitted this as bug last night: http://bugs.python.org/issue17584 and was 
*honored* to be rejected by Raymond Hettinger. However, I would like feedback 
on whether my concern (this bug) is justified and clarity if not.

Consider:

```python
class A(object):
 def __init__(self):
 self.r = iter(range(5))
 def __iter__(self):
 return self
 @property
 def next(self):
 return next(self.r)
```

The `next` method is a property, however:

```python
from collections import Iterator
a = A()
isinstance(a, Iterator) # True
next(a) # TypeError: 'int' object is not callable
```

I am using `collections.Iterator` as the means to check if the object is an 
iterator, however I am not sure if that is _root_ problem here. My 
understanding of the iterator protocol is that is assumes the __iter__ and next 
*methods* are implemented. In the example, `A.next` is defined as a property, 
but is still identified as an iterator. To me, this is incorrect behavior since 
it's not conforming to the iterator protocol requirements (i.e. a `next` 
method, not a property).


The root problem is that whoever implemented A did so incorrectly.



Raymond stated: "The design of ABCs are to check for the existence to required 
named; none of them verify the signature." I think I understand _why_ this is the 
case.. but I downstream libraries use `collections.Iterator` to determine if an object 
_is one_: see 
https://github.com/django/django/blob/master/django/utils/itercompat.py#L22-L31

Who's job is it to check if `next` (and technically `__iter__`) are methods?


The programmer who wrote it, with good tests.

Technically, the issue is not that 'next' is a property, but that it is not returning a callable.  If it did (and the 
callable was appropriate for the iterator), that would also work.


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


Re: Sudoku

2013-03-31 Thread Arnaud Delobelle
On 31 March 2013 23:34, Dave Angel  wrote:
>[...]  With my Python
> 2.7.2, exit(something) with something being a string prints the string and
> then exits.  Nowhere have I seen that documented, and I thought it either
> took an int or nothing.

It is documented, just not exactly where you'd expect it (exit is a
constant, not a function):


http://docs.python.org/2/library/constants.html#constants-added-by-the-site-module

As for the behaviour when you pass a string, it's documented here:

http://docs.python.org/2/library/exceptions.html#exceptions.SystemExit

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


Re: Sudoku

2013-03-31 Thread Chris Angelico
On Mon, Apr 1, 2013 at 9:27 AM, Eric Parry  wrote:
> [ chomp 128 lines of quoted text ]
>
> I tried all those things. The program keeps running after the solution in 
> every case. Never mind. It won't do that in VBA when I finish it.
> Eric.

You have just spammed us with, and I counted them, one hundred and
twenty-eight lines of quoted text. And you posted to both
comp.lang.python and python-list, so some of us will have seen those
lines twice. Please don't do this. If you MUST use Google Groups,
check out this page, and try to adjust your posts to be more
courteous.

http://wiki.python.org/moin/GoogleGroupsPython

Thanks!

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


Re: Sudoku

2013-03-31 Thread Dave Angel

On 03/31/2013 06:03 PM, Eric Parry wrote:



 



I think in the original it was exit(a). That did not work either.


There you go again.  "Did not work" tells us very little.  With my 
Python 2.7.2, exit(something) with something being a string prints the 
string and then exits.  Nowhere have I seen that documented, and I 
thought it either took an int or nothing.


So please be much more specific.  Did it give some exception, or did it 
not print the right result (I don't see any print statement in the 
code), or what?



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


Re: Why does 1**2**3**4**5 raise a MemoryError?

2013-03-31 Thread Dave Angel

On 03/31/2013 06:06 PM, Alex wrote:

Dave Angel wrote:


On 03/31/2013 02:56 AM, morphex wrote:

1**2

1

1**2**3

1

1**2**3**4

1L

1**2**3**4**5

Traceback (most recent call last):
   File "", line 1, in 
MemoryError




Does anyone know why this raises a MemoryError?  Doesn't make sense
to me.


Perhaps you didn't realize that the expression will be done from
right to left.


Really?

The Python 3 documentation
(http://docs.python.org/3/reference/expressions.html) says in section
6.14 (Evaluation order) that "Python evaluates expressions from left to
right" (an exception being when evaluating assignments, in which case
the RHS of the assignment is calculated first, in left-to-right order).

Section 6.4 discusses the power operator specifically and does not
contradict 6.14 except that the power operator uses right-to-left
evaluation in the presence of unparenthesized unary operators.

Neither of these two exception cases appear to apply here, so I think
the OP is reasonable in expecting Python to do the operation
left-to-right.

Am I missing something written somewhere else in the docs? Are the docs
I quoted wrong? Please help me understand the discrepancy I am
perceiving here.

Alex



On the page you reference, in section 6.14, see the 4th entry:

expr1 + expr2 * (expr3 - expr4)

expr1 is evaluated before expr2, but the multiply happens before the add.

Now see the following paragraph (6.15):

"""
The following table summarizes the operator precedences in Python, from 
lowest precedence (least binding) to highest precedence (most binding). 
Operators in the same box have the same precedence. Unless the syntax is 
explicitly given, operators are binary. Operators in the same box group 
left to right (except for comparisons, including tests, which all have 
the same precedence and chain from left to right — see section 
Comparisons — and exponentiation, which groups from right to left).

"""

What this paragraph refers to as "grouping" is commonly called 
associativity in other languages.


There are three different concepts here that apply whenever an 
expression has more than one term:


1) evaluation order is important for terms lie function calls which have 
side effects

2) precedence, lie where multiply will happen before add
3) associativity, where the order of operations for operators with the 
same precedence are done either left to right (usually), or right to 
left (like exponentiation)





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


Re: Why does 1**2**3**4**5 raise a MemoryError?

2013-03-31 Thread Chris Angelico
On Mon, Apr 1, 2013 at 9:28 AM, Chris Angelico  wrote:
> On Mon, Apr 1, 2013 at 9:06 AM, Alex  wrote:
>> Really?
>>
>> The Python 3 documentation
>> (http://docs.python.org/3/reference/expressions.html) says in section
>> 6.14 (Evaluation order) that "Python evaluates expressions from left to
>> right" (an exception being when evaluating assignments, in which case
>> the RHS of the assignment is calculated first, in left-to-right order).
>>
>> Section 6.4 discusses the power operator specifically and does not
>> contradict 6.14 except that the power operator uses right-to-left
>> evaluation in the presence of unparenthesized unary operators.
>
> http://docs.python.org/3/reference/expressions.html#operator-precedence
>
> Opening paragraph, "... exponentiation, which groups from right to
> left". It follows the obvious expectation from mathematics. (The OP is
> using Python 2, but the same applies.)

Though your point about 6.14 is still true. It states the order that
the integers will be evaluated in. Note one of the examples given:

expr1 + expr2 * (expr3 - expr4)

The evaluation of the expression starts with 3 and 4, then picks up 2,
then 1, but the operands themselves are evaluated left to right.

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


Re: Why does 1**2**3**4**5 raise a MemoryError?

2013-03-31 Thread Chris Angelico
On Mon, Apr 1, 2013 at 9:06 AM, Alex  wrote:
> Dave Angel wrote:
>
>> On 03/31/2013 02:56 AM, morphex wrote:
>> > > > > 1**2
>> > 1
>> > > > > 1**2**3
>> > 1
>> > > > > 1**2**3**4
>> > 1L
>> > > > > 1**2**3**4**5
>> > Traceback (most recent call last):
>> >   File "", line 1, in 
>> > MemoryError
>> > > > >
>> >
>> > Does anyone know why this raises a MemoryError?  Doesn't make sense
>> > to me.
>>
>> Perhaps you didn't realize that the expression will be done from
>> right to left.
>
> Really?
>
> The Python 3 documentation
> (http://docs.python.org/3/reference/expressions.html) says in section
> 6.14 (Evaluation order) that "Python evaluates expressions from left to
> right" (an exception being when evaluating assignments, in which case
> the RHS of the assignment is calculated first, in left-to-right order).
>
> Section 6.4 discusses the power operator specifically and does not
> contradict 6.14 except that the power operator uses right-to-left
> evaluation in the presence of unparenthesized unary operators.

http://docs.python.org/3/reference/expressions.html#operator-precedence

Opening paragraph, "... exponentiation, which groups from right to
left". It follows the obvious expectation from mathematics. (The OP is
using Python 2, but the same applies.)

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


Re: Sudoku

2013-03-31 Thread Eric Parry
On Monday, April 1, 2013 8:33:47 AM UTC+10:30, Eric Parry wrote:
> On Sunday, March 31, 2013 9:45:36 AM UTC+10:30, Dave Angel wrote:
> 
> > On 03/30/2013 06:06 PM, Eric Parry wrote:
> 
> > 
> 
> > > On Saturday, March 30, 2013 8:41:08 AM UTC+10:30, Dave Angel wrote:
> 
> > 
> 
> > >> On 03/29/2013 05:47 PM, Eric Parry wrote:
> 
> > 
> 
> > >>
> 
> > 
> 
> > >>>  
> 
> > 
> 
> > >>
> 
> > 
> 
> > >> Sometimes a bug in such a function will cause it to run indefinitely,
> 
> > 
> 
> > >>
> 
> > 
> 
> > >> and/or to overflow the stack.  I don't see such a bug in this function.
> 
> > 
> 
> > >>
> 
> > 
> 
> > >>
> 
> > 
> 
> > >>
> 
> > 
> 
> > >>
> 
> > 
> 
> > >>
> 
> > 
> 
> > >> --
> 
> > 
> 
> > >>
> 
> > 
> 
> > >> DaveA
> 
> > 
> 
> > >
> 
> > 
> 
> > > The exit() did not work.
> 
> > 
> 
> > 
> 
> > 
> 
> > Would you like to elaborate?  exit() is supposed to take an int 
> 
> > 
> 
> > parameter, but the author apparently didn't notice that.  So perhaps you 
> 
> > 
> 
> > got an exception of some sort.  Change it to exit() or exit(0) and it 
> 
> > 
> 
> > might solve the problem, depending on what the problem was.
> 
> > 
> 
> > 
> 
> > 
> 
> > > I replaced it with return = 0, and that does work.
> 
> > 
> 
> > 
> 
> > 
> 
> > No it doesn't.  return = 0 is a syntax error in both Python 2.x and 3.x
> 
> > 
> 
> > 
> 
> > 
> 
> > But if you changed it to a valid return statement, then that's why it 
> 
> > 
> 
> > doesn't stop on the first solution.
> 
> > 
> 
> > 
> 
> > 
> 
> > 
> 
> > 
> 
> > -- 
> 
> > 
> 
> > DaveA
> 
> 
> 
> I think in the original it was exit(a). That did not work either.
> 
> I'll try the others.
> 
> Eric.

I tried all those things. The program keeps running after the solution in every 
case. Never mind. It won't do that in VBA when I finish it.
Eric.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Help with python code!

2013-03-31 Thread Chris Angelico
On Mon, Apr 1, 2013 at 9:02 AM, Mark Lawrence  wrote:
> On 31/03/2013 22:21, Chris Angelico wrote:
>>>
>>>sue = time.mktime(
>>>  (int(m.group(7)), int(months[m.group(2)]), int(m.group(3)),
>>>int(m.group(4)), int(m.group(5)), int(m.group(6)),
>>>int(days[m.group(1)]), 0, 0)
>>>  )
>>>  expire_time = (sue ­ current_time)/60/60/24
>>
>>
>> Here's a likely problem. There's supposed to be an operator - probably
>> a plus sign - between sue and current_time.
>>
>
> There is actually a minus sign there which showed up when I pasted the code
> into the Eclipse/Pydev editor.  That sadly doesn't fix the problem with the
> call to mktime, 12 open round brackets to 14 close if I've counted
> correctly.

Oh, of course, since sue comes from mktime. But yeah, definitely needs
an operator there.

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


Re: Why does 1**2**3**4**5 raise a MemoryError?

2013-03-31 Thread Alex
Dave Angel wrote:

> On 03/31/2013 02:56 AM, morphex wrote:
> > > > > 1**2
> > 1
> > > > > 1**2**3
> > 1
> > > > > 1**2**3**4
> > 1L
> > > > > 1**2**3**4**5
> > Traceback (most recent call last):
> >   File "", line 1, in 
> > MemoryError
> > > > > 
> > 
> > Does anyone know why this raises a MemoryError?  Doesn't make sense
> > to me.
> 
> Perhaps you didn't realize that the expression will be done from
> right to left.  

Really? 

The Python 3 documentation
(http://docs.python.org/3/reference/expressions.html) says in section
6.14 (Evaluation order) that "Python evaluates expressions from left to
right" (an exception being when evaluating assignments, in which case
the RHS of the assignment is calculated first, in left-to-right order).

Section 6.4 discusses the power operator specifically and does not
contradict 6.14 except that the power operator uses right-to-left
evaluation in the presence of unparenthesized unary operators.

Neither of these two exception cases appear to apply here, so I think
the OP is reasonable in expecting Python to do the operation
left-to-right.

Am I missing something written somewhere else in the docs? Are the docs
I quoted wrong? Please help me understand the discrepancy I am
perceiving here.

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


Re: Sudoku

2013-03-31 Thread Eric Parry
On Sunday, March 31, 2013 9:45:36 AM UTC+10:30, Dave Angel wrote:
> On 03/30/2013 06:06 PM, Eric Parry wrote:
> 
> > On Saturday, March 30, 2013 8:41:08 AM UTC+10:30, Dave Angel wrote:
> 
> >> On 03/29/2013 05:47 PM, Eric Parry wrote:
> 
> >>
> 
> >>>  
> 
> >>
> 
> >> Sometimes a bug in such a function will cause it to run indefinitely,
> 
> >>
> 
> >> and/or to overflow the stack.  I don't see such a bug in this function.
> 
> >>
> 
> >>
> 
> >>
> 
> >>
> 
> >>
> 
> >> --
> 
> >>
> 
> >> DaveA
> 
> >
> 
> > The exit() did not work.
> 
> 
> 
> Would you like to elaborate?  exit() is supposed to take an int 
> 
> parameter, but the author apparently didn't notice that.  So perhaps you 
> 
> got an exception of some sort.  Change it to exit() or exit(0) and it 
> 
> might solve the problem, depending on what the problem was.
> 
> 
> 
> > I replaced it with return = 0, and that does work.
> 
> 
> 
> No it doesn't.  return = 0 is a syntax error in both Python 2.x and 3.x
> 
> 
> 
> But if you changed it to a valid return statement, then that's why it 
> 
> doesn't stop on the first solution.
> 
> 
> 
> 
> 
> -- 
> 
> DaveA

I think in the original it was exit(a). That did not work either.
I'll try the others.
Eric.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Help with python code!

2013-03-31 Thread Mark Lawrence

On 31/03/2013 22:21, Chris Angelico wrote:

   sue = time.mktime(
 (int(m.group(7)), int(months[m.group(2)]), int(m.group(3)),
   int(m.group(4)), int(m.group(5)), int(m.group(6)),
   int(days[m.group(1)]), 0, 0)
 )
 expire_time = (sue ­ current_time)/60/60/24


Here's a likely problem. There's supposed to be an operator - probably
a plus sign - between sue and current_time.



There is actually a minus sign there which showed up when I pasted the 
code into the Eclipse/Pydev editor.  That sadly doesn't fix the problem 
with the call to mktime, 12 open round brackets to 14 close if I've 
counted correctly.


--
If you're using GoogleCrap™ please read this 
http://wiki.python.org/moin/GoogleGroupsPython.


Mark Lawrence

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


Re: Help with python code!

2013-03-31 Thread rurpy
On Sunday, March 31, 2013 3:27:06 PM UTC-6, Roy Smith wrote:

> If this is for an interview, you really should be doing this on your 
> own.  I assume the point of the interview is to see how well you know 
> Python.  Please don't expect people here to take your interview for you.

Maybe the interviewer gives higher ratings to someone who knows 
how to take advantage of all available resources than someone who
goes off in a corner and tries to do it alone?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Help with python code!

2013-03-31 Thread gerrymcgovern
On Sunday, March 31, 2013 5:35:38 PM UTC-4, Chris Angelico wrote:
> On Mon, Apr 1, 2013 at 8:21 AM, jojo  wrote:
> 
> > Thanks for your replies. Just to be clear this is for a interview and they 
> > would like me to figure out what the code does and come back with some test 
> > cases
> 
> 
> 
> That explains the utter lack of comments, then. In well-maintained
> 
> code, you would simply read through the comments to get an idea of
> 
> what it does.
> 
> 
> 
> A couple of key things to look up: glob.glob and os.popen. When you
> 
> know what they do, you should be able to get a broad understanding of
> 
> the whole program.
> 
> 
> 
> ChrisA

OK perfect Chris. Thanks for your reply.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Creating a dictionary from a .txt file

2013-03-31 Thread Dave Angel

On 03/31/2013 02:41 PM, Roy Smith wrote:

In article ,
  Dave Angel  wrote:


On 03/31/2013 12:52 PM, C.T. wrote:

On Sunday, March 31, 2013 12:20:25 PM UTC-4, zipher wrote:

  



Thank you, Mark! My problem is the data isn't consistently ordered. I can
use slicing and indexing to put the year into a tuple, but because a car
manufacturer could have two names (ie, Aston Martin) or a car model could
have two names(ie, Iron Duke), its harder to use slicing and indexing for
those two.  I've added the following, but the output is still not what I
need it to be.


So the correct answer is "it cannot be done," and an explanation.

Many times I've been given impossible conditions for a problem.  And
invariably the correct solution is to press [back] on the supplier of the
constraints.


In real life, you often have to deal with crappy input data (and bogus
project requirements).  Sometimes you just need to be creative.

There's only a small set of car manufacturers.  A good start would be
mining wikipedia's [[List of automobile manufacturers]].  Once you've
got that list, you could try matching portions of the input against the
list.

Depending on how much effort you wanted to put into this, you could
explore all sorts of fuzzy matching (ie "delorean" vs "delorean motor
company"), but even a simple search is better than giving up.

And, this is a good excuse to explore some of the interesting
third-party modules.  For example, mwclient ("pip install mwclient")
gives you a neat Python interface to wikipedia.  And there's a whole
landscape of string matching packages to explore.

We deal with this every day at Songza.  Are Kesha and Ke$ha the same
artist?  Pushing back on the record labels to clean up their catalogs
isn't going to get us very far.



I agree with everything you've said, although in your case, presumably 
the record labels are not your client/boss, so that's not who you push 
back against.  The client should know when the data is being fudged, and 
have a say in how it's to be done.


But this is a homework assignment.  I think the OP is learning Python, 
not how to second-guess a client.



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


Re: Help with python code!

2013-03-31 Thread gerrymcgovern
On Sunday, March 31, 2013 5:27:06 PM UTC-4, Roy Smith wrote:
> In article <4455829d-5b4a-44ee-b65f-5f72d429b...@googlegroups.com>,
> 
>  jojo  wrote:
> 
> 
> 
> > Thanks for your replies. Just to be clear this is for a interview and they 
> 
> > would like me to figure out what the code does and come back with some test 
> 
> > cases. I don't need to code the tests, just give some high level tests. As 
> 
> > far as I can make out it is some system where you input your name and it 
> > will 
> 
> > bring back your details plus how much time you have left on your card. Have 
> 
> > to say I find the code extremely confusing, hopefully all python isn't like 
> 
> > this!!
> 
> 
> 
> If this is for an interview, you really should be doing this on your 
> 
> own.  I assume the point of the interview is to see how well you know 
> 
> Python.  Please don't expect people here to take your interview for you.

Where did I ask people to take the interview for me? I asked for some tips on 
interpreting the code something which you have been unable to give me. If a 
senior dev (I am assuming you are a python dev) is unable to figure out what 
the code does, then I think me, been a newbie to new language (with horrible 
syntax) is entitled to ask for help. 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Help with python code!

2013-03-31 Thread Chris Angelico
On Mon, Apr 1, 2013 at 8:21 AM, jojo  wrote:
> Thanks for your replies. Just to be clear this is for a interview and they 
> would like me to figure out what the code does and come back with some test 
> cases

That explains the utter lack of comments, then. In well-maintained
code, you would simply read through the comments to get an idea of
what it does.

A couple of key things to look up: glob.glob and os.popen. When you
know what they do, you should be able to get a broad understanding of
the whole program.

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


Re: Help with python code!

2013-03-31 Thread Roy Smith
In article <4455829d-5b4a-44ee-b65f-5f72d429b...@googlegroups.com>,
 jojo  wrote:

> Thanks for your replies. Just to be clear this is for a interview and they 
> would like me to figure out what the code does and come back with some test 
> cases. I don't need to code the tests, just give some high level tests. As 
> far as I can make out it is some system where you input your name and it will 
> bring back your details plus how much time you have left on your card. Have 
> to say I find the code extremely confusing, hopefully all python isn't like 
> this!!

If this is for an interview, you really should be doing this on your 
own.  I assume the point of the interview is to see how well you know 
Python.  Please don't expect people here to take your interview for you.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Help with python code!

2013-03-31 Thread jojo
On Sunday, March 31, 2013 5:13:49 PM UTC-4, Roy Smith wrote:
> In article <2912c674-e30b-4339-9344-1f460cb96...@googlegroups.com>,
> 
>  jojo  wrote:
> 
> 
> 
> > for fname in dirList:
> 
> >  cmd = "keytool �printcert �file " + fname
> 
> >  for line in os.popen(cmd).readlines():
> 
> >line = line.rstrip()
> 
> >m = p.search(line)
> 
> >if m:
> 
> >   sue = time.mktime(
> 
> > (int(m.group(7)), int(months[m.group(2)]), int(m.group(3)),
> 
> >   int(m.group(4)), int(m.group(5)), int(m.group(6)),
> 
> >   int(days[m.group(1)]), 0, 0)
> 
> > )
> 
> > expire_time = (sue � current_time)/60/60/24
> 
> > if expire_time < 0:
> 
> >   print cert_name + " has already expired!"
> 
> > elif expire_time < 31:
> 
> >   print cert_name + " expires in " +str(int(expire_time)) + " days"
> 
> >else:
> 
> > m = q.search(line)
> 
> > if m:
> 
> > cert_name = m.group(1)
> 
> 
> 
> Was this code really indented like this when you got it?  You've got (at 
> 
> least) three different indent sizes.  I see 1, 2, and 3 space indents in 
> 
> different places in the code.
> 
> 
> 
> I'm not even sure if this is legal, but even if it is, it's really bad 
> 
> form.  Pick an indent, and stick with it uniformly.  4 spaces seems to 
> 
> be pretty standard.
> 
> 
> 
> That being said, I'm going to return to my previous statement that until 
> 
> you know what the code is *supposed* to do, trying to test it is 
> 
> meaningless.


Hi Rob.

Thanks for your replies. Just to be clear this is for a interview and they 
would like me to figure out what the code does and come back with some test 
cases. I don't need to code the tests, just give some high level tests. As far 
as I can make out it is some system where you input your name and it will bring 
back your details plus how much time you have left on your card. Have to say I 
find the code extremely confusing, hopefully all python isn't like this!!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Help with python code!

2013-03-31 Thread gerrymcgovern
On Sunday, March 31, 2013 5:21:00 PM UTC-4, Chris Angelico wrote:
> On Mon, Apr 1, 2013 at 8:06 AM, jojo  wrote:
> 
> > On Sunday, March 31, 2013 4:39:11 PM UTC-4, Chris Angelico wrote:
> 
> >> On Mon, Apr 1, 2013 at 7:10 AM, jojo wrote:
> 
> >>
> 
> >> > Im used to C# so the syntax looks bizarre to me! Any help would be great.
> 
> >>
> 
> >>
> 
> >>
> 
> >> The first thing you'll need to understand about Python syntax is that
> 
> >>
> 
> >> indentation is important. By posting this code flush-left, you've
> 
> >>
> 
> >> actually destroyed its block structure. Could you post it again, with
> 
> >>
> 
> >> indentation, please? We'd then be in a much better position to help.
> 
> >>
> 
> >>
> 
> >>
> 
> >> Chris Angelico
> 
> >
> 
> >
> 
> > Hi Chris, thanks for your reply. See code below...
> 
> 
> 
> Ah, you appear to be posting from Google Groups. You may want to check
> 
> this page out, as a lot of people rather dislike GG posts.
> 
> 
> 
> http://wiki.python.org/moin/GoogleGroupsPython
> 
> 
> 
> The best method is simply to avoid Google Groups altogether.
> 
> 
> 
> Anyway, some code comments. (Though the biggest comment to make about
> 
> the code is its utter lack of comments. Not a good idea in any
> 
> language, for anything more than the most trivial script.)
> 
> 
> 
> > current_time = time.time() + 60*60+24*30
> 
> 
> 
> This line doesn't, quite frankly, make a lot of sense; time.time()
> 
> returns the current time already, but then an offset of one hour and
> 
> twelve minutes is added.
> 
> 
> 
> >if m:
> 
> >   sue = time.mktime(
> 
> > (int(m.group(7)), int(months[m.group(2)]), int(m.group(3)),
> 
> >   int(m.group(4)), int(m.group(5)), int(m.group(6)),
> 
> >   int(days[m.group(1)]), 0, 0)
> 
> > )
> 
> > expire_time = (sue ­ current_time)/60/60/24
> 
> 
> 
> Here's a likely problem. There's supposed to be an operator - probably
> 
> a plus sign - between sue and current_time.
> 
> 
> 
> >else:
> 
> > m = q.search(line)
> 
> > if m:
> 
> > cert_name = m.group(1)
> 
> 
> 
> And this last line needs indentation.
> 
> 
> 
> The very easiest way to debug Python code is to run it. If it runs,
> 
> great! See what output it made and whether it's correct or not. If it
> 
> doesn't, Python will give you an exception traceback that points you
> 
> to the failing line. Get familiar with them, as you'll be seeing them
> 
> a lot :)
> 
> 
> 
> Chris Angelico


Ok, thanks Chris!!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Help with python code!

2013-03-31 Thread Chris Angelico
On Mon, Apr 1, 2013 at 8:06 AM, jojo  wrote:
> On Sunday, March 31, 2013 4:39:11 PM UTC-4, Chris Angelico wrote:
>> On Mon, Apr 1, 2013 at 7:10 AM, jojo wrote:
>>
>> > Im used to C# so the syntax looks bizarre to me! Any help would be great.
>>
>>
>>
>> The first thing you'll need to understand about Python syntax is that
>>
>> indentation is important. By posting this code flush-left, you've
>>
>> actually destroyed its block structure. Could you post it again, with
>>
>> indentation, please? We'd then be in a much better position to help.
>>
>>
>>
>> Chris Angelico
>
>
> Hi Chris, thanks for your reply. See code below...

Ah, you appear to be posting from Google Groups. You may want to check
this page out, as a lot of people rather dislike GG posts.

http://wiki.python.org/moin/GoogleGroupsPython

The best method is simply to avoid Google Groups altogether.

Anyway, some code comments. (Though the biggest comment to make about
the code is its utter lack of comments. Not a good idea in any
language, for anything more than the most trivial script.)

> current_time = time.time() + 60*60+24*30

This line doesn't, quite frankly, make a lot of sense; time.time()
returns the current time already, but then an offset of one hour and
twelve minutes is added.

>if m:
>   sue = time.mktime(
> (int(m.group(7)), int(months[m.group(2)]), int(m.group(3)),
>   int(m.group(4)), int(m.group(5)), int(m.group(6)),
>   int(days[m.group(1)]), 0, 0)
> )
> expire_time = (sue ­ current_time)/60/60/24

Here's a likely problem. There's supposed to be an operator - probably
a plus sign - between sue and current_time.

>else:
> m = q.search(line)
> if m:
> cert_name = m.group(1)

And this last line needs indentation.

The very easiest way to debug Python code is to run it. If it runs,
great! See what output it made and whether it's correct or not. If it
doesn't, Python will give you an exception traceback that points you
to the failing line. Get familiar with them, as you'll be seeing them
a lot :)

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


Re: Help with python code!

2013-03-31 Thread Roy Smith
In article <2912c674-e30b-4339-9344-1f460cb96...@googlegroups.com>,
 jojo  wrote:

> for fname in dirList:
>  cmd = "keytool ­printcert ­file " + fname
>  for line in os.popen(cmd).readlines():
>line = line.rstrip()
>m = p.search(line)
>if m:
>   sue = time.mktime(
> (int(m.group(7)), int(months[m.group(2)]), int(m.group(3)),
>   int(m.group(4)), int(m.group(5)), int(m.group(6)),
>   int(days[m.group(1)]), 0, 0)
> )
> expire_time = (sue ­ current_time)/60/60/24
> if expire_time < 0:
>   print cert_name + " has already expired!"
> elif expire_time < 31:
>   print cert_name + " expires in " +str(int(expire_time)) + " days"
>else:
> m = q.search(line)
> if m:
> cert_name = m.group(1)

Was this code really indented like this when you got it?  You've got (at 
least) three different indent sizes.  I see 1, 2, and 3 space indents in 
different places in the code.

I'm not even sure if this is legal, but even if it is, it's really bad 
form.  Pick an indent, and stick with it uniformly.  4 spaces seems to 
be pretty standard.

That being said, I'm going to return to my previous statement that until 
you know what the code is *supposed* to do, trying to test it is 
meaningless.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Help with python code!

2013-03-31 Thread Roy Smith
In article <37f23623-8bf5-421a-ab6a-34ff622c6...@googlegroups.com>,
 jojo  wrote:

> Hi - I am a newbie to python and was wondering can someone tell me what the 
> following code does. I need to figure out how to test it

I know this is going to sound unhelpful, but if your task is to test the 
code, what good does it do to know what it does?  Clearly, it does what 
it does.  What you really want to know is "What is it *supposed* to do?"  
Until you know what it's supposed to do, it is meaningless to even think 
about testing it.

Seriously.  I'm not trying to make life difficult for you.  I've seen 
too much time and effort wasted on useless testing because there wasn't 
any specification for what the code was supposed to do.

I will give you one hint, however.  You've got stuff like:

for line in os.popen(cmd).readlines():
line = line.rstrip()

This is a syntax error because the indenting is wrong.  Unlike C#, 
indenting is significant in Python.  I don't know if the code you've got 
really is indented wrong, or it's just an artifact of how you posted it.  
But before anything else, you need to sort that out.

Unless, of course, the specification for this code is, "It is supposed 
to raise IndentationError", in which case it passes the test :-)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Help with python code!

2013-03-31 Thread jojo
On Sunday, March 31, 2013 4:39:11 PM UTC-4, Chris Angelico wrote:
> On Mon, Apr 1, 2013 at 7:10 AM, jojo wrote:
> 
> > Im used to C# so the syntax looks bizarre to me! Any help would be great.
> 
> 
> 
> The first thing you'll need to understand about Python syntax is that
> 
> indentation is important. By posting this code flush-left, you've
> 
> actually destroyed its block structure. Could you post it again, with
> 
> indentation, please? We'd then be in a much better position to help.
> 
> 
> 
> Chris Angelico


Hi Chris, thanks for your reply. See code below...

import time
import glob
import re
import os
current_time = time.time() + 60*60+24*30
dirList = glob.glob('\content\paytek\ejbProperties\cybersource\*.crt')
q = re.compile('^Owner:.*CN=([^\s\,]+)')
p = re.compile('until: (\w+) (\w+) (\d+) (\d+):(\d+):(\d+) \w+ (\d+)')
cert_name = ""
days = {"Mon":0, "Tue":1, "Wed":2, "Thu":3, "Fri":4, "Sat":5, "Sun":6}
months = {"Jan":1, "Feb":2, "Mar":3, "Apr":4,
  "May":5, "Jun":6, "Jul":7, "Aug":8,
  "Sep":9, "Oct":10, "Nov":11, "Dec":12}
for fname in dirList:
 cmd = "keytool ­printcert ­file " + fname
 for line in os.popen(cmd).readlines():
   line = line.rstrip()
   m = p.search(line)
   if m:
  sue = time.mktime(
(int(m.group(7)), int(months[m.group(2)]), int(m.group(3)),
  int(m.group(4)), int(m.group(5)), int(m.group(6)),
  int(days[m.group(1)]), 0, 0)
)
expire_time = (sue ­ current_time)/60/60/24
if expire_time < 0:
  print cert_name + " has already expired!"
elif expire_time < 31:
  print cert_name + " expires in " +str(int(expire_time)) + " days"
   else:
m = q.search(line)
if m:
cert_name = m.group(1)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Help with python code!

2013-03-31 Thread Chris Angelico
On Mon, Apr 1, 2013 at 7:10 AM, jojo  wrote:
> Im used to C# so the syntax looks bizarre to me! Any help would be great.

The first thing you'll need to understand about Python syntax is that
indentation is important. By posting this code flush-left, you've
actually destroyed its block structure. Could you post it again, with
indentation, please? We'd then be in a much better position to help.

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


Re: Python 3.2.3 and my blank page

2013-03-31 Thread Νίκος Γκρ33κ
Τη Κυριακή, 31 Μαρτίου 2013 11:21:21 μ.μ. UTC+3, ο χρήστης ru...@yahoo.com 
έγραψε:
> On 03/31/2013 02:08 PM, Νίκος Γκρ33κ wrote:
> 
> 
> 
> > But i look the code and run python via interactive prompt and it says
> 
> > it has no error.
> 
> 
> 
> Does it produce any output?  Is that output the right html?  That is, if
> 
> you save the html to a file and open that file in a browser, does it look
> 
> right? 
> 
> 
> 
> > So i don't have a clue on what i still need to try since i get no
> 
> > error via cmd or via browser(blank page)
> 
> 
> 
> I have no clue either because I don't know what output you are getting 
> 
> when you run the script interactively, nor do I know what the code is
> 
> that you are running.

I think i have mase some progress and it seems that the reason *perhaps* is 
encoding issues.

look at http://superhost.gr now and biew its source too.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python 3.2.3 and my blank page

2013-03-31 Thread rurpy
On 03/31/2013 02:08 PM, Νίκος Γκρ33κ wrote:

> But i look the code and run python via interactive prompt and it says
> it has no error.

Does it produce any output?  Is that output the right html?  That is, if
you save the html to a file and open that file in a browser, does it look
right? 

> So i don't have a clue on what i still need to try since i get no
> error via cmd or via browser(blank page)

I have no clue either because I don't know what output you are getting 
when you run the script interactively, nor do I know what the code is
that you are running.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python 3.2.3 and my blank page

2013-03-31 Thread rurpy
On 03/31/2013 01:19 PM, Νίκος Γκρ33κ wrote:
> I just tried the testmysql.py script:
>[...snip code...]
 
I hope no one who reads this list also has access to your database
and that you don't use that username/password anyplace else.

> it works, as you can see at:
> http://superhost.gr/cgi-bin/testmysql.py
> so MySQLdb mpodule does work for Python3 !
> so mysql connector is not the problem.
> but hwta is it then i get no errors!!

Get no errors from what?  The original script you were having
trouble with?  Are you running it by using your browser or
from interactively in a terminal window?

I probably should have asked this before, but can do you have
shell access to the script?  Can you run it interactively in 
a terminal window?
-- 
http://mail.python.org/mailman/listinfo/python-list


Help with python code!

2013-03-31 Thread jojo
Hi - I am a newbie to python and was wondering can someone tell me what the 
following code does. I need to figure out how to test it

import time
import glob
import re
import os

current_time = time.time() + 60*60+24*30

dirList = glob.glob('\content\paytek\ejbProperties\cybersource\*.crt')

q = re.compile('^Owner:.*CN=([^\s\,]+)')
p = re.compile('until: (\w+) (\w+) (\d+) (\d+):(\d+):(\d+) \w+ (\d+)')
cert_name = ""
days = {"Mon":0, "Tue":1, "Wed":2, "Thu":3, "Fri":4, "Sat":5, "Sun":6}
months = {"Jan":1, "Feb":2, "Mar":3, "Apr":4,
"May":5, "Jun":6, "Jul":7, "Aug":8,
"Sep":9, "Oct":10, "Nov":11, "Dec":12}

for fname in dirList:
cmd = "keytool ­printcert ­file " + fname
for line in os.popen(cmd).readlines():
line = line.rstrip()
m = p.search(line)
if m:
sue = time.mktime(
(int(m.group(7)), int(months[m.group(2)]), int(m.group(3)),
int(m.group(4)), int(m.group(5)), int(m.group(6)),
int(days[m.group(1)]), 0, 0)
)
expire_time = (sue ­ current_time)/60/60/24
if expire_time < 0:
print cert_name + " has already expired!"
elif expire_time < 31:
print cert_name + " expires in " +str(int(expire_time)) + " days"
else:
m = q.search(line)
if m:
cert_name = m.group(1)


Im used to C# so the syntax looks bizarre to me! Any help would be great.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python 3.2.3 and my blank page

2013-03-31 Thread Νίκος Γκρ33κ
Τη Κυριακή, 31 Μαρτίου 2013 10:46:57 μ.μ. UTC+3, ο χρήστης ru...@yahoo.com 
έγραψε:
> On 03/31/2013 01:12 PM, Νίκος Γκρ33κ wrote:
> 
> > Firsly, thank you for your willing to help me. i wrote, uploaded an
> 
> > chmoded test.py and you can see the cgi enviromental table here:
> 
> > http://superhost.gr/cgi-bin/test.py All values seem okey, so it
> 
> > really isnt somehting wrong with the cgi enviroment. Also i chnagen
> 
> > the host line to what you suggestes so interactive prompts will not
> 
> > give errors. Please take a look the values to see if something not
> 
> > look  ok and i 'am about to create another trest script to check if i
> 
> > can pefrom a simple mysql query with python 3.2.3 just to make sure
> 
> > the MySQLdb connector work ok with 3.x
> 
> 
> 
> I didn't mean that there was anything *wrong* with your cgi 
> 
> environment, only that it is *different* than your interactive 
> 
> environment.
> 
> 
> 
> It is easier to debug code in an interactive environment than a 
> 
> cgi one so you want to do as much debugging interactively as possible,.
> 
> But because the environments are different your code will behave 
> 
> differently.  Knowing what is different between the two environments
> 
> will help you know if an error is due to a real problem in your
> 
> code, or is just due to the different environment.  And it will
> 
> help you setup your interactive environment to be as close as 
> 
> possible to the cgi one.


But i look the code and run python via interactive prompt and it says it has no 
error.

So i don't have a clue on what i still need to try since i get no error via cmd 
or via browser(blank page)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: collections.Iterator __subclasshook__ does not check if next() is callable

2013-03-31 Thread Byron Ruth
Thanks for responding Terry.

I can assure you I did not initially realize both the `next` and the `__iter__` 
methods were implemented when I ran into my original problem. I saw a behavior 
and had to work backwards to realize why it was behaving the way it was (the 
comparison against Iterator). Once I realized this, the behavior made complete 
sense. It just dawned on me the fact that `next` was not being checked to be 
callable (I was surprised by this at the time) which is why I investigated the 
`Iterator.__subclasshook__` and assumed it was behaving incorrectly based on my 
assumptions.

On Sunday, March 31, 2013 3:47:07 PM UTC-4, Terry Jan Reedy wrote:
> On 3/31/2013 1:57 PM, Byron Ruth wrote:
> 
> > I submitted this as bug last night: http://bugs.python.org/issue17584 and 
> > was *honored* to be rejected by Raymond Hettinger. However, I would like 
> > feedback on whether my concern (this bug) is justified and clarity if not.
> 
> >
> 
> > Consider:
> 
> >
> 
> > ```python
> 
> > class A(object):
> 
> >  def __init__(self):
> 
> >  self.r = iter(range(5))
> 
> >  def __iter__(self):
> 
> >  return self
> 
> >  @property
> 
> >  def next(self):
> 
> >  return next(self.r)
> 
> > ```
> 
> >
> 
> > The `next` method is a property, however:
> 
> 
> 
> A competent Python programmer should not do that. In Py3, the method is 
> 
> properly renamed '__next__', which should make doing that accidentally 
> 
> even less likely.
> 
> 
> 
> >
> 
> > ```python
> 
> > from collections import Iterator
> 
> > a = A()
> 
> > isinstance(a, Iterator) # True
> 
> > next(a) # TypeError: 'int' object is not callable
> 
> > ```
> 
> >
> 
> > I am using `collections.Iterator` as the means to check if the object is an 
> > iterator,
> 
> 
> 
> Being an Iterator only means that it *might* be an iterator.
> 
> 
> 
>  > however I am not sure if that is _root_ problem here. My 
> 
> understanding of the iterator protocol is that is assumes the __iter__ 
> 
> and next *methods* are implemented. In the example, `A.next` is defined 
> 
> as a property, but is still identified as an iterator. To me, this is 
> 
> incorrect behavior since it's not conforming to the iterator protocol 
> 
> requirements (i.e. a `next` method, not a property).
> 
> 
> 
> There is more to any protocol than can be statically checked.
> 
> 
> 
> > Raymond stated: "The design of ABCs are to check for the existence to 
> > required named; none of them verify the signature."
> 
> 
> 
> Having the required attributes is currently the definition of being an 
> 
> instance of an ABC. Adding 'not a property' would be possible. but 
> 
> hardly worthwhile. Checking signatures would be worthwhile, but 
> 
> signatures are not yet available to Python for C-coded methods, let 
> 
> alone other implementations.
> 
> 
> 
>   I think I understand _why_ this is the case.. but I downstream 
> 
> libraries use `collections.Iterator` to determine if an object _is one_: 
> 
> see 
> 
> https://github.com/django/django/blob/master/django/utils/itercompat.py#L22-L31
> 
> >
> 
> > Who's job is it to check if `next` (and technically `__iter__`) are methods?
> 
> 
> 
> The programmer, and a user who does not trust the competence of the 
> 
> programmer. But this is the least of the possible errors.
> 
> 
> 
> --
> 
> Terry Jan Reedy

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


Re: Python 3.2.3 and my blank page

2013-03-31 Thread rurpy
On 03/31/2013 01:12 PM, Νίκος Γκρ33κ wrote:
> Firsly, thank you for your willing to help me. i wrote, uploaded an
> chmoded test.py and you can see the cgi enviromental table here:
> http://superhost.gr/cgi-bin/test.py All values seem okey, so it
> really isnt somehting wrong with the cgi enviroment. Also i chnagen
> the host line to what you suggestes so interactive prompts will not
> give errors. Please take a look the values to see if something not
> look  ok and i 'am about to create another trest script to check if i
> can pefrom a simple mysql query with python 3.2.3 just to make sure
> the MySQLdb connector work ok with 3.x

I didn't mean that there was anything *wrong* with your cgi 
environment, only that it is *different* than your interactive 
environment.

It is easier to debug code in an interactive environment than a 
cgi one so you want to do as much debugging interactively as possible,.
But because the environments are different your code will behave 
differently.  Knowing what is different between the two environments
will help you know if an error is due to a real problem in your
code, or is just due to the different environment.  And it will
help you setup your interactive environment to be as close as 
possible to the cgi one.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: collections.Iterator __subclasshook__ does not check if next() is callable

2013-03-31 Thread Terry Jan Reedy

On 3/31/2013 1:57 PM, Byron Ruth wrote:

I submitted this as bug last night: http://bugs.python.org/issue17584 and was 
*honored* to be rejected by Raymond Hettinger. However, I would like feedback 
on whether my concern (this bug) is justified and clarity if not.

Consider:

```python
class A(object):
 def __init__(self):
 self.r = iter(range(5))
 def __iter__(self):
 return self
 @property
 def next(self):
 return next(self.r)
```

The `next` method is a property, however:


A competent Python programmer should not do that. In Py3, the method is 
properly renamed '__next__', which should make doing that accidentally 
even less likely.




```python
from collections import Iterator
a = A()
isinstance(a, Iterator) # True
next(a) # TypeError: 'int' object is not callable
```

I am using `collections.Iterator` as the means to check if the object is an 
iterator,


Being an Iterator only means that it *might* be an iterator.

> however I am not sure if that is _root_ problem here. My 
understanding of the iterator protocol is that is assumes the __iter__ 
and next *methods* are implemented. In the example, `A.next` is defined 
as a property, but is still identified as an iterator. To me, this is 
incorrect behavior since it's not conforming to the iterator protocol 
requirements (i.e. a `next` method, not a property).


There is more to any protocol than can be statically checked.


Raymond stated: "The design of ABCs are to check for the existence to required 
named; none of them verify the signature."


Having the required attributes is currently the definition of being an 
instance of an ABC. Adding 'not a property' would be possible. but 
hardly worthwhile. Checking signatures would be worthwhile, but 
signatures are not yet available to Python for C-coded methods, let 
alone other implementations.


 I think I understand _why_ this is the case.. but I downstream 
libraries use `collections.Iterator` to determine if an object _is one_: 
see 
https://github.com/django/django/blob/master/django/utils/itercompat.py#L22-L31


Who's job is it to check if `next` (and technically `__iter__`) are methods?


The programmer, and a user who does not trust the competence of the 
programmer. But this is the least of the possible errors.


--
Terry Jan Reedy


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


Re: collections.Iterator __subclasshook__ does not check if next() is callable

2013-03-31 Thread Byron Ruth
Raymond's replied to my follow-up and made me realize that the `next` property 
could return a callable and it would be transparent to the caller.

On Sunday, March 31, 2013 1:57:08 PM UTC-4, Byron Ruth wrote:
> I submitted this as bug last night: http://bugs.python.org/issue17584 and was 
> *honored* to be rejected by Raymond Hettinger. However, I would like feedback 
> on whether my concern (this bug) is justified and clarity if not.
> 
> 
> 
> Consider:
> 
> 
> 
> ```python
> 
> class A(object):
> 
> def __init__(self):
> 
> self.r = iter(range(5))
> 
> def __iter__(self):
> 
> return self
> 
> @property
> 
> def next(self):
> 
> return next(self.r)
> 
> ```
> 
> 
> 
> The `next` method is a property, however:
> 
> 
> 
> ```python
> 
> from collections import Iterator
> 
> a = A()
> 
> isinstance(a, Iterator) # True
> 
> next(a) # TypeError: 'int' object is not callable
> 
> ```
> 
> 
> 
> I am using `collections.Iterator` as the means to check if the object is an 
> iterator, however I am not sure if that is _root_ problem here. My 
> understanding of the iterator protocol is that is assumes the __iter__ and 
> next *methods* are implemented. In the example, `A.next` is defined as a 
> property, but is still identified as an iterator. To me, this is incorrect 
> behavior since it's not conforming to the iterator protocol requirements 
> (i.e. a `next` method, not a property).
> 
> 
> 
> Raymond stated: "The design of ABCs are to check for the existence to 
> required named; none of them verify the signature." I think I understand 
> _why_ this is the case.. but I downstream libraries use 
> `collections.Iterator` to determine if an object _is one_: see 
> https://github.com/django/django/blob/master/django/utils/itercompat.py#L22-L31
> 
> 
> 
> Who's job is it to check if `next` (and technically `__iter__`) are methods?
-- 
http://mail.python.org/mailman/listinfo/python-list


interacting with an opened libreoffice calc file

2013-03-31 Thread androidmaroso
Hi everyone,

i'm new to the newsgroup and to python allthough (thanks to internet and the 
helpfull people i find) i've done a few scripts in python working like a charm.

First of all i have to say i'm working on linux with python 2.3.7 (hope it's 
right) and libreoffice calc.

My calc file gathers info from the web and adjusts it like i want and 
everything works fine there.

My final result is a sheet called RESULTS where i have 6 columns :

1st column has BUY MARKET NAMES
2nd column has EURO PRICES (relative to the market's name in EURO currency)
3rd column has ORIG PRICE (value in the original currency)

4th column has SELL MARKET NAMES
5th column has EURO PRICES (relative to the market's name in EURO currency)
6th column has ORIG PRICE (value in the original currency)

I would like to have another sheet or place (let's call it ALERTS)  where i can 
make a list of alerts i would like to receive ... for example :

MARKET1   BUY   <= 20
MARKET2   SELL  = 90
MARKET3   BUY  > 59

What i would like is a script in python that reads all lines in the sheet 
ALERTS every n. (minutes or seconds) and compares the values from the RESULTS 
sheet and if the condition is TRUE then shoots an ALARM (soundfile would be 
great, maybe a customizable one)

Is this possible? How can i acheive this?

Thanks to anyone that can give me a solution, hint o show me the right 
direction.

Cheers!

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


Re: Python 3.2.3 and my blank page

2013-03-31 Thread Νίκος Γκρ33κ
I just tried the testmysql.py script:

#!/usr/bin/python3
# coding=utf-8

import cgitb; cgitb.enable()
import cgi, re, os, sys, socket, datetime, MySQLdb, locale, random, subprocess



# connect to database
con = MySQLdb.connect( db = 'nikos_metrites', host = 'localhost', user = 
'nikos_nikos', passwd = 'tiabhp2r#', init_command='SET NAMES UTF8' )
cur = con.cursor()

print ( "Content-type: text/html; charset=utf-8\n" )


# 
=
# if extra string is attached to the URL is 'log' then show explicit page log 
and exit
# 
=

cur.execute('''SELECT hits FROM counters''')
data = cur.fetchall()#URL is unique, so should only be one

for item in data:
print( item )
===


it works, as you can see at: http://superhost.gr/cgi-bin/testmysql.py

so MySQLdb mpodule does work for Python3 !

so mysql connector is not the problem.

but hwta is it then i get no errors!!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python 3.2.3 and my blank page

2013-03-31 Thread Νίκος Γκρ33κ
Τη Κυριακή, 31 Μαρτίου 2013 9:14:43 μ.μ. UTC+3, ο χρήστης ru...@yahoo.com 
έγραψε:
> On 03/31/2013 08:03 AM, Νίκος Γκρ33κ wrote:
> 
> > Hello all,
> 
> > 
> 
> > i need some help
> 
> > i recently changes pythoon 2.6 code => python 3.2.3 but my script although 
> > not producing any errors now doesnt display anything else but a blank page 
> > at htp://superhost.gr
> 
> > can you help?
> 
> > 
> 
> > I tried MySQLdb, pymysql, oursql, but nothing happens.
> 
> > i still get a blank page. I dont know what else to try since i see no error.
> 
> 
> 
> When I look at your page and do a "show source" in my browser
> 
> it shows me the following:
> 
> 
> 
>   
> 
>--> -->
> 
> 
> 
>  
> 
> 
> 
> One obvious error is that you are writing html text before the 
> 
> "Content-Type: text/html" line.  And whatever code is supposed
> 
> to create the content is not getting run.
> 
> 
> 
> > can anyone suggest anything?
> 
> 
> 
> It is hard to help you because there is no code to look at.  
> 
> Also, I looked at your web site a couple days ago after you 
> 
> said you were getting a blank page, but I got a traceback 
> 
> page.  I realize your are working on the problem and changing 
> 
> things but nobody wants to spend time looking for a problem, 
> 
> only to find out you've changed the code and their time was 
> 
> wasted.
> 
> 
> 
> Also, your requests for help are spread out over multiple 
> 
> threads making it hard for anyone to figure out what you've 
> 
> already tried and what the current state of your code and 
> 
> problems are.
> 
> 
> 
> I haven't used MySql so I can't offer any specific help regarding
> 
> that, but I can say how I would try to attack your problem if it 
> 
> were my problem.  
> 
> 
> 
> First, Python 2 and Python 3 are two different languages.  Code
> 
> written for Python 2 will not run under Python 3 (in general) 
> 
> unless it is changed.  So first, are you sure that the database
> 
> connector (dbi module) runs under Python 3?  Are you sure it is 
> 
> installed properly? 
> 
> 
> 
> To answer this question definitively you can write a simple 
> 
> Python program to import the dbi module, open a connection to
> 
> your database and execute a simple query.
> 
> 
> 
> Once you are sure you can access the database with Python 3 
> 
> code, next is your cgi script code.  
> 
> 
> 
> Try running your cgi script interactively.
> 
> 
> 
> But when you do this, remember that the environment that your 
> 
> script sees is different when you run it interactively than 
> 
> when Apache runs your script.  When Apache runs your script 
> 
> it might be using a different userid (which can affect what 
> 
> files your script can open), there different environment variables 
> 
> (like REMOTE_HOST which will be missing when you run interactively).
> 
> 
> 
> You can see the environment that exists when Apache is running 
> 
> your script by creating a cgi script like:
> 
> 
> 
> 
> 
> #!/bin/env python3
> 
> import cgi, os, sys
> 
> 
> 
> print("Content-type: text/html\n")
> 
> print("""\
> 
>  
> PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
> 
>  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd";>
> 
> http://www.w3.org/1999/xhtml"; lang="en-US" xml:lang="en-US">
> 
> 
> 
> Python CGI Environment
> 
> 
> 
> 
> 
> 
> 
> Python CGI Environment
> 
> """)
> 
> print("Python %s" % sys.version)
> 
> print("Current directory: %s" % os.getcwd())
> 
> print("Environment Variables:")
> 
> for k in sorted(os.environ.keys()):
> 
> print("  %s: %s" % (k, cgi.escape(os.environ[k])))
> 
> 
> 
> print("")
> 
> 
> 
> 
> 
> Open that cgi script in your browser.  You can also run it
> 
> interactively and you'll see many differences with what
> 
> you see in your browser.
> 
> 
> 
> When you run your failing cgi script interactively, you can 
> 
> give it an argument that is the url of the cgi script.  For 
> 
> example, if you do:
> 
> 
> 
>   cd ~me/public_html/cgi_bin/
> 
>   python3 myscript.py 'http://superhost.gr/myscript.cgi'
> 
> 
> 
> the cgi module will parse the url argument and setup the right
> 
> values for the QUERY_STRING environment value that Apache would 
> 
> normally set up.
> 
> 
> 
> There may be other problems resulting from the different interactive
> 
> environment.  If I recall, at one point you were having an error 
> 
> because REMOTE_ADDR was not present in the interactive environment.
> 
> 
> 
> Perhaps the best way to deal with that is to modify your code.
> 
> Foe example replace
> 
> 
> 
>   host = socket.gethostbyaddr( os.environ['REMOTE_ADDR'] )[0]
> 
> 
> 
> with 
> 
>   try:
> 
> host = socket.gethostbyaddr( os.environ['REMOTE_ADDR'] )[0]
> 
>   except KeyError:
> 
> host = 'not available' 
> 
> 
> 
> Then your script will be able to run interactively and you can 
> 
> continue debugging the real problems in it.  Of course there 
> 
> may be other issue you have to fix as well but find and fix 

Re: Creating a dictionary from a .txt file

2013-03-31 Thread Terry Jan Reedy

On 3/31/2013 11:52 AM, C.T. wrote:

Hello,

I'm currently working on a homework problem that requires me to create a 
dictionary from a .txt file that contains some of the worst cars ever made. The 
file looks something like this:

1958 MGA Twin Cam
1958 Zunndapp Janus
1961 Amphicar
1961 Corvair
1966 Peel Trident
1970 AMC Gremlin
1970 Triumph Stag
1971 Chrysler Imperial LeBaron Two-Door Hardtop

The car manufacturer should be the key and a tuple containing the year and the 
model should be the key's value. I tried the following to just get the contents 
of the file into a list, but only the very last line in the txt file is shown 
as a list with three elements (ie, ['2004', 'Chevy', 'SSR']) when I print temp.

d={}
car_file = open('worstcars.txt', 'r')
for line in car_file:
 temp = line.split()


If all makers are one word (Austen-Martin would be ok, and if the file 
is otherwise consistently year maker model words, then adding 
'maxsplit=3' to the split call would be all the parsing you need.




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


"Laws of Form" are a notation for the SK calculus, demo in Python.

2013-03-31 Thread forman . simon
I was investigating G. Spencer-Brown's Laws of Form[1] by implementing it
in Python.  You can represent the "marks" of LoF as datastructures in
Python composed entirely of tuples.

For example:
A mark: ()
A mark next to a mark: (), ()
A mark within a mark: ((),)
and so on...


It is known that the propositional calculus can be represented by the
"arithmetic of the mark". The two rules suffice:

((),) == nothing
() == (), ()

There are details, but essentially math and logic can be derived from the
behaviour of "the mark".


After reading "Every Bit Counts"[2] I spent some time trying to come up
with an EBC coding for the circle language (Laws of Form expressed as
tuples, See Burnett-Stuart's "The Markable Mark"[3])

With a little skull-sweat I found the following encoding:

  For the empty state (no mark) write '0'.

  Start at the left, if you encounter a boundary (one "side" of a mark, or
  the left, opening, parenthesis) write a '1'.

  Repeat for the contents of the mark, then the neighbors.

 _ -> 0
() -> 100
(), () -> 10100
 ((),) -> 11000
and so on...


I recognized these numbers as the patterns of the language called
'Iota'.[4]

Briefly, the SK combinators:

S = λx.λy.λz.xz(yz)
K = λx.λy.x

Or, in Python:

S = lambda x: lambda y: lambda z: x(z)(y(z))
K = lambda x: lambda y: x

can be used to define the combinator used to implement Iota:

i = λc.cSK

or,

i = lambda c: c(S)(K)


And the bitstrings are decoded like so: if you encounter '0' return i,
otherwise decode two terms and apply the first to the second.

In other words, the empty space, or '0', corresponds to i:

_ -> 0 -> i

and the mark () corresponds to i applied to itself:

() -> 100 -> i(i)

which is an Identity function I.

The S and K combinators can be "recovered" by application of i to itself
like so (this is Python code, note that I am able to use 'is' instead of
the weaker '==' operator.  The i combinator is actually recovering the
very same lambda functions used to create it.  Neat, eh?):

K is i(i(i(i))) is decode('1010100')
S is i(i(i(i(i is decode('101010100')

Where decode is defined (in Python) as:

decode = lambda path: _decode(path)[0]

def _decode(path):
  bit, path = path[0], path[1:]
  if bit == '0':
return i, path
  A, path = _decode(path)
  B, path = _decode(path)
  return A(B), path


(I should note that there is an interesting possibility of encoding the
tuples two ways: contents before neighbors (depth-first) or neighbors
before content (breadth-first). Here we look at the former.)

So, in "Laws of Form" K is ()()() and S is ()()()() and, amusingly, the
identity function I is ().

The term '(())foo' applies the identity function to foo, which matches the
behaviour of the (()) form in the Circle Arithmetic (()) == _ ("nothing".)


(())A ->  i(i)(A) -> I(A) -> A


I just discovered this (that the Laws of Form have a direct mapping to
the combinator calculus[5] by means of λc.cSK) and I haven't found anyone
else mentioning yet (although [6] might, I haven't worked my way all the
way through it yet.)

There are many interesting avenues to explore from here, and I personally
am just beginning, but this seems like something worth reporting.

Warm regards,
~Simon Peter Forman



[1] http://en.wikipedia.org/wiki/Laws_of_Form
[2] research.microsoft.com/en-us/people/dimitris/every-bit-counts.pdf
[3] http://www.markability.net/
[4] http://semarch.linguistics.fas.nyu.edu/barker/Iota/
[5] http://en.wikipedia.org/wiki/SKI_combinator_calculus have 
[6] 
http://memristors.memristics.com/Combinatory%20Logic%20and%20LoF/Combinatory%20Logic%20and%20the%20Laws%20of%20Form.html
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Creating a dictionary from a .txt file

2013-03-31 Thread Roy Smith
In article ,
 Dave Angel  wrote:

> On 03/31/2013 12:52 PM, C.T. wrote:
> > On Sunday, March 31, 2013 12:20:25 PM UTC-4, zipher wrote:
> >>  
> >>
> >
> > Thank you, Mark! My problem is the data isn't consistently ordered. I can 
> > use slicing and indexing to put the year into a tuple, but because a car 
> > manufacturer could have two names (ie, Aston Martin) or a car model could 
> > have two names(ie, Iron Duke), its harder to use slicing and indexing for 
> > those two.  I've added the following, but the output is still not what I 
> > need it to be.
> 
> So the correct answer is "it cannot be done," and an explanation.
> 
> Many times I've been given impossible conditions for a problem.  And 
> invariably the correct solution is to press [back] on the supplier of the 
> constraints.

In real life, you often have to deal with crappy input data (and bogus 
project requirements).  Sometimes you just need to be creative.

There's only a small set of car manufacturers.  A good start would be 
mining wikipedia's [[List of automobile manufacturers]].  Once you've 
got that list, you could try matching portions of the input against the 
list.

Depending on how much effort you wanted to put into this, you could 
explore all sorts of fuzzy matching (ie "delorean" vs "delorean motor 
company"), but even a simple search is better than giving up.

And, this is a good excuse to explore some of the interesting 
third-party modules.  For example, mwclient ("pip install mwclient") 
gives you a neat Python interface to wikipedia.  And there's a whole 
landscape of string matching packages to explore.

We deal with this every day at Songza.  Are Kesha and Ke$ha the same 
artist?  Pushing back on the record labels to clean up their catalogs 
isn't going to get us very far.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python 3.2.3 and my blank page

2013-03-31 Thread rurpy
On 03/31/2013 08:03 AM, Νίκος Γκρ33κ wrote:
> Hello all,
> 
> i need some help
> i recently changes pythoon 2.6 code => python 3.2.3 but my script although 
> not producing any errors now doesnt display anything else but a blank page at 
> htp://superhost.gr
> can you help?
> 
> I tried MySQLdb, pymysql, oursql, but nothing happens.
> i still get a blank page. I dont know what else to try since i see no error.

When I look at your page and do a "show source" in my browser
it shows me the following:

  
   --> -->

 

One obvious error is that you are writing html text before the 
"Content-Type: text/html" line.  And whatever code is supposed
to create the content is not getting run.

> can anyone suggest anything?

It is hard to help you because there is no code to look at.  
Also, I looked at your web site a couple days ago after you 
said you were getting a blank page, but I got a traceback 
page.  I realize your are working on the problem and changing 
things but nobody wants to spend time looking for a problem, 
only to find out you've changed the code and their time was 
wasted.

Also, your requests for help are spread out over multiple 
threads making it hard for anyone to figure out what you've 
already tried and what the current state of your code and 
problems are.

I haven't used MySql so I can't offer any specific help regarding
that, but I can say how I would try to attack your problem if it 
were my problem.  

First, Python 2 and Python 3 are two different languages.  Code
written for Python 2 will not run under Python 3 (in general) 
unless it is changed.  So first, are you sure that the database
connector (dbi module) runs under Python 3?  Are you sure it is 
installed properly? 

To answer this question definitively you can write a simple 
Python program to import the dbi module, open a connection to
your database and execute a simple query.

Once you are sure you can access the database with Python 3 
code, next is your cgi script code.  

Try running your cgi script interactively.

But when you do this, remember that the environment that your 
script sees is different when you run it interactively than 
when Apache runs your script.  When Apache runs your script 
it might be using a different userid (which can affect what 
files your script can open), there different environment variables 
(like REMOTE_HOST which will be missing when you run interactively).

You can see the environment that exists when Apache is running 
your script by creating a cgi script like:


#!/bin/env python3
import cgi, os, sys

print("Content-type: text/html\n")
print("""\
http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd";>
http://www.w3.org/1999/xhtml"; lang="en-US" xml:lang="en-US">

Python CGI Environment



Python CGI Environment
""")
print("Python %s" % sys.version)
print("Current directory: %s" % os.getcwd())
print("Environment Variables:")
for k in sorted(os.environ.keys()):
print("  %s: %s" % (k, cgi.escape(os.environ[k])))

print("")


Open that cgi script in your browser.  You can also run it
interactively and you'll see many differences with what
you see in your browser.

When you run your failing cgi script interactively, you can 
give it an argument that is the url of the cgi script.  For 
example, if you do:

  cd ~me/public_html/cgi_bin/
  python3 myscript.py 'http://superhost.gr/myscript.cgi'

the cgi module will parse the url argument and setup the right
values for the QUERY_STRING environment value that Apache would 
normally set up.

There may be other problems resulting from the different interactive
environment.  If I recall, at one point you were having an error 
because REMOTE_ADDR was not present in the interactive environment.

Perhaps the best way to deal with that is to modify your code.
Foe example replace

  host = socket.gethostbyaddr( os.environ['REMOTE_ADDR'] )[0]

with 
  try:
host = socket.gethostbyaddr( os.environ['REMOTE_ADDR'] )[0]
  except KeyError:
host = 'not available' 

Then your script will be able to run interactively and you can 
continue debugging the real problems in it.  Of course there 
may be other issue you have to fix as well but find and fix 
them one at a time.  

Add print statements to your code to find out where things are 
going wrong.  Don't trust your own thinking about the code!
If you think a variable should be 3 at some point in the code,
print it out and verify it!

After you get the program to generate html that looks ok, comment
out your debugging print statements (so that only html is printed), 
redirect the html output into a file, them open the file in your
browser and see if it looks ok.  If not, modify the code until 
it does.

After you've got the script producing good output interactively
see if works from Apache as cgi script.  If not, it should be 
much easier now to find the problem since most of the other 
problems have been fixed.


> I can even provide host:port user & pass f

collections.Iterator __subclasshook__ does not check if next() is callable

2013-03-31 Thread Byron Ruth
I submitted this as bug last night: http://bugs.python.org/issue17584 and was 
*honored* to be rejected by Raymond Hettinger. However, I would like feedback 
on whether my concern (this bug) is justified and clarity if not.

Consider:

```python
class A(object):
def __init__(self):
self.r = iter(range(5))
def __iter__(self):
return self
@property
def next(self):
return next(self.r)
```

The `next` method is a property, however:

```python
from collections import Iterator
a = A()
isinstance(a, Iterator) # True
next(a) # TypeError: 'int' object is not callable
```

I am using `collections.Iterator` as the means to check if the object is an 
iterator, however I am not sure if that is _root_ problem here. My 
understanding of the iterator protocol is that is assumes the __iter__ and next 
*methods* are implemented. In the example, `A.next` is defined as a property, 
but is still identified as an iterator. To me, this is incorrect behavior since 
it's not conforming to the iterator protocol requirements (i.e. a `next` 
method, not a property).

Raymond stated: "The design of ABCs are to check for the existence to required 
named; none of them verify the signature." I think I understand _why_ this is 
the case.. but I downstream libraries use `collections.Iterator` to determine 
if an object _is one_: see 
https://github.com/django/django/blob/master/django/utils/itercompat.py#L22-L31

Who's job is it to check if `next` (and technically `__iter__`) are methods?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Creating a dictionary from a .txt file

2013-03-31 Thread Dave Angel

On 03/31/2013 12:52 PM, C.T. wrote:

On Sunday, March 31, 2013 12:20:25 PM UTC-4, zipher wrote:

 



Thank you, Mark! My problem is the data isn't consistently ordered. I can use 
slicing and indexing to put the year into a tuple, but because a car 
manufacturer could have two names (ie, Aston Martin) or a car model could have 
two names(ie, Iron Duke), its harder to use slicing and indexing for those two. 
 I've added the following, but the output is still not what I need it to be.




So the correct answer is "it cannot be done," and an explanation.

Many times I've been given impossible conditions for a problem.  And 
invariably the correct solution is to press bac on the supplier of the 
constraints.


Unless there are some invisible characters in that file, lie tabs in 
between the fields, it loocs liec you're out of luc.  Or you could 
manually edit the file before running the program.


[The character after 'j' is broccen on this cceyboard.]
--
DaveA
--
http://mail.python.org/mailman/listinfo/python-list


Re: Creating a dictionary from a .txt file

2013-03-31 Thread C.T.
On Sunday, March 31, 2013 12:38:56 PM UTC-4, Roy Smith wrote:
> In article ,
> 
>  "C.T."  wrote:
> 
> 
> 
> > Hello,
> 
> > 
> 
> > I'm currently working on a homework problem that requires me to create a 
> 
> > dictionary from a .txt file that contains some of the worst cars ever made. 
> 
> > The file looks something like this:
> 
> > 
> 
> > 1958 MGA Twin Cam
> 
> > 1958 Zunndapp Janus
> 
> > 1961 Amphicar
> 
> > 1961 Corvair
> 
> > 1966 Peel Trident
> 
> > 1970 AMC Gremlin
> 
> > 1970 Triumph Stag
> 
> > 1971 Chrysler Imperial LeBaron Two-Door Hardtop
> 
> > 
> 
> > The car manufacturer should be the key and a tuple containing the year and 
> 
> > the model should be the key's value. I tried the following to just get the 
> 
> > contents of the file into a list, but only the very last line in the txt 
> > file 
> 
> > is shown as a list with three elements (ie, ['2004', 'Chevy', 'SSR']) when 
> > I 
> 
> > print temp.
> 
> > 
> 
> > d={}
> 
> > car_file = open('worstcars.txt', 'r')
> 
> > for line in car_file:
> 
> > temp = line.split()
> 
> > print (temp)
> 
> > car_file.close()
> 
> 
> 
> Yup.  Because you run through the whole file, putting each line into 
> 
> temp, overwriting the previous temp value.
> 
> 
> 
> > d=[]
> 
> > car_file = open('worstcars.txt', 'r')
> 
> > for line in car_file:
> 
> > d.append(line.strip('\n'))
> 
> > print (d)
> 
> > car_file.close()
> 
> 
> 
> You could do most of that with just:
> 
> 
> 
> car_file = open('worstcars.txt', 'r')
> 
> d = car_file.readlines()
> 
> 
> 
> but there's no real reason to read the whole file into a list.  What you 
> 
> probably want to do is something like:
> 
> 
> 
> d = {}
> 
> car_file = open('worstcars.txt', 'r')
> 
> for line in car_file:
> 
>year, manufacturer, model = parse_line(line)
> 
>d[manufacturer] = (year, model)
> 
> 
> 
> One comment about the above; it assumes that there's only a single entry 
> 
> for a given manufacturer in the file.  If that's not true, the above 
> 
> code will only keep the last one.  But let's assume it's true for the 
> 
> moment.
> 
> 
> 
> Now, we're just down to writing parse_line().  This takes a string and 
> 
> breaks it up into 3 strings.  I'm going to leave this as an exercise for 
> 
> you to work out.  The complicated part is going to be figuring out some 
> 
> logic to deal with anything from multi-word model names ("Imperial 
> 
> LeBaron Two-Door Hardtop"), to lines like the Corvair where there is no 
> 
> manufacturer (or maybe there's no model?).

Roy, thank you so much! I'll do some more research to see how I can achieve 
this. Thank you!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Creating a dictionary from a .txt file

2013-03-31 Thread Chris Angelico
On Mon, Apr 1, 2013 at 4:19 AM, C.T.  wrote:
> Thank you, Chris! I could use slicing and indexing to build the dictionary 
> but the problem is with the car manufacturer an the car model. Either or both 
> could be multiple names.

Then you're going to need some other form of magic to recognize where
the manufacturer ends and the model starts. Do you have, say, tabs
between the fields and spaces within?

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


Re: Creating a dictionary from a .txt file

2013-03-31 Thread C.T.
On Sunday, March 31, 2013 12:06:18 PM UTC-4, Chris Angelico wrote:
> On Mon, Apr 1, 2013 at 2:52 AM, C.T.
> 
> > After playing around with the code, I came up with the following code to 
> > get everything into a list:
> 
> >
> 
> > d=[]
> 
> > car_file = open('worstcars.txt', 'r')
> 
> > for line in car_file:
> 
> > d.append(line.strip('\n'))
> 
> > print (d)
> 
> > car_file.close()
> 
> >
> 
> > Every line is now an element in list d. The question I have now is how can 
> > I make a dictionary out of the list d with the car manufacturer as the key 
> > and a tuple containing the year and the model should be the key's value.
> 
> 
> 
> Ah, a nice straight-forward text parsing problem!
> 
> 
> 
> The question is how to recognize the manufacturer. Is it guaranteed to
> 
> be the second blank-delimited word, with the year being the first? If
> 
> so, you were almost there with .split().
> 
> 
> 
> car_file = open('worstcars.txt', 'r')
> 
> # You may want to consider the 'with' statement here - no need to close()
> 
> for line in car_file:
> 
> temp = line.split(None, 2)
> 
> if len(temp)==3:
> 
> year, mfg, model = temp
> 
> # Now do something with these three values
> 
> print("Manufacturer: %s  Year: %s  Model: %s"%(mfg,year,model))
> 
> 
> 
> That's sorted out the parsing side of things. Do you know how to build
> 
> up the dictionary from there?
> 
> 
> 
> What happens if there are multiple entries in the file for the same
> 
> manufacturer? Do you need to handle that?
> 
> 
> 
> ChrisA

Thank you, Chris! I could use slicing and indexing to build the dictionary but 
the problem is with the car manufacturer an the car model. Either or both could 
be multiple names. 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Creating a dictionary from a .txt file

2013-03-31 Thread C.T.
On Sunday, March 31, 2013 12:20:25 PM UTC-4, zipher wrote:
> Every line is now an element in list d. The question I have now is how can I 
> make a dictionary out of the list d with the car manufacturer as the key and 
> a tuple containing the year and the model should be the key's value. Here is 
> a sample of what list d looks like:
> 
> 
> 
> 
> ['1899 Horsey Horseless', '1909 Ford Model T', '1911 Overland OctoAuto', 
> '2003 Hummer H2', '2004 Chevy SSR']
> 
> 
> 
> Any help would be appreciated!
> 
> 
> 
> 
> As long as your data is consistently ordered, just use list indexing.  d[2] 
> is your key, and (d[1],d[3]) the key's value.
> 
> 
> 
> Mark
> Tacoma, Washington


Thank you, Mark! My problem is the data isn't consistently ordered. I can use 
slicing and indexing to put the year into a tuple, but because a car 
manufacturer could have two names (ie, Aston Martin) or a car model could have 
two names(ie, Iron Duke), its harder to use slicing and indexing for those two. 
 I've added the following, but the output is still not what I need it to be.


t={}
for i in d :
t[d[d.index(i)][5:]]= tuple(d[d.index(i)][:4])

print (t)

The output looks something like this:

{'Ford Model T': ('1', '9', '0', '9'), 'Mosler Consulier GTP': ('1', '9', '8', 
'5'), 'Scripps-Booth Bi-Autogo': ('1', '9', '1', '3'), 'Morgan Plus 8 Propane': 
('1', '9', '7', '5'), 'Fiat Multipla': ('1', '9', '9', '8'), 'Ford Pinto': 
('1', '9', '7', '1'), 'Triumph Stag': ('1', '9', '7', '0'), 'BMW 7-series': 
('2', '0', '0', '2')}


Here the key is the car manufacturer and car model and the value is a tuple 
containing the year separated by a comma.( Not sure why that is ?)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Creating a dictionary from a .txt file

2013-03-31 Thread Roy Smith
In article ,
 "C.T."  wrote:

> Hello,
> 
> I'm currently working on a homework problem that requires me to create a 
> dictionary from a .txt file that contains some of the worst cars ever made. 
> The file looks something like this:
> 
> 1958 MGA Twin Cam
> 1958 Zunndapp Janus
> 1961 Amphicar
> 1961 Corvair
> 1966 Peel Trident
> 1970 AMC Gremlin
> 1970 Triumph Stag
> 1971 Chrysler Imperial LeBaron Two-Door Hardtop
> 
> The car manufacturer should be the key and a tuple containing the year and 
> the model should be the key's value. I tried the following to just get the 
> contents of the file into a list, but only the very last line in the txt file 
> is shown as a list with three elements (ie, ['2004', 'Chevy', 'SSR']) when I 
> print temp.
> 
> d={}
> car_file = open('worstcars.txt', 'r')
> for line in car_file:
> temp = line.split()
> print (temp)
> car_file.close()

Yup.  Because you run through the whole file, putting each line into 
temp, overwriting the previous temp value.

> d=[]
> car_file = open('worstcars.txt', 'r')
> for line in car_file:
> d.append(line.strip('\n'))
> print (d)
> car_file.close()

You could do most of that with just:

car_file = open('worstcars.txt', 'r')
d = car_file.readlines()

but there's no real reason to read the whole file into a list.  What you 
probably want to do is something like:

d = {}
car_file = open('worstcars.txt', 'r')
for line in car_file:
   year, manufacturer, model = parse_line(line)
   d[manufacturer] = (year, model)

One comment about the above; it assumes that there's only a single entry 
for a given manufacturer in the file.  If that's not true, the above 
code will only keep the last one.  But let's assume it's true for the 
moment.

Now, we're just down to writing parse_line().  This takes a string and 
breaks it up into 3 strings.  I'm going to leave this as an exercise for 
you to work out.  The complicated part is going to be figuring out some 
logic to deal with anything from multi-word model names ("Imperial 
LeBaron Two-Door Hardtop"), to lines like the Corvair where there is no 
manufacturer (or maybe there's no model?).
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Creating a dictionary from a .txt file

2013-03-31 Thread Mark Janssen
>
> Every line is now an element in list d. The question I have now is how can
> I make a dictionary out of the list d with the car manufacturer as the key
> and a tuple containing the year and the model should be the key's value.
> Here is a sample of what list d looks like:
>
> ['1899 Horsey Horseless', '1909 Ford Model T', '1911 Overland OctoAuto',
> '2003 Hummer H2', '2004 Chevy SSR']
>
> Any help would be appreciated!
>
>
As long as your data is consistently ordered, just use list indexing.  d[2]
is your key, and (d[1],d[3]) the key's value.

Mark
Tacoma, Washington
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Creating a dictionary from a .txt file

2013-03-31 Thread Chris Angelico
On Mon, Apr 1, 2013 at 2:52 AM, C.T.  wrote:
> After playing around with the code, I came up with the following code to get 
> everything into a list:
>
> d=[]
> car_file = open('worstcars.txt', 'r')
> for line in car_file:
> d.append(line.strip('\n'))
> print (d)
> car_file.close()
>
> Every line is now an element in list d. The question I have now is how can I 
> make a dictionary out of the list d with the car manufacturer as the key and 
> a tuple containing the year and the model should be the key's value.

Ah, a nice straight-forward text parsing problem!

The question is how to recognize the manufacturer. Is it guaranteed to
be the second blank-delimited word, with the year being the first? If
so, you were almost there with .split().

car_file = open('worstcars.txt', 'r')
# You may want to consider the 'with' statement here - no need to close()
for line in car_file:
temp = line.split(None, 2)
if len(temp)==3:
year, mfg, model = temp
# Now do something with these three values
print("Manufacturer: %s  Year: %s  Model: %s"%(mfg,year,model))

That's sorted out the parsing side of things. Do you know how to build
up the dictionary from there?

What happens if there are multiple entries in the file for the same
manufacturer? Do you need to handle that?

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


Creating a dictionary from a .txt file

2013-03-31 Thread C.T.
Hello,

I'm currently working on a homework problem that requires me to create a 
dictionary from a .txt file that contains some of the worst cars ever made. The 
file looks something like this:

1958 MGA Twin Cam
1958 Zunndapp Janus
1961 Amphicar
1961 Corvair
1966 Peel Trident
1970 AMC Gremlin
1970 Triumph Stag
1971 Chrysler Imperial LeBaron Two-Door Hardtop

The car manufacturer should be the key and a tuple containing the year and the 
model should be the key's value. I tried the following to just get the contents 
of the file into a list, but only the very last line in the txt file is shown 
as a list with three elements (ie, ['2004', 'Chevy', 'SSR']) when I print temp.

d={}
car_file = open('worstcars.txt', 'r')
for line in car_file:
temp = line.split()
print (temp)
car_file.close()

After playing around with the code, I came up with the following code to get 
everything into a list:

d=[]
car_file = open('worstcars.txt', 'r')
for line in car_file:
d.append(line.strip('\n'))
print (d)
car_file.close()

Every line is now an element in list d. The question I have now is how can I 
make a dictionary out of the list d with the car manufacturer as the key and a 
tuple containing the year and the model should be the key's value. Here is a 
sample of what list d looks like:

['1899 Horsey Horseless', '1909 Ford Model T', '1911 Overland OctoAuto', '2003 
Hummer H2', '2004 Chevy SSR']

Any help would be appreciated!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python 3.2.3 and my blank page

2013-03-31 Thread feedthetroll
I like to feed trolls :-)

On 31 Mrz., 16:03, Νίκος Γκρ33κ  wrote:
> Hello all,
Hello Ferrous Cranus [3]!

> ...
> I tried MySQLdb, pymysql, oursql, but nothing happens.
> i still get a blank page. I dont know what else to try since i see no error.
Well, the output of your cgi is:

 --> -->
  
   

This is not valid html. Therefore the browser does not render
anything.

>
> can anyone suggest anything?
Learn html [1] and python [2], read your code. Find out, why most of
your html-output does not get into the response. Solve the reasons.
Done.

>
> I can even provide host:port user & pass for someone willing to take a look 
> from the inside.
I'm sure it depends what you are willing to pay.
[Sorry, I forgot. You are looking for someone, who does your work
(which you are payed for because aou are a hoster) for free.]


[1] https://www.google.at/search?q=learn+html+online
[2] https://www.google.at/search?q=learn+python+online
[3] http://redwing.hutman.net/~mreed/warriorshtm/ferouscranus.htm
-- 
http://mail.python.org/mailman/listinfo/python-list


A Healthy Alternative to Takeaway Regret

2013-03-31 Thread saddd
A Healthy Alternative to Takeaway Regret

http://natigtas7ab.blogspot.com/2013/03/a-healthy-alternative-to-takeaway-regret.html
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Convert Latitude, Longitude To TimeZone

2013-03-31 Thread Roy Smith
In article ,
 Steve B  wrote:

> I found a piece of code
> [http://blog.pamelafox.org/2012/04/converting-addresses-to-timezones-in.html
> ] which uses the function [https://gist.github.com/pamelafox/2288222]
> 
> When I try to run the code, I get the error geonames is not defined (This is
> the function previously linked to)

The best thing to do when asking questions like this is to copy-paste 
the exact error message you got.  It was probably something like:

Traceback (most recent call last):
  File "", line 1, in 
NameError: name 'geonames' is not defined

In this example, it's easy enough to figure out what went wrong from 
your description, but in general, giving the exact error helps in the 
diagnosis.

> geonames_client = geonames.GeonamesClient('Username_alpha')
> 
> geonames_result = geonames_client.find_timezone({'lat': 48.871236, 'lng':
> 2.77928})
> 
> user.timezone = geonames_result['timezoneId']

You simply never imported the geonames module.  Somewhere before your 
first line of code, you want to add:

import geonames

This assumes that you've saved the module in a file named "geonames.py".
-- 
http://mail.python.org/mailman/listinfo/python-list


Convert Latitude, Longitude To TimeZone

2013-03-31 Thread Steve B
Hi All

 

I'm new to python (4 days J) and was wondering if anyone out there can help
me

 

I am trying to get the time zones for latitude and longitude  coordinates
but am having a few problems

The mistakes are probably very basic

 

I have a table in a database with around 600 rows. Each row contains a lat
long coordinate for somewhere in the world

I want to feed these co-ordinates into a function and then retrieve the time
zone. The aim being to convert events which have a local time stamp within
each of these 600 places into UTC time

I found a piece of code
[http://blog.pamelafox.org/2012/04/converting-addresses-to-timezones-in.html
] which uses the function [https://gist.github.com/pamelafox/2288222]

 

When I try to run the code, I get the error geonames is not defined (This is
the function previously linked to)

I have applied for an account with geonames, I think I have just saved the
function file in the wrong directory or something simple. Can anyone help

 

#---


# Converts latitude longitude into a time zone

# REF: https://gist.github.com/pamelafox/2288222

# REF:
http://blog.pamelafox.org/2012/04/converting-addresses-to-timezones-in.html

#---


 

geonames_client = geonames.GeonamesClient('Username_alpha')

geonames_result = geonames_client.find_timezone({'lat': 48.871236, 'lng':
2.77928})

user.timezone = geonames_result['timezoneId']

 

Thanks

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


Python 3.2.3 and my blank page

2013-03-31 Thread Νίκος Γκρ33κ
Hello all,

i need some help
i recently changes pythoon 2.6 code => python 3.2.3 but my script although not 
producing any errors now doesnt display anything else but a blank page at 
htp://superhost.gr
can you help?

I tried MySQLdb, pymysql, oursql, but nothing happens.
i still get a blank page. I dont know what else to try since i see no error.

can anyone suggest anything?

I can even provide host:port user & pass for someone willing to take a look 
from the inside.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Why does 1**2**3**4**5 raise a MemoryError?

2013-03-31 Thread Jason Swails
On Sun, Mar 31, 2013 at 9:15 AM, Roy Smith  wrote:

>
> > $ prtstat 29937
> > Process: mongodState: S (sleeping)
> > [...]
> > Memory
> >   Vsize:   1998285 MB
> >   RSS: 5428 MB
> >   RSS Limit: 18446744073709 MB
>
> If I counted the digits right, that 1.9 TB.  I love the RSS Limit.  I'll
> be really impressed when somebody builds a machine with enough RAM to
> reach that :-)
>

http://www.ncsa.illinois.edu/UserInfo/Resources/Hardware/SGIAltix/TechSummary/

Look at co-compute2.  The indicated memory is available as shared memory
across all 512 cores.  And that's nothing---it can be configured with up to
64 TB of global shared memory:
http://www.sgi.com/products/servers/uv/configs.html

Impressed? :)

All the best,
Jason
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python GUI questions

2013-03-31 Thread Jan Riechers

On 19.03.2013 21:01, maiden129 wrote:

Hello,

I'm using python 3.2.3 and I'm making a program that show the of occurrences of 
the character in the string in Tkinter.

My questions are:

How can I make an empty Entry object that will hold a word that a user will 
enter?

How to make an empty Entry object that will hold a single character that the 
user will enter?

 [..]



Hello,

here is a very good documentation about Tkinter and its most likely that 
the same principals of coding apply to Python 3.x when it comes down to 
the Tkinter part:

http://www.pythonware.com/library/tkinter/introduction/index.htm

Also as an tip, you can make use of a StringVar object for example - 
those are (if Im not completely wrong) meant to hold values which you 
can then access from the interface. Alike a binding to any element 
holding text. Which should take care of the updating part if you call a 
proper "StringVar/yourVariableName".set method of that particular class.


As for the UI creation, have a look at that documentation, its very easy 
to navigate inside if you know what you are looking for.


Regards
Jan


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


Re: Why does 1**2**3**4**5 raise a MemoryError?

2013-03-31 Thread Roy Smith
In article ,
 Dave Angel  wrote:

> I'm typing this while a terminal is open doing the particular operation, 
> and the system doesn't seem in the least sluggish.
> 
> Currently the memory used is at 10gig, and while there are some pauses 
> in my typing, the system has not died.  This is on Linux Ubuntu 12.04.
> 
> At 15gig, there are some blockages, of maybe 5 secs each.

15 gig?  Feh.

> $ prtstat 29937
> Process: mongodState: S (sleeping)
> [...]
> Memory
>   Vsize:   1998285 MB
>   RSS: 5428 MB
>   RSS Limit: 18446744073709 MB

If I counted the digits right, that 1.9 TB.  I love the RSS Limit.  I'll 
be really impressed when somebody builds a machine with enough RAM to 
reach that :-)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Why does 1**2**3**4**5 raise a MemoryError?

2013-03-31 Thread Roy Smith
In article <8276eff6-9e5c-4060-b9e8-94fab6062...@googlegroups.com>,
 morphex  wrote:

> Aha, OK.  Thought I found a bug but yeah that makes sense ;)
> 
> While we're on the subject, wouldn't it be nice to have some cap there so 
> that it isn't possible to more or less block the system with large 
> exponentiation?

Every time we think we know a good upper bound to something (i.e. 
"nobody will ever need more than 64k of memory"), it turns out that 
limit is wrong.

There's great value in writing code which continues to work until it 
runs out of some external resource (i.e. memory, disk space, whatever).  
Eventually, somebody will want to do some calculation which you 
previously thought was absurd but turns out to be useful.

I don't use Python bugnums very often, but when I do, I'm really happy 
they're there.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: flaming vs accuracy [was Re: Performance of int/long in Python 3]

2013-03-31 Thread Mark Lawrence

On 31/03/2013 08:35, jmfauth wrote:

--

Neil Hodgson:

"The counter-problem is that a French document that needs to include
one mathematical symbol (or emoji) outside Latin-1 will double in size
as a Python string."

Serious developers/typographers/users know that you can not compose
a text in French with "latin-1". This is now also the case with
German (Germany).

---

Neil's comment is correct,


sys.getsizeof('a' * 1000 + 'z')

1026

sys.getsizeof('a' * 1000 + '€')

2040

This is not really the problem. "Serious users" may
notice sooner or later, Python and Unicode are walking in
opposite directions (technically and in spirit).


timeit.repeat("'a' * 1000 + 'ẞ'")

[1.1088995672090292, 1.0842266613261913, 1.1010779011941594]

timeit.repeat("'a' * 1000 + 'z'")

[0.6362570846925735, 0.6159128762502917, 0.6200501673623791]


(Just an opinion)

jmf



I'm feeling very sorry for this horse, it's been flogged so often it's 
down to bare bones.


--
If you're using GoogleCrap™ please read this 
http://wiki.python.org/moin/GoogleGroupsPython.


Mark Lawrence

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


Re: Why does 1**2**3**4**5 raise a MemoryError?

2013-03-31 Thread Roy Smith
In article <5157e6cc$0$29974$c3e8da3$54964...@news.astraweb.com>,
 Steven D'Aprano  wrote:

> For what it's worth, that last intermediate result (two to the power of 
> the 489-digit number) has approximately a billion trillion trillion 
> trillion trillion trillion trillion trillion trillion trillion trillion 
> trillion trillion trillion trillion trillion trillion trillion trillion 
> trillion trillion trillion trillion trillion trillion trillion trillion 
> trillion trillion trillion trillion trillion trillion trillion trillion 
> trillion trillion trillion trillion trillion trillion digits.
> 
> (American billion and trillion, 10**9 and 10**12 respectively.)

What's that in crore?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Why does 1**2**3**4**5 raise a MemoryError?

2013-03-31 Thread Dave Angel

On 03/31/2013 08:07 AM, morphex wrote:

Aha, OK.  Thought I found a bug but yeah that makes sense ;)

While we're on the subject, wouldn't it be nice to have some cap there so that 
it isn't possible to more or less block the system with large exponentiation?



There's an assumption there.  The Operating System should defend itself 
against starvation by any single process.


Besides, there are many ways for a process to run out of memory, and 
exponentiation is probably the least likely of them.  In general, an 
application cannot tell whether a particular memory allocation will 
succeed or not without actually trying the allocation.  If it fails, you 
get the exception.


I'm typing this while a terminal is open doing the particular operation, 
and the system doesn't seem in the least sluggish.


Currently the memory used is at 10gig, and while there are some pauses 
in my typing, the system has not died.  This is on Linux Ubuntu 12.04.


At 15gig, there are some blockages, of maybe 5 secs each.

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


Re: Why does 1**2**3**4**5 raise a MemoryError?

2013-03-31 Thread morphex
Aha, OK.  Thought I found a bug but yeah that makes sense ;)

While we're on the subject, wouldn't it be nice to have some cap there so that 
it isn't possible to more or less block the system with large exponentiation?

On Sunday, March 31, 2013 9:33:32 AM UTC+2, Steven D'Aprano wrote:
> On Sat, 30 Mar 2013 23:56:46 -0700, morphex wrote:
> 
> 
> 
> > Hi.
> 
> > 
> 
> > I was just doodling around with the python interpreter today, and here
> 
> > is the dump from the terminal:
> 
> > 
> 
> > morphex@laptop:~$ python
> 
> > Python 2.7.3 (default, Sep 26 2012, 21:53:58) [GCC 4.7.2] on linux2
> 
> > Type "help", "copyright", "credits" or "license" for more information.
> 
>  1**2
> 
> > 1
> 
>  1**2**3
> 
> > 1
> 
>  1**2**3**4
> 
> > 1L
> 
>  1**2**3**4**5
> 
> > Traceback (most recent call last):
> 
> >   File "", line 1, in 
> 
> > MemoryError
> 
>  
> 
>  
> 
> > Does anyone know why this raises a MemoryError?  Doesn't make sense to
> 
> > me.
> 
> 
> 
> Because exponentiation is right-associative, not left.
> 
> 
> 
> 1**2**3**4**5 is calculated like this:
> 
> 
> 
> 1**2**3**4**5
> 
> => 1**2**3**1024
> 
> => 1**2**373...481  #  489-digit number
> 
> => 1**(something absolutely humongous)
> 
> => 1
> 
> 
> 
> except of course you get a MemoryError in calculating the intermediate 
> 
> values.
> 
> 
> 
> In other words, unlike you or me, Python is not smart enough to realise 
> 
> that 1**(...) is automatically 1, it tries to calculate the humongous 
> 
> intermediate result, and that's what fails.
> 
> 
> 
> For what it's worth, that last intermediate result (two to the power of 
> 
> the 489-digit number) has approximately a billion trillion trillion 
> 
> trillion trillion trillion trillion trillion trillion trillion trillion 
> 
> trillion trillion trillion trillion trillion trillion trillion trillion 
> 
> trillion trillion trillion trillion trillion trillion trillion trillion 
> 
> trillion trillion trillion trillion trillion trillion trillion trillion 
> 
> trillion trillion trillion trillion trillion trillion digits.
> 
> 
> 
> (American billion and trillion, 10**9 and 10**12 respectively.)
> 
> 
> 
> 
> 
> 
> 
> -- 
> 
> Steven

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


ASCII versus non-ASCII [was Re: flaming vs accuracy [was Re: Performance of int/long in Python 3]]

2013-03-31 Thread Steven D'Aprano
On Sun, 31 Mar 2013 00:35:23 -0700, jmfauth wrote:


> This is not really the problem. "Serious users" may notice sooner or
> later, Python and Unicode are walking in opposite directions
> (technically and in spirit).
> 
 timeit.repeat("'a' * 1000 + 'ẞ'")
> [1.1088995672090292, 1.0842266613261913, 1.1010779011941594]
 timeit.repeat("'a' * 1000 + 'z'")
> [0.6362570846925735, 0.6159128762502917, 0.6200501673623791]

Perhaps you should stick to Python 3.2, where ASCII strings are no faster 
than non-ASCII strings.


Python 3.2 versus Python 3.3, no significant difference:

# 3.2
py> timeit.repeat("'a' * 1000 + 'ẞ'")
[1.7418999671936035, 1.7198870182037354, 1.763346004486084]

# 3.3
py> timeit.repeat("'a' * 1000 + 'ẞ'")
[1.8083378580026329, 1.818592812011484, 1.7922867869958282]



Python 3.2, ASCII vs Non-ASCII:

py> timeit.repeat("'a' * 1000 + 'z'")
[1.756322135925293, 1.8002049922943115, 1.721085958480835]
py> timeit.repeat("'a' * 1000 + 'ẞ'")
[1.7209150791168213, 1.7162668704986572, 1.7260780334472656]



In other words, if you stick to non-ASCII strings, Python 3.3 is no 
slower than Python 3.2.



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


Re: Why does 1**2**3**4**5 raise a MemoryError?

2013-03-31 Thread Dave Angel

On 03/31/2013 03:33 AM, Steven D'Aprano wrote:

On Sat, 30 Mar 2013 23:56:46 -0700, morphex wrote:


Hi.

I was just doodling around with the python interpreter today, and here
is the dump from the terminal:

morphex@laptop:~$ python
Python 2.7.3 (default, Sep 26 2012, 21:53:58) [GCC 4.7.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.

1**2

1

1**2**3

1

1**2**3**4

1L

1**2**3**4**5

Traceback (most recent call last):
   File "", line 1, in 
MemoryError




Does anyone know why this raises a MemoryError?  Doesn't make sense to
me.


Because exponentiation is right-associative, not left.

1**2**3**4**5 is calculated like this:

1**2**3**4**5
=> 1**2**3**1024
=> 1**2**373...481  #  489-digit number


Oops, you're right, it's 489.  I figured 488 but was wrong.




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


Re: flaming vs accuracy [was Re: Performance of int/long in Python 3]

2013-03-31 Thread jmfauth
--

Neil Hodgson:

"The counter-problem is that a French document that needs to include
one mathematical symbol (or emoji) outside Latin-1 will double in size
as a Python string."

Serious developers/typographers/users know that you can not compose
a text in French with "latin-1". This is now also the case with
German (Germany).

---

Neil's comment is correct,

>>> sys.getsizeof('a' * 1000 + 'z')
1026
>>> sys.getsizeof('a' * 1000 + '€')
2040

This is not really the problem. "Serious users" may
notice sooner or later, Python and Unicode are walking in
opposite directions (technically and in spirit).

>>> timeit.repeat("'a' * 1000 + 'ẞ'")
[1.1088995672090292, 1.0842266613261913, 1.1010779011941594]
>>> timeit.repeat("'a' * 1000 + 'z'")
[0.6362570846925735, 0.6159128762502917, 0.6200501673623791]


(Just an opinion)

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


Re: Why does 1**2**3**4**5 raise a MemoryError?

2013-03-31 Thread Steven D'Aprano
On Sat, 30 Mar 2013 23:56:46 -0700, morphex wrote:

> Hi.
> 
> I was just doodling around with the python interpreter today, and here
> is the dump from the terminal:
> 
> morphex@laptop:~$ python
> Python 2.7.3 (default, Sep 26 2012, 21:53:58) [GCC 4.7.2] on linux2
> Type "help", "copyright", "credits" or "license" for more information.
 1**2
> 1
 1**2**3
> 1
 1**2**3**4
> 1L
 1**2**3**4**5
> Traceback (most recent call last):
>   File "", line 1, in 
> MemoryError
 
 
> Does anyone know why this raises a MemoryError?  Doesn't make sense to
> me.

Because exponentiation is right-associative, not left.

1**2**3**4**5 is calculated like this:

1**2**3**4**5
=> 1**2**3**1024
=> 1**2**373...481  #  489-digit number
=> 1**(something absolutely humongous)
=> 1

except of course you get a MemoryError in calculating the intermediate 
values.

In other words, unlike you or me, Python is not smart enough to realise 
that 1**(...) is automatically 1, it tries to calculate the humongous 
intermediate result, and that's what fails.

For what it's worth, that last intermediate result (two to the power of 
the 489-digit number) has approximately a billion trillion trillion 
trillion trillion trillion trillion trillion trillion trillion trillion 
trillion trillion trillion trillion trillion trillion trillion trillion 
trillion trillion trillion trillion trillion trillion trillion trillion 
trillion trillion trillion trillion trillion trillion trillion trillion 
trillion trillion trillion trillion trillion trillion digits.

(American billion and trillion, 10**9 and 10**12 respectively.)



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


Re: Why does 1**2**3**4**5 raise a MemoryError?

2013-03-31 Thread Dave Angel

On 03/31/2013 02:56 AM, morphex wrote:

Hi.

I was just doodling around with the python interpreter today, and here is the 
dump from the terminal:

morphex@laptop:~$ python
Python 2.7.3 (default, Sep 26 2012, 21:53:58)
[GCC 4.7.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.

1**2

1

1**2**3

1

1**2**3**4

1L

1**2**3**4**5

Traceback (most recent call last):
   File "", line 1, in 
MemoryError




Does anyone know why this raises a MemoryError?  Doesn't make sense to me.




Perhaps you didn't realize that the expression will be done from right 
to left.  So first it calculates 4**5 which is 1024


Then it calculates 3**1024, which has 488 digits.  then it calculates 2 
to that power, which is a number large enough to boggle the mind.  That 
number's storage needs makes a few gigabytes seem like a molecule in the 
ocean.


Anyway, it never gets around to doing the 1**  part.

On the other hand, perhaps you wanted to do a different calculation:

>>> 1**2)**3)**4)**5)
1






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


Why does 1**2**3**4**5 raise a MemoryError?

2013-03-31 Thread morphex
Hi.

I was just doodling around with the python interpreter today, and here is the 
dump from the terminal:

morphex@laptop:~$ python
Python 2.7.3 (default, Sep 26 2012, 21:53:58) 
[GCC 4.7.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> 1**2
1
>>> 1**2**3
1
>>> 1**2**3**4
1L
>>> 1**2**3**4**5
Traceback (most recent call last):
  File "", line 1, in 
MemoryError
>>> 

Does anyone know why this raises a MemoryError?  Doesn't make sense to me.

Happy Easter!

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