Re: [Tutor] Reformatting phone number

2008-08-20 Thread Dotan Cohen
2008/8/21 Robert Berman <[EMAIL PROTECTED]>: > One can 'quasi' compile Python code. Since you come from a C background and > I come from a C++ background, a Python compile isn't really compiling an > object module. I don't see an object file, I don't see an executable; > therefore, in my opinion, P

Re: [Tutor] Reformatting phone number

2008-08-20 Thread Dotan Cohen
2008/8/21 Kent Johnson <[EMAIL PROTECTED]>: > Another way to write this is > if sys.argv[1].startswith('0'): Nice! I had looked for this type of function, but could not find it. Is there a list of functions, organized by categories, for Python? Take for example these pages from te php documentat

Re: [Tutor] programming tic tac toe

2008-08-20 Thread Alan Gauld
"Ark" <[EMAIL PROTECTED]> wrote I used a list (with lists inside) to represent the board. And to identify a winning line I used many if's, like this one: def line(board): if board[0][0] == board[1][1] == board[2][2]: return True I did not like using all those if's, and I would like

[Tutor] programming tic tac toe

2008-08-20 Thread Ark
Hi. I programmed a simple tic tac toe game in python. I already finished it, but I'm not pleased with the way I used to identify a line. I used a list (with lists inside) to represent the board. And to identify a winning line I used many if's, like this one: def line(board): if board[0][0] ==

Re: [Tutor] Reformatting phone number

2008-08-20 Thread Kent Johnson
On Wed, Aug 20, 2008 at 4:43 PM, Dotan Cohen <[EMAIL PROTECTED]> wrote: > I have a small script (linux) that takes a phone number as an argument: > #!/usr/bin/env python > import sys > number = '+' + sys.argv[1] > > > However, if the first digit of the phone number is a 0 then I need to > repl

Re: [Tutor] Reformatting phone number

2008-08-20 Thread Dotan Cohen
2008/8/21 Robert Berman <[EMAIL PROTECTED]>: > Not directly as in C, but, for example, if you have s='3' and you want s > used as an integer, you can say s=int(s) and it is an integer. Conversely, > if you have a question about the type, you could also say type(s) which, > depending, will return, '

Re: [Tutor] Reformatting phone number

2008-08-20 Thread Dotan Cohen
2008/8/21 Alan Gauld <[EMAIL PROTECTED]>: > "Dotan Cohen" <[EMAIL PROTECTED]> wrote > >> know if this is the case. Can I declare a variable type in Python as >> in C? > > In Python values have types and variables are simply > names associated with values. > > Thus > > v = '123'# v 'is' a string

Re: [Tutor] Reformatting phone number

2008-08-20 Thread Alan Gauld
"Dotan Cohen" <[EMAIL PROTECTED]> wrote know if this is the case. Can I declare a variable type in Python as in C? In Python values have types and variables are simply names associated with values. Thus v = '123'# v 'is' a string because '123' is a string v = 123 # now v 'is' an int

Re: [Tutor] Reformatting phone number

2008-08-20 Thread Robert Berman
Not directly as in C, but, for example, if you have s='3' and you want s used as an integer, you can say s=int(s) and it is an integer. Conversely, if you have a question about the type, you could also say type(s) which, depending, will return, 'str','int', etc. Hope this helps a bit. Robert

Re: [Tutor] Reformatting phone number

2008-08-20 Thread Dotan Cohen
2008/8/21 Robert Berman <[EMAIL PROTECTED]>: > Perhaps because preNumber is a character and not an integer? > Perhaps. In php the distinction was made by the fact that there were no non-numerical characters in a string. I don't know enough Python to know if this is the case. Can I declare a variab

Re: [Tutor] named pipe problem

2008-08-20 Thread Kent Johnson
On Wed, Aug 20, 2008 at 4:53 PM, Kent Johnson <[EMAIL PROTECTED]> wrote: > See this informative thread: > http://mail.python.org/pipermail/python-list/2006-August/396499.html > > Summary: opening a pipe for write blocks until it is also opened for read. Also, on Mac OSX at least ordinary file ope

Re: [Tutor] Reformatting phone number

2008-08-20 Thread Robert Berman
Perhaps because preNumber is a character and not an integer? Robert Dotan Cohen wrote: I was missing the quotes in the if statement. Changing if preNumber[0] == 0: to if preNumber[0] == "0": fixed the problem. Why did I need those quotes? The 0 is numerical, so it should not need the quot

Re: [Tutor] Reformatting phone number

2008-08-20 Thread Dotan Cohen
I was missing the quotes in the if statement. Changing if preNumber[0] == 0: to if preNumber[0] == "0": fixed the problem. Why did I need those quotes? The 0 is numerical, so it should not need the quotes, no? -- Dotan Cohen http://what-is-what.com http://gibberish.co.il א-ב-ג-ד-ה-ו-ז-ח-ט-י-ך-כ

Re: [Tutor] Reformatting phone number

2008-08-20 Thread Dotan Cohen
I have gotten a bit farther, but I cannot get this to work as described in the previous mail: #!/usr/bin/env python import sys preNumber = sys.argv[1] if preNumber[0] == 0: number = '+972' + preNumber[1:] else: number = '+' + preNumber Where is my flaw? -- Dotan Cohen http://what-is-w

Re: [Tutor] named pipe problem

2008-08-20 Thread Kent Johnson
On Wed, Aug 20, 2008 at 3:54 PM, dave selby <[EMAIL PROTECTED]> wrote: > Hi All, > > > I am trying to get a named pipe working, I have already made a fifo > > [EMAIL PROTECTED]:/usr/local/bin$ ls -al /home/dave/kmotion2/www/pipe_func > prw-rw 1 dave www-data 0 2008-08-20 20:25 > /home/dave/kmo

[Tutor] Reformatting phone number

2008-08-20 Thread Dotan Cohen
I have a small script (linux) that takes a phone number as an argument: #!/usr/bin/env python import sys number = '+' + sys.argv[1] However, if the first digit of the phone number is a 0 then I need to replace that 0 with "972". I can add the "972", but how do I remove the leading "0"? For i

[Tutor] named pipe problem

2008-08-20 Thread dave selby
Hi All, I am trying to get a named pipe working, I have already made a fifo [EMAIL PROTECTED]:/usr/local/bin$ ls -al /home/dave/kmotion2/www/pipe_func prw-rw 1 dave www-data 0 2008-08-20 20:25 /home/dave/kmotion2/www/pipe_func [EMAIL PROTECTED]:/usr/local/bin$ but when I execute my test cod

Re: [Tutor] Is this a "Class" problem?

2008-08-20 Thread Jeff Younker
I'm assuming you do that so that you don't confuse what a Python built-in method (or function) is, compared to methods (or functions) that you've authored. It's done more to distinguish classes from methods and attributes. I can't claim any credit though. It's part of the python coding con

Re: [Tutor] names and variables

2008-08-20 Thread Kent Johnson
On Wed, Aug 20, 2008 at 5:37 AM, Marc Tompkins <[EMAIL PROTECTED]> wrote: > print(getattr(myObject, "colour")) Or, of course, print getattr(myObject, myAttribute) which is what the OP wanted. Kent ___ Tutor maillist - Tutor@python.org http://mail.pyt

Re: [Tutor] names and variables

2008-08-20 Thread Lie Ryan
On Wed, 2008-08-20 at 11:37 +0200, [EMAIL PROTECTED] wrote: > Message: 7 > Date: Wed, 20 Aug 2008 17:30:37 +0800 > From: Jim Morcombe <[EMAIL PROTECTED]> > Subject: [Tutor] names and variables > To: tutor@python.org > Message-ID: <[EMAIL PROTECTED]> > Content-Type: text/plain; charset=ISO-8859-1; f

Re: [Tutor] names and variables

2008-08-20 Thread Marc Tompkins
On Wed, Aug 20, 2008 at 2:30 AM, Jim Morcombe <[EMAIL PROTECTED]>wrote: > I have an object called "myObject" with an attribute called "colour". > > If I type: > print myObject.colour > then python prints: >red > > Now, I have a variable "myAttribute" and set its value to "colour" by > typin

[Tutor] names and variables

2008-08-20 Thread Jim Morcombe
I have an object called "myObject" with an attribute called "colour". If I type: print myObject.colour then python prints: red Now, I have a variable "myAttribute" and set its value to "colour" by typing: myAttribute = "colour" I want to have a line of code: something like this: