Re: [Tutor] web programming tutorials?

2008-04-17 Thread Norman Khine
Hi Che,
I started with python web programming using Zope, but this was because I 
needed a quick CMS application for a small project I did and Zope's CMF 
fitted the bill nicely.

Now I use itools (http://ikaaro.org/itools) it is relatively easy to 
setup and is 99% python (the parser is now in C) the latest version has 
two packages, the core itools is a python library and ikaaro is the CMS.

Here are the docs, http://download.ikaaro.org/doc/itools/index.html

Hope this helps.
Good luck.

Che M wrote:
> [I thought I sent a similar msg to this list 2 days ago, but now I'm not 
> sure it went through, so sorry if I've doubled]
> 
> Can someone point me to a start-from-dead-scratch tutorial about the 
> basics of web programming?  I've been learning wxPython for GUI 
> programming, but web programming (that is, making web applications) 
> seems like another world entirely.  I'm aware of *names*--Django, 
> Pylons, CherryPy, TurboGears, Zope, Webpy, etc.--but I have a poor sense 
> of what all this means,  and so I am sort of 'pre-Python' in my 
> understanding.  I've scanned the archives of this list, but so far 
> haven't found pointers to tutorials that assume very little knowledge. 
> 
> I was kind of hoping Alan Gauld's project would be updated for the 
> tempting but not yet existent section on web programming.  Any word on 
> that, Alan?  In lieu of that, can anyone recommend books/online 
> tutorials/words of advice?
> 
> Thanks,
> Che
> 
> 
> 
> Pack up or back up–use SkyDrive to transfer files or keep extra copies. 
> Learn how. 
> 
> 
> 
> 
> 
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor

-- 
Norman Khine
24 rue de la Madeleine, 3, Nîmes, France
tel +33 (0) 466 267 064 e-fax +44 7006 009 324

%>>> "".join( [ {'*':'@','^':'.'}.get(c,None) or chr(97+(ord(c)-83)%26) 
for c in ",adym,*)&uzq^zqf" ] )
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] web programming tutorials?

2008-04-17 Thread Oleg Oltar
OK. take a look on the pages:

 1. http://www.djangobook.com/
 2. Official docs on http://www.djangoproject.com/
 3. Dive into python (http://diveintopython.org/)
 4. And the last one (but the best) showmedo: http://showmedo.com/

On Fri, Apr 18, 2008 at 6:20 AM, Che M <[EMAIL PROTECTED]> wrote:

>  [I thought I sent a similar msg to this list 2 days ago, but now I'm not
> sure it went through, so sorry if I've doubled]
>
> Can someone point me to a start-from-dead-scratch tutorial about the
> basics of web programming?  I've been learning wxPython for GUI programming,
> but web programming (that is, making web applications) seems like another
> world entirely.  I'm aware of *names*--Django, Pylons, CherryPy, TurboGears,
> Zope, Webpy, etc.--but I have a poor sense of what all this means,  and so I
> am sort of 'pre-Python' in my understanding.  I've scanned the archives of
> this list, but so far haven't found pointers to tutorials that assume very
> little knowledge.
>
> I was kind of hoping Alan Gauld's project would be updated for the
> tempting but not yet existent section on web programming.  Any word on that,
> Alan?  In lieu of that, can anyone recommend books/online tutorials/words of
> advice?
>
> Thanks,
> Che
>
>
> --
> Pack up or back up–use SkyDrive to transfer files or keep extra copies. Learn
> how.
>
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
>
>
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] web programming tutorials?

2008-04-17 Thread Che M

[I thought I sent a similar msg to this list 2 days ago, but now I'm not sure 
it went through, so sorry if I've doubled]

Can someone point me to a start-from-dead-scratch tutorial about the basics of 
web programming?  I've been learning wxPython for GUI programming, but web 
programming (that is, making web applications) seems like another world 
entirely.  I'm aware of *names*--Django, Pylons, CherryPy, TurboGears, Zope, 
Webpy, etc.--but I have a poor sense of what all this means,  and so I am sort 
of 'pre-Python' in my understanding.  I've scanned the archives of this list, 
but so far haven't found pointers to tutorials that assume very little 
knowledge.  

I was kind of hoping Alan Gauld's project would be updated for the tempting but 
not yet existent section on web programming.  Any word on that, Alan?  In lieu 
of that, can anyone recommend books/online tutorials/words of advice?

Thanks,
Che


_
Pack up or back up–use SkyDrive to transfer files or keep extra copies. Learn 
how.
http://www.windowslive.com/skydrive/overview.html?ocid=TXT_TAGLM_WL_Refresh_skydrive_packup_042008___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] datetime module problem

2008-04-17 Thread Dick Moores
Got it, I think. 

The crucial lines are 22, 27.

Thanks all,

Dick




UliPad <>: http://code.google.com/p/ulipad/ 

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Need suggestion / advice - controlling remote server

2008-04-17 Thread Alan Gauld

"dave selby" <[EMAIL PROTECTED]> wrote

> The question is how to communicate with the remote kmotion servers
> Python daemons. I could access the images via port 80, no prob but I
> need the KDE interface to change configs etc and restart services.

You should still be able to do thast via a web interface. Restarts
are probably the trickiest becauyse you need to be able to pick
up again with the admin interface after the restart. But its not that 
tricky.

> ...getting the KDE interface to ssh in and do the changes

That will work too, but a web admin is probably easier for users
since you don't need to maintain a thick client on the desktop.

Alan G 


___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] datetime module problem

2008-04-17 Thread Dick Moores
At 01:29 PM 4/17/2008, Hansen, Mike wrote:
>
>
> > -Original Message-
> > From: [EMAIL PROTECTED]
> > [mailto:[EMAIL PROTECTED] On Behalf Of Dick Moores
> > Sent: Thursday, April 17, 2008 2:21 PM
> > To: Python Tutor List
> > Subject: Re: [Tutor] datetime module problem
> >
> > At 06:29 AM 4/17/2008, Kent Johnson wrote:
> > >Dick Moores wrote:
> > >
> > >>>You could either create n with hours=minutes=0, or round the
> > >>>difference up to the next whole number of days.
> > >>I have no idea how to implement either of your suggestions as to
> > >>how to eliminate it. Could you please spell them both out?
> > >
> > >1.
> > >
> > >In [17]: n=datetime.today()
> > >In [18]: n=datetime(n.year, n.month, n.day)
> > >In [19]: n
> > >Out[19]: datetime.datetime(2008, 4, 17, 0, 0)
> > >
> > >2.
> > >
> > >In [20]: diff=y-n
> > >In [21]: diff
> > >Out[21]: datetime.timedelta(0, 57464, 721369)
> > >In [22]: days = diff.days
> > >In [23]: if diff.seconds or diff.microseconds:
> > >: days += 1
> > >:
> > >:
> > >In [24]: days
> > >Out[24]: 1
> >
> > Thanks, Kent. So here's where I am now:
> > 
> >
> > The script calculates correctly, but note the output, lines 34, 39,
> > 49, 53. Please show me how to print these in the form 4/17/2007. I've
> > tried everything I could think of.
> >
> > Dick
> >
>
>
>In [23]: import datetime
>
>In [24]: x = datetime.datetime.now()
>
>In [25]: x
>Out[25]: datetime.datetime(2008, 4, 17, 14, 24, 18, 447000)
>
>In [26]: x.month
>Out[26]: 4
>
>In [27]: x.day
>Out[27]: 17
>
>In [28]: x.year
>Out[28]: 2008
>
>In [30]: print "%s/%s/%s" %(x.month, x.day, x.year, )
>4/17/2008
>
>Does that help? There's probably another way to do it, but this seems to
>work.

Yes, I'd finally done that (honest), so that will take care of lines 
39, 49, but not 34, 53 of .

Thanks,

Dick




UliPad <>: http://code.google.com/p/ulipad/ 

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Need suggestion / advice - controlling remote server

2008-04-17 Thread dave selby
Hi all,

I am after some advice / suggestions. I have written web interface for
viewing CCTV images http://code.google.com/p/kmotion/wiki/ScreenShots
its called 'kmotion'. Underneath its all Python daemons. It usually
runs stand alone on headless servers. Now I am about to write a KDE
interface in Python & QT4 for config & local viewing.

The question is how to communicate with the remote kmotion servers
Python daemons. I could access the images via port 80, no prob but I
need the KDE interface to change configs etc and restart services. I
am thinking of getting the KDE interface to ssh in and do the changes
via shell commands, ie change config files, restarts deamons etc,
should work OK. Is this acceptable ? How would you guys do it ?

Thanks in advance

Dave

-- 

Please avoid sending me Word or PowerPoint attachments.
See http://www.gnu.org/philosophy/no-word-attachments.html
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] datetime module problem

2008-04-17 Thread Hansen, Mike
 

> -Original Message-
> From: [EMAIL PROTECTED] 
> [mailto:[EMAIL PROTECTED] On Behalf Of Dick Moores
> Sent: Thursday, April 17, 2008 2:21 PM
> To: Python Tutor List
> Subject: Re: [Tutor] datetime module problem
> 
> At 06:29 AM 4/17/2008, Kent Johnson wrote:
> >Dick Moores wrote:
> >
> >>>You could either create n with hours=minutes=0, or round the 
> >>>difference up to the next whole number of days.
> >>I have no idea how to implement either of your suggestions as to 
> >>how to eliminate it. Could you please spell them both out?
> >
> >1.
> >
> >In [17]: n=datetime.today()
> >In [18]: n=datetime(n.year, n.month, n.day)
> >In [19]: n
> >Out[19]: datetime.datetime(2008, 4, 17, 0, 0)
> >
> >2.
> >
> >In [20]: diff=y-n
> >In [21]: diff
> >Out[21]: datetime.timedelta(0, 57464, 721369)
> >In [22]: days = diff.days
> >In [23]: if diff.seconds or diff.microseconds:
> >: days += 1
> >:
> >:
> >In [24]: days
> >Out[24]: 1
> 
> Thanks, Kent. So here's where I am now: 
> 
> 
> The script calculates correctly, but note the output, lines 34, 39, 
> 49, 53. Please show me how to print these in the form 4/17/2007. I've 
> tried everything I could think of.
> 
> Dick
> 


In [23]: import datetime

In [24]: x = datetime.datetime.now()

In [25]: x
Out[25]: datetime.datetime(2008, 4, 17, 14, 24, 18, 447000)

In [26]: x.month
Out[26]: 4

In [27]: x.day
Out[27]: 17

In [28]: x.year
Out[28]: 2008

In [30]: print "%s/%s/%s" %(x.month, x.day, x.year, )
4/17/2008

Does that help? There's probably another way to do it, but this seems to
work.

Mike
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] datetime module problem

2008-04-17 Thread Kent Johnson
Dick Moores wrote:
> The script calculates correctly, but note the output, lines 34, 39, 
> 49, 53. Please show me how to print these in the form 4/17/2007. I've 
> tried everything I could think of.

Come to think of it, you should be using datetime.date everywhere 
instead of datetime.datetime; you are always trying to get rid of the 
time part of datetime.

Then look at date.strftime() or datetime.strftime() to format the 
output. Use the same format string as for strptime().

Kent
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] datetime module problem

2008-04-17 Thread Dick Moores
At 06:29 AM 4/17/2008, Kent Johnson wrote:
>Dick Moores wrote:
>
>>>You could either create n with hours=minutes=0, or round the 
>>>difference up to the next whole number of days.
>>I have no idea how to implement either of your suggestions as to 
>>how to eliminate it. Could you please spell them both out?
>
>1.
>
>In [17]: n=datetime.today()
>In [18]: n=datetime(n.year, n.month, n.day)
>In [19]: n
>Out[19]: datetime.datetime(2008, 4, 17, 0, 0)
>
>2.
>
>In [20]: diff=y-n
>In [21]: diff
>Out[21]: datetime.timedelta(0, 57464, 721369)
>In [22]: days = diff.days
>In [23]: if diff.seconds or diff.microseconds:
>: days += 1
>:
>:
>In [24]: days
>Out[24]: 1

Thanks, Kent. So here's where I am now: 


The script calculates correctly, but note the output, lines 34, 39, 
49, 53. Please show me how to print these in the form 4/17/2007. I've 
tried everything I could think of.

Dick




UliPad <>: http://code.google.com/p/ulipad/ 

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] python assignments

2008-04-17 Thread Dick Moores
At 04:42 AM 4/17/2008, you wrote:
>Dear friends,
>
>I covered few introductory books on python. B4 going for an advanced 
>book, i want to take up small, small assignments and try to solve 
>with python. Can someone please suggest me any url where i can have 
>assignments and solutions.

http://projecteuler.net/index.php?section=problems

Dick Moores




UliPad <>: http://code.google.com/p/ulipad/ 

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] python assignments

2008-04-17 Thread Alan Gauld

"Bala subramanian" <[EMAIL PROTECTED]> wrote

> someone please suggest me any url where i can have assignments and
> solutions.

The old Useless Python website had a whole bundle of these.
And of course you should try the Python Challenge web game.

Alan G

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] HELP!!!!!

2008-04-17 Thread Alan Gauld

"Michael Kim" <[EMAIL PROTECTED]> wrote

> Hi I am having a really hard time making my tictactoe program work. 
> I
> was wondering if you could could check it out and help me with the
> error.  Thanks

Like to give us a clue as to what the error is?
And include the error message if there is one please.

However, at a quick glance:

> def pieces():
>whosefirst=askquestion("Do you want to go first? (y/n): ")
>if whosefirst == "y":
>human = X

I would expect that to fail since you haven't defined the
variable X yet. You need to put the line below above
the assignment...

>X="X"
>computer = O
>O="O"
>else:
>computer = X
>human = O

Similarly here, X and O are not defined anywhere.

This is as far
-- 
Alan Gauld
Author of the Learn to Program web site
http://www.freenetpages.co.uk/hp/alan.gauldas I read...



___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Error with incorrect encoding

2008-04-17 Thread Alan Gauld
I don't know the cause of the error here but I will say that
parsing HTML with regular expressions is fraught with difficulty
unless you know that the HTML will be suitably formatted
in advance.

You may be better off using one of the HTML parsing
modules such as HTMLParser or even the more powerful
BeautifulSoup.

-- 
Alan Gauld
Author of the Learn to Program web site
http://www.freenetpages.co.uk/hp/alan.gauld



"Oleg Oltar" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
>I am trying to parse an html page. Have following error while doing 
>that
>
>
> src = sel.get_html_source()
>links = re.findall(r'', src)
>for link in links:
>print link
>
>
>
> ==
> ERROR: test_new (__main__.NewTest)
> --
> Traceback (most recent call last):
>  File "", line 19, in test_new
> UnicodeEncodeError: 'ascii' codec can't encode character u'\xae' 
> in
> position 90: ordinal not in range(128)
>
> --
> Ran 1 test in 6.345s
>





> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
> 


___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] input and output files from terminal

2008-04-17 Thread Alan Gauld

"Brain Stormer" <[EMAIL PROTECTED]> wrote

> Thanks for the file direction method but how do I get the names of 
> the files
> so I can use it inside my program.

I'm not sure I understand.

Thepoint of using redirection is that your code doesn't need to know
anything about the files, it just reads/writes to/from stdin/stdout.

The OS connects the bits together at runtime.

>> Easier to use file redirection:
>>
>> python test.py < inputfile > outputfile

So you can provide any name you like for inputfile
and outputfile when you execute the program.

If you want the program to read/write to a specific file then
use the standard open()/read/write functions

Or am I missing something?

Alan G. 


___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] HELP!!!!!

2008-04-17 Thread Chris Calloway
On 4/17/2008 3:40 AM, Michael Kim wrote:
> Hi I am having a really hard time making my tictactoe program work.  I 
> was wondering if you could could check it out and help me with the 
> error.  Thanks

Heh.

First, there are two obvious indentation errors you can find yourself. 
This may be a byproduct of having pasted your program into an email. 
Email programs will often incorrectly reformat Python code so that the 
indentation no longer works. To send long code listings to an email 
list, use a pastebin like:

http://python.pastebin.com/

and send us the link of your pasted code.

So after you fix the indentation errors, we get this:

 >>> main()
Do you want to go first? (y/n): y
Traceback (most recent call last):
   File "", line 1, in ?
   File "", line 2, in main
   File "", line 4, in pieces
UnboundLocalError: local variable 'X' referenced before assignment
 >>>

And if you look just where the traceback is telling you (line 4 of 
function pieces):

 >>> def pieces():
... whosefirst=askquestion("Do you want to go first? (y/n): ")
... if whosefirst == "y":
... human = X

You see that you did indeed do exactly what the traceback told you. You 
referenced a local variable named X before anything was assigned to X.

Good luck with your homework!

-- 
Sincerely,

Chris Calloway
http://www.secoora.org
office: 332 Chapman Hall   phone: (919) 599-3530
mail: Campus Box #3300, UNC-CH, Chapel Hill, NC 27599
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] HELP!!!!!

2008-04-17 Thread bob gailer
Michael Kim wrote:
> Hi I am having a really hard time making my tictactoe program work.  I 
> was wondering if you could could check it out and help me with the 
> error.  Thanks
>   

As Kent pointed out, we need to see the error you are getting in order 
to help. That usually shows up as a traceback. When I run your program I 
get:

  File "j:/python/tictactoe.py", line 53

movestowin=((0,1,2),(3,4,5),(6,7,8),(0,3,6),(1,4,7),(2,5,8),(0,4,8),(2,4,6))

 ^
IndentationError: expected an indented block

There are numerous other problems in your code. As you fix one error the 
next will be revealed. For example when I fix the indentation error I 
next get:

  File "J:\python\tictactoe.py", line 124, in 
main()
  File "J:\python\tictactoe.py", line 105, in main
computer, human = pieces()
  File "J:\python\tictactoe.py", line 20, in pieces
human = X
UnboundLocalError: local variable 'X' referenced before assignment

Do you understand that variables must be assigned before reference? 
Python does not know what X is.
So please report the specific error. Also try to determine what it means 
before reporting it.
>
> blank = " "
>
>
>
> def asknumber(question, low, high):
> response = None
> while response not in range(low, high):
> response = int(raw_input(question))
> return response
>
> def askquestion(question):
> response = None
> while response not in ("y", "n"):
> response = raw_input (question).lower()
> return response
>
> def pieces():
> whosefirst=askquestion("Do you want to go first? (y/n): ")
> if whosefirst == "y":
> human = X
>   
X is undefined (here and below)
> X="X"
> computer = O
>   
O is undefined (here and below)
> O="O"
> else:
> computer = X
> human = O
> return computer, human
>
> def newboard():
> board = []
> box = 9
> for square in range(box):
> blank = " "
> board.append(blank)
> return board
>
> def createboard(board):
> print "\n\t", board[0], "|", board[1], "|", board[2]
> print "\t", "-"
> print "\t", board[3], "|", board[4], "|", board[5]
> print "\t", "-"
> print "\t", board[6], "|", board[7], "|", board[8], "\n"
>
> def allowedmove(board):
> moves=[]
> for square in range(box):
> if board[square] == blank:
> moves.append(square)
> return moves
>
> def winner(board):
> 
> movestowin=((0,1,2),(3,4,5),(6,7,8),(0,3,6),(1,4,7),(2,5,8),(0,4,8),(2,4,6))
> for row in movestowin:
> if board[row[0]] == board[row[1]] ==board[row[2]] !=blank:
> winner=board[row[0]]
> return winner
> if blank not in board:
> tie = "tie"
> return tie
> return None
>
> def humanmove (board, human):
> allowed = allowedmove(board)
> move = None
> while move not in allowed:
> move = asknumber("It is your turn.  Pick 0-8:", 0, box)
> if move not in allowed:
> print "\nPick again.\n"
> return move
>
> def computermove (board, computer, human):
> board = board[:]
> winnermoves = (4, 0, 2, 6, 8, 1, 3, 5, 7)
> for move in allowedmoves(board):
> board[move] = computer
> if winner (board) == computer:
> print move
> return move
> board[move] = blank
> for move in allowedmoves(board):
> board[move] = human
> if winner(board) == human:
> print move
> return move
> board[move] = blank
> for move in winnermoves:
> if move in allwedmoves(board):
> print move
> return move
>
> def whoseturn(turn):
> if turn == X:
> return O
> else:
> return X
>
> def whowon(iwon, computer, human):
> if iwon !=tie:
> print iwon, "you win!"
> else:
> print "a tie"
>
> def main():
> computer, human = pieces()
> turn = X
> board = newboard()
> createboard(board)
>
> while not winner(board):
> if turn == human:
> move = humanmove(board, human)
> board[move] = human
> else:
> move = computermove(board, computer, human)
> board[move] = computer
> createboard(board)
> turn = whoseturn(turn)
>
> iwon =  winner(board)
> whowon(iwon, computer, human)
>
>
> main()
>
>
>
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
>
>   


-- 
Bob Gailer
919-636-4239 Chapel Hill, NC

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Best practice for installing new packages (eggs)

2008-04-17 Thread python
I would like to take a look at the wxOptParse package. This is my first
time installing a package (vs. a module) so I'm looking for feedback on
what installation technique I should use and where (in terms of folder
paths) one would normally install 3rd party packages. For example, is
are there conventions for where to put core packages, experimental
packages, and packages that one is building themselves?

Also, is it safe to assume that installing a 3rd party package won't
(unexpectedly) affect other parts of my Python environment.

I'm running Python 2.5.2 on Windows XP Pro SP2.

Here are the 3 installation options that wxOptParse provides:


Choose one of the following methods.  In all cases you probably need to
run as root.

Egg Download


# easy_install.py wxoptparse

Egg File
-

# easy_install.py wxOptParse-x.y.z-py2.4.egg

Easy Install Zip


# easy_install.py wxOptParse-x.y.z.zip

Normal Python Install
--

# unzip wxOptParse-x.y.z.zip
# cd wxOptParse-x.y.z
# python setup.py install

Also note the following run instructions:

If you want to run your program you should be able to type:

wxoptparse myprogram.py

Under Windows you may need to add "c:\Python2.4\scripts" to your path
(or whatever directory python is installed) in order to run wxoptparse.

The standard Python installer does not appear to do this for you.



Thank you!

Malcolm
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] input and output files from terminal

2008-04-17 Thread Brain Stormer
Actually, Let me take that back with the raw_input comment since it is not
the idle issue but I didn't want to the program to be interactive so I
didn't want to wait for someone to put the information and press enter.
Thanks for the file direction method but how do I get the names of the files
so I can use it inside my program.

On Mon, Apr 14, 2008 at 2:57 PM, Alan Gauld <[EMAIL PROTECTED]>
wrote:

>
> "Brain Stormer" <[EMAIL PROTECTED]> wrote
>
> >I have a python program which works fine when run using idle but I
> >would
> > like call the program from the terminal.
> >
> > python test.py -i inputfile -o outputfile
>
> Easier to use file redirection:
>
> python test.py < inputfile > outputfile
>
> The -i flag in particular might conflict with Pythons own -i option.
>
> > I tried with raw_input but that only works in idle.
>
> What makes you think that?
> raw_input is the normal way to get input from stdin.
>
> Can you explain what you did and what the result was?
> Perhaps with a short code example?
>
> Try this for example:
>
> 
>
> name = raw_input('What's your name? ')
> print "hello", name
>
> 
>
> That can be run in IDLE or in a command window
> or using file redirection as described above.
>
> Tell us how you get on...
>
>
> --
> Alan Gauld
> Author of the Learn to Program web site
> http://www.freenetpages.co.uk/hp/alan.gauld
>
>
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
>
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Error with incorrect encoding

2008-04-17 Thread linuxian iandsd
Kent was right,

>>> print u'\xae'.encode('utf-8')
> (R)
>


but i think you are using the wrong source file, i mean don't copy & paste
it from your browsers 'VIEW SOURCE' button. use python native urllib to get
the file.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] datetime module problem

2008-04-17 Thread Kent Johnson
Dick Moores wrote:

>> You could either create n with hours=minutes=0, or round the 
>> difference up to the next whole number of days.
> 
> I have no idea how to implement either of 
> your suggestions as to how to eliminate it. Could you please spell 
> them both out?

1.

In [17]: n=datetime.today()
In [18]: n=datetime(n.year, n.month, n.day)
In [19]: n
Out[19]: datetime.datetime(2008, 4, 17, 0, 0)

2.

In [20]: diff=y-n
In [21]: diff
Out[21]: datetime.timedelta(0, 57464, 721369)
In [22]: days = diff.days
In [23]: if diff.seconds or diff.microseconds:
: days += 1
:
:
In [24]: days
Out[24]: 1

Kent
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] python assignments

2008-04-17 Thread linuxian iandsd
http://www.pythonchallenge.com/
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] datetime module problem

2008-04-17 Thread Dick Moores
At 05:10 AM 4/17/2008, Kent Johnson wrote:
>Dick Moores wrote:
>
>>from datetime import datetime
>>print "Enter 2 dates, first the earlier date, then the later date."
>>def getDate():
>> date = raw_input("Enter date as month/day/year, or enter 
>> nothing for today: ")
>> if date == "":
>> date = datetime.now()
>> print "Today's date entered"
>> else:
>> date = datetime.strptime(date, '%m/%d/%Y')
>> return date
>>
>>print "What's the earlier date?"
>>date1 = getDate()
>>print
>>print "What's the later date?"
>>date2 = getDate()
>>print
>>print "The difference between the dates is", (date2 - date1).days, 'days'
>>However, when the earlier date (date1) is today's date entered by 
>>just pressing Enter, the result is always 1 day too small. And I 
>>don't see how to correct this, other than by adding the 1 (and I'd 
>>have to give up using a function, I think). I still don't really 
>>get datetime. Help?
>
>It's a rounding error.
>
>In [3]: from datetime import datetime
>In [4]: n=datetime.now()
>In [5]: n
>Out[5]: datetime.datetime(2008, 4, 17, 8, 2, 15, 278631)
>
>Notice n has a time component.
>
>In [8]: y=datetime.strptime('4/18/2008', '%m/%d/%Y')
>In [14]: y
>Out[14]: datetime.datetime(2008, 4, 18, 0, 0)
>
>y represents midnight on the given date.
>
>In [9]: y-n
>Out[9]: datetime.timedelta(0, 57464, 721369)
>
>So y-n is a fractional day, not a whole day.
>
>You could either create n with hours=minutes=0, or round the 
>difference up to the next whole number of days.

Kent,

Man, I don't think I've ever been so frustrated with Python as I am 
with it's datetime module. I had guessed correctly at WHY I was 
getting that error, but I have no idea how to implement either of 
your suggestions as to how to eliminate it. Could you please spell 
them both out?

Here's my script again: 

Thanks,

Dick




UliPad <>: http://code.google.com/p/ulipad/ 

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] python assignments

2008-04-17 Thread Kent Johnson
Bala subramanian wrote:
> Dear friends,
> 
> I covered few introductory books on python. B4 going for an advanced 
> book, i want to take up small, small assignments and try to solve with 
> python. Can someone please suggest me any url where i can have 
> assignments and solutions.

Here are some ideas:
http://personalpages.tds.net/~kent37/stories/00021.html#e21puzzles-and-problems

Kent
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] datetime module problem

2008-04-17 Thread Kent Johnson
Dick Moores wrote:

> from datetime import datetime
> 
> print "Enter 2 dates, first the earlier date, then the later date."
> def getDate():
> date = raw_input("Enter date as month/day/year, or enter nothing for 
> today: ")
> if date == "":
> date = datetime.now()
> print "Today's date entered"
> else:
> date = datetime.strptime(date, '%m/%d/%Y')
> return date
>
> print "What's the earlier date?"
> date1 = getDate()
> print
> print "What's the later date?"
> date2 = getDate()
> print
> print "The difference between the dates is", (date2 - date1).days, 'days'
> 
> However, when the earlier date (date1) is today's date entered by just 
> pressing Enter, the result is always 1 day too small. And I don't see 
> how to correct this, other than by adding the 1 (and I'd have to give up 
> using a function, I think). I still don't really get datetime. Help?

It's a rounding error.

In [3]: from datetime import datetime
In [4]: n=datetime.now()
In [5]: n
Out[5]: datetime.datetime(2008, 4, 17, 8, 2, 15, 278631)

Notice n has a time component.

In [8]: y=datetime.strptime('4/18/2008', '%m/%d/%Y')
In [14]: y
Out[14]: datetime.datetime(2008, 4, 18, 0, 0)

y represents midnight on the given date.

In [9]: y-n
Out[9]: datetime.timedelta(0, 57464, 721369)

So y-n is a fractional day, not a whole day.

You could either create n with hours=minutes=0, or round the difference 
up to the next whole number of days.

Kent
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] python assignments

2008-04-17 Thread Bala subramanian
Dear friends,

I covered few introductory books on python. B4 going for an advanced book, i
want to take up small, small assignments and try to solve with python. Can
someone please suggest me any url where i can have assignments and
solutions.

Thanks,
Bala
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] datetime module problem

2008-04-17 Thread Dick Moores


At 04:31 PM 4/15/2008, Dick Moores wrote:
At 02:37 PM 4/15/2008, Kent
Johnson wrote:
>Dick Moores wrote:
>>I'm really struggling with the datetime module. Trying for a
script 
>>that will calculate the number of days between any two dates
>
>How about this:
>
>from datetime import datetime
>date1 = raw_input("Enter date1 as year-month-day: ")
>date1 = datetime.strptime(date1, '%Y-%m-%d')
>date2 = raw_input("Enter date2 as year-month-day: ")
>date2 = datetime.strptime(date2, '%Y-%m-%d')
>print "date2 - date1 is", (date2 - date1).days, 'days'
>
>Kent
Yes, thanks, Kent.
I finally tracked down that table for the format string, at 
<
http://docs.python.org/lib/module-time.html>. Been experimenting

with it. Realized that the format string could be the more familiar 
American '%m/%d/%Y', or '%m/%d/%y'.
The docs are so hard for me to understand, that I'm even feeling 
pleased with myself for this:
from datetime import datetime
date1 = raw_input("Enter date1 as year-month-day: ")
date1 = datetime.strptime(date1, '%m/%d/%Y')
today = datetime.now()
print "today - date1 is", (today - date1).days,
'days'
But then I thought it would be handy for the user to be able to just hit
Enter for today's date for either the earlier date or the later one, and
came up with:
from datetime import datetime
print "Enter 2 dates, first the earlier date, then the later
date."
def getDate():
    date = raw_input("Enter date as month/day/year,
or enter nothing for today: ")
    if date == "":
    date = datetime.now()
    print "Today's date
entered"
    else:
    date = datetime.strptime(date,
'%m/%d/%Y') 
    return date
    
print "What's the earlier date?"
date1 = getDate()
print
print "What's the later date?"
date2 = getDate()
print
print "The difference between the dates is", (date2 -
date1).days, 'days'
However, when the earlier date (date1) is today's date entered by
just pressing Enter, the result is always 1 day too small. And I don't
see how to correct this, other than by adding the 1 (and I'd have to give
up using a function, I think). I still don't really get datetime.
Help?
Thanks,
Dick Moores


  

UliPad <>:

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


___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] HELP!!!!!

2008-04-17 Thread Kent Johnson
Michael Kim wrote:
> Hi I am having a really hard time making my tictactoe program work.  I 
> was wondering if you could could check it out and help me with the 
> error.  Thanks

What is the error?

Kent
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Nested dictionary with defaultdict

2008-04-17 Thread Kent Johnson
Kepala Pening wrote:
> count = lambda x: [{y: x.count(y)} for y in set(x)]

At least for long enough lists, this is likely to be more expensive than 
the approach using defaultdict. Your count() function iterates the list 
(1+m) times, where m is the number of distinct words - once to create 
the set, and once for each call to x.count(). The complexity of your 
count() is O(m*n) where n is len(x).

OTOH the defaultdict method is O(n). The loops in your solution are all 
in C code which may give some performance improvement but I expect that 
would be overshadowed by the factor of m as m and n get large.

Kent

> y = {}
> for key, val in myDict.items():
> y[key] = count(val)
> 
> print y
> 
> {'1': [{'220': 3}], '3': [{'238': 1}, {'220': 1}], '2': [{'238': 4}, {'220': 
> 1}], '5': [{'238': 1}, {'220': 2}], '4': [{'220': 2}], '7': [{'220': 1}], 
> '6': [{'238': 2}]}

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] HELP!!!!!

2008-04-17 Thread Michael Kim
Hi I am having a really hard time making my tictactoe program work.  I 
was wondering if you could could check it out and help me with the 
error.  Thanks


blank = " "



def asknumber(question, low, high):
response = None
while response not in range(low, high):
response = int(raw_input(question))
return response

def askquestion(question):
response = None
while response not in ("y", "n"):
response = raw_input (question).lower()
return response

def pieces():
whosefirst=askquestion("Do you want to go first? (y/n): ")
if whosefirst == "y":
human = X
X="X"
computer = O
O="O"
else:
computer = X
human = O
return computer, human

def newboard():
board = []
box = 9
for square in range(box):
blank = " "
board.append(blank)
return board

def createboard(board):
print "\n\t", board[0], "|", board[1], "|", board[2]
print "\t", "-"
print "\t", board[3], "|", board[4], "|", board[5]
print "\t", "-"
print "\t", board[6], "|", board[7], "|", board[8], "\n"

def allowedmove(board):
moves=[]
for square in range(box):
if board[square] == blank:
moves.append(square)
return moves

def winner(board):

movestowin=((0,1,2),(3,4,5),(6,7,8),(0,3,6),(1,4,7),(2,5,8),(0,4,8),(2,4,6))
for row in movestowin:
if board[row[0]] == board[row[1]] ==board[row[2]] !=blank:
winner=board[row[0]]
return winner
if blank not in board:
tie = "tie"
return tie
return None

def humanmove (board, human):
allowed = allowedmove(board)
move = None
while move not in allowed:
move = asknumber("It is your turn.  Pick 0-8:", 0, box)
if move not in allowed:
print "\nPick again.\n"
return move

def computermove (board, computer, human):
board = board[:]
winnermoves = (4, 0, 2, 6, 8, 1, 3, 5, 7)
for move in allowedmoves(board):
board[move] = computer
if winner (board) == computer:
print move
return move
board[move] = blank
for move in allowedmoves(board):
board[move] = human
if winner(board) == human:
print move
return move
board[move] = blank
for move in winnermoves:
if move in allwedmoves(board):
print move
return move

def whoseturn(turn):
if turn == X:
return O
else:
return X

def whowon(iwon, computer, human):
if iwon !=tie:
print iwon, "you win!"
else:
print "a tie"

def main():
computer, human = pieces()
turn = X
board = newboard()
createboard(board)
   
while not winner(board):
if turn == human:
move = humanmove(board, human)
board[move] = human
else:
move = computermove(board, computer, human)
board[move] = computer
createboard(board)
turn = whoseturn(turn)

iwon =  winner(board)
whowon(iwon, computer, human)
   
   
main()



___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Hoping to benefit from someone's experience...

2008-04-17 Thread linuxian iandsd
just a thought ...
 there must be some way of using OpenOffice to convert your ORIGINAL word
documents into HTML files ... then as html is a very nice & structured
language that you can manipulate & modify with ease just by adding some tags
inside where you want or wish 
this is also only if you have some rich content like tables inside your
documents ... if thats not your case, you can use OpenOffice tou extract
just text ...

hope this helps
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor