Re: generating unique variable name via loops

2014-11-04 Thread Denis McMahon
On Tue, 04 Nov 2014 05:53:04 -0800, Fatih Güven wrote:

 Call employee1.name or employee2.salary and assign it to a new variable,
 something etc.

1) Put the file into a database.
2) database calls

-- 
Denis McMahon, denismfmcma...@gmail.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Classes

2014-11-03 Thread Denis McMahon
On Mon, 03 Nov 2014 06:29:39 +, Dan Sommers wrote:

 On Mon, 03 Nov 2014 03:12:32 +, Denis McMahon wrote:
 
 Quadrilateral
 Parallelogram
 Square Rectangle Rhombus Diamond (4 sides eq)
 Trapezoid
 Arrowhead
 
 What's the difference between a Diamond and a Rhombus?

Oops, I was thinking a rhombus was a general parallelogram, my mistake.

-- 
Denis McMahon, denismfmcma...@gmail.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Classes

2014-11-02 Thread Denis McMahon
On Sat, 01 Nov 2014 12:42:10 -0400, Seymore4Head wrote:

 OK  Maybe I misunderstood the question.
 
 My answer to you then is ..I don't know.  I will have to think about
 it some more.

The question (I thought) was to write a class for Square that inherited a 
class Rectangle but imposed on it the additional constraints of a square 
over a rectangle, namely that length == width.

To do this, you need to override the inherited methods to set length and 
width with new methods to set length and width as follows:

when setting length, also set width equal to length.
when setting width, also set length equal to width.

For bonus points, if your constructor accepts width and length parameters 
(from the Rectangle constructor) then detect if they are different and 
raise a suitable error.

from math import sqrt

class SquareGeometryError(Exception):
The parameters create an illegal geometry for a square
pass

class Rectangle:

def __init__(self,length,width):
self.length=length 
self.width=width

def area(self):
return self.length*self.width

def perimeter(self):
return 2*self.length+2*self.width

def diagonal(self):
return sqrt(self.length*self.length+self.width*self.width)

def get_width(self):
return self.width

def get_length(self):
return self.length

def set_width(self, width):
self.width = width

def set_length(self, length):
self.length = length

class Square(Rectangle):

_def _init__(self, length, width):
if not length == width:
raise SquareGeometryError(Length must equal width)
self.length = length # or width
self.width = length # or width

def set_width(self, width):
self.length = width
self.width = width

def set_length(self, length):
self.length = length
self.width = length

Note that to make my square, I only need to over-ride those rectangle 
methods which allow the setting of length and width to enforce squareness 
upon the square. All the other methods of rectangle will work equally 
well for the square.

-- 
Denis McMahon, denismfmcma...@gmail.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Classes

2014-11-02 Thread Denis McMahon
On Sun, 02 Nov 2014 21:32:13 +1100, Tim Delaney wrote:

 On 2 November 2014 20:50, Denis McMahon denismfmcma...@gmail.com
 wrote:
 
 The question (I thought) was to write a class for Square that inherited
 a class Rectangle but imposed on it the additional constraints of a
 square over a rectangle, namely that length == width.


 I'm late to the party and this has already been partially addressed in
 the thread, but it always annoys me. A square is as much a rhombus with
 90 degree angles as it is a rectangle with equal length and width, and
 yet I *never* see the former given as an option.
 
 If course, that's probably because rectangles have a multitude of uses
 for user interfaces, whilst other quadrilaterals are somewhat less
 useful.

And perhaps that also addresses the square - rectangle (or circle - 
ellipse) issue - square, rectangle and rhombus are all forms of 
quadrilateral, and perhaps should all inherit a base class Quadrilateral, 
rather than trying (and partially failing) to inherit each other.

-- 
Denis McMahon, denismfmcma...@gmail.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Classes

2014-11-02 Thread Denis McMahon
On Sun, 02 Nov 2014 11:31:12 -0500, Dennis Lee Bieber wrote:

 On Sun, 2 Nov 2014 12:27:06 + (UTC), Denis McMahon
 denismfmcma...@gmail.com declaimed the following:
 
On Sun, 02 Nov 2014 21:32:13 +1100, Tim Delaney wrote:

 If course, that's probably because rectangles have a multitude of uses
 for user interfaces, whilst other quadrilaterals are somewhat less
 useful.

And perhaps that also addresses the square - rectangle (or circle -
ellipse) issue - square, rectangle and rhombus are all forms of
quadrilateral, and perhaps should all inherit a base class
Quadrilateral,
rather than trying (and partially failing) to inherit each other.
 
   I'd class them as parallelograms -- as they differ from a 
trapezoid in
 that opposite faces are parallel... Not to mention arrow heads where
 two adjacent sides actually bend inwards.

So:

Quadrilateral
Parallelogram
Square
Rectangle
Rhombus
Diamond (4 sides eq)
Trapezoid
Arrowhead

Is an arrowhead a trapezoid?

-- 
Denis McMahon, denismfmcma...@gmail.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python Style Question

2014-10-30 Thread Denis McMahon
On Fri, 31 Oct 2014 09:48:10 +1100, Steven D'Aprano wrote:

 MRAB wrote:

 How about:
 
 int(str(obj).strip(''))
 
 Absolutely not.
 
 obj = '1\n\n\n\n'  # not valid JSON load_int(obj)
 = raises ValueError int(str(obj).strip(''))
 = wrongly returns 1

How about

#!/usr/bin/python

import re, json

l = [1, -1, 0, '+2', '2', '-2', '0', '+3', '3', '-3', '0', 
 json.dumps(-4), json.dumps(4), json.dumps(0), 
 'x', 'sqjklsqjk__', (5, 6), 
 7.7, -7.7, '8.8', '+8.8', '-8.8', '9.9', '+9.9', '-9.9']

patt1 = re.compile(r'^([-+]?\d+)$')
patt2 = re.compile(r'^([-+]?\d+)$')

def getTheInt(x):

if isinstance(x,int):
return x

if isinstance(x,str):
tmp = patt1.match(x)

if tmp:
return int(tmp.group(1))

tmp = patt2.match(x)

if tmp:
return int(tmp.group(1))

return None

a = []

for n in l:
a.append(getTheInt(n))

print a

# end of code

prints:

[1, -1, 0, 2, 2, -2, 0, 3, 3, -3, 0, -4, 4, 0, None, None, None, None, 
None, None, None, None, None, None, None]

I know re matching the strings may be overkill, but it may be the best 
way of checking that the string contains the expected character format to 
convert to an int.

-- 
Denis McMahon, denismfmcma...@gmail.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Anyone know the solution

2014-10-29 Thread Denis McMahon
On Mon, 27 Oct 2014 08:10:04 -0700, emmanueloje wrote:

 Write a program ...

Hey dudester

I coded a solution for you, you can get it here:

http://www.sined.co.uk/tmp/names.py.txt

Make sure you leave all the comments in so your instructor realises how 
much effort you went in to in researching how to code this.

-- 
Denis McMahon, denismfmcma...@gmail.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: A bug?

2014-10-28 Thread Denis McMahon
On Tue, 28 Oct 2014 01:29:28 +, Joshua Landau wrote:

 On 28 October 2014 00:36, Denis McMahon denismfmcma...@gmail.com
 wrote:

 d = [[list(range(1,13))[i*3+j] for j in range(3)] for i in range(4)]
 
 A quick note. Ranges (even 2.7's xrange) are all indexable. The cast to
 a list isn't needed.

Until you apply Chris' slicing trick, and then:

 [list(range(1,13))[i*3:i*3+3] for i in range(4)]
[[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11, 12]]
 [range(1,13)[i*3:i*3+3] for i in range(4)]
[range(1, 4), range(4, 7), range(7, 10), range(10, 13)]
 

Depends how important it is that you get a list and not a range object ;)

(Thinking back to a recent discussion where someone was taking str(range
(x)) and not getting the expected results)

-- 
Denis McMahon, denismfmcma...@gmail.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: memory, PE files, etc...

2014-10-28 Thread Denis McMahon
On Mon, 27 Oct 2014 10:16:43 -0700, kiuhnm03 wrote:

 I'd like to write one or more scripts that analyze processes in memory
 on Windows 7. I used to do these things in C++ by using native Win32 API
 calls.
 How should I proceed in python? Any pointers?

This seems to be a very common request. Does anyone know why?

-- 
Denis McMahon, denismfmcma...@gmail.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Anyone know the solution

2014-10-27 Thread Denis McMahon
On Mon, 27 Oct 2014 08:10:04 -0700, emmanueloje wrote:

 Write a program that reads the contents of the two files into two
 separate lists.

Yep, know how to do that

 The user should be able to enter a boy's name, a girl's
 name or both

Yep, know how to do that

 and the application will display messages
 indicating whether the names were among the most popular.

Nope, not sure how to do that, please define the algorithm for 
determining a most popular name

Determining if the name is in either of the lists is easy, know how to do 
that, but I'm not sure from your problem description if that's your 
definition of a most popular name or not.

-- 
Denis McMahon, denismfmcma...@gmail.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: A bug?

2014-10-27 Thread Denis McMahon
On Mon, 27 Oct 2014 09:01:57 -0700, uma...@gmail.com wrote:

 I use python 3.4.0 version. In the course of developing / running a
 python program, I have encountered a problem. I have reproduced below a
 simple program to bring it out.
  
  
 d = [[0]*3]*4 dd = [1,2,3,4,5,6,7,8,9,10,11,12]
 for i in range(4):
 ...   for j in range(3): d[i][j] = dd[i*3+j]
 ...
 d
 [[10, 11, 12], [10, 11, 12], [10, 11, 12], [10, 11, 12]]
 
 d is not transferred to dd as expected?
 Of course I can use 'append'  do my job (less elegantly though).

Not sure if this is elegant or not:

d = [[list(range(1,13))[i*3+j] for j in range(3)] for i in range(4)]

but it seems to be a one-line solution for what you're trying to do.

-- 
Denis McMahon, denismfmcma...@gmail.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: id == vs is

2014-10-26 Thread Denis McMahon
On Sun, 26 Oct 2014 17:12:29 -0700, Dan Stromberg wrote:

 Are the following two expressions the same?
 
 x is y
 
 Id(x) == id(y)

No, although if Id and id were the same function, they might be 
equivalent in some cases. 

-- 
Denis McMahon, denismfmcma...@gmail.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: I am out of trial and error again Lists

2014-10-25 Thread Denis McMahon
On Sat, 25 Oct 2014 15:01:54 +, Grant Edwards wrote:

 On 2014-10-24, Denis McMahon denismfmcma...@gmail.com wrote:
 On Fri, 24 Oct 2014 10:38:31 -0400, Seymore4Head wrote:

 Thanks everyone for your suggestions.

 Try loading the following in codeskulptor:

 http://www.codeskulptor.org/#user38_j6kGKgeOMr_0.py

 No.

I wasn't replying to you, I was replying to S4H.

 We[1] aren't intested in whatever Python-like language is implemented in
 codeskulptor.

However S4H may be, and one thing I can be sure is that if I give him a 
cs url, he will at least be running the exact same python code I typed in 
the same python environment, and hence I know what results he should see, 
namely the same ones I saw.

-- 
Denis McMahon, denismfmcma...@gmail.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: I am out of trial and error again Lists

2014-10-25 Thread Denis McMahon
On Fri, 24 Oct 2014 20:15:02 -0400, Seymore4Head wrote:

 On Wed, 22 Oct 2014 16:30:37 -0400, Seymore4Head
 Seymore4Head@Hotmail.invalid wrote:
 
 name=012

name is a string of 3 characters

 b=list(range(3))

b is a list of 3 numbers

 print (name[1])

name[1] is the string 1

 print (b[1])

b[1] is the number 1

 if name[1] == b[1]:
 print (Eureka!)

This didn't happen

 else:
 print (OK, I get it)

This happened

-- 
Denis McMahon, denismfmcma...@gmail.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: I am out of trial and error again Lists

2014-10-24 Thread Denis McMahon
On Fri, 24 Oct 2014 10:38:31 -0400, Seymore4Head wrote:

 I tried list(range(10)  

This is missing a )

It probably sat there waiting for you to finish the line.

list(range(10))

You have two ( in the line, you need two ) to match them. 

 I thought that would work in Python 3.  It
 didn't.

It does if you enter it properly.

also try:

str(list(range(10))) 

Note that that has three ( and three ) on the line.

-- 
Denis McMahon, denismfmcma...@gmail.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: I am out of trial and error again Lists

2014-10-24 Thread Denis McMahon
On Fri, 24 Oct 2014 14:15:13 -0400, Seymore4Head wrote:

 I do understand that.  7 is a number and 7 is a string.
 What my question was...and still is...is why Python 3 fails when I try
 using y=1 800 get charter
 
 y in range str(range(10))
 should work because y is a string and str(range(10)) should be y in
 str(1) fails.
 It doesn't give an error it's just not True when y is a number.

This is because str(range(10)) does not do what you think it does.

In python 2.x, str(range(10)) creates a string representation of the 
complete list, not a list of the string representation of the separate 
list elements. '[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]'

In python 3.x, str(range(10)) creates a string representation of the list 
object. 'range(0, 10)'

the only single digit strings in the python3 representation are 0 and 
1

To recreate the python2 behaviour in python 3, use:

str(list(range(10)))

which gives

'[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]'

howver the test:

if x.isdigit():

is much better.

But finally, with your telephone number decoder, look at:

http://www.codeskulptor.org/#user38_QnR06Upp4AH6h0Q.py

-- 
Denis McMahon, denismfmcma...@gmail.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: I am out of trial and error again Lists

2014-10-24 Thread Denis McMahon
On Fri, 24 Oct 2014 10:38:31 -0400, Seymore4Head wrote:

 Thanks everyone for your suggestions.

Try loading the following in codeskulptor:

http://www.codeskulptor.org/#user38_j6kGKgeOMr_0.py

-- 
Denis McMahon, denismfmcma...@gmail.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: I am out of trial and error again Lists

2014-10-24 Thread Denis McMahon
On Fri, 24 Oct 2014 15:07:06 -0400, Seymore4Head wrote:

 On Fri, 24 Oct 2014 19:40:39 +0100, Mark Lawrence
 breamore...@yahoo.co.uk wrote:
 
On 24/10/2014 19:20, Seymore4Head wrote:
 I meant to type:
 if y in range(1,10) doesn't work.
 Sigh Sorry


How many more times, state what you expect to happen and what actually
happens.  doesn't work is useless.  Please read this http://sscce.org/
 
 Good suggestion.
 OK  how is this?
 It doesn't print what I expect.
 Does it print what you expect?
 
 name=123-xyz-abc
 for x in name:
 if x in range(10):
 print (Range,(x))
 if x in str(range(10)):
 print (String range,(x))
 
 http://i.imgur.com/EGKUpAb.jpg

I suspect you're discovering the difference between the python2 and 
python3 range() functions, and what happens when you encapsulate them in 
string.

I've already posted about this once this evening.

-- 
Denis McMahon, denismfmcma...@gmail.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: I am out of trial and error again Lists

2014-10-24 Thread Denis McMahon
On Fri, 24 Oct 2014 17:35:34 -0400, Seymore4Head wrote:

But finally, with your telephone number decoder, look at:

http://www.codeskulptor.org/#user38_QnR06Upp4AH6h0Q.py
 
 That is much cleaner than mine.  Nice.
 
 I did make one more change to mine that makes it easier to read. I
 changed treating all  -()  With a space.
 I am still thinking about how to treat the large space if it is a digit
 instead:
 1 800 555 

Note that my decoder assumes anything other than a letter can be copied 
straight to the output string.

-- 
Denis McMahon, denismfmcma...@gmail.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: I am out of trial and error again Lists

2014-10-24 Thread Denis McMahon
On Fri, 24 Oct 2014 16:58:00 -0400, Seymore4Head wrote:

 I make lots of typing mistakes.  It is not that. Did you see the short
 example I posted?
 
 name=123-xyz-abc
 for x in name:
 if x in range(10):
 print (Range,(x))
 if x in str(range(10)):
 print (String range,(x))
 
 It doesn't throw an error but it doesn't print what you would expect.

It prints exactly what I expect.

Try the following:

print(str(range(10)), type(str(range(10
print(str(list(range(10))), type(str(listr(range(10)

In python 3, str(x) just wraps x up and puts it in a string. range(x) 
generates an iterable range object.

hence str(range(10)) is a string telling you that range(10) is an iterable 
range object with certain boundaries.

However, list(iterable) expands the iterable to the full list of possible 
values, so str(list(range(10))) is a string representation of the list 
containing the values that the iterable range(10) creates.

Note that whether you're looking at a string representation of a value or 
the value itself is a lot clearer in the interpreter console where 
strings are displayed with quotes.

-- 
Denis McMahon, denismfmcma...@gmail.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: I am out of trial and error again Lists

2014-10-24 Thread Denis McMahon
On Fri, 24 Oct 2014 18:58:04 -0400, Seymore4Head wrote:

 On Wed, 22 Oct 2014 16:30:37 -0400, Seymore4Head
 Seymore4Head@Hotmail.invalid wrote:

OK, assuming you tried to run this in python3, not python2 or 
codeskulptor.

 name=123-xyz-abc
 a=range(10)

  a is an iterable object giving the numbers 0 through 9

 b=list(range(10))

  b is an list containing the numbers 0 through 9

 c=str(list(range(10)))

  c is an string representation of a list containing the numbers 0 
through 9

 print (a,(a))
 print (b,(b))
 print (c,(c))
 
 for x in name:

 ^ x is a string representing one character in name

 if x in a:
 print (a,(x))

  here you are looking for a string x amongst the numbers yielded by 
an iterable

 if x in b:
 print (b,(x))

  here you are comparing a string x with the elements of a list of 
numbers

 if x in c:
 print (c,(x))

  here you are comparing a string x with the characters in a string 
representation of a list of numbers

 B is type list and C is type str.
 I guess I am still a little too thick.  I would expect b and c to work.
 http://i.imgur.com/dT3sEQq.jpg

a is the range object: range(0, 9)
b is the list: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
c is the string: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]

When you try and compare a character x eg 8 with the numbers yielded by 
the iterable a, none of them match because character 8 is not the same 
as number 8

When you try and compare a character x eg 8 with the elements of the 
list b, none of them match because character 8 is not the same as 
number 8

When you try and compare a character x eg 8 with the string 
representation of the list b, you get a match of x 8 to the 25th 
character of string c which is also 8.

-- 
Denis McMahon, denismfmcma...@gmail.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: I am out of trial and error again Lists

2014-10-23 Thread Denis McMahon
On Wed, 22 Oct 2014 18:30:17 -0400, Seymore4Head wrote:

 One more question.
 if y in str(range(10)
 Why doesn't that work.
 I commented it out and just did it long hand

In the last post I made, I suggested to you the mechanisms of using the 
python console and using code which prints out variables after every line.

Try the following 3 commands at the console:

 10
 range(10)
 str(range(10))

10 is just the number 10
range(10) is a list of 10 integers in the sequence 0 to 9
str(range(10)) is?

Please stop the stab in the dark trial and error coding followed by the 
plaintive why doesn't it work wailing, and put some effort into reading 
and understanding the manuals.

If a function doesn't do what you expect with the input you think you've 
given it, there is invariably one of three causes:

a) The input you actually gave it isn't the input you thought you gave it
b) You didn't read the description of the function, and it doesn't in 
fact do what you thought
c) Both a and b above

-- 
Denis McMahon, denismfmcma...@gmail.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: I am out of trial and error again Lists

2014-10-23 Thread Denis McMahon
On Wed, 22 Oct 2014 19:11:51 -0400, Seymore4Head wrote:

 On Wed, 22 Oct 2014 22:43:14 + (UTC), Denis McMahon
 denismfmcma...@gmail.com wrote:
 
On Wed, 22 Oct 2014 16:30:37 -0400, Seymore4Head wrote:

 def nametonumber(name):
 lst=[]
 for x,y in enumerate (name):
 lst=lst.append(y)
 print (lst)
 return (lst)
 a=[1-800-getcharter]
 print (nametonumber(a))#18004382427837
 
 
 The syntax for when to use a () and when to use [] still throws me a
 curve.
 
 For now, I am trying to end up with a list that has each character in
 a as a single item.
 
 I get:
 None None

First of all, an empty list is created with:

emptylist = []

whereas

x = []

creates a list containing one element, that element being an empty
string. Not the same thing!

Did you try stepping through your code line by line in the interpreter
to see what happened at each step?

note that append is a method of a list object, it has no return value,
the original list is modified in place.

 l = [a,b,c]   # declare a list l.append( d ) # use the
 append method l   # show the list
['a', 'b', 'c', 'd']

So your line:

lst = lst.append(y)

should be:

lst.append(y)

Finally, did you really intend to pass a single element list into the
function, or did you intend to pass a string into the function?

 Those string errors were desperate attempts to fix the append error I
 didn't understand.

If you don't understand the error, that is the point that you should ask 
for help, rather than make stab in the dark attempts to fix it and then 
asking why the solutions don't work.

-- 
Denis McMahon, denismfmcma...@gmail.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: I am out of trial and error again Lists

2014-10-23 Thread Denis McMahon
On Thu, 23 Oct 2014 10:04:56 -0400, Seymore4Head wrote:

 On Thu, 23 Oct 2014 09:15:16 + (UTC), Denis McMahon
 denismfmcma...@gmail.com wrote:

Try the following 3 commands at the console:

You obviously didn't, so I'll try again. Try each of the following three 
commands in the python console at the  prompt.

1) 10
2) range(10)
3) str(range(10))

Show *and* describe the output in each case. Describing the output that 
you see is actually the key here, as it will allow us to assess whether 
you understand what you are actually seeing or not, and if you don't 
understand the output you see in the console, then we need to fix that 
very fundamental and basic issue before moving on to more complex stuff!

 Ok Thanks

You were expected to answer the question in the original. I have now set 
it as a clearer and more specific task.

If you're not going to do these things that are intended to help you 
learn some of the basic features of the language, then I and everyone 
else here that has so far been attempting to help you are wasting our 
time.

-- 
Denis McMahon, denismfmcma...@gmail.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: I am out of trial and error again Lists

2014-10-23 Thread Denis McMahon
On Thu, 23 Oct 2014 16:25:28 +0200, giacomo boffi wrote:

 Rustom Mody rustompm...@gmail.com writes:
 
 [As best as I can make out the OP is not using the standalone
 interpreter nor idle nor (the many options like)
 python-interpreter-inside-emacs nor ipython nor ...
 
 but CodeSkulptor http://www.codeskulptor.org/]
 
 CodeSkulptor has been mentioned recently by S4H, and he had explained
 why he uses CodeSkulptor, but I cannot remember anything of the
 explanation...

CodeSkulptor is a tool used by a group of instructors at RICE to teach an 
on-line python programming course in a web browser environment. It may be 
a python IDE and interpreter implemented in HTML, CSS and javascript, I'm 
not sure.

IO is handled by a package called simplegui, and I believe there's a 
wrapper for tkinter that presents simplegui if you want to run code 
written for codeskulptor outside of the codeskulptor environment.

-- 
Denis McMahon, denismfmcma...@gmail.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Truthiness

2014-10-23 Thread Denis McMahon
On Thu, 23 Oct 2014 16:47:27 +0200, Alain Ketterlin wrote:

 says: In the context of Boolean operations, and also when expressions
 are used by control flow statements, the following values are
 interpreted as false: False, None, numeric zero of all types, and empty
 strings and containers (including strings, tuples, lists, dictionaries,
 sets and frozensets). All other values are interpreted as true.

Yep, and I expect this to bite S4H shortly, when he can't understand why 
the following are not all of the same truthiness:

0 (falsey - numeric 0)
[] (falsey - empty set)
 (falsey - empty string)
[] (truthy - non empty set)
[0] (truthy - non empty set)

-- 
Denis McMahon, denismfmcma...@gmail.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: I am out of trial and error again Lists

2014-10-22 Thread Denis McMahon
On Wed, 22 Oct 2014 16:30:37 -0400, Seymore4Head wrote:

 def nametonumber(name):
 lst=[]
 for x,y in enumerate (name):
 lst=lst.append(y)
 print (lst)
 return (lst)
 a=[1-800-getcharter]
 print (nametonumber(a))#18004382427837
 
 
 The syntax for when to use a () and when to use [] still throws me a
 curve.
 
 For now, I am trying to end up with a list that has each character in
 a as a single item.
 
 I get:
 None None

First of all, an empty list is created with:

emptylist = []

whereas

x = []

creates a list containing one element, that element being an empty 
string. Not the same thing!

Did you try stepping through your code line by line in the interpreter to 
see what happened at each step?

note that append is a method of a list object, it has no return value, 
the original list is modified in place.

 l = [a,b,c]   # declare a list
 l.append( d ) # use the append method
 l   # show the list
['a', 'b', 'c', 'd']

So your line:

lst = lst.append(y)

should be:

lst.append(y)

Finally, did you really intend to pass a single element list into the 
function, or did you intend to pass a string into the function?

There is a difference between:

a=[1-800-getcharter] 

which creates a single element list, the one element is the string 1-800-
getcharter, and:

a=1-800-getcharter

which creates a string variable with the value 1-800-getcharter

when you pass a list containing a string to your function, enumerate will 
look at each list element, so if your list contains one string, enumerate 
will return the pair 0, the_string, so the string gets appended to your 
empty list as a single item.

The code I think you wanted to write is as follows:

def nametonumber(name):
lst=[]
for x,y in enumerate(name):
lst.append(y)
return lst

a=1-800-getcharter
print ( nametonumber(a) )

I suggests that you study very carefully the differences between this and 
your original code until you understand the reason and effect of every 
difference, as only by doing so will you discover the misconceptions 
which you seem to be operating under, and until you can get some of those 
straightened out, you're not going to make a lot of progress.

Try running the original code and my suggested alternative line by line 
in the interpreter, and examining the state of relevant variables after 
each line of execution.

Here's a code file with both your original code and my modified code with 
comprehensive print statements inserted for debugging. By referencing the 
debugging statements back to the code, you should be able to determine 
exactly where in your original code the value of none comes from.

### code starts

print ( original code )

def nametonumber(name):
print (a) name =, name)
lst=[]
print ( b) lst = , lst )
for x,y in enumerate (name):
print ( c) x = , x, ; y = , y, ; lst = , lst )
lst=lst.append(y)
print ( d) lst = , lst )
print (lst)
return (lst)

a=[1-800-getcharter]
print ( e) a = , a )
print (nametonumber(a))

print ( modified code )

def nametonumber2(name):
print (f) name =, name)
lst=[]
print ( g) lst = , lst )
for x,y in enumerate(name):
print ( h) x = , x, ; y = , y, ; lst = , lst )
lst.append(y)
print ( i) lst = , lst )
return lst

a=1-800-getcharter
print ( j) a = , a )
print ( nametonumber2(a) )

### code ends

If you run the above code exactly as it is, you should see in the output 
how the enumeration reacts according to the different data it is given to 
enumerate, and also where lst is assigned the value none.

As I said above, getting your head round why this is happening is 
essential, and I really do suggest that you slow down and try and 
understand these basic concepts, because at the moment it seems you are 
striving to attempt more and more complicated things without 
understanding the basics upon which they are constructed, and like many 
other similar newsgroups, it's been my experience in the past that there 
is limited tolerance here for people who repeatedly make the same basic 
errors without learning from them.

-- 
Denis McMahon, denismfmcma...@gmail.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Building lists

2014-10-20 Thread Denis McMahon
On Mon, 20 Oct 2014 20:40:18 +0100, MRAB wrote:

 There are a number of stores, so that would be a list of stores. For
 each store you want the price of each item, so that would be a dict
 where the key is the item and the value is the price of that item. That
 means it would be a list of dicts.
 
 Does that help?

It think it would be a dict of dicts:

shopping = { store1 : { item1: price1, item2: price2, ...  }, 
store2 : { item3: price3, item4: price4, ... }, ... }

-- 
Denis McMahon, denismfmcma...@gmail.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Building lists

2014-10-20 Thread Denis McMahon
On Mon, 20 Oct 2014 15:49:15 -0400, Seymore4Head wrote:

 For starters I would like to know if you can make a single item list and
 then turn it into a 2 item list.  Is there a command for that?

Yes, it's called assignment. You can for example change a member of a 
list from an string to a tuple such as ( string, number ):

 x = [ fred, jim, susan ]
 x[x.index(jim)] = ( jim, 11, )
 print x
['fred', ('jim', 11), 'susan']

 Do you have to know the number of items the list will have before making
 it?

No. See the append() method of the list object.

-- 
Denis McMahon, denismfmcma...@gmail.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to select every other line from a text file?

2014-10-13 Thread Denis McMahon
On Mon, 13 Oct 2014 10:38:48 -0700, Rff wrote:

 I have a text file. Now it is required to select every other line of
 that text to
  generate a new text file. I have read through Python grammar, but still
  lack the idea at the beginning of the task. Could you tell me some
  methods to get this?

So this could be written as an algorithm something like:

1/ open the input file
2/ open the output file
3/ while there are lines to read from the input file
3/1/ read a line from the input file
3/2/ if I should output this line
3/2/1/ write line to output file
4/ close the input file
5/ close the output file

Or in several other ways, and once you have an algorithm, you can start 
coding it (or implementing it in the programming language of your choice, 
whichever form of words best pleases your perfesser).

-- 
Denis McMahon, denismfmcma...@gmail.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: what is wrong with this script and how do I get the value in a php script

2014-10-12 Thread Denis McMahon
On Sun, 12 Oct 2014 07:24:52 -0700, martijnperdaan wrote:

 what is wrong with this script and how do I get the value Rij1 and Rij2
 and Rij3 and Rij4 and Rij5 and Rij6 in a php script

I can see several pythonic errors in your script, however as for what is 
wrong, I see no indication from you of what you expect it to do, what 
output you expect, what error messages you get when you try and run it 
etc.

Perhaps a better subject would have been how to read gpio on raspberry 
pi

It also helps if you can reduce your code example to the minimum needed 
to demonstrate the error. In this case, I would suggest that once you can 
read one input correctly, you should be able to expand that code to read 
all inputs.

The code below might help (uses 2.x style print):

import RPi.GPIO as GPIO

GPIO.setmode(mode)
GPIO.setup(17, GPIO.IN)

if GPIO.input(17) == GPIO.HIGH:
print True
else:
print False

-- 
Denis McMahon, denismfmcma...@gmail.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: while loop - multiple condition

2014-10-12 Thread Denis McMahon
On Sun, 12 Oct 2014 17:08:00 +, Shiva wrote:

 while ans.lower() != 'yes' or ans.lower()[0] != 'y':

while ans.lower() is not equal to yes
   or ans.lower()[0] is not equal to y

the loop will continue to run

Note that if ans.lower() == 'y', then the first clause ( ans.lower() != 
'yes' ) is true, so the loop will continue to run, ignoring the result of 
the second clause ( ans.lower()[0] != 'y' ), This will also be the case 
if you reverse the order of the clauses.

It seems that you need a better understanding of combinatorial logic, 
perhaps http://www.ee.surrey.ac.uk/Projects/Labview/boolalgebra/
index.html#booleantheorems will help.

-- 
Denis McMahon, denismfmcma...@gmail.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Hi Guys... Reading XML using Jython code

2014-10-09 Thread Denis McMahon
On Thu, 09 Oct 2014 05:30:21 -0700, Venugopal Reddy wrote:

 XML parsing using Jython..

 In my XML file , One main node is there and Multiple child tags are
 there. But In Child tags , same name repeated twice (like subject tag
 repeated twice)

 Please help me on this

Normally, when pulling data from an xml document, you'll get a collection 
of some sort:

Are you trying to select every subject of every child, the first subject 
of every child, the last subject of every child, or some nth subject of 
every child?

You may need to go back to your specification code and look again at how 
you're specifying which node(s) you want to select.

-- 
Denis McMahon, denismfmcma...@gmail.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Practice question

2014-10-06 Thread Denis McMahon
On Sun, 05 Oct 2014 19:02:31 -0400, Seymore4Head wrote:

 For the record, I don't want a hint.  I want the answer.
 I see a practice question is similar to this.
 15 = x  30  And it wants a similar expression that is equivalent.

I think part of the problem here is that you don't understand the 
expression.

The expression:

15 = x  30

contains two conditions:

15 = x

x  30

For the whole expression to be true, both conditions must be true, hence 
the equivalence is:

(15 = x) and (x  30)

to test this in python command line, see if the two different expressions 
give the same result for a suitable range of values of x:

for x in range(50):
if not (15 = x  30) == ((15 = x) and (x  30)):
print discrepancy

or

for x in range(50):
if (15 = x  30) == ((15 = x) and (x  30)):
print ok

-- 
Denis McMahon, denismfmcma...@gmail.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Looking for volunteers developing wsgi Webmailer Application!

2014-10-04 Thread Denis McMahon
On Sat, 04 Oct 2014 17:52:18 +0200, Tamer Higazi wrote:

 I am planing to develop on longer time a n open source Webmailer written
 in Python (not 2.7.x) with:

Because the world really needs another webmailer spamengine.

-- 
Denis McMahon, denismfmcma...@gmail.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Issue in printing top 20 dictionary items by dictionary value

2014-10-04 Thread Denis McMahon
On Sat, 04 Oct 2014 09:11:43 +, Shiva wrote:

 I have written a function that -reads a file -splits the words and
 stores it in a dictionary as word(key) and the total count of word in
 file (value).
 
 I want to print the words with top 20 occurrences in the file in reverse
 order - but can't figure it out. Here is my function:

Once you've generated your dictionary, use a list comprehension to turn 
it into a list of tuples of ( word, count ). Sort the list of tuples 
according to the count element. Select the top 20. copy it to a new list 
and reverse that list. now loop through the second list and print results.

-- 
Denis McMahon, denismfmcma...@gmail.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Function passed as an argument returns none

2014-10-01 Thread Denis McMahon
On Wed, 01 Oct 2014 22:37:13 +, Shiva wrote:

 Hi,
 I am learning Python (version 3.4) strings.I have a function that takes
 in a parameter and prints it out as given below.
 
 def donuts(count):
   if count = 5:
 print('Number of donuts: ',count)
   else:
 print('Number of donuts: many') return
 
 It works fine if I call donuts(5)
 
 It returns:

No it doesn't

 we have 5 DN  (as expected)

It doesn't return anything, it prints something out.

Printing something out from within a function is not the same as 
returning something.

Consider the following::

def nonsense( something ):
print( something is, something )
return ( 5, elephants, { monkey: peanut, baboon: 
 banana, numbers: ( 1, ), }, [ 1, 2, 3, 4, 5, 
 mouse,( -6.34565e-35, 4.765213e84, ), ], 
 None, True, False, )

print( nonsense( 10 ) is, nonsense( 10 ) )
print( nonsense( None ) is, nonsense( None ) )
print( nonsense( ( 5, \donuts\, ) ) is, nonsense( ( 5, donuts, ) ) )

The above code shows there is no automatic connection between data output 
carried out within a function and the value (if any) returned by that 
function.

-- 
Denis McMahon, denismfmcma...@gmail.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Storage Cost Calculation

2014-09-29 Thread Denis McMahon
On Sun, 28 Sep 2014 20:07:31 +, Duncan Booth wrote:

 Later on the B+ had 64k of RAM and the B+128 had 128k of RAM and in each
 case the additional RAM was paged in as necessary but I don't think the
 RAM in the B was ever expandable.

You could get various expansions to page multiple roms, I had a machine 
at one point with 15 multiple internally and a zif socket on top.

I think there was a board that sat across the 4 paged ROM sockets which 
then had a cable to another board with 16 sockets on it, and one of the 
16 sockets came through the case in a ZIF.

Aries or Dabs or Watford Electronics I expect.

I also remember soldering switches to TEAC drives from RS to make them 
40 / 80 track switchable.

Duncan, your name looks mighty familiar . Do you know a Judith?

-- 
Denis McMahon, denismfmcma...@gmail.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: how to write a html to automatically display the dictionary?

2014-09-23 Thread Denis McMahon
On Tue, 23 Sep 2014 09:53:40 -0700, Tobiah wrote:

 On 09/23/2014 07:18 AM, luofeiyu wrote:

 how can i create the following html

 f3 /td
 /tr

No tr here?

 td
 1

...

 td
 3
 /td
 tr

What is the above tr doing there?

 /tr
 /table

 [code]

Although your solution will produce valid html, it doesn't produce the 
specified output. ;)

-- 
Denis McMahon, denismfmcma...@gmail.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: how to write a html to automatically display the dictionary?

2014-09-23 Thread Denis McMahon
On Tue, 23 Sep 2014 17:34:53 +, John Gordon wrote:

 In mailman.14262.1411481932.18130.python-l...@python.org luofeiyu
 elearn2...@gmail.com writes:
 
 x={'f1':1,'f2':2,'f3':3}
 how can i create the following html file automatically with python to
 display x ?
 
 You might want to use something other than a dictionary, as the order
 isn't guaranteed.

Assuming you want them in order of the key field:

from string import *

x={'f1':1,'f2':2,'f3':3}
y = [ (a,x[a]) for a in x.keys() ]
y.sort( cmp=lambda a,b: cmp(a[0],b[0]) )
table = ( table\n +
  \n.join([tr\n +
 \n.join([td{}/td.format(z[i]) for z in y]) +
 \n/tr for i in range(len(y[0]))]) +
  \n/table )
print table

-- 
Denis McMahon, denismfmcma...@gmail.com
-- 
https://mail.python.org/mailman/listinfo/python-list


ANN: Lea 1.3.1 released

2014-09-22 Thread Pierre Denis
Lea, discrete probability distributions in Python

=

 

I have the pleasure to announce the release of Lea 1.3.1. 



NEW: Lea now runs on Python 3 (and still on Python 2.x) !

 

Lea is a Python package that allows you to define and play with discrete

probability distributions in an intuitive way. 

Lea can model a broad range of random discrete phenomenons. Then, it

allows calculating probabilities of events, whether atomic, aggregated or 
combined through operations. A typical example is the probabilities of the
sum of N dice having known, possibly unfair, probability distributions. 

Download (PyPi)

===

 http://pypi.python.org/pypi/lea http://pypi.python.org/pypi/lea



Project page / documentation



 http://code.google.com/p/lea/ http://code.google.com/p/lea/

Features 

- models finite discrete probability distributions 
- standard distribution indicators (mean, standard deviation,.) 
- arithmetic and logical operators on probability distribution 
- cartesian products, conditional probabilities, joint distributions 
- generation of random samples 
- open-source project, LGPL license 

- runs on Python 2.x and 3.x
- pure Python module, lightweight - no package dependency 
- probabilities stored as rationals (no floating-point biases) 

Hoping Lea could be helpful in this uncertain universe... 

 

Pierre Denis

 

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

Support the Python Software Foundation:
http://www.python.org/psf/donations/


Re: face detection

2014-09-22 Thread Denis McMahon
On Mon, 22 Sep 2014 15:29:58 +0530, narayan naik wrote:

 good evening sir,
 I am doing my M.Tech project on face
 detection,I am confused with the face detection algorithm,can you please
 tell me the simple and best algorithm.

http://www.lmgtfy.com/?q=best+face+detection+algorithm+python

-- 
Denis McMahon, denismfmcma...@gmail.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: find the error

2014-09-13 Thread Denis McMahon
On Fri, 12 Sep 2014 22:47:57 -0700, daoudimca wrote:

 Dear friends when i used import urllib, re, sys
 
 symbol = sys.argv[1]  this function is show -- symbol = sys.argv[1]
 IndexError: list index out of range
 
 kindly find the solution of this

You are trying to reference more elements than your list contains.

-- 
Denis McMahon, denismfmcma...@gmail.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: My backwards logic

2014-09-06 Thread Denis McMahon
On Fri, 05 Sep 2014 12:48:56 -0400, Seymore4Head wrote:

 But, what this instructions want printed is This is a prime number
 So how to I use this code logic NOT print (not prime) and have the logic
 print This number is prime

This is an algorithmic question, not a python question, so the answer is 
to write out the steps you would follow to determine that a number is 
prime, and then write that code.

Note also that when searching for factors of a number n, and starting at 
2, you can generally stop at somewhere around n/3, as the only possible 
factor of n greater than n/2 is n, and 2 is probably the first value you 
tested. This can speed things up.

-- 
Denis McMahon, denismfmcma...@gmail.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: I have tried and errored a reasonable amount of times

2014-09-04 Thread Denis McMahon
On Wed, 03 Sep 2014 07:16:34 +, Steven D'Aprano wrote:

 Who uses + for disjunction (∨ OR) and concatenation for conjunction (∧
 AND)? That's crazy notation.

The way I was taught it in the mid 1980s, a.b === a and b, a+b === a or b.

-- 
Denis McMahon, denismfmcma...@gmail.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: I have tried and errored a reasonable amount of times

2014-09-04 Thread Denis McMahon
On Thu, 04 Sep 2014 21:42:56 +1000, Chris Angelico wrote:

 On Thu, Sep 4, 2014 at 9:17 PM, Denis McMahon denismfmcma...@gmail.com
 wrote:
 On Wed, 03 Sep 2014 07:16:34 +, Steven D'Aprano wrote:

 Who uses + for disjunction (∨ OR) and concatenation for conjunction (∧
 AND)? That's crazy notation.

 The way I was taught it in the mid 1980s, a.b === a and b, a+b === a or
 b.
 
 The middle dot is another notation for multiplication, as is abuttal
 (not actually concatenation, in this context). So they're all saying the
 same thing: boolean 'and' is multiplication, boolean 'or' is addition.

Yes Chris, I know that. I was responding to Stephen's statement that 
using + for or was crazy notation, and pointing out that 30 years ago, 
that's what UK colleges were teaching!

-- 
Denis McMahon, denismfmcma...@gmail.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python is going to be hard

2014-09-03 Thread Denis McMahon
On Wed, 03 Sep 2014 14:10:42 -0400, Seymore4Head wrote:

 import math import random import sys b=[]
 steve = [1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89]
 for x in steve:
 print (steve[x])
 
 Traceback (most recent call last):
   File C:\Functions\blank.py, line 7, in module
 print (steve[x])
 IndexError: list index out of range

x is the value, not the index

Try:

steve = [1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89]
for x in steve:
print (x)

or if you want to use the index:

for x in range(len(steve)):
print (steve[x])


-- 
Denis McMahon, denismfmcma...@gmail.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Storing instances using jsonpickle

2014-09-03 Thread Denis McMahon
On Thu, 04 Sep 2014 00:39:07 +0100, MRAB wrote:

 It would add tuples, delimited by (...), which are not used otherwise
 (no expressions):

I guess  and () are both unused as delims by json at present.

I like the idea of other key types than string.

-- 
Denis McMahon, denismfmcma...@gmail.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: error while writing program to send mail.

2014-09-01 Thread Denis McMahon
On Tue, 02 Sep 2014 05:05:41 +0530, Om Prakash wrote:

 fp = open(message, 'rb')

message here is a string literal

 fp.close

should be fp.close()

 msg['Subject']  = 'The contents of $s' % message

message here is a variable. The variable named message has not previously 
had a value assigned to it.
$s should be %s

If you want the subject to be the filename, then what you need to do is:

1) assign the filename to some variable
2) open the file using the variable that contains the filename
3) use the variable that contains the filename to generate the subject

eg (assuming suitable imports etc) and the message is in a text file 
called message.txt:
 
msgfile = message.txt
fp = open( msgfile, r )
msg = MIMEText(fp.read())
fp.close()
msg['Subject']  = 'The contents of %s' % msgfile

-- 
Denis McMahon, denismfmcma...@gmail.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python code to distinguish between data having, 2 different formats, in a given cell(MS Excel).

2014-08-23 Thread Denis McMahon
On Sat, 23 Aug 2014 11:56:29 -0700, Ed Joz wrote:

 Please suggest a sample python code.

while program result not correct:
fix program

Note - we are not here to write your code for you, but we will try and 
help you develop your own code to do what you want.

-- 
Denis McMahon, denismfmcma...@gmail.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Distinguishing attribute name from varible name to make codes clear and definite

2014-08-21 Thread Denis McMahon
On Thu, 21 Aug 2014 22:13:32 +0800, luofeiyu wrote:

 I feel that self.x and x will be confused in the following codes.

Then don't call them self.x and x, call them self.internal_x and param_x, 
or any other pair of different names.

You are the one who chooses what names to use in your code.

-- 
Denis McMahon, denismfmcma...@gmail.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Very basic question. How do I start again?

2014-08-21 Thread Denis McMahon
On Thu, 21 Aug 2014 21:37:22 -0400, Seymore4Head wrote:

 I want to give the computer 100 tries to guess a random number between 1
 and 100 picked by the computer.
 
 For the moment I am always using 37 as the random pick.  I want to
 change the pick to pick=random.randrange(1,100).  The program works as
 expected until the computer gets a correct guess.  I don't know what I
 should be doing to restart the program when pick=guess.
 
 It is supposed to let the computer pick a number between 1 and 100 and
 then let the computer guess the answer.  If the computer picks a low
 number the next guess is supposed to be limited to higher numbers than
 the guess.  If the computer picks a high number, the next guess is
 supposed to be limited to lower numbers than the first guess.
 
 The program fails when guess=pick
 
 import random count = 1  #Start the counter at 1 low=1   #
 the low range of 1 to 10 high=100  #The high range of 1 to 100 pick
 = 37  # Will change to pick=random.randrange(1,100)
 guess = 0 #Guess is the computer's guess at pick print (Time to
 play a guessing game.)
 print ()
 
 
 while count  100:
 guess = random.randrange(low,high)
 print (pick, guess)
 if guess == pick:
 print (correct)
 
 #What I need is something here that says start over
 
 elif guess  pick:
 low=guess+1 print (Too low)
 elif guess  pick:
 high=guess-1 print (Too high)
 count = count +1
 
 (I can see where adding a 25 then 10 increment later would speed up the
 guessing)

Write the problem out in basic english terms, then translate these to the 
program. The english might look like this (laid out in a pythonic manner):

while I want to play a game:
choose a number
guess the answer
tries = 1
while guess != choice:
guess another answer
tries = tries + 1
print it took  + tries +  attempts to guess  + choice

This simplification doesn't take the calculation of ranges into account, 
but that's part of guess the/another answer.

-- 
Denis McMahon, denismfmcma...@gmail.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to look up historical time zones by date and location

2014-08-19 Thread Denis McMahon
On Tue, 19 Aug 2014 10:25:58 -0600, Ian Kelly wrote:

 We might be able to be more helpful if you would be more clear about
 what problem it is that you are trying to solve. Are you trying, for a
 given point on the Earth, to determine what nautical time zone it falls
 into, or some other natural time zone, or its LMT offset, or something
 else? For any of those cases, I think the Olson database of *legal* time
 zones is not going to be very useful. It would probably be better to
 obtain the longitude and do the calculation yourself.

Agreed, if OP wishes to insist that time is defined solely by longitude, 
then his best bet is to look up the longitude of the point in question on 
google maps and calculate his UTC time zone offset from that at 240 
seconds of time per degree longitude.

But Urumqi seems to be almost 83 seconds wide in astronomical time terms, 
so does he want West Urumqi time, Central Urumqi time or East Urumqi time?

-- 
Denis McMahon, denismfmcma...@gmail.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Collaps arrays/ list of intergers

2014-08-19 Thread Denis McMahon
On Tue, 19 Aug 2014 05:54:24 -0700, Jurgens de Bruin wrote:

 I do hope somebody can help me with the following:
 I have the followings lists which represent the upper and lower value of
 a range/array.
 
 a = [1,50]
 b = [75,150]
 c = [25,42]
 d = [120,149]
 e = [35,55]

I think you're starting off with the wrong data model.

I think you should be starting with is a list of either tuples or lists, 
eg:

[(1,50),(75,150),(25,42),(120,149),(35,55)]

and looking to output another list of tuples or lists, eg:

[(1,55),(75,150)]

I have a solution, but I don't consider it particularly elegant. :(

-- 
Denis McMahon, denismfmcma...@gmail.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to look up historical time zones by date and location

2014-08-18 Thread Denis McMahon
On Mon, 18 Aug 2014 12:55:59 +0800, luofeiyu wrote:

 http://www.thefreedictionary.com/time+zone
 
 time zone Any of the 24 divisions of the Earth's surface used to
 determine the local time for any given locality.
 Each zone is roughly 15° of longitude in width, with local variations
 for economic and political convenience.
 Local time is one hour ahead for each time zone as one travels east and
 one hour behind for each time zone as one travels west.
 
 Urumqi  's localtime is beijin time ,it is decided  by law .
 Urumqi  's timezone is east 6 ,it is decided by geography.
 
 There is only one localtime in all over the chian,beijin time,but there
 are 5  timezone time in china .
 
 you are totally wrong ,not me .

The Oxford Dictionaries ( http://www.oxforddictionaries.com/definition/
english/zone?q=timezone#zone__8 ) definition of zone includes:

(also time zone) A range of longitudes where a common standard time is 
used.

freedictionary has a very broad definition of time zone and is probably 
slightly less authoritative on the definition of English words than the 
Oxford University Press.

Most timezones may even be roughly 15 degrees in longitude in width, but 
this is not binding, and it is not unusual to find other widths applied.

In the case of China, the Chinese government has determined that the 
whole country operates on Beijing Time, so the time zone *FOR ALL OF 
CHINA* is that of Beijing.

The astronomical time[1] in Urumqi may not match the time zone, however 
the time zone is Beijing Time.

[1] I consider astronomical noon for any point as being when the sun is 
at zenith, ie overhead of the longitude of the point[2].

[2] Yes, I realise this means that it's always noon, and midnight, and 
everything else at the poles, I just have to live with that.

-- 
Denis McMahon, denismfmcma...@gmail.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Unicode in cgi-script with apache2

2014-08-16 Thread Denis McMahon
On Fri, 15 Aug 2014 20:10:25 +0200, Dominique Ramaekers wrote:

 #!/usr/bin/env python3
 print(Content-Type: text/html)
 print(Cache-Control: no-cache, must-revalidate)# HTTP/1.1
 print(Expires: Sat, 26 Jul 1997 05:00:00 GMT) # Date in the past
 print()
 f = open(/var/www/cgi-data/index.html, r)
 for line in f:
  print(line,end='')
 
 If I run the script in the terminal, it nicely prints the webpage
 'index.html'.
 
 If access the script through a webbrowser, apache gives an error:
 UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position
 1791: ordinal not in range(128)

Is this a message appearing in the apache error log or in the browser? If 
it is appearing in the browser, this is probably apache passing through a 
python error message.

Is this the complete error message?

What happens when you try and access http://[server]/cgi-data/index.html 
directly in a web browser? You may need to copy the file to a different 
directory to do this depending on the apache configuration.

-- 
Denis McMahon, denismfmcma...@gmail.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Unicode in cgi-script with apache2

2014-08-16 Thread Denis McMahon
On Sun, 17 Aug 2014 00:36:14 +0200, Dominique Ramaekers wrote:

 What seems to be the problem:
 My Script was ok. I know this because in the terminal I got my expected
 output. Python3 uses UTF-8 coding as a standard. The problem is, when
 python 'prints' to the apache interface, it translates the string to
 ascii. (Why, I never found an answer).

Is the apache server running on a linux or a windows platform?

The problem may not be python, it may be the underlying OS. I wonder if 
apache is spawning a process for python though, and if so whether it is 
in some way constraining the character set available to stdout of the 
spawned process.

From your other message, the error appears to be a python error on 
reading the input file. For some reason python seems to be trying to 
interpret the file it is reading as ascii.

I wonder if specifying the binary data parameter and / or utf-8 encoding 
when opening the file might help.

eg:

f = open( /var/www/cgi-data/index.html, rb )
f = open( /var/www/cgi-data/index.html, rb, encoding=utf-8 )
f = open( /var/www/cgi-data/index.html, r, encoding=utf-8 )

I've managed to drive down a bit further in the problem:

print() goes to sys.stdout

This is part of what the docs say about sys.stdout:


The character encoding is platform-dependent. Under Windows, if the 
stream is interactive (that is, if its isatty() method returns True), the 
console codepage is used, otherwise the ANSI code page. Under other 
platforms, the locale encoding is used (see locale.getpreferredencoding
()).

Under all platforms though, you can override this value by setting the 
PYTHONIOENCODING environment variable before starting Python.


At this point, details of the OS become very significant. If your server 
is running on a windows platform you may need to figure out how to make 
apache set the PYTHONIOENCODING environment variable to utf-8 (or 
whatever else is appropriate) before calling the python script.

I believe that the following line in your httpd.conf may have the 
required effect.

SetEnv PYTHONIOENCODING utf-8

Of course, if the file is not encoded as utf-8, but rather something 
else, then use that as the encoding in the above suggestions. If the 
server is not running windows, then I'm not sure where the problem might 
be.

-- 
Denis McMahon, denismfmcma...@gmail.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: timedelta problem

2014-08-15 Thread Denis McMahon
On Fri, 15 Aug 2014 10:24:47 +0800, luofeiyu wrote:

On further inspection, it seems that strptime() in 2.7 doesn't handle %z 
at all. In 3.2, it ignores the value it gets, because there's no 
practical way to select the right tz string from the offset.

For example, a dictionary of offset minutes to tzstrings looks something 
like this:

{
-720: ['BIT'], 
-660: ['NUT', 'SST'], 
-600: ['CKT', 'HAST', 'HST', 'TAHT'], 
-570: ['MART', 'MIT'], 
-540: ['AKST', 'GAMT', 'GIT', 'HADT'], 
-480: ['AKDT', 'CIST', 'PST'], 
-420: ['MST', 'PDT'], 
-360: ['CST', 'EAST', 'GALT', 'MDT'], 
-300: ['CDT', 'COT', 'CST', 'EASST', 'ECT', 'EST', 'PET'], 
-270: ['VET'], 
-240: ['AMT', 'AST', 'BOT', 'CDT', 'CLT', 'COST', 'ECT', 'EDT', 'FKT', 
'GYT', 'PYT'], 
-210: ['NST', 'NT'], 
-180: ['ADT', 'AMST', 'ART', 'BRT', 'CLST', 'FKST', 'FKST', 'GFT', 'PMST', 
'PYST', 'ROTT', 'SRT', 'UYT'], 
-150: ['NDT'], 
-120: ['FNT', 'GST', 'PMDT', 'UYST'], 
-60: ['AZOST', 'CVT', 'EGT'], 
0: ['GMT', 'UCT', 'UTC', 'WET', 'Z', 'EGST'], 
60: ['BST', 'CET', 'DFT', 'IST', 'MET', 'WAT', 'WEDT', 'WEST'], 
120: ['CAT', 'CEDT', 'CEST', 'EET', 'HAEC', 'IST', 'MEST', 'SAST', 
'WAST'], 
180: ['AST', 'EAT', 'EEDT', 'EEST', 'FET', 'IDT', 'IOT', 'SYOT'], 
210: ['IRST'], 
240: ['AMT', 'AZT', 'GET', 'GST', 'MSK', 'MUT', 'RET', 'SAMT', 'SCT', 
'VOLT'], 
270: ['AFT', 'IRDT'], 
300: ['AMST', 'HMT', 'MAWT', 'MVT', 'ORAT', 'PKT', 'TFT', 'TJT', 'TMT', 
'UZT'], 
330: ['IST', 'SLST'], 
345: ['NPT'], 
360: ['BIOT', 'BST', 'BTT', 'KGT', 'VOST', 'YEKT'], 
390: ['CCT', 'MMT', 'MST'], 
420: ['CXT', 'DAVT', 'HOVT', 'ICT', 'KRAT', 'OMST', 'THA', 'WIT'], 
480: ['ACT', 'AWST', 'BDT', 'CHOT', 'CIT', 'CST', 'CT', 'HKT', 'MST', 
'MYT', 'PST', 'SGT', 'SST', 'ULAT', 'WST'], 
525: ['CWST'], 
540: ['AWDT', 'EIT', 'IRKT', 'JST', 'KST', 'TLT'], 
570: ['ACST', 'CST'], 
600: ['AEST', 'CHUT', 'DDUT', 'EST', 'PGT', 'VLAT', 'YAKT'], 
630: ['ACDT', 'CST', 'LHST'], 
660: ['AEDT', 'KOST', 'LHST', 'MIST', 'NCT', 'PONT', 'SAKT', 'SBT', 
'VUT'], 
690: ['NFT'], 
720: ['FJT', 'GILT', 'MAGT', 'MHT', 'NZST', 'PETT', 'TVT', 'WAKT'], 
765: ['CHAST']
780: ['NZDT', 'PHOT', 'TKT', 'TOT'], 
825: ['CHADT'], 
840: ['LINT'], 
}

I've patched my 2.7 to set a tz string of UTC[+-] from the [+-] 
%z value.

-- 
Denis McMahon, denismfmcma...@gmail.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: timedelta problem

2014-08-15 Thread Denis McMahon
On Fri, 15 Aug 2014 07:39:23 +, Denis McMahon wrote:

 I've patched my 2.7 to set a tz string of UTC[+-] from the
 [+-] %z value.

... but that doesn't do much, because time.struct_time in 2.7 doesn't 
recognise anything that strptime passes in as a tz at all, as it expects 
the dst flag in that position and seems to have no concept of tz at all.

So in 2.7 you can probably forget any question of reading in tz info with 
datetime.strptime().

See another reply to the OP regarding Python 3.2

-- 
Denis McMahon, denismfmcma...@gmail.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: timedelta problem

2014-08-15 Thread Denis McMahon
On Fri, 15 Aug 2014 10:24:47 +0800, luofeiyu wrote:

 problem :
 
 t1 is GMT time   2014  00:36:46 t2 is GMT time   2014  14:36:46
 
 datetime.datetime.strptime  do not give me the right answer.

As far as I can tell from running the following, it all seems to work as 
expected in python 3.2 (and hence I expect in 3.4). If the expected 
output doesn't match yours, it would be interesting to see what your 
output is. If the expected output does match yours, and you think it's 
wrong, it would be interesting to know which bits you think are wrong and 
why you think they are wrong, because having a fair bit of the night 
looking at this, it all looks good to me.

#!/usr/bin/python3

from datetime import tzinfo, timedelta, datetime, timezone

# define timedelta based timezones

UTCm7 = timezone(timedelta(0,-7*3600),UTC-07:00)
UTCp7 = timezone(timedelta(0,+7*3600),UTC+07:00)
UTC  = timezone(timedelta(0),UTC+00:00)

# some timestrings

t1 = 'Sat, 09 Aug 2014 07:36:46 -0700'
t2 = 'Sat, 09 Aug 2014 07:36:46 +0700'
t3 = 'Sat, 09 Aug 2014 07:36:46 +'

# make some datetime objects
# these are both utc -7

a1 = datetime.strptime(t1,%a, %d %b %Y %H:%M:%S %z)
b1 = datetime(2014, 8, 9, 7, 36, 46, tzinfo = UTCm7)

# these are both utc +7

a2 = datetime.strptime(t2,%a, %d %b %Y %H:%M:%S %z)
b2 = datetime(2014, 8, 9, 7, 36, 46, tzinfo = UTCp7)

# these are both utc

a3 = datetime.strptime(t3,%a, %d %b %Y %H:%M:%S %z)
b3 = datetime(2014, 8, 9, 7, 36, 46, tzinfo = UTC)

# print them out as stored

print( UTC -7: )
print( t1 )
print( a1 )
print( b1 )

print( UTC +7: )
print( t2 )
print( a2 )
print( b2 )

print( UTC: )
print( t3 )
print( a3 )
print( b3 )

# print them out converted to UTC

print( UTC -7 as UTC: )
print( a1.astimezone( UTC ) )
print( b1.astimezone( UTC ) )

print( UTC +7 as UTC: )
print( a2.astimezone( UTC ) )
print( b2.astimezone( UTC ) )

print( UTC as UTC: )
print( a3.astimezone( UTC ) )
print( b3.astimezone( UTC ) )

# expected output


UTC -7:
Sat, 09 Aug 2014 07:36:46 -0700
2014-08-09 07:36:46-07:00
2014-08-09 07:36:46-07:00
UTC +7:
Sat, 09 Aug 2014 07:36:46 +0700
2014-08-09 07:36:46+07:00
2014-08-09 07:36:46+07:00
UTC:
Sat, 09 Aug 2014 07:36:46 +
2014-08-09 07:36:46+00:00
2014-08-09 07:36:46+00:00
UTC -7 as UTC:
2014-08-09 14:36:46+00:00
2014-08-09 14:36:46+00:00
UTC +7 as UTC:
2014-08-09 00:36:46+00:00
2014-08-09 00:36:46+00:00
UTC as UTC:
2014-08-09 07:36:46+00:00
2014-08-09 07:36:46+00:00


-- 
Denis McMahon, denismfmcma...@gmail.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: how to change the time string into number?

2014-08-15 Thread Denis McMahon
On Thu, 14 Aug 2014 14:52:17 +0800, luofeiyu wrote:

 in the manual  https://docs.python.org/3.4/library/time.html
 
 %zTime zone offset indicating a positive or negative time difference
 from UTC/GMT of the form +HHMM or -HHMM, where H represents decimal hour
 digits and M represents decimal minute digits [-23:59, +23:59].
 %ZTime zone name (no characters if no time zone exists).
 
 
 t1='Sat, 09 Aug 2014  07:36:46  '
 time.strptime(t1,%a, %d %b %Y %H:%M:%S )
 time.struct_time(tm_year=2014, tm_mon=8, tm_mday=9, tm_hour=7,
 tm_min=36, tm_sec =46, tm_wday=5, tm_yday=221, tm_isdst=-1)
 
   t2='Sat, 09 Aug 2014  07:36:46  -0700' time.strptime(t2,%a, %d %b
   %Y %H:%M:%S %z)
 time.struct_time(tm_year=2014, tm_mon=8, tm_mday=9, tm_hour=7,
 tm_min=36, tm_sec =46, tm_wday=5, tm_yday=221, tm_isdst=-1)
 
 t1 and t2 is different time ,the timezone in t2 is -0700 ,why we get the
 same result?
 
   t3='Sat, 09 Aug 2014  07:36:46  +0400' time.strptime(t3,%a, %d %b
   %Y %H:%M:%S %z)
 time.struct_time(tm_year=2014, tm_mon=8, tm_mday=9, tm_hour=7,
 tm_min=36, tm_sec =46, tm_wday=5, tm_yday=221, tm_isdst=-1)
 
 
 The Directive   %z  has no any effect here,what is the matter?

Please learn to use usenet properly. Comments go below the text they 
refer to.

What version of python are you using? I know what version of the 
documentation you are looking at, but as I explained inj an earlier post, 
the implementation varies between different python versions, and for 
example python 2.7 strptime seems to completely ignore the %z in the 
format string, so again, what version of python are you using?

To check your python version:

$ python
 import sys
 sys.version

will output something like:

'2.7.3 (default, Feb 27 2014, 19:58:35) \n[GCC 4.6.3]'

for Python 2.7 or:

'3.2.3 (default, Feb 27 2014, 21:31:18) \n[GCC 4.6.3]'

for Python 3.2. Again, I stress, we need to know what version of python 
you are using to help you!

Did you run the code I posted? Did you get the same output as me? If you 
didn't, what was different. If you did get the same output, what do you 
think is wrong with it?

-- 
Denis McMahon, denismfmcma...@gmail.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: timedelta problem

2014-08-15 Thread Denis McMahon
On Fri, 15 Aug 2014 09:23:02 -0600, Ian Kelly wrote:

 On Fri, Aug 15, 2014 at 1:39 AM, Denis McMahon
 denismfmcma...@gmail.com wrote:
 On Fri, 15 Aug 2014 10:24:47 +0800, luofeiyu wrote:

 On further inspection, it seems that strptime() in 2.7 doesn't handle
 %z at all. In 3.2, it ignores the value it gets, because there's no
 practical way to select the right tz string from the offset.
 
 I'm not sure when %z was added, but it's worth noting that it doesn't
 seem to be documented earlier than 3.3.

There may be some confusion because %z is in the table of strftime and 
strptime format chars on the 2.7.8 docs at

https://docs.python.org/2/library/datetime.html#strftime-and-strptime-
behavior

but I suspect it's only applicable to strftime in that release.

-- 
Denis McMahon, denismfmcma...@gmail.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: get the min date from a list

2014-08-15 Thread Denis McMahon
On Thu, 14 Aug 2014 22:10:36 +0800, luofeiyu wrote:

 I finished it ,but how to make it into more pythonic way such as min
 (dates, key = converter)

1. If you don't learn to post properly, I'm going to stop trying to help 
you.

2. To user strptime, you need to have all the time strings in the same 
format. Your time strings are not all in the same format.

3. Consider the following code which works on python 3.2:

#!/usr/bin/python3

from datetime import tzinfo, timedelta, datetime, timezone

times=[
'Sat, 09 Aug 2014 07:36:46 -0700',
# rest of array here
'Tue, 05 Aug 2014 01:55:24 +',
]

realtimes = [ datetime.strptime( x, %a, %d %b %Y %H:%M:%S %z ) 
  for x in times ]
realtimes.sort()
utctimes = [ x.astimezone(timezone(timedelta(0))) 
 for x in realtimes ]
for i in range( len( realtimes ) ):
print( realtimes[i], ==, utctimes[i] )

Output is a sorted list of the actual times and the UTC equivalents of 
all the times in the original list. Note that I had to edit several 
strings in your times list to ensure they were all in identical format: I 
added leading 0s to numeric values in some strings, deleted extra spaces 
in some strings, deleted extraneous information after the tz offset in 
some strings. When feeding strings to a parsing function such as strptime
() it is critically important that the format specifier matches the input 
data.

-- 
Denis McMahon, denismfmcma...@gmail.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Captcha identify

2014-08-14 Thread Denis McMahon
On Wed, 13 Aug 2014 07:39:20 -0400, Eric S. Johansson wrote:

 you are clear but also missing a really good reason to break captchas.
 handicapped accessibility.  Captchas are a huge barrier to access and in
 many cases push disabled users away from using a service  with captchas.

That's as may be, but bozo is not trying to improve handicapped 
accessibility, he's trying to write a spambot.

Please don't use the accessibility concerns surrounding captcha to 
justify writing spambot software. It doesn't help the accessibility 
argument to be seen to be pro spambot, in fact if anything it may damage 
it. I agree that there are more reasons not to use captcha these days 
than there are to use them, however I still don't advocate helping spambot 
bastards defeat them.

-- 
Denis McMahon, denismfmcma...@gmail.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Captcha identify

2014-08-14 Thread Denis McMahon
On Tue, 12 Aug 2014 18:36:21 -0700, Wesley wrote:

 I just wanna a general suggestion here in the beginning.

OK, the general suggestion is that you take your spambot software, print 
it out on spiky metal sheets and ram it up your rectum.

 Why I need to write such program is just having such requirements.

Yes, we understand that your spambot requires to decode captcha. We were 
just telling you in fairly polite terms that you should fuck off because 
we have no wish to help you. We tried polite, it didn't work, now I'm 
trying robustness and profanity.

-- 
Denis McMahon, denismfmcma...@gmail.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: how to change the time string into number?

2014-08-14 Thread Denis McMahon
On Thu, 14 Aug 2014 09:46:20 +0800, luofeiyu wrote:

 s=Aug
 
 how can i change it into 8 with some python time module?

You don't need a time module for this, just use a dictionary:

months = { Jan : 1, . , Dec: 12 }
num = months[s]
print num

Fill in the rest of the months dictionary yourself, it shouldn't be too 
hard.

-- 
Denis McMahon, denismfmcma...@gmail.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: timedelta problem

2014-08-14 Thread Denis McMahon
On Fri, 15 Aug 2014 10:24:47 +0800, luofeiyu wrote:

 import datetime
 t1='Sat, 09 Aug 2014 07:36:46 -0700'
 t2='Sat, 09 Aug 2014 07:36:46 +0700'
 datetime.datetime.strptime(t1,%a, %d %b %Y %H:%M:%S %z)

Are you sure? When I try this I get:

ValueError: 'z' is a bad directive in format '%a, %d %b %Y %H:%M:%S %z'

 datetime.datetime(2014, 8, 9, 7, 36, 46,
 tzinfo=datetime.timezone(datetime.timedelta(-1, 61200)))

And this:

AttributeError: 'module' object has no attribute 'timezone'

-- 
Denis McMahon, denismfmcma...@gmail.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Suitable Python code to scrape specific details from web pages.

2014-08-13 Thread Denis McMahon
On Tue, 12 Aug 2014 13:00:30 -0700, Simon Evans wrote:

 in accessing from the 'Racing Post' on a daily basis. Anyhow, the code

Following is some starter code. You will have to look at the output, 
compare it to the web page, and work out how you want to process it 
further. Note that I use beautifulsoup and requests. The output is the 
html for each cell in the table with a line of + characters at the 
table row breaks. I suggest you look at the beautifulsoup documentation 
at http://www.crummy.com/software/BeautifulSoup/bs4/doc/ to work out how 
you may wish to select which table cells contain data you are interested 
in and how to extract it.

#!/usr/bin/python

Program to extract data from racingpost.


from bs4 import BeautifulSoup
import requests

r = requests.get( http://www.racingpost.com/horses2/cards/card.sd?
race_id=607466r_date=2014-08-13#raceTabs=sc_ )

if r.status_code == 200:
soup = BeautifulSoup( r.content )
table = soup.find( table, id=sc_horseCard )
for row in table.find_all( tr ):
for cell in row.find_all( td ):
print cell
print +
else:
print HTTP Status, r.status_code

-- 
Denis McMahon, denismfmcma...@gmail.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Captcha identify

2014-08-12 Thread Denis McMahon
On Tue, 12 Aug 2014 00:04:33 -0700, Wesley wrote:

 These days I got a small task to identify Captcha characters.

Several of us code websites. Some of our websites may even use captcha. 
We use captcha to stop software posting spam to websites.

What makes you think we have any inclination to help you defeat captchas?

-- 
Denis McMahon, denismfmcma...@gmail.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Captcha identify

2014-08-12 Thread Denis McMahon
On Wed, 13 Aug 2014 01:06:47 +1000, Chris Angelico wrote:

 Let me spell it out for you: NO WE WILL NOT do this for you. And if you
 do it yourself, we will not be happy. Just don't.

Chris, I suspect he's a codemonkey in a chinese or similar asian spamhaus. 
We should probably be thankful that he's so dumb.

-- 
Denis McMahon, denismfmcma...@gmail.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python in financial services

2014-08-12 Thread Denis McMahon
On Tue, 12 Aug 2014 00:33:11 -0700, Rustom Mody wrote:

 Ive been asked to formulate a python course for financial services folk.

I wouldn't worry too much about c or c++ interfacing paradigms.

-- 
Denis McMahon, denismfmcma...@gmail.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python in financial services

2014-08-12 Thread Denis McMahon
On Tue, 12 Aug 2014 10:48:14 -0700, Rustom Mody wrote:

 However those folks have thousands of lines of C/C++ which they are
 porting to python.

That begs the question: Why?

Seriously, I'd like to know what benefits they expect to achieve by doing 
so.

-- 
Denis McMahon, denismfmcma...@gmail.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Best place to find sample data

2014-07-26 Thread Denis McMahon
On Sat, 26 Jul 2014 06:41:11 -0700, Nicholas Cannon wrote:

 Hey I need some sample data to test out and do stuff with.

When I want sample data I usually write a python script to generate it.

 Also I am
 having strange errors with idle when i load a .txt file read it and then
 print it, idle crashes well kind of freezes.

Missing libraries? Bad characters in the text file? 

 Not sure what is wrong
 here. Also I am having troubles with Numpy and its loadtxt function:
 
 ValueError: cannot set an array element with a sequence

How about showing us the code concerned, and the text that's being loaded.

-- 
Denis McMahon, denismfmcma...@gmail.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Newbie: unexpected indenting error

2014-07-13 Thread Denis McMahon
On Sun, 13 Jul 2014 09:01:12 +0200, Martin S wrote:

 While coding a rating calculator I am using a for-loop within
 if-elif-else.
 When using the for-loop in the first if instance my editor accepts this,
 but when using the same for-loop within the elif instance it complain
 about unexpected indent.
 
 Like so:
 
 def function(x):
if rdiff =500:
   for 
  [do stuff]
elif rdiff =410:
for ...  == unexpected indent
   [do other stuff]
 
 
 What the...? What am I doing wrong?
 (hopefully the indents translate; else def, if/elif, for and [dostuff]
 are indented)

You seem to have posted what you believe is an equivalent structure to 
your code, rather than your actual code.

The structure you have posted looks fine, but it's not a runnable snippet 
that we can actually test.

Can you actually reproduce the problem in a single block of code that we 
can try and run ourselves?

For example, if you copy your problem function to a new file and edit 
the function def line and the code and lines after the for statements as 
follows, does the problem persist?

for rdiff in range( 450, 600, 100 ):
   if rdiff =500:
  for i in range( 1, 3 ):
 print rdiff, i
   elif rdiff =410:
  for i in range( 1, 3 ):
 print i, ridff

-- 
Denis McMahon, denismfmcma...@gmail.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Writing Python File at Specific Interval

2014-07-09 Thread Denis McMahon
On Wed, 09 Jul 2014 07:36:49 -0700, subhabangalore wrote:

 The code (a basic crawler) would run every morning or evening, on a
 predefined time. [This part is fine].
 
 In the next part, I am trying to store the daily results to a new file.

So what you want to do is store each day's results in a new file, so 
probably you want to create a filename that looks something like an iso 
8601 date.

Luckily for you python has this functionality available:

https://docs.python.org/2/library/datetime.html#date-objects

$ python
Python 2.7.3 (default, Feb 27 2014, 19:58:35) 
[GCC 4.6.3] on linux2
Type help, copyright, credits or license for more information.
 from datetime import date
 fn = date.today().isoformat() + .log
 print fn
2014-07-10.log
 quit()
$

Once you have a string containing your filename, you might use:

fp = open( fn, w )
fp.write( data )
fp.close()

-- 
Denis McMahon, denismfmcma...@gmail.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Saving

2014-07-07 Thread Denis McMahon
On Sun, 06 Jul 2014 23:03:07 +, mrwhackadoo1 wrote:

 Hi, I’ve been looking forever for this and I cant get it.
 
 I need to know how to save my code and save as programs because I write
 code and I run it but then I cant save it for later.
 
 Please help and thank you for your time.

Write your code in a file and run them from your command line, instead of 
entering your programs directly into the interpreter.

-- 
Denis McMahon, denismfmcma...@gmail.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Why is regexp not working?

2014-07-05 Thread Denis McMahon
On Fri, 04 Jul 2014 14:27:12 +0200, Florian Lindner wrote:

 self.regexps = [rit (?Pcoupling_iterations\d+) .* dt complete yes |
 write-iteration-checkpoint |,
 rit (?Pit_read_ahead\d+) read ahead

My first thought is what is the effect of '|' as the last character in 
the regex?

-- 
Denis McMahon, denismfmcma...@gmail.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Convert Excel Range into python List

2014-07-01 Thread Denis McMahon
On Tue, 01 Jul 2014 03:51:31 -0700, Jaydeep Patil wrote:

 How to convert excel range into python list or tuple?
 show me example

http://lmgtfy.com/?q=convert+excel+range+into+python+list+or+tuple

This is an example of how to google a programming question. Learn from it!

-- 
Denis McMahon, denismfmcma...@gmail.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python While loop Takes too much time.

2014-07-01 Thread Denis McMahon
On Tue, 01 Jul 2014 14:40:18 +0200, Peter Otten wrote:

 What I'm trying to tell you: you need to put in some work to identify
 the culprit...

His next question was how do I read a range from excel, please give me 
an example

I gave him an example of using google to search for solutions to his 
problem. If he can't be bothered to try and solve it himslef, I'm nopt 
going to write his code for him.

-- 
Denis McMahon, denismfmcma...@gmail.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Writing Multiple files at a times

2014-06-30 Thread Denis McMahon
On Mon, 30 Jun 2014 12:23:08 -0700, subhabangalore wrote:

 Thank you for your kind suggestion. But I am not being able to sort out,
 fp = open( scraped/body{:05d}.htm.format( n ), w ) 
 please suggest.

look up the python manual for string.format() and open() functions.

The line indicated opens a file for write whose name is generated by the 
string.format() function by inserting the number N formatted to 5 digits 
with leading zeroes into the string scraped/bodyN.htm

It expects you to have a subdir called scraped below the dir you're 
executing the code in.

Also, this newsgroup is *NOT* a substitute for reading the manual for 
basic python functions and methods.

Finally, if you don't understand basic string and file handling in 
python, why on earth are you trying to write code that arguably needs a 
level of competence in both? Perhaps as your starter project you should 
try something simpler, print hello world is traditional.

To understand the string formatting, try:

print hello {:05d} world.format( 5 )
print hello {:05d} world.format( 50 )
print hello {:05d} world.format( 500 )
print hello {:05d} world.format( 5000 )
print hello {:05d} world.format( 5 )

-- 
Denis McMahon, denismfmcma...@gmail.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Writing Multiple files at a times

2014-06-29 Thread Denis McMahon
On Sun, 29 Jun 2014 10:32:00 -0700, subhabangalore wrote:

 I am opening multiple URLs with urllib.open, now one Url has huge html
 source files, like that each one has. As these files are read I am
 trying to concatenate them and put in one txt file as string.
 From this big txt file I am trying to take out each html file body of
 each URL and trying to write and store them

OK, let me clarify what I think you said.

First you concatenate all the web pages into a single file.
Then you extract all the page bodies from the single file and save them 
as separate files.

This seems a silly way to do things, why don't you just save each html 
body section as you receive it?

This sounds like it should be something as simple as:

from BeautifulSoup import BeautifulSoup
import requests

urlList = [ 
http://something/;, 
http://something/;, 
http://something/;, 
... ]

n = 0
for url in urlList:
r = requests.get( url )
soup = BeautifulSoup( r.content )
body = soup.find( body )
fp = open( scraped/body{:05d}.htm.format( n ), w )
fp.write( body.prettify() )
fp.close
n += 1

will give you:

scraped/body0.htm
scraped/body1.htm
scraped/body2.htm


for as many urls as you have in your url list. (make sure the target 
directory exists!)

-- 
Denis McMahon, denismfmcma...@gmail.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: lists vs. NumPy arrays for sets of dates and strings

2014-06-09 Thread Denis McMahon
On Mon, 09 Jun 2014 12:48:12 -0700, beliavsky wrote:

 I am going to read a multivariate time series from a CSV file that looks
 like
 
 Date,A,B 2014-01-01,10.0,20.0 2014-01-02,10.1,19.9 ...
 
 The numerical data I will store in a NumPy array, since they are more
 convenient to work with than lists of lists. What are the advantages and
 disadvantages of storing the symbols [A,B] and dates
 [2014-01-01,2014-01-02] as lists vs. NumPy arrays?

You could also use a dictionary of either lists or tuples or even NumPy 
arrays keyed on the date.

$ python
Python 2.7.3 (default, Feb 27 2014, 19:58:35) 
[GCC 4.6.3] on linux2
Type help, copyright, credits or license for more information.
 import numpy
 x = {}
 y = numpy.array( [0,1] )
 x['2014-06-05'] = y
 x['2014-06-05']
array([0, 1])
 x
{'2014-06-05': array([0, 1])}
 x['2014-06-05'][0]
0
 x['2014-06-05'][1]
1

-- 
Denis McMahon, denismfmcma...@gmail.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python 3.2 has some deadly infection

2014-06-06 Thread Denis McMahon
On Sat, 07 Jun 2014 01:50:50 +1000, Chris Angelico wrote:

 Yes and no. ASCII means two things:

ASCII means: American Standard Code for Information Interchange aka ASA 
Standard X3.4-1963

 into the lowest seven bits of a byte, with the high byte left clear.

high BIT left clear.

-- 
Denis McMahon, denismfmcma...@gmail.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to read a directory path from a txt file

2014-06-02 Thread Denis McMahon
On Mon, 02 Jun 2014 08:13:23 -0700, Samuel Kamau wrote:

 I have permission issues with my web server.

Hacks to fix permissions problems are dangerous. There is probably a 
better way to fix this issue.

-- 
Denis McMahon, denismfmcma...@gmail.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Verify JSON Data

2014-05-26 Thread Denis McMahon
On Mon, 26 May 2014 07:26:20 -0700, gaurangnshah wrote:

 Is there any module through which i can verify JSON file like DOM or
 Object oriented way. ( i.e. data.key)

Where is the json data coming from? What do you mean by verify?

https://docs.python.org/2/library/json.html#encoders-and-decoders

explains how json object strings get decoded to python data types. A json 
object string should at the highest level be either an object or an 
array, although the python decoder can also handle strings, numbers and a 
few special values.

Are you trying to check that the json string is valid json code (ie json 
lint) or are you trying to check that it meets some specific structure, 
in which case the only way to verify it is to decode it and check the 
structure.

Note that not all valid python structures can be successfully converted 
to json objects, for example a python dictionary can have tuples as keys, 
but a json object can not have an array as an attribute name. For example:

d = { (1,2,3):'one',('a','b','c'):'two' }
print d
print json.JSONEncoder().encode( d )

Gives a TypeError in the json code keys must be a string

If you have a debian based linux distro, you can get jsonlint with:

sudo apt-get install python-demjson

which provides a command line json syntax checker and formatter. 
Otherwise, google json lint, there are several web based tools that seem 
to be able to do something similar.

-- 
Denis McMahon, denismfmcma...@gmail.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: problems decoding json objects

2014-05-14 Thread Denis McMahon
On Wed, 14 May 2014 10:36:11 +0200, Tamer Higazi wrote:

 Hi people!
 
 My JSON String:
 
 from json.decoder import JSONDecoder

 myjs =
 
'{AVName:Tamer,ANName:Higazi,AAnschrift:Bauerngasse,AHausnr:1,APLZ:55116,AOrt:Mainz},
{KontaktTel:[01234,11223344],{ZahlungsArt:0},{ZugangsDaten:
[tamer.hig...@nomail.com,mypass]}'
 
 If I try to decode it, with:
 
 JSD = JSONDecoder()
 rsx = JSD.decode(myjs)
 
 I get this error message:
 
 JSD.decode(myjs)
 Traceback (most recent call last):
   File stdin, line 1, in module
   File /usr/lib64/python2.7/json/decoder.py, line 368, in decode
 raise ValueError(errmsg(Extra data, s, end, len(s)))
 ValueError: Extra data: line 1 column 108 - line 1 column 220 (char 107
 - 219)

 How do I solve this problem ?!

 For any help, thanks

Try doing a manual inspection of your json string. It appears to contain 
several objects, but they're not contained within an outer object or an 
array. If you want a list of data objects, you need to put [] round them. 
If you want them to be dictionary elements, you need to wrap them with {} 
and put identifiers in. If you want a single dictionary, you need to 
remove most of the { and }.

In addition, one of the objects doesn't appear to be terminated.

{AVName:Tamer,ANName:Higazi,AAnschrift:Bauerngasse,AHausnr:1,APLZ:55116,AOrt:Mainz},
{KontaktTel:[01234,11223344] ** missing '}' ??? ** ,
{ZahlungsArt:0},
{ZugangsDaten:[tamer.hig...@nomail.com,mypass]}

Depending how I correct the json string, I can create different values 
for rsx:

(1) a list of 4 dictionaries:

$ ./jsonerr.py
[{u'APLZ': u'55116', u'ANName': u'Higazi', u'AHausnr': u'1', u'AVName': 
u'Tamer', u'AAnschrift': u'Bauerngasse', u'AOrt': u'Mainz'}, 
{u'KontaktTel': [u'01234', u'11223344']}, {u'ZahlungsArt': u'0'}, 
{u'ZugangsDaten': [u'tamer.hig...@nomail.com', u'mypass']}]

(2) a single dictionary:

$ ./jsonerr.py
{u'APLZ': u'55116', u'KontaktTel': [u'01234', u'11223344'], 
u'ZugangsDaten': [u'tamer.hig...@nomail.com', u'mypass'], u'ANName': 
u'Higazi', u'AHausnr': u'1', u'AVName': u'Tamer', u'AAnschrift': 
u'Bauerngasse', u'AOrt': u'Mainz', u'ZahlungsArt': u'0'}

(3) an object with 4 subsidiary objects:

$ ./jsonerr.py
{u'Misc data': {u'ZahlungsArt': u'0'}, u'Name and Addr': {u'APLZ': 
u'55116', u'ANName': u'Higazi', u'AHausnr': u'1', u'AVName': u'Tamer', 
u'AAnschrift': u'Bauerngasse', u'AOrt': u'Mainz'}, u'Login info': 
{u'ZugangsDaten': [u'tamer.hig...@nomail.com', u'mypass']}, 
u'Telephones': {u'KontaktTel': [u'01234', u'11223344']}}

but I have no way of knowing which it is you require.

-- 
Denis McMahon, denismfmcma...@gmail.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: A Question about Python

2014-05-06 Thread Denis McMahon
On Tue, 06 May 2014 05:09:25 -0700, doaa eman wrote:

 I'm a researcher ..

Obviously part of your PhD research is going to be whether the 
citeulike_api 0.1.3dev python package can help you extract the 
information you want from http://citeulike.org/

We look forwards to seeing your conclusions in this matter.

-- 
Denis McMahon, denismfmcma...@gmail.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: [Call for Paper - SCOPUS/ISI THOMSON] ICESTI 2014, September 10-13, 2014, Kuta Bali - Indonesia

2014-05-03 Thread Denis McMahon
On Sat, 03 May 2014 06:51:02 -0700, icesti2014editor wrote:

 sharing best practice in the field of Engineering, Science, and
 Technology towards sustainable development.

 The first event of this conference series (ICESTI 2014) will be held in
 Bali, Indonesia

Let's all fly to Bali in the name of sustainability and preserving the 
planet, and damn the CO2 created by doing so.

-- 
Denis McMahon, denismfmcma...@gmail.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Hi. I want to create a script to read a file placed in a remote linux server using python..need help..?

2014-05-02 Thread Denis McMahon
On Fri, 02 May 2014 12:55:18 -0700, Bhawani Singh wrote:

 I have created the script till here ..
 
 import os
 
 os.chdir(/var/log)
 fd = open(t1.txt, r)
 for line in fd:
 if re.match((.*)(file1)(.*), line):
 print line,
 
 Output :
 
 file1
 
 
 this script i ran on the linux server, but now i want to run this script
 from another linux server and get the output displayed there..how can i
 do that...
 
 i tried to use : pexpect but getting no help..

Method a:

Go and sit in front of the keyboard on the other linux server, run the 
script and read the screen.

Method b:

Use telnet to login to your account on the other server, run the script.

To run your script on someone elses machine usually needs you to be able 
to access their machine somehow. Either you are permitted to do it, in 
which case you should already know how to do it, or you're not permitted 
to do it, in which case we're not going to teach you how to do it here.

-- 
Denis McMahon, denismfmcma...@gmail.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to get final URL after redirection

2014-04-27 Thread Denis McMahon
On Sun, 27 Apr 2014 22:41:57 +0500, Rana Muhammad Usman wrote:

 On Sun, Apr 27, 2014 at 8:55 PM, Joel Goldstick
 joel.goldst...@gmail.comwrote:

 ranasa...@gmail.com wrote:

 Hi Nsihant, I need your help, can I get your email address?

 Huh? His email is in his post On Apr 27, 2014 11:45 AM,

 Not visible to me, can you tell me please?

Get some clues about usenet[see below]. Then you'd be able to see his 
email address.

[1] Don't use google groups to access usenet messages, use an nntp client 
that talks to real newsservers.
[2] Learn not to top post.
[3] See 1, 2.
[4] see [3]
[5] repeat to infinity, referencing previous item each time.

pythonically:

while isUsingGoogleGroups or isTopPosting:
stop_doing_that()

-- 
Denis McMahon, denismfmcma...@gmail.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: python obfuscate

2014-04-12 Thread Denis McMahon
On Thu, 10 Apr 2014 18:29:21 -0700, Wesley wrote:

 Currently our company wanna release one product developed by python to
 our customer. But dont's wanna others see the py code.

Your business model is fucked.

-- 
Denis McMahon, denismfmcma...@gmail.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: the logical operation confused me

2014-04-10 Thread Denis McMahon
On Fri, 11 Apr 2014 07:02:33 +0800, length power wrote:

 ok or not ok
 'ok'
 ok and not ok
 'not ok'


 why ok or not ok output ok  , ok and not ok  output not ok ?

I believe that:

[ (falsey condition) or ]* (first truthy condition) or (any condition) 
[ or (any condition) ]*

will return (first truthy condition)

whereas:

(truthy condition) and [ (truthy condition) and ]* (last truthy condition)

will return (last truthy condition)

where [ clause ]* represents an optional clause that may be repeated 
any number of times, any condition may evaluate falsey or truthy, 
first and last relate to the position of the condition type in a left 
to right evaluation sequence.

-- 
Denis McMahon, denismfmcma...@gmail.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Latching variables in function

2014-04-08 Thread Denis McMahon
On Tue, 08 Apr 2014 16:09:28 -0400, Grawburg wrote:

 def button():
    pushbutton = 0
   button_value = 0
    pushbutton=bus.read_byte_data(address,GPIOB)
    if pushbutton  0:
         button_value = 1
    return button_value

Every time your function is called, you start out with button_value of 0.

You may need a global variable that starts out as False (or 0), and once 
flipped to True (or 1) and then stays there:

button_value = False # or: button_value = 0

def button():
global button_value
    pushbutton = bus.read_byte_data( address, GPIOB )
    if pushbutton  0:
         button_value = True # or: button_value = 1
    return button_value

Also I think I'd probably pass the IO address as a parameter to the 
button function.

-- 
Denis McMahon, denismfmcma...@gmail.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Extracting parts of string between anchor points

2014-02-27 Thread Denis McMahon
On Thu, 27 Feb 2014 20:07:56 +, Jignesh Sutar wrote:

 I've kind of got this working but my code is very ugly. I'm sure it's
 regular expression I need to achieve this more but not very familiar
 with use regex, particularly retaining part of the string that is being
 searched/matched for.
 
 Notes and code below to demonstrate what I am trying to achieve. Any
 help,
 much appreciated.

It seems you have a string which may be split into between 1 and 3 
substrings by the presence of up to 2 delimeters, and that if both 
delimeters are present, they are in a specified order.

You have several possible cases which, broadly speaking, break down into 
4 groups:

(a) no delimiters present
(b) delimiter 1 present
(c) delimiter 2 present
(d) both delimiters present

It is important when coding for such scenarios to consider the possible 
cases that are not specified, as well as the ones that are.

For example, consider the string:

delim1delim2

where you have both delims, in sequence, but no other data elements.

I believe there are at least 17 possible combinations, and maybe another 
8 if you allow for the delims being out of sequence.

The code in the file at the url below processes 17 different cases. It 
may help, or it may confuse.

http://www.sined.co.uk/tmp/strparse.py.txt

-- 
Denis McMahon, denismfmcma...@gmail.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Extracting parts of string between anchor points

2014-02-27 Thread Denis McMahon
On Fri, 28 Feb 2014 00:55:01 +, Denis McMahon wrote:

 The code in the file at the url below processes 17 different cases. It
 may help, or it may confuse.

 http://www.sined.co.uk/tmp/strparse.py.txt

I added some more cases to it, and then realised that the code could 
actually be simplified quite a lot. So now it has been.

-- 
Denis McMahon, denismfmcma...@gmail.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Just For Inquiry

2014-02-21 Thread Denis McMahon
On Thu, 20 Feb 2014 20:58:52 +0530, shivang patel wrote:

 So, I kindly request to you please, give me a very brief info regarding
 *Role of Project Manager*.

while not project_is_finished():
take_steps_to_advance_project()

-- 
Denis McMahon, denismfmcma...@gmail.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Storing the state of script between steps

2014-02-21 Thread Denis Usanov
Good evening.

First of all I would like to apologize for the name of topic. I really didn't 
know how to name it more correctly.

I mostly develop on Python some automation scripts such as deployment (it's not 
about fabric and may be not ssh at all), testing something, etc. In this terms 
I have such abstraction as step.

Some code:

class IStep(object):
def run():
raise NotImplementedError()

And the certain steps:

class DeployStep: ...
class ValidateUSBFlash: ...
class SwitchVersionS: ...

Where I implement run method. 
Then I use some builder class which can add steps to internal list and has a 
method start running all step one by one.

And I like this. It's loosely coupled system. It works fine in simple cases. 
But sometimes some steps have to use the results from previous steps. And now I 
have problems. Before now I had internal dict in builder and named it as 
world and passed it to each run() methods of steps. It worked but I disliked 
this. 

How would you solve this problem and how would you do it? I understant that 
it's more architecture specific question, not a python one. 

I bet I wouldn't have asked this if I had worked with some of functional 
programming languages.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Explanation of list reference

2014-02-14 Thread Denis McMahon
On Fri, 14 Feb 2014 10:54:29 -0800, dave em wrote:

 On Friday, February 14, 2014 11:26:13 AM UTC-7, Jussi Piitulainen wrote:
 dave em writes:
 
 
 
  He is asking a question I am having trouble answering which is how a
 
  variable containing a value differs from a variable containing a
 
  list or more specifically a list reference.
 
 
 
 My quite serious answer is: not at all. In particular, a list is a
 
 value.
 
 
 
 All those pointers to references to locations are implementation
 
 details. The user of the language needs to understand that an object
 
 keeps its identity when it's passed around: passed as an argument,
 
 returned by a function, stored in whatever location, retrieved from
 
 whatever location.
 
 Jessi,
 
 Thanks for your quick response.  I'm still not sure we understand.  The
 code below illustrates the concept we are trying to understand.
 
 Case 1: Example of variable with a specific value from P 170 of IYOCGWP
 
 spam = 42 cheese = spam spam = 100 spam
 100
 cheese
 42
 
 Case 2: Example of variable with a list reference from p 170
 
 spam = [0, 1, 2, 3, 4, 5]
 cheese = spam cheese[1] = 'Hello!' spam
 [0, 'Hello!', 2, 3, 4, 5]
 cheese
 [0, 'Hello!', 2, 3, 4, 5]
 
 What I am trying to explain is this, why in case 1 when acting on spam
 (changing the value from 42 to 100) only affects spam and not cheese. 
 Meanwhile, in case two acting on cheese also affects spam.

A list is a container for multiple values, when you do:

cheese = spam

You're pointing cheese and spam at the same container. Now anything you 
do to the container (whether by referencing it as cheese or spam) will 
affect the container.

If you want cheese and spam to start out as separate copies of the same 
list that you can manipulate independently, then you can use:

cheese = [ x for x in spam ]
eggs = spam[:]
ham = list( spam )

 spam = [1,2,3,4,5]
 cheese = [ x for x in spam ]
 ham = list( spam )
 eggs = spam[:]
 spam
[1, 2, 3, 4, 5]
 cheese
[1, 2, 3, 4, 5]
 ham
[1, 2, 3, 4, 5]
 eggs
[1, 2, 3, 4, 5]
 cheese[3] = fred
 ham[4] = 'ham'
 eggs[4] ='eggs'
 spam
[1, 2, 3, 4, 5]
 cheese
[1, 2, 3, 'fred', 5]
 ham
[1, 2, 3, 4, 'ham']
 eggs
[1, 2, 3, 4, 'eggs']

-- 
Denis McMahon, denismfmcma...@gmail.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: What are the kinds of software that are not advisable to be developed using Python?

2014-02-08 Thread Denis McMahon
On Sat, 08 Feb 2014 15:54:30 -0800, Sam wrote:

 I got to know about Python a few months ago and today, I want to develop
 only using Python because of its code readability. This is not a healthy
 bias. To play my own devil's advocate, I have a question. What are the
 kinds of software that are not advisable to be developed using Python?

OS Kernels. Hardware drivers.

-- 
Denis McMahon, denismfmcma...@gmail.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: [newbie] making rows of table with discrete values for different number systems

2014-02-03 Thread Denis McMahon
On Sun, 02 Feb 2014 09:44:05 -0800, Jean Dupont wrote:

 I'm looking for an efficient method to produce rows of tables like this:
 
 for base 2 0 0 0 0 0 0 0 1 0 0 1 0 0 0 1 1 0 1 0 0 .
 .
 .
 1 1 1 1
 
 for base 3 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 2 0 0 0 0 1 0 0 0 0 0 1 1 0
 0 0 0 1 2 .
 .
 2 2 2 2 2 2
 
 As you can see the rows are always twice the size of the base I _don't_
 need to have all rows available together in one array which would become
 too large for higher value number bases. It's sufficient to produce one
 row after the other, as I will do further data manipulation on such a
 row immediately.
 
 If someone here could suggest best practices to perform this kind of
 operations,I'd really appreciate it very much
 
 kind regards and thanks in advance jean

s=3
p=s*2

def b(n,x):
s=[]
while n:
s.append(str(n%x))
n=n/x
if s==[]:
return 0
return ''.join(s[::-1])

for i in range(s**p):
r=({:0+str(p)+d}).format(int(b(i,s)))
if len(r)==p:
print [int(r[a])for a in range(len(r))]

change s to 2 or 4 etc

-- 
Denis McMahon, denismfmcma...@gmail.com
-- 
https://mail.python.org/mailman/listinfo/python-list


<    1   2   3   4   5   6   7   >